diff --git a/auth/callback.go b/auth/callback.go index a437d834ccc7240cdcc5ee18ee85528c6fc99d8a..34f8eb064222a1d02a899a1e96b72e7a785b501d 100644 --- a/auth/callback.go +++ b/auth/callback.go @@ -107,10 +107,19 @@ func (m *Manager) handleRequest(cmixMsg format.Message, jww.TRACE.Printf("handleRequest ECRPAYLOAD: %v", baseFmt.GetEcrPayload()) jww.TRACE.Printf("handleRequest MAC: %v", cmixMsg.GetMac()) + ecrPayload := baseFmt.GetEcrPayload() success, payload := cAuth.Decrypt(myHistoricalPrivKey, - partnerPubKey, baseFmt.GetEcrPayload(), + partnerPubKey, ecrPayload, cmixMsg.GetMac(), grp) + if !success { + jww.WARN.Printf("Attempting to decrypt old request packet...") + ecrPayload = append(ecrPayload, baseFmt.GetVersion()) + success, payload = cAuth.Decrypt(myHistoricalPrivKey, + partnerPubKey, ecrPayload, + cmixMsg.GetMac(), grp) + } + if !success { jww.WARN.Printf("Received auth request failed " + "its mac check") @@ -531,7 +540,7 @@ func handleBaseFormat(cmixMsg format.Message, grp *cyclic.Group) (baseFormat, baseFmt, err := unmarshalBaseFormat(cmixMsg.GetContents(), grp.GetP().ByteLen()) - if err != nil { + if err != nil && baseFmt == nil { return baseFormat{}, nil, errors.WithMessage(err, "Failed to"+ " unmarshal auth") } @@ -542,5 +551,5 @@ func handleBaseFormat(cmixMsg format.Message, grp *cyclic.Group) (baseFormat, } partnerPubKey := grp.NewIntFromBytes(baseFmt.pubkey) - return baseFmt, partnerPubKey, nil + return *baseFmt, partnerPubKey, nil } diff --git a/auth/fmt.go b/auth/fmt.go index f267945be7934705f7046b948efc409c42f51d6d..cf38aaed44967d8a825a27451783bf5318038544 100644 --- a/auth/fmt.go +++ b/auth/fmt.go @@ -65,18 +65,18 @@ func buildBaseFormat(data []byte, pubkeySize int) baseFormat { return f } -func unmarshalBaseFormat(b []byte, pubkeySize int) (baseFormat, error) { +func unmarshalBaseFormat(b []byte, pubkeySize int) (*baseFormat, error) { if len(b) < pubkeySize { - return baseFormat{}, errors.New("Received baseFormat too small") + return nil, errors.New("Received baseFormat too small") } bfmt := buildBaseFormat(b, pubkeySize) version := bfmt.GetVersion() if version != requestFmtVersion { - return baseFormat{}, errors.Errorf( + return &bfmt, errors.Errorf( "Unknown baseFormat version: %d", version) } - return bfmt, nil + return &bfmt, nil } func (f baseFormat) Marshal() []byte { diff --git a/auth/fmt_test.go b/auth/fmt_test.go index 64785b399abc261400a346fceb68bc4ee0fc59c0..30580ec1bef400eb05409d3033076e9f0b00b4cd 100644 --- a/auth/fmt_test.go +++ b/auth/fmt_test.go @@ -151,10 +151,10 @@ func TestBaseFormat_MarshalUnmarshal(t *testing.T) { "Could not unmarshal into baseFormat: %v", err) } - if !reflect.DeepEqual(newMsg, baseMsg) { + if !reflect.DeepEqual(*newMsg, baseMsg) { t.Errorf("unmarshalBaseFormat() error: "+ "Unmarshalled message does not match originally marshalled message."+ - "\n\tExpected: %v\n\tRecieved: %v", baseMsg, newMsg) + "\n\tExpected: %v\n\tRecieved: %v", baseMsg, *newMsg) } // Unmarshal error test: Invalid size parameter diff --git a/go.mod b/go.mod index d21814b72e803fcee02798ea1f6c1b288361e2a8..702a42a82cc1b4fe1af9adfecc7f5cb4c620ead0 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.7.1 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 - gitlab.com/elixxir/comms v0.0.4-0.20220302214218-7cef54bc0c37 + gitlab.com/elixxir/comms v0.0.4-0.20220308001050-fc12c9f23295 gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b gitlab.com/elixxir/ekv v0.1.6 gitlab.com/elixxir/primitives v0.0.3-0.20220222212109-d412a6e46623 diff --git a/go.sum b/go.sum index 9ab0c958936ee3dda207fc2f11880a93d4b26441..5d19aa93263a7c5c77ec457cf84c1782f7ba12eb 100644 --- a/go.sum +++ b/go.sum @@ -274,6 +274,8 @@ gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= gitlab.com/elixxir/comms v0.0.4-0.20220302214218-7cef54bc0c37 h1:VifEG3xpMq8bKkOyIL3KvEeyWCBmPvadKc7Mss5TZ1A= gitlab.com/elixxir/comms v0.0.4-0.20220302214218-7cef54bc0c37/go.mod h1:4yMdU+Jee5W9lqkZGHJAuipEhW7FloT0eyVEFUJza+E= +gitlab.com/elixxir/comms v0.0.4-0.20220308001050-fc12c9f23295 h1:PtGwLthY45FuHJNN4znhlsbDdHk2OEBwMEjDrHNyHTs= +gitlab.com/elixxir/comms v0.0.4-0.20220308001050-fc12c9f23295/go.mod h1:4yMdU+Jee5W9lqkZGHJAuipEhW7FloT0eyVEFUJza+E= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b h1:m80Ub5mshPbMzYjRC0nXuI8vtm6e5crISczRsP2YUJ4=