Skip to content
Snippets Groups Projects
Commit 78e268b4 authored by Jonah Husson's avatar Jonah Husson
Browse files

Merge branch 'register-refactor' into 'RSARegistration'

Simple Registration (Client)

See merge request !174
parents 616c5f86 40fab57c
Branches
Tags
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package api package api
import ( import (
"crypto"
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
...@@ -29,7 +30,6 @@ import ( ...@@ -29,7 +30,6 @@ import (
"gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/hash"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/registration" "gitlab.com/elixxir/crypto/registration"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/circuit" "gitlab.com/elixxir/primitives/circuit"
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
...@@ -48,6 +48,8 @@ type Client struct { ...@@ -48,6 +48,8 @@ type Client struct {
topology *circuit.Circuit topology *circuit.Circuit
} }
var PermissioningAddrID = "registration"
// Populates a text message and returns its wire representation // Populates a text message and returns its wire representation
// TODO support multi-type messages or telling if a message is too long? // TODO support multi-type messages or telling if a message is too long?
func FormatTextMessage(message string) []byte { func FormatTextMessage(message string) []byte {
...@@ -182,7 +184,7 @@ func (cl *Client) Connect() error { ...@@ -182,7 +184,7 @@ func (cl *Client) Connect() error {
globals.Log.ERROR.Printf("failed to read certificate from %s: %+v", cl.ndf.Registration.TlsCertificate, err) globals.Log.ERROR.Printf("failed to read certificate from %s: %+v", cl.ndf.Registration.TlsCertificate, err)
} }
} }
addr := io.ConnAddr("registration") addr := io.ConnAddr(PermissioningAddrID)
err = (cl.comm).(*io.Messaging).Comms.ConnectToRegistration(addr, cl.ndf.Registration.Address, cert) err = (cl.comm).(*io.Messaging).Comms.ConnectToRegistration(addr, cl.ndf.Registration.Address, cert)
if err != nil { if err != nil {
globals.Log.ERROR.Printf("Failed connecting to permissioning: %+v", err) globals.Log.ERROR.Printf("Failed connecting to permissioning: %+v", err)
...@@ -200,70 +202,43 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (* ...@@ -200,70 +202,43 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (*
var u *user.User var u *user.User
var UID *id.User var UID *id.User
largeIntBits := 16
cmixGrp := cyclic.NewGroup( cmixGrp := cyclic.NewGroup(
large.NewIntFromString(cl.ndf.CMIX.Prime, 16), large.NewIntFromString(cl.ndf.CMIX.Prime, largeIntBits),
large.NewIntFromString(cl.ndf.CMIX.Generator, 16), large.NewIntFromString(cl.ndf.CMIX.Generator, largeIntBits),
large.NewIntFromString(cl.ndf.CMIX.SmallPrime, 16)) large.NewIntFromString(cl.ndf.CMIX.SmallPrime, largeIntBits))
e2eGrp := cyclic.NewGroup( e2eGrp := cyclic.NewGroup(
large.NewIntFromString(cl.ndf.E2E.Prime, 16), large.NewIntFromString(cl.ndf.E2E.Prime, largeIntBits),
large.NewIntFromString(cl.ndf.E2E.Generator, 16), large.NewIntFromString(cl.ndf.E2E.Generator, largeIntBits),
large.NewIntFromString(cl.ndf.E2E.SmallPrime, 16)) large.NewIntFromString(cl.ndf.E2E.SmallPrime, largeIntBits))
// Make CMIX keys array // Make CMIX keys array
nk := make(map[id.Node]user.NodeKeys) nk := make(map[id.Node]user.NodeKeys)
// Generate DSA keypair even for precanned users as it will probably // GENERATE CLIENT RSA KEYS
// be needed for the new UDB flow privateKeyRSA, err := rsa.GenerateKey(rand.Reader, rsa.DefaultRSABitLen)
params := signature.CustomDSAParams( if err != nil {
cmixGrp.GetP(), return nil, err
cmixGrp.GetQ(), }
cmixGrp.GetG()) publicKeyRSA := privateKeyRSA.GetPublic()
privateKey := params.PrivateKeyGen(rand.Reader)
publicKey := privateKey.PublicKeyGen()
fmt.Println("gened private keys") privateKeyDH := cmixGrp.RandomCoprime(cmixGrp.NewMaxInt())
publicKeyDH := cmixGrp.ExpG(privateKeyDH, cmixGrp.NewMaxInt())
// Handle precanned registration // Handle precanned registration
if preCan { if preCan {
var successLook bool globals.Log.INFO.Printf("Registering precanned user")
globals.Log.DEBUG.Printf("Registering precanned user") u, UID, nk, err = cl.precannedRegister(registrationCode, nick, nk)
UID, successLook = user.Users.LookupUser(registrationCode) if err != nil {
globals.Log.ERROR.Printf("Unable to complete precanned registration: %+v", err)
fmt.Println("UID:", UID, "success:", successLook)
if !successLook {
globals.Log.ERROR.Printf("Register: HUID does not match")
return id.ZeroID, errors.New("could not register due to invalid HUID")
}
var successGet bool
u, successGet = user.Users.GetUser(UID)
if !successGet {
globals.Log.ERROR.Printf("Register: ID lookup failed")
err = errors.New("could not register due to ID lookup failure")
return id.ZeroID, err
}
if nick != "" {
u.Nick = nick
}
nodekeys, successKeys := user.Users.LookupKeys(u.User)
if !successKeys {
globals.Log.ERROR.Printf("Register: could not find user keys")
err = errors.New("could not register due to missing user keys")
return id.ZeroID, err return id.ZeroID, err
} }
for i := 0; i < len(cl.ndf.Gateways); i++ {
nk[*cl.topology.GetNodeAtIndex(i)] = *nodekeys
}
} else { } else {
saltSize := 256
// Generate salt for UserID // Generate salt for UserID
salt := make([]byte, 256) salt := make([]byte, saltSize)
_, err = csprng.NewSystemRNG().Read(salt) _, err = csprng.NewSystemRNG().Read(salt)
if err != nil { if err != nil {
globals.Log.ERROR.Printf("Register: Unable to generate salt! %s", err) globals.Log.ERROR.Printf("Register: Unable to generate salt! %s", err)
...@@ -271,131 +246,58 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (* ...@@ -271,131 +246,58 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (*
} }
// Generate UserID by hashing salt and public key // Generate UserID by hashing salt and public key
UID = registration.GenUserID(publicKey, salt) UID = registration.GenUserID(publicKeyRSA, salt)
// Keep track of Server public keys provided at end of registration
var serverPublicKeys []*signature.DSAPublicKey
// Initialized response from Registration Server // Initialized response from Registration Server
regHash, regR, regS := make([]byte, 0), make([]byte, 0), make([]byte, 0) regHash := make([]byte, 0)
// If Registration Server is specified, contact it // If Registration Server is specified, contact it
// Only if registrationCode is set // Only if registrationCode is set
globals.Log.INFO.Println("Register: Contacting registration server")
if cl.ndf.Registration.Address != "" && registrationCode != "" { if cl.ndf.Registration.Address != "" && registrationCode != "" {
// Send registration code and public key to RegistrationServer regHash, err = cl.sendRegistrationMessage(registrationCode, publicKeyRSA)
response, err := (cl.comm).(*io.Messaging).Comms.
SendRegistrationMessage(io.ConnAddr("registration"),
&pb.UserRegistration{
RegistrationCode: registrationCode,
Client: &pb.DSAPublicKey{
Y: publicKey.GetKey().Bytes(),
P: params.GetP().Bytes(),
Q: params.GetQ().Bytes(),
G: params.GetG().Bytes(),
},
})
if err != nil { if err != nil {
globals.Log.ERROR.Printf( globals.Log.ERROR.Printf("Register: Unable to send registration message: %+v", err)
"Register: Unable to contact Registration Server! %s", err)
return id.ZeroID, err return id.ZeroID, err
} }
if response.Error != "" {
globals.Log.ERROR.Printf("Register: %s", response.Error)
return id.ZeroID, errors.New(response.Error)
} }
regHash = response.ClientSignedByServer.Hash globals.Log.INFO.Println("Register: successfully passed Registration message")
regR = response.ClientSignedByServer.R
regS = response.ClientSignedByServer.S // Initialise blake2b hash for transmission keys and sha256 for reception
// Disconnect from regServer here since it will not be needed // keys
(cl.comm).(*io.Messaging).Comms.Disconnect(cl.ndf.Registration.Address) transmissionHash, _ := hash.NewCMixHash()
} receptionHash := sha256.New()
fmt.Println("passed reg")
// Loop over all Servers // Loop over all Servers
for i := range cl.ndf.Gateways { for i := range cl.ndf.Gateways {
gwID := id.NewNodeFromBytes(cl.ndf.Nodes[i].ID).NewGateway() gwID := id.NewNodeFromBytes(cl.ndf.Nodes[i].ID).NewGateway()
// Send signed public key and salt for UserID to Server // Request nonce message from gateway
nonceResponse, err := (cl.comm).(*io.Messaging).Comms. globals.Log.INFO.Println("Register: Requesting nonce from gateway")
SendRequestNonceMessage(gwID, nonce, dhPub, err := cl.requestNonce(salt, regHash, publicKeyDH, publicKeyRSA, privateKeyRSA, gwID)
&pb.NonceRequest{
Salt: salt,
Client: &pb.DSAPublicKey{
Y: publicKey.GetKey().Bytes(),
P: params.GetP().Bytes(),
Q: params.GetQ().Bytes(),
G: params.GetG().Bytes(),
},
ClientSignedByServer: &pb.DSASignature{
Hash: regHash,
R: regR,
S: regS,
},
})
if err != nil { if err != nil {
globals.Log.ERROR.Printf( globals.Log.ERROR.Printf("Register: Failed requesting nonce from gateway: %+v", err)
"Register: Unable to request nonce! %s",
err)
return id.ZeroID, err return id.ZeroID, err
} }
if nonceResponse.Error != "" {
globals.Log.ERROR.Printf("Register: %s", nonceResponse.Error)
return id.ZeroID, errors.New(nonceResponse.Error)
}
// Use Client keypair to sign Server nonce // Load server DH pubkey
nonce := nonceResponse.Nonce serverPubDH := cmixGrp.NewIntFromBytes(dhPub)
sig, err := privateKey.Sign(nonce, rand.Reader)
if err != nil {
globals.Log.ERROR.Printf(
"Register: Unable to sign nonce! %s", err)
return id.ZeroID, err
}
// Send signed nonce to Server // Confirm received nonce
// TODO: This returns a receipt that can be used to speed up registration globals.Log.INFO.Println("Register: Confirming received nonce")
confirmResponse, err := (cl.comm).(*io.Messaging).Comms. err = cl.confirmNonce(UID.Bytes(), nonce, privateKeyRSA, gwID)
SendConfirmNonceMessage(gwID,
&pb.DSASignature{
Hash: nonce,
R: sig.R.Bytes(),
S: sig.S.Bytes(),
})
if err != nil { if err != nil {
globals.Log.ERROR.Printf( globals.Log.ERROR.Printf("Register: Unable to confirm nonce: %+v", err)
"Register: Unable to send signed nonce! %s", err)
return id.ZeroID, err return id.ZeroID, err
} }
if confirmResponse.Error != "" {
globals.Log.ERROR.Printf(
"Register: %s", confirmResponse.Error)
return id.ZeroID, errors.New(confirmResponse.Error)
}
// Append Server public key
serverPublicKeys = append(serverPublicKeys,
signature.ReconstructPublicKey(signature.
CustomDSAParams(
large.NewIntFromBytes(confirmResponse.Server.GetP()),
large.NewIntFromBytes(confirmResponse.Server.GetQ()),
large.NewIntFromBytes(confirmResponse.Server.GetG())),
large.NewIntFromBytes(confirmResponse.Server.GetY())))
}
// 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 {
nodeID := *cl.topology.GetNodeAtIndex(itr)
nodeID := *cl.topology.GetNodeAtIndex(i)
nk[nodeID] = user.NodeKeys{ nk[nodeID] = user.NodeKeys{
TransmissionKey: registration.GenerateBaseKey(cmixGrp, TransmissionKey: registration.GenerateBaseKey(cmixGrp,
publicKey, privateKey, transmissionHash), serverPubDH, privateKeyDH, transmissionHash),
ReceptionKey: registration.GenerateBaseKey(cmixGrp, publicKey, ReceptionKey: registration.GenerateBaseKey(cmixGrp, serverPubDH,
privateKey, receptionHash), privateKeyDH, receptionHash),
} }
receptionHash.Reset() receptionHash.Reset()
...@@ -415,10 +317,10 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (* ...@@ -415,10 +317,10 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (*
u.Email = email u.Email = email
// Create the user session // Create the user session
nus := user.NewSession(cl.storage, u, nk, publicKey, privateKey, cmixGrp, e2eGrp) newSession := user.NewSession(cl.storage, u, nk, publicKeyRSA, privateKeyRSA, publicKeyDH, privateKeyDH, cmixGrp, e2eGrp)
// Store the user session // Store the user session
errStore := nus.StoreSession() errStore := newSession.StoreSession()
// FIXME If we have an error here, the session that gets created doesn't get immolated. // FIXME If we have an error here, the session that gets created doesn't get immolated.
// Immolation should happen in a deferred call instead. // Immolation should happen in a deferred call instead.
...@@ -430,15 +332,176 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (* ...@@ -430,15 +332,176 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (*
return id.ZeroID, err return id.ZeroID, err
} }
err = nus.Immolate() err = newSession.Immolate()
if err != nil { if err != nil {
globals.Log.ERROR.Printf("Error on immolate: %+v", err) globals.Log.ERROR.Printf("Error on immolate: %+v", err)
} }
nus = nil newSession = nil
return UID, nil return UID, nil
} }
// precannedRegister is a helper function for Register
// It handles the precanned registration case
func (cl *Client) precannedRegister(registrationCode, nick string,
nk map[id.Node]user.NodeKeys) (*user.User, *id.User, map[id.Node]user.NodeKeys, error) {
var successLook bool
var UID *id.User
var u *user.User
var err error
UID, successLook = user.Users.LookupUser(registrationCode)
globals.Log.DEBUG.Printf("UID: %+v, success: %+v", UID, successLook)
if !successLook {
return nil, nil, nil, errors.New("precannedRegister: could not register due to invalid HUID")
}
var successGet bool
u, successGet = user.Users.GetUser(UID)
if !successGet {
err = errors.New("precannedRegister: could not register due to ID lookup failure")
return nil, nil, nil, err
}
if nick != "" {
u.Nick = nick
}
nodekeys, successKeys := user.Users.LookupKeys(u.User)
if !successKeys {
err = errors.New("precannedRegister: could not register due to missing user keys")
return nil, nil, nil, err
}
for i := 0; i < len(cl.ndf.Gateways); i++ {
nk[*cl.topology.GetNodeAtIndex(i)] = *nodekeys
}
return u, UID, nk, nil
}
// sendRegistrationMessage is a helper for the Register function
// It sends a registration message and returns the registration hash
func (cl *Client) sendRegistrationMessage(registrationCode string,
publicKeyRSA *rsa.PublicKey) ([]byte, error) {
regHash := make([]byte, 0)
// Send registration code and public key to RegistrationServer
response, err := (cl.comm).(*io.Messaging).Comms.
SendRegistrationMessage(io.ConnAddr(PermissioningAddrID),
&pb.UserRegistration{
RegistrationCode: registrationCode,
ClientRSAPubKey: string(rsa.CreatePublicKeyPem(publicKeyRSA)),
})
if err != nil {
err = errors.New(fmt.Sprintf(
"sendRegistrationMessage: Unable to contact Registration Server! %s", err))
return nil, err
}
if response.Error != "" {
err = errors.New(fmt.Sprintf("sendRegistrationMessage: error handing message: %s", response.Error))
return nil, err
}
regHash = response.ClientSignedByServer.Signature
// Disconnect from regServer here since it will not be needed
(cl.comm).(*io.Messaging).Comms.Disconnect(cl.ndf.Registration.Address)
return regHash, nil
}
// requestNonce is a helper for the Register function
// It sends a request nonce message containing the client's keys for signing
// Returns nonce if successful
func (cl *Client) requestNonce(salt, regHash []byte,
publicKeyDH *cyclic.Int, publicKeyRSA *rsa.PublicKey,
privateKeyRSA *rsa.PrivateKey, gwID *id.Gateway) ([]byte, []byte, error) {
dhPub := publicKeyDH.Bytes()
sha := crypto.SHA256
opts := rsa.NewDefaultOptions()
opts.Hash = sha
h := sha.New()
h.Write(dhPub)
data := h.Sum(nil)
// Sign DH pubkey
rng := csprng.NewSystemRNG()
signed, err := rsa.Sign(rng, privateKeyRSA, sha, data, opts)
if err != nil {
return nil, nil, err
}
// Send signed public key and salt for UserID to Server
nonceResponse, err := (cl.comm).(*io.Messaging).Comms.
SendRequestNonceMessage(gwID,
&pb.NonceRequest{
Salt: salt,
ClientRSAPubKey: string(rsa.CreatePublicKeyPem(publicKeyRSA)),
ClientSignedByServer: &pb.RSASignature{
Signature: regHash,
},
ClientDHPubKey: publicKeyDH.Bytes(),
RequestSignature: &pb.RSASignature{
Signature: signed,
},
}) // TODO: modify this to return server DH
if err != nil {
err := errors.New(fmt.Sprintf(
"requestNonce: Unable to request nonce! %s", err))
return nil, nil, err
}
if nonceResponse.Error != "" {
err := errors.New(fmt.Sprintf("requestNonce: nonceResponse error: %s", nonceResponse.Error))
return nil, nil, err
}
// Use Client keypair to sign Server nonce
return nonceResponse.Nonce, nonceResponse.DHPubKey, nil
}
// confirmNonce is a helper for the Register function
// It signs a nonce and sends it for confirmation
// Returns nil if successful, error otherwise
func (cl *Client) confirmNonce(UID, nonce []byte,
privateKeyRSA *rsa.PrivateKey, gwID *id.Gateway) error {
sha := crypto.SHA256
opts := rsa.NewDefaultOptions()
opts.Hash = sha
h := sha.New()
h.Write(nonce)
data := h.Sum(nil)
// Hash nonce & sign
sig, err := rsa.Sign(rand.Reader, privateKeyRSA, sha, data, opts)
if err != nil {
globals.Log.ERROR.Printf(
"Register: Unable to sign nonce! %s", err)
return err
}
// Send signed nonce to Server
// TODO: This returns a receipt that can be used to speed up registration
msg := &pb.RequestRegistrationConfirmation{
UserID: UID,
NonceSignedByClient: &pb.RSASignature{
Signature: sig,
},
}
confirmResponse, err := (cl.comm).(*io.Messaging).Comms.
SendConfirmNonceMessage(gwID, msg)
if err != nil {
err := errors.New(fmt.Sprintf(
"confirmNonce: Unable to send signed nonce! %s", err))
return err
}
if confirmResponse.Error != "" {
err := errors.New(fmt.Sprintf(
"confirmNonce: Error confirming nonce: %s", confirmResponse.Error))
return err
}
return nil
}
// LoadSession loads the session object for the UID // LoadSession loads the session object for the UID
func (cl *Client) Login(UID *id.User) (string, error) { func (cl *Client) Login(UID *id.User) (string, error) {
session, err := user.LoadSession(cl.storage, UID) session, err := user.LoadSession(cl.storage, UID)
...@@ -590,8 +653,8 @@ func (cl *Client) registerForUserDiscovery(emailAddress string) error { ...@@ -590,8 +653,8 @@ func (cl *Client) registerForUserDiscovery(emailAddress string) error {
return err return err
} }
publicKey := cl.session.GetPublicKey() publicKey := cl.session.GetRSAPublicKey()
publicKeyBytes := publicKey.GetKey().LeftpadBytes(256) publicKeyBytes := rsa.CreatePublicKeyPem(publicKey)
return bots.Register(valueType, emailAddress, publicKeyBytes) return bots.Register(valueType, emailAddress, publicKeyBytes)
} }
...@@ -650,8 +713,8 @@ func (cl *Client) registerUserE2E(partnerID *id.User, ...@@ -650,8 +713,8 @@ func (cl *Client) registerUserE2E(partnerID *id.User,
// Create user private key and partner public key // Create user private key and partner public key
// in the group // in the group
privKey := cl.session.GetPrivateKey() privKey := cl.session.GetDHPrivateKey()
privKeyCyclic := grp.NewIntFromLargeInt(privKey.GetKey()) privKeyCyclic := grp.NewIntFromLargeInt(privKey.GetLargeInt())
partnerPubKeyCyclic := grp.NewIntFromBytes(partnerPubKey) partnerPubKeyCyclic := grp.NewIntFromBytes(partnerPubKey)
// Generate baseKey // Generate baseKey
......
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/hash"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature" "gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/circuit" "gitlab.com/elixxir/primitives/circuit"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
...@@ -32,6 +33,8 @@ import ( ...@@ -32,6 +33,8 @@ import (
"time" "time"
) )
var TestKeySize = 768
func TestRegistrationGob(t *testing.T) { func TestRegistrationGob(t *testing.T) {
// Get a Client // Get a Client
testClient, err := NewClient(&globals.RamStorage{}, "", def) testClient, err := NewClient(&globals.RamStorage{}, "", def)
...@@ -198,14 +201,18 @@ func TestRegisterUserE2E(t *testing.T) { ...@@ -198,14 +201,18 @@ func TestRegisterUserE2E(t *testing.T) {
rng := csprng.NewSystemRNG() rng := csprng.NewSystemRNG()
myPrivKey := params.PrivateKeyGen(rng) myPrivKey := params.PrivateKeyGen(rng)
myPrivKeyCyclic := cmixGrp.NewIntFromLargeInt(myPrivKey.GetKey()) myPrivKeyCyclic := cmixGrp.NewIntFromLargeInt(myPrivKey.GetKey())
myPubKey := myPrivKey.PublicKeyGen() myPubKeyCyclic := cmixGrp.ExpG(myPrivKeyCyclic, cmixGrp.NewMaxInt())
partnerPrivKey := params.PrivateKeyGen(rng) partnerPrivKey := params.PrivateKeyGen(rng)
partnerPubKey := partnerPrivKey.PublicKeyGen() partnerPubKey := partnerPrivKey.PublicKeyGen()
partnerPubKeyCyclic := cmixGrp.NewIntFromLargeInt(partnerPubKey.GetKey()) partnerPubKeyCyclic := cmixGrp.NewIntFromLargeInt(partnerPubKey.GetKey())
privateKeyRSA, _ := rsa.GenerateKey(rng, TestKeySize)
publicKeyRSA := rsa.PublicKey{PublicKey: privateKeyRSA.PublicKey}
myUser := &user.User{User: userID, Nick: "test"} myUser := &user.User{User: userID, Nick: "test"}
session := user.NewSession(testClient.storage, session := user.NewSession(testClient.storage,
myUser, make(map[id.Node]user.NodeKeys), myPubKey, myPrivKey, cmixGrp, e2eGrp) myUser, make(map[id.Node]user.NodeKeys), &publicKeyRSA, privateKeyRSA,
myPubKeyCyclic, myPrivKeyCyclic, cmixGrp, e2eGrp)
testClient.session = session testClient.session = session
fmt.Println("runn") fmt.Println("runn")
...@@ -287,15 +294,18 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { ...@@ -287,15 +294,18 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) {
rng := csprng.NewSystemRNG() rng := csprng.NewSystemRNG()
myPrivKey := params.PrivateKeyGen(rng) myPrivKey := params.PrivateKeyGen(rng)
myPrivKeyCyclic := cmixGrp.NewIntFromLargeInt(myPrivKey.GetKey()) myPrivKeyCyclic := cmixGrp.NewIntFromLargeInt(myPrivKey.GetKey())
myPubKey := myPrivKey.PublicKeyGen() myPubKeyCyclic := cmixGrp.ExpG(myPrivKeyCyclic, cmixGrp.NewMaxInt())
partnerPrivKey := params.PrivateKeyGen(rng) partnerPrivKey := params.PrivateKeyGen(rng)
partnerPubKey := partnerPrivKey.PublicKeyGen() partnerPubKey := partnerPrivKey.PublicKeyGen()
partnerPubKeyCyclic := cmixGrp.NewIntFromLargeInt(partnerPubKey.GetKey()) partnerPubKeyCyclic := cmixGrp.NewIntFromLargeInt(partnerPubKey.GetKey())
privateKeyRSA, _ := rsa.GenerateKey(rng, TestKeySize)
publicKeyRSA := rsa.PublicKey{PublicKey: privateKeyRSA.PublicKey}
myUser := &user.User{User: userID, Nick: "test"} myUser := &user.User{User: userID, Nick: "test"}
session := user.NewSession(testClient.storage, session := user.NewSession(testClient.storage,
myUser, make(map[id.Node]user.NodeKeys), myPubKey, myUser, make(map[id.Node]user.NodeKeys), &publicKeyRSA,
myPrivKey, cmixGrp, e2eGrp) privateKeyRSA, myPubKeyCyclic, myPrivKeyCyclic, cmixGrp, e2eGrp)
testClient.session = session testClient.session = session
...@@ -417,80 +427,99 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { ...@@ -417,80 +427,99 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) {
} }
} }
// FIXME Reinstate tests for the UDB api // Test happy path for precannedRegister
//var ListenCh chan *format.Message func TestClient_precannedRegister(t *testing.T) {
//var lastmsg string testClient, err := NewClient(&globals.RamStorage{}, "", def)
if err != nil {
//type dummyMessaging struct { t.Error(err)
// listener chan *format.Message }
//}
err = testClient.Connect()
// SendMessage to the server if err != nil {
//func (d *dummyMessaging) SendMessage(recipientID id.User, t.Error(err)
// message string) error { }
// jww.INFO.Printf("Sending: %s", message)
// lastmsg = message nk := make(map[id.Node]user.NodeKeys)
// return nil
//} _, _, nk, err = testClient.precannedRegister("UAV6IWD6", "tony_johns", nk)
if err != nil {
// Listen for messages from a given sender t.Errorf("Error during precannedRegister: %+v", err)
//func (d *dummyMessaging) Listen(senderID id.User) chan *format.Message { }
// return d.listener }
//}
// Test happy path for sendRegistrationMessage
// StopListening to a given switchboard (closes and deletes) func TestClient_sendRegistrationMessage(t *testing.T) {
//func (d *dummyMessaging) StopListening(listenerCh chan *format.Message) {} testClient, err := NewClient(&globals.RamStorage{}, "", def)
if err != nil {
// MessageReceiver thread to get new messages t.Error(err)
//func (d *dummyMessaging) MessageReceiver(delay time.Duration) {} }
//var pubKeyBits []string err = testClient.Connect()
//var keyFingerprint string if err != nil {
//var pubKey []byte t.Error(err)
}
// SendMsg puts a fake udb response message on the channel
//func SendMsg(msg string) { rng := csprng.NewSystemRNG()
// m, _ := format.NewMessage(13, 1, msg) privateKeyRSA, _ := rsa.GenerateKey(rng, TestKeySize)
// ListenCh <- &m[0] publicKeyRSA := rsa.PublicKey{PublicKey: privateKeyRSA.PublicKey}
//}
_, err = testClient.sendRegistrationMessage("UAV6IWD6", &publicKeyRSA)
//func TestRegisterPubKeyByteLen(t *testing.T) { if err != nil {
// ListenCh = make(chan *format.Message, 100) t.Errorf("Error during sendRegistrationMessage: %+v", err)
// io.Messaging = &dummyMessaging{ }
// switchboard: ListenCh, }
// }
// pubKeyBits = []string{ // Test happy path for requestNonce
// "S8KXBczy0jins9uS4LgBPt0bkFl8t00MnZmExQ6GcOcu8O7DKgAsNz" + func TestClient_requestNonce(t *testing.T) {
// "LU7a+gMTbIsS995IL/kuFF8wcBaQJBY23095PMSQ/nMuetzhk9HdXxrGIiKBo3C/n4SClp" + cmixGrp, _ := getGroups()
// "q4H+PoF9XziEVKua8JxGM2o83KiCK3tNUpaZbAAElkjueY4=", privateKeyDH := cmixGrp.RandomCoprime(cmixGrp.NewMaxInt())
// "8Lg/eoeKGgPlleTYfO3JyGfnwBtLi73ti0h2dBQWW94JTqTQDr+z" + publicKeyDH := cmixGrp.ExpG(privateKeyDH, cmixGrp.NewMaxInt())
// "xVpLzdgTt+87TkAl0yXu9mOUXqGJ+51lTcRlIdIpWpfgUbibdRme8IThg0RNCF31ESKCts" + rng := csprng.NewSystemRNG()
// "o8gJ8mSVljIXxrC+Uuoi+Gl1LNN5nPARykatx0Y70xNdJd2BQ=", privateKeyRSA, _ := rsa.GenerateKey(rng, TestKeySize)
// } publicKeyRSA := rsa.PublicKey{PublicKey: privateKeyRSA.PublicKey}
// pubKey = make([]byte, 256)
// for i := range pubKeyBits { testClient, err := NewClient(&globals.RamStorage{}, "", def)
// pubkeyBytes, _ := base64.StdEncoding.DecodeString(pubKeyBits[i]) if err != nil {
// for j := range pubkeyBytes { t.Error(err)
// pubKey[j+i*128] = pubkeyBytes[j] }
// }
// } err = testClient.Connect()
// if err != nil {
// keyFingerprint = "8oKh7TYG4KxQcBAymoXPBHSD/uga9pX3Mn/jKhvcD8M=" t.Error(err)
// //SendMsg("SEARCH blah@privategrity.com NOTFOUND") }
// SendMsg(fmt.Sprintf("GETKEY %s NOTFOUND", keyFingerprint))
// SendMsg("PUSHKEY ACK NEED 128") salt := make([]byte, 256)
// SendMsg(fmt.Sprintf("PUSHKEY COMPLETE %s", keyFingerprint)) _, err = csprng.NewSystemRNG().Read(salt)
// SendMsg("REGISTRATION COMPLETE") if err != nil {
// t.Errorf("Unable to generate salt! %s", err)
// err := bots.Register("EMAIL", "blah@privategrity.com", pubKey) }
//
// if err != nil { gwID := id.NewNodeFromBytes(testClient.ndf.Nodes[0].ID).NewGateway()
// t.Errorf("Unexpected error: %s", err.Error()) _, _, err = testClient.requestNonce(salt, []byte("test"), publicKeyDH, &publicKeyRSA, privateKeyRSA, gwID)
// } if err != nil {
// if len(lastmsg) != 81 { t.Errorf("Error during requestNonce: %+v", err)
// t.Errorf("Message wrong length: %d v. expected 81", len(lastmsg)) }
// } }
//}
// Test happy path for confirmNonce
func TestClient_confirmNonce(t *testing.T) {
testClient, err := NewClient(&globals.RamStorage{}, "", def)
if err != nil {
t.Error(err)
}
err = testClient.Connect()
if err != nil {
t.Error(err)
}
rng := csprng.NewSystemRNG()
privateKeyRSA, _ := rsa.GenerateKey(rng, TestKeySize)
gwID := id.NewNodeFromBytes(testClient.ndf.Nodes[0].ID).NewGateway()
err = testClient.confirmNonce([]byte("user"), []byte("test"), privateKeyRSA, gwID)
if err != nil {
t.Errorf("Error during confirmNonce: %+v", err)
}
}
func getGroups() (*cyclic.Group, *cyclic.Group) { func getGroups() (*cyclic.Group, *cyclic.Group) {
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"gitlab.com/elixxir/client/cmixproto" "gitlab.com/elixxir/client/cmixproto"
"gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/parse"
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
"sync" "sync"
...@@ -77,16 +78,11 @@ func (m *TestInterface) PutMessage(msg *pb.Slot) bool { ...@@ -77,16 +78,11 @@ func (m *TestInterface) PutMessage(msg *pb.Slot) bool {
return true return true
} }
func (m *TestInterface) ConfirmNonce(message *pb.DSASignature) (*pb.RegistrationConfirmation, error) { func (m *TestInterface) ConfirmNonce(message *pb.RequestRegistrationConfirmation) (*pb.RegistrationConfirmation, error) {
regConfirmation := &pb.RegistrationConfirmation{ regConfirmation := &pb.RegistrationConfirmation{
Server: &pb.DSAPublicKey{}, ClientSignedByServer: &pb.RSASignature{},
} }
regConfirmation.Server.P = large.NewInt(1).Bytes()
regConfirmation.Server.Q = large.NewInt(1).Bytes()
regConfirmation.Server.G = large.NewInt(1).Bytes()
regConfirmation.Server.Y = large.NewInt(1).Bytes()
return regConfirmation, nil return regConfirmation, nil
} }
...@@ -101,14 +97,41 @@ func (s *MockRegistration) RegisterNode(ID []byte, ...@@ -101,14 +97,41 @@ func (s *MockRegistration) RegisterNode(ID []byte,
} }
// Registers a user and returns a signed public key // Registers a user and returns a signed public key
func (s *MockRegistration) RegisterUser(registrationCode string, func (s *MockRegistration) RegisterUser(registrationCode,
Y, P, Q, G []byte) (hash, R, S []byte, err error) { key string) (hash []byte, err error) {
return nil, nil, nil, nil return nil, nil
}
func getDHPubKey() *cyclic.Int {
cmixGrp := cyclic.NewGroup(
large.NewIntFromString("9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48"+
"C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44F"+
"FE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5"+
"B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE2"+
"35567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41"+
"F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE"+
"92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA15"+
"3E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B", 16),
large.NewIntFromString("5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613"+
"D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C4"+
"6A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472"+
"085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5"+
"AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA"+
"3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71"+
"BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0"+
"DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7", 16),
large.NewIntFromString("F2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F", 16))
dh := cmixGrp.RandomCoprime(cmixGrp.NewMaxInt())
return cmixGrp.ExpG(dh, cmixGrp.NewMaxInt())
} }
// Pass-through for Registration Nonce Communication // Pass-through for Registration Nonce Communication
func (m *TestInterface) RequestNonce(message *pb.NonceRequest) (*pb.Nonce, error) { func (m *TestInterface) RequestNonce(message *pb.NonceRequest) (*pb.Nonce, error) {
return &pb.Nonce{}, nil dh := getDHPubKey().Bytes()
return &pb.Nonce{
DHPubKey: dh,
}, nil
} }
// Mock dummy storage interface for testing. // Mock dummy storage interface for testing.
......
...@@ -70,7 +70,7 @@ func TestMain(m *testing.M) { ...@@ -70,7 +70,7 @@ func TestMain(m *testing.M) {
cmixGrp, e2eGrp := getGroups() cmixGrp, e2eGrp := getGroups()
fakeSession := user.NewSession(&globals.RamStorage{}, fakeSession := user.NewSession(&globals.RamStorage{},
u, nil, nil, nil, cmixGrp, e2eGrp) u, nil, nil, nil, nil, nil, cmixGrp, e2eGrp)
fakeComm := &dummyMessaging{ fakeComm := &dummyMessaging{
listener: ListenCh, listener: ListenCh,
} }
......
...@@ -81,7 +81,7 @@ func setup() { ...@@ -81,7 +81,7 @@ func setup() {
} }
session = user.NewSession(nil, u, nkMap, session = user.NewSession(nil, u, nkMap,
nil, nil, cmixGrp, e2eGrp) nil, nil, nil, nil, cmixGrp, e2eGrp)
} }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
......
...@@ -4,11 +4,11 @@ import: ...@@ -4,11 +4,11 @@ import:
version: master version: master
vcs: git vcs: git
- package: gitlab.com/elixxir/crypto - package: gitlab.com/elixxir/crypto
version: master version: RSARegistration
repo: git@gitlab.com:elixxir/crypto repo: git@gitlab.com:elixxir/crypto
vcs: git vcs: git
- package: gitlab.com/elixxir/comms - package: gitlab.com/elixxir/comms
version: master version: RSARegistration
repo: git@gitlab.com:elixxir/comms repo: git@gitlab.com:elixxir/comms
vcs: git vcs: git
- package: gitlab.com/elixxir/primitives - package: gitlab.com/elixxir/primitives
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/hash"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature" "gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/circuit" "gitlab.com/elixxir/primitives/circuit"
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
"os" "os"
...@@ -67,14 +68,17 @@ func TestMain(m *testing.M) { ...@@ -67,14 +68,17 @@ func TestMain(m *testing.M) {
} }
myPrivKey := params.PrivateKeyGen(rng) myPrivKey := params.PrivateKeyGen(rng)
myPrivKeyCyclic := grp.NewIntFromLargeInt(myPrivKey.GetKey()) myPrivKeyCyclic := grp.NewIntFromLargeInt(myPrivKey.GetKey())
myPubKey := myPrivKey.PublicKeyGen() myPubKeyCyclic := grp.ExpG(myPrivKeyCyclic, grp.NewInt(1))
partnerID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 12}) partnerID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 12})
partnerPrivKey := params.PrivateKeyGen(rng) partnerPrivKey := params.PrivateKeyGen(rng)
partnerPubKey := partnerPrivKey.PublicKeyGen() partnerPubKey := partnerPrivKey.PublicKeyGen()
partnerPubKeyCyclic := grp.NewIntFromLargeInt(partnerPubKey.GetKey()) partnerPubKeyCyclic := grp.NewIntFromLargeInt(partnerPubKey.GetKey())
privateKeyRSA, _ := rsa.GenerateKey(rng, 768)
publicKeyRSA := rsa.PublicKey{PublicKey: privateKeyRSA.PublicKey}
session := user.NewSession(&globals.RamStorage{}, session := user.NewSession(&globals.RamStorage{},
u, nil, myPubKey, myPrivKey, grp, e2eGrp) u, nil, &publicKeyRSA, privateKeyRSA, myPubKeyCyclic, myPrivKeyCyclic, grp, e2eGrp)
ListenCh = make(chan []byte, 100) ListenCh = make(chan []byte, 100)
fakeComm := &dummyMessaging{ fakeComm := &dummyMessaging{
listener: ListenCh, listener: ListenCh,
...@@ -216,7 +220,7 @@ func TestRekeyConfirm(t *testing.T) { ...@@ -216,7 +220,7 @@ func TestRekeyConfirm(t *testing.T) {
// Confirm that user Private key in Send Key Manager // Confirm that user Private key in Send Key Manager
// differs from the one stored in session // differs from the one stored in session
if session.GetPrivateKey().GetKey().Cmp( if session.GetDHPrivateKey().GetLargeInt().Cmp(
session.GetKeyStore().GetSendManager(partnerID). session.GetKeyStore().GetSendManager(partnerID).
GetPrivKey().GetLargeInt()) == 0 { GetPrivKey().GetLargeInt()) == 0 {
t.Errorf("PrivateKey remained unchanged after Outgoing Rekey!") t.Errorf("PrivateKey remained unchanged after Outgoing Rekey!")
...@@ -291,7 +295,7 @@ func TestRekey(t *testing.T) { ...@@ -291,7 +295,7 @@ func TestRekey(t *testing.T) {
keys := rkm.GetKeys(partnerID) keys := rkm.GetKeys(partnerID)
if keys.CurrPrivKey.GetLargeInt(). if keys.CurrPrivKey.GetLargeInt().
Cmp(session.GetPrivateKey().GetKey()) == 0 { Cmp(session.GetDHPrivateKey().GetLargeInt()) == 0 {
t.Errorf("Own PrivateKey didn't update properly after both parties rekeys") t.Errorf("Own PrivateKey didn't update properly after both parties rekeys")
} }
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/keyStore" "gitlab.com/elixxir/client/keyStore"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/signature" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/circuit" "gitlab.com/elixxir/primitives/circuit"
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/switchboard" "gitlab.com/elixxir/primitives/switchboard"
...@@ -31,8 +31,10 @@ var ErrQuery = errors.New("element not in map") ...@@ -31,8 +31,10 @@ var ErrQuery = errors.New("element not in map")
type Session interface { type Session interface {
GetCurrentUser() (currentUser *User) GetCurrentUser() (currentUser *User)
GetKeys(topology *circuit.Circuit) []NodeKeys GetKeys(topology *circuit.Circuit) []NodeKeys
GetPrivateKey() *signature.DSAPrivateKey GetRSAPrivateKey() *rsa.PrivateKey
GetPublicKey() *signature.DSAPublicKey GetRSAPublicKey() *rsa.PublicKey
GetDHPrivateKey() *cyclic.Int
GetDHPublicKey() *cyclic.Int
GetCmixGroup() *cyclic.Group GetCmixGroup() *cyclic.Group
GetE2EGroup() *cyclic.Group GetE2EGroup() *cyclic.Group
GetLastMessageID() string GetLastMessageID() string
...@@ -59,16 +61,20 @@ type NodeKeys struct { ...@@ -59,16 +61,20 @@ type NodeKeys struct {
// Creates a new Session interface for registration // Creates a new Session interface for registration
func NewSession(store globals.Storage, func NewSession(store globals.Storage,
u *User, nk map[id.Node]NodeKeys, u *User, nk map[id.Node]NodeKeys,
publicKey *signature.DSAPublicKey, publicKeyRSA *rsa.PublicKey,
privateKey *signature.DSAPrivateKey, privateKeyRSA *rsa.PrivateKey,
publicKeyDH *cyclic.Int,
privateKeyDH *cyclic.Int,
cmixGrp, e2eGrp *cyclic.Group) Session { cmixGrp, e2eGrp *cyclic.Group) Session {
// With an underlying Session data structure // With an underlying Session data structure
return Session(&SessionObj{ return Session(&SessionObj{
CurrentUser: u, CurrentUser: u,
Keys: nk, Keys: nk,
PrivateKey: privateKey, RSAPublicKey: publicKeyRSA,
PublicKey: publicKey, RSAPrivateKey: privateKeyRSA,
DHPublicKey: publicKeyDH,
DHPrivateKey: privateKeyDH,
CmixGrp: cmixGrp, CmixGrp: cmixGrp,
E2EGrp: e2eGrp, E2EGrp: e2eGrp,
InterfaceMap: make(map[string]interface{}), InterfaceMap: make(map[string]interface{}),
...@@ -148,8 +154,10 @@ type SessionObj struct { ...@@ -148,8 +154,10 @@ type SessionObj struct {
CurrentUser *User CurrentUser *User
Keys map[id.Node]NodeKeys Keys map[id.Node]NodeKeys
PrivateKey *signature.DSAPrivateKey RSAPrivateKey *rsa.PrivateKey
PublicKey *signature.DSAPublicKey RSAPublicKey *rsa.PublicKey
DHPrivateKey *cyclic.Int
DHPublicKey *cyclic.Int
CmixGrp *cyclic.Group CmixGrp *cyclic.Group
E2EGrp *cyclic.Group E2EGrp *cyclic.Group
...@@ -203,16 +211,28 @@ func (s *SessionObj) GetKeys(topology *circuit.Circuit) []NodeKeys { ...@@ -203,16 +211,28 @@ func (s *SessionObj) GetKeys(topology *circuit.Circuit) []NodeKeys {
return keys return keys
} }
func (s *SessionObj) GetPrivateKey() *signature.DSAPrivateKey { func (s *SessionObj) GetRSAPrivateKey() *rsa.PrivateKey {
s.LockStorage() s.LockStorage()
defer s.UnlockStorage() defer s.UnlockStorage()
return s.PrivateKey return s.RSAPrivateKey
} }
func (s *SessionObj) GetPublicKey() *signature.DSAPublicKey { func (s *SessionObj) GetRSAPublicKey() *rsa.PublicKey {
s.LockStorage() s.LockStorage()
defer s.UnlockStorage() defer s.UnlockStorage()
return s.PublicKey return s.RSAPublicKey
}
func (s *SessionObj) GetDHPrivateKey() *cyclic.Int {
s.LockStorage()
defer s.UnlockStorage()
return s.DHPrivateKey
}
func (s *SessionObj) GetDHPublicKey() *cyclic.Int {
s.LockStorage()
defer s.UnlockStorage()
return s.DHPublicKey
} }
func (s *SessionObj) GetCmixGroup() *cyclic.Group { func (s *SessionObj) GetCmixGroup() *cyclic.Group {
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/circuit" "gitlab.com/elixxir/primitives/circuit"
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
"math/rand" "math/rand"
...@@ -51,14 +51,16 @@ func TestUserSession(t *testing.T) { ...@@ -51,14 +51,16 @@ func TestUserSession(t *testing.T) {
storage := &globals.RamStorage{} storage := &globals.RamStorage{}
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L1024N160) privateKey, _ := rsa.GenerateKey(rng, 768)
privateKey := params.PrivateKeyGen(rng) publicKey := rsa.PublicKey{PublicKey: privateKey.PublicKey}
publicKey := privateKey.PublicKeyGen()
cmixGrp, e2eGrp := getGroups() cmixGrp, e2eGrp := getGroups()
privateKeyDH := cmixGrp.RandomCoprime(cmixGrp.NewInt(1))
publicKeyDH := cmixGrp.ExpG(privateKeyDH, cmixGrp.NewInt(1))
ses := NewSession(storage, ses := NewSession(storage,
u, keys, publicKey, privateKey, cmixGrp, e2eGrp) u, keys, &publicKey, privateKey, publicKeyDH, privateKeyDH, cmixGrp, e2eGrp)
ses.SetLastMessageID("totally unique ID") ses.SetLastMessageID("totally unique ID")
...@@ -118,10 +120,26 @@ func TestUserSession(t *testing.T) { ...@@ -118,10 +120,26 @@ func TestUserSession(t *testing.T) {
for i := 0; i < len(ses.GetKeys(topology)); i++ { for i := 0; i < len(ses.GetKeys(topology)); i++ {
if !reflect.DeepEqual(*ses.GetPublicKey(), *publicKey) { sesPriv := ses.GetRSAPrivateKey().PrivateKey
if !reflect.DeepEqual(*ses.GetRSAPublicKey(), publicKey) {
t.Errorf("Error: Public key not set correctly!") t.Errorf("Error: Public key not set correctly!")
} else if !reflect.DeepEqual(*ses.GetPrivateKey(), *privateKey) { } else if !reflect.DeepEqual(sesPriv, privateKey.PrivateKey) {
t.Errorf("Error: Private key not set correctly!") orig := privateKey.PrivateKey
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 {
t.Log("DeepEqual failed, but values are equal...")
}
} else if ses.GetKeys(topology)[i].ReceptionKey.Cmp(grp. } else if ses.GetKeys(topology)[i].ReceptionKey.Cmp(grp.
NewInt(2)) != 0 { NewInt(2)) != 0 {
t.Errorf("Error: Reception key not set correctly!") t.Errorf("Error: Reception key not set correctly!")
...@@ -135,7 +153,7 @@ func TestUserSession(t *testing.T) { ...@@ -135,7 +153,7 @@ func TestUserSession(t *testing.T) {
} }
//TODO: FIX THIS? //TODO: FIX THIS?
if ses.GetPrivateKey() == nil { if ses.GetRSAPrivateKey() == nil {
t.Errorf("Error: Private Keys not set correctly!") t.Errorf("Error: Private Keys not set correctly!")
} else { } else {
pass++ pass++
...@@ -212,15 +230,17 @@ func TestGetPubKey(t *testing.T) { ...@@ -212,15 +230,17 @@ func TestGetPubKey(t *testing.T) {
} }
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L1024N160) privateKey, _ := rsa.GenerateKey(rng, 768)
privateKey := params.PrivateKeyGen(rng) publicKey := rsa.PublicKey{PublicKey: privateKey.PublicKey}
publicKey := privateKey.PublicKeyGen()
cmixGrp, e2eGrp := getGroups() cmixGrp, e2eGrp := getGroups()
ses := NewSession(nil, u, keys, publicKey, privateKey, cmixGrp, e2eGrp) privateKeyDH := cmixGrp.RandomCoprime(cmixGrp.NewInt(1))
publicKeyDH := cmixGrp.ExpG(privateKeyDH, cmixGrp.NewInt(1))
pubKey := ses.GetPublicKey() ses := NewSession(nil, u, keys, &publicKey, privateKey, publicKeyDH, privateKeyDH, cmixGrp, e2eGrp)
pubKey := *ses.GetRSAPublicKey()
if !reflect.DeepEqual(pubKey, publicKey) { if !reflect.DeepEqual(pubKey, publicKey) {
t.Errorf("Public key not returned correctly!") t.Errorf("Public key not returned correctly!")
} }
...@@ -243,15 +263,17 @@ func TestGetPrivKey(t *testing.T) { ...@@ -243,15 +263,17 @@ func TestGetPrivKey(t *testing.T) {
} }
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewSource(42))
params := signature.NewDSAParams(rng, signature.L1024N160) privateKey, _ := rsa.GenerateKey(rng, 768)
privateKey := params.PrivateKeyGen(rng) publicKey := rsa.PublicKey{PublicKey: privateKey.PublicKey}
publicKey := privateKey.PublicKeyGen()
cmixGrp, e2eGrp := getGroups() cmixGrp, e2eGrp := getGroups()
ses := NewSession(nil, u, keys, publicKey, privateKey, cmixGrp, e2eGrp) privateKeyDH := cmixGrp.RandomCoprime(cmixGrp.NewInt(1))
publicKeyDH := cmixGrp.ExpG(privateKeyDH, cmixGrp.NewInt(1))
ses := NewSession(nil, u, keys, &publicKey, privateKey, publicKeyDH, privateKeyDH, cmixGrp, e2eGrp)
privKey := ses.GetPrivateKey() privKey := ses.GetRSAPrivateKey()
if !reflect.DeepEqual(*privKey, *privateKey) { if !reflect.DeepEqual(*privKey, *privateKey) {
t.Errorf("Private key is not returned correctly!") t.Errorf("Private key is not returned correctly!")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment