Skip to content

Commit

Permalink
[panthalassa] fixed build errors and failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Lenz committed Jun 15, 2018
1 parent e45c1dc commit 9aab602
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 9 deletions.
7 changes: 6 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,15 @@ func main() {
return
}

rawStore, err := exportedAccount.Marshal()
if err != nil {
panic(err)
}

err = db.Write("account", id.String(), &Account{
ID: id.String(),
Name: accountName,
AccountStore: exportedAccount,
AccountStore: string(rawStore),
Profile: string(rawProfile),
})

Expand Down
1 change: 1 addition & 0 deletions client/client_key_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (s *DoubleRatchetKeyStore) Get(k dr.Key, msgNum uint) (mk dr.Key, ok bool)
}

resp := <-respCha

if resp.Error != nil {
resp.Close(nil)
return dr.Key{}, false
Expand Down
2 changes: 1 addition & 1 deletion client/client_key_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestDoubleRatchetKeyStore_GetSuccess(t *testing.T) {

mustBeEqual(`{"key":"0000000000000000000100010000000000010001000000000000000100000001","msg_num":7}`, rpcCall.Data)

requireNil(api.Receive(rpcCall.Id, `{"error":"","payload":"{\"key\":\"{\\\"iv\\\":\\\"f+ZgKGwhkz82bokcs7HI8A==\\\",\\\"cipher_text\\\":\\\"Qu0SeXs/ahOjqcwPRIrK0sR9ngirapvt33x3SNLayFs=\\\",\\\"mac\\\":\\\"vJhCluH/bWdkcaA3vtTzDDsYFVO0A7UcL7wbPbvYdG0=\\\",\\\"v\\\":1}\"}"}`))
requireNil(api.Receive(rpcCall.Id, `{"error":"","payload":"{\"key\":\"{\\\"iv\\\":\\\"3Zd2O1KxUz2OZnWQPrTgCg==\\\",\\\"cipher_text\\\":\\\"q4FO26h5TICATqwwp9RXXXes1jX8asn+0TkL5Khx8Oc=\\\",\\\"mac\\\":\\\"XwX884HeXuodY3vgoKvmZcGkW0oPu2fBvRafxAsMu/I=\\\",\\\"v\\\":2}\"}"}`))

}
}
Expand Down
14 changes: 14 additions & 0 deletions keyManager/keyManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"errors"

"encoding/json"
aes "github.com/Bit-Nation/panthalassa/crypto/aes"
scrypt "github.com/Bit-Nation/panthalassa/crypto/scrypt"
ks "github.com/Bit-Nation/panthalassa/keyStore"
Expand All @@ -30,6 +31,19 @@ type Store struct {
Version uint8 `json:"version"`
}

// marshal
func (s Store) Marshal() ([]byte, error) {
return json.Marshal(s)
}

func UnmarshalStore(data []byte) (Store, error) {
var s Store
if err := json.Unmarshal(data, &s); err != nil {
return Store{}, err
}
return s, nil
}

//Open encrypted keystore with password
func OpenWithPassword(store Store, pw string) (*KeyManager, error) {

Expand Down
16 changes: 14 additions & 2 deletions mobile_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ func Start(config string, password string, client UpStream) error {
return err
}

store, err := keyManager.UnmarshalStore([]byte(c.EncryptedKeyManager))
if err != nil {
return err
}

// open key manager with password
km, err := keyManager.OpenWithPassword(c.EncryptedKeyManager, password)
km, err := keyManager.OpenWithPassword(store, password)
if err != nil {
return err
}
Expand All @@ -108,8 +113,13 @@ func StartFromMnemonic(config string, mnemonic string, client UpStream) error {
return err
}

store, err := keyManager.UnmarshalStore([]byte(c.EncryptedKeyManager))
if err != nil {
return err
}

// create key manager
km, err := keyManager.OpenWithMnemonic(c.EncryptedKeyManager, mnemonic)
km, err := keyManager.OpenWithMnemonic(store, mnemonic)
if err != nil {
return err
}
Expand Down Expand Up @@ -207,6 +217,8 @@ func Stop() error {
//Stop panthalassa
err := panthalassaInstance.Stop()
if err != nil {
//Reset singleton
panthalassaInstance = nil
return err
}

Expand Down
16 changes: 15 additions & 1 deletion panthalassa.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ func (p *Panthalassa) Stop() error {

//Export account with the given password
func (p *Panthalassa) Export(pw, pwConfirm string) (string, error) {
return p.km.Export(pw, pwConfirm)

// export
store, err := p.km.Export(pw, pwConfirm)
if err != nil {
return "", err
}

// marshal key store
rawStore, err := store.Marshal()
if err != nil {
return "", err
}

return string(rawStore), nil

}

// add friend to peer store
Expand Down
2 changes: 1 addition & 1 deletion profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func SignProfile(name, location, image string, km km.KeyManager) (Profile, error
}

// sign's a profile without the need to start panthalassa
func SignWithKeyManagerStore(name, location, image, keyManagerStore, password string) (Profile, error) {
func SignWithKeyManagerStore(name, location, image string, keyManagerStore km.Store, password string) (Profile, error) {

keyManager, err := km.OpenWithPassword(keyManagerStore, password)
if err != nil {
Expand Down
35 changes: 32 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ func NewAccountKeys(pw, pwConfirm string) (string, error) {
}

km := keyManager.CreateFromKeyStore(ks)
return km.Export(pw, pwConfirm)

// export store
store, err := km.Export(pw, pwConfirm)
if err != nil {
return "", err
}

rawStore, err := store.Marshal()
if err != nil {
return "", err
}

return string(rawStore), nil

}

//Create new account store from mnemonic
Expand All @@ -47,7 +60,18 @@ func NewAccountKeysFromMnemonic(mne, pw, pwConfirm string) (string, error) {

//Create keyManager
km := keyManager.CreateFromKeyStore(ks)
return km.Export(pw, pwConfirm)

store, err := km.Export(pw, pwConfirm)
if err != nil {
return "", err
}

rawStore, err := store.Marshal()
if err != nil {
return "", err
}

return string(rawStore), nil
}

//Check if mnemonic is valid
Expand All @@ -65,7 +89,12 @@ func IsValidMnemonic(mne string) bool {
// sign profile
func SignProfileStandAlone(name, location, image, keyManagerStore, password string) (string, error) {

p, err := profile.SignWithKeyManagerStore(name, location, image, keyManagerStore, password)
store, err := keyManager.UnmarshalStore([]byte(keyManagerStore))
if err != nil {
return "", err
}

p, err := profile.SignWithKeyManagerStore(name, location, image, store, password)

if err != nil {
return "", err
Expand Down

0 comments on commit 9aab602

Please sign in to comment.