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

small fixes for rekeying

parent a45daceb
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ func trigger(ctx *context.Context, manager *e2e.Manager, session *e2e.Session) { ...@@ -40,7 +40,7 @@ func trigger(ctx *context.Context, manager *e2e.Manager, session *e2e.Session) {
case e2e.NewSessionTriggered: case e2e.NewSessionTriggered:
//create the session, pass a nil private key to generate a new one //create the session, pass a nil private key to generate a new one
negotiatingSession = manager.NewSendSession(nil, negotiatingSession = manager.NewSendSession(nil,
e2e.GetDefaultSessionParams(), session.GetID()) e2e.GetDefaultSessionParams())
//move the state of the triggering session forward //move the state of the triggering session forward
session.SetNegotiationStatus(e2e.NewSessionCreated) session.SetNegotiationStatus(e2e.NewSessionCreated)
// If the session has not successfully negotiated, redo its negotiation // If the session has not successfully negotiated, redo its negotiation
...@@ -71,7 +71,7 @@ func negotiate(ctx *context.Context, session *e2e.Session) error { ...@@ -71,7 +71,7 @@ func negotiate(ctx *context.Context, session *e2e.Session) error {
//build the payload //build the payload
payload, err := proto.Marshal(&RekeyTrigger{ payload, err := proto.Marshal(&RekeyTrigger{
PublicKey: pubKey.Bytes(), PublicKey: pubKey.Bytes(),
SessionID: session.GetTrigger().Marshal(), SessionID: session.GetSource().Marshal(),
}) })
//If the payload cannot be marshaled, panic //If the payload cannot be marshaled, panic
......
...@@ -51,7 +51,7 @@ func handleTrigger(ctx *context.Context, request message.Receive) error { ...@@ -51,7 +51,7 @@ func handleTrigger(ctx *context.Context, request message.Receive) error {
} }
//unmarshal the message //unmarshal the message
oldSessionID, PartnerPublicKey, err := unmarshalTrigger( oldSessionID, PartnerPublicKey, err := unmarshalSource(
ctx.Session.E2e().GetGroup(), request.Payload) ctx.Session.E2e().GetGroup(), request.Payload)
if err != nil { if err != nil {
jww.ERROR.Printf("could not unmarshal partner %s: %s", jww.ERROR.Printf("could not unmarshal partner %s: %s",
...@@ -83,7 +83,7 @@ func handleTrigger(ctx *context.Context, request message.Receive) error { ...@@ -83,7 +83,7 @@ func handleTrigger(ctx *context.Context, request message.Receive) error {
//Send the Confirmation Message //Send the Confirmation Message
//build the payload //build the payload
payload, err := proto.Marshal(&RekeyConfirm{ payload, err := proto.Marshal(&RekeyConfirm{
SessionID: session.GetTrigger().Marshal(), SessionID: session.GetSource().Marshal(),
}) })
//If the payload cannot be marshaled, panic //If the payload cannot be marshaled, panic
...@@ -125,10 +125,10 @@ func handleTrigger(ctx *context.Context, request message.Receive) error { ...@@ -125,10 +125,10 @@ func handleTrigger(ctx *context.Context, request message.Receive) error {
if !success { if !success {
jww.ERROR.Printf("Key Negotiation for %s failed to "+ jww.ERROR.Printf("Key Negotiation for %s failed to "+
"transmit %v/%v paritions: %v round failures, %v timeouts", "transmit %v/%v paritions: %v round failures, %v timeouts",
newSession, numRoundFail+numTimeOut, len(rounds), numRoundFail, session, numRoundFail+numTimeOut, len(rounds), numRoundFail,
numTimeOut) numTimeOut)
ctx.Session.GetCriticalMessages().Failed(m) ctx.Session.GetCriticalMessages().Failed(m)
return return nil
} }
// otherwise, the transmission is a success and this should be denoted // otherwise, the transmission is a success and this should be denoted
...@@ -136,12 +136,11 @@ func handleTrigger(ctx *context.Context, request message.Receive) error { ...@@ -136,12 +136,11 @@ func handleTrigger(ctx *context.Context, request message.Receive) error {
ctx.Session.GetCriticalMessages().Succeeded(m) ctx.Session.GetCriticalMessages().Succeeded(m)
jww.INFO.Printf("Key Negotiation transmission for %s sucesfull", jww.INFO.Printf("Key Negotiation transmission for %s sucesfull",
session) session)
session.SetNegotiationStatus(e2e.Sent)
return nil return nil
} }
func unmarshalTrigger(grp *cyclic.Group, payload []byte) (e2e.SessionID, func unmarshalSource(grp *cyclic.Group, payload []byte) (e2e.SessionID,
*cyclic.Int, error) { *cyclic.Int, error) {
msg := &RekeyTrigger{} msg := &RekeyTrigger{}
......
...@@ -95,10 +95,10 @@ func (m *Manager) GetPartnerID() *id.ID { ...@@ -95,10 +95,10 @@ func (m *Manager) GetPartnerID() *id.ID {
// session will be returned, with the bool set to true denoting a duplicate. // session will be returned, with the bool set to true denoting a duplicate.
// This is so duplicate key exchange triggering can be supported // This is so duplicate key exchange triggering can be supported
func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionParams, func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionParams,
trigger *Session) (*Session, bool) { source *Session) (*Session, bool) {
//check if the session already exists //check if the session already exists
baseKey := dh.GenerateSessionKey(trigger.myPrivKey, partnerPubKey, m.ctx.grp) baseKey := dh.GenerateSessionKey(source.myPrivKey, partnerPubKey, m.ctx.grp)
sessionID := getSessionIDFromBaseKey(baseKey) sessionID := getSessionIDFromBaseKey(baseKey)
if s := m.receive.GetByID(sessionID); s != nil { if s := m.receive.GetByID(sessionID); s != nil {
...@@ -106,8 +106,8 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionPar ...@@ -106,8 +106,8 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionPar
} }
//create the session but do not save //create the session but do not save
session := newSession(m, trigger.myPrivKey, partnerPubKey, baseKey, params, Receive, session := newSession(m, source.myPrivKey, partnerPubKey, baseKey, params, Receive,
trigger.GetID()) source.GetID())
//add the session to the buffer //add the session to the buffer
m.receive.AddSession(session) m.receive.AddSession(session)
...@@ -119,13 +119,13 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionPar ...@@ -119,13 +119,13 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionPar
// partner and a mew private key for the user // partner and a mew private key for the user
// passing in a private key is optional. a private key will be generated if // passing in a private key is optional. a private key will be generated if
// none is passed // none is passed
func (m *Manager) NewSendSession(myPrivKey *cyclic.Int, params SessionParams, trigger SessionID) *Session { func (m *Manager) NewSendSession(myPrivKey *cyclic.Int, params SessionParams) *Session {
//find the latest public key from the other party //find the latest public key from the other party
partnerPubKey := m.receive.GetNewestRekeyableSession().partnerPubKey sourceSession := m.receive.GetNewestRekeyableSession()
//create the session //create the session
session := newSession(m, myPrivKey, partnerPubKey, nil, session := newSession(m, myPrivKey, sourceSession.partnerPubKey, nil,
params, Send, trigger) params, Send, sourceSession.GetID())
//add the session to the send session buffer and return //add the session to the send session buffer and return
m.send.AddSession(session) m.send.AddSession(session)
......
...@@ -3,7 +3,7 @@ package e2e ...@@ -3,7 +3,7 @@ package e2e
import "fmt" import "fmt"
// Fix-me: this solution is incompatible with offline sending, when that is // Fix-me: this solution is incompatible with offline sending, when that is
// added, a session which has not been confirmed will never trigger the // added, a session which has not been confirmed will never partnerSource the
// creation of new session, the Unconfirmed->Confirmed and // creation of new session, the Unconfirmed->Confirmed and
// Confirmed->NewSessionCreated most likely need to be two separate enums // Confirmed->NewSessionCreated most likely need to be two separate enums
// tracked separately // tracked separately
......
...@@ -42,10 +42,10 @@ type Session struct { ...@@ -42,10 +42,10 @@ type Session struct {
myPrivKey *cyclic.Int myPrivKey *cyclic.Int
// Partner Public Key // Partner Public Key
partnerPubKey *cyclic.Int partnerPubKey *cyclic.Int
// ID of the session which triggered this sessions creation. // ID of the session which teh partner public key comes from for this
// Shares a partner public key if a send session, shares a myPrivateKey // sessions creation. Shares a partner public key if a send session,
// if a receive session // shares a myPrivateKey if a receive session
trigger SessionID partnerSource SessionID
//denotes if the other party has confirmed this key //denotes if the other party has confirmed this key
negotiationStatus Negotiation negotiationStatus Negotiation
...@@ -105,7 +105,7 @@ func newSession(manager *Manager, myPrivKey, partnerPubKey, ...@@ -105,7 +105,7 @@ func newSession(manager *Manager, myPrivKey, partnerPubKey,
partnerPubKey: partnerPubKey, partnerPubKey: partnerPubKey,
baseKey: baseKey, baseKey: baseKey,
negotiationStatus: confirmation, negotiationStatus: confirmation,
trigger: trigger, partnerSource: trigger,
} }
session.kv = session.generate(manager.kv) session.kv = session.generate(manager.kv)
...@@ -201,9 +201,9 @@ func (s *Session) GetPartnerPubKey() *cyclic.Int { ...@@ -201,9 +201,9 @@ func (s *Session) GetPartnerPubKey() *cyclic.Int {
return s.partnerPubKey.DeepCopy() return s.partnerPubKey.DeepCopy()
} }
func (s *Session) GetTrigger() SessionID { func (s *Session) GetSource() SessionID {
// no lock is needed because this cannot be edited // no lock is needed because this cannot be edited
return s.trigger return s.partnerSource
} }
//underlying definition of session id //underlying definition of session id
...@@ -239,7 +239,7 @@ func (s *Session) marshal() ([]byte, error) { ...@@ -239,7 +239,7 @@ func (s *Session) marshal() ([]byte, error) {
sd.BaseKey = s.baseKey.Bytes() sd.BaseKey = s.baseKey.Bytes()
sd.MyPrivKey = s.myPrivKey.Bytes() sd.MyPrivKey = s.myPrivKey.Bytes()
sd.PartnerPubKey = s.partnerPubKey.Bytes() sd.PartnerPubKey = s.partnerPubKey.Bytes()
sd.Trigger = s.trigger[:] sd.Trigger = s.partnerSource[:]
// assume in progress confirmations and session creations have failed on // assume in progress confirmations and session creations have failed on
// reset, therefore do not store their pending progress // reset, therefore do not store their pending progress
...@@ -275,7 +275,7 @@ func (s *Session) unmarshal(b []byte) error { ...@@ -275,7 +275,7 @@ func (s *Session) unmarshal(b []byte) error {
s.partnerPubKey = grp.NewIntFromBytes(sd.PartnerPubKey) s.partnerPubKey = grp.NewIntFromBytes(sd.PartnerPubKey)
s.negotiationStatus = Negotiation(sd.Confirmation) s.negotiationStatus = Negotiation(sd.Confirmation)
s.ttl = sd.TTL s.ttl = sd.TTL
copy(s.trigger[:], sd.Trigger) copy(s.partnerSource[:], sd.Trigger)
s.keyState, err = loadStateVector(s.kv, "") s.keyState, err = loadStateVector(s.kv, "")
if err != nil { if err != nil {
...@@ -394,9 +394,9 @@ func (s *Session) TrySetNegotiationStatus(status Negotiation) error { ...@@ -394,9 +394,9 @@ func (s *Session) TrySetNegotiationStatus(status Negotiation) error {
// WARNING: This function relies on proper action by the caller for data safety. // WARNING: This function relies on proper action by the caller for data safety.
// When triggering the creation of a new session (the first case) it does not // When triggering the creation of a new session (the first case) it does not
// store to disk the fact that it has triggered the session. This is because // store to disk the fact that it has triggered the session. This is because
// every session should only trigger one other session and in the event that // every session should only partnerSource one other session and in the event that
// session trigger does not resolve before a crash, by not storing it the // session partnerSource does not resolve before a crash, by not storing it the
// trigger will automatically happen again when reloading after the crash. // partnerSource will automatically happen again when reloading after the crash.
// In order to ensure the session creation is not triggered again after the // In order to ensure the session creation is not triggered again after the
// reload, it is the responsibility of the caller to call // reload, it is the responsibility of the caller to call
// Session.SetConfirmationStatus(NewSessionCreated) . // Session.SetConfirmationStatus(NewSessionCreated) .
...@@ -413,7 +413,7 @@ func (s *Session) triggerNegotiation() bool { ...@@ -413,7 +413,7 @@ func (s *Session) triggerNegotiation() bool {
s.mux.RUnlock() s.mux.RUnlock()
s.mux.Lock() s.mux.Lock()
if s.keyState.GetNumUsed() >= s.ttl && s.negotiationStatus == Confirmed { if s.keyState.GetNumUsed() >= s.ttl && s.negotiationStatus == Confirmed {
//trigger a rekey to create a new session //partnerSource a rekey to create a new session
s.negotiationStatus = NewSessionTriggered s.negotiationStatus = NewSessionTriggered
// no save is make after the update because we do not want this state // no save is make after the update because we do not want this state
// saved to disk. The caller will shortly execute the operation, // saved to disk. The caller will shortly execute the operation,
......
...@@ -523,45 +523,45 @@ func TestSession_SetNegotiationStatus(t *testing.T) { ...@@ -523,45 +523,45 @@ func TestSession_SetNegotiationStatus(t *testing.T) {
// Tests that TriggerNegotiation makes only valid state transitions // Tests that TriggerNegotiation makes only valid state transitions
func TestSession_TriggerNegotiation(t *testing.T) { func TestSession_TriggerNegotiation(t *testing.T) {
s, _ := makeTestSession(t) s, _ := makeTestSession(t)
// Set up num keys used to be > ttl: should trigger negotiation // Set up num keys used to be > ttl: should partnerSource negotiation
s.keyState.numAvailable = 50 s.keyState.numAvailable = 50
s.keyState.numkeys = 100 s.keyState.numkeys = 100
s.ttl = 49 s.ttl = 49
s.negotiationStatus = Confirmed s.negotiationStatus = Confirmed
if !s.triggerNegotiation() { if !s.triggerNegotiation() {
t.Error("trigger negotiation unexpectedly failed") t.Error("partnerSource negotiation unexpectedly failed")
} }
if s.negotiationStatus != NewSessionTriggered { if s.negotiationStatus != NewSessionTriggered {
t.Errorf("negotiationStatus: got %v, expected %v", s.negotiationStatus, NewSessionTriggered) t.Errorf("negotiationStatus: got %v, expected %v", s.negotiationStatus, NewSessionTriggered)
} }
// Set up num keys used to be = ttl: should trigger negotiation // Set up num keys used to be = ttl: should partnerSource negotiation
s.ttl = 50 s.ttl = 50
s.negotiationStatus = Confirmed s.negotiationStatus = Confirmed
if !s.triggerNegotiation() { if !s.triggerNegotiation() {
t.Error("trigger negotiation unexpectedly failed") t.Error("partnerSource negotiation unexpectedly failed")
} }
if s.negotiationStatus != NewSessionTriggered { if s.negotiationStatus != NewSessionTriggered {
t.Errorf("negotiationStatus: got %v, expected %v", s.negotiationStatus, NewSessionTriggered) t.Errorf("negotiationStatus: got %v, expected %v", s.negotiationStatus, NewSessionTriggered)
} }
// Set up num keys used to be < ttl: shouldn't trigger negotiation // Set up num keys used to be < ttl: shouldn't partnerSource negotiation
s.ttl = 51 s.ttl = 51
s.negotiationStatus = Confirmed s.negotiationStatus = Confirmed
if !s.triggerNegotiation() { if !s.triggerNegotiation() {
t.Error("trigger negotiation unexpectedly failed") t.Error("partnerSource negotiation unexpectedly failed")
} }
if s.negotiationStatus != Confirmed { if s.negotiationStatus != Confirmed {
t.Errorf("negotiationStatus: got %v, expected %v", s.negotiationStatus, NewSessionTriggered) t.Errorf("negotiationStatus: got %v, expected %v", s.negotiationStatus, NewSessionTriggered)
} }
// Test other case: trigger sending confirmation message on unconfirmed session // Test other case: partnerSource sending confirmation message on unconfirmed session
s.negotiationStatus = Unconfirmed s.negotiationStatus = Unconfirmed
if !s.triggerNegotiation() { if !s.triggerNegotiation() {
t.Error("trigger negotiation unexpectedly failed") t.Error("partnerSource negotiation unexpectedly failed")
} }
if s.negotiationStatus != Sending { if s.negotiationStatus != Sending {
t.Errorf("negotiationStatus: got %v, expected %v", s.negotiationStatus, NewSessionTriggered) t.Errorf("negotiationStatus: got %v, expected %v", s.negotiationStatus, NewSessionTriggered)
...@@ -577,12 +577,12 @@ func TestSession_String(t *testing.T) { ...@@ -577,12 +577,12 @@ func TestSession_String(t *testing.T) {
t.Log(s.String()) t.Log(s.String())
} }
// Shows that GetTrigger gets the trigger we set // Shows that GetSource gets the partnerSource we set
func TestSession_GetTrigger(t *testing.T) { func TestSession_GetTrigger(t *testing.T) {
s, _ := makeTestSession(t) s, _ := makeTestSession(t)
thisTrigger := s.GetID() thisTrigger := s.GetID()
s.trigger = thisTrigger s.partnerSource = thisTrigger
if !reflect.DeepEqual(s.GetTrigger(), thisTrigger) { if !reflect.DeepEqual(s.GetSource(), thisTrigger) {
t.Error("Trigger different from expected") t.Error("Trigger different from expected")
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment