Skip to content
Snippets Groups Projects
Commit 734ecb66 authored by Jake Taylor's avatar Jake Taylor
Browse files

Merge remote-tracking branch 'origin/hotfix/integration' into hotfix/integration

parents 23248df9 61575d6b
No related branches found
No related tags found
3 merge requests!510Release,!267Make BuildReceptionIdentity public, and make backup restore function return a...,!263Hotfix/refactor cmd
......@@ -10,6 +10,8 @@
package storage
import (
"gitlab.com/elixxir/crypto/diffieHellman"
"math/rand"
"sync"
"testing"
"time"
......@@ -230,7 +232,14 @@ func InitTestingSession(i interface{}) Session {
kv := versioned.NewKV(ekv.MakeMemstore())
s := &session{kv: kv}
uid := id.NewIdFromString("zezima", id.User, i)
u, err := user.NewUser(kv, uid, uid, []byte("salt"), []byte("salt"), privKey, privKey, false, nil, nil)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := user.NewUser(kv, uid, uid, []byte("salt"), []byte("salt"), privKey, privKey, false, dhPrivKey, dhPubKey)
if err != nil {
jww.FATAL.Panicf("InitTestingSession failed to create dummy user: %+v", err)
}
......
......@@ -11,7 +11,10 @@ import (
"bytes"
"crypto/rand"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"testing"
......@@ -22,11 +25,19 @@ func TestNewCryptographicIdentity(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("zezima", id.User, t)
salt := []byte("salt")
_ = newCryptographicIdentity(uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, kv)
_, err := kv.Get(cryptographicIdentityKey, 0)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
_ = newCryptographicIdentity(uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey, kv)
_, err := kv.Get(cryptographicIdentityKey, currentCryptographicIdentityVersion)
if err != nil {
t.Errorf("Did not store cryptographic identity")
t.Errorf("Did not store cryptographic identity: %+v", err)
}
}
......@@ -35,7 +46,15 @@ func TestLoadCryptographicIdentity(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("zezima", id.User, t)
salt := []byte("salt")
ci := newCryptographicIdentity(uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, kv)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey, kv)
err := ci.save(kv)
if err != nil {
......@@ -64,7 +83,15 @@ func TestCryptographicIdentity_GetReceptionRSA(t *testing.T) {
t.Errorf("Failed to generate pk2")
}
salt := []byte("salt")
ci := newCryptographicIdentity(uid, uid, salt, salt, pk1, pk2, false, kv)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(
uid, uid, salt, salt, pk1, pk2, false, dhPrivKey, dhPubKey, kv)
if ci.GetReceptionRSA().D != pk2.D {
t.Errorf("Did not receive expected RSA key. Expected: %+v, Received: %+v", pk2, ci.GetReceptionRSA())
}
......@@ -83,7 +110,15 @@ func TestCryptographicIdentity_GetTransmissionRSA(t *testing.T) {
t.Errorf("Failed to generate pk2")
}
salt := []byte("salt")
ci := newCryptographicIdentity(uid, uid, salt, salt, pk1, pk2, false, kv)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(
uid, uid, salt, salt, pk1, pk2, false, dhPrivKey, dhPubKey, kv)
if ci.GetTransmissionRSA().D != pk1.D {
t.Errorf("Did not receive expected RSA key. Expected: %+v, Received: %+v", pk1, ci.GetTransmissionRSA())
}
......@@ -95,7 +130,15 @@ func TestCryptographicIdentity_GetTransmissionSalt(t *testing.T) {
uid := id.NewIdFromString("zezima", id.User, t)
ts := []byte("transmission salt")
rs := []byte("reception salt")
ci := newCryptographicIdentity(uid, uid, ts, rs, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, kv)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(uid, uid, ts, rs, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey, kv)
if bytes.Compare(ci.GetTransmissionSalt(), ts) != 0 {
t.Errorf("Did not get expected salt. Expected: %+v, Received: %+v", ts, ci.GetTransmissionSalt())
}
......@@ -107,7 +150,15 @@ func TestCryptographicIdentity_GetReceptionSalt(t *testing.T) {
uid := id.NewIdFromString("zezima", id.User, t)
ts := []byte("transmission salt")
rs := []byte("reception salt")
ci := newCryptographicIdentity(uid, uid, ts, rs, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, kv)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(uid, uid, ts, rs, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey, kv)
if bytes.Compare(ci.GetReceptionSalt(), rs) != 0 {
t.Errorf("Did not get expected salt. Expected: %+v, Received: %+v", rs, ci.GetReceptionSalt())
}
......@@ -119,7 +170,14 @@ func TestCryptographicIdentity_GetTransmissionID(t *testing.T) {
rid := id.NewIdFromString("zezima", id.User, t)
tid := id.NewIdFromString("jakexx360", id.User, t)
salt := []byte("salt")
ci := newCryptographicIdentity(tid, rid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, kv)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(tid, rid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, dhPrivKey, dhPubKey, kv)
if !ci.GetTransmissionID().Cmp(tid) {
t.Errorf("Did not receive expected user ID. Expected: %+v, Received: %+v", tid, ci.GetTransmissionID())
}
......@@ -131,7 +189,14 @@ func TestCryptographicIdentity_GetReceptionID(t *testing.T) {
rid := id.NewIdFromString("zezima", id.User, t)
tid := id.NewIdFromString("jakexx360", id.User, t)
salt := []byte("salt")
ci := newCryptographicIdentity(tid, rid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, kv)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(tid, rid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, dhPrivKey, dhPubKey, kv)
if !ci.GetReceptionID().Cmp(rid) {
t.Errorf("Did not receive expected user ID. Expected: %+v, Received: %+v", rid, ci.GetReceptionID())
}
......@@ -142,7 +207,14 @@ func TestCryptographicIdentity_IsPrecanned(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("zezima", id.User, t)
salt := []byte("salt")
ci := newCryptographicIdentity(uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, true, kv)
prng := rand.Reader
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, true, dhPrivKey, dhPubKey, kv)
if !ci.IsPrecanned() {
t.Error("I really don't know how this could happen")
}
......
......@@ -11,10 +11,14 @@ import (
"bytes"
"encoding/binary"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime"
"math/rand"
"testing"
"time"
)
......@@ -24,7 +28,15 @@ func TestUser_GetRegistrationValidationSignature(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("test", id.User, t)
salt := []byte("salt")
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......@@ -59,7 +71,15 @@ func TestUser_SetRegistrationValidationSignature(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("test", id.User, t)
salt := []byte("salt")
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......@@ -102,7 +122,15 @@ func TestUser_loadRegistrationValidationSignature(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("test", id.User, t)
salt := []byte("salt")
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......@@ -145,7 +173,15 @@ func TestUser_GetRegistrationTimestamp(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("test", id.User, t)
salt := []byte("salt")
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......@@ -194,7 +230,15 @@ func TestUser_loadRegistrationTimestamp(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("test", id.User, t)
salt := []byte("salt")
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......
......@@ -9,9 +9,13 @@ package user
import (
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"math/rand"
"testing"
)
......@@ -26,7 +30,15 @@ func TestLoadUser(t *testing.T) {
uid := id.NewIdFromString("test", id.User, t)
salt := []byte("salt")
ci := newCryptographicIdentity(uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false, kv)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
ci := newCryptographicIdentity(uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey, kv)
err = ci.save(kv)
if err != nil {
t.Errorf("Failed to save ci to kv: %+v", err)
......@@ -43,7 +55,15 @@ func TestNewUser(t *testing.T) {
kv := versioned.NewKV(ekv.MakeMemstore())
uid := id.NewIdFromString("test", id.User, t)
salt := []byte("salt")
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, uid, uid, salt, salt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......
......@@ -9,10 +9,14 @@ package user
import (
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime"
"math/rand"
"testing"
)
......@@ -23,7 +27,15 @@ func TestUser_SetUsername(t *testing.T) {
rid := id.NewIdFromString("recv", id.User, t)
tsalt := []byte("tsalt")
rsalt := []byte("rsalt")
u, err := NewUser(kv, tid, rid, tsalt, rsalt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, tid, rid, tsalt, rsalt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......@@ -57,7 +69,15 @@ func TestUser_GetUsername(t *testing.T) {
rid := id.NewIdFromString("recv", id.User, t)
tsalt := []byte("tsalt")
rsalt := []byte("rsalt")
u, err := NewUser(kv, tid, rid, tsalt, rsalt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, tid, rid, tsalt, rsalt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......@@ -85,7 +105,15 @@ func TestUser_loadUsername(t *testing.T) {
rid := id.NewIdFromString("recv", id.User, t)
tsalt := []byte("tsalt")
rsalt := []byte("rsalt")
u, err := NewUser(kv, tid, rid, tsalt, rsalt, &rsa.PrivateKey{}, &rsa.PrivateKey{}, false)
prng := rand.New(rand.NewSource(42))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
dhPrivKey := diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng)
dhPubKey := diffieHellman.GeneratePublicKey(dhPrivKey, grp)
u, err := NewUser(kv, tid, rid, tsalt, rsalt, &rsa.PrivateKey{},
&rsa.PrivateKey{}, false, dhPrivKey, dhPubKey)
if err != nil || u == nil {
t.Errorf("Failed to create new user: %+v", err)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment