Skip to content
Snippets Groups Projects
Commit c0d76602 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Merge remote-tracking branch 'origin/peppa/newClient' into XX-2576/receptionlogic

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