Skip to content
Snippets Groups Projects
Commit 6e1d6c71 authored by Jono's avatar Jono
Browse files

Integrating output registration with input of cMix

parent 37f99124
Branches
Tags
No related merge requests found
......@@ -8,6 +8,7 @@ package api
import (
"crypto/rand"
"crypto/sha256"
"errors"
"fmt"
"github.com/golang/protobuf/proto"
......@@ -25,6 +26,7 @@ import (
pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/csprng"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/hash"
"gitlab.com/elixxir/crypto/registration"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/primitives/id"
......@@ -85,18 +87,18 @@ func Register(registrationCode, registrationAddr string, gwAddresses []string,
// Generate DSA keypair
params := signature.NewDSAParams(rand.Reader, signature.L2048N256)
privateKey := params.PrivateKeyGen(rand.Reader)
publicKey := privateKey.PublicKeyGen()
// Generate UserID by hashing salt and public key
UID := registration.GenUserID(privateKey.PublicKeyGen(), salt)
UID := registration.GenUserID(publicKey, salt)
// Send registration code and public key to RegistrationServer
p, q, g := privateKey.GetParams()
response, err := client.SendRegistrationMessage(registrationAddr,
&pb.RegisterUserMessage{
Y: privateKey.GetPublicKey().Bytes(),
P: p.Bytes(),
Q: q.Bytes(),
G: g.Bytes(),
Y: publicKey.GetKey().Bytes(),
P: params.GetP().Bytes(),
Q: params.GetQ().Bytes(),
G: params.GetG().Bytes(),
})
if err != nil {
globals.Log.ERROR.Printf(
......@@ -119,10 +121,10 @@ func Register(registrationCode, registrationAddr string, gwAddresses []string,
nonceResponse, err := client.SendRequestNonceMessage(gwAddr,
&pb.RequestNonceMessage{
Salt: salt,
Y: privateKey.GetPublicKey().Bytes(),
P: p.Bytes(),
Q: q.Bytes(),
G: g.Bytes(),
Y: publicKey.GetKey().Bytes(),
P: params.GetP().Bytes(),
Q: params.GetQ().Bytes(),
G: params.GetG().Bytes(),
Hash: regHash,
R: regR,
S: regS,
......@@ -177,29 +179,56 @@ func Register(registrationCode, registrationAddr string, gwAddresses []string,
}
// FIXME: Add private key to session storage
//nus := user.NewSession(u, gwAddresses[0], nk, cyclic.NewIntFromBytes([]byte(
// "this is not a real public key")))
//
//_, err = payment.CreateWallet(nus, mint)
//if err != nil {
// return id.ZeroID, err
//}
// Generate cyclic group for key generation
grp := cyclic.NewGroup(
params.GetP(),
cyclic.NewInt(2),
cyclic.NewInt(2),
cyclic.NewRandom(cyclic.NewInt(3), cyclic.NewInt(7)),
)
nk := make([]user.NodeKeys, len(gwAddresses))
// Initialise blake2b hash for transmission keys and sha256 for reception
// keys
transmissionHash, _ := hash.NewCMixHash()
receptionHash := sha256.New()
// Loop through all the server public keys
for itr, publicKey := range serverPublicKeys {
// Generate the base keys
nk[itr].TransmissionKey = registration.GenerateBaseKey(
&grp, publicKey, privateKey, transmissionHash,
)
nk[itr].ReceptionKey = registration.GenerateBaseKey(
&grp, publicKey, privateKey, receptionHash,
)
}
u := user.User{UID, ""}
nus := user.NewSession(&u, gwAddresses[0], nk, privateKey.PublicKeyGen(), privateKey)
_, err = payment.CreateWallet(nus, mint)
if err != nil {
return id.ZeroID, err
}
//
//errStore := nus.StoreSession()
errStore := nus.StoreSession()
//
//// FIXME If we have an error here, the session that gets created doesn't get immolated.
//// Immolation should happen in a deferred call instead.
//if errStore != nil {
// err = errors.New(fmt.Sprintf(
// "Register: could not register due to failed session save"+
// ": %s", errStore.Error()))
// globals.Log.ERROR.Printf(err.Error())
// return id.ZeroID, err
//}
//
//nus.Immolate()
//nus = nil
if errStore != nil {
err = errors.New(fmt.Sprintf(
"Register: could not register due to failed session save"+
": %s", errStore.Error()))
globals.Log.ERROR.Printf(err.Error())
return id.ZeroID, err
}
nus.Immolate()
nus = nil
return UID, err
}
......@@ -361,7 +390,7 @@ func RegisterForUserDiscovery(emailAddress string) error {
}
publicKey := user.TheSession.GetPublicKey()
publicKeyBytes := publicKey.LeftpadBytes(256)
publicKeyBytes := publicKey.GetKey().LeftpadBytes(256)
return bots.Register(valueType, emailAddress, publicKeyBytes)
}
......
......@@ -13,13 +13,13 @@ import (
"github.com/golang/protobuf/proto"
"gitlab.com/elixxir/client/cmixproto"
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/id"
"reflect"
"testing"
"time"
"reflect"
"gitlab.com/elixxir/client/parse"
)
func TestRegistrationGob(t *testing.T) {
......@@ -27,7 +27,7 @@ func TestRegistrationGob(t *testing.T) {
globals.InitStorage(&globals.RamStorage{}, "")
// populate a gob in the store
Register("UAV6IWD6", gwAddress, 1, false)
Register("UAV6IWD6", gwAddress, []string{"1"}, false)
// get the gob out of there again
sessionGob := globals.LocalStorage.Load()
......@@ -58,77 +58,25 @@ func VerifyRegisterGobUser(t *testing.T) {
}
func VerifyRegisterGobKeys(t *testing.T) {
if Session.GetPublicKey().Cmp(cyclic.NewIntFromBytes([]byte(
"this is not a real public key"))) != 0 {
t.Errorf("Public key was %v, expected %v",
string(Session.GetPublicKey().Bytes()),
"this is not a real public key")
}
h := sha256.New()
h.Write([]byte(string(30005)))
expectedTransmissionRecursiveKey := cyclic.NewIntFromBytes(h.Sum(nil))
if Session.GetKeys()[0].TransmissionKeys.Recursive.Cmp(
expectedTransmissionRecursiveKey) != 0 {
t.Errorf("Transmission recursive key was %v, expected %v",
Session.GetKeys()[0].TransmissionKeys.Recursive.Text(16),
expectedTransmissionRecursiveKey.Text(16))
}
h = sha256.New()
h.Write([]byte(string(20005)))
expectedTransmissionBaseKey := cyclic.NewIntFromBytes(h.Sum(nil))
if Session.GetKeys()[0].TransmissionKeys.Base.Cmp(
if Session.GetKeys()[0].TransmissionKey.Cmp(
expectedTransmissionBaseKey) != 0 {
t.Errorf("Transmission base key was %v, expected %v",
Session.GetKeys()[0].TransmissionKeys.Base.Text(16),
Session.GetKeys()[0].TransmissionKey.Text(16),
expectedTransmissionBaseKey.Text(16))
}
h = sha256.New()
h.Write([]byte(string(50005)))
expectedReceptionRecursiveKey := cyclic.NewIntFromBytes(h.Sum(nil))
if Session.GetKeys()[0].ReceptionKeys.Recursive.Cmp(
expectedReceptionRecursiveKey) != 0 {
t.Errorf("Reception recursive key was %v, expected %v",
Session.GetKeys()[0].ReceptionKeys.Recursive.Text(16),
expectedReceptionRecursiveKey.Text(16))
}
h = sha256.New()
h.Write([]byte(string(40005)))
expectedReceptionBaseKey := cyclic.NewIntFromBytes(h.Sum(nil))
if Session.GetKeys()[0].ReceptionKeys.Base.Cmp(
if Session.GetKeys()[0].ReceptionKey.Cmp(
expectedReceptionBaseKey) != 0 {
t.Errorf("Reception base key was %v, expected %v",
Session.GetKeys()[0].ReceptionKeys.Base.Text(16),
Session.GetKeys()[0].ReceptionKey.Text(16),
expectedReceptionBaseKey.Text(16))
}
if Session.GetKeys()[0].ReturnKeys.Recursive == nil {
t.Logf("warning: return recursive key is nil")
} else {
t.Logf("return recursive key is not nil. " +
"update gob test to ensure that it's serialized to storage, " +
"if needed")
}
if Session.GetKeys()[0].ReturnKeys.Base == nil {
t.Logf("warning: return base key is nil")
} else {
t.Logf("return base key is not nil. " +
"update gob test to ensure that it's serialized to storage, " +
"if needed")
}
if Session.GetKeys()[0].ReceiptKeys.Recursive == nil {
t.Logf("warning: receipt recursive key is nil")
} else {
t.Logf("receipt recursive key is not nil. " +
"update gob test to ensure that it's serialized to storage, " +
"if needed")
}
if Session.GetKeys()[0].ReceiptKeys.Base == nil {
t.Logf("warning: receipt recursive key is nil")
} else {
t.Logf("receipt base key is not nil. " +
"update gob test to ensure that it's serialized to storage, " +
"if needed")
}
}
// Make sure that a formatted text message can deserialize to the text
......
......@@ -64,7 +64,7 @@ func TestRegister(t *testing.T) {
registrationCode := "UAV6IWD6"
d := DummyStorage{Location: "Blah", LastSave: []byte{'a', 'b', 'c'}}
err := InitClient(&d, "hello")
regRes, err := Register(registrationCode, gwAddress, 1, false)
regRes, err := Register(registrationCode, gwAddress, []string{"1", "2", "3"}, false)
if err != nil {
t.Errorf("Registration failed: %s", err.Error())
}
......@@ -83,7 +83,7 @@ func TestRegisterBadNumNodes(t *testing.T) {
registrationCode := "UAV6IWD6"
d := DummyStorage{Location: "Blah", LastSave: []byte{'a', 'b', 'c'}}
err := InitClient(&d, "hello")
_, err = Register(registrationCode, gwAddress, 0, false)
_, err = Register(registrationCode, gwAddress, []string{"1", "2", "3"}, false)
if err == nil {
t.Errorf("Registration worked with bad numnodes! %s", err.Error())
}
......@@ -99,7 +99,7 @@ func TestRegisterBadHUID(t *testing.T) {
registrationCode := "OIF3OJ6I"
d := DummyStorage{Location: "Blah", LastSave: []byte{'a', 'b', 'c'}}
err := InitClient(&d, "hello")
_, err = Register(registrationCode, gwAddress, 1, false)
_, err = Register(registrationCode, gwAddress, []string{"1", "2", "3"}, false)
if err == nil {
t.Error("Registration worked with bad registration code!")
}
......@@ -117,7 +117,7 @@ func TestRegisterDeletedUser(t *testing.T) {
err := InitClient(&d, "hello")
tempUser, _ := user.Users.GetUser(id.NewUserFromUint(5, t))
user.Users.DeleteUser(id.NewUserFromUint(5, t))
_, err = Register(registrationCode, gwAddress, 1, false)
_, err = Register(registrationCode, gwAddress, []string{"1", "2", "3"}, false)
if err == nil {
t.Errorf("Registration worked with a deleted user: %s",
err.Error())
......@@ -131,8 +131,8 @@ func SetNulKeys() {
// FIXME: Why doesn't crypto panic when these keys are empty?
keys := user.TheSession.GetKeys()
for i := range keys {
keys[i].TransmissionKeys.Base = cyclic.NewInt(1)
keys[i].TransmissionKeys.Recursive = cyclic.NewInt(1)
keys[i].TransmissionKey = cyclic.NewInt(1)
keys[i].TransmissionKey = cyclic.NewInt(1)
}
}
......@@ -145,7 +145,7 @@ func TestSend(t *testing.T) {
d := DummyStorage{Location: "Blah", LastSave: []byte{'a', 'b', 'c'}}
err := InitClient(&d, "hello")
registrationCode := "UAV6IWD6"
userID, err := Register(registrationCode, gwAddress, 1, false)
userID, err := Register(registrationCode, gwAddress, []string{"1", "2", "3"}, false)
session, err2 := Login(userID, gwAddress, "")
SetNulKeys()
......
......@@ -17,6 +17,7 @@ import (
"gitlab.com/elixxir/crypto/certs"
"gitlab.com/elixxir/primitives/id"
"io"
"strings"
)
// Copy of the storage interface.
......@@ -110,17 +111,19 @@ func InitClient(storage Storage, loc string) error {
// Registers user and returns the User ID. Returns null if registration fails.
// registrationCode is a one time use string
// registrationAddr is the address of the registration server
// gwAddresses is a list of gateway addresses
// gwAddresses is CSV of gateway addresses
// numNodes is the number of nodes in the system
func Register(registrationCode, registrationAddr string, gwAddresses []string,
func Register(registrationCode, registrationAddr string, gwAddressesList string,
mint bool) ([]byte, error) {
if len(gwAddresses) < 1 {
gwList := strings.Split(gwAddressesList, ",")
if len(gwList) < 1 {
return id.ZeroID[:], errors.New("invalid number of nodes")
}
UID, err := api.Register(registrationCode, registrationAddr,
gwAddresses, mint)
gwList, mint)
if err != nil {
return id.ZeroID[:], err
......
......@@ -130,7 +130,7 @@ func TestRegister(t *testing.T) {
d := api.DummyStorage{Location: "Blah", LastSave: []byte{'a', 'b', 'c'}}
err := InitClient(&d, "hello")
regRes, err := Register(registrationCode, gwAddress, 1, false)
regRes, err := Register(registrationCode, gwAddress, "1,2,3", false)
if err != nil {
t.Errorf("Registration failed: %s", err.Error())
}
......@@ -149,7 +149,7 @@ func TestRegisterBadNumNodes(t *testing.T) {
d := api.DummyStorage{Location: "Blah", LastSave: []byte{'a', 'b', 'c'}}
err := InitClient(&d, "hello")
_, err = Register(registrationCode, gwAddress, 0, false)
_, err = Register(registrationCode, gwAddress, "1,2,3", false)
if err == nil {
t.Errorf("Registration worked with bad numnodes! %s", err.Error())
}
......@@ -165,7 +165,7 @@ func TestLoginLogout(t *testing.T) {
d := api.DummyStorage{Location: "Blah", LastSave: []byte{'a', 'b', 'c'}}
err := InitClient(&d, "hello")
regRes, err := Register(registrationCode, gwAddress, 1, false)
regRes, err := Register(registrationCode, gwAddress, "1,2,3", false)
loginRes, err2 := Login(regRes, gwAddress, "")
if err2 != nil {
t.Errorf("Login failed: %s", err.Error())
......@@ -194,7 +194,7 @@ func TestDisableBlockingTransmission(t *testing.T) {
func TestSetRateLimiting(t *testing.T) {
u, _ := user.Users.GetUser(id.NewUserFromUint(1, t))
nk := make([]user.NodeKeys, 1)
user.TheSession = user.NewSession(u, gwAddress, nk, nil)
user.TheSession = user.NewSession(u, gwAddress, nk, nil, nil)
if io.TransmitDelay != time.Duration(1000)*time.Millisecond {
t.Errorf("SetRateLimiting not intilized properly")
}
......
......@@ -27,6 +27,7 @@ import (
"log"
"math/big"
"os"
"strings"
"sync/atomic"
"time"
)
......@@ -119,7 +120,8 @@ func sessionInitialization() {
// to allow testing with IDs that are long enough to exercise more than
// 64 bits
regCode := new(id.User).SetUints(&[4]uint64{0, 0, 0, userId}).RegistrationCode()
_, err := bindings.Register(regCode, "", gwAddresses, mint)
_, err := bindings.Register(regCode, "", strings.Join(gwAddresses, ","), mint)
if err != nil {
fmt.Printf("Could Not Register User: %s\n", err.Error())
return
......
......@@ -58,14 +58,10 @@ func setup(t *testing.T) {
// this makes it possible for the reception key to decrypt the
// transmission key without spinning up a whole server to decouple them
nk[i].TransmissionKeys.Base = cyclic.NewInt(1)
nk[i].TransmissionKeys.Recursive = cyclic.NewIntFromString(
"ad333f4ccea0ccf2afcab6c1b9aa2384e561aee970046e39b7f2a78c3942a251", 16)
nk[i].ReceptionKeys.Base = cyclic.NewInt(1)
nk[i].ReceptionKeys.Recursive = grp.Inverse(
nk[i].TransmissionKeys.Recursive, cyclic.NewInt(1))
nk[i].TransmissionKey = cyclic.NewInt(1)
nk[i].ReceptionKey = cyclic.NewInt(1)
}
user.TheSession = user.NewSession(u, "", nk, nil)
user.TheSession = user.NewSession(u, "", nk, nil, nil)
}
func TestEncryptDecrypt(t *testing.T) {
......@@ -83,7 +79,7 @@ func TestEncryptDecrypt(t *testing.T) {
// Generate a compound encryption key
encryptionKey := cyclic.NewInt(1)
for _, key := range user.TheSession.GetKeys() {
baseKey := key.TransmissionKeys.Base
baseKey := key.TransmissionKey
partialEncryptionKey := cmix.NewEncryptionKey(salt, baseKey, Grp)
Grp.Mul(encryptionKey, encryptionKey, partialEncryptionKey)
//TODO: Add KMAC generation here
......
......@@ -11,7 +11,7 @@ import (
"encoding/hex"
"gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id"
"math/rand"
......@@ -21,9 +21,14 @@ import (
func TestCollator_AddMessage(t *testing.T) {
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
user.TheSession = user.NewSession(&user.User{id.NewUserFromUint(8, t),
"test"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, publicKey, privateKey)
collator := &collator{
pendingMessages: make(map[PendingMessageKey]*multiPartMessage),
......@@ -70,9 +75,14 @@ func TestCollator_AddMessage(t *testing.T) {
func TestCollator_AddMessage_Timeout(t *testing.T) {
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
user.TheSession = user.NewSession(&user.User{id.NewUserFromUint(8, t),
"test"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, publicKey, privateKey)
collator := &collator{
pendingMessages: make(map[PendingMessageKey]*multiPartMessage),
......
......@@ -127,7 +127,7 @@ func send(senderID *id.User, message *format.Message) error {
// Generate a compound encryption key
encryptionKey := cyclic.NewInt(1)
for _, key := range user.TheSession.GetKeys() {
baseKey := key.TransmissionKeys.Base
baseKey := key.TransmissionKey
partialEncryptionKey := cmix.NewEncryptionKey(salt, baseKey, crypto.Grp)
crypto.Grp.Mul(encryptionKey, partialEncryptionKey, encryptionKey)
//TODO: Add KMAC generation here
......@@ -240,7 +240,7 @@ func (m *messaging) receiveMessagesFromGateway(
salt := newMessage.Salt
decryptionKey := cyclic.NewInt(1)
for _, key := range user.TheSession.GetKeys() {
baseKey := key.ReceptionKeys.Base
baseKey := key.ReceptionKey
partialDecryptionKey := cmix.NewDecryptionKey(salt, baseKey,
crypto.Grp)
crypto.Grp.Mul(decryptionKey, partialDecryptionKey, decryptionKey)
......
......@@ -11,7 +11,7 @@ import (
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/coin"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/primitives/id"
"math/rand"
"os"
......@@ -24,8 +24,14 @@ func TestCreateOrderedStorage_New(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
userID := id.NewUserFromUint(1, t)
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
publicKey, privateKey)
// show that the ordered list does not exist
key := "TestOrderedList"
......@@ -70,8 +76,13 @@ func TestCreateOrderedStorage_Load(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
userID := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
// show that the ordered list does not exist
key := "TestOrderedList"
......@@ -118,8 +129,13 @@ func TestOrderedCoinStorage_Value(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
userID := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng1 := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng1, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng1)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
src := rand.NewSource(42)
rng := rand.New(src)
......@@ -142,8 +158,13 @@ func TestOrderedCoinStorage_Add_Empty(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
userID := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
cs, err := coin.NewSleeve(69)
......@@ -165,9 +186,13 @@ func TestOrderedCoinStorage_Add_Multi(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
userID := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
ocs := OrderedCoinStorage{&[]coin.Sleeve{}, 0, s}
unorderdValues := []uint64{100, 13, 44}
......@@ -210,8 +235,13 @@ func TestOrderedCoinStorage_Add_Save(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
userID := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{userID, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
// show that the ordered list does not exist
key := "TestOrderedList"
......@@ -249,8 +279,13 @@ func TestOrderedCoinStorage_Get(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -289,7 +324,13 @@ func TestOrderedCoinStorage_Pop(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -328,8 +369,13 @@ func TestOrderedCoinStorage_Pop_Save(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -386,8 +432,13 @@ func TestOrderedCoinStorage_Fund_Insufficient(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -429,8 +480,13 @@ func TestOrderedCoinStorage_Fund_Single_Exact(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -473,8 +529,13 @@ func TestOrderedCoinStorage_Fund_Multi_Exact(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -529,8 +590,13 @@ func TestOrderedCoinStorage_Fund_Multi_Exact_Split(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -585,8 +651,13 @@ func TestOrderedCoinStorage_Fund_Organization(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -626,8 +697,13 @@ func TestOrderedCoinStorage_Fund_Multi_Exact_Split_Change(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
key := "TestOrderedList"
......@@ -690,8 +766,13 @@ func TestOrderedStorage_FileLoading(t *testing.T) {
}
globals.InitStorage(&globals.DefaultStorage{}, storagePath+filename)
uid := id.NewUserFromUint(1, t)
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{},
cyclic.NewInt(0))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{uid, "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
// show that the ordered list does not exist
key := "TestOrderedList"
......
......@@ -12,7 +12,7 @@ import (
"gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/coin"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/primitives/id"
"math"
"math/rand"
......@@ -25,9 +25,15 @@ import (
func TestCreateTransactionList_New(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, publicKey, privateKey)
// show that the ordered list does not exist
key := "TestTransactionList"
......@@ -72,8 +78,15 @@ func TestCreateTransactionList_New(t *testing.T) {
func TestCreateTransactionList_Load(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
// show that the transaction list does not exist
key := "TestTransactionList"
......@@ -116,8 +129,15 @@ func TestTransactionList_Value(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng1 := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng1, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng1)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
src := rand.NewSource(42)
rng := rand.New(src)
......@@ -138,8 +158,15 @@ func TestTransactionList_Value(t *testing.T) {
func TestTransactionList_Upsert_Empty(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
tMap := make(map[parse.MessageHash]*Transaction)
......@@ -164,8 +191,15 @@ func TestTransactionList_Upsert_Empty(t *testing.T) {
func TestTransactionList_Upsert_Multi(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
t1 := Transaction{Memo: "1"}
t1Hash := parse.Message{
......@@ -198,8 +232,15 @@ func TestTransactionList_Upsert_Multi(t *testing.T) {
func TestTransactionList_Upsert_Save(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
key := "TestTransactionList"
......@@ -241,8 +282,15 @@ func TestTransactionList_Upsert_Save(t *testing.T) {
func TestTransactionList_Get(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
t1 := Transaction{Memo: "1"}
t1Hash := parse.Message{
......@@ -286,8 +334,15 @@ func TestTransactionList_Get(t *testing.T) {
func TestTransactionList_Pop(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
t1 := Transaction{Memo: "1"}
t1Hash := parse.Message{
......@@ -331,8 +386,15 @@ func TestTransactionList_Pop(t *testing.T) {
func TestTransactionList_Pop_Invalid(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
t1 := Transaction{Memo: "1"}
t1Hash := parse.Message{
......@@ -365,8 +427,15 @@ func TestTransactionList_Pop_Invalid(t *testing.T) {
func TestTransactionList_Pop_Save(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
key := "TestTransactionList"
......@@ -430,8 +499,16 @@ func TestTransactionList_GetKeysByTimestampDescending(t *testing.T) {
// populate a transaction list with some items
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "",
[]user.NodeKeys{}, publicKey, privateKey)
transactionMap := make(map[parse.MessageHash]*Transaction)
transactions := TransactionList{
transactionMap: &transactionMap,
......
......@@ -17,8 +17,9 @@ import (
"gitlab.com/elixxir/client/switchboard"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/coin"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/primitives/id"
"math/rand"
"reflect"
"testing"
"time"
......@@ -32,9 +33,15 @@ func TestWallet_registerInvoice(t *testing.T) {
value := uint64(85)
globals.LocalStorage = nil
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
globals.InitStorage(&globals.RamStorage{}, "")
s := user.NewSession(&user.User{User: payee, Nick: "Taxman McGee"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, publicKey, privateKey)
or, err := createTransactionList(OutboundRequestsTag, s)
if err != nil {
......@@ -86,8 +93,14 @@ func TestWallet_registerInvoice(t *testing.T) {
func TestCreateWallet(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: id.NewUserFromUint(1, t),
Nick: "test"}, "", []user.NodeKeys{}, cyclic.NewInt(0))
Nick: "test"}, "", []user.NodeKeys{}, publicKey, privateKey)
_, err := CreateWallet(s, false)
......@@ -137,8 +150,14 @@ func TestWallet_Invoice(t *testing.T) {
// Set up the wallet and its storage
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
s := user.NewSession(&user.User{User: payee, Nick: "Taxman McGee"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, publicKey, privateKey)
or, err := createTransactionList(OutboundRequestsTag, s)
if err != nil {
......@@ -319,12 +338,12 @@ func (ms *MockSession) GetKeys() []user.NodeKeys {
return nil
}
func (ms *MockSession) GetPrivateKey() *cyclic.Int {
func (ms *MockSession) GetPrivateKey() *signature.DSAPrivateKey {
*ms = true
return nil
}
func (ms *MockSession) GetPublicKey() *cyclic.Int {
func (ms *MockSession) GetPublicKey() *signature.DSAPublicKey {
*ms = true
return nil
}
......@@ -379,7 +398,7 @@ func TestInvoiceListener_Hear(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
s := user.NewSession(&user.User{User: payer, Nick: "CEO MF DOOM"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, nil, nil)
ir, err := createTransactionList(InboundRequestsTag, s)
if err != nil {
......@@ -467,7 +486,7 @@ func TestWallet_Invoice_Error(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
s := user.NewSession(&user.User{User: payee, Nick: "Taxman McGee"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, nil, nil)
or, err := createTransactionList(OutboundRequestsTag, s)
if err != nil {
......@@ -511,7 +530,7 @@ func TestResponseListener_Hear(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
s := user.NewSession(&user.User{User: payer, Nick: "Darth Icky"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, nil, nil)
walletAmount := uint64(8970)
paymentAmount := uint64(962)
......@@ -637,7 +656,7 @@ func TestResponseListener_Hear_Failure(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
s := user.NewSession(&user.User{User: payer, Nick: "Darth Icky"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, nil, nil)
walletAmount := uint64(8970)
paymentAmount := uint64(962)
......@@ -749,7 +768,7 @@ func TestWallet_Pay_NoChange(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
s := user.NewSession(&user.User{User: payer, Nick: "Darth Icky"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, nil, nil)
paymentAmount := uint64(5008)
walletAmount := uint64(5008)
......@@ -842,7 +861,7 @@ func TestWallet_Pay_YesChange(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
s := user.NewSession(&user.User{User: payer, Nick: "Darth Icky"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, nil, nil)
paymentAmount := uint64(2611)
walletAmount := uint64(5008)
......@@ -968,7 +987,7 @@ func TestReceiptListener_Hear(t *testing.T) {
globals.LocalStorage = nil
globals.InitStorage(&globals.RamStorage{}, "")
s := user.NewSession(&user.User{User: payer, Nick: "Darth Icky"}, "",
[]user.NodeKeys{}, cyclic.NewInt(0))
[]user.NodeKeys{}, nil, nil)
walletAmount := uint64(8970)
paymentAmount := uint64(1234)
......
......@@ -11,13 +11,14 @@ import (
"encoding/gob"
"errors"
"fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/primitives/id"
"math/rand"
"sync"
"time"
jww "github.com/spf13/jwalterweatherman"
)
// Errors
......@@ -33,8 +34,8 @@ type Session interface {
GetGWAddress() string
SetGWAddress(addr string)
GetKeys() []NodeKeys
GetPrivateKey() *cyclic.Int
GetPublicKey() *cyclic.Int
GetPrivateKey() *signature.DSAPrivateKey
GetPublicKey() *signature.DSAPublicKey
GetLastMessageID() string
SetLastMessageID(id string)
StoreSession() error
......@@ -48,26 +49,19 @@ type Session interface {
}
type NodeKeys struct {
TransmissionKeys RatchetKey
ReceptionKeys RatchetKey
ReceiptKeys RatchetKey
ReturnKeys RatchetKey
}
type RatchetKey struct {
Base *cyclic.Int
Recursive *cyclic.Int
TransmissionKey *cyclic.Int
ReceptionKey *cyclic.Int
}
// Creates a new Session interface for registration
func NewSession(u *User, GatewayAddr string, nk []NodeKeys, publicKey *cyclic.Int) Session {
func NewSession(u *User, GatewayAddr string, nk []NodeKeys, publicKey *signature.DSAPublicKey, privateKey *signature.DSAPrivateKey) Session {
// With an underlying Session data structure
return Session(&SessionObj{
CurrentUser: u,
GWAddress: GatewayAddr, // FIXME: don't store this here
Keys: nk,
PrivateKey: cyclic.NewMaxInt(),
PrivateKey: privateKey,
PublicKey: publicKey,
InterfaceMap: make(map[string]interface{}),
})
......@@ -136,8 +130,8 @@ type SessionObj struct {
GWAddress string
Keys []NodeKeys
PrivateKey *cyclic.Int
PublicKey *cyclic.Int
PrivateKey *signature.DSAPrivateKey
PublicKey *signature.DSAPublicKey
// Last received message ID. Check messages after this on the gateway.
LastMessageID string
......@@ -166,13 +160,13 @@ func (s *SessionObj) GetKeys() []NodeKeys {
return s.Keys
}
func (s *SessionObj) GetPrivateKey() *cyclic.Int {
func (s *SessionObj) GetPrivateKey() *signature.DSAPrivateKey {
s.LockStorage()
defer s.UnlockStorage()
return s.PrivateKey
}
func (s *SessionObj) GetPublicKey() *cyclic.Int {
func (s *SessionObj) GetPublicKey() *signature.DSAPublicKey {
s.LockStorage()
defer s.UnlockStorage()
return s.PublicKey
......@@ -255,14 +249,6 @@ func (s *SessionObj) Immolate() error {
s.GWAddress = burntString(len(s.GWAddress))
s.GWAddress = ""
clearCyclicInt(s.PrivateKey)
clearCyclicInt(s.PublicKey)
for i := 0; i < len(s.Keys); i++ {
clearRatchetKeys(&s.Keys[i].TransmissionKeys)
clearRatchetKeys(&s.Keys[i].ReceptionKeys)
}
TheSession = nil
s.UnlockStorage()
......@@ -336,11 +322,6 @@ func clearCyclicInt(c *cyclic.Int) {
c.SetInt64(0)
}
func clearRatchetKeys(r *RatchetKey) {
clearCyclicInt(r.Base)
clearCyclicInt(r.Recursive)
}
// FIXME Shouldn't we just be putting pseudorandom bytes in to obscure the mem?
func burntString(length int) string {
......
......@@ -10,7 +10,10 @@ import (
"crypto/sha256"
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/primitives/id"
"math/rand"
"reflect"
"testing"
)
......@@ -31,10 +34,8 @@ func TestUserSession(t *testing.T) {
keys := make([]NodeKeys, 1)
keys[0] = NodeKeys{
TransmissionKeys: RatchetKey{cyclic.NewInt(2), cyclic.NewInt(2)},
ReceptionKeys: RatchetKey{cyclic.NewInt(2), cyclic.NewInt(2)},
ReceiptKeys: RatchetKey{cyclic.NewInt(2), cyclic.NewInt(2)},
ReturnKeys: RatchetKey{cyclic.NewInt(2), cyclic.NewInt(2)},
TransmissionKey: cyclic.NewInt(2),
ReceptionKey: cyclic.NewInt(2),
}
err := globals.InitStorage(&globals.RamStorage{}, "")
......@@ -43,10 +44,12 @@ func TestUserSession(t *testing.T) {
t.Errorf("User Session: Local storage could not be created: %s", err.Error())
}
//Ask Ben if there should be a Node Address here!
ses := NewSession(u, "abc", keys, cyclic.NewInt(2))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
ses := NewSession(u, "abc", keys, publicKey, privateKey)
ses.(*SessionObj).PrivateKey.SetInt64(2)
ses.SetLastMessageID("totally unique ID")
err = ses.StoreSession()
......@@ -124,32 +127,16 @@ func TestUserSession(t *testing.T) {
for i := 0; i < len(TheSession.GetKeys()); i++ {
if TheSession.GetPublicKey().Cmp(cyclic.NewInt(2)) != 0 {
if !reflect.DeepEqual(*TheSession.GetPublicKey(), *publicKey) {
t.Errorf("Error: Public key not set correctly!")
} else if TheSession.GetKeys()[i].ReceiptKeys.Base.Cmp(cyclic.
} else if !reflect.DeepEqual(*TheSession.GetPrivateKey(), *privateKey) {
t.Errorf("Error: Private key not set correctly!")
} else if TheSession.GetKeys()[i].ReceptionKey.Cmp(cyclic.
NewInt(2)) != 0 {
t.Errorf("Error: Receipt base key not set correctly!")
} else if TheSession.GetKeys()[i].ReceiptKeys.Recursive.Cmp(cyclic.
t.Errorf("Error: Reception key not set correctly!")
} else if TheSession.GetKeys()[i].TransmissionKey.Cmp(cyclic.
NewInt(2)) != 0 {
t.Errorf("Error: Receipt base key not set correctly!")
} else if TheSession.GetKeys()[i].ReceptionKeys.Base.Cmp(cyclic.
NewInt(2)) != 0 {
t.Errorf("Error: Receipt base key not set correctly!")
} else if TheSession.GetKeys()[i].ReceptionKeys.Recursive.Cmp(
cyclic.NewInt(2)) != 0 {
t.Errorf("Error: Receipt base key not set correctly!")
} else if TheSession.GetKeys()[i].ReturnKeys.Base.Cmp(cyclic.
NewInt(2)) != 0 {
t.Errorf("Error: Receipt base key not set correctly!")
} else if TheSession.GetKeys()[i].ReturnKeys.Recursive.Cmp(cyclic.
NewInt(2)) != 0 {
t.Errorf("Error: Receipt base key not set correctly!")
} else if TheSession.GetKeys()[i].TransmissionKeys.Base.Cmp(cyclic.
NewInt(2)) != 0 {
t.Errorf("Error: Receipt base key not set correctly!")
} else if TheSession.GetKeys()[i].TransmissionKeys.Recursive.Cmp(
cyclic.NewInt(2)) != 0 {
t.Errorf("Error: Receipt base key not set correctly!")
t.Errorf("Error: Transmission key not set correctly!")
}
pass++
......@@ -235,15 +222,43 @@ func TestGetPubKey(t *testing.T) {
keys := make([]NodeKeys, 1)
keys[0] = NodeKeys{
TransmissionKeys: RatchetKey{cyclic.NewInt(2), cyclic.NewInt(2)},
ReceptionKeys: RatchetKey{cyclic.NewInt(2), cyclic.NewInt(2)},
ReceiptKeys: RatchetKey{cyclic.NewInt(2), cyclic.NewInt(2)},
ReturnKeys: RatchetKey{cyclic.NewInt(2), cyclic.NewInt(2)},
TransmissionKey: cyclic.NewInt(2),
ReceptionKey: cyclic.NewInt(2),
}
ses := NewSession(u, "abc", keys, cyclic.NewInt(2))
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
ses := NewSession(u, "abc", keys, publicKey, privateKey)
pubKey := ses.GetPublicKey()
if pubKey.Cmp(cyclic.NewInt(2)) != 0 {
t.Errorf("Public key is not set correctly!")
if !reflect.DeepEqual(pubKey, publicKey) {
t.Errorf("Public key not returned correctly!")
}
}
func TestGetPrivKey(t *testing.T) {
u := new(User)
UID := id.NewUserFromUint(1, t)
u.User = UID
u.Nick = "Mario"
keys := make([]NodeKeys, 1)
keys[0] = NodeKeys{
TransmissionKey: cyclic.NewInt(2),
ReceptionKey: cyclic.NewInt(2),
}
rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L3072N256)
privateKey := params.PrivateKeyGen(rng)
publicKey := privateKey.PublicKeyGen()
ses := NewSession(u, "abc", keys, publicKey, privateKey)
privKey := ses.GetPrivateKey()
if !reflect.DeepEqual(*privKey, *privateKey) {
t.Errorf("Private key is not returned correctly!")
}
}
......@@ -70,16 +70,10 @@ func newRegistry() Registry {
// TODO We need a better way to generate base/recursive keys
h := sha256.New()
h.Write([]byte(string(20000 + i)))
k.TransmissionKeys.Base = cyclic.NewIntFromBytes(h.Sum(nil))
h = sha256.New()
h.Write([]byte(string(30000 + i)))
k.TransmissionKeys.Recursive = cyclic.NewIntFromBytes(h.Sum(nil))
k.TransmissionKey = cyclic.NewIntFromBytes(h.Sum(nil))
h = sha256.New()
h.Write([]byte(string(40000 + i)))
k.ReceptionKeys.Base = cyclic.NewIntFromBytes(h.Sum(nil))
h = sha256.New()
h.Write([]byte(string(50000 + i)))
k.ReceptionKeys.Recursive = cyclic.NewIntFromBytes(h.Sum(nil))
k.ReceptionKey = cyclic.NewIntFromBytes(h.Sum(nil))
// Add user to collection and lookup table
uc[*t.User] = t
......
......@@ -73,35 +73,21 @@ func TestUserRegistry(t *testing.T) {
h := sha256.New()
h.Write([]byte(string(20001)))
key := cyclic.NewIntFromBytes(h.Sum(nil))
if keys.TransmissionKeys.Base.Text(16) != key.Text(16) {
if keys.TransmissionKey.Text(16) != key.Text(16) {
t.Errorf("LookupKeys returned an incorrect key. "+
"Expected:%v \nActual%v", key.Text(16),
keys.TransmissionKeys.Base.Text(16))
}
h = sha256.New()
h.Write([]byte(string(30001)))
key = cyclic.NewIntFromBytes(h.Sum(nil))
if keys.TransmissionKeys.Recursive.Text(16) != key.Text(16) {
t.Errorf("LookupKeys returned an incorrect key. "+
"Expected:%v \nActual%v", key.Text(16),
keys.TransmissionKeys.Recursive.Text(16))
keys.TransmissionKey.Text(16))
}
h = sha256.New()
h.Write([]byte(string(40001)))
key = cyclic.NewIntFromBytes(h.Sum(nil))
if keys.ReceptionKeys.Base.Text(16) != key.Text(16) {
if keys.ReceptionKey.Text(16) != key.Text(16) {
t.Errorf("LookupKeys returned an incorrect key. "+
"Expected:%v \nActual%v", key.Text(16),
keys.ReceptionKeys.Base.Text(16))
}
h = sha256.New()
h.Write([]byte(string(50001)))
key = cyclic.NewIntFromBytes(h.Sum(nil))
if keys.ReceptionKeys.Recursive.Text(16) != key.Text(16) {
t.Errorf("LookupKeys returned an incorrect key. "+
"Expected:%v \nActual%v", key.Text(16),
keys.ReceptionKeys.Recursive.Text(16))
keys.ReceptionKey.Text(16))
}
// Test delete user
Users.DeleteUser(id.NewUserFromUint(2, t))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment