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

in progress e2e, very broken

parent 127a9469
No related branches found
No related tags found
No related merge requests found
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2020-08-06 13:38:20.0089 -0700 PDT m=+0.031406132
// 2020-08-10 10:05:18.2662998 -0700 PDT m=+0.116012701
package globals
const GITVERSION = `f537145 Merge branch 'Optimus/ClientStorage' into XX-2415/NodeKeys`
const GITVERSION = `127a946 Merge branch 'XX-2415/NodeKeys' into 'Optimus/ClientStorage'`
const SEMVER = "1.4.0"
const DEPENDENCIES = `module gitlab.com/elixxir/client
......
package key
type FingerprintAccess interface {
AddFingerprints([]*Key) error
//recieves a list of fingerprints
RemoveFingerprints([]*Key) error
}
package key
import (
"gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/hash"
"gitlab.com/elixxir/primitives/format"
)
type Key struct {
// Links
session *Session
// Key to be used
key *cyclic.Int
// Designation of crypto type
outer parse.CryptoType
// keyNum is the index of the key by order of creation
// it is used to identify the key in the key.Session
keyNum uint32
}
func Operate(func(s *Session, )) error
// return pointers to higher level management structures
func (k *Key) GetSession() *Session { return k.session }
// Get key value (cyclic.Int)
func (k *Key) GetKey() *cyclic.Int { return k.key }
// Get key type, E2E or Rekey
func (k *Key) GetOuterType() parse.CryptoType { return k.outer }
// Generate key fingerprint
// NOTE: This function is not a getter,
// it returns a new byte array on each call
func (k *Key) KeyFingerprint() format.Fingerprint {
h, _ := hash.NewCMixHash()
h.Write(k.key.Bytes())
fp := format.Fingerprint{}
copy(fp[:], h.Sum(nil))
return fp
}
package key
import (
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/xx_network/primitives/id"
)
type Manager struct {
params Params
partner id.ID
receive *SessionBuff
send *SessionBuff
}
// generator
func NewManager(params Params, partnerID *id.ID, myPrivKey *cyclic.Int, partnerPubKey *cyclic.Int) (*Manager, error) {
return nil, nil
}
// ekv functions
func (m *Manager) Marshal() ([]byte, error) { return nil, nil }
func (m *Manager) Unmarshal([]byte) error { return nil }
//gets a copy of the ID of the partner
func (m *Manager) GetPartner() *id.ID {
p := m.partner
return &p
}
// creates a new receive session using the latest private key this user has sent
// and the new public key received from the partner
func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int) {}
// creates a new receive session using the latest public key received from the
// partner and a mew private key for the user
func (m *Manager) NewSendSession(myPrivKey *cyclic.Int) {}
// gets the session buffer for message reception
func (m *Manager) GetReceiveSessionBuff() *SessionBuff { return nil }
// gets the session buffer for message reception
func (m *Manager) LatestReceiveSession() *Session { return nil }
package key
import "gitlab.com/elixxir/crypto/e2e"
// DEFAULT KEY GENERATION PARAMETERS
// Hardcoded limits for keys
// With 16 receiving states we can hold
// 16*64=1024 dirty bits for receiving keys
// With that limit, and setting maxKeys to 800,
// we need a Threshold of 224, and a scalar
// smaller than 1.28 to ensure we never generate
// more than 1024 keys
// With 1 receiving states for ReKeys we can hold
// 64 Rekeys
const (
minKeys uint16 = 500
maxKeys uint16 = 800
ttlScalar float64 = 1.2 // generate 20% extra keys
threshold uint16 = 224
numReKeys uint16 = 64
)
type Params struct {
MinKeys uint16
MaxKeys uint16
NumRekeys uint16
e2e.TTLParams
}
func GetDefaultParams() Params {
return Params{
MinKeys: minKeys,
MaxKeys: maxKeys,
NumRekeys: numReKeys,
TTLParams: e2e.TTLParams{
TTLScalar: ttlScalar,
MinNumKeys: threshold,
},
}
}
package key
import (
"encoding/base64"
"gitlab.com/elixxir/client/keyStore"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/hash"
"sync"
)
type SessionID [32]byte
func (sid SessionID) String() string {
return base64.StdEncoding.EncodeToString(sid[:])
}
type Session struct {
//pointer to manager
manager *Manager
// Underlying key
baseKey *cyclic.Int
// Own Private Key
myPrivKey *cyclic.Int
// Partner Public Key
partnerPubKey *cyclic.Int
//denotes if the other party has confirmed this key
confirmed bool
// Value of the counter at which a rekey is triggered
ttl uint16
// Total number of Keys
numKeys uint32
// Total number of Rekey keys
numReKeys uint16
// Received Keys dirty bits
// Each bit represents a single Key
KeyState []*uint64
// Received ReKeys dirty bits
// Each bit represents a single ReKey
ReKeyState []*uint64
// Keys
keys []*Key
lastKey uint32
// ReKeys
reKeys []*Key
lastReKey uint32
//mutex
mux sync.RWMutex
}
type SessionDisk struct {
// Underlying key
baseKey *cyclic.Int
// Own Private Key
myPrivKey *cyclic.Int
// Partner Public Key
partnerPubKey *cyclic.Int
// Received Keys dirty bits
// Each bit represents a single Key
KeyState []*uint64
// Received ReKeys dirty bits
// Each bit represents a single ReKey
ReKeyState []*uint64
//denotes if the other party has confirmed this key
confirmed bool
//position of the earliest unused key
lastKey uint32
//position of the earliest unused key
lastReKey uint32
}
//Generator which creates all keys and structures
func (s *Session) NewSession(myPrivKey *cyclic.Int, partnerPubKey *cyclic.Int, manager *Manager) (*Session, error) {
return nil, nil
}
//Gets the manager used to
//Gets the base key.
func (s *Session) GetBaseKey() *cyclic.Int {
// no lock is needed because this cannot be edited
return s.baseKey.DeepCopy()
}
func (s *Session) GetMyPrivKey() *cyclic.Int {
// no lock is needed because this cannot be edited
return s.myPrivKey.DeepCopy()
}
func (s *Session) GetPartnerPubKey() *cyclic.Int {
// no lock is needed because this cannot be edited
return s.partnerPubKey.DeepCopy()
}
//Blake2B hash of base key used for storage
func (s *Session) GetID() SessionID {
sid := SessionID{}
h, _ := hash.NewCMixHash()
h.Write(s.baseKey.Bytes())
copy(sid[:], h.Sum(nil))
return sid
}
//ekv functions
func (s *Session) Marshal() ([]byte, error) { return nil, nil }
func (s *Session) Unmarshal([]byte) error { return nil }
//key usage
// Pops the first unused key, skipping any which are denoted as used
func (s *Session) PopKey() (*keyStore.E2EKey, error) { return nil, nil }
// Pops the first unused rekey, skipping any which are denoted as used
func (s *Session) PopReKey() (*keyStore.E2EKey, error) { return nil, nil }
// denotes the passed key as used
func (s *Session) UseKey(*keyStore.E2EKey) error { return nil }
// denotes the passed rekey as used
func (s *Session) UseRekey(*keyStore.E2EKey) error { return nil }
// returns the state of the keyblob, which denotes if the Session is active,
// functional but in need of a rekey, empty of send key, or empty of rekeys
func (s *Session) Status() Status { return 0 }
// Sets the confirm bool. this is set when the partner is certain to share the
// session. It should be called immediately for receive keys and only on rekey
// confirmation for send keys. Confirmation can only be made by the sessionBuffer
// because it is used to keep track of active sessions for rekey as well
func (s *Session) confirm() {
s.mux.Lock()
defer s.mux.Unlock()
s.confirmed = true
}
// checks if the session has been confirmed
func (s *Session) IsConfirmed() bool {
s.mux.RLock()
defer s.mux.RUnlock()
return s.confirmed
}
/*PRIVATE*/
package key
import (
"github.com/pkg/errors"
"sync"
)
type SessionBuff struct {
sessions []*Session
sessionByID map[SessionID]*Session
mux sync.RWMutex
}
type SessionBuffDisk struct {
sessions []SessionID
}
func NewSessionBuff(n int, deletion func(session *Session)) *SessionBuff { return &SessionBuff{} }
//ekv functions
func (sb *SessionBuff) Marshal() ([]byte, error) { return nil, nil }
func (sb *SessionBuff) Unmarshal([]byte) error { return nil }
func (sb *SessionBuff) AddSession(s *Session) {
sb.mux.Lock()
defer sb.mux.Unlock()
sb.sessions = append([]*Session{s}, sb.sessions...)
sb.sessionByID[s.GetID()] = s
return
}
func (sb *SessionBuff) GetNewest() *Session {
sb.mux.RLock()
defer sb.mux.RUnlock()
if len(sb.sessions) == 0 {
return nil
}
return sb.sessions[0]
}
// returns the session which is most likely to be successful for sending
func (sb *SessionBuff) GetSessionForSending() *Session {
sb.mux.RLock()
defer sb.mux.RUnlock()
if len(sb.sessions) == 0 {
return nil
}
var confirmedRekey []*Session
var unconfirmedActive []*Session
var unconfirmedRekey []*Session
for _, s := range sb.sessions {
status := s.Status()
confirmed := s.confirmed
if status == Active && confirmed {
//always return the first confirmed active, happy path
return s
} else if status == RekeyNeeded && confirmed {
confirmedRekey = append(confirmedRekey, s)
} else if status == Active && !confirmed {
unconfirmedActive = append(unconfirmedActive, s)
} else if status == RekeyNeeded && !confirmed {
unconfirmedRekey = append(unconfirmedRekey, s)
}
}
//return the newest based upon priority
if len(confirmedRekey) > 0 {
return confirmedRekey[0]
} else if len(unconfirmedActive) > 0 {
return unconfirmedActive[0]
} else if len(unconfirmedRekey) > 0 {
return unconfirmedRekey[0]
}
return nil
}
func (sb *SessionBuff) GetNewestConfirmed() *Session {
sb.mux.RLock()
defer sb.mux.RUnlock()
if len(sb.sessions) == 0 {
return nil
}
for _, s := range sb.sessions {
status := s.Status()
confirmed := s.confirmed
if status != RekeyEmpty && confirmed {
return s
}
}
return nil
}
func (sb *SessionBuff) GetByID(id SessionID) *Session {
sb.mux.RLock()
defer sb.mux.RUnlock()
return sb.sessionByID[id]
}
// sets the passed session ID as confirmed. Call "GetSessionRotation" after
// to get any sessions that are to be deleted and then "DeleteSession" to
// remove them
func (sb *SessionBuff) Confirm(id SessionID) error {
sb.mux.Lock()
defer sb.mux.Unlock()
s, ok := sb.sessionByID[id]
if !ok {
return errors.Errorf("Could not confirm session %s, does not exist", s.GetID())
}
s.confirm()
return nil
}
func (sb *SessionBuff) Clean() error {
}
}
//find the sessions position in the session buffer
loc := -1
for i, sBuf := range sb.sessions{
if sBuf==s{
loc = i
}
package key
type Status uint8
const (
Active Status = iota
RekeyNeeded
Empty
RekeyEmpty
)
func (a Status) String() string {
switch a {
case Active:
return "Active"
case RekeyNeeded:
return "Rekey Needed"
case Empty:
return "Empty"
case RekeyEmpty:
return "Rekey Empty"
}
}
package key
import (
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
)
type Store struct {
managers map[id.ID]*Manager
fingerprintToKey map[format.Fingerprint]*Key
}
type StoreDisk struct {
contacts []id.ID
}
func (s *Store) CleanManager(partner id.ID) error {
//lookup
//get sessions to be removed
}
......@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/pkg/errors"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/ring"
)
const ReceptionKeyManagerBufferLength = 5
......@@ -18,8 +19,11 @@ func NewReceptionKeyManagerBuffer() *ReceptionKeyManagerBuffer {
}
type ReceptionKeyManagerBuffer struct {
managers [ReceptionKeyManagerBufferLength]*KeyManager
loc int
managers ring.Buff
}
type ReceptionKeyManagerBufferDisk struct {
managers ring.Buff
}
// Push takes in a new keymanager obj, and adds it into our circular buffer of keymanagers,
......
......@@ -113,20 +113,26 @@ type KeyStore struct {
// Key generation parameters
params *KeyParams
// Transmission Keys map
// Maps id.ID to *KeyManager
sendKeyManagers *keyManMap
// Reception Keys map
// Maps format.Fingerprint to *E2EKey
receptionKeys *inKeyMap
fingerprintToKey map[format.Fingerprint]*E2EKey
// Reception Key Managers map
recvKeyManagers map[id.ID]*ReceptionKeyManagerBuffer
KeyManagers map[id.ID]*KeyManagerBuffer
lock sync.Mutex
}
//storage version
type KeyStoreDisk struct {
// Key generation parameters
params *KeyParams
contacts []id.ID
}
func NewStore() *KeyStore {
ks := new(KeyStore)
ks.params = &KeyParams{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment