Skip to content
Snippets Groups Projects
Commit a2cff65b authored by Jake Taylor's avatar Jake Taylor
Browse files

clean up comments

parent 582a0a1c
Branches
Tags
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
...@@ -107,11 +107,9 @@ type Handler interface { ...@@ -107,11 +107,9 @@ type Handler interface {
// AddPartner adds a partner. Automatically creates both send // AddPartner adds a partner. Automatically creates both send
// and receive sessions using the passed cryptographic data // and receive sessions using the passed cryptographic data
// and per the parameters sent If an alternate ID public key // and per the parameters sent. If an alternate ID public key
// are to be used for this relationship, then pass them in, // are to be used for this relationship, then pass them in,
// otherwise, leave myID and myPrivateKey nil If temporary is // otherwise, leave myID and myPrivateKey nil
// true, an alternate ram kv will be used for storage and the
// relationship will not survive a reset
AddPartner(partnerID *id.ID, AddPartner(partnerID *id.ID,
partnerPubKey, myPrivKey *cyclic.Int, partnerPubKey, myPrivKey *cyclic.Int,
partnerSIDHPubKey *sidh.PublicKey, partnerSIDHPubKey *sidh.PublicKey,
...@@ -119,12 +117,12 @@ type Handler interface { ...@@ -119,12 +117,12 @@ type Handler interface {
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
// assume to be your defaultID // assume to be your defaultID
DeletePartner(partnerId *id.ID) error DeletePartner(partnerId *id.ID) error
......
...@@ -9,40 +9,63 @@ import ( ...@@ -9,40 +9,63 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
// Manager create and manages both E2E send and receive sessions using the passed cryptographic data
type Manager interface { type Manager interface {
//accessors // GetPartnerID returns the ID of the E2E partner
GetPartnerID() *id.ID GetPartnerID() *id.ID
// GetMyID returns my ID used for the E2E relationship
GetMyID() *id.ID GetMyID() *id.ID
// GetMyOriginPrivateKey returns my private key
GetMyOriginPrivateKey() *cyclic.Int GetMyOriginPrivateKey() *cyclic.Int
// GetPartnerOriginPublicKey returns the partner's public key
GetPartnerOriginPublicKey() *cyclic.Int GetPartnerOriginPublicKey() *cyclic.Int
// GetSendRelationshipFingerprint returns the fingerprint of the send session
GetSendRelationshipFingerprint() []byte GetSendRelationshipFingerprint() []byte
// GetReceiveRelationshipFingerprint returns the fingerprint of the receive session
GetReceiveRelationshipFingerprint() []byte GetReceiveRelationshipFingerprint() []byte
// GetConnectionFingerprintBytes returns a unique fingerprint for an E2E relationship in bytes format
GetConnectionFingerprintBytes() []byte GetConnectionFingerprintBytes() []byte
// GetConnectionFingerprint returns a unique fingerprint for an E2E relationship in string format
GetConnectionFingerprint() string GetConnectionFingerprint() string
// GetContact returns the contact of the E2E partner
GetContact() contact.Contact GetContact() contact.Contact
//sending and receving // PopSendCypher returns the key which is most likely to be successful for sending
PopSendCypher() (*session.Cypher, error) PopSendCypher() (*session.Cypher, error)
// PopRekeyCypher returns a key which should be used for rekeying
PopRekeyCypher() (*session.Cypher, error) PopRekeyCypher() (*session.Cypher, error)
//Ratcheting // 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
// session will be returned with the bool set to true denoting a duplicate. This
// allows for support of duplicate key exchange triggering.
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 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
// private key is optional. A private key will be generated if none is passed.
NewSendSession(myDHPrivKey *cyclic.Int, mySIDHPrivateKey *sidh.PrivateKey, NewSendSession(myDHPrivKey *cyclic.Int, mySIDHPrivateKey *sidh.PrivateKey,
e2eParams session.Params, source *session.Session) *session.Session e2eParams session.Params, source *session.Session) *session.Session
// GetSendSession gets the Send session of the passed ID. Returns nil if no session is found.
GetSendSession(sid session.SessionID) *session.Session GetSendSession(sid session.SessionID) *session.Session
//GetReceiveSession gets the Receive session of the passed ID. Returns nil if no session is found.
//state machine
GetReceiveSession(sid session.SessionID) *session.Session GetReceiveSession(sid session.SessionID) *session.Session
// Confirm sets the passed session ID as confirmed and cleans up old sessions
Confirm(sid session.SessionID) error Confirm(sid session.SessionID) error
// TriggerNegotiations returns a list of session that need rekeys
TriggerNegotiations() []*session.Session TriggerNegotiations() []*session.Session
//services // MakeService Returns a service interface with the
// appropriate identifier for who is being sent to. Will populate
// the metadata with the partner
MakeService(tag string) message.Service MakeService(tag string) message.Service
//storage // Delete removes the relationship between the partner
// and deletes the Send and Receive sessions. This includes the
// sessions and the key vectors
Delete() error Delete() error
} }
...@@ -30,6 +30,7 @@ const managerPrefix = "Manager{partner:%s}" ...@@ -30,6 +30,7 @@ const managerPrefix = "Manager{partner:%s}"
const originMyPrivKeyKey = "originMyPrivKey" const originMyPrivKeyKey = "originMyPrivKey"
const originPartnerPubKey = "originPartnerPubKey" const originPartnerPubKey = "originPartnerPubKey"
// Implements the partner.Manager interface
type manager struct { type manager struct {
kv *versioned.KV kv *versioned.KV
...@@ -231,14 +232,12 @@ func (m *manager) NewSendSession(myPrivKey *cyclic.Int, ...@@ -231,14 +232,12 @@ func (m *manager) NewSendSession(myPrivKey *cyclic.Int,
sourceSession.GetID(), session.Sending, e2eParams) sourceSession.GetID(), session.Sending, e2eParams)
} }
// PopSendCypher gets the correct session to Send with depending on the type // PopSendCypher returns the key which is most likely to be successful for sending
// 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 returns a key which should be used for rekeying
// of Send.
func (m *manager) PopRekeyCypher() (*session.Cypher, error) { func (m *manager) PopRekeyCypher() (*session.Cypher, error) {
return m.send.getKeyForRekey() return m.send.getKeyForRekey()
...@@ -266,14 +265,12 @@ func (m *manager) GetReceiveSession(sid session.SessionID) *session.Session { ...@@ -266,14 +265,12 @@ func (m *manager) GetReceiveSession(sid session.SessionID) *session.Session {
return m.receive.GetByID(sid) return m.receive.GetByID(sid)
} }
// GetSendRelationshipFingerprint gets the Send session of the passed ID. Returns nil if no // GetSendRelationshipFingerprint
// session is found.
func (m *manager) GetSendRelationshipFingerprint() []byte { func (m *manager) GetSendRelationshipFingerprint() []byte {
return m.send.fingerprint return m.send.fingerprint
} }
// GetReceiveRelationshipFingerprint gets the receive session of the passed ID. // GetReceiveRelationshipFingerprint
// Returns nil if no session is found.
func (m *manager) GetReceiveRelationshipFingerprint() []byte { func (m *manager) GetReceiveRelationshipFingerprint() []byte {
return m.receive.fingerprint return m.receive.fingerprint
} }
...@@ -283,8 +280,7 @@ func (m *manager) Confirm(sid session.SessionID) error { ...@@ -283,8 +280,7 @@ 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()
} }
...@@ -299,8 +295,8 @@ func (m *manager) GetPartnerOriginPublicKey() *cyclic.Int { ...@@ -299,8 +295,8 @@ func (m *manager) GetPartnerOriginPublicKey() *cyclic.Int {
const relationshipFpLength = 15 const relationshipFpLength = 15
// GetRelationshipFingerprint returns a unique fingerprint for an E2E // GetConnectionFingerprint 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 the two
// relationship fingerprints truncated to 15 characters. // relationship fingerprints truncated to 15 characters.
func (m *manager) GetConnectionFingerprint() string { func (m *manager) GetConnectionFingerprint() string {
...@@ -309,8 +305,8 @@ func (m *manager) GetConnectionFingerprint() string { ...@@ -309,8 +305,8 @@ func (m *manager) GetConnectionFingerprint() string {
m.GetConnectionFingerprintBytes())[:relationshipFpLength] m.GetConnectionFingerprintBytes())[:relationshipFpLength]
} }
// GetRelationshipFingerprintBytes returns a unique fingerprint for an E2E // GetConnectionFingerprintBytes returns a unique fingerprint for an E2E
// relationship. used for the e2e preimage. // relationship used for the e2e preimage.
func (m *manager) GetConnectionFingerprintBytes() []byte { func (m *manager) GetConnectionFingerprintBytes() []byte {
// Sort fingerprints // Sort fingerprints
var fps [][]byte var fps [][]byte
......
...@@ -311,11 +311,9 @@ func (r *relationship) getSessionForSending() *session.Session { ...@@ -311,11 +311,9 @@ func (r *relationship) getSessionForSending() *session.Session {
return nil return nil
} }
// todo - doscstring // TriggerNegotiation returns a list of session that need rekeys. Nil instances mean a new rekey from scratch
// returns a list of session that need rekeys. Nil instances mean a new rekey
// from scratch
func (r *relationship) TriggerNegotiation() []*session.Session { func (r *relationship) TriggerNegotiation() []*session.Session {
//dont need to take the lock due to the use of a copy of the buffer // Don't need to take the lock due to the use of a copy of the buffer
sessions := r.getInternalBufferShallowCopy() sessions := r.getInternalBufferShallowCopy()
var instructions []*session.Session var instructions []*session.Session
for _, ses := range sessions { for _, ses := range sessions {
...@@ -379,10 +377,7 @@ func (r *relationship) GetByID(id session.SessionID) *session.Session { ...@@ -379,10 +377,7 @@ func (r *relationship) GetByID(id session.SessionID) *session.Session {
return r.sessionByID[id] return r.sessionByID[id]
} }
// todo - doscstring // Confirm sets the passed session ID as confirmed and cleans up old sessions
// sets the passed session ID as confirmed. Call "GetSessionRotation" after
// to get any sessions that are to be deleted and then "DeleteSession" to
// remove them
func (r *relationship) Confirm(id session.SessionID) error { func (r *relationship) Confirm(id session.SessionID) error {
r.mux.Lock() r.mux.Lock()
defer r.mux.Unlock() defer r.mux.Unlock()
...@@ -409,7 +404,7 @@ func (r *relationship) getInternalBufferShallowCopy() []*session.Session { ...@@ -409,7 +404,7 @@ func (r *relationship) getInternalBufferShallowCopy() []*session.Session {
return r.sessions return r.sessions
} }
// todo - doscstring // clean deletes old confirmed sessions
func (r *relationship) clean() { func (r *relationship) clean() {
numConfirmed := uint(0) numConfirmed := uint(0)
...@@ -432,7 +427,7 @@ func (r *relationship) clean() { ...@@ -432,7 +427,7 @@ func (r *relationship) clean() {
newSessions = append(newSessions, s) newSessions = append(newSessions, s)
} }
//only do the update and save if changes occured //only do the update and save if changes occurred
if editsMade { if editsMade {
r.sessions = newSessions r.sessions = newSessions
......
...@@ -515,7 +515,6 @@ func (s *Session) NegotiationStatus() Negotiation { ...@@ -515,7 +515,6 @@ func (s *Session) NegotiationStatus() Negotiation {
// IsConfirmed checks if the session has been confirmed // IsConfirmed checks if the session has been confirmed
func (s *Session) IsConfirmed() bool { func (s *Session) IsConfirmed() bool {
c := s.NegotiationStatus() c := s.NegotiationStatus()
//fmt.Println(c)
return c >= Confirmed return c >= Confirmed
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment