Modified: app/cli/main.go

Updated queries

Modified:   peer/cwtch_peer.go

Changed capitalization
This commit is contained in:
Angus Champion de Crespigny 2018-06-23 19:56:51 -04:00 committed by Gogs
parent 13b5d17214
commit 966642c957
2 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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