diff --git a/api/client.go b/api/client.go index a5a132cc121a0b2009a1c81feb9446777767d32b..7990553550f938d85e8404ad800377339f02b0fe 100644 --- a/api/client.go +++ b/api/client.go @@ -260,7 +260,7 @@ func (c *Client) StartNetworkFollower() error { } c.runner.Add(stopFollow) // Key exchange - c.runner.Add(keyExchange.Start(c.switchboard, c.storage, c.network)) + c.runner.Add(keyExchange.Start(c.switchboard, c.storage, c.network, params.GetDefaultRekey())) err = c.status.toRunning() if err != nil { diff --git a/go.sum b/go.sum index 76966418b77c1e86585f62d3aaebb816ade88081..4f91b79f821ce8a2345cc44cbdd9c4afe6859a7d 100644 --- a/go.sum +++ b/go.sum @@ -246,6 +246,8 @@ github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN github.com/zeebo/blake3 v0.0.4 h1:vtZ4X8B2lKXZFg2Xyg6Wo36mvmnJvc2VQYTtA4RDCkI= github.com/zeebo/blake3 v0.0.4/go.mod h1:YOZo8A49yNqM0X/Y+JmDUZshJWLt1laHsNSn5ny2i34= github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm//LBaEvBiaXY7hXJ6KGe2V32X2F6E= +gitlab.com/elixxir/client v1.5.0/go.mod h1:/uVTzYDhKaGgN8LGGh1sSsxbh+BrpVi1X8VToAT3DfA= +gitlab.com/elixxir/comms v0.0.0-20200707210150-b8ebd0951d23/go.mod h1:OsWMZ1O/R9fOkm+PoHnR3rkXfFtipGoPs73FuKuurHY= gitlab.com/elixxir/comms v0.0.0-20200810165153-3039323b5656 h1:A5S3E7EPL95s3+PGhgAiwnMaa7VcWj8/RtBur3lxdOw= gitlab.com/elixxir/comms v0.0.0-20200810165153-3039323b5656/go.mod h1:EeS1z5wXKrnWOvR0dJlVNVv8OzuiGJz7fa6LyUeN6Q0= gitlab.com/elixxir/comms v0.0.0-20200813225502-e879259ca741 h1:yIjgre8xSDpnhJkDzTr1lgR7NC1bPWCk2Sgn8udiS2A= @@ -272,6 +274,7 @@ gitlab.com/elixxir/comms v0.0.0-20200916212207-60e7bd5b0913 h1:p4TLPPaMysV//lOJU gitlab.com/elixxir/comms v0.0.0-20200916212207-60e7bd5b0913/go.mod h1:yBEsOZSPyJQJvDbtlQ5L8ydy1JRgVlRoNgMDy9koQcE= gitlab.com/elixxir/comms v0.0.0-20200917172539-929fc227eb0c h1:go7/RknV7646Ie+nmQXZAa/aJ5wZBn5bpAYRB+tPens= gitlab.com/elixxir/comms v0.0.0-20200917172539-929fc227eb0c/go.mod h1:yBEsOZSPyJQJvDbtlQ5L8ydy1JRgVlRoNgMDy9koQcE= +gitlab.com/elixxir/comms v0.0.0-20200917221445-8a509560122a/go.mod h1:L2Va13j2AbQkpkveOQmNzrQD37uI5NKeBhYH+LWMOx0= gitlab.com/elixxir/comms v0.0.0-20200921200427-5955a0a798b9 h1:skzHNWCMh+T7Cn58/88Mikg2R8KnSWfzLV0w7SnerOs= gitlab.com/elixxir/comms v0.0.0-20200921200427-5955a0a798b9/go.mod h1:uRr8j6yTjCslxZxbRe6k4ixACu9gAeF61JZH36OFFa0= gitlab.com/elixxir/comms v0.0.0-20200922163657-3e723b7170f6 h1:dFgfdATZuiPybonCBh0s4HeLB8Qw3Zm9EoLDRh2Eaaw= @@ -280,6 +283,10 @@ gitlab.com/elixxir/comms v0.0.0-20200924072138-2e2709483d89 h1:PQalM7pnCRzZRKvdz gitlab.com/elixxir/comms v0.0.0-20200924072138-2e2709483d89/go.mod h1:uRr8j6yTjCslxZxbRe6k4ixACu9gAeF61JZH36OFFa0= gitlab.com/elixxir/comms v0.0.0-20200924210331-d7903c023fa6 h1:ctVsHyiabgRls3esApbBemDwmQ/a0CramEmZt9RCQb8= gitlab.com/elixxir/comms v0.0.0-20200924210331-d7903c023fa6/go.mod h1:9+Jj7K8HOTgBjPuiP69VtTKTv7GvAK6bWlh4lgMAqrk= +gitlab.com/elixxir/comms v0.0.0-20200924225440-76e02f95fb92 h1:KwqVzHpqYg1l1/KG6uRqnl7HBgvrzuknMVCeEvRsbow= +gitlab.com/elixxir/comms v0.0.0-20200924225440-76e02f95fb92/go.mod h1:3i4o6ie4LFC+EVN68l9tdt9JxJlAd3+pNNnKBFubKSg= +gitlab.com/elixxir/crypto v0.0.0-20200707005343-97f868cbd930/go.mod h1:LHBAaEf48a0/AjU118rjoworH0LgXifhAqmNX3ZRvME= +gitlab.com/elixxir/crypto v0.0.0-20200731174640-0503cf80524a/go.mod h1:LHBAaEf48a0/AjU118rjoworH0LgXifhAqmNX3ZRvME= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4 h1:28ftZDeYEko7xptCZzeFWS1Iam95dj46TWFVVlKmw6A= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.0-20200805174804-bdf909f2a16d/go.mod h1:cu6uNoANVLV0J6HyTL6KqVtVyh9SHU1RjJhytYlsbVQ= @@ -321,6 +328,8 @@ gitlab.com/elixxir/ekv v0.1.1 h1:Em3rF8sv+tNbQGXbcpYzAS2blWRAP708JGhYlkN74Kg= gitlab.com/elixxir/ekv v0.1.1/go.mod h1:bXY0kgbV5BHYda4YY5/hiG5bjimGK+R3PYub5yM9C/s= gitlab.com/elixxir/ekv v0.1.3 h1:OE+LBMIhjGUMwc6hHJzYvEPNJQV7t1vMnJyIgxUMUo8= gitlab.com/elixxir/ekv v0.1.3/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4= +gitlab.com/elixxir/primitives v0.0.0-20200706165052-9fe7a4fb99a3/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= +gitlab.com/elixxir/primitives v0.0.0-20200708185800-a06e961280e6/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= gitlab.com/elixxir/primitives v0.0.0-20200804170709-a1896d262cd9/go.mod h1:p0VelQda72OzoUckr1O+vPW0AiFe0nyKQ6gYcmFSuF8= gitlab.com/elixxir/primitives v0.0.0-20200804182913-788f47bded40/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc= @@ -346,8 +355,11 @@ gitlab.com/xx_network/comms v0.0.0-20200910173932-bd179f5fee4f h1:ExTCqEoro7VuS1 gitlab.com/xx_network/comms v0.0.0-20200910173932-bd179f5fee4f/go.mod h1:+jEkDQKoK51WLl2ZZuxfAZkz6YFbUQ+oZfH0dt2wIF0= gitlab.com/xx_network/comms v0.0.0-20200915154643-d533291041b7 h1:lPx1wpkjNpwLaZ0pyd7/iCcdITjT+eCMmb0HXCVoIkk= gitlab.com/xx_network/comms v0.0.0-20200915154643-d533291041b7/go.mod h1:+jEkDQKoK51WLl2ZZuxfAZkz6YFbUQ+oZfH0dt2wIF0= +gitlab.com/xx_network/comms v0.0.0-20200916172635-6ab807c3c820/go.mod h1:J+GJ6fn71a4xnYVvbcrhtvWSOQIqqhaGcaej5xB3/JY= gitlab.com/xx_network/comms v0.0.0-20200924172734-1124191b69ee h1:dPRaW0OxcoBlWALd5H6VUYnL/ALvT7j14kWJNBi0K7A= gitlab.com/xx_network/comms v0.0.0-20200924172734-1124191b69ee/go.mod h1:jECvMkoYKZFooCudoZxxaf2bo1DzpWP0gCahXHdlqUM= +gitlab.com/xx_network/comms v0.0.0-20200924225518-0c867207b1e6 h1:8rNFHiwKJvcfN89FAmp4RyfjD/rknp4tNm9sI/Nos0g= +gitlab.com/xx_network/comms v0.0.0-20200924225518-0c867207b1e6/go.mod h1:jECvMkoYKZFooCudoZxxaf2bo1DzpWP0gCahXHdlqUM= gitlab.com/xx_network/crypto v0.0.0-20200805231039-4aa0e350ed0a h1:BlfWGPokU6yU69O+PGGsgc5iA/P9gERbHzYUvjoYbgM= gitlab.com/xx_network/crypto v0.0.0-20200806202113-978fa1984bbf/go.mod h1:i0df/q6dDCBiscgD51fMoS2U2TBrm6LcyN822JmB5Tw= gitlab.com/xx_network/crypto v0.0.0-20200806235322-ede3c15881ce h1:gypNBUl2guESEv4MDgH+miwYqR4jPoWM8dLt2Zs5gIs= @@ -419,6 +431,7 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -498,6 +511,7 @@ google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200514193133-8feb7f20f2a2/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20200709005830-7a2ca40e9dc3 h1:JwLN1jVnmIsfE4HkDVe2AblFAbo0Z+4cjteDSOnv6oE= google.golang.org/genproto v0.0.0-20200709005830-7a2ca40e9dc3/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= diff --git a/interfaces/params/keyExchange.go b/interfaces/params/keyExchange.go new file mode 100644 index 0000000000000000000000000000000000000000..49ef1719b3178d59800b949ab7bdd427ca5893fc --- /dev/null +++ b/interfaces/params/keyExchange.go @@ -0,0 +1,13 @@ +package params + +import "time" + +type Rekey struct { + RoundTimeout time.Duration +} + +func GetDefaultRekey() Rekey { + return Rekey{ + RoundTimeout: time.Minute, + } +} diff --git a/keyExchange/confirm_test.go b/keyExchange/confirm_test.go index 020a8b23f07509aaf961ef68bb2fedbd850b6a37..9088fc4f68c951709bccfb5da2cb0acad537f4be 100644 --- a/keyExchange/confirm_test.go +++ b/keyExchange/confirm_test.go @@ -29,15 +29,24 @@ func TestHandleConfirm(t *testing.T) { // Generate a session ID, bypassing some business logic here sessionID := GeneratePartnerID(alicePrivKey, bobPubKey, genericGroup) + // Get Alice's manager for Bob + receivedManager, err := aliceSession.E2e().GetPartner(bobID) + if err != nil { + t.Errorf("Bob is not recognized as Alice's partner: %v", err) + } + + // Trigger negotiations, so that negotiation statuses + // can be transitioned + receivedManager.TriggerNegotiations() + // Generate the message rekey, _ := proto.Marshal(&RekeyConfirm{ SessionID: sessionID.Marshal(), }) - payload := make([]byte, 0) - payload = append(payload, rekey...) + receiveMsg := message.Receive{ - Payload: payload, + Payload: rekey, MessageType: message.NoType, Sender: bobID, Timestamp: time.Now(), @@ -46,4 +55,17 @@ func TestHandleConfirm(t *testing.T) { // Handle the confirmation handleConfirm(aliceSession, receiveMsg) + + // Get Alice's session for Bob + confirmedSession := receivedManager.GetSendSession(sessionID) + + // Check that the session is in the proper status + newSession := receivedManager.GetSendSession(sessionID) + if newSession.NegotiationStatus() != e2e.Confirmed { + t.Errorf("Session not in confirmed status!" + + "\n\tExpected: Confirmed" + + "\n\tReceived: %s", confirmedSession.NegotiationStatus()) + } + + } diff --git a/keyExchange/exchange.go b/keyExchange/exchange.go index 27ba638d6bdee8cd491b425270aa584d673425a6..d58b59ac8baf53588414653c79f18f8b1b54f385 100644 --- a/keyExchange/exchange.go +++ b/keyExchange/exchange.go @@ -3,6 +3,7 @@ package keyExchange import ( "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/switchboard" @@ -14,8 +15,8 @@ const keyExchangeTriggerName = "KeyExchangeTrigger" const keyExchangeConfirmName = "KeyExchangeConfirm" const keyExchangeMulti = "KeyExchange" -func Start(switchboard *switchboard.Switchboard, sess *storage.Session, - net interfaces.NetworkManager) stoppable.Stoppable { +func Start(switchboard *switchboard.Switchboard, sess *storage.Session, net interfaces.NetworkManager, + params params.Rekey) stoppable.Stoppable { // register the rekey trigger thread triggerCh := make(chan message.Receive, 100) @@ -31,7 +32,7 @@ func Start(switchboard *switchboard.Switchboard, sess *storage.Session, }) // start the trigger thread - go startTrigger(sess, net, triggerCh, triggerStop.Quit()) + go startTrigger(sess, net, triggerCh, triggerStop.Quit(), params) //register the rekey confirm thread confirmCh := make(chan message.Receive, 100) diff --git a/keyExchange/exchange_test.go b/keyExchange/exchange_test.go index 507bb0c2f46ab7153ef78df63c792ffb5a81d9e6..94e118772d475dcd37d7d1fb9afb2ebc3607a112 100644 --- a/keyExchange/exchange_test.go +++ b/keyExchange/exchange_test.go @@ -4,6 +4,7 @@ import ( "github.com/golang/protobuf/proto" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/e2e" "gitlab.com/elixxir/client/switchboard" @@ -38,8 +39,10 @@ func TestFullExchange(t *testing.T) { e2e.GetDefaultSessionParams(), e2e.GetDefaultSessionParams()) // Start the listeners for alice and bob - Start(aliceSwitchboard, aliceSession, aliceManager) - Start(bobSwitchboard, bobSession, bobManager) + rekeyParams := params.GetDefaultRekey() + rekeyParams.RoundTimeout = 5 * time.Second + Start(aliceSwitchboard, aliceSession, aliceManager, rekeyParams) + Start(bobSwitchboard, bobSession, bobManager, rekeyParams) // Generate a session ID, bypassing some business logic here sessionID := GeneratePartnerID(alicePrivKey, bobPubKey, genericGroup) diff --git a/keyExchange/rekey.go b/keyExchange/rekey.go index 08c136ab1cb8ecc85243ecd315226b0cad47ed14..342712fe85bf94a286dd27d37db28c1b9c2ff589 100644 --- a/keyExchange/rekey.go +++ b/keyExchange/rekey.go @@ -24,10 +24,10 @@ import ( ) func CheckKeyExchanges(instance *network.Instance, sendE2E interfaces.SendE2E, - sess *storage.Session, manager *e2e.Manager) { + sess *storage.Session, manager *e2e.Manager, sendTimeout time.Duration) { sessions := manager.TriggerNegotiations() for _, session := range sessions { - go trigger(instance, sendE2E, sess, manager, session) + go trigger(instance, sendE2E, sess, manager, session, sendTimeout) } } @@ -36,7 +36,8 @@ func CheckKeyExchanges(instance *network.Instance, sendE2E interfaces.SendE2E, // session. They run the same negotiation, the former does it on a newly created // session while the latter on an extand func trigger(instance *network.Instance, sendE2E interfaces.SendE2E, - sess *storage.Session, manager *e2e.Manager, session *e2e.Session) { + sess *storage.Session, manager *e2e.Manager, session *e2e.Session, + sendTimeout time.Duration) { var negotiatingSession *e2e.Session switch session.NegotiationStatus() { // If the passed session is triggering a negotiation on a new session to @@ -56,7 +57,7 @@ func trigger(instance *network.Instance, sendE2E interfaces.SendE2E, } // send the rekey notification to the partner - err := negotiate(instance, sendE2E, sess, negotiatingSession) + err := negotiate(instance, sendE2E, sess, negotiatingSession, sendTimeout) // if sending the negotiation fails, revert the state of the session to // unconfirmed so it will be triggered in the future if err != nil { @@ -66,7 +67,8 @@ func trigger(instance *network.Instance, sendE2E interfaces.SendE2E, } func negotiate(instance *network.Instance, sendE2E interfaces.SendE2E, - sess *storage.Session, session *e2e.Session) error { + sess *storage.Session, session *e2e.Session, + sendTimeout time.Duration) error { e2eStore := sess.E2e() //generate public key @@ -111,7 +113,7 @@ func negotiate(instance *network.Instance, sendE2E interfaces.SendE2E, //Register the event for all rounds roundEvents := instance.GetRoundEvents() for _, r := range rounds { - roundEvents.AddRoundEventChan(r, sendResults, 1*time.Minute, + roundEvents.AddRoundEventChan(r, sendResults, sendTimeout, states.COMPLETED, states.FAILED) } diff --git a/keyExchange/trigger.go b/keyExchange/trigger.go index 77abc94cad0d5b98132baa1cb96d15c4b6cb3723..60fb18d2ea48a525619884ff3ec283a4481bf37a 100644 --- a/keyExchange/trigger.go +++ b/keyExchange/trigger.go @@ -14,7 +14,6 @@ import ( ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/primitives/states" - "time" ) const ( @@ -23,13 +22,13 @@ const ( ) func startTrigger(sess *storage.Session, net interfaces.NetworkManager, - c chan message.Receive, quitCh <-chan struct{}) { + c chan message.Receive, quitCh <-chan struct{}, params params.Rekey) { for true { select { case <-quitCh: return case request := <-c: - err := handleTrigger(sess, net, request) + err := handleTrigger(sess, net, request, params) if err != nil { jww.ERROR.Printf("Failed to handle rekey trigger: %s", err) @@ -39,7 +38,7 @@ func startTrigger(sess *storage.Session, net interfaces.NetworkManager, } func handleTrigger(sess *storage.Session, net interfaces.NetworkManager, - request message.Receive) error { + request message.Receive, param params.Rekey) error { //ensure the message was encrypted properly if request.Encryption != message.E2E { errMsg := fmt.Sprintf(errBadTrigger, request.Sender) @@ -122,14 +121,17 @@ func handleTrigger(sess *storage.Session, net interfaces.NetworkManager, sendResults := make(chan ds.EventReturn, len(rounds)) roundEvents := net.GetInstance().GetRoundEvents() for _, r := range rounds { - roundEvents.AddRoundEventChan(r, sendResults, 1*time.Minute, + roundEvents.AddRoundEventChan(r, sendResults, param.RoundTimeout, states.COMPLETED, states.FAILED) } + + fmt.Println("before tracking") //Wait until the result tracking responds success, numTimeOut, numRoundFail := utility.TrackResults(sendResults, len(rounds)) // If a single partition of the Key Negotiation request does not // transmit, the partner will not be able to read the confirmation. If // such a failure occurs + fmt.Println("after tracking") if !success { jww.ERROR.Printf("Key Negotiation for %s failed to "+ "transmit %v/%v paritions: %v round failures, %v timeouts", diff --git a/keyExchange/trigger_test.go b/keyExchange/trigger_test.go index 1c0c5da6e83e1aeac479988256e078eaab7cdb50..824e5f75236fd596d001c2d76ed1c64228971d3b 100644 --- a/keyExchange/trigger_test.go +++ b/keyExchange/trigger_test.go @@ -2,7 +2,10 @@ package keyExchange import ( "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/e2e" + "gitlab.com/elixxir/crypto/csprng" + dh "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/xx_network/primitives/id" "google.golang.org/protobuf/proto" "testing" @@ -19,6 +22,10 @@ func TestHandleTrigger(t *testing.T) { alicePrivKey := aliceSession.E2e().GetDHPrivateKey() bobPubKey := bobSession.E2e().GetDHPublicKey() + // Generate bob's new keypair + newBobPrivKey := dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, genericGroup, csprng.NewSystemRNG()) + newBobPubKey := dh.GeneratePublicKey(newBobPrivKey, genericGroup) + // Maintain an ID for bob bobID := id.NewIdFromBytes([]byte("test"), t) @@ -27,19 +34,16 @@ func TestHandleTrigger(t *testing.T) { e2e.GetDefaultSessionParams(), e2e.GetDefaultSessionParams()) // Generate a session ID, bypassing some business logic here - sessionID := GeneratePartnerID(alicePrivKey, bobPubKey, genericGroup) + oldSessionID := GeneratePartnerID(alicePrivKey, bobPubKey, genericGroup) // Generate the message rekey, _ := proto.Marshal(&RekeyTrigger{ - SessionID: sessionID.Marshal(), - PublicKey: bobPubKey.Bytes(), + SessionID: oldSessionID.Marshal(), + PublicKey: newBobPubKey.Bytes(), }) - payload := make([]byte, 0) - - payload = append(payload, rekey...) receiveMsg := message.Receive{ - Payload: payload, + Payload: rekey, MessageType: message.NoType, Sender: bobID, Timestamp: time.Now(), @@ -47,8 +51,43 @@ func TestHandleTrigger(t *testing.T) { } // Handle the trigger and check for an error - err := handleTrigger(aliceSession, aliceManager, receiveMsg) + rekeyParams := params.GetDefaultRekey() + rekeyParams.RoundTimeout = 0 * time.Second + err := handleTrigger(aliceSession, aliceManager, receiveMsg, rekeyParams) if err != nil { t.Errorf("Handle trigger error: %v", err) } + + // Get Alice's manager for reception from Bob + receivedManager, err := aliceSession.E2e().GetPartner(bobID) + if err != nil { + t.Errorf("Failed to get bob's manager: %v", err) + } + + // Generate the new session ID based off of Bob's new keys + baseKey := dh.GenerateSessionKey(alicePrivKey, newBobPubKey, genericGroup) + newSessionID := e2e.GetSessionIDFromBaseKeyForTesting(baseKey, t) + + // Check that this new session ID is now in the manager + newSession := receivedManager.GetReceiveSession(newSessionID) + if newSession == nil { + t.Errorf("Did not get expected session") + } + + // Generate a keypair alice will not recognize + unknownPrivateKey := dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, genericGroup, csprng.NewSystemRNG()) + unknownPubliceKey := dh.GeneratePublicKey(unknownPrivateKey, genericGroup) + + // Generate a new session ID based off of these unrecognized keys + badSessionID := e2e.GetSessionIDFromBaseKeyForTesting(unknownPubliceKey, t) + + // Check that this session with unrecognized keys is not valid + badSession := receivedManager.GetReceiveSession(badSessionID) + if badSession != nil { + t.Errorf("Alice found a session from an unknown keypair. " + + "\nSession: %v", badSession) + } + + + } diff --git a/keyExchange/utils_test.go b/keyExchange/utils_test.go index 47fb71b9a9c4329aef8c06bff04539ab2b9e32ef..da439420b22bccbf6fdade6b3d77a71308e549ec 100644 --- a/keyExchange/utils_test.go +++ b/keyExchange/utils_test.go @@ -45,15 +45,15 @@ type testNetworkManagerGeneric struct { } func (t *testNetworkManagerGeneric) GetHealthTracker() interfaces.HealthTracker { - panic("implement me") + return nil } func (t *testNetworkManagerGeneric) Follow() (stoppable.Stoppable, error) { - panic("implement me") + return nil, nil } func (t *testNetworkManagerGeneric) CheckGarbledMessages() { - panic("implement me") + return } func (t *testNetworkManagerGeneric) SendE2E(m message.Send, p params.E2E) ([]id.Round, error) { @@ -131,15 +131,15 @@ type testNetworkManagerFullExchange struct { } func (t *testNetworkManagerFullExchange) GetHealthTracker() interfaces.HealthTracker { - panic("implement me") + return nil } func (t *testNetworkManagerFullExchange) Follow() (stoppable.Stoppable, error) { - panic("implement me") + return nil, nil } func (t *testNetworkManagerFullExchange) CheckGarbledMessages() { - panic("implement me") + return } // Intended for alice to send to bob. Trigger's Bob's confirmation, chaining the operation diff --git a/network/message/sendE2E.go b/network/message/sendE2E.go index 92907519a8a1055536c5329d4554268f1b746814..f33d0126736546876e821bce905f8c3a3220f8c8 100644 --- a/network/message/sendE2E.go +++ b/network/message/sendE2E.go @@ -72,7 +72,7 @@ func (m *Manager) SendE2E(msg message.Send, param params.E2E) ([]id.Round, error // while waiting check if any rekeys need to happen and trigger them. This // can happen now because the key popping happens in this thread, // only the sending is parallelized - keyExchange.CheckKeyExchanges(m.Instance, m.SendE2E, m.Session, partner) + keyExchange.CheckKeyExchanges(m.Instance, m.SendE2E, m.Session, partner, 1*time.Minute) wg.Wait() diff --git a/storage/e2e/session.go b/storage/e2e/session.go index 2c9fb39d4031969b57a92d0b7f41bb0b5b8abe12..09d3d0bccdce470d5e08fd1cedc493e4efeaed93 100644 --- a/storage/e2e/session.go +++ b/storage/e2e/session.go @@ -11,6 +11,7 @@ import ( "fmt" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" dh "gitlab.com/elixxir/crypto/diffieHellman" @@ -18,6 +19,7 @@ import ( "gitlab.com/elixxir/crypto/hash" "gitlab.com/xx_network/primitives/id" "sync" + "testing" "time" ) @@ -216,6 +218,23 @@ func getSessionIDFromBaseKey(baseKey *cyclic.Int) SessionID { return sid } +//underlying definition of session id +// FOR TESTING PURPOSES ONLY +func GetSessionIDFromBaseKeyForTesting(baseKey *cyclic.Int, i interface{}) SessionID { + switch i.(type) { + case *testing.T: + break + case *testing.M: + break + case *testing.B: + break + default: + globals.Log.FATAL.Panicf("GetSessionIDFromBaseKeyForTesting is restricted to testing only. Got %T", i) + } + return getSessionIDFromBaseKey(baseKey) +} + + //Blake2B hash of base key used for storage func (s *Session) GetID() SessionID { return getSessionIDFromBaseKey(s.baseKey)