diff --git a/auth/callback.go b/auth/callback.go index f9ca1cfac8d3e0974494b9369fd3ac73b7854641..f73c3ea1f1ffd28cb6a2d660a1bad07e174670b1 100644 --- a/auth/callback.go +++ b/auth/callback.go @@ -26,6 +26,9 @@ import ( "gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/format" "strings" + util "gitlab.com/elixxir/client/storage/utility" + "gitlab.com/elixxir/crypto/fastRNG" + "gitlab.com/xx_network/crypto/csprng" ) func (m *Manager) StartProcesses() (stoppable.Stoppable, error) { @@ -179,6 +182,18 @@ func (m *Manager) handleRequest(cmixMsg format.Message, jww.INFO.Printf("Received AuthRequest from %s,"+ " msgDigest: %s which has been requested, auto-confirming", partnerID, cmixMsg.Digest()) + // Note that our sent request SIDH key needs to + // change to be compatible + rngGen := fastRNG.NewStreamGenerator(1, 1, + csprng.NewSystemRNG) + rng := rngGen.GetStream() + myVariant := util.GetCompatibleSIDHVariant( + partnerSIDHPubKey.Variant()) + myPriv, myPub := util.GenerateSIDHKeyPair( + myVariant, rng) + sr2.OverwriteSIDHKeys(myPriv, myPub) + rng.Close() + // do the confirmation if err := m.doConfirm(sr2, grp, partnerPubKey, m.storage.E2e().GetDHPrivateKey(), @@ -197,23 +212,12 @@ func (m *Manager) handleRequest(cmixMsg format.Message, } } - //process the inner payload - facts, msg, err := fact.UnstringifyFactList( - string(requestFmt.GetPayload())) - if err != nil { - em := fmt.Sprintf("failed to parse facts and message "+ - "from Auth Request: %s", err) - jww.WARN.Print(em) - events.Report(10, "Auth", "RequestError", em) - return - } - - //create the contact + //create the contact, note that no facts are sent in the payload c := contact.Contact{ ID: partnerID, DhPubKey: partnerPubKey, OwnershipProof: copySlice(ecrFmt.ownership), - Facts: facts, + Facts: make([]fact.Fact, 0), } // fixme: the client will never be notified of the channel creation if a @@ -232,7 +236,7 @@ func (m *Manager) handleRequest(cmixMsg format.Message, cbList := m.requestCallbacks.Get(c.ID) for _, cb := range cbList { rcb := cb.(interfaces.RequestCallback) - go rcb(c, msg) + go rcb(c, "") } return } diff --git a/auth/confirm.go b/auth/confirm.go index 8e6475756f7b36d4e4c22389e99614d580aca275..8a05297de5f67b6a32205a35bf6e5667825e252a 100644 --- a/auth/confirm.go +++ b/auth/confirm.go @@ -68,7 +68,7 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, newPrivKey := diffieHellman.GeneratePrivateKey(256, grp, rng) newPubKey := diffieHellman.GeneratePublicKey(newPrivKey, grp) - sidhVariant := util.GetSIDHVariant(theirSidhKey.Variant()) + sidhVariant := util.GetCompatibleSIDHVariant(theirSidhKey.Variant()) newSIDHPrivKey := util.NewSIDHPrivateKey(sidhVariant) newSIDHPubKey := util.NewSIDHPublicKey(sidhVariant) diff --git a/storage/auth/sentRequest.go b/storage/auth/sentRequest.go index 42b908192d4c2ffad9499607ebc97cde86ea01d1..2b42df4727b99f58448ce3de2ca888ec217a34d8 100644 --- a/storage/auth/sentRequest.go +++ b/storage/auth/sentRequest.go @@ -205,6 +205,16 @@ func (sr *SentRequest) GetMySIDHPubKey() *sidh.PublicKey { return sr.mySidHPubKeyA } +// OverwriteSIDHKeys is used to temporarily overwrite sidh keys +// to handle e.g., confirmation requests. +// FIXME: this is a code smell but was the cleanest solution at +// the time. Business logic should probably handle this better? +func (sr *SentRequest) OverwriteSIDHKeys(priv *sidh.PrivateKey, + pub *sidh.PublicKey) { + sr.mySidHPrivKeyA = priv + sr.mySidHPubKeyA = pub +} + func (sr *SentRequest) GetFingerprint() format.Fingerprint { return sr.fingerprint } diff --git a/storage/e2e/session.go b/storage/e2e/session.go index ebea67c480adf9970473c69d9ffd69529a0afe79..f8c89b9721e6c16ae7e434a93624ebb45c18adc7 100644 --- a/storage/e2e/session.go +++ b/storage/e2e/session.go @@ -613,7 +613,8 @@ func (s *Session) generate(kv *versioned.KV) *versioned.KV { s.myPrivKey = dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, grp, stream) // Get the variant opposite my partners variant - sidhVariant := utility.GetSIDHVariant(s.partnerSIDHPubKey.Variant()) + sidhVariant := utility.GetCompatibleSIDHVariant( + s.partnerSIDHPubKey.Variant()) s.mySIDHPrivKey = utility.NewSIDHPrivateKey(sidhVariant) s.mySIDHPrivKey.Generate(stream) stream.Close() diff --git a/storage/utility/sidh.go b/storage/utility/sidh.go index 88053fd24ecccaf23195cb308b562dc3a3f0a948..d4bef091fd349871c3d287326e006fff3c9a0b76 100644 --- a/storage/utility/sidh.go +++ b/storage/utility/sidh.go @@ -15,6 +15,8 @@ import ( sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" "gitlab.com/xx_network/primitives/id" "fmt" + jww "github.com/spf13/jwalterweatherman" + "io" ) const currentSIDHVersion = 0 @@ -32,7 +34,7 @@ func NewSIDHPrivateKey(variant sidh.KeyVariant) *sidh.PrivateKey { } // GetSIDHVariant returns the variant opposite the otherVariant -func GetSIDHVariant(otherVariant sidh.KeyVariant) sidh.KeyVariant { +func GetCompatibleSIDHVariant(otherVariant sidh.KeyVariant) sidh.KeyVariant { // Note -- this is taken from inside the sidh lib to look for the A flag if (otherVariant & sidh.KeyVariantSidhA) == sidh.KeyVariantSidhA { return sidh.KeyVariantSidhB @@ -40,6 +42,20 @@ func GetSIDHVariant(otherVariant sidh.KeyVariant) sidh.KeyVariant { return sidh.KeyVariantSidhA } +// GenerateSIDHKeyPair generates a SIDH keypair +func GenerateSIDHKeyPair(variant sidh.KeyVariant, rng io.Reader) ( + *sidh.PrivateKey, *sidh.PublicKey) { + priv := NewSIDHPrivateKey(variant) + pub := NewSIDHPublicKey(variant) + + if err := priv.Generate(rng); err!=nil { + jww.FATAL.Panicf("Unable to generate SIDH private key: %+v", + err) + } + priv.GeneratePublicKey(pub) + return priv, pub +} + // String interface impl to dump the contents of the public key as b64 string func StringSIDHPubKey(k *sidh.PublicKey) string { kBytes := make([]byte, k.Size())