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

startie dchanging message and type handling

parent 10af6992
Branches
Tags
No related merge requests found
...@@ -151,28 +151,90 @@ func (Type) EnumDescriptor() ([]byte, []int) { ...@@ -151,28 +151,90 @@ func (Type) EnumDescriptor() ([]byte, []int) {
return file_types_proto_rawDescGZIP(), []int{0} return file_types_proto_rawDescGZIP(), []int{0}
} }
type RekeyTrigger struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// PublicKey used in the registration
PublicKey []byte `protobuf:"bytes,1,opt,name=publicKey,proto3" json:"publicKey,omitempty"`
// ID of the session used to create this session
SessionID []byte `protobuf:"bytes,2,opt,name=SessionID,json=sessionID,proto3" json:"SessionID,omitempty"`
}
func (x *RekeyTrigger) Reset() {
*x = RekeyTrigger{}
if protoimpl.UnsafeEnabled {
mi := &file_types_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *RekeyTrigger) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RekeyTrigger) ProtoMessage() {}
func (x *RekeyTrigger) ProtoReflect() protoreflect.Message {
mi := &file_types_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RekeyTrigger.ProtoReflect.Descriptor instead.
func (*RekeyTrigger) Descriptor() ([]byte, []int) {
return file_types_proto_rawDescGZIP(), []int{0}
}
func (x *RekeyTrigger) GetPublicKey() []byte {
if x != nil {
return x.PublicKey
}
return nil
}
func (x *RekeyTrigger) GetSessionID() []byte {
if x != nil {
return x.SessionID
}
return nil
}
var File_types_proto protoreflect.FileDescriptor var File_types_proto protoreflect.FileDescriptor
var file_types_proto_rawDesc = []byte{ var file_types_proto_rawDesc = []byte{
0x0a, 0x0b, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x0a, 0x0b, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70,
0x61, 0x72, 0x73, 0x65, 0x2a, 0xf9, 0x01, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x61, 0x72, 0x73, 0x65, 0x22, 0x4a, 0x0a, 0x0c, 0x52, 0x65, 0x6b, 0x65, 0x79, 0x54, 0x72, 0x69,
0x07, 0x4e, 0x4f, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x45, 0x67, 0x67, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65,
0x58, 0x54, 0x5f, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b,
0x55, 0x44, 0x42, 0x5f, 0x50, 0x55, 0x53, 0x48, 0x5f, 0x4b, 0x45, 0x59, 0x10, 0x0a, 0x12, 0x19, 0x65, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x18,
0x0a, 0x15, 0x55, 0x44, 0x42, 0x5f, 0x50, 0x55, 0x53, 0x48, 0x5f, 0x4b, 0x45, 0x59, 0x5f, 0x52, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x44,
0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x0b, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x44, 0x42, 0x2a, 0xf9, 0x01, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x4f, 0x5f,
0x5f, 0x47, 0x45, 0x54, 0x5f, 0x4b, 0x45, 0x59, 0x10, 0x0c, 0x12, 0x18, 0x0a, 0x14, 0x55, 0x44, 0x54, 0x59, 0x50, 0x45, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x45, 0x58, 0x54, 0x5f, 0x4d,
0x42, 0x5f, 0x47, 0x45, 0x54, 0x5f, 0x4b, 0x45, 0x59, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x55, 0x44, 0x42, 0x5f,
0x53, 0x45, 0x10, 0x0d, 0x12, 0x10, 0x0a, 0x0c, 0x55, 0x44, 0x42, 0x5f, 0x52, 0x45, 0x47, 0x49, 0x50, 0x55, 0x53, 0x48, 0x5f, 0x4b, 0x45, 0x59, 0x10, 0x0a, 0x12, 0x19, 0x0a, 0x15, 0x55, 0x44,
0x53, 0x54, 0x45, 0x52, 0x10, 0x0e, 0x12, 0x19, 0x0a, 0x15, 0x55, 0x44, 0x42, 0x5f, 0x52, 0x45, 0x42, 0x5f, 0x50, 0x55, 0x53, 0x48, 0x5f, 0x4b, 0x45, 0x59, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f,
0x47, 0x49, 0x53, 0x54, 0x45, 0x52, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x4e, 0x53, 0x45, 0x10, 0x0b, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x44, 0x42, 0x5f, 0x47, 0x45, 0x54,
0x0f, 0x12, 0x0e, 0x0a, 0x0a, 0x55, 0x44, 0x42, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x10, 0x5f, 0x4b, 0x45, 0x59, 0x10, 0x0c, 0x12, 0x18, 0x0a, 0x14, 0x55, 0x44, 0x42, 0x5f, 0x47, 0x45,
0x10, 0x12, 0x17, 0x0a, 0x13, 0x55, 0x44, 0x42, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x5f, 0x54, 0x5f, 0x4b, 0x45, 0x59, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x0d,
0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x11, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x45, 0x12, 0x10, 0x0a, 0x0c, 0x55, 0x44, 0x42, 0x5f, 0x52, 0x45, 0x47, 0x49, 0x53, 0x54, 0x45, 0x52,
0x4b, 0x45, 0x59, 0x5f, 0x54, 0x52, 0x49, 0x47, 0x47, 0x45, 0x52, 0x10, 0x1e, 0x12, 0x11, 0x0a, 0x10, 0x0e, 0x12, 0x19, 0x0a, 0x15, 0x55, 0x44, 0x42, 0x5f, 0x52, 0x45, 0x47, 0x49, 0x53, 0x54,
0x0d, 0x52, 0x45, 0x4b, 0x45, 0x59, 0x5f, 0x43, 0x4f, 0x4e, 0x46, 0x49, 0x52, 0x4d, 0x10, 0x1f, 0x45, 0x52, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x0f, 0x12, 0x0e, 0x0a,
0x42, 0x0b, 0x5a, 0x09, 0x63, 0x6d, 0x69, 0x78, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x0a, 0x55, 0x44, 0x42, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x10, 0x10, 0x12, 0x17, 0x0a,
0x72, 0x6f, 0x74, 0x6f, 0x33, 0x13, 0x55, 0x44, 0x42, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x5f, 0x52, 0x45, 0x53, 0x50,
0x4f, 0x4e, 0x53, 0x45, 0x10, 0x11, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x45, 0x4b, 0x45, 0x59, 0x5f,
0x54, 0x52, 0x49, 0x47, 0x47, 0x45, 0x52, 0x10, 0x1e, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x45, 0x4b,
0x45, 0x59, 0x5f, 0x43, 0x4f, 0x4e, 0x46, 0x49, 0x52, 0x4d, 0x10, 0x1f, 0x42, 0x0b, 0x5a, 0x09,
0x63, 0x6d, 0x69, 0x78, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
} }
var ( var (
...@@ -188,8 +250,10 @@ func file_types_proto_rawDescGZIP() []byte { ...@@ -188,8 +250,10 @@ func file_types_proto_rawDescGZIP() []byte {
} }
var file_types_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_types_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_types_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_types_proto_goTypes = []interface{}{ var file_types_proto_goTypes = []interface{}{
(Type)(0), // 0: parse.Type (Type)(0), // 0: parse.Type
(*RekeyTrigger)(nil), // 1: parse.RekeyTrigger
} }
var file_types_proto_depIdxs = []int32{ var file_types_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method output_type
...@@ -204,19 +268,34 @@ func file_types_proto_init() { ...@@ -204,19 +268,34 @@ func file_types_proto_init() {
if File_types_proto != nil { if File_types_proto != nil {
return return
} }
if !protoimpl.UnsafeEnabled {
file_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*RekeyTrigger); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{ File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_types_proto_rawDesc, RawDescriptor: file_types_proto_rawDesc,
NumEnums: 1, NumEnums: 1,
NumMessages: 0, NumMessages: 1,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },
GoTypes: file_types_proto_goTypes, GoTypes: file_types_proto_goTypes,
DependencyIndexes: file_types_proto_depIdxs, DependencyIndexes: file_types_proto_depIdxs,
EnumInfos: file_types_proto_enumTypes, EnumInfos: file_types_proto_enumTypes,
MessageInfos: file_types_proto_msgTypes,
}.Build() }.Build()
File_types_proto = out.File File_types_proto = out.File
file_types_proto_rawDesc = nil file_types_proto_rawDesc = nil
......
...@@ -109,6 +109,6 @@ enum Type { ...@@ -109,6 +109,6 @@ enum Type {
message RekeyTrigger { message RekeyTrigger {
// PublicKey used in the registration // PublicKey used in the registration
bytes publicKey = 1; bytes publicKey = 1;
// ID of the session used to create this session
bytes SessionID = 2; bytes SessionID = 2;
bool newSession = 3;
} }
package context package message
import "gitlab.com/xx_network/primitives/id" import "gitlab.com/xx_network/primitives/id"
......
package context package context
import ( import (
"gitlab.com/elixxir/client/context/message"
"gitlab.com/elixxir/client/context/params" "gitlab.com/elixxir/client/context/params"
"gitlab.com/elixxir/client/context/stoppable" "gitlab.com/elixxir/client/context/stoppable"
"gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/comms/network"
...@@ -9,8 +10,8 @@ import ( ...@@ -9,8 +10,8 @@ import (
) )
type NetworkManager interface { type NetworkManager interface {
SendE2E(m Message, e2eP params.E2E, cmixP params.CMIX) ([]id.Round, error) SendE2E(m message.Message, e2eP params.E2E, cmixP params.CMIX) ([]id.Round, error)
SendUnsafe(m Message) ([]id.Round, error) SendUnsafe(m message.Message) ([]id.Round, error)
SendCMIX(message format.Message) (id.Round, error) SendCMIX(message format.Message) (id.Round, error)
GetInstance() *network.Instance GetInstance() *network.Instance
Stoppable() stoppable.Stoppable Stoppable() stoppable.Stoppable
......
package keyExchange package keyExchange
import ( import (
"github.com/golang/protobuf/proto"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmixproto"
"gitlab.com/elixxir/client/context" "gitlab.com/elixxir/client/context"
"gitlab.com/elixxir/client/context/message"
"gitlab.com/elixxir/client/context/params" "gitlab.com/elixxir/client/context/params"
"gitlab.com/elixxir/client/context/utility" "gitlab.com/elixxir/client/context/utility"
"gitlab.com/elixxir/client/storage/e2e" "gitlab.com/elixxir/client/storage/e2e"
ds "gitlab.com/elixxir/comms/network/dataStructures" ds "gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/primitives/states" "gitlab.com/elixxir/primitives/states"
jww "github.com/spf13/jwalterweatherman"
"time" "time"
) )
...@@ -32,7 +35,8 @@ func trigger(ctx *context.Context, manager *e2e.Manager, session *e2e.Session) { ...@@ -32,7 +35,8 @@ func trigger(ctx *context.Context, manager *e2e.Manager, session *e2e.Session) {
// replace itself, then create the session // replace itself, then create the session
case e2e.NewSessionTriggered: case e2e.NewSessionTriggered:
//create the session, pass a nil private key to generate a new one //create the session, pass a nil private key to generate a new one
negotiatingSession = manager.NewSendSession(nil, e2e.GetDefaultSessionParams()) negotiatingSession = manager.NewSendSession(nil,
e2e.GetDefaultSessionParams(), session.GetID())
//move the state of the triggering session forward //move the state of the triggering session forward
session.SetNegotiationStatus(e2e.NewSessionCreated) session.SetNegotiationStatus(e2e.NewSessionCreated)
// If the session has not successfully negotiated, redo its negotiation // If the session has not successfully negotiated, redo its negotiation
...@@ -60,11 +64,23 @@ func negotiate(ctx *context.Context, session *e2e.Session) error { ...@@ -60,11 +64,23 @@ func negotiate(ctx *context.Context, session *e2e.Session) error {
pubKey := diffieHellman.GeneratePublicKey(session.GetMyPrivKey(), pubKey := diffieHellman.GeneratePublicKey(session.GetMyPrivKey(),
e2eStore.GetGroup()) e2eStore.GetGroup())
//build the payload
payload, err := proto.Marshal(&cmixproto.RekeyTrigger{
PublicKey: pubKey.Bytes(),
SessionID: session.GetTrigger().Bytes(),
})
//If the payload cannot be marshaled, panic
if err != nil {
jww.FATAL.Printf("Failed to marshal payload for Key "+
"Negotation with %s", session.GetPartner())
}
//send session //send session
m := context.Message{ m := message.Message{
Recipient: session.GetPartner(), Recipient: session.GetPartner(),
Payload: pubKey.Bytes(), Payload: payload,
MessageType: 42, MessageType: int32(cmixproto.Type_REKEY_TRIGGER),
} }
//send the message under the key exchange //send the message under the key exchange
......
...@@ -102,7 +102,6 @@ func (s *Store) Add(nid *id.ID, k *cyclic.Int) { ...@@ -102,7 +102,6 @@ func (s *Store) Add(nid *id.ID, k *cyclic.Int) {
nodekey := newKey(s.kv, k, nid) nodekey := newKey(s.kv, k, nid)
s.nodes[*nid] = nodekey s.nodes[*nid] = nodekey
if err := s.save(); err != nil { if err := s.save(); err != nil {
jww.FATAL.Panicf("Failed to save nodeKey list for %s: %s", nid, err) jww.FATAL.Panicf("Failed to save nodeKey list for %s: %s", nid, err)
......
...@@ -28,11 +28,11 @@ func newManager(ctx *context, partnerID *id.ID, myPrivKey *cyclic.Int, ...@@ -28,11 +28,11 @@ func newManager(ctx *context, partnerID *id.ID, myPrivKey *cyclic.Int,
m.send = NewSessionBuff(m, "send") m.send = NewSessionBuff(m, "send")
m.receive = NewSessionBuff(m, "receive") m.receive = NewSessionBuff(m, "receive")
sendSession := newSession(m, myPrivKey, partnerPubKey, sendParams, Send) sendSession := newSession(m, myPrivKey, partnerPubKey, sendParams, Send, SessionID{})
m.send.AddSession(sendSession) m.send.AddSession(sendSession)
receiveSession := newSession(m, myPrivKey, partnerPubKey, receiveParams, Receive) receiveSession := newSession(m, myPrivKey, partnerPubKey, receiveParams, Receive, SessionID{})
m.receive.AddSession(receiveSession) m.receive.AddSession(receiveSession)
...@@ -73,12 +73,12 @@ func (m *Manager) GetPartnerID() *id.ID { ...@@ -73,12 +73,12 @@ func (m *Manager) GetPartnerID() *id.ID {
// creates a new receive session using the latest private key this user has sent // creates a new receive session using the latest private key this user has sent
// and the new public key received from the partner. // and the new public key received from the partner.
func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionParams) *Session { func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionParams, trigger SessionID) *Session {
//find your last confirmed private key //find your last confirmed private key
myPrivKey := m.send.GetNewestRekeyableSession().GetMyPrivKey() myPrivKey := m.send.GetNewestRekeyableSession().GetMyPrivKey()
//create the session //create the session
session := newSession(m, myPrivKey, partnerPubKey, params, Receive) session := newSession(m, myPrivKey, partnerPubKey, params, Receive, trigger)
//add the session to the buffer //add the session to the buffer
m.receive.AddSession(session) m.receive.AddSession(session)
...@@ -90,12 +90,12 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionPar ...@@ -90,12 +90,12 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionPar
// partner and a mew private key for the user // partner and a mew private key for the user
// passing in a private key is optional. a private key will be generated if // passing in a private key is optional. a private key will be generated if
// none is passed // none is passed
func (m *Manager) NewSendSession(myPrivKey *cyclic.Int, params SessionParams) *Session { func (m *Manager) NewSendSession(myPrivKey *cyclic.Int, params SessionParams, trigger SessionID) *Session {
//find the latest public key from the other party //find the latest public key from the other party
partnerPubKey := m.receive.GetNewestRekeyableSession().partnerPubKey partnerPubKey := m.receive.GetNewestRekeyableSession().partnerPubKey
//create the session //create the session
session := newSession(m, myPrivKey, partnerPubKey, params, Send) session := newSession(m, myPrivKey, partnerPubKey, params, Send, trigger)
//add the session to the send session buffer and return //add the session to the send session buffer and return
m.send.AddSession(session) m.send.AddSession(session)
......
...@@ -196,6 +196,11 @@ func (s *Session) GetPartnerPubKey() *cyclic.Int { ...@@ -196,6 +196,11 @@ func (s *Session) GetPartnerPubKey() *cyclic.Int {
return s.partnerPubKey.DeepCopy() return s.partnerPubKey.DeepCopy()
} }
func (s *Session) GetTrigger() SessionID {
// no lock is needed because this cannot be edited
return s.trigger
}
//Blake2B hash of base key used for storage //Blake2B hash of base key used for storage
func (s *Session) GetID() SessionID { func (s *Session) GetID() SessionID {
// no lock is needed because this cannot be edited // no lock is needed because this cannot be edited
...@@ -256,6 +261,8 @@ func (s *Session) unmarshal(b []byte) error { ...@@ -256,6 +261,8 @@ func (s *Session) unmarshal(b []byte) error {
s.partnerPubKey = grp.NewIntFromBytes(sd.PartnerPubKey) s.partnerPubKey = grp.NewIntFromBytes(sd.PartnerPubKey)
s.negotiationStatus = Negotiation(sd.Confirmation) s.negotiationStatus = Negotiation(sd.Confirmation)
s.ttl = sd.TTL s.ttl = sd.TTL
copy(s.trigger[:], sd.Trigger)
statesKey := makeStateVectorKey(keyEKVPrefix, s.GetID()) statesKey := makeStateVectorKey(keyEKVPrefix, s.GetID())
s.keyState, err = loadStateVector(s.manager.ctx, statesKey) s.keyState, err = loadStateVector(s.manager.ctx, statesKey)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment