Skip to content
Snippets Groups Projects
Commit a3ebc4f7 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Switch over to the ratchet partner interface

parent 0db240fe
Branches
Tags
4 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast,!195Restructure e2e
...@@ -116,12 +116,12 @@ type Handler interface { ...@@ -116,12 +116,12 @@ type Handler interface {
partnerPubKey, myPrivKey *cyclic.Int, partnerPubKey, myPrivKey *cyclic.Int,
partnerSIDHPubKey *sidh.PublicKey, partnerSIDHPubKey *sidh.PublicKey,
mySIDHPrivKey *sidh.PrivateKey, sendParams, mySIDHPrivKey *sidh.PrivateKey, sendParams,
receiveParams session.Params) (*partner.Manager, error) receiveParams session.Params) (partner.Manager, error)
// GetPartner returns the partner per its ID, if it exists // GetPartner returns the partner per its ID, if it exists
// myID is your ID in the relationship, if left blank, it will // myID is your ID in the relationship, if left blank, it will
// assume to be your defaultID // assume to be your defaultID
GetPartner(partnerID *id.ID) (*partner.Manager, error) GetPartner(partnerID *id.ID) (partner.Manager, error)
// DeletePartner removes the associated contact from the E2E store // DeletePartner removes the associated contact from the E2E store
// myID is your ID in the relationship, if left blank, it will // myID is your ID in the relationship, if left blank, it will
......
...@@ -9,22 +9,27 @@ import ( ...@@ -9,22 +9,27 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
type ManagerInt interface { type Manager interface {
NewReceiveSession(partnerPubKey *cyclic.Int, NewReceiveSession(partnerPubKey *cyclic.Int,
partnerSIDHPubKey *sidh.PublicKey, e2eParams session.Params, partnerSIDHPubKey *sidh.PublicKey, e2eParams session.Params,
source *session.Session) (*session.Session, bool) source *session.Session) (*session.Session, bool)
NewSendSession(myPrivKey *cyclic.Int, NewSendSession(*cyclic.Int, *sidh.PrivateKey, session.Params,
mySIDHPrivKey *sidh.PrivateKey, e2eParams session.Params) *session.Session) *session.Session
PopSendCypher() (*session.Cypher, error) PopSendCypher() (*session.Cypher, error)
PopRekeyCypher() (*session.Cypher, error) PopRekeyCypher() (*session.Cypher, error)
GetPartnerID() *id.ID GetPartnerID() *id.ID
GetMyID() *id.ID
GetSendSession(sid session.SessionID) *session.Session GetSendSession(sid session.SessionID) *session.Session
GetSendRelationshipFingerprint() GetReceiveSession(sid session.SessionID) *session.Session
Confirm(sid session.SessionID) GetSendRelationshipFingerprint() []byte
Confirm(sid session.SessionID) error
TriggerNegotiations() []*session.Session TriggerNegotiations() []*session.Session
GetMyOriginPrivateKey() GetMyOriginPrivateKey() *cyclic.Int
GetPartnerOriginPublicKey() GetPartnerOriginPublicKey() *cyclic.Int
GetRelationshipFingerprintBytes() []byte GetRelationshipFingerprintBytes() []byte
GetRelationshipFingerprint() string
MakeService(tag string) message.Service MakeService(tag string) message.Service
GetContact() contact.Contact GetContact() contact.Contact
DeleteRelationship() error
ClearManager() error
} }
...@@ -30,7 +30,7 @@ const managerPrefix = "Manager{partner:%s}" ...@@ -30,7 +30,7 @@ const managerPrefix = "Manager{partner:%s}"
const originMyPrivKeyKey = "originMyPrivKey" const originMyPrivKeyKey = "originMyPrivKey"
const originPartnerPubKey = "originPartnerPubKey" const originPartnerPubKey = "originPartnerPubKey"
type Manager struct { type manager struct {
kv *versioned.KV kv *versioned.KV
myID *id.ID myID *id.ID
...@@ -55,11 +55,11 @@ func NewManager(kv *versioned.KV, myID, partnerID *id.ID, myPrivKey, ...@@ -55,11 +55,11 @@ func NewManager(kv *versioned.KV, myID, partnerID *id.ID, myPrivKey,
partnerPubKey *cyclic.Int, mySIDHPrivKey *sidh.PrivateKey, partnerPubKey *cyclic.Int, mySIDHPrivKey *sidh.PrivateKey,
partnerSIDHPubKey *sidh.PublicKey, sendParams, partnerSIDHPubKey *sidh.PublicKey, sendParams,
receiveParams session.Params, cyHandler session.CypherHandler, receiveParams session.Params, cyHandler session.CypherHandler,
grp *cyclic.Group, rng *fastRNG.StreamGenerator) *Manager { grp *cyclic.Group, rng *fastRNG.StreamGenerator) Manager {
kv = kv.Prefix(makeManagerPrefix(partnerID)) kv = kv.Prefix(makeManagerPrefix(partnerID))
m := &Manager{ m := &manager{
kv: kv, kv: kv,
originMyPrivKey: myPrivKey, originMyPrivKey: myPrivKey,
originPartnerPubKey: partnerPubKey, originPartnerPubKey: partnerPubKey,
...@@ -96,9 +96,9 @@ func NewManager(kv *versioned.KV, myID, partnerID *id.ID, myPrivKey, ...@@ -96,9 +96,9 @@ func NewManager(kv *versioned.KV, myID, partnerID *id.ID, myPrivKey,
//LoadManager loads a relationship and all buffers and sessions from disk //LoadManager loads a relationship and all buffers and sessions from disk
func LoadManager(kv *versioned.KV, myID, partnerID *id.ID, func LoadManager(kv *versioned.KV, myID, partnerID *id.ID,
cyHandler session.CypherHandler, grp *cyclic.Group, cyHandler session.CypherHandler, grp *cyclic.Group,
rng *fastRNG.StreamGenerator) (*Manager, error) { rng *fastRNG.StreamGenerator) (Manager, error) {
m := &Manager{ m := &manager{
kv: kv.Prefix(makeManagerPrefix(partnerID)), kv: kv.Prefix(makeManagerPrefix(partnerID)),
myID: myID, myID: myID,
partner: partnerID, partner: partnerID,
...@@ -144,8 +144,8 @@ func LoadManager(kv *versioned.KV, myID, partnerID *id.ID, ...@@ -144,8 +144,8 @@ func LoadManager(kv *versioned.KV, myID, partnerID *id.ID,
// ClearManager removes the relationship between the partner // ClearManager removes the relationship between the partner
// and deletes the Send and Receive sessions. This includes the // and deletes the Send and Receive sessions. This includes the
// sessions and the key vectors // sessions and the key vectors
func ClearManager(m *Manager) error { func (m *manager) ClearManager() error {
if err := DeleteRelationship(m); err != nil { if err := m.DeleteRelationship(); err != nil {
return errors.WithMessage(err, return errors.WithMessage(err,
"Failed to delete relationship") "Failed to delete relationship")
} }
...@@ -164,7 +164,7 @@ func ClearManager(m *Manager) error { ...@@ -164,7 +164,7 @@ func ClearManager(m *Manager) error {
// session already exists, then it will not be overwritten and the extant // session already exists, then it will not be overwritten and the extant
// session will be returned with the bool set to true denoting a duplicate. This // session will be returned with the bool set to true denoting a duplicate. This
// allows for support of duplicate key exchange triggering. // allows for support of duplicate key exchange triggering.
func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, func (m *manager) NewReceiveSession(partnerPubKey *cyclic.Int,
partnerSIDHPubKey *sidh.PublicKey, e2eParams session.Params, partnerSIDHPubKey *sidh.PublicKey, e2eParams session.Params,
source *session.Session) (*session.Session, bool) { source *session.Session) (*session.Session, bool) {
...@@ -190,7 +190,7 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, ...@@ -190,7 +190,7 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int,
// NewSendSession creates a new Send session using the latest public key // NewSendSession creates a new Send session using the latest public key
// received from the partner and a new private key for the user. Passing in a // received from the partner and a new private key for the user. Passing in a
// private key is optional. A private key will be generated if none is passed. // private key is optional. A private key will be generated if none is passed.
func (m *Manager) NewSendSession(myPrivKey *cyclic.Int, func (m *manager) NewSendSession(myPrivKey *cyclic.Int,
mySIDHPrivKey *sidh.PrivateKey, e2eParams session.Params, mySIDHPrivKey *sidh.PrivateKey, e2eParams session.Params,
sourceSession *session.Session) *session.Session { sourceSession *session.Session) *session.Session {
...@@ -202,61 +202,61 @@ func (m *Manager) NewSendSession(myPrivKey *cyclic.Int, ...@@ -202,61 +202,61 @@ func (m *Manager) NewSendSession(myPrivKey *cyclic.Int,
// PopSendCypher gets the correct session to Send with depending on the type // PopSendCypher gets the correct session to Send with depending on the type
// of Send. // of Send.
func (m *Manager) PopSendCypher() (*session.Cypher, error) { func (m *manager) PopSendCypher() (*session.Cypher, error) {
return m.send.getKeyForSending() return m.send.getKeyForSending()
} }
// PopRekeyCypher gets the correct session to Send with depending on the type // PopRekeyCypher gets the correct session to Send with depending on the type
// of Send. // of Send.
func (m *Manager) PopRekeyCypher() (*session.Cypher, error) { func (m *manager) PopRekeyCypher() (*session.Cypher, error) {
return m.send.getKeyForRekey() return m.send.getKeyForRekey()
} }
// GetPartnerID returns a copy of the ID of the partner. // GetPartnerID returns a copy of the ID of the partner.
func (m *Manager) GetPartnerID() *id.ID { func (m *manager) GetPartnerID() *id.ID {
return m.partner.DeepCopy() return m.partner.DeepCopy()
} }
// GetMyID returns a copy of the ID used as self. // GetMyID returns a copy of the ID used as self.
func (m *Manager) GetMyID() *id.ID { func (m *manager) GetMyID() *id.ID {
return m.myID.DeepCopy() return m.myID.DeepCopy()
} }
// GetSendSession gets the Send session of the passed ID. Returns nil if no // GetSendSession gets the Send session of the passed ID. Returns nil if no
// session is found. // session is found.
func (m *Manager) GetSendSession(sid session.SessionID) *session.Session { func (m *manager) GetSendSession(sid session.SessionID) *session.Session {
return m.send.GetByID(sid) return m.send.GetByID(sid)
} }
// GetReceiveSession gets the Receive session of the passed ID. Returns nil if // GetReceiveSession gets the Receive session of the passed ID. Returns nil if
// no session is found. // no session is found.
func (m *Manager) GetReceiveSession(sid session.SessionID) *session.Session { func (m *manager) GetReceiveSession(sid session.SessionID) *session.Session {
return m.receive.GetByID(sid) return m.receive.GetByID(sid)
} }
// GetSendSession gets the Send session of the passed ID. Returns nil if no // GetSendSession gets the Send session of the passed ID. Returns nil if no
// session is found. // session is found.
func (m *Manager) GetSendRelationshipFingerprint() []byte { func (m *manager) GetSendRelationshipFingerprint() []byte {
return m.send.fingerprint return m.send.fingerprint
} }
// Confirm confirms a Send session is known about by the partner. // Confirm confirms a Send session is known about by the partner.
func (m *Manager) Confirm(sid session.SessionID) error { func (m *manager) Confirm(sid session.SessionID) error {
return m.send.Confirm(sid) return m.send.Confirm(sid)
} }
// TriggerNegotiations returns a list of key exchange operations if any are // TriggerNegotiations returns a list of key exchange operations if any are
// necessary. // necessary.
func (m *Manager) TriggerNegotiations() []*session.Session { func (m *manager) TriggerNegotiations() []*session.Session {
return m.send.TriggerNegotiation() return m.send.TriggerNegotiation()
} }
func (m *Manager) GetMyOriginPrivateKey() *cyclic.Int { func (m *manager) GetMyOriginPrivateKey() *cyclic.Int {
return m.originMyPrivKey.DeepCopy() return m.originMyPrivKey.DeepCopy()
} }
func (m *Manager) GetPartnerOriginPublicKey() *cyclic.Int { func (m *manager) GetPartnerOriginPublicKey() *cyclic.Int {
return m.originPartnerPubKey.DeepCopy() return m.originPartnerPubKey.DeepCopy()
} }
...@@ -265,7 +265,7 @@ const relationshipFpLength = 15 ...@@ -265,7 +265,7 @@ const relationshipFpLength = 15
// GetRelationshipFingerprint returns a unique fingerprint for an E2E // GetRelationshipFingerprint returns a unique fingerprint for an E2E
// relationship. The fingerprint is a base 64 encoded hash of of the two // relationship. The fingerprint is a base 64 encoded hash of of the two
// relationship fingerprints truncated to 15 characters. // relationship fingerprints truncated to 15 characters.
func (m *Manager) GetRelationshipFingerprint() string { func (m *manager) GetRelationshipFingerprint() string {
// Base 64 encode hash and truncate // Base 64 encode hash and truncate
return base64.StdEncoding.EncodeToString( return base64.StdEncoding.EncodeToString(
...@@ -274,7 +274,7 @@ func (m *Manager) GetRelationshipFingerprint() string { ...@@ -274,7 +274,7 @@ func (m *Manager) GetRelationshipFingerprint() string {
// GetRelationshipFingerprintBytes returns a unique fingerprint for an E2E // GetRelationshipFingerprintBytes returns a unique fingerprint for an E2E
// relationship. used for the e2e preimage. // relationship. used for the e2e preimage.
func (m *Manager) GetRelationshipFingerprintBytes() []byte { func (m *manager) GetRelationshipFingerprintBytes() []byte {
// Sort fingerprints // Sort fingerprints
var fps [][]byte var fps [][]byte
...@@ -297,7 +297,7 @@ func (m *Manager) GetRelationshipFingerprintBytes() []byte { ...@@ -297,7 +297,7 @@ func (m *Manager) GetRelationshipFingerprintBytes() []byte {
// MakeService Returns a service interface with the // MakeService Returns a service interface with the
// appropriate identifier for who is being sent to. Will populate // appropriate identifier for who is being sent to. Will populate
// the metadata with the partner // the metadata with the partner
func (m *Manager) MakeService(tag string) message.Service { func (m *manager) MakeService(tag string) message.Service {
return message.Service{ return message.Service{
Identifier: m.GetRelationshipFingerprintBytes(), Identifier: m.GetRelationshipFingerprintBytes(),
Tag: tag, Tag: tag,
...@@ -307,7 +307,7 @@ func (m *Manager) MakeService(tag string) message.Service { ...@@ -307,7 +307,7 @@ func (m *Manager) MakeService(tag string) message.Service {
// GetContact assembles and returns a contact.Contact with the partner's ID // GetContact assembles and returns a contact.Contact with the partner's ID
// and DH key. // and DH key.
func (m *Manager) GetContact() contact.Contact { func (m *manager) GetContact() contact.Contact {
// Assemble Contact // Assemble Contact
return contact.Contact{ return contact.Contact{
ID: m.GetPartnerID(), ID: m.GetPartnerID(),
......
...@@ -32,15 +32,17 @@ func Test_newManager(t *testing.T) { ...@@ -32,15 +32,17 @@ func Test_newManager(t *testing.T) {
expectedM, kv := newTestManager(t) expectedM, kv := newTestManager(t)
// Create new relationship // Create new relationship
m := NewManager(kv, expectedM.myID, expectedM.partner, newM := NewManager(kv, expectedM.myID, expectedM.partner,
expectedM.originMyPrivKey, expectedM.originPartnerPubKey, expectedM.originMyPrivKey, expectedM.originPartnerPubKey,
expectedM.originMySIDHPrivKey, expectedM.originMySIDHPrivKey,
expectedM.originPartnerSIDHPubKey, session.GetDefaultParams(), expectedM.originPartnerSIDHPubKey, session.GetDefaultParams(),
session.GetDefaultParams(), session.GetDefaultParams(),
expectedM.cyHandler, expectedM.grp, expectedM.rng) expectedM.cyHandler, expectedM.grp, expectedM.rng)
m := newM.(*manager)
// Check if the new relationship matches the expected // Check if the new relationship matches the expected
if !managersEqual(expectedM, m, t) { if !managersEqual(&expectedM, m, t) {
t.Errorf("newManager() did not produce the expected Manager."+ t.Errorf("newManager() did not produce the expected Manager."+
"\n\texpected: %+v\n\treceived: %+v", expectedM, m) "\n\texpected: %+v\n\treceived: %+v", expectedM, m)
} }
...@@ -52,14 +54,15 @@ func TestLoadManager(t *testing.T) { ...@@ -52,14 +54,15 @@ func TestLoadManager(t *testing.T) {
expectedM, kv := newTestManager(t) expectedM, kv := newTestManager(t)
// Attempt to load relationship // Attempt to load relationship
m, err := LoadManager(kv, expectedM.myID, expectedM.partner, newM, err := LoadManager(kv, expectedM.myID, expectedM.partner,
expectedM.cyHandler, expectedM.grp, expectedM.rng) expectedM.cyHandler, expectedM.grp, expectedM.rng)
if err != nil { if err != nil {
t.Errorf("LoadManager() returned an error: %v", err) t.Errorf("LoadManager() returned an error: %v", err)
} }
m := newM.(*manager)
// Check if the loaded relationship matches the expected // Check if the loaded relationship matches the expected
if !managersEqual(expectedM, m, t) { if !managersEqual(&expectedM, m, t) {
t.Errorf("LoadManager() did not produce the expected Manager."+ t.Errorf("LoadManager() did not produce the expected Manager."+
"\n\texpected: %+v\n\treceived: %+v", expectedM, m) "\n\texpected: %+v\n\treceived: %+v", expectedM, m)
} }
...@@ -77,7 +80,7 @@ func TestManager_ClearManager(t *testing.T) { ...@@ -77,7 +80,7 @@ func TestManager_ClearManager(t *testing.T) {
// Set up expected and test values // Set up expected and test values
expectedM, kv := newTestManager(t) expectedM, kv := newTestManager(t)
err := ClearManager(expectedM) err := expectedM.ClearManager()
if err != nil { if err != nil {
t.Fatalf("clearManager returned an error: %v", err) t.Fatalf("clearManager returned an error: %v", err)
} }
...@@ -252,7 +255,7 @@ func TestManager_GetPartnerID(t *testing.T) { ...@@ -252,7 +255,7 @@ func TestManager_GetPartnerID(t *testing.T) {
func TestManager_GetMyID(t *testing.T) { func TestManager_GetMyID(t *testing.T) {
myId := id.NewIdFromUInt(rand.Uint64(), id.User, t) myId := id.NewIdFromUInt(rand.Uint64(), id.User, t)
m := &Manager{myID: myId} m := &manager{myID: myId}
receivedMyId := m.GetMyID() receivedMyId := m.GetMyID()
......
...@@ -148,11 +148,11 @@ func LoadRelationship(kv *versioned.KV, t session.RelationshipType, myID, ...@@ -148,11 +148,11 @@ func LoadRelationship(kv *versioned.KV, t session.RelationshipType, myID,
// DeleteRelationship removes all relationship and // DeleteRelationship removes all relationship and
// relationship adjacent information from storage // relationship adjacent information from storage
func DeleteRelationship(manager *Manager) error { func (m *manager) DeleteRelationship() error {
// Delete the send information // Delete the send information
sendKv := manager.kv.Prefix(session.Send.Prefix()) sendKv := m.kv.Prefix(session.Send.Prefix())
manager.send.Delete() m.send.Delete()
if err := deleteRelationshipFingerprint(sendKv); err != nil { if err := deleteRelationshipFingerprint(sendKv); err != nil {
return err return err
} }
...@@ -163,8 +163,8 @@ func DeleteRelationship(manager *Manager) error { ...@@ -163,8 +163,8 @@ func DeleteRelationship(manager *Manager) error {
} }
// Delete the receive information // Delete the receive information
receiveKv := manager.kv.Prefix(session.Receive.Prefix()) receiveKv := m.kv.Prefix(session.Receive.Prefix())
manager.receive.Delete() m.receive.Delete()
if err := deleteRelationshipFingerprint(receiveKv); err != nil { if err := deleteRelationshipFingerprint(receiveKv); err != nil {
return err return err
} }
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
package partner package partner
import ( import (
"reflect"
"testing"
"github.com/cloudflare/circl/dh/sidh" "github.com/cloudflare/circl/dh/sidh"
"gitlab.com/elixxir/client/e2e/ratchet/partner/session" "gitlab.com/elixxir/client/e2e/ratchet/partner/session"
util "gitlab.com/elixxir/client/storage/utility" util "gitlab.com/elixxir/client/storage/utility"
...@@ -19,8 +22,6 @@ import ( ...@@ -19,8 +22,6 @@ import (
"gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"reflect"
"testing"
) )
// Subtest: unmarshal/marshal with one session in the buff // Subtest: unmarshal/marshal with one session in the buff
...@@ -89,7 +90,7 @@ func TestDeleteRelationship(t *testing.T) { ...@@ -89,7 +90,7 @@ func TestDeleteRelationship(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err := DeleteRelationship(mgr) err := mgr.DeleteRelationship()
if err != nil { if err != nil {
t.Fatalf("DeleteRelationship error: Could not delete manager: %v", err) t.Fatalf("DeleteRelationship error: Could not delete manager: %v", err)
} }
...@@ -842,7 +843,7 @@ func TestSessionBuff_TriggerNegotiation(t *testing.T) { ...@@ -842,7 +843,7 @@ func TestSessionBuff_TriggerNegotiation(t *testing.T) {
} }
} }
func makeTestRelationshipManager(t *testing.T) (*Manager, *versioned.KV) { func makeTestRelationshipManager(t *testing.T) (*manager, *versioned.KV) {
grp := cyclic.NewGroup( grp := cyclic.NewGroup(
large.NewIntFromString("E2EE983D031DC1DB6F1A7A67DF0E9A8E5561DB8E8D49413394C049B"+ large.NewIntFromString("E2EE983D031DC1DB6F1A7A67DF0E9A8E5561DB8E8D49413394C049B"+
"7A8ACCEDC298708F121951D9CF920EC5D146727AA4AE535B0922C688B55B3DD2AE"+ "7A8ACCEDC298708F121951D9CF920EC5D146727AA4AE535B0922C688B55B3DD2AE"+
...@@ -876,7 +877,7 @@ func makeTestRelationshipManager(t *testing.T) (*Manager, *versioned.KV) { ...@@ -876,7 +877,7 @@ func makeTestRelationshipManager(t *testing.T) (*Manager, *versioned.KV) {
kv := versioned.NewKV(make(ekv.Memstore)) kv := versioned.NewKV(make(ekv.Memstore))
frng := fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG) frng := fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG)
return &Manager{ return &manager{
kv: kv, kv: kv,
myID: myID, myID: myID,
partner: id.NewIdFromString("zezima", id.User, t), partner: id.NewIdFromString("zezima", id.User, t),
......
...@@ -2,6 +2,9 @@ package partner ...@@ -2,6 +2,9 @@ package partner
import ( import (
"bytes" "bytes"
"reflect"
"testing"
"github.com/cloudflare/circl/dh/sidh" "github.com/cloudflare/circl/dh/sidh"
"gitlab.com/elixxir/client/e2e/ratchet/partner/session" "gitlab.com/elixxir/client/e2e/ratchet/partner/session"
util "gitlab.com/elixxir/client/storage/utility" util "gitlab.com/elixxir/client/storage/utility"
...@@ -13,8 +16,6 @@ import ( ...@@ -13,8 +16,6 @@ import (
"gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"reflect"
"testing"
) )
type mockCyHandler struct { type mockCyHandler struct {
...@@ -50,7 +51,7 @@ func getGroup() *cyclic.Group { ...@@ -50,7 +51,7 @@ func getGroup() *cyclic.Group {
} }
// newTestManager returns a new relationship for testing. // newTestManager returns a new relationship for testing.
func newTestManager(t *testing.T) (*Manager, *versioned.KV) { func newTestManager(t *testing.T) (manager, *versioned.KV) {
if t == nil { if t == nil {
panic("Cannot run this outside tests") panic("Cannot run this outside tests")
} }
...@@ -83,10 +84,12 @@ func newTestManager(t *testing.T) (*Manager, *versioned.KV) { ...@@ -83,10 +84,12 @@ func newTestManager(t *testing.T) (*Manager, *versioned.KV) {
mockCyHandler{}, grp, mockCyHandler{}, grp,
fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG)) fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG))
return m, kv newM := m.(*manager)
return *newM, kv
} }
func managersEqual(expected, received *Manager, t *testing.T) bool { func managersEqual(expected, received *manager, t *testing.T) bool {
equal := true equal := true
if !reflect.DeepEqual(expected.cyHandler, received.cyHandler) { if !reflect.DeepEqual(expected.cyHandler, received.cyHandler) {
t.Errorf("Did not Receive expected Manager.cyHandler."+ t.Errorf("Did not Receive expected Manager.cyHandler."+
......
...@@ -33,7 +33,7 @@ const ( ...@@ -33,7 +33,7 @@ const (
var NoPartnerErrorStr = "No relationship with partner found" var NoPartnerErrorStr = "No relationship with partner found"
type Ratchet struct { type Ratchet struct {
managers map[id.ID]*partner.Manager managers map[id.ID]partner.Manager
mux sync.RWMutex mux sync.RWMutex
myID *id.ID myID *id.ID
...@@ -66,7 +66,7 @@ func New(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, ...@@ -66,7 +66,7 @@ func New(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int,
kv = kv.Prefix(packagePrefix) kv = kv.Prefix(packagePrefix)
r := &Ratchet{ r := &Ratchet{
managers: make(map[id.ID]*partner.Manager), managers: make(map[id.ID]partner.Manager),
services: make(map[string]message.Processor), services: make(map[string]message.Processor),
myID: myID, myID: myID,
...@@ -98,7 +98,7 @@ func New(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, ...@@ -98,7 +98,7 @@ func New(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int,
func (r *Ratchet) AddPartner(partnerID *id.ID, func (r *Ratchet) AddPartner(partnerID *id.ID,
partnerPubKey, myPrivKey *cyclic.Int, partnerSIDHPubKey *sidh.PublicKey, partnerPubKey, myPrivKey *cyclic.Int, partnerSIDHPubKey *sidh.PublicKey,
mySIDHPrivKey *sidh.PrivateKey, sendParams, mySIDHPrivKey *sidh.PrivateKey, sendParams,
receiveParams session.Params) (*partner.Manager, error) { receiveParams session.Params) (partner.Manager, error) {
r.mux.Lock() r.mux.Lock()
defer r.mux.Unlock() defer r.mux.Unlock()
...@@ -132,7 +132,7 @@ func (r *Ratchet) AddPartner(partnerID *id.ID, ...@@ -132,7 +132,7 @@ func (r *Ratchet) AddPartner(partnerID *id.ID,
} }
// GetPartner returns the partner per its ID, if it exists // GetPartner returns the partner per its ID, if it exists
func (r *Ratchet) GetPartner(partnerID *id.ID) (*partner.Manager, error) { func (r *Ratchet) GetPartner(partnerID *id.ID) (partner.Manager, error) {
r.mux.RLock() r.mux.RLock()
defer r.mux.RUnlock() defer r.mux.RUnlock()
...@@ -152,7 +152,7 @@ func (r *Ratchet) DeletePartner(partnerID *id.ID) error { ...@@ -152,7 +152,7 @@ func (r *Ratchet) DeletePartner(partnerID *id.ID) error {
return errors.New(NoPartnerErrorStr) return errors.New(NoPartnerErrorStr)
} }
if err := partner.ClearManager(m); err != nil { if err := m.ClearManager(); err != nil {
return errors.WithMessagef(err, return errors.WithMessagef(err,
"Could not remove partner %s from store", "Could not remove partner %s from store",
partnerID) partnerID)
......
...@@ -32,7 +32,7 @@ func TestNewStore(t *testing.T) { ...@@ -32,7 +32,7 @@ func TestNewStore(t *testing.T) {
privKey := grp.NewInt(57) privKey := grp.NewInt(57)
kv := versioned.NewKV(make(ekv.Memstore)) kv := versioned.NewKV(make(ekv.Memstore))
expectedStore := &Ratchet{ expectedStore := &Ratchet{
managers: make(map[id.ID]*partner.Manager), managers: make(map[id.ID]partner.Manager),
myInitialDHPrivateKey: privKey, myInitialDHPrivateKey: privKey,
myInitialDHPublicKey: diffieHellman.GeneratePublicKey(privKey, grp), myInitialDHPublicKey: diffieHellman.GeneratePublicKey(privKey, grp),
grp: grp, grp: grp,
......
...@@ -15,7 +15,7 @@ type Services interface { ...@@ -15,7 +15,7 @@ type Services interface {
processor message.Processor) processor message.Processor)
} }
func (r *Ratchet) add(m *partner.Manager) { func (r *Ratchet) add(m partner.Manager) {
r.servicesmux.RLock() r.servicesmux.RLock()
defer r.servicesmux.RUnlock() defer r.servicesmux.RUnlock()
for tag, process := range r.services { for tag, process := range r.services {
...@@ -23,7 +23,7 @@ func (r *Ratchet) add(m *partner.Manager) { ...@@ -23,7 +23,7 @@ func (r *Ratchet) add(m *partner.Manager) {
} }
} }
func (r *Ratchet) delete(m *partner.Manager) { func (r *Ratchet) delete(m partner.Manager) {
r.servicesmux.RLock() r.servicesmux.RLock()
defer r.servicesmux.RUnlock() defer r.servicesmux.RUnlock()
for tag, process := range r.services { for tag, process := range r.services {
......
...@@ -28,7 +28,7 @@ func Load(kv *versioned.KV, myID *id.ID, grp *cyclic.Group, ...@@ -28,7 +28,7 @@ func Load(kv *versioned.KV, myID *id.ID, grp *cyclic.Group,
kv = kv.Prefix(packagePrefix) kv = kv.Prefix(packagePrefix)
r := &Ratchet{ r := &Ratchet{
managers: make(map[id.ID]*partner.Manager), managers: make(map[id.ID]partner.Manager),
services: make(map[string]message.Processor), services: make(map[string]message.Processor),
myID: myID, myID: myID,
......
package ratchet package ratchet
import ( import (
"io"
"reflect"
"strings"
"testing"
"github.com/cloudflare/circl/dh/sidh" "github.com/cloudflare/circl/dh/sidh"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/client/cmix/message" "gitlab.com/elixxir/client/cmix/message"
...@@ -14,10 +19,6 @@ import ( ...@@ -14,10 +19,6 @@ import (
"gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"io"
"reflect"
"strings"
"testing"
) )
func makeTestRatchet() (*Ratchet, *versioned.KV, error) { func makeTestRatchet() (*Ratchet, *versioned.KV, error) {
...@@ -42,7 +43,7 @@ func makeTestRatchet() (*Ratchet, *versioned.KV, error) { ...@@ -42,7 +43,7 @@ func makeTestRatchet() (*Ratchet, *versioned.KV, error) {
return r, kv, err return r, kv, err
} }
func managersEqual(expected, received *partner.Manager, t *testing.T) bool { func managersEqual(expected, received partner.Manager, t *testing.T) bool {
equal := true equal := true
if !reflect.DeepEqual(expected.GetPartnerID(), received.GetPartnerID()) { if !reflect.DeepEqual(expected.GetPartnerID(), received.GetPartnerID()) {
t.Errorf("Did not Receive expected Manager.partnerID."+ t.Errorf("Did not Receive expected Manager.partnerID."+
......
...@@ -9,6 +9,8 @@ package rekey ...@@ -9,6 +9,8 @@ package rekey
import ( import (
"fmt" "fmt"
"time"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
...@@ -22,11 +24,10 @@ import ( ...@@ -22,11 +24,10 @@ import (
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/primitives/states" "gitlab.com/elixxir/primitives/states"
"time"
) )
func CheckKeyExchanges(instance *commsNetwork.Instance, grp *cyclic.Group, func CheckKeyExchanges(instance *commsNetwork.Instance, grp *cyclic.Group,
sendE2E E2eSender, events event.Manager, manager *partner.Manager, sendE2E E2eSender, events event.Manager, manager partner.Manager,
param Params, sendTimeout time.Duration) { param Params, sendTimeout time.Duration) {
//get all sessions that may need a key exchange //get all sessions that may need a key exchange
...@@ -44,7 +45,7 @@ func CheckKeyExchanges(instance *commsNetwork.Instance, grp *cyclic.Group, ...@@ -44,7 +45,7 @@ func CheckKeyExchanges(instance *commsNetwork.Instance, grp *cyclic.Group,
// session. They run the same negotiation, the former does it on a newly created // session. They run the same negotiation, the former does it on a newly created
// session while the latter on an extant session // session while the latter on an extant session
func trigger(instance *commsNetwork.Instance, grp *cyclic.Group, sendE2E E2eSender, func trigger(instance *commsNetwork.Instance, grp *cyclic.Group, sendE2E E2eSender,
events event.Manager, manager *partner.Manager, inputSession *session.Session, events event.Manager, manager partner.Manager, inputSession *session.Session,
sendTimeout time.Duration, params Params) { sendTimeout time.Duration, params Params) {
var negotiatingSession *session.Session var negotiatingSession *session.Session
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment