diff --git a/e2e/interface.go b/e2e/interface.go index 670311b885e461e9a89242d6c2a98d18a77f3afa..ac9590649c7038ac1d1ab04cfd8361d777192f8f 100644 --- a/e2e/interface.go +++ b/e2e/interface.go @@ -49,7 +49,7 @@ type Handler interface { // pass nil to this. // // If a message matches multiple listeners, all of them will hear the message. - RegisterListener(user *id.ID, messageType catalog.MessageType, + RegisterListener(senderID *id.ID, messageType catalog.MessageType, newListener receive.Listener) receive.ListenerID // RegisterFunc Registers a new listener built around the passed function. @@ -66,7 +66,7 @@ type Handler interface { // Do not pass nil to this. // // If a message matches multiple listeners, all of them will hear the message. - RegisterFunc(name string, user *id.ID, messageType catalog.MessageType, + RegisterFunc(name string, senderID *id.ID, messageType catalog.MessageType, newListener receive.ListenerFunc) receive.ListenerID // RegisterChannel Registers a new listener built around the passed channel. @@ -83,7 +83,7 @@ type Handler interface { // Do not pass nil to this. // // If a message matches multiple listeners, all of them will hear the message. - RegisterChannel(name string, user *id.ID, messageType catalog.MessageType, + RegisterChannel(name string, senderID *id.ID, messageType catalog.MessageType, newListener chan receive.Message) receive.ListenerID // Unregister removes the listener with the specified ID so it will no longer @@ -98,7 +98,7 @@ type Handler interface { // then pass them in, otherwise, leave myID and myPrivateKey nil // If temporary is true, an alternate ram kv will be used for storage and // the relationship will not survive a reset - AddPartner(myID *id.ID, partnerID *id.ID, + AddPartner(partnerID *id.ID, partnerPubKey, myPrivKey *cyclic.Int, partnerSIDHPubKey *sidh.PublicKey, mySIDHPrivKey *sidh.PrivateKey, sendParams, receiveParams session.Params) (*partner.Manager, error) @@ -106,16 +106,16 @@ type Handler interface { // GetPartner returns the partner per its ID, if it exists // myID is your ID in the relationship, if left blank, it will // assume to be your defaultID - GetPartner(partnerID *id.ID, myID *id.ID) (*partner.Manager, error) + GetPartner(partnerID *id.ID) (*partner.Manager, error) // DeletePartner removes the associated contact from the E2E store // myID is your ID in the relationship, if left blank, it will // assume to be your defaultID - DeletePartner(partnerId *id.ID, myID *id.ID) error + DeletePartner(partnerId *id.ID) error // GetAllPartnerIDs returns a list of all partner IDs that the user has // an E2E relationship with. - GetAllPartnerIDs(myID *id.ID) []*id.ID + GetAllPartnerIDs() []*id.ID /* === Services ========================================================= */ @@ -155,12 +155,12 @@ type Handler interface { // GetGroup returns the cyclic group used for end to end encruption GetGroup() *cyclic.Group - // GetDefaultHistoricalDHPubkey returns the default user's Historical DH Public Key - GetDefaultHistoricalDHPubkey() *cyclic.Int + // GetHistoricalDHPubkey returns the default user's Historical DH Public Key + GetHistoricalDHPubkey() *cyclic.Int - // GetDefaultHistoricalDHPrivkey returns the default user's Historical DH Private Key - GetDefaultHistoricalDHPrivkey() *cyclic.Int + // GetHistoricalDHPrivkey returns the default user's Historical DH Private Key + GetHistoricalDHPrivkey() *cyclic.Int - // GetDefaultID returns the default IDs - GetDefaultID() *id.ID + // GetReceptionID returns the default IDs + GetReceptionID() *id.ID } diff --git a/e2e/manager.go b/e2e/manager.go index 56c940e8a436f0bc366e02a5a60834f7e339cb8d..aac3cb2040cbc849ebec1b97f9c9c5e00f1d3767 100644 --- a/e2e/manager.go +++ b/e2e/manager.go @@ -37,9 +37,19 @@ const e2eRekeyParamsKey = "e2eRekeyParams" const e2eRekeyParamsVer = 0 // Init Creates stores. After calling, use load -// Passes a default ID and public key which is used for relationship with -// partners when no default ID is selected -func Init(kv *versioned.KV, myDefaultID *id.ID, privKey *cyclic.Int, +// Passes a the ID public key which is used for the relationship +// uses the passed ID to modify the kv prefix for a unique storage path +func Init(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, + grp *cyclic.Group, rekeyParams rekey.Params) error { + kv = kv.Prefix(makeE2ePrefix(myID)) + return InitLegacy(kv, myID, privKey, grp, rekeyParams) +} + +// InitLegacy Creates stores. After calling, use load +// Passes a the ID public key which is used for the relationship +// Does not modify the kv prefix in any way to maintain backwards compatibility +// before multiple IDs were supported +func InitLegacy(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, grp *cyclic.Group, rekeyParams rekey.Params) error { rekeyParamsData, err := json.Marshal(rekeyParams) if err != nil { @@ -53,13 +63,21 @@ func Init(kv *versioned.KV, myDefaultID *id.ID, privKey *cyclic.Int, if err != nil { return errors.WithMessage(err, "Failed to save rekeyParams") } - return ratchet.New(kv, myDefaultID, privKey, grp) + return ratchet.New(kv, myID, privKey, grp) } -// Load returns an e2e manager from storage +func Load(kv *versioned.KV, net cmix.Client, myDefaultID *id.ID, + grp *cyclic.Group, rng *fastRNG.StreamGenerator, events event.Manager) ( + Handler, error) { + +} + +// LoadLegacy returns an e2e manager from storage // Passes a default ID which is used for relationship with // partners when no default ID is selected -func Load(kv *versioned.KV, net cmix.Client, myDefaultID *id.ID, +// Does not modify the kv prefix in any way to maintain backwards compatibility +// before multiple IDs were supported +func LoadLegacy(kv *versioned.KV, net cmix.Client, myDefaultID *id.ID, grp *cyclic.Group, rng *fastRNG.StreamGenerator, events event.Manager) (Handler, error) { //build the manager @@ -141,3 +159,7 @@ func (m *manager) EnableUnsafeReception() { tag: ratchet.E2e, }) } + +func makeE2ePrefix(myid *id.ID) string { + return "e2eStore:" + myid.String() +} diff --git a/e2e/util.go b/e2e/util.go index 8acd9cac3415a76f21fa4e7ca41f4dc9f10d06ed..800058c50468ebc379f68790728548770fa42185 100644 --- a/e2e/util.go +++ b/e2e/util.go @@ -11,16 +11,16 @@ func (m *manager) GetGroup() *cyclic.Group { } // GetDefaultHistoricalDHPubkey returns the default user's Historical DH Public Key -func (m *manager) GetDefaultHistoricalDHPubkey() *cyclic.Int { +func (m *manager) GetHistoricalDHPubkey() *cyclic.Int { return m.Ratchet.GetDHPublicKey() } // GetDefaultHistoricalDHPrivkey returns the default user's Historical DH Private Key -func (m *manager) GetDefaultHistoricalDHPrivkey() *cyclic.Int { +func (m *manager) GetHistoricalDHPrivkey() *cyclic.Int { return m.Ratchet.GetDHPrivateKey() } // GetDefaultID returns the default IDs -func (m *manager) GetDefaultID() *id.ID { +func (m *manager) GetReceptionID() *id.ID { return m.myDefaultID } diff --git a/groupChat/manager.go b/groupChat/manager.go index 85f4926babb9f1f7bd25d0dcfa3079d024afaf96..c5ec117c76ae0903487c7c6b7d015294bb616e33 100644 --- a/groupChat/manager.go +++ b/groupChat/manager.go @@ -50,7 +50,7 @@ func NewManager(services cmix.Client, e2e e2e.Handler, receptionId *id.ID, // Load the group chat storage or create one if one does not exist gStore, err := gs.NewOrLoadStore( - kv, group.Member{ID: receptionId, DhKey: e2e.GetDefaultHistoricalDHPubkey()}) + kv, group.Member{ID: receptionId, DhKey: e2e.GetHistoricalDHPubkey()}) if err != nil { return nil, errors.Errorf(newGroupStoreErr, err) } diff --git a/groupChat/manager_test.go b/groupChat/manager_test.go index 48ee13ea8b0f5ef46df8c742c2665b560c38d400..9cf51c8bcded7fd73381fff79d05a2cf57027604 100644 --- a/groupChat/manager_test.go +++ b/groupChat/manager_test.go @@ -274,7 +274,7 @@ func Test_newManager_LoadError(t *testing.T) { func TestManager_JoinGroup(t *testing.T) { prng := rand.New(rand.NewSource(42)) m, _ := newTestManagerWithStore(prng, 10, 0, nil, nil, t) - g := newTestGroup(m.grp, m.e2e.GetDefaultHistoricalDHPubkey(), prng, t) + g := newTestGroup(m.grp, m.e2e.GetHistoricalDHPubkey(), prng, t) err := m.JoinGroup(g) if err != nil { diff --git a/groupChat/receiveRequest_test.go b/groupChat/receiveRequest_test.go index 8fdaa1f02f7e292efb259be2017a54970397806f..294198f92544d49353e6e6a2f3244cb6742b6737 100644 --- a/groupChat/receiveRequest_test.go +++ b/groupChat/receiveRequest_test.go @@ -28,8 +28,8 @@ func TestManager_receiveRequest(t *testing.T) { requestFunc := func(g gs.Group) { requestChan <- g } m, _ := newTestManagerWithStore(prng, 10, 0, requestFunc, nil, t) g := newTestGroupWithUser(m.grp, - m.receptionId, m.e2e.GetDefaultHistoricalDHPubkey(), - m.e2e.GetDefaultHistoricalDHPrivkey(), prng, t) + m.receptionId, m.e2e.GetHistoricalDHPubkey(), + m.e2e.GetHistoricalDHPrivkey(), prng, t) requestMarshaled, err := proto.Marshal(&Request{ Name: g.Name,