diff --git a/api/client.go b/api/client.go index 58697ae0f86e1b9f9c1d3ecb560e4be94af82b6a..5db02f69ce0fa1aca51368d975746b6f63b8fc18 100644 --- a/api/client.go +++ b/api/client.go @@ -17,6 +17,7 @@ import ( "github.com/pkg/errors" "gitlab.com/elixxir/client/bots" "gitlab.com/elixxir/client/cmixproto" + clientcrypto "gitlab.com/elixxir/client/crypto" "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/keyStore" @@ -109,6 +110,17 @@ func newClient(s globals.Storage, locA, locB string, ndfJSON *ndf.NetworkDefinit cl.ndf = ndfJSON cl.sendFunc = sendFunc + // TODO: FIX ME + // While the old session is still valid, we are using the LocA storage to initialize the session + dirname := filepath.Dir(locA) + //FIXME: We need to accept the user's password here! + io.SessionV2, err = storage.Init(dirname, "DUMMYPASSWORDFIXME") + if err != nil { + return nil, errors.Wrap(err, "Login: could not initialize v2 storage") + } + clientcrypto.SessionV2 = io.SessionV2 + cl.sessionV2 = io.SessionV2 + //Create the cmix group and init the registry cmixGrp := cyclic.NewGroup( large.NewIntFromString(cl.ndf.CMIX.Prime, 16), @@ -159,17 +171,7 @@ func (cl *Client) Login(password string) (*id.ID, error) { cl.session = session - // TODO: FIX ME - // While the old session is still valid, we are using the LocA storage to initialize the session - locA, _ := cl.storage.GetLocation() - dirname := filepath.Dir(locA) - io.SessionV2, err = storage.Init(dirname, password) - if err != nil { - return nil, errors.Wrap(err, "Login: could not initialize v2 storage") - } - cl.sessionV2 = io.SessionV2 - - regState, err := io.SessionV2.GetRegState() + regState, err := cl.sessionV2.GetRegState() // fixme ! if err != nil && os.IsNotExist(err) { io.SessionV2.SetRegState(user.KeyGenComplete) diff --git a/api/client_test.go b/api/client_test.go index fcd302c1e629d82a474f5a7ec59010be557f9618..7cf46eeeb77a446cd074af0442a37c0121b70a23 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -596,6 +596,9 @@ func TestClient_LogoutHappyPath(t *testing.T) { t.Errorf("Could not connect: %+v", err) } + tc.sessionV2, err = storage.Init(".ekv-logouthappypath", "password") + io.SessionV2 = tc.sessionV2 + err = tc.GenerateKeys(nil, "") if err != nil { t.Errorf("Could not generate Keys: %+v", err) diff --git a/api/mockserver_test.go b/api/mockserver_test.go index ac3f9919dbc48b6cb99ec111bdf0345896a3dbbe..e64309f108dc48398b6d13fb5ff81a12dfce3f4b 100644 --- a/api/mockserver_test.go +++ b/api/mockserver_test.go @@ -11,8 +11,9 @@ import ( "fmt" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/io" - clientStorage "gitlab.com/elixxir/client/storage" + //clientStorage "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/user" + //"gitlab.com/elixxir/client/crypto" "gitlab.com/elixxir/comms/gateway" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/notificationBot" @@ -60,7 +61,6 @@ func TestMain(m *testing.M) { // Set logging params jww.SetLogThreshold(jww.LevelTrace) jww.SetStdoutThreshold(jww.LevelTrace) - io.SessionV2, _ = clientStorage.Init(".ekvapi", "test") os.Exit(testMainWrapper(m)) } diff --git a/api/register.go b/api/register.go index 7dd5c28a76c5664167c60bcaf4c904d7c80f8aa4..7af4fea2bbf0c52025427f6391b3f62cd5db5f66 100644 --- a/api/register.go +++ b/api/register.go @@ -63,7 +63,7 @@ func (cl *Client) RegisterWithPermissioning(preCan bool, registrationCode string //store the node keys for n, k := range nodeKeyMap { - cl.session.PushNodeKey(&n, k) + cl.sessionV2.PushNodeKey(&n, k) } //update the state @@ -331,7 +331,7 @@ func (cl *Client) registerWithNode(index int, salt, registrationValidationSignat ReceptionKey: registration.GenerateBaseKey(cmixGrp, serverPubDH, cmixPrivateKeyDH, receptionHash), } - cl.session.PushNodeKey(nodeID, key) + cl.sessionV2.PushNodeKey(nodeID, key) } //registerWithPermissioning serves as a helper function for RegisterWithPermissioning. diff --git a/api/register_test.go b/api/register_test.go index 055c9a8a222d2cdb3f405815c396c62963d143af..dad3b6e8bef3fb297deb22328315eda915330b49 100644 --- a/api/register_test.go +++ b/api/register_test.go @@ -6,11 +6,9 @@ package api import ( - "crypto/sha256" "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/user" - "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "testing" ) @@ -53,7 +51,6 @@ func TestRegistrationGob(t *testing.T) { } VerifyRegisterGobUser(Session, t) - VerifyRegisterGobKeys(Session, testClient.topology, t) disconnectServers() } @@ -99,7 +96,6 @@ func TestClient_Register(t *testing.T) { VerifyRegisterGobUser(Session, t) - VerifyRegisterGobKeys(Session, testClient.topology, t) disconnectServers() } @@ -114,22 +110,6 @@ func VerifyRegisterGobUser(session user.Session, t *testing.T) { } } -//Verify that the keys from the session in the registration above match the expected keys -func VerifyRegisterGobKeys(session user.Session, topology *connect.Circuit, t *testing.T) { - cmixGrp, _ := getGroups() - h := sha256.New() - h.Write([]byte(string(40005))) - expectedTransmissionBaseKey := cmixGrp.NewIntFromBytes(h.Sum(nil)) - - if session.GetNodeKeys(topology)[0].TransmissionKey.Cmp( - expectedTransmissionBaseKey) != 0 { - t.Errorf("Transmission base key was %v, expected %v", - session.GetNodeKeys(topology)[0].TransmissionKey.Text(16), - expectedTransmissionBaseKey.Text(16)) - } - -} - // Verify that a valid precanned user can register func TestRegister_ValidRegParams___(t *testing.T) { // Initialize client with dummy storage diff --git a/crypto/encrypt.go b/crypto/encrypt.go index 7686521401474733e45bc47b508e90501d4ef8ea..8c39105409b7a0e461493b00cfaf846be31925cd 100644 --- a/crypto/encrypt.go +++ b/crypto/encrypt.go @@ -8,6 +8,7 @@ package crypto import ( "gitlab.com/elixxir/client/globals" + "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/crypto/cmix" "gitlab.com/elixxir/crypto/cyclic" @@ -17,16 +18,23 @@ import ( "gitlab.com/xx_network/comms/connect" ) +// TODO: REMOVE ME +var SessionV2 *storage.Session + // CMIX Encrypt performs the encryption // of the msg to a team of nodes // It returns a new msg func CMIXEncrypt(session user.Session, topology *connect.Circuit, salt []byte, msg *format.Message) (*format.Message, [][]byte) { // Generate the encryption key - nodeKeys := session.GetNodeKeys(topology) + nodeKeys, err := SessionV2.GetNodeKeys(topology) + if err != nil { + globals.Log.FATAL.Panicf("could not get nodeKeys: %+v", err) + } baseKeys := make([]*cyclic.Int, len(nodeKeys)) for i, key := range nodeKeys { + globals.Log.WARN.Printf("NodeKey for %d: %v", i, key.TransmissionKey) baseKeys[i] = key.TransmissionKey } diff --git a/crypto/encryptdecrypt_test.go b/crypto/encryptdecrypt_test.go index 3e7d30506a5504abee1f285806fb9eda01d7192b..a74a65d9bd79480f233875e8ed5238fa4025ae4e 100644 --- a/crypto/encryptdecrypt_test.go +++ b/crypto/encryptdecrypt_test.go @@ -9,6 +9,8 @@ package crypto import ( "bytes" "encoding/binary" + "fmt" + "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/user" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/crypto/cmix" @@ -71,6 +73,8 @@ func setup() { nil, nil, nil, nil, nil, cmixGrp, e2eGrp, "password") + SessionV2, _ = storage.Init(".ekvcryptotest", "password") + for i := 0; i < numNodes; i++ { nk := user.NodeKeys{} @@ -85,7 +89,9 @@ func setup() { cmix.NodeKeyGen(cmixGrp, h.Sum(nil), nk.TransmissionKey, tempKey) cmixGrp.Mul(serverPayloadBKey, tempKey, serverPayloadBKey) - session.PushNodeKey(topology.GetNodeAtIndex(i), nk) + SessionV2.PushNodeKey(topology.GetNodeAtIndex(i), nk) + fmt.Printf("Saved NodeKey: %s, %v", topology.GetNodeAtIndex(i), + nk.TransmissionKey) } diff --git a/io/send.go b/io/send.go index 74d008e18a969bc58603c1aa3247fada8749d6e4..b9965f8ec8135016219244eeb6a6f65d6cc89b0c 100644 --- a/io/send.go +++ b/io/send.go @@ -150,7 +150,11 @@ func (rm *ReceptionManager) send(session user.Session, topology *connect.Circuit } // Retrieve the base key for the zeroeth node - nodeKeys := session.GetNodeKeys(topology) + nodeKeys, err := SessionV2.GetNodeKeys(topology) + if err != nil { + globals.Log.ERROR.Printf("could not get nodeKeys: %+v", err) + return err + } nk := nodeKeys[0] clientGatewayKey := cmix.GenerateClientGatewayKey(nk.TransmissionKey) diff --git a/user/session.go b/user/session.go index 948208bf39ca9a6360a238daa180512d6f43c814..95ee3f16a747056af6d734e83c78302f06dce5de 100644 --- a/user/session.go +++ b/user/session.go @@ -21,7 +21,6 @@ import ( "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/switchboard" - "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "io" "sync" @@ -35,8 +34,6 @@ var ErrQuery = errors.New("element not in map") // Interface for User Session operations type Session interface { GetCurrentUser() (currentUser *User) - GetNodeKeys(topology *connect.Circuit) []NodeKeys - PushNodeKey(id *id.ID, key NodeKeys) GetRSAPrivateKey() *rsa.PrivateKey GetRSAPublicKey() *rsa.PublicKey GetCMIXDHPrivateKey() *cyclic.Int @@ -366,28 +363,6 @@ func (s *SessionObj) GetSalt() []byte { return salt } -func (s *SessionObj) GetNodeKeys(topology *connect.Circuit) []NodeKeys { - s.LockStorage() - defer s.UnlockStorage() - - keys := make([]NodeKeys, topology.Len()) - - for i := 0; i < topology.Len(); i++ { - keys[i] = s.NodeKeys[*topology.GetNodeAtIndex(i)] - } - - return keys -} - -func (s *SessionObj) PushNodeKey(id *id.ID, key NodeKeys) { - s.LockStorage() - defer s.UnlockStorage() - - s.NodeKeys[*id] = key - - return -} - //RegisterPermissioningSignature sets sessions registration signature and // sets the regState to reflect that registering with permissioning is complete // Returns an error if unable to set the regState diff --git a/user/session_test.go b/user/session_test.go index d0a2805a25d8e8bb9b3ff08c05057cf57f80f972..08176cf53d877d5d028ca4499f5cc3506a68ca4b 100644 --- a/user/session_test.go +++ b/user/session_test.go @@ -15,7 +15,6 @@ import ( "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/primitives/format" - "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "math/rand" "reflect" @@ -26,7 +25,6 @@ import ( // surrounding the User struct and the Registry interface func TestUserSession(t *testing.T) { - test := 11 pass := 0 u := new(User) @@ -37,12 +35,6 @@ func TestUserSession(t *testing.T) { u.User = id.NewIdFromUInt(UID, id.User, t) u.Username = "Mario" - grp := cyclic.NewGroup(large.NewInt(107), large.NewInt(2)) - - nodeID := id.NewIdFromUInt(1, id.Node, t) - - topology := connect.NewCircuit([]*id.ID{nodeID}) - // Storage storage := &globals.RamStorage{} @@ -72,11 +64,6 @@ func TestUserSession(t *testing.T) { err.Error()) } - ses.PushNodeKey(nodeID, NodeKeys{ - TransmissionKey: grp.NewInt(2), - ReceptionKey: grp.NewInt(2), - }) - ses.SetLastMessageID("totally unique ID") err = ses.StoreSession() @@ -114,41 +101,6 @@ func TestUserSession(t *testing.T) { pass++ } - if ses.GetNodeKeys(topology) == nil { - t.Errorf("Keys not set correctly!") - } else { - - test += len(ses.GetNodeKeys(topology)) - - for i := 0; i < len(ses.GetNodeKeys(topology)); i++ { - orig := privateKey.PrivateKey - sesPriv := ses.GetRSAPrivateKey().PrivateKey - if !reflect.DeepEqual(*ses.GetRSAPublicKey(), publicKey) { - t.Errorf("Error: Public key not set correctly!") - } else if sesPriv.E != orig.E { - t.Errorf("Error: Private key not set correctly E! \nExpected: %+v\nreceived: %+v", - orig.E, sesPriv.E) - } else if sesPriv.D.Cmp(orig.D) != 0 { - t.Errorf("Error: Private key not set correctly D! \nExpected: %+v\nreceived: %+v", - orig.D, sesPriv.D) - } else if sesPriv.N.Cmp(orig.N) != 0 { - t.Errorf("Error: Private key not set correctly N! \nExpected: %+v\nreceived: %+v", - orig.N, sesPriv.N) - } else if !reflect.DeepEqual(sesPriv.Primes, orig.Primes) { - t.Errorf("Error: Private key not set correctly PRIMES! \nExpected: %+v\nreceived: %+v", - orig, sesPriv) - } else if ses.GetNodeKeys(topology)[i].ReceptionKey.Cmp(grp. - NewInt(2)) != 0 { - t.Errorf("Reception key not set correct!") - } else if ses.GetNodeKeys(topology)[i].TransmissionKey.Cmp( - grp.NewInt(2)) != 0 { - t.Errorf("Transmission key not set correctly!") - } - - pass++ - } - } - //TODO: FIX THIS? if ses.GetRSAPrivateKey() == nil { t.Errorf("Error: Private Keys not set correctly!") @@ -223,10 +175,6 @@ func TestSessionObj_DeleteContact(t *testing.T) { u.User = id.NewIdFromUInt(UID, id.User, t) u.Username = "Mario" - grp := cyclic.NewGroup(large.NewInt(107), large.NewInt(2)) - - nodeID := id.NewIdFromUInt(1, id.Node, t) - // Storage storage := &globals.RamStorage{} @@ -256,11 +204,6 @@ func TestSessionObj_DeleteContact(t *testing.T) { err.Error()) } - ses.PushNodeKey(nodeID, NodeKeys{ - TransmissionKey: grp.NewInt(2), - ReceptionKey: grp.NewInt(2), - }) - testContact := id.NewIdFromString("test", id.User, t) ses.StoreContactByValue("test", testContact, []byte("test")) @@ -277,8 +220,6 @@ func TestGetPubKey(t *testing.T) { u.User = UID u.Username = "Mario" - grp := cyclic.NewGroup(large.NewInt(107), large.NewInt(2)) - rng := rand.New(rand.NewSource(42)) privateKey, _ := rsa.GenerateKey(rng, 768) publicKey := rsa.PublicKey{PublicKey: privateKey.PublicKey} @@ -305,11 +246,6 @@ func TestGetPubKey(t *testing.T) { err.Error()) } - ses.PushNodeKey(id.NewIdFromUInt(1, id.Node, t), NodeKeys{ - TransmissionKey: grp.NewInt(2), - ReceptionKey: grp.NewInt(2), - }) - pubKey := *ses.GetRSAPublicKey() if !reflect.DeepEqual(pubKey, publicKey) { t.Errorf("Public key not returned correctly!") @@ -327,9 +263,6 @@ func TestSessionObj_StorageIsEmpty(t *testing.T) { u.User = id.NewIdFromUInt(UID, id.User, t) u.Username = "Mario" - grp := cyclic.NewGroup(large.NewInt(107), large.NewInt(2)) - - nodeID := id.NewIdFromUInt(1, id.Node, t) // Storage storage := &globals.RamStorage{} @@ -351,11 +284,6 @@ func TestSessionObj_StorageIsEmpty(t *testing.T) { regSignature := make([]byte, 768) rng.Read(regSignature) - ses.PushNodeKey(nodeID, NodeKeys{ - TransmissionKey: grp.NewInt(2), - ReceptionKey: grp.NewInt(2), - }) - ses.SetLastMessageID("totally unique ID") //Test that the session is empty before the StoreSession call @@ -385,10 +313,6 @@ func TestSessionObj_GetContactByValue(t *testing.T) { u.User = id.NewIdFromUInt(UID, id.User, t) u.Username = "Mario" - grp := cyclic.NewGroup(large.NewInt(107), large.NewInt(2)) - - nodeID := id.NewIdFromUInt(1, id.Node, t) - // Storage storage := &globals.RamStorage{} @@ -416,11 +340,6 @@ func TestSessionObj_GetContactByValue(t *testing.T) { err.Error()) } - ses.PushNodeKey(nodeID, NodeKeys{ - TransmissionKey: grp.NewInt(2), - ReceptionKey: grp.NewInt(2), - }) - userId := id.NewIdFromBytes([]byte("test"), t) ses.StoreContactByValue("value", userId, []byte("test")) @@ -445,8 +364,6 @@ func TestGetPrivKey(t *testing.T) { u.User = UID u.Username = "Mario" - grp := cyclic.NewGroup(large.NewInt(107), large.NewInt(2)) - rng := rand.New(rand.NewSource(42)) privateKey, _ := rsa.GenerateKey(rng, 768) publicKey := rsa.PublicKey{PublicKey: privateKey.PublicKey} @@ -473,11 +390,6 @@ func TestGetPrivKey(t *testing.T) { err.Error()) } - ses.PushNodeKey(id.NewIdFromUInt(1, id.Node, t), NodeKeys{ - TransmissionKey: grp.NewInt(2), - ReceptionKey: grp.NewInt(2), - }) - privKey := ses.GetRSAPrivateKey() if !reflect.DeepEqual(*privKey, *privateKey) { t.Errorf("Private key is not returned correctly!")