Skip to content
Snippets Groups Projects
Commit 62e6f99f authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'XX-4076/UnexpectedEndOfJson' into 'release'

Frond End Assistance And Iterative Clean Up

See merge request !333
parents a842fef5 d28f3af4
No related branches found
No related tags found
2 merge requests!510Release,!333Frond End Assistance And Iterative Clean Up
...@@ -145,19 +145,26 @@ func (e *E2e) GetUdCertFromNdf() []byte { ...@@ -145,19 +145,26 @@ func (e *E2e) GetUdCertFromNdf() []byte {
// Returns // Returns
// - []byte - A byte marshalled contact.Contact. // - []byte - A byte marshalled contact.Contact.
func (e *E2e) GetUdContactFromNdf() ([]byte, error) { func (e *E2e) GetUdContactFromNdf() ([]byte, error) {
udIdData := e.api.GetCmix().GetInstance().GetPartialNdf().Get().UDB.ID // Retrieve data from E2e
netDef := e.api.GetCmix().GetInstance().GetPartialNdf().Get()
e2eGroup := e.api.GetE2E().GetGroup()
// Unmarshal UD ID
udIdData := netDef.UDB.ID
udId, err := id.Unmarshal(udIdData) udId, err := id.Unmarshal(udIdData)
if err != nil { if err != nil {
return nil, err return nil, err
} }
udDhPubKeyData := e.api.GetCmix().GetInstance().GetPartialNdf().Get().UDB.DhPubKey // Unmarshal DH pub key
udDhPubKey := e.api.GetE2E().GetGroup().NewInt(1) udDhPubKeyData := netDef.UDB.DhPubKey
udDhPubKey := e2eGroup.NewInt(1)
err = udDhPubKey.UnmarshalJSON(udDhPubKeyData) err = udDhPubKey.UnmarshalJSON(udDhPubKeyData)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Construct contact
udContact := contact.Contact{ udContact := contact.Contact{
ID: udId, ID: udId,
DhPubKey: udDhPubKey, DhPubKey: udDhPubKey,
......
...@@ -26,12 +26,14 @@ import ( ...@@ -26,12 +26,14 @@ import (
// "RSAPrivatePem":"LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcFFJQkFBS0NBUUVBNU15dTdhYjBJOS9UL1BFUUxtd2x3ejZHV3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3NjA3MTNhYjQ0YTYzMzdjMjBlNzg2MTU3NWU3NDVkMzFmOGI5ZTlhZDg0MTIxMThjNjJhM2UyZTI5ZGY0NmIwODY0ZDBjOTUxYzM5NGE1Y2JiZGM2YWRjNzE4ZGQyYTNlMDQxMDIzZGJiNWFiMjNlYmI0NzQyZGU5YzE2ODdiNWIzNGZhNDhjMzUyMTYzMmM0YTUzMGU4ZmZiMWJjNTFkYWRkZjQ1M2IwYjI3MTdjMmJjNjY2OWVkNzZiNGJkZDVjOWZmNTU4ZTg4ZjI2ZTU3ODUzMDJiZWRiY2EyM2VhYzVhY2U5MjA5NmVlOGE2MDY0MmZiNjFlOGYzZDI0OTkwYjhjYjEyZWU0NDhlZWY3OGUxODRjNzI0MmRkMTYxYzc3MzhmMzJiZjI5YTg0MTY5ODk3ODgyNWI0MTExYjRiYzNlMWUxOTg0NTUwOTU5NTgzMzNkNzc2ZDhiMmJlZWVkM2ExYTFhMjIxYTZlMzdlNjY0YTY0YjgzOTgxYzQ2ZmZkZGMxYTQ1ZTNkNTIxMWFhZjhiZmJjMDcyNzY4YzRmNTBkN2Q3ODAzZDJkNGYyNzhkZTgwMTRhNDczMjM2MzFkN2UwNjRkZTgxYzBjNmJmYTQzZWYwZTY5OTg4NjBmMTM5MGI1ZDNmZWFjYWYxNjk2MDE1Y2I3OWMzZjljMmQ5M2Q5NjExMjBjZDBlNWYxMmNiYjY4N2VhYjA0NTI0MWY5Njc4OWMzOGU4OWQ3OTYxMzhlNjMxOWJlNjJlMzVkODdiMTA0OGNhMjhiZTM4OWI1NzVlOTk0ZGNhNzU1NDcxNTg0YTA5ZWM3MjM3NDJkYzM1ODczODQ3YWVmNDlmNjZlNDM4NzMifQ=="
// } // }
type ReceptionIdentity struct { type ReceptionIdentity struct {
ID []byte // User ID (base64) ID []byte // User ID (base64)
RSAPrivatePem []byte // RSA Private key (PEM format) RSAPrivatePem []byte // RSA Private key (PEM format)
Salt []byte // Salt for identity (base64) Salt []byte // Salt for identity (base64)
DHKeyPrivate []byte // DH Private key DHKeyPrivate []byte // DH Private key
E2eGrp []byte
} }
// StoreReceptionIdentity stores the given identity in Cmix storage with the // StoreReceptionIdentity stores the given identity in Cmix storage with the
...@@ -77,7 +79,8 @@ func (c *Cmix) MakeReceptionIdentity() ([]byte, error) { ...@@ -77,7 +79,8 @@ func (c *Cmix) MakeReceptionIdentity() ([]byte, error) {
} }
// MakeLegacyReceptionIdentity generates the legacy identity for receiving // MakeLegacyReceptionIdentity generates the legacy identity for receiving
// messages. // messages. As with all legacy calls, this should primarily be used
// for the xx messenger team.
func (c *Cmix) MakeLegacyReceptionIdentity() ([]byte, error) { func (c *Cmix) MakeLegacyReceptionIdentity() ([]byte, error) {
ident, err := xxdk.MakeLegacyReceptionIdentity(c.api) ident, err := xxdk.MakeLegacyReceptionIdentity(c.api)
if err != nil { if err != nil {
...@@ -90,7 +93,8 @@ func (c *Cmix) MakeLegacyReceptionIdentity() ([]byte, error) { ...@@ -90,7 +93,8 @@ func (c *Cmix) MakeLegacyReceptionIdentity() ([]byte, error) {
// GetReceptionRegistrationValidationSignature returns the signature provided by // GetReceptionRegistrationValidationSignature returns the signature provided by
// the xx network. // the xx network.
func (c *Cmix) GetReceptionRegistrationValidationSignature() []byte { func (c *Cmix) GetReceptionRegistrationValidationSignature() []byte {
return c.api.GetStorage().GetReceptionRegistrationValidationSignature() regSig := c.api.GetStorage().GetReceptionRegistrationValidationSignature()
return regSig
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -29,13 +29,16 @@ func TestIdentity_JSON(t *testing.T) { ...@@ -29,13 +29,16 @@ func TestIdentity_JSON(t *testing.T) {
dhpk := dh.GeneratePrivateKey(64, grp, rng) dhpk := dh.GeneratePrivateKey(64, grp, rng)
dhpkJson, _ := dhpk.MarshalJSON() dhpkJson, _ := dhpk.MarshalJSON()
op := make([]byte, 64) op := make([]byte, 64)
e2eGrp, _ := getGroup().MarshalJSON()
_, _ = rng.Read(op) _, _ = rng.Read(op)
identity := ReceptionIdentity{ identity := ReceptionIdentity{
ID: uid.Marshal(), ID: uid.Marshal(),
RSAPrivatePem: rsa.CreatePrivateKeyPem(pk), RSAPrivatePem: rsa.CreatePrivateKeyPem(pk),
Salt: salt, Salt: salt,
DHKeyPrivate: dhpkJson, DHKeyPrivate: dhpkJson,
E2eGrp: e2eGrp,
} }
im, _ := json.Marshal(identity) im, _ := json.Marshal(identity)
t.Log("Marshalled ReceptionIdentity object") t.Log("Marshalled ReceptionIdentity object")
t.Log(string(im)) t.Log(string(im))
......
...@@ -105,31 +105,72 @@ type UdNetworkStatus interface { ...@@ -105,31 +105,72 @@ type UdNetworkStatus interface {
// Manager functions // // Manager functions //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NewOrLoadUd loads an existing Manager from storage or creates a new one if // IsRegisteredWithUD is a function which checks the internal state
// there is no extant storage information. Parameters need be provided to // files to determine if a user has registered with UD in the past.
// specify how to connect to the User Discovery service. These parameters may be //
// used to contact either the UD server hosted by the xx network team or a // Parameters:
// custom third-party operated server. For the former, all the information may // - e2eID - REQUIRED. The tracked e2e object ID. This can be retrieved using [E2e.GetID].
// be pulled from the NDF using the bindings. //
// Returns:
// - bool - A boolean representing true if the user has been registered with UD already
// or false if it has not been registered already.
// - error - An error should only be returned if the internal tracker failed to retrieve an
// E2e object given the e2eId. If an error was returned, the registration state check
// was not performed properly, and the boolean returned should be ignored.
func IsRegisteredWithUD(e2eId int) (bool, error) {
// Get user from singleton
user, err := e2eTrackerSingleton.get(e2eId)
if err != nil {
return false, err
}
return ud.IsRegistered(user.api.GetStorage().GetKV()), nil
}
// NewOrLoadUd loads an existing UserDiscovery from storage or creates a new
// UserDiscovery if there is no storage data. Regardless of storage state,
// the UserDiscovery object returned will be registered with the
// User Discovery service. If the user is not already registered, a call
// to register will occur internally. If the user is already registered,
// this call will simply load state and return to you a UserDiscovery object.
// Some parameters are required for registering with the service, but are not required
// if the user is already registered. These will be noted in the parameters section as
// "SEMI-REQUIRED".
//
// Certain parameters are required every call to this function. These parameters are listed below
// as "REQUIRED". For example, parameters need be provided to specify how to connect to the
// User Discovery service. These parameters specifically may be used to contact either the UD
// server hosted by the xx network team or a custom third-party operated server. For the former,
// all the information may be fetched from the NDF using the bindings. These fetch
// methods are detailed in the parameters section.
// //
// Params // Params
// - e2eID - e2e object ID in the tracker // - e2eID - REQUIRED. The tracked e2e object ID. This is returned by [E2e.GetID].
// - follower - network follower func wrapped in UdNetworkStatus // - follower - REQUIRED. Network follower function. This will check if the network
// - username - the username the user wants to register with UD. If the user is // follower is running.
// already registered, this field may be blank // - username - SEMI-REQUIRED. The username the user wants to register with UD.
// - registrationValidationSignature - a signature provided by the network // If the user is already registered, this field may be blank. If the user is not
// (i.e., the client registrar). This may be nil; however, UD may return an // already registered, these field must be populated with a username that meets the
// error in some cases (e.g., in a production level environment). // requirements of the UD service. For example, in the xx network's UD service,
// - cert - the TLS certificate for the UD server this call will connect with. // the username must not be registered by another user.
// You may use the UD server run by the xx network team by using // - registrationValidationSignature - SEMI-REQUIRED. A signature provided by the xx network
// E2e.GetUdCertFromNdf. // (i.e. the client registrar). If the user is not already registered, this field is required
// - contactFile - the data within a marshalled contact.Contact. This // in order to register with the xx network. This may be nil if the user is already registered
// represents the contact file of the server this call will connect with. You // or connecting to a third-party UD service unassociated with the xx network.
// may use the UD server run by the xx network team by using // - cert - REQUIRED. The TLS certificate for the UD server this call will connect with.
// E2e.GetUdContactFromNdf. // If this is nil, you may not contact the UD server hosted by the xx network.
// - address - the IP address of the UD server this call will connect with. You // Third-party services may vary.
// may use the UD server run by the xx network team by using // You may use the UD server run by the xx network team by using [E2e.GetUdCertFromNdf].
// E2e.GetUdAddressFromNdf. // - contactFile - REQUIRED. The data within a marshalled [contact.Contact]. This represents the
// contact file of the server this call will connect with.
// If this is nil, you may not contact the UD server hosted by the xx network.
// Third-party services may vary.
// You may use the UD server run by the xx network team by using [E2e.GetUdContactFromNdf].
// - address - REQUIRED. The IP address of the UD server this call will connect with.
// You may use the UD server run by the xx network team by using [E2e.GetUdAddressFromNdf].
// If this is nil, you may not contact the UD server hosted by the xx network.
// Third-party services may vary.
// //
// Returns // Returns
// - A Manager object which is registered to the specified UD service. // - A Manager object which is registered to the specified UD service.
......
...@@ -67,7 +67,7 @@ func ConnectWithAuthentication(recipient contact.Contact, user *xxdk.E2e, ...@@ -67,7 +67,7 @@ func ConnectWithAuthentication(recipient contact.Contact, user *xxdk.E2e,
// Build the authenticated connection and return // Build the authenticated connection and return
identity := user.GetReceptionIdentity() identity := user.GetReceptionIdentity()
privKey, err := identity.GetRSAPrivatePem() privKey, err := identity.GetRSAPrivateKey()
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -62,14 +62,6 @@ func register(comms registrationMessageSender, host *connect.Host, ...@@ -62,14 +62,6 @@ func register(comms registrationMessageSender, host *connect.Host,
"reception confirmation message") "reception confirmation message")
} }
transmissionConfirmation := &pb.ClientRegistrationConfirmation{}
err = proto.Unmarshal(response.GetClientReceptionConfirmation().
ClientRegistrationConfirmation, transmissionConfirmation)
if err != nil {
return nil, nil, 0, errors.WithMessage(err, "Failed to unmarshal "+
"transmission confirmation message")
}
// Verify reception signature // Verify reception signature
receptionSignature := response.GetClientReceptionConfirmation(). receptionSignature := response.GetClientReceptionConfirmation().
GetRegistrarSignature().Signature GetRegistrarSignature().Signature
...@@ -80,6 +72,15 @@ func register(comms registrationMessageSender, host *connect.Host, ...@@ -80,6 +72,15 @@ func register(comms registrationMessageSender, host *connect.Host,
return nil, nil, 0, errors.WithMessage(err, "Failed to verify reception signature") return nil, nil, 0, errors.WithMessage(err, "Failed to verify reception signature")
} }
// Unmarshal transmission confirmation
transmissionConfirmation := &pb.ClientRegistrationConfirmation{}
err = proto.Unmarshal(response.GetClientTransmissionConfirmation().
ClientRegistrationConfirmation, transmissionConfirmation)
if err != nil {
return nil, nil, 0, errors.WithMessage(err, "Failed to unmarshal "+
"transmission confirmation message")
}
// Verify transmission signature // Verify transmission signature
transmissionSignature := response.GetClientTransmissionConfirmation(). transmissionSignature := response.GetClientTransmissionConfirmation().
GetRegistrarSignature().Signature GetRegistrarSignature().Signature
......
...@@ -40,7 +40,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID, ...@@ -40,7 +40,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID,
fHash := factID.Fingerprint(f) fHash := factID.Fingerprint(f)
// Sign our inFact for putting into the request // Sign our inFact for putting into the request
privKey, err := m.user.GetReceptionIdentity().GetRSAPrivatePem() privKey, err := m.user.GetReceptionIdentity().GetRSAPrivateKey()
if err != nil { if err != nil {
return "", err return "", err
} }
......
...@@ -90,7 +90,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus, ...@@ -90,7 +90,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus,
} }
// If already registered, return // If already registered, return
if m.isRegistered() { if IsRegistered(m.getKv()) {
return m, nil return m, nil
} }
...@@ -223,7 +223,7 @@ func (m *Manager) getCmix() udCmix { ...@@ -223,7 +223,7 @@ func (m *Manager) getCmix() udCmix {
return m.user.GetCmix() return m.user.GetCmix()
} }
// getKv returns a versioned.KV used for isRegistered and setRegistered. // getKv returns a versioned.KV used for IsRegistered and setRegistered.
// This is separated from store operations as store's kv // This is separated from store operations as store's kv
// has a different prefix which breaks backwards compatibility. // has a different prefix which breaks backwards compatibility.
func (m *Manager) getKv() *versioned.KV { func (m *Manager) getKv() *versioned.KV {
......
...@@ -19,7 +19,7 @@ func (m *Manager) register(username string, networkSignature []byte, ...@@ -19,7 +19,7 @@ func (m *Manager) register(username string, networkSignature []byte,
// Retrieve data used for registration // Retrieve data used for registration
identity := m.user.GetReceptionIdentity() identity := m.user.GetReceptionIdentity()
privKey, err := identity.GetRSAPrivatePem() privKey, err := identity.GetRSAPrivateKey()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -11,10 +11,10 @@ import ( ...@@ -11,10 +11,10 @@ import (
const isRegisteredKey = "isRegisteredKey" const isRegisteredKey = "isRegisteredKey"
const isRegisteredVersion = 0 const isRegisteredVersion = 0
// isRegistered loads from storage if the user is registered with user // IsRegistered loads from storage if the user is registered with user
// discovery. // discovery.
func (m *Manager) isRegistered() bool { func IsRegistered(kv *versioned.KV) bool {
_, err := m.getKv().Get(isRegisteredKey, isRegisteredVersion) _, err := kv.Get(isRegisteredKey, isRegisteredVersion)
if err != nil { if err != nil {
return false return false
} }
......
...@@ -40,7 +40,7 @@ func (m *Manager) removeFact(f fact.Fact, ...@@ -40,7 +40,7 @@ func (m *Manager) removeFact(f fact.Fact,
// Sign our inFact for putting into the request // Sign our inFact for putting into the request
identity := m.user.GetReceptionIdentity() identity := m.user.GetReceptionIdentity()
privKey, err := identity.GetRSAPrivatePem() privKey, err := identity.GetRSAPrivateKey()
if err != nil { if err != nil {
return err return err
} }
...@@ -78,7 +78,7 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error { ...@@ -78,7 +78,7 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error {
"a username. Cannot remove fact %q", f.Fact)) "a username. Cannot remove fact %q", f.Fact))
} }
identity := m.user.GetReceptionIdentity() identity := m.user.GetReceptionIdentity()
privKey, err := identity.GetRSAPrivatePem() privKey, err := identity.GetRSAPrivateKey()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"time" "time"
) )
...@@ -23,35 +22,26 @@ func (m *Manager) setUserDiscovery(cert, ...@@ -23,35 +22,26 @@ func (m *Manager) setUserDiscovery(cert,
params.AuthEnabled = false params.AuthEnabled = false
params.SendTimeout = 20 * time.Second params.SendTimeout = 20 * time.Second
udIdBytes, dhPubKeyBytes, err := contact.ReadContactFromFile(contactFile) // Unmarshal the new contact
if err != nil { con, err := contact.Unmarshal(contactFile)
return err
}
udID, err := id.Unmarshal(udIdBytes)
if err != nil { if err != nil {
return err return err
} }
// Add a new host and return it if it does not already exist // Add a new host and return it if it does not already exist
host, err := m.comms.AddHost(udID, address, host, err := m.comms.AddHost(con.ID, address,
cert, params) cert, params)
if err != nil { if err != nil {
return errors.WithMessage(err, "User Discovery host object could "+ return errors.WithMessage(err, "User Discovery host object could "+
"not be constructed.") "not be constructed.")
} }
dhPubKey := m.user.GetE2E().GetGroup().NewInt(1) // Set the user discovery object within the manager
err = dhPubKey.UnmarshalJSON(dhPubKeyBytes)
if err != nil {
return err
}
m.ud = &userDiscovery{ m.ud = &userDiscovery{
host: host, host: host,
contact: contact.Contact{ contact: contact.Contact{
ID: udID, ID: con.ID,
DhPubKey: dhPubKey, DhPubKey: con.DhPubKey,
}, },
} }
......
...@@ -102,7 +102,7 @@ func loginLegacy(net *Cmix, callbacks AuthCallbacks, ...@@ -102,7 +102,7 @@ func loginLegacy(net *Cmix, callbacks AuthCallbacks,
return nil, err return nil, err
} }
rsaKey, err := identity.GetRSAPrivatePem() rsaKey, err := identity.GetRSAPrivateKey()
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -116,7 +116,7 @@ func login(net *Cmix, callbacks AuthCallbacks, identity ReceptionIdentity, ...@@ -116,7 +116,7 @@ func login(net *Cmix, callbacks AuthCallbacks, identity ReceptionIdentity,
kv *versioned.KV, params E2EParams) (m *E2e, err error) { kv *versioned.KV, params E2EParams) (m *E2e, err error) {
// Verify the passed-in ReceptionIdentity matches its properties // Verify the passed-in ReceptionIdentity matches its properties
privatePem, err := identity.GetRSAPrivatePem() privatePem, err := identity.GetRSAPrivateKey()
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -246,7 +246,7 @@ func (m *E2e) ConstructProtoUserFile() ([]byte, error) { ...@@ -246,7 +246,7 @@ func (m *E2e) ConstructProtoUserFile() ([]byte, error) {
transIdentity := m.Cmix.GetTransmissionIdentity() transIdentity := m.Cmix.GetTransmissionIdentity()
receptionIdentity := m.GetReceptionIdentity() receptionIdentity := m.GetReceptionIdentity()
privatePem, err := receptionIdentity.GetRSAPrivatePem() privatePem, err := receptionIdentity.GetRSAPrivateKey()
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -80,8 +80,8 @@ func (r ReceptionIdentity) GetDHKeyPrivate() (*cyclic.Int, error) { ...@@ -80,8 +80,8 @@ func (r ReceptionIdentity) GetDHKeyPrivate() (*cyclic.Int, error) {
return dhKeyPriv, err return dhKeyPriv, err
} }
// GetRSAPrivatePem returns the RSAPrivatePem. // GetRSAPrivateKey returns the RSAPrivatePem.
func (r ReceptionIdentity) GetRSAPrivatePem() (*rsa.PrivateKey, error) { func (r ReceptionIdentity) GetRSAPrivateKey() (*rsa.PrivateKey, error) {
return rsa.LoadPrivateKeyFromPem(r.RSAPrivatePem) return rsa.LoadPrivateKeyFromPem(r.RSAPrivatePem)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment