Skip to content
Snippets Groups Projects
Commit 6ed4c1fa authored by Jake Taylor's avatar Jake Taylor
Browse files

added GetContact to bindings/E2e object

parent 0241a9e3
No related branches found
No related tags found
1 merge request!510Release
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
) )
// ReceptionIdentity struct // ReceptionIdentity struct
...@@ -47,57 +46,6 @@ func (c *Cmix) MakeIdentity() ([]byte, error) { ...@@ -47,57 +46,6 @@ func (c *Cmix) MakeIdentity() ([]byte, error) {
return json.Marshal(&I) return json.Marshal(&I)
} }
// GetContactFromIdentity accepts a marshalled ReceptionIdentity object and returns a marshalled contact.Contact object
func (c *Cmix) GetContactFromIdentity(identity []byte) ([]byte, error) {
unmarshalledIdentity, err := c.unmarshalIdentity(identity)
if err != nil {
return nil, err
}
grp := c.api.GetStorage().GetE2EGroup()
dhPub := grp.ExpG(unmarshalledIdentity.DHKeyPrivate, grp.NewInt(1))
ct := contact.Contact{
ID: unmarshalledIdentity.ID,
DhPubKey: dhPub,
OwnershipProof: nil,
Facts: nil,
}
return ct.Marshal(), nil
}
func (c *Cmix) unmarshalIdentity(marshaled []byte) (xxdk.ReceptionIdentity, error) {
newIdentity := xxdk.ReceptionIdentity{}
// Unmarshal given identity into ReceptionIdentity object
givenIdentity := ReceptionIdentity{}
err := json.Unmarshal(marshaled, &givenIdentity)
if err != nil {
return xxdk.ReceptionIdentity{}, err
}
newIdentity.ID, err = id.Unmarshal(givenIdentity.ID)
if err != nil {
return xxdk.ReceptionIdentity{}, err
}
newIdentity.DHKeyPrivate = c.api.GetStorage().GetE2EGroup().NewInt(1)
err = newIdentity.DHKeyPrivate.UnmarshalJSON(givenIdentity.DHKeyPrivate)
if err != nil {
return xxdk.ReceptionIdentity{}, err
}
newIdentity.RSAPrivatePem, err = rsa.LoadPrivateKeyFromPem(givenIdentity.RSAPrivatePem)
if err != nil {
return xxdk.ReceptionIdentity{}, err
}
newIdentity.Salt = givenIdentity.Salt
return newIdentity, nil
}
// GetIDFromContact accepts a marshalled contact.Contact object & returns a marshalled id.ID object // GetIDFromContact accepts a marshalled contact.Contact object & returns a marshalled id.ID object
func GetIDFromContact(marshaled []byte) ([]byte, error) { func GetIDFromContact(marshaled []byte) ([]byte, error) {
cnt, err := contact.Unmarshal(marshaled) cnt, err := contact.Unmarshal(marshaled)
......
...@@ -7,11 +7,14 @@ ...@@ -7,11 +7,14 @@
package bindings package bindings
import ( import (
"encoding/json"
"gitlab.com/elixxir/client/auth" "gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
) )
// e2eTrackerSingleton is used to track E2e objects so that // e2eTrackerSingleton is used to track E2e objects so that
...@@ -37,7 +40,7 @@ func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, ...@@ -37,7 +40,7 @@ func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e,
return nil, err return nil, err
} }
newIdentity, err := cmix.unmarshalIdentity(identity) newIdentity, err := e.unmarshalIdentity(identity)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -56,6 +59,46 @@ func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, ...@@ -56,6 +59,46 @@ func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e,
return e2eTrackerSingleton.make(newE2e), nil return e2eTrackerSingleton.make(newE2e), nil
} }
// GetContactFromIdentity accepts a marshalled ReceptionIdentity object and returns a marshalled contact.Contact object
func (e *E2e) GetContactFromIdentity(identity []byte) ([]byte, error) {
unmarshalledIdentity, err := e.unmarshalIdentity(identity)
if err != nil {
return nil, err
}
return unmarshalledIdentity.GetContact(e.api.GetStorage().GetE2EGroup()).Marshal(), nil
}
// unmarshalIdentity is a helper function for taking in a marshalled xxdk.ReceptionIdentity and making it an object
func (e *E2e) unmarshalIdentity(marshaled []byte) (xxdk.ReceptionIdentity, error) {
newIdentity := xxdk.ReceptionIdentity{}
// Unmarshal given identity into ReceptionIdentity object
givenIdentity := ReceptionIdentity{}
err := json.Unmarshal(marshaled, &givenIdentity)
if err != nil {
return xxdk.ReceptionIdentity{}, err
}
newIdentity.ID, err = id.Unmarshal(givenIdentity.ID)
if err != nil {
return xxdk.ReceptionIdentity{}, err
}
newIdentity.DHKeyPrivate = e.api.GetStorage().GetE2EGroup().NewInt(1)
err = newIdentity.DHKeyPrivate.UnmarshalJSON(givenIdentity.DHKeyPrivate)
if err != nil {
return xxdk.ReceptionIdentity{}, err
}
newIdentity.RSAPrivatePem, err = rsa.LoadPrivateKeyFromPem(givenIdentity.RSAPrivatePem)
if err != nil {
return xxdk.ReceptionIdentity{}, err
}
newIdentity.Salt = givenIdentity.Salt
return newIdentity, nil
}
// AuthCallbacks is the bindings-specific interface for auth.Callbacks methods. // AuthCallbacks is the bindings-specific interface for auth.Callbacks methods.
type AuthCallbacks interface { type AuthCallbacks interface {
Request(contact, receptionId []byte, ephemeralId, roundId int64) Request(contact, receptionId []byte, ephemeralId, roundId int64)
......
...@@ -66,7 +66,7 @@ func ConnectWithAuthentication(recipient contact.Contact, e2eClient *xxdk.E2e, ...@@ -66,7 +66,7 @@ func ConnectWithAuthentication(recipient contact.Contact, e2eClient *xxdk.E2e,
} }
// Build the authenticated connection and return // Build the authenticated connection and return
identity := e2eClient.GetTransmissionIdentity() identity := e2eClient.GetReceptionIdentity()
return connectWithAuthentication(conn, timeStart, recipient, identity.Salt, identity.RSAPrivatePem, return connectWithAuthentication(conn, timeStart, recipient, identity.Salt, identity.RSAPrivatePem,
e2eClient.GetRng(), e2eClient.GetCmix(), p) e2eClient.GetRng(), e2eClient.GetCmix(), p)
} }
......
...@@ -209,8 +209,8 @@ func (m *E2e) GetUser() user.Info { ...@@ -209,8 +209,8 @@ func (m *E2e) GetUser() user.Info {
return u return u
} }
// GetTransmissionIdentity returns a safe copy of the E2e ReceptionIdentity // GetReceptionIdentity returns a safe copy of the E2e ReceptionIdentity
func (m *E2e) GetTransmissionIdentity() ReceptionIdentity { func (m *E2e) GetReceptionIdentity() ReceptionIdentity {
return m.e2eIdentity.DeepCopy() return m.e2eIdentity.DeepCopy()
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package xxdk package xxdk
import ( import (
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/csprng"
...@@ -59,13 +60,26 @@ func MakeReceptionIdentity(rng csprng.Source, grp *cyclic.Group) (ReceptionIdent ...@@ -59,13 +60,26 @@ func MakeReceptionIdentity(rng csprng.Source, grp *cyclic.Group) (ReceptionIdent
} }
// DeepCopy produces a safe copy of a ReceptionIdentity // DeepCopy produces a safe copy of a ReceptionIdentity
func (t ReceptionIdentity) DeepCopy() ReceptionIdentity { func (r ReceptionIdentity) DeepCopy() ReceptionIdentity {
saltCopy := make([]byte, len(t.Salt)) saltCopy := make([]byte, len(r.Salt))
copy(saltCopy, t.Salt) copy(saltCopy, r.Salt)
return ReceptionIdentity{ return ReceptionIdentity{
ID: t.ID.DeepCopy(), ID: r.ID.DeepCopy(),
RSAPrivatePem: t.RSAPrivatePem, RSAPrivatePem: r.RSAPrivatePem,
Salt: saltCopy, Salt: saltCopy,
DHKeyPrivate: t.DHKeyPrivate.DeepCopy(), DHKeyPrivate: r.DHKeyPrivate.DeepCopy(),
} }
} }
// GetContact accepts a xxdk.ReceptionIdentity object and returns a contact.Contact object
func (r ReceptionIdentity) GetContact(grp *cyclic.Group) contact.Contact {
dhPub := grp.ExpG(r.DHKeyPrivate, grp.NewInt(1))
ct := contact.Contact{
ID: r.ID,
DhPubKey: dhPub,
OwnershipProof: nil,
Facts: nil,
}
return ct
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment