diff --git a/auth/interface.go b/auth/interface.go index ac0b1c4b89e18adf9f8ecd90952aee723ad2aaff..f44e221acf77e303b0e19559d5a3410335fa7a56 100644 --- a/auth/interface.go +++ b/auth/interface.go @@ -57,7 +57,7 @@ type State interface { // This will not be useful if either side has ratcheted ReplayConfirm(partner *id.ID) (id.Round, error) - // CallReceivedRequests will iterate through all pending contact requests + // CallAllReceivedRequests will iterate through all pending contact requests // and replay them on the callbacks. - CallReceivedRequests() + CallAllReceivedRequests() } diff --git a/auth/state.go b/auth/state.go index ef311d23a9711a89b99ae9ec7c337ea26a28d19a..d4a8fdb87f89dee32e9af3ada8e5a25cff09e701 100644 --- a/auth/state.go +++ b/auth/state.go @@ -112,9 +112,9 @@ func NewStateLegacy(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, return s, nil } -// CallReceivedRequests will iterate through all pending contact requests and replay +// CallAllReceivedRequests will iterate through all pending contact requests and replay // them on the callbacks. -func (s *state) CallReceivedRequests() { +func (s *state) CallAllReceivedRequests() { rrList := s.store.GetAllReceivedRequests() for i := range rrList { rr := rrList[i] diff --git a/e2e/ratchet/partner/interface.go b/e2e/ratchet/partner/interface.go index 6877291c48c81e332e044ebbb9a4042d1cf6dfcd..06a3aadc624daad3324144d30c9790679e8700d6 100644 --- a/e2e/ratchet/partner/interface.go +++ b/e2e/ratchet/partner/interface.go @@ -10,26 +10,39 @@ import ( ) type Manager interface { + //accessors + GetPartnerID() *id.ID + GetMyID() *id.ID + GetMyOriginPrivateKey() *cyclic.Int + GetPartnerOriginPublicKey() *cyclic.Int + + GetSendRelationshipFingerprint() []byte + GetReceiveRelationshipFingerprint() []byte + + GetConnectionFingerprintBytes() []byte + GetConnectionFingerprint() string + GetContact() contact.Contact + + //sending and receving + PopSendCypher() (*session.Cypher, error) + PopRekeyCypher() (*session.Cypher, error) + + //Ratcheting NewReceiveSession(partnerPubKey *cyclic.Int, partnerSIDHPubKey *sidh.PublicKey, e2eParams session.Params, source *session.Session) (*session.Session, bool) NewSendSession(myDHPrivKey *cyclic.Int, mySIDHPrivateKey *sidh.PrivateKey, e2eParams session.Params, source *session.Session) *session.Session - PopSendCypher() (*session.Cypher, error) - PopRekeyCypher() (*session.Cypher, error) - GetPartnerID() *id.ID - GetMyID() *id.ID GetSendSession(sid session.SessionID) *session.Session + + //state machine GetReceiveSession(sid session.SessionID) *session.Session Confirm(sid session.SessionID) error TriggerNegotiations() []*session.Session - GetMyOriginPrivateKey() *cyclic.Int - GetPartnerOriginPublicKey() *cyclic.Int - GetSendRelationshipFingerprint() []byte - GetRelationshipFingerprintBytes() []byte - GetRelationshipFingerprint() string + + //services MakeService(tag string) message.Service - GetContact() contact.Contact - DeleteRelationship() error - ClearManager() error + + //storage + Delete() error } diff --git a/e2e/ratchet/partner/manager.go b/e2e/ratchet/partner/manager.go index a8e482cc4acbc53c14f6680a9f94825391b27fe6..789bb3b2e74bc3d0864e423fa4859a3241a4d1d3 100644 --- a/e2e/ratchet/partner/manager.go +++ b/e2e/ratchet/partner/manager.go @@ -141,11 +141,11 @@ func LoadManager(kv *versioned.KV, myID, partnerID *id.ID, return m, nil } -// ClearManager removes the relationship between the partner +// Delete removes the relationship between the partner // and deletes the Send and Receive sessions. This includes the // sessions and the key vectors -func (m *manager) ClearManager() error { - if err := m.DeleteRelationship(); err != nil { +func (m *manager) Delete() error { + if err := m.deleteRelationships(); err != nil { return errors.WithMessage(err, "Failed to delete relationship") } @@ -159,6 +159,37 @@ func (m *manager) ClearManager() error { return nil } +// deleteRelationships removes all relationship and +// relationship adjacent information from storage +func (m *manager) deleteRelationships() error { + + // Delete the send information + sendKv := m.kv.Prefix(session.Send.Prefix()) + m.send.Delete() + if err := deleteRelationshipFingerprint(sendKv); err != nil { + return err + } + if err := sendKv.Delete(relationshipKey, + currentRelationshipVersion); err != nil { + return errors.Errorf("cannot delete send relationship: %v", + err) + } + + // Delete the receive information + receiveKv := m.kv.Prefix(session.Receive.Prefix()) + m.receive.Delete() + if err := deleteRelationshipFingerprint(receiveKv); err != nil { + return err + } + if err := receiveKv.Delete(relationshipKey, + currentRelationshipVersion); err != nil { + return errors.Errorf("cannot delete receive relationship: %v", + err) + } + + return nil +} + // NewReceiveSession creates a new Receive session using the latest private key // this user has sent and the new public key received from the partner. If the // session already exists, then it will not be overwritten and the extant @@ -235,12 +266,18 @@ func (m *manager) GetReceiveSession(sid session.SessionID) *session.Session { return m.receive.GetByID(sid) } -// GetSendSession gets the Send session of the passed ID. Returns nil if no +// GetSendRelationshipFingerprint gets the Send session of the passed ID. Returns nil if no // session is found. func (m *manager) GetSendRelationshipFingerprint() []byte { return m.send.fingerprint } +// GetReceiveRelationshipFingerprint gets the receive session of the passed ID. +// Returns nil if no session is found. +func (m *manager) GetReceiveRelationshipFingerprint() []byte { + return m.receive.fingerprint +} + // Confirm confirms a Send session is known about by the partner. func (m *manager) Confirm(sid session.SessionID) error { return m.send.Confirm(sid) @@ -265,16 +302,16 @@ const relationshipFpLength = 15 // GetRelationshipFingerprint returns a unique fingerprint for an E2E // relationship. The fingerprint is a base 64 encoded hash of of the two // relationship fingerprints truncated to 15 characters. -func (m *manager) GetRelationshipFingerprint() string { +func (m *manager) GetConnectionFingerprint() string { // Base 64 encode hash and truncate return base64.StdEncoding.EncodeToString( - m.GetRelationshipFingerprintBytes())[:relationshipFpLength] + m.GetConnectionFingerprintBytes())[:relationshipFpLength] } // GetRelationshipFingerprintBytes returns a unique fingerprint for an E2E // relationship. used for the e2e preimage. -func (m *manager) GetRelationshipFingerprintBytes() []byte { +func (m *manager) GetConnectionFingerprintBytes() []byte { // Sort fingerprints var fps [][]byte @@ -299,7 +336,7 @@ func (m *manager) GetRelationshipFingerprintBytes() []byte { // the metadata with the partner func (m *manager) MakeService(tag string) message.Service { return message.Service{ - Identifier: m.GetRelationshipFingerprintBytes(), + Identifier: m.GetConnectionFingerprintBytes(), Tag: tag, Metadata: m.partner[:], } diff --git a/e2e/ratchet/partner/manager_test.go b/e2e/ratchet/partner/manager_test.go index f0ffd05b9fac33be86ad92ae514bdff4f8927d2b..944121e069191ebd0946df8e33548f32fb7e64fa 100644 --- a/e2e/ratchet/partner/manager_test.go +++ b/e2e/ratchet/partner/manager_test.go @@ -80,7 +80,7 @@ func TestManager_ClearManager(t *testing.T) { // Set up expected and test values expectedM, kv := newTestManager(t) - err := expectedM.ClearManager() + err := expectedM.Delete() if err != nil { t.Fatalf("clearManager returned an error: %v", err) } @@ -345,18 +345,18 @@ func TestManager_GetRelationshipFingerprint(t *testing.T) { h.Write(append(m.receive.fingerprint, m.send.fingerprint...)) expected := base64.StdEncoding.EncodeToString(h.Sum(nil))[:relationshipFpLength] - fp := m.GetRelationshipFingerprint() + fp := m.GetConnectionFingerprint() if fp != expected { - t.Errorf("GetRelationshipFingerprint did not return the expected "+ + t.Errorf("GetConnectionFingerprint did not return the expected "+ "fingerprint.\nexpected: %s\nreceived: %s", expected, fp) } // Flip the order and show that the output is the same. m.receive.fingerprint, m.send.fingerprint = m.send.fingerprint, m.receive.fingerprint - fp = m.GetRelationshipFingerprint() + fp = m.GetConnectionFingerprint() if fp != expected { - t.Errorf("GetRelationshipFingerprint did not return the expected "+ + t.Errorf("GetConnectionFingerprint did not return the expected "+ "fingerprint.\nexpected: %s\nreceived: %s", expected, fp) } } @@ -379,18 +379,18 @@ func TestManager_GetRelationshipFingerprint_Consistency(t *testing.T) { prng.Read(m.receive.fingerprint) prng.Read(m.send.fingerprint) - fp := m.GetRelationshipFingerprint() + fp := m.GetConnectionFingerprint() if fp != expected { - t.Errorf("GetRelationshipFingerprint did not return the expected "+ + t.Errorf("GetConnectionFingerprint did not return the expected "+ "fingerprint (%d).\nexpected: %s\nreceived: %s", i, expected, fp) } // Flip the order and show that the output is the same. m.receive.fingerprint, m.send.fingerprint = m.send.fingerprint, m.receive.fingerprint - fp = m.GetRelationshipFingerprint() + fp = m.GetConnectionFingerprint() if fp != expected { - t.Errorf("GetRelationshipFingerprint did not return the expected "+ + t.Errorf("GetConnectionFingerprint did not return the expected "+ "fingerprint (%d).\nexpected: %s\nreceived: %s", i, expected, fp) } @@ -402,7 +402,7 @@ func TestManager_MakeService(t *testing.T) { m, _ := newTestManager(t) tag := "hunter2" expected := message.Service{ - Identifier: m.GetRelationshipFingerprintBytes(), + Identifier: m.GetConnectionFingerprintBytes(), Tag: tag, Metadata: m.partner[:], } diff --git a/e2e/ratchet/partner/relationship.go b/e2e/ratchet/partner/relationship.go index e41b368116068c074aa974caf546c7e6bc180525..6c54b5921d1ced8f68f96d7f8f51ad06acf984ee 100644 --- a/e2e/ratchet/partner/relationship.go +++ b/e2e/ratchet/partner/relationship.go @@ -146,37 +146,6 @@ func LoadRelationship(kv *versioned.KV, t session.RelationshipType, myID, return r, nil } -// DeleteRelationship removes all relationship and -// relationship adjacent information from storage -func (m *manager) DeleteRelationship() error { - - // Delete the send information - sendKv := m.kv.Prefix(session.Send.Prefix()) - m.send.Delete() - if err := deleteRelationshipFingerprint(sendKv); err != nil { - return err - } - if err := sendKv.Delete(relationshipKey, - currentRelationshipVersion); err != nil { - return errors.Errorf("cannot delete send relationship: %v", - err) - } - - // Delete the receive information - receiveKv := m.kv.Prefix(session.Receive.Prefix()) - m.receive.Delete() - if err := deleteRelationshipFingerprint(receiveKv); err != nil { - return err - } - if err := receiveKv.Delete(relationshipKey, - currentRelationshipVersion); err != nil { - return errors.Errorf("cannot delete receive relationship: %v", - err) - } - - return nil -} - func (r *relationship) save() error { now := netTime.Now() diff --git a/e2e/ratchet/ratchet.go b/e2e/ratchet/ratchet.go index fd1d6f28994bb798ce0635f0d935a01f49bb7e35..3bc73f3b953bb3b3b1f83037049335803ccc5340 100644 --- a/e2e/ratchet/ratchet.go +++ b/e2e/ratchet/ratchet.go @@ -152,7 +152,7 @@ func (r *Ratchet) DeletePartner(partnerID *id.ID) error { return errors.New(NoPartnerErrorStr) } - if err := m.ClearManager(); err != nil { + if err := m.Delete(); err != nil { return errors.WithMessagef(err, "Could not remove partner %s from store", partnerID) diff --git a/e2e/ratchet/utils_test.go b/e2e/ratchet/utils_test.go index 9c2b763e93e4d6864d92632f009b593b31016549..c3497872084493d7e5c8e6dc65997365ad191c3b 100644 --- a/e2e/ratchet/utils_test.go +++ b/e2e/ratchet/utils_test.go @@ -52,10 +52,10 @@ func managersEqual(expected, received partner.Manager, t *testing.T) bool { equal = false } - if !strings.EqualFold(expected.GetRelationshipFingerprint(), received.GetRelationshipFingerprint()) { + if !strings.EqualFold(expected.GetConnectionFingerprint(), received.GetConnectionFingerprint()) { t.Errorf("Did not Receive expected Manager.Receive."+ "\n\texpected: %+v\n\treceived: %+v", - expected.GetRelationshipFingerprint(), received.GetRelationshipFingerprint()) + expected.GetConnectionFingerprint(), received.GetConnectionFingerprint()) equal = false } if !reflect.DeepEqual(expected.GetMyID(), received.GetMyID()) {