diff --git a/api/auth.go b/api/auth.go index 3114bee8cf73da4e610615524fb7a87d2d9e8512..d7a5cc362ea49dc9108e220d05c5fd45eeb5586f 100644 --- a/api/auth.go +++ b/api/auth.go @@ -11,14 +11,11 @@ import ( "encoding/binary" "math/rand" - "gitlab.com/elixxir/client/catalog" - "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/auth" - "gitlab.com/elixxir/client/interfaces" - "gitlab.com/elixxir/client/storage/edge" + "gitlab.com/elixxir/client/e2e/ratchet/partner/session" util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/primitives/fact" @@ -37,13 +34,12 @@ func (c *Client) RequestAuthenticatedChannel(recipient, me contact.Contact, message string) (id.Round, error) { jww.INFO.Printf("RequestAuthenticatedChannel(%s)", recipient.ID) - if !c.network.HealthTracker().IsHealthy() { + if !c.network.IsHealthy() { return 0, errors.New("Cannot request authenticated channel " + "creation when the network is not healthy") } - return auth.RequestAuth(recipient, me, c.rng.GetStream(), - c.storage, c.network) + return c.auth.Request(recipient, c.GetUser().GetContact().Facts) } // ResetSession resets an authenticate channel that already exists @@ -51,18 +47,17 @@ func (c *Client) ResetSession(recipient, me contact.Contact, message string) (id.Round, error) { jww.INFO.Printf("ResetSession(%s)", recipient.ID) - if !c.network.GetHealthTracker().IsHealthy() { + if !c.network.IsHealthy() { return 0, errors.New("Cannot request authenticated channel " + "creation when the network is not healthy") } - return auth.ResetSession(recipient, me, c.rng.GetStream(), - c.storage, c.network) + return c.auth.Reset(recipient) } // GetAuthRegistrar gets the object which allows the registration of auth // callbacks -func (c *Client) GetAuthRegistrar() interfaces.Auth { +func (c *Client) GetAuthRegistrar() auth.State { jww.INFO.Printf("GetAuthRegistrar(...)") return c.auth @@ -73,7 +68,7 @@ func (c *Client) GetAuthRegistrar() interfaces.Auth { func (c *Client) GetAuthenticatedChannelRequest(partner *id.ID) (contact.Contact, error) { jww.INFO.Printf("GetAuthenticatedChannelRequest(%s)", partner) - return c.storage.Auth().GetReceivedRequestData(partner) + return c.auth.GetReceivedRequest(partner) } // ConfirmAuthenticatedChannel creates an authenticated channel out of a valid @@ -87,7 +82,7 @@ func (c *Client) GetAuthenticatedChannelRequest(partner *id.ID) (contact.Contact func (c *Client) ConfirmAuthenticatedChannel(recipient contact.Contact) (id.Round, error) { jww.INFO.Printf("ConfirmAuthenticatedChannel(%s)", recipient.ID) - if !c.network.GetHealthTracker().IsHealthy() { + if !c.network.IsHealthy() { return 0, errors.New("Cannot request authenticated channel " + "creation when the network is not healthy") } @@ -100,18 +95,19 @@ func (c *Client) ConfirmAuthenticatedChannel(recipient contact.Contact) (id.Roun func (c *Client) VerifyOwnership(received, verified contact.Contact) bool { jww.INFO.Printf("VerifyOwnership(%s)", received.ID) - return auth.VerifyOwnership(received, verified, c.storage) + return c.auth.VerifyOwnership(received, verified, c.e2e) } // HasAuthenticatedChannel returns true if an authenticated channel exists for // the partner func (c *Client) HasAuthenticatedChannel(partner *id.ID) bool { - m, err := c.storage.E2e().GetPartner(partner) + m, err := c.e2e.GetPartner(partner) return m != nil && err == nil } // Create an insecure e2e relationship with a precanned user -func (c *Client) MakePrecannedAuthenticatedChannel(precannedID uint) (contact.Contact, error) { +func (c *Client) MakePrecannedAuthenticatedChannel(precannedID uint) ( + contact.Contact, error) { precan := c.MakePrecannedContact(precannedID) @@ -136,49 +132,15 @@ func (c *Client) MakePrecannedAuthenticatedChannel(precannedID uint) (contact.Co mySIDHPrivKey.GeneratePublicKey(mySIDHPubKey) // add the precanned user as a e2e contact - sesParam := c.parameters.E2EParams - err := c.storage.E2e().AddPartner(precan.ID, precan.DhPubKey, - c.storage.E2e().GetDHPrivateKey(), theirSIDHPubKey, + // FIXME: these params need to be threaded through... + sesParam := session.GetDefaultParams() + _, err := c.e2e.AddPartner(precan.ID, precan.DhPubKey, + c.e2e.GetHistoricalDHPrivkey(), theirSIDHPubKey, mySIDHPrivKey, sesParam, sesParam) // check garbled messages in case any messages arrived before creating // the channel - c.network.CheckGarbledMessages() - - //add the e2e and rekey firngeprints - //e2e - sessionPartner, err := c.storage.E2e().GetPartner(precan.ID) - if err != nil { - jww.FATAL.Panicf("Cannot find %s right after creating: %+v", precan.ID, err) - } - me := c.storage.GetUser().ReceptionID - - c.storage.GetEdge().Add(edge.Preimage{ - Data: sessionPartner.GetE2EPreimage(), - Type: catalog.E2e, - Source: precan.ID[:], - }, me) - - // slient (rekey) - c.storage.GetEdge().Add(edge.Preimage{ - Data: sessionPartner.GetSilentPreimage(), - Type: catalog.Silent, - Source: precan.ID[:], - }, me) - - // File transfer end - c.storage.GetEdge().Add(edge.Preimage{ - Data: sessionPartner.GetFileTransferPreimage(), - Type: catalog.EndFT, - Source: precan.ID[:], - }, me) - - // group request - c.storage.GetEdge().Add(edge.Preimage{ - Data: sessionPartner.GetGroupRequestPreimage(), - Type: catalog.GroupRq, - Source: precan.ID[:], - }, me) + c.network.CheckInProgressMessages() return precan, err } @@ -186,14 +148,14 @@ func (c *Client) MakePrecannedAuthenticatedChannel(precannedID uint) (contact.Co // Create an insecure e2e contact object for a precanned user func (c *Client) MakePrecannedContact(precannedID uint) contact.Contact { - e2eGrp := c.storage.E2e().GetGroup() + e2eGrp := c.storage.GetE2EGroup() - // get the user definition precanned := createPrecannedUser(precannedID, c.rng.GetStream(), - c.storage.Cmix().GetGroup(), e2eGrp) + c.storage.GetCmixGroup(), e2eGrp) // compute their public e2e key - partnerPubKey := e2eGrp.ExpG(precanned.E2eDhPrivateKey, e2eGrp.NewInt(1)) + partnerPubKey := e2eGrp.ExpG(precanned.E2eDhPrivateKey, + e2eGrp.NewInt(1)) return contact.Contact{ ID: precanned.ReceptionID, @@ -207,12 +169,14 @@ func (c *Client) MakePrecannedContact(precannedID uint) contact.Contact { // E2E relationship. An error is returned if no relationship with the partner // is found. func (c *Client) GetRelationshipFingerprint(partner *id.ID) (string, error) { - m, err := c.storage.E2e().GetPartner(partner) + m, err := c.e2e.GetPartner(partner) if err != nil { - return "", errors.Errorf("could not get partner %s: %+v", partner, err) + return "", errors.Errorf("could not get partner %s: %+v", + partner, err) } else if m == nil { - return "", errors.Errorf("manager for partner %s is nil.", partner) + return "", errors.Errorf("manager for partner %s is nil.", + partner) } - return m.GetRelationshipFingerprint(), nil + return m.GetConnectionFingerprint(), nil } diff --git a/api/client.go b/api/client.go index 048cc24a6b84e1813ab44131fe0a698c63ff873b..1129c3a871997c6c61af4c8a9f8269ef9ab927b2 100644 --- a/api/client.go +++ b/api/client.go @@ -51,8 +51,8 @@ type Client struct { //object used for communications comms *client.Comms - // Network parameters - parameters cmix.Params + // Network parameters, note e2e params wrap CMIXParams + parameters e2e.Params network cmix.Client //object used to register and communicate with permissioning diff --git a/api/permissioning.go b/api/permissioning.go index 2dd62ec87dd8a95f43bce9f93df31db105edc4ca..b4060d994c84622f3395193c145a1e257559c815 100644 --- a/api/permissioning.go +++ b/api/permissioning.go @@ -9,17 +9,18 @@ package api import ( "encoding/json" + "github.com/pkg/errors" - "gitlab.com/elixxir/client/interfaces/user" "gitlab.com/elixxir/client/storage" + "gitlab.com/elixxir/client/storage/user" ) // Returns an error if registration fails. func (c *Client) registerWithPermissioning() error { - userData := c.storage.User() + userData := c.userState.CryptographicIdentity //get the users public key - transmissionPubKey := userData.GetCryptographicIdentity().GetTransmissionRSA().GetPublic() - receptionPubKey := userData.GetCryptographicIdentity().GetReceptionRSA().GetPublic() + transmissionPubKey := userData.GetTransmissionRSA().GetPublic() + receptionPubKey := userData.GetReceptionRSA().GetPublic() //load the registration code regCode, err := c.storage.GetRegCode() @@ -30,16 +31,19 @@ func (c *Client) registerWithPermissioning() error { //register with registration transmissionRegValidationSignature, receptionRegValidationSignature, - registrationTimestamp, err := c.permissioning.Register(transmissionPubKey, receptionPubKey, regCode) + registrationTimestamp, err := c.permissioning.Register( + transmissionPubKey, receptionPubKey, regCode) if err != nil { return errors.WithMessage(err, "failed to register with "+ "permissioning") } //store the signature - userData.SetTransmissionRegistrationValidationSignature(transmissionRegValidationSignature) - userData.SetReceptionRegistrationValidationSignature(receptionRegValidationSignature) - userData.SetRegistrationTimestamp(registrationTimestamp) + c.storage.SetTransmissionRegistrationValidationSignature( + transmissionRegValidationSignature) + c.storage.SetReceptionRegistrationValidationSignature( + receptionRegValidationSignature) + c.storage.SetRegistrationTimestamp(registrationTimestamp) //update the registration state err = c.storage.ForwardRegistrationStatus(storage.PermissioningComplete) @@ -50,9 +54,9 @@ func (c *Client) registerWithPermissioning() error { return nil } -// ConstructProtoUerFile is a helper function which is used for proto client testing. -// This is used for development testing. -func (c *Client) ConstructProtoUerFile() ([]byte, error) { +// ConstructProtoUserFile is a helper function which is used for proto +// client testing. This is used for development testing. +func (c *Client) ConstructProtoUserFile() ([]byte, error) { //load the registration code regCode, err := c.storage.GetRegCode() @@ -71,10 +75,10 @@ func (c *Client) ConstructProtoUerFile() ([]byte, error) { Precanned: c.GetUser().Precanned, RegistrationTimestamp: c.GetUser().RegistrationTimestamp, RegCode: regCode, - TransmissionRegValidationSig: c.storage.User().GetTransmissionRegistrationValidationSignature(), - ReceptionRegValidationSig: c.storage.User().GetReceptionRegistrationValidationSignature(), - E2eDhPrivateKey: c.GetStorage().E2e().GetDHPrivateKey(), - E2eDhPublicKey: c.GetStorage().E2e().GetDHPublicKey(), + TransmissionRegValidationSig: c.storage.GetTransmissionRegistrationValidationSignature(), + ReceptionRegValidationSig: c.storage.GetReceptionRegistrationValidationSignature(), + E2eDhPrivateKey: c.e2e.GetHistoricalDHPrivkey(), + E2eDhPublicKey: c.e2e.GetHistoricalDHPubkey(), } jsonBytes, err := json.Marshal(Usr) diff --git a/api/send.go b/api/send.go index 9f14e2b7a7092dea74e491da62eb2689371214a5..5959d81946ada40f94d56f40b06f0ead130ae3d5 100644 --- a/api/send.go +++ b/api/send.go @@ -16,7 +16,6 @@ import ( "gitlab.com/elixxir/client/cmix" "gitlab.com/elixxir/client/cmix/message" "gitlab.com/elixxir/client/e2e" - "gitlab.com/elixxir/client/interfaces/params" e2eCrypto "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" @@ -64,16 +63,16 @@ func (c *Client) SendCMIX(msg format.Message, recipientID *id.ID, // SendManyCMIX sends many "raw" CMIX message payloads to each of the // provided recipients. Used for group chat functionality. Returns the // round ID of the round the payload was sent or an error if it fails. -func (c *Client) SendManyCMIX(messages []message.TargetedCmixMessage, - params params.CMIX) (id.Round, []ephemeral.Id, error) { - return c.network.SendManyCMIX(messages, params) +func (c *Client) SendManyCMIX(messages []cmix.TargetedCmixMessage, + params cmix.CMIXParams) (id.Round, []ephemeral.Id, error) { + return c.network.SendMany(messages, params) } // NewCMIXMessage Creates a new cMix message with the right properties // for the current cMix network. // FIXME: this is weird and shouldn't be necessary, but it is. func (c *Client) NewCMIXMessage(contents []byte) (format.Message, error) { - primeSize := len(c.storage.Cmix().GetGroup().GetPBytes()) + primeSize := len(c.storage.GetCmixGroup().GetPBytes()) msg := format.NewMessage(primeSize) if len(contents) > msg.ContentsSize() { return format.Message{}, errors.New("Contents to long for cmix") diff --git a/auth/interface.go b/auth/interface.go index 8ccd87c92b0072b6bdda2d777eb69a8dad219e3d..b8ea8865c78f89ba7ffacce3476e46aeb3ff0f7f 100644 --- a/auth/interface.go +++ b/auth/interface.go @@ -1,6 +1,7 @@ package auth import ( + "gitlab.com/elixxir/client/e2e" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/primitives/id" @@ -75,4 +76,11 @@ type State interface { // DeleteReceiveRequests clears all received requests from client's auth // storage. DeleteReceiveRequests() error + + // GetReceivedRequest returns a contact if there's a received + // request for it. + GetReceivedRequest(partner *id.ID) (contact.Contact, error) + + // VerifyOwnership checks if the received ownership proof is valid + VerifyOwnership(received, verified contact.Contact, e2e e2e.Handler) bool }