Skip to content
Snippets Groups Projects
Commit 63fcc21a authored by Josh Brooks's avatar Josh Brooks
Browse files

Merge branch 'xx-3003/update-id-creation' of gitlab.com:elixxir/client into...

Merge branch 'xx-3003/update-id-creation' of gitlab.com:elixxir/client into XX-3063/PersonalEphemeralTracking
parents ee6642a8 5fe98354
No related branches found
No related tags found
No related merge requests found
Showing with 274 additions and 74 deletions
...@@ -114,7 +114,7 @@ func (c *Client) MakePrecannedContact(precannedID uint) contact.Contact { ...@@ -114,7 +114,7 @@ func (c *Client) MakePrecannedContact(precannedID uint) contact.Contact {
partnerPubKey := e2eGrp.ExpG(precanned.E2eDhPrivateKey, e2eGrp.NewInt(1)) partnerPubKey := e2eGrp.ExpG(precanned.E2eDhPrivateKey, e2eGrp.NewInt(1))
return contact.Contact{ return contact.Contact{
ID: precanned.ID, ID: precanned.ReceptionID,
DhPubKey: partnerPubKey, DhPubKey: partnerPubKey,
OwnershipProof: nil, OwnershipProof: nil,
Facts: make([]fact.Fact, 0), Facts: make([]fact.Fact, 0),
......
...@@ -194,10 +194,10 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie ...@@ -194,10 +194,10 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie
cryptoUser := u.GetCryptographicIdentity() cryptoUser := u.GetCryptographicIdentity()
//start comms //start comms
c.comms, err = client.NewClientComms(cryptoUser.GetUserID(), c.comms, err = client.NewClientComms(cryptoUser.GetTransmissionID(),
rsa.CreatePublicKeyPem(cryptoUser.GetRSA().GetPublic()), rsa.CreatePublicKeyPem(cryptoUser.GetTransmissionRSA().GetPublic()),
rsa.CreatePrivateKeyPem(cryptoUser.GetRSA()), rsa.CreatePrivateKeyPem(cryptoUser.GetTransmissionRSA()),
cryptoUser.GetSalt()) cryptoUser.GetTransmissionSalt())
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "failed to load client") return nil, errors.WithMessage(err, "failed to load client")
} }
...@@ -346,7 +346,7 @@ func (c *Client) GetHealth() interfaces.HealthTracker { ...@@ -346,7 +346,7 @@ func (c *Client) GetHealth() interfaces.HealthTracker {
return c.network.GetHealthTracker() return c.network.GetHealthTracker()
} }
// Returns the switchboard for Registration // Returns the switchboard for Identity
func (c *Client) GetSwitchboard() interfaces.Switchboard { func (c *Client) GetSwitchboard() interfaces.Switchboard {
jww.INFO.Printf("GetSwitchboard()") jww.INFO.Printf("GetSwitchboard()")
return c.switchboard return c.switchboard
......
...@@ -16,7 +16,8 @@ import ( ...@@ -16,7 +16,8 @@ import (
func (c *Client) registerWithPermissioning() error { func (c *Client) registerWithPermissioning() error {
userData := c.storage.User() userData := c.storage.User()
//get the users public key //get the users public key
pubKey := userData.GetCryptographicIdentity().GetRSA().GetPublic() transmissionPubKey := userData.GetCryptographicIdentity().GetTransmissionRSA().GetPublic()
receptionPubKey := userData.GetCryptographicIdentity().GetReceptionRSA().GetPublic()
//load the registration code //load the registration code
regCode, err := c.storage.GetRegCode() regCode, err := c.storage.GetRegCode()
...@@ -26,14 +27,15 @@ func (c *Client) registerWithPermissioning() error { ...@@ -26,14 +27,15 @@ func (c *Client) registerWithPermissioning() error {
} }
//register with permissioning //register with permissioning
regValidationSignature, err := c.permissioning.Register(pubKey, regCode) transmissionRegValidationSignature, receptionRegValidationSignature, err := c.permissioning.Register(transmissionPubKey, receptionPubKey, regCode)
if err != nil { if err != nil {
return errors.WithMessage(err, "failed to register with "+ return errors.WithMessage(err, "failed to register with "+
"permissioning") "permissioning")
} }
//store the signature //store the signature
userData.SetRegistrationValidationSignature(regValidationSignature) userData.SetTransmissionRegistrationValidationSignature(transmissionRegValidationSignature)
userData.SetReceptionRegistrationValidationSignature(receptionRegValidationSignature)
//update the registration status //update the registration status
err = c.storage.ForwardRegistrationStatus(storage.PermissioningComplete) err = c.storage.ForwardRegistrationStatus(storage.PermissioningComplete)
......
...@@ -26,12 +26,6 @@ const ( ...@@ -26,12 +26,6 @@ const (
// createNewUser generates an identity for cMix // createNewUser generates an identity for cMix
func createNewUser(rng csprng.Source, cmix, e2e *cyclic.Group) user.User { func createNewUser(rng csprng.Source, cmix, e2e *cyclic.Group) user.User {
// RSA Keygen (4096 bit defaults)
rsaKey, err := rsa.GenerateKey(rng, rsa.DefaultRSABitLen)
if err != nil {
jww.FATAL.Panicf(err.Error())
}
// CMIX Keygen // CMIX Keygen
// FIXME: Why 256 bits? -- this is spec but not explained, it has // FIXME: Why 256 bits? -- this is spec but not explained, it has
// to do with optimizing operations on one side and still preserves // to do with optimizing operations on one side and still preserves
...@@ -50,24 +44,51 @@ func createNewUser(rng csprng.Source, cmix, e2e *cyclic.Group) user.User { ...@@ -50,24 +44,51 @@ func createNewUser(rng csprng.Source, cmix, e2e *cyclic.Group) user.User {
jww.FATAL.Panicf(err.Error()) jww.FATAL.Panicf(err.Error())
} }
// RSA Keygen (4096 bit defaults)
transmissionRsaKey, err := rsa.GenerateKey(rng, rsa.DefaultRSABitLen)
if err != nil {
jww.FATAL.Panicf(err.Error())
}
receptionRsaKey, err := rsa.GenerateKey(rng, rsa.DefaultRSABitLen)
if err != nil {
jww.FATAL.Panicf(err.Error())
}
// Salt, UID, etc gen // Salt, UID, etc gen
salt := make([]byte, SaltSize) transmissionSalt := make([]byte, SaltSize)
n, err := csprng.NewSystemRNG().Read(salt) n, err := csprng.NewSystemRNG().Read(transmissionSalt)
if err != nil {
jww.FATAL.Panicf(err.Error())
}
if n != SaltSize {
jww.FATAL.Panicf("transmissionSalt size too small: %d", n)
}
transmissionID, err := xx.NewID(transmissionRsaKey.GetPublic(), transmissionSalt, id.User)
if err != nil {
jww.FATAL.Panicf(err.Error())
}
// Salt, UID, etc gen
receptionSalt := make([]byte, SaltSize)
n, err = csprng.NewSystemRNG().Read(receptionSalt)
if err != nil { if err != nil {
jww.FATAL.Panicf(err.Error()) jww.FATAL.Panicf(err.Error())
} }
if n != SaltSize { if n != SaltSize {
jww.FATAL.Panicf("salt size too small: %d", n) jww.FATAL.Panicf("receptionSalt size too small: %d", n)
} }
userID, err := xx.NewID(rsaKey.GetPublic(), salt, id.User) receptionID, err := xx.NewID(receptionRsaKey.GetPublic(), receptionSalt, id.User)
if err != nil { if err != nil {
jww.FATAL.Panicf(err.Error()) jww.FATAL.Panicf(err.Error())
} }
return user.User{ return user.User{
ID: userID.DeepCopy(), TransmissionID: transmissionID.DeepCopy(),
Salt: salt, TransmissionSalt: transmissionSalt,
RSA: rsaKey, TransmissionRSA: transmissionRsaKey,
ReceptionID: receptionID.DeepCopy(),
ReceptionSalt: receptionSalt,
ReceptionRSA: receptionRsaKey,
Precanned: false, Precanned: false,
CmixDhPrivateKey: cmix.NewIntFromBytes(cMixKeyBytes), CmixDhPrivateKey: cmix.NewIntFromBytes(cMixKeyBytes),
E2eDhPrivateKey: e2e.NewIntFromBytes(e2eKeyBytes), E2eDhPrivateKey: e2e.NewIntFromBytes(e2eKeyBytes),
...@@ -101,12 +122,15 @@ func createPrecannedUser(precannedID uint, rng csprng.Source, cmix, e2e *cyclic. ...@@ -101,12 +122,15 @@ func createPrecannedUser(precannedID uint, rng csprng.Source, cmix, e2e *cyclic.
} }
return user.User{ return user.User{
ID: userID.DeepCopy(), TransmissionID: &userID,
Salt: salt, TransmissionSalt: salt,
ReceptionID: &userID,
ReceptionSalt: salt,
Precanned: true, Precanned: true,
E2eDhPrivateKey: e2e.NewIntFromBytes(e2eKeyBytes), E2eDhPrivateKey: e2e.NewIntFromBytes(e2eKeyBytes),
// NOTE: These are dummy/not used // NOTE: These are dummy/not used
CmixDhPrivateKey: cmix.NewInt(1), CmixDhPrivateKey: cmix.NewInt(1),
RSA: rsaKey, TransmissionRSA: rsaKey,
ReceptionRSA: rsaKey,
} }
} }
...@@ -47,7 +47,7 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader, ...@@ -47,7 +47,7 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader,
} }
// check that the request is being sent from the proper ID // check that the request is being sent from the proper ID
if !me.ID.Cmp(storage.GetUser().ID) { if !me.ID.Cmp(storage.GetUser().TransmissionID) {
return errors.Errorf("Authenticated channel request " + return errors.Errorf("Authenticated channel request " +
"can only be sent from user's identity") "can only be sent from user's identity")
} }
...@@ -116,7 +116,7 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader, ...@@ -116,7 +116,7 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader,
jww.INFO.Printf("RequestAuth THEIRPUBKEY: %v", partner.DhPubKey.Bytes()) jww.INFO.Printf("RequestAuth THEIRPUBKEY: %v", partner.DhPubKey.Bytes())
/*encrypt payload*/ /*encrypt payload*/
requestFmt.SetID(storage.GetUser().ID) requestFmt.SetID(storage.GetUser().TransmissionID)
requestFmt.SetMsgPayload(msgPayloadBytes) requestFmt.SetMsgPayload(msgPayloadBytes)
ecrFmt.SetOwnership(ownership) ecrFmt.SetOwnership(ownership)
ecrPayload, mac := cAuth.Encrypt(newPrivKey, partner.DhPubKey, ecrPayload, mac := cAuth.Encrypt(newPrivKey, partner.DhPubKey,
......
...@@ -44,7 +44,7 @@ func NewUserDiscovery(client *Client)(*UserDiscovery, error){ ...@@ -44,7 +44,7 @@ func NewUserDiscovery(client *Client)(*UserDiscovery, error){
// network signatures are malformed or if the username is taken. Usernames // network signatures are malformed or if the username is taken. Usernames
// cannot be changed after registration at this time. Will fail if the user is // cannot be changed after registration at this time. Will fail if the user is
// already registered. // already registered.
// Registration does not go over cmix, it occurs over normal communications // Identity does not go over cmix, it occurs over normal communications
func (ud *UserDiscovery)Register(username string)error{ func (ud *UserDiscovery)Register(username string)error{
return ud.ud.Register(username) return ud.ud.Register(username)
} }
......
...@@ -16,20 +16,36 @@ type User struct { ...@@ -16,20 +16,36 @@ type User struct {
u *user.User u *user.User
} }
func (u *User) GetID() []byte { func (u *User) GetTransmissionID() []byte {
return u.u.ID.Marshal() return u.u.TransmissionID.Marshal()
} }
func (u *User) GetSalt() []byte { func (u *User) GetReceptionID() []byte {
return u.u.Salt return u.u.ReceptionID.Marshal()
} }
func (u *User) GetRSAPrivateKeyPem() []byte { func (u *User) GetTransmissionSalt() []byte {
return rsa.CreatePrivateKeyPem(u.u.RSA) return u.u.TransmissionSalt
} }
func (u *User) GetRSAPublicKeyPem() []byte { func (u *User) GetReceptionSalt() []byte {
return rsa.CreatePublicKeyPem(u.u.RSA.GetPublic()) return u.u.ReceptionSalt
}
func (u *User) GetTransmissionRSAPrivateKeyPem() []byte {
return rsa.CreatePrivateKeyPem(u.u.TransmissionRSA)
}
func (u *User) GetTransmissionRSAPublicKeyPem() []byte {
return rsa.CreatePublicKeyPem(u.u.TransmissionRSA.GetPublic())
}
func (u *User) GetReceptionRSAPrivateKeyPem() []byte {
return rsa.CreatePrivateKeyPem(u.u.ReceptionRSA)
}
func (u *User) GetReceptionRSAPublicKeyPem() []byte {
return rsa.CreatePublicKeyPem(u.u.ReceptionRSA.GetPublic())
} }
func (u *User) IsPrecanned() bool { func (u *User) IsPrecanned() bool {
......
...@@ -22,9 +22,9 @@ var initCmd = &cobra.Command{ ...@@ -22,9 +22,9 @@ var initCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
client := createClient() client := createClient()
user := client.GetUser() user := client.GetUser()
jww.INFO.Printf("User: %s", user.ID) jww.INFO.Printf("User: %s", user.TransmissionID)
writeContact(user.GetContact()) writeContact(user.GetContact())
fmt.Printf("%s\n", user.ID) fmt.Printf("%s\n", user.TransmissionID)
}, },
} }
......
...@@ -49,7 +49,7 @@ var rootCmd = &cobra.Command{ ...@@ -49,7 +49,7 @@ var rootCmd = &cobra.Command{
client := initClient() client := initClient()
user := client.GetUser() user := client.GetUser()
jww.INFO.Printf("User: %s", user.ID) jww.INFO.Printf("User: %s", user.TransmissionID)
writeContact(user.GetContact()) writeContact(user.GetContact())
// Set up reception handler // Set up reception handler
...@@ -103,7 +103,7 @@ var rootCmd = &cobra.Command{ ...@@ -103,7 +103,7 @@ var rootCmd = &cobra.Command{
// Set it to myself // Set it to myself
if recipientID == nil { if recipientID == nil {
jww.INFO.Printf("sending message to self") jww.INFO.Printf("sending message to self")
recipientID = user.ID recipientID = user.ReceptionID
recipientContact = user.GetContact() recipientContact = user.GetContact()
} }
...@@ -565,7 +565,7 @@ func init() { ...@@ -565,7 +565,7 @@ func init() {
viper.BindPFlag("log", rootCmd.PersistentFlags().Lookup("log")) viper.BindPFlag("log", rootCmd.PersistentFlags().Lookup("log"))
rootCmd.Flags().StringP("regcode", "", "", rootCmd.Flags().StringP("regcode", "", "",
"Registration code (optional)") "Identity code (optional)")
viper.BindPFlag("regcode", rootCmd.Flags().Lookup("regcode")) viper.BindPFlag("regcode", rootCmd.Flags().Lookup("regcode"))
rootCmd.Flags().StringP("message", "m", "", "Message to send") rootCmd.Flags().StringP("message", "m", "", "Message to send")
......
...@@ -34,7 +34,7 @@ var udCmd = &cobra.Command{ ...@@ -34,7 +34,7 @@ var udCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
client := initClient() client := initClient()
user := client.GetUser() user := client.GetUser()
jww.INFO.Printf("User: %s", user.ID) jww.INFO.Printf("User: %s", user.TransmissionID)
writeContact(user.GetContact()) writeContact(user.GetContact())
// Set up reception handler // Set up reception handler
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
package globals package globals
//Registration //Identity
const REG_KEYGEN = 1 //Generating Cryptographic Keys const REG_KEYGEN = 1 //Generating Cryptographic Keys
const REG_PRECAN = 2 //Doing a Precanned Registration (Not Secure) const REG_PRECAN = 2 //Doing a Precanned Identity (Not Secure)
const REG_UID_GEN = 3 //Generating User ID const REG_UID_GEN = 3 //Generating User ID
const REG_PERM = 4 //Validating User Identity With Permissioning Server const REG_PERM = 4 //Validating User Identity With Permissioning Server
const REG_NODE = 5 //Registering with Nodes const REG_NODE = 5 //Registering with Nodes
......
...@@ -17,9 +17,12 @@ import ( ...@@ -17,9 +17,12 @@ import (
type User struct { type User struct {
//General Identity //General Identity
ID *id.ID TransmissionID *id.ID
Salt []byte TransmissionSalt []byte
RSA *rsa.PrivateKey TransmissionRSA *rsa.PrivateKey
ReceptionID *id.ID
ReceptionSalt []byte
ReceptionRSA *rsa.PrivateKey
Precanned bool Precanned bool
//cmix Identity //cmix Identity
...@@ -33,7 +36,7 @@ type User struct { ...@@ -33,7 +36,7 @@ type User struct {
func (u User) GetContact() contact.Contact { func (u User) GetContact() contact.Contact {
return contact.Contact{ return contact.Contact{
ID: u.ID.DeepCopy(), ID: u.ReceptionID.DeepCopy(),
DhPubKey: u.E2eDhPublicKey, DhPubKey: u.E2eDhPublicKey,
Facts: make([]fact.Fact, 0), Facts: make([]fact.Fact, 0),
} }
......
...@@ -77,7 +77,7 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, ...@@ -77,7 +77,7 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard,
Health: health.Init(instance, params.NetworkHealthTimeout), Health: health.Init(instance, params.NetworkHealthTimeout),
NodeRegistration: make(chan network.NodeGateway, params.RegNodesBufferLen), NodeRegistration: make(chan network.NodeGateway, params.RegNodesBufferLen),
Instance: instance, Instance: instance,
Uid: session.User().GetCryptographicIdentity().GetUserID(), Uid: session.User().GetCryptographicIdentity().GetReceptionID(),
} }
//create sub managers //create sub managers
......
...@@ -142,7 +142,7 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err ...@@ -142,7 +142,7 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err
} }
// Signals to the node registration thread to register a node if keys are // Signals to the node registration thread to register a node if keys are
// missing. Registration is triggered automatically when the node is first seen, // missing. Identity is triggered automatically when the node is first seen,
// so this should on trigger on rare events. // so this should on trigger on rare events.
func handleMissingNodeKeys(instance *network.Instance, func handleMissingNodeKeys(instance *network.Instance,
newNodeChan chan network.NodeGateway, nodes []*id.ID) { newNodeChan chan network.NodeGateway, nodes []*id.ID) {
......
...@@ -52,7 +52,7 @@ func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round, ...@@ -52,7 +52,7 @@ func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round,
msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen()) msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen())
msgCmix.SetContents(p) msgCmix.SetContents(p)
msgCmix.SetRecipientID(msg.Recipient) msgCmix.SetRecipientID(msg.Recipient)
e2e.SetUnencrypted(msgCmix, m.Session.User().GetCryptographicIdentity().GetUserID()) e2e.SetUnencrypted(msgCmix, m.Session.User().GetCryptographicIdentity().GetTransmissionID())
wg.Add(1) wg.Add(1)
go func(i int) { go func(i int) {
var err error var err error
......
...@@ -55,7 +55,7 @@ func StartRegistration(instance *network.Instance, session *storage.Session, rng ...@@ -55,7 +55,7 @@ func StartRegistration(instance *network.Instance, session *storage.Session, rng
func registerNodes(session *storage.Session, rngGen *fastRNG.StreamGenerator, comms RegisterNodeCommsInterface, func registerNodes(session *storage.Session, rngGen *fastRNG.StreamGenerator, comms RegisterNodeCommsInterface,
stop *stoppable.Single, c chan network.NodeGateway) { stop *stoppable.Single, c chan network.NodeGateway) {
u := session.User() u := session.User()
regSignature := u.GetRegistrationValidationSignature() regSignature := u.GetTransmissionRegistrationValidationSignature()
uci := u.GetCryptographicIdentity() uci := u.GetCryptographicIdentity()
cmix := session.Cmix() cmix := session.Cmix()
...@@ -104,7 +104,7 @@ func registerWithNode(comms RegisterNodeCommsInterface, ngw network.NodeGateway, ...@@ -104,7 +104,7 @@ func registerWithNode(comms RegisterNodeCommsInterface, ngw network.NodeGateway,
var transmissionKey *cyclic.Int var transmissionKey *cyclic.Int
// TODO: should move this to a precanned user initialization // TODO: should move this to a precanned user initialization
if uci.IsPrecanned() { if uci.IsPrecanned() {
userNum := int(uci.GetUserID().Bytes()[7]) userNum := int(uci.GetTransmissionID().Bytes()[7])
h := sha256.New() h := sha256.New()
h.Reset() h.Reset()
h.Write([]byte(strconv.Itoa(int(4000 + userNum)))) h.Write([]byte(strconv.Itoa(int(4000 + userNum))))
...@@ -126,8 +126,8 @@ func registerWithNode(comms RegisterNodeCommsInterface, ngw network.NodeGateway, ...@@ -126,8 +126,8 @@ func registerWithNode(comms RegisterNodeCommsInterface, ngw network.NodeGateway,
// Confirm received nonce // Confirm received nonce
jww.INFO.Println("Register: Confirming received nonce") jww.INFO.Println("Register: Confirming received nonce")
err = confirmNonce(comms, uci.GetUserID().Bytes(), err = confirmNonce(comms, uci.GetTransmissionID().Bytes(),
nonce, uci.GetRSA(), gatewayID) nonce, uci.GetTransmissionRSA(), gatewayID)
if err != nil { if err != nil {
errMsg := fmt.Sprintf("Register: Unable to confirm nonce: %v", err) errMsg := fmt.Sprintf("Register: Unable to confirm nonce: %v", err)
return errors.New(errMsg) return errors.New(errMsg)
...@@ -154,7 +154,7 @@ func requestNonce(comms RegisterNodeCommsInterface, gwId *id.ID, regHash []byte, ...@@ -154,7 +154,7 @@ func requestNonce(comms RegisterNodeCommsInterface, gwId *id.ID, regHash []byte,
data := h.Sum(nil) data := h.Sum(nil)
// Sign DH pubkey // Sign DH pubkey
clientSig, err := rsa.Sign(rng, uci.GetRSA(), sha, data, opts) clientSig, err := rsa.Sign(rng, uci.GetTransmissionRSA(), sha, data, opts)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -169,8 +169,8 @@ func requestNonce(comms RegisterNodeCommsInterface, gwId *id.ID, regHash []byte, ...@@ -169,8 +169,8 @@ func requestNonce(comms RegisterNodeCommsInterface, gwId *id.ID, regHash []byte,
} }
nonceResponse, err := comms.SendRequestNonceMessage(host, nonceResponse, err := comms.SendRequestNonceMessage(host,
&pb.NonceRequest{ &pb.NonceRequest{
Salt: uci.GetSalt(), Salt: uci.GetTransmissionSalt(),
ClientRSAPubKey: string(rsa.CreatePublicKeyPem(uci.GetRSA().GetPublic())), ClientRSAPubKey: string(rsa.CreatePublicKeyPem(uci.GetTransmissionRSA().GetPublic())),
ClientSignedByServer: &messages.RSASignature{ ClientSignedByServer: &messages.RSASignature{
Signature: regHash, Signature: regHash,
}, },
......
...@@ -14,8 +14,8 @@ import ( ...@@ -14,8 +14,8 @@ import (
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
) )
func (perm *Permissioning) Register(publicKey *rsa.PublicKey, registrationCode string) ([]byte, error) { func (perm *Permissioning) Register(transmissionPublicKey, receptionPublicKey *rsa.PublicKey, registrationCode string) ([]byte, []byte, error) {
return register(perm.comms, perm.host, publicKey, registrationCode) return register(perm.comms, perm.host, transmissionPublicKey, receptionPublicKey, registrationCode)
} }
// client.Comms should implement this interface // client.Comms should implement this interface
...@@ -26,20 +26,21 @@ type registrationMessageSender interface { ...@@ -26,20 +26,21 @@ type registrationMessageSender interface {
//register registers the user with optional registration code //register registers the user with optional registration code
// Returns an error if registration fails. // Returns an error if registration fails.
func register(comms registrationMessageSender, host *connect.Host, func register(comms registrationMessageSender, host *connect.Host,
publicKey *rsa.PublicKey, registrationCode string) ([]byte, error) { transmissionPublicKey, receptionPublicKey *rsa.PublicKey, registrationCode string) ([]byte, []byte, error) {
response, err := comms. response, err := comms.
SendRegistrationMessage(host, SendRegistrationMessage(host,
&pb.UserRegistration{ &pb.UserRegistration{
RegistrationCode: registrationCode, RegistrationCode: registrationCode,
ClientRSAPubKey: string(rsa.CreatePublicKeyPem(publicKey)), ClientRSAPubKey: string(rsa.CreatePublicKeyPem(transmissionPublicKey)),
ClientReceptionRSAPubKey: string(rsa.CreatePublicKeyPem(receptionPublicKey)),
}) })
if err != nil { if err != nil {
err = errors.Wrap(err, "sendRegistrationMessage: Unable to contact Registration Server!") err = errors.Wrap(err, "sendRegistrationMessage: Unable to contact Identity Server!")
return nil, err return nil, nil, err
} }
if response.Error != "" { if response.Error != "" {
return nil, errors.Errorf("sendRegistrationMessage: error handling message: %s", response.Error) return nil, nil, errors.Errorf("sendRegistrationMessage: error handling message: %s", response.Error)
} }
return response.ClientSignedByServer.Signature, nil return response.ClientSignedByServer.Signature, response.ClientReceptionSignedByServer.Signature, nil
} }
...@@ -38,6 +38,10 @@ func (s *MockRegistrationSender) SendRegistrationMessage(host *connect.Host, mes ...@@ -38,6 +38,10 @@ func (s *MockRegistrationSender) SendRegistrationMessage(host *connect.Host, mes
Nonce: []byte("nonce"), Nonce: []byte("nonce"),
Signature: []byte("sig"), Signature: []byte("sig"),
}, },
ClientReceptionSignedByServer: &messages.RSASignature{
Nonce: []byte("receptionnonce"),
Signature: []byte("receptionsig"),
},
Error: s.errInReply, Error: s.errInReply,
}, s.errSendRegistration }, s.errSendRegistration
} }
...@@ -64,13 +68,16 @@ func TestRegisterWithPermissioning(t *testing.T) { ...@@ -64,13 +68,16 @@ func TestRegisterWithPermissioning(t *testing.T) {
} }
regCode := "flooble doodle" regCode := "flooble doodle"
sig, err := register(&sender, sender.getHost, key.GetPublic(), regCode) sig1, sig2, err := register(&sender, sender.getHost, key.GetPublic(), key.GetPublic(), regCode)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if string(sig) != "sig" { if string(sig1) != "sig" {
t.Error("expected signature to be 'sig'") t.Error("expected signature to be 'sig'")
} }
if string(sig2) != "receptionsig" {
t.Error("expected signature to be 'receptionsig'")
}
if sender.host.String() != sender.getHost.String() { if sender.host.String() != sender.getHost.String() {
t.Errorf("hosts differed. expected %v, got %v", sender.host, sender.getHost) t.Errorf("hosts differed. expected %v, got %v", sender.host, sender.getHost)
} }
...@@ -98,7 +105,7 @@ func TestRegisterWithPermissioning_ResponseErr(t *testing.T) { ...@@ -98,7 +105,7 @@ func TestRegisterWithPermissioning_ResponseErr(t *testing.T) {
var sender MockRegistrationSender var sender MockRegistrationSender
sender.succeedGetHost = true sender.succeedGetHost = true
sender.errInReply = "failure occurred on permissioning" sender.errInReply = "failure occurred on permissioning"
_, err = register(&sender, nil, key.GetPublic(), "") _, _, err = register(&sender, nil, key.GetPublic(), key.GetPublic(), "")
if err == nil { if err == nil {
t.Error("no error if registration fails on permissioning") t.Error("no error if registration fails on permissioning")
} }
...@@ -115,7 +122,7 @@ func TestRegisterWithPermissioning_ConnectionErr(t *testing.T) { ...@@ -115,7 +122,7 @@ func TestRegisterWithPermissioning_ConnectionErr(t *testing.T) {
var sender MockRegistrationSender var sender MockRegistrationSender
sender.succeedGetHost = true sender.succeedGetHost = true
sender.errSendRegistration = errors.New("connection problem") sender.errSendRegistration = errors.New("connection problem")
_, err = register(&sender, nil, key.GetPublic(), "") _, _, err = register(&sender, nil, key.GetPublic(), key.GetPublic(), "")
if err == nil { if err == nil {
t.Error("no error if e.g. context deadline exceeded") t.Error("no error if e.g. context deadline exceeded")
} }
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2021 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package ephemeral
import (
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/storage/versioned"
"sync"
"time"
)
const (
storePrefix = "ephemeralTimestamp"
ephemeralVersion = 0
timestampKey = "timestampKeyStore"
)
type Store struct {
kv *versioned.KV
// Timestamp of last check for ephemeral Ids
timestamp time.Time
mux sync.RWMutex
}
// NewStore creates a new store.
func NewStore(kv *versioned.KV) (*Store, error) {
kv = kv.Prefix(storePrefix)
s := &Store{
kv: kv,
timestamp: time.Time{},
}
return s, s.save()
}
// loads the ephemeral storage object
func LoadStore(kv *versioned.KV) (*Store, error) {
kv = kv.Prefix(storePrefix)
s := &Store{
timestamp: time.Time{},
kv: kv,
}
obj, err := kv.Get(timestampKey)
if err != nil {
return nil, err
}
if err = s.unmarshal(obj.Data); err != nil {
return nil, err
}
return s, nil
}
// Returns the stored timestamp. If a timestamp is empty, we check disk.
// If the disk's timestamp is empty. we return an error.
// Otherwise, we return the valid timestamp found
func (s *Store) GetTimestamp() (time.Time, error) {
s.mux.RLock()
defer s.mux.RUnlock()
ts := s.timestamp
// Check that t
if ts.Equal(time.Time{}) {
obj, err := s.kv.Get(timestampKey)
if err != nil {
return time.Time{}, err
}
ts = time.Time{}
if err := ts.UnmarshalBinary(obj.Data); err != nil {
return time.Time{}, err
}
// If still an empty time object, then no timestamp exists
if ts.Equal(time.Time{}) {
return time.Time{}, errors.Errorf("No timestamp has been found")
}
}
return ts, nil
}
// Updates the stored time stamp with the time passed in
func (s *Store) UpdateTimestamp(ts time.Time) error {
s.mux.Lock()
defer s.mux.Unlock()
s.timestamp = ts
if err := s.save(); err != nil {
jww.FATAL.Panicf("Failed to update timestamp of last check for ephemeral IDs")
}
return nil
}
// stores the ephemeral store
func (s *Store) save() error {
data, err := s.marshal()
if err != nil {
return err
}
obj := versioned.Object{
Version: ephemeralVersion,
Timestamp: time.Now(),
Data: data,
}
return s.kv.Set(timestampKey, &obj)
}
// builds a byte representation of the store
func (s *Store) marshal() ([]byte, error) {
return s.timestamp.MarshalBinary()
}
// restores the data for a store from the byte representation of the store
func (s *Store) unmarshal(b []byte) error {
ts := time.Time{}
if err := ts.UnmarshalBinary(b); err != nil {
return err
}
s.timestamp = ts
return nil
}
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2021 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package ephemeral
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment