Skip to content
Snippets Groups Projects
Commit ae5df0c3 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

started removign my ID in e2e

parent 4029f414
No related branches found
No related tags found
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
...@@ -49,7 +49,7 @@ type Handler interface { ...@@ -49,7 +49,7 @@ type Handler interface {
// pass nil to this. // pass nil to this.
// //
// If a message matches multiple listeners, all of them will hear the message. // 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 newListener receive.Listener) receive.ListenerID
// RegisterFunc Registers a new listener built around the passed function. // RegisterFunc Registers a new listener built around the passed function.
...@@ -66,7 +66,7 @@ type Handler interface { ...@@ -66,7 +66,7 @@ type Handler interface {
// Do not pass nil to this. // Do not pass nil to this.
// //
// If a message matches multiple listeners, all of them will hear the message. // 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 newListener receive.ListenerFunc) receive.ListenerID
// RegisterChannel Registers a new listener built around the passed channel. // RegisterChannel Registers a new listener built around the passed channel.
...@@ -83,7 +83,7 @@ type Handler interface { ...@@ -83,7 +83,7 @@ type Handler interface {
// Do not pass nil to this. // Do not pass nil to this.
// //
// If a message matches multiple listeners, all of them will hear the message. // 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 newListener chan receive.Message) receive.ListenerID
// Unregister removes the listener with the specified ID so it will no longer // Unregister removes the listener with the specified ID so it will no longer
...@@ -98,7 +98,7 @@ type Handler interface { ...@@ -98,7 +98,7 @@ type Handler interface {
// then pass them in, otherwise, leave myID and myPrivateKey nil // then pass them in, otherwise, leave myID and myPrivateKey nil
// If temporary is true, an alternate ram kv will be used for storage and // If temporary is true, an alternate ram kv will be used for storage and
// the relationship will not survive a reset // 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, 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)
...@@ -106,16 +106,16 @@ type Handler interface { ...@@ -106,16 +106,16 @@ type Handler interface {
// 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, myID *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
// assume to be your defaultID // 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 // GetAllPartnerIDs returns a list of all partner IDs that the user has
// an E2E relationship with. // an E2E relationship with.
GetAllPartnerIDs(myID *id.ID) []*id.ID GetAllPartnerIDs() []*id.ID
/* === Services ========================================================= */ /* === Services ========================================================= */
...@@ -155,12 +155,12 @@ type Handler interface { ...@@ -155,12 +155,12 @@ type Handler interface {
// GetGroup returns the cyclic group used for end to end encruption // GetGroup returns the cyclic group used for end to end encruption
GetGroup() *cyclic.Group GetGroup() *cyclic.Group
// GetDefaultHistoricalDHPubkey returns the default user's Historical DH Public Key // GetHistoricalDHPubkey returns the default user's Historical DH Public Key
GetDefaultHistoricalDHPubkey() *cyclic.Int GetHistoricalDHPubkey() *cyclic.Int
// GetDefaultHistoricalDHPrivkey returns the default user's Historical DH Private Key // GetHistoricalDHPrivkey returns the default user's Historical DH Private Key
GetDefaultHistoricalDHPrivkey() *cyclic.Int GetHistoricalDHPrivkey() *cyclic.Int
// GetDefaultID returns the default IDs // GetReceptionID returns the default IDs
GetDefaultID() *id.ID GetReceptionID() *id.ID
} }
...@@ -37,9 +37,19 @@ const e2eRekeyParamsKey = "e2eRekeyParams" ...@@ -37,9 +37,19 @@ const e2eRekeyParamsKey = "e2eRekeyParams"
const e2eRekeyParamsVer = 0 const e2eRekeyParamsVer = 0
// Init Creates stores. After calling, use load // Init Creates stores. After calling, use load
// Passes a default ID and public key which is used for relationship with // Passes a the ID public key which is used for the relationship
// partners when no default ID is selected // uses the passed ID to modify the kv prefix for a unique storage path
func Init(kv *versioned.KV, myDefaultID *id.ID, privKey *cyclic.Int, 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 { grp *cyclic.Group, rekeyParams rekey.Params) error {
rekeyParamsData, err := json.Marshal(rekeyParams) rekeyParamsData, err := json.Marshal(rekeyParams)
if err != nil { if err != nil {
...@@ -53,13 +63,21 @@ func Init(kv *versioned.KV, myDefaultID *id.ID, privKey *cyclic.Int, ...@@ -53,13 +63,21 @@ func Init(kv *versioned.KV, myDefaultID *id.ID, privKey *cyclic.Int,
if err != nil { if err != nil {
return errors.WithMessage(err, "Failed to save rekeyParams") 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 // Passes a default ID which is used for relationship with
// partners when no default ID is selected // 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) { grp *cyclic.Group, rng *fastRNG.StreamGenerator, events event.Manager) (Handler, error) {
//build the manager //build the manager
...@@ -141,3 +159,7 @@ func (m *manager) EnableUnsafeReception() { ...@@ -141,3 +159,7 @@ func (m *manager) EnableUnsafeReception() {
tag: ratchet.E2e, tag: ratchet.E2e,
}) })
} }
func makeE2ePrefix(myid *id.ID) string {
return "e2eStore:" + myid.String()
}
...@@ -11,16 +11,16 @@ func (m *manager) GetGroup() *cyclic.Group { ...@@ -11,16 +11,16 @@ func (m *manager) GetGroup() *cyclic.Group {
} }
// GetDefaultHistoricalDHPubkey returns the default user's Historical DH Public Key // 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() return m.Ratchet.GetDHPublicKey()
} }
// GetDefaultHistoricalDHPrivkey returns the default user's Historical DH Private Key // 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() return m.Ratchet.GetDHPrivateKey()
} }
// GetDefaultID returns the default IDs // GetDefaultID returns the default IDs
func (m *manager) GetDefaultID() *id.ID { func (m *manager) GetReceptionID() *id.ID {
return m.myDefaultID return m.myDefaultID
} }
...@@ -50,7 +50,7 @@ func NewManager(services cmix.Client, e2e e2e.Handler, receptionId *id.ID, ...@@ -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 // Load the group chat storage or create one if one does not exist
gStore, err := gs.NewOrLoadStore( gStore, err := gs.NewOrLoadStore(
kv, group.Member{ID: receptionId, DhKey: e2e.GetDefaultHistoricalDHPubkey()}) kv, group.Member{ID: receptionId, DhKey: e2e.GetHistoricalDHPubkey()})
if err != nil { if err != nil {
return nil, errors.Errorf(newGroupStoreErr, err) return nil, errors.Errorf(newGroupStoreErr, err)
} }
......
...@@ -274,7 +274,7 @@ func Test_newManager_LoadError(t *testing.T) { ...@@ -274,7 +274,7 @@ func Test_newManager_LoadError(t *testing.T) {
func TestManager_JoinGroup(t *testing.T) { func TestManager_JoinGroup(t *testing.T) {
prng := rand.New(rand.NewSource(42)) prng := rand.New(rand.NewSource(42))
m, _ := newTestManagerWithStore(prng, 10, 0, nil, nil, t) 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) err := m.JoinGroup(g)
if err != nil { if err != nil {
......
...@@ -28,8 +28,8 @@ func TestManager_receiveRequest(t *testing.T) { ...@@ -28,8 +28,8 @@ func TestManager_receiveRequest(t *testing.T) {
requestFunc := func(g gs.Group) { requestChan <- g } requestFunc := func(g gs.Group) { requestChan <- g }
m, _ := newTestManagerWithStore(prng, 10, 0, requestFunc, nil, t) m, _ := newTestManagerWithStore(prng, 10, 0, requestFunc, nil, t)
g := newTestGroupWithUser(m.grp, g := newTestGroupWithUser(m.grp,
m.receptionId, m.e2e.GetDefaultHistoricalDHPubkey(), m.receptionId, m.e2e.GetHistoricalDHPubkey(),
m.e2e.GetDefaultHistoricalDHPrivkey(), prng, t) m.e2e.GetHistoricalDHPrivkey(), prng, t)
requestMarshaled, err := proto.Marshal(&Request{ requestMarshaled, err := proto.Marshal(&Request{
Name: g.Name, Name: g.Name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment