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

improvements to e2e/ratchet/partner/manager interface

parent 4b466c8e
Branches
Tags
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
......@@ -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()
}
......@@ -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]
......
......@@ -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
}
......@@ -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[:],
}
......
......@@ -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[:],
}
......
......@@ -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()
......
......@@ -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)
......
......@@ -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()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment