diff --git a/app/cli/main.go b/app/cli/main.go index ec9e7ac..7198198 100644 --- a/app/cli/main.go +++ b/app/cli/main.go @@ -7,6 +7,10 @@ import ( "github.com/c-bata/go-prompt" "strings" "time" + + "bytes" + "syscall" + "golang.org/x/crypto/ssh/terminal" ) var app app2.Application diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 56e9aa4..eb53740 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -29,6 +29,8 @@ type cwtchPeer struct { Log chan string `json:"-"` connectionsManager *connections.Manager 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 @@ -80,13 +82,13 @@ return dkr, salt } //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 if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil { panic(err) } //copy Peer struct, then remove password and save the copy - cpc := &CwtchPeer{} + cpc := &cwtchPeer{} deepcopier.Copy(p).To(cpc) var blankpass [32]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. -func DecryptProfile(ciphertext []byte, password [32]byte) (error, *CwtchPeer){ +func DecryptProfile(ciphertext []byte, password [32]byte) (error, *cwtchPeer){ var decryptNonce [24]byte copy(decryptNonce[:], ciphertext[:24]) decrypted, ok := secretbox.Open(nil, ciphertext[24:], &decryptNonce, &password) if ok { - cp := &CwtchPeer{} + cp := &cwtchPeer{} err := json.Unmarshal(decrypted, &cp) if err == nil { return nil, cp @@ -137,8 +139,8 @@ func (cp *cwtchPeer) setup() { } // NewCwtchPeer creates and returns a new CwtchPeer with the given name. -func NewCwtchPeer(name string, password string) *CwtchPeer { - cp := new(CwtchPeer) +func NewCwtchPeer(name string, password string) *cwtchPeer { + cp := new(cwtchPeer) cp.Profile = model.GenerateNewProfile(name) cp.setup() pass, salt := CreateKey(password) @@ -148,7 +150,7 @@ func NewCwtchPeer(name string, password string) *CwtchPeer { } // 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() encryptedbytes := EncryptProfile(cp, cp.password) 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 -func LoadCwtchPeer(profilefile string, password string) (*CwtchPeer, error) { +func LoadCwtchPeer(profilefile string, password string) (*cwtchPeer, error) { encryptedbytes, _ := ioutil.ReadFile(profilefile) //get the salt