diff --git a/auth/callback.go b/auth/callback.go index 791292f3e6782c4e3648f1246715300a90676f73..f9ca1cfac8d3e0974494b9369fd3ac73b7854641 100644 --- a/auth/callback.go +++ b/auth/callback.go @@ -180,8 +180,11 @@ func (m *Manager) handleRequest(cmixMsg format.Message, " msgDigest: %s which has been requested, auto-confirming", partnerID, cmixMsg.Digest()) // do the confirmation - if err := m.doConfirm(sr2, grp, partnerPubKey, m.storage.E2e().GetDHPrivateKey(), - sr2.GetPartnerHistoricalPubKey(), ecrFmt.GetOwnership()); err != nil { + if err := m.doConfirm(sr2, grp, partnerPubKey, + m.storage.E2e().GetDHPrivateKey(), + sr2.GetPartnerHistoricalPubKey(), + ecrFmt.GetOwnership(), + partnerSIDHPubKey); err != nil { em := fmt.Sprintf("Auto Confirmation with %s failed: %s", partnerID, err) jww.WARN.Print(em) @@ -293,7 +296,8 @@ func (m *Manager) handleConfirm(cmixMsg format.Message, sr *auth.SentRequest, // finalize the confirmation if err := m.doConfirm(sr, grp, partnerPubKey, sr.GetMyPrivKey(), sr.GetPartnerHistoricalPubKey(), - ecrFmt.GetOwnership()); err != nil { + ecrFmt.GetOwnership(), + partnerSIDHPubKey); err != nil { em := fmt.Sprintf("Confirmation failed: %s", err) jww.WARN.Print(em) events.Report(10, "Auth", "ConfirmError", em) @@ -303,7 +307,8 @@ func (m *Manager) handleConfirm(cmixMsg format.Message, sr *auth.SentRequest, } func (m *Manager) doConfirm(sr *auth.SentRequest, grp *cyclic.Group, - partnerPubKey, myPrivateKeyOwnershipProof, partnerPubKeyOwnershipProof *cyclic.Int, ownershipProof []byte) error { + partnerPubKey, myPrivateKeyOwnershipProof, partnerPubKeyOwnershipProof *cyclic.Int, + ownershipProof []byte, partnerSIDHPubKey *sidh.PublicKey) error { // verify the message came from the intended recipient if !cAuth.VerifyOwnershipProof(myPrivateKeyOwnershipProof, partnerPubKeyOwnershipProof, grp, ownershipProof) { @@ -315,7 +320,8 @@ func (m *Manager) doConfirm(sr *auth.SentRequest, grp *cyclic.Group, // the second does not p := m.storage.E2e().GetE2ESessionParams() if err := m.storage.E2e().AddPartner(sr.GetPartner(), - partnerPubKey, sr.GetMyPrivKey(), p, p); err != nil { + partnerPubKey, sr.GetMyPrivKey(), partnerSIDHPubKey, + sr.GetMySIDHPrivKey(), p, p); err != nil { return errors.Errorf("Failed to create channel with partner (%s) "+ "after confirmation: %+v", sr.GetPartner(), err) @@ -392,7 +398,7 @@ func handleBaseFormat(cmixMsg format.Message, grp *cyclic.Group) (baseFormat, *cyclic.Int, *sidh.PublicKey, error) { baseFmt, err := unmarshalBaseFormat(cmixMsg.GetContents(), - grp.GetP().ByteLen(), sidhinterface.SidHPubKeyByteSize) + grp.GetP().ByteLen(), sidhinterface.PubKeyByteSize) if err != nil { return baseFormat{}, nil, nil, errors.WithMessage(err, "Failed to"+ " unmarshal auth") diff --git a/auth/confirm.go b/auth/confirm.go index a8fe1552edfd957933524f46288b36db5a398c08..8e6475756f7b36d4e4c22389e99614d580aca275 100644 --- a/auth/confirm.go +++ b/auth/confirm.go @@ -23,6 +23,7 @@ import ( "gitlab.com/xx_network/primitives/id" sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" "io" + util "gitlab.com/elixxir/client/storage/utility" ) func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, @@ -37,11 +38,13 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, } // check if the partner has an auth in progress - // this takes the lock, from this point forward any errors need to release - // the lock - storedContact, _, err := storage.Auth().GetReceivedRequest(partner.ID) + // this takes the lock, from this point forward any errors need to + // release the lock + storedContact, theirSidhKey, err := storage.Auth().GetReceivedRequest( + partner.ID) if err != nil { - return 0, errors.Errorf("failed to find a pending Auth Request: %s", + return 0, errors.Errorf( + "failed to find a pending Auth Request: %s", err) } defer storage.Auth().Done(partner.ID) @@ -49,8 +52,8 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, // verify the passed contact matches what is stored if storedContact.DhPubKey.Cmp(partner.DhPubKey) != 0 { storage.Auth().Done(partner.ID) - return 0, errors.WithMessage(err, "Pending Auth Request has different "+ - "pubkey than stored") + return 0, errors.WithMessage(err, + "Pending Auth Request has different pubkey than stored") } grp := storage.E2e().GetGroup() @@ -65,6 +68,10 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, newPrivKey := diffieHellman.GeneratePrivateKey(256, grp, rng) newPubKey := diffieHellman.GeneratePublicKey(newPrivKey, grp) + sidhVariant := util.GetSIDHVariant(theirSidhKey.Variant()) + newSIDHPrivKey := util.NewSIDHPrivateKey(sidhVariant) + newSIDHPubKey := util.NewSIDHPublicKey(sidhVariant) + //generate salt salt := make([]byte, saltSize) _, err = rng.Read(salt) @@ -77,7 +84,8 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, // we build the payload before we save because it is technically fallible // which can get into a bricked state if it fails cmixMsg := format.NewMessage(storage.Cmix().GetGroup().GetP().ByteLen()) - baseFmt := newBaseFormat(cmixMsg.ContentsSize(), grp.GetP().ByteLen(), sidhinterface.SidHPubKeyByteSize) + baseFmt := newBaseFormat(cmixMsg.ContentsSize(), grp.GetP().ByteLen(), + sidhinterface.PubKeyByteSize) ecrFmt := newEcrFormat(baseFmt.GetEcrPayloadLen()) // setup the encrypted payload @@ -96,6 +104,7 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, baseFmt.SetEcrPayload(ecrPayload) baseFmt.SetSalt(salt) baseFmt.SetPubKey(newPubKey) + baseFmt.SetSidHPubKey(newSIDHPubKey) cmixMsg.SetKeyFP(fp) cmixMsg.SetMac(mac) @@ -109,7 +118,8 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, //create local relationship p := storage.E2e().GetE2ESessionParams() - if err := storage.E2e().AddPartner(partner.ID, partner.DhPubKey, newPrivKey, + if err := storage.E2e().AddPartner(partner.ID, partner.DhPubKey, + newPrivKey, theirSidhKey, newSIDHPrivKey, p, p); err != nil { em := fmt.Sprintf("Failed to create channel with partner (%s) "+ "on confirmation, this is likley a replay: %s", diff --git a/auth/fmt.go b/auth/fmt.go index 83855fd8c0f578175556a274c069ff0885cd26f9..4580725d39c1f020f9ca34561cc367bbdb13caf8 100644 --- a/auth/fmt.go +++ b/auth/fmt.go @@ -80,7 +80,7 @@ func (f baseFormat) SetSidHPubKey(pubKey *sidh.PublicKey) { } func (f baseFormat) GetSidhPubKey() (*sidh.PublicKey, error) { - pubKey := sidh.NewPublicKey(sidhinterface.SidHKeyId, + pubKey := sidh.NewPublicKey(sidhinterface.KeyId, sidh.KeyVariantSidhA) err := pubKey.Import(f.sidHpubkey) return pubKey, err diff --git a/auth/fmt_test.go b/auth/fmt_test.go index 68fc7d000aacc2aa096c7ccdd58a46d4dd0be472..8ffab3b86a43380ffcffa35c1503a6e0b997df54 100644 --- a/auth/fmt_test.go +++ b/auth/fmt_test.go @@ -20,9 +20,9 @@ import ( func TestNewBaseFormat(t *testing.T) { // Construct message pubKeySize := 256 - payloadSize := saltSize + pubKeySize + sidhinterface.SidHPubKeyByteSize + payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize baseMsg := newBaseFormat(payloadSize, pubKeySize, - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) // Check that the base format was constructed properly if !bytes.Equal(baseMsg.pubkey, make([]byte, pubKeySize)) { @@ -40,7 +40,7 @@ func TestNewBaseFormat(t *testing.T) { } expectedEcrPayloadSize := payloadSize - (pubKeySize + - sidhinterface.SidHPubKeyByteSize + saltSize) + sidhinterface.PubKeyByteSize + saltSize) if !bytes.Equal(baseMsg.ecrPayload, make([]byte, expectedEcrPayloadSize)) { t.Errorf("NewBaseFormat error: "+ "Unexpected payload field in base format."+ @@ -56,7 +56,7 @@ func TestNewBaseFormat(t *testing.T) { } }() - newBaseFormat(0, pubKeySize, sidhinterface.SidHPubKeyByteSize) + newBaseFormat(0, pubKeySize, sidhinterface.PubKeyByteSize) } /* Tests the setter/getter methods for baseFormat */ @@ -65,9 +65,9 @@ func TestNewBaseFormat(t *testing.T) { func TestBaseFormat_SetGetPubKey(t *testing.T) { // Construct message pubKeySize := 256 - payloadSize := saltSize + pubKeySize + sidhinterface.SidHPubKeyByteSize + payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize baseMsg := newBaseFormat(payloadSize, pubKeySize, - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) // Test setter grp := getGroup() @@ -94,9 +94,9 @@ func TestBaseFormat_SetGetPubKey(t *testing.T) { func TestBaseFormat_SetGetSalt(t *testing.T) { // Construct message pubKeySize := 256 - payloadSize := saltSize + pubKeySize + sidhinterface.SidHPubKeyByteSize + payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize baseMsg := newBaseFormat(payloadSize, pubKeySize, - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) // Test setter salt := newSalt("salt") @@ -130,13 +130,13 @@ func TestBaseFormat_SetGetSalt(t *testing.T) { func TestBaseFormat_SetGetEcrPayload(t *testing.T) { // Construct message pubKeySize := 256 - payloadSize := (saltSize + pubKeySize + sidhinterface.SidHPubKeyByteSize) * 2 + payloadSize := (saltSize + pubKeySize + sidhinterface.PubKeyByteSize) * 2 baseMsg := newBaseFormat(payloadSize, pubKeySize, - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) // Test setter ecrPayloadSize := payloadSize - (pubKeySize + saltSize + - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) ecrPayload := newPayload(ecrPayloadSize, "ecrPayload") baseMsg.SetEcrPayload(ecrPayload) if !bytes.Equal(ecrPayload, baseMsg.ecrPayload) { @@ -169,11 +169,11 @@ func TestBaseFormat_SetGetEcrPayload(t *testing.T) { func TestBaseFormat_MarshalUnmarshal(t *testing.T) { // Construct a fully populated message pubKeySize := 256 - payloadSize := (saltSize + pubKeySize + sidhinterface.SidHPubKeyByteSize) * 2 + payloadSize := (saltSize + pubKeySize + sidhinterface.PubKeyByteSize) * 2 baseMsg := newBaseFormat(payloadSize, pubKeySize, - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) ecrPayloadSize := payloadSize - (pubKeySize + saltSize + - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) ecrPayload := newPayload(ecrPayloadSize, "ecrPayload") baseMsg.SetEcrPayload(ecrPayload) salt := newSalt("salt") @@ -192,7 +192,7 @@ func TestBaseFormat_MarshalUnmarshal(t *testing.T) { // Test unmarshal newMsg, err := unmarshalBaseFormat(data, pubKeySize, - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) if err != nil { t.Errorf("unmarshalBaseFormat() error: "+ "Could not unmarshal into baseFormat: %v", err) @@ -206,7 +206,7 @@ func TestBaseFormat_MarshalUnmarshal(t *testing.T) { // Unmarshal error test: Invalid size parameter _, err = unmarshalBaseFormat(make([]byte, 0), pubKeySize, - sidhinterface.SidHPubKeyByteSize) + sidhinterface.PubKeyByteSize) if err == nil { t.Errorf("unmarshalBaseFormat() error: " + "Should not be able to unmarshal when baseFormat is too small") @@ -383,7 +383,7 @@ func TestNewRequestFormat(t *testing.T) { // FIXME: Commented out for now.. it's not clear why this was necessary // if !bytes.Equal(reqMsg.GetPayload(), make([]byte, 0, - // sidhinterface.SidHPubKeyByteSize)) { + // sidhinterface.PubKeyByteSize)) { // t.Errorf("newRequestFormat() error: "+ // "Unexpected msgPayload field in requestFormat."+ // "\n\tExpected: %v"+ @@ -445,10 +445,10 @@ func TestRequestFormat_SetGetID(t *testing.T) { // Unit test for Get/SetMsgPayload func TestRequestFormat_SetGetMsgPayload(t *testing.T) { // Construct message - payloadSize := id.ArrIDLen*3 - 1 + sidhinterface.SidHPubKeyByteSize + payloadSize := id.ArrIDLen*3 - 1 + sidhinterface.PubKeyByteSize ecrMsg := newEcrFormat(payloadSize) expectedPayload := newPayload(id.ArrIDLen*2 + - sidhinterface.SidHPubKeyByteSize, "ownership") + sidhinterface.PubKeyByteSize, "ownership") ecrMsg.SetPayload(expectedPayload) reqMsg, err := newRequestFormat(ecrMsg) if err != nil { @@ -457,7 +457,7 @@ func TestRequestFormat_SetGetMsgPayload(t *testing.T) { } // Test SetMsgPayload - msgPayload := newPayload(id.ArrIDLen*2 + sidhinterface.SidHPubKeyByteSize, + msgPayload := newPayload(id.ArrIDLen*2 + sidhinterface.PubKeyByteSize, "msgPayload") reqMsg.SetPayload(msgPayload) if !bytes.Equal(reqMsg.GetPayload(), msgPayload) { diff --git a/auth/request.go b/auth/request.go index 637e04c56542f2d80cc16d6e4b80f805e5cc7ec6..e4971d044d8a39ed0793edb62fc09e360617060d 100644 --- a/auth/request.go +++ b/auth/request.go @@ -17,6 +17,7 @@ import ( "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/interfaces/preimage" "gitlab.com/elixxir/client/storage" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/auth" "gitlab.com/elixxir/client/storage/e2e" "gitlab.com/elixxir/client/storage/edge" @@ -75,7 +76,8 @@ func RequestAuth(partner, me contact.Contact, rng io.Reader, /*generate embedded message structures and check payload*/ cmixMsg := format.NewMessage(storage.Cmix().GetGroup().GetP().ByteLen()) - baseFmt := newBaseFormat(cmixMsg.ContentsSize(), grp.GetP().ByteLen(), sidhinterface.SidHPubKeyByteSize) + baseFmt := newBaseFormat(cmixMsg.ContentsSize(), grp.GetP().ByteLen(), + sidhinterface.PubKeyByteSize) ecrFmt := newEcrFormat(baseFmt.GetEcrPayloadLen()) requestFmt, err := newRequestFormat(ecrFmt) if err != nil { @@ -99,16 +101,16 @@ func RequestAuth(partner, me contact.Contact, rng io.Reader, if resend { newPrivKey = sr.GetMyPrivKey() newPubKey = sr.GetMyPubKey() - sidHPrivKeyA = sr.GetMySidhPrivKeyA() - sidHPubKeyA = sr.GetMySidhPubKeyA() + sidHPrivKeyA = sr.GetMySIDHPrivKey() + sidHPubKeyA = sr.GetMySIDHPubKey() //in this case it is a new request and we must generate new keys } else { //generate new keypair newPrivKey = diffieHellman.GeneratePrivateKey(256, grp, rng) newPubKey = diffieHellman.GeneratePublicKey(newPrivKey, grp) - sidHPrivKeyA = sidh.NewPrivateKey(sidhinterface.SidHKeyId, sidh.KeyVariantSidhA) - sidHPubKeyA = sidh.NewPublicKey(sidhinterface.SidHKeyId, sidh.KeyVariantSidhA) + sidHPrivKeyA = util.NewSIDHPrivateKey(sidh.KeyVariantSidhA) + sidHPubKeyA = util.NewSIDHPublicKey(sidh.KeyVariantSidhA) if err = sidHPrivKeyA.Generate(rng); err!=nil{ return 0, errors.WithMessagef(err, "Failed to send requrest due to " +