Skip to content
Snippets Groups Projects
Commit 5132edf3 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

added more to connection

parent d2c643e7
No related branches found
No related tags found
3 merge requests!510Release,!226WIP: Api2.0,!207WIP: Client Restructure
...@@ -104,6 +104,8 @@ func createKeys(rng *fastRNG.StreamGenerator) ( ...@@ -104,6 +104,8 @@ func createKeys(rng *fastRNG.StreamGenerator) (
stream := rng.GetStream() stream := rng.GetStream()
transmissionRsaKey, err = rsa.GenerateKey(stream, transmissionRsaKey, err = rsa.GenerateKey(stream,
rsa.DefaultRSABitLen) rsa.DefaultRSABitLen)
transmissionSalt = make([]byte, 32)
_, err = stream.Read(receptionSalt)
stream.Close() stream.Close()
if err != nil { if err != nil {
jww.FATAL.Panicf(err.Error()) jww.FATAL.Panicf(err.Error())
...@@ -116,6 +118,8 @@ func createKeys(rng *fastRNG.StreamGenerator) ( ...@@ -116,6 +118,8 @@ func createKeys(rng *fastRNG.StreamGenerator) (
stream := rng.GetStream() stream := rng.GetStream()
receptionRsaKey, err = rsa.GenerateKey(stream, receptionRsaKey, err = rsa.GenerateKey(stream,
rsa.DefaultRSABitLen) rsa.DefaultRSABitLen)
receptionSalt = make([]byte, 32)
_, err = stream.Read(receptionSalt)
stream.Close() stream.Close()
if err != nil { if err != nil {
jww.FATAL.Panicf(err.Error()) jww.FATAL.Panicf(err.Error())
......
package bindings
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/connect"
"sync"
)
// connectionTracker is a singleton used to keep track of extant clients, allowing
// for race condition free passing over the bindings
type authenticatedConnectionTracker struct {
connections map[int]*AuthenticatedConnection
count int
mux sync.RWMutex
}
// make makes a client from an API client, assigning it a unique ID
func (act *authenticatedConnectionTracker) make(c connect.AuthenticatedConnection) *AuthenticatedConnection {
act.mux.Lock()
defer act.mux.Unlock()
id := act.count
act.count++
act.connections[id] = &AuthenticatedConnection{
Connection: Connection{
connection: c,
id: id,
},
}
return act.connections[id]
}
//get returns a client given its ID
func (act *authenticatedConnectionTracker) get(id int) (*AuthenticatedConnection, error) {
act.mux.RLock()
defer act.mux.RUnlock()
c, exist := act.connections[id]
if !exist {
return nil, errors.Errorf("Cannot get client for id %d, client "+
"does not exist", id)
}
return c, nil
}
//deletes a client if it exists
func (act *authenticatedConnectionTracker) delete(id int) {
act.mux.Lock()
defer act.mux.Unlock()
delete(act.connections, id)
}
package bindings
import (
"gitlab.com/elixxir/client/connect"
"gitlab.com/elixxir/crypto/contact"
)
//connection tracker singleton, used to track connections so they can be
//referenced by id back over the bindings
var authenticatedConnectionTrackerSingleton = &authenticatedConnectionTracker{
connections: make(map[int]*AuthenticatedConnection),
count: 0,
}
type AuthenticatedConnection struct {
Connection
}
func (_ *AuthenticatedConnection) IsAuthenticated() bool {
return true
}
// ConnectWithAuthentication is called by the client, ie the one establishing
// connection with the server. Once a connect.Connection has been established
// with the server and then authenticate their identity to the server.
func (c *Client) ConnectWithAuthentication(recipientContact []byte, myIdentity []byte) (*AuthenticatedConnection, error) {
cont, err := contact.Unmarshal(recipientContact)
if err != nil {
return nil, err
}
myID, rsaPriv, salt, myDHPriv, err := unmarshalIdentity(myIdentity)
if err != nil {
return nil, err
}
connection, err := connect.ConnectWithAuthentication(cont, myID, salt, rsaPriv, myDHPriv, c.api.GetRng(),
c.api.GetStorage().GetE2EGroup(), c.api.GetCmix(), connect.GetDefaultParams())
return authenticatedConnectionTrackerSingleton.make(connection), nil
}
...@@ -19,7 +19,7 @@ var connectionTrackerSingleton = &connectionTracker{ ...@@ -19,7 +19,7 @@ var connectionTrackerSingleton = &connectionTracker{
// //
type Connection struct { type Connection struct {
connection connect.AuthenticatedConnection connection connect.Connection
id int id int
} }
...@@ -48,24 +48,6 @@ func (c *Client) Connect(recipientContact []byte, myIdentity []byte) ( ...@@ -48,24 +48,6 @@ func (c *Client) Connect(recipientContact []byte, myIdentity []byte) (
return connectionTrackerSingleton.make(connection), nil return connectionTrackerSingleton.make(connection), nil
} }
// ConnectWithAuthentication is called by the client, ie the one establishing
// connection with the server. Once a connect.Connection has been established
// with the server and then authenticate their identity to the server.
func (c *Client) ConnectWithAuthentication(recipientContact []byte, myIdentity []byte) (*Connection, error) {
cont, err := contact.Unmarshal(recipientContact)
if err != nil {
return nil, err
}
myID, rsaPriv, salt, myDHPriv, err := unmarshalIdentity(myIdentity)
if err != nil {
return nil, err
}
connection, err := connect.ConnectWithAuthentication(cont, myID, salt, rsaPriv, myDHPriv, c.api.GetRng(),
c.api.GetStorage().GetE2EGroup(), c.api.GetCmix(), connect.GetDefaultParams())
return connectionTrackerSingleton.make(connection), nil
}
// //
type E2ESendReport struct { type E2ESendReport struct {
roundsList roundsList
...@@ -98,8 +80,8 @@ func (c *Connection) Close() { ...@@ -98,8 +80,8 @@ func (c *Connection) Close() {
} }
// GetPartner returns the partner.Manager for this Connection // GetPartner returns the partner.Manager for this Connection
func (c *Connection) GetPartner() partner.Manager { func (c *Connection) GetPartner() []byte {
return c.connection.GetPartner().PartnerId().Marshal()
} }
// RegisterListener is used for E2E reception // RegisterListener is used for E2E reception
......
...@@ -3,7 +3,9 @@ package bindings ...@@ -3,7 +3,9 @@ package bindings
import ( import (
"encoding/json" "encoding/json"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/crypto/xx"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
...@@ -22,7 +24,41 @@ type Fact struct { ...@@ -22,7 +24,41 @@ type Fact struct {
// MakeIdentity generates a new cryptographic identity for receving // MakeIdentity generates a new cryptographic identity for receving
// messages // messages
func (c *Client) MakeIdentity() ([]byte, error) { func (c *Client) MakeIdentity() ([]byte, error) {
I := Identity{} stream := c.api.GetRng().GetStream()
defer stream.Close()
//make RSA Key
rsaKey, err := rsa.GenerateKey(stream,
rsa.DefaultRSABitLen)
if err != nil {
return nil, err
}
//make salt
salt := make([]byte, 32)
_, err = stream.Read(salt)
//make dh private key
privkey := diffieHellman.GeneratePrivateKey(
len(c.api.GetStorage().GetE2EGroup().GetPBytes()),
c.api.GetStorage().GetE2EGroup(), stream)
//make the ID
id, err := xx.NewID(rsaKey.GetPublic(),
salt, id.User)
if err != nil {
return nil, err
}
//create the identity object
I := Identity{
ID: id.Marshal(),
RSAPrivatePem: rsa.CreatePrivateKeyPem(rsaKey),
Salt: salt,
DHKeyPrivate: privkey.Bytes(),
}
return json.Marshal(&I) return json.Marshal(&I)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment