forked from cwtch.im/cwtch
Modified: app/cli/main.go
Updated queries Modified: peer/cwtch_peer.go Changed capitalization
This commit is contained in:
parent
13b5d17214
commit
966642c957
|
@ -7,6 +7,10 @@ import (
|
||||||
"github.com/c-bata/go-prompt"
|
"github.com/c-bata/go-prompt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"bytes"
|
||||||
|
"syscall"
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
var app app2.Application
|
var app app2.Application
|
||||||
|
|
|
@ -29,6 +29,8 @@ type cwtchPeer struct {
|
||||||
Log chan string `json:"-"`
|
Log chan string `json:"-"`
|
||||||
connectionsManager *connections.Manager
|
connectionsManager *connections.Manager
|
||||||
profilefile string
|
profilefile string
|
||||||
|
password [32]byte
|
||||||
|
salt [128]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// CwtchPeerInterface provides us with a way of testing systems built on top of cwtch without having to
|
// CwtchPeerInterface provides us with a way of testing systems built on top of cwtch without having to
|
||||||
|
@ -80,13 +82,13 @@ return dkr, salt
|
||||||
}
|
}
|
||||||
|
|
||||||
//EncryptMessage takes a message and encrypts the message under the group key.
|
//EncryptMessage takes a message and encrypts the message under the group key.
|
||||||
func EncryptProfile(p *CwtchPeer, password [32]byte) []byte {
|
func EncryptProfile(p *cwtchPeer, password [32]byte) []byte {
|
||||||
var nonce [24]byte
|
var nonce [24]byte
|
||||||
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
|
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
//copy Peer struct, then remove password and save the copy
|
//copy Peer struct, then remove password and save the copy
|
||||||
cpc := &CwtchPeer{}
|
cpc := &cwtchPeer{}
|
||||||
deepcopier.Copy(p).To(cpc)
|
deepcopier.Copy(p).To(cpc)
|
||||||
var blankpass [32]byte
|
var blankpass [32]byte
|
||||||
var blanksalt [128]byte
|
var blanksalt [128]byte
|
||||||
|
@ -99,13 +101,13 @@ func EncryptProfile(p *CwtchPeer, password [32]byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
//EncryptMessage takes a message and encrypts the message under the group key.
|
//EncryptMessage takes a message and encrypts the message under the group key.
|
||||||
func DecryptProfile(ciphertext []byte, password [32]byte) (error, *CwtchPeer){
|
func DecryptProfile(ciphertext []byte, password [32]byte) (error, *cwtchPeer){
|
||||||
|
|
||||||
var decryptNonce [24]byte
|
var decryptNonce [24]byte
|
||||||
copy(decryptNonce[:], ciphertext[:24])
|
copy(decryptNonce[:], ciphertext[:24])
|
||||||
decrypted, ok := secretbox.Open(nil, ciphertext[24:], &decryptNonce, &password)
|
decrypted, ok := secretbox.Open(nil, ciphertext[24:], &decryptNonce, &password)
|
||||||
if ok {
|
if ok {
|
||||||
cp := &CwtchPeer{}
|
cp := &cwtchPeer{}
|
||||||
err := json.Unmarshal(decrypted, &cp)
|
err := json.Unmarshal(decrypted, &cp)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil, cp
|
return nil, cp
|
||||||
|
@ -137,8 +139,8 @@ func (cp *cwtchPeer) setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCwtchPeer creates and returns a new CwtchPeer with the given name.
|
// NewCwtchPeer creates and returns a new CwtchPeer with the given name.
|
||||||
func NewCwtchPeer(name string, password string) *CwtchPeer {
|
func NewCwtchPeer(name string, password string) *cwtchPeer {
|
||||||
cp := new(CwtchPeer)
|
cp := new(cwtchPeer)
|
||||||
cp.Profile = model.GenerateNewProfile(name)
|
cp.Profile = model.GenerateNewProfile(name)
|
||||||
cp.setup()
|
cp.setup()
|
||||||
pass, salt := CreateKey(password)
|
pass, salt := CreateKey(password)
|
||||||
|
@ -148,7 +150,7 @@ func NewCwtchPeer(name string, password string) *CwtchPeer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save saves the CwtchPeer profile state to a file.
|
// Save saves the CwtchPeer profile state to a file.
|
||||||
func (cp *CwtchPeer) Save(profilefile string) error {
|
func (cp *cwtchPeer) Save(profilefile string) error {
|
||||||
cp.mutex.Lock()
|
cp.mutex.Lock()
|
||||||
encryptedbytes := EncryptProfile(cp, cp.password)
|
encryptedbytes := EncryptProfile(cp, cp.password)
|
||||||
encryptedbytes = append(cp.salt[:],encryptedbytes...)
|
encryptedbytes = append(cp.salt[:],encryptedbytes...)
|
||||||
|
@ -159,7 +161,7 @@ func (cp *CwtchPeer) Save(profilefile string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadCwtchPeer loads an existing CwtchPeer from a file. CHECK METHOD RETURN
|
// LoadCwtchPeer loads an existing CwtchPeer from a file. CHECK METHOD RETURN
|
||||||
func LoadCwtchPeer(profilefile string, password string) (*CwtchPeer, error) {
|
func LoadCwtchPeer(profilefile string, password string) (*cwtchPeer, error) {
|
||||||
encryptedbytes, _ := ioutil.ReadFile(profilefile)
|
encryptedbytes, _ := ioutil.ReadFile(profilefile)
|
||||||
|
|
||||||
//get the salt
|
//get the salt
|
||||||
|
|
Loading…
Reference in New Issue