diff --git a/cmixproto/types.pb.go b/cmixproto/types.pb.go index d1cb16dcb305fc09a49da1002e2d909f7d40eff6..bfd3993996f5e065b82d61c18b785904f598ebdb 100644 --- a/cmixproto/types.pb.go +++ b/cmixproto/types.pb.go @@ -151,28 +151,90 @@ func (Type) EnumDescriptor() ([]byte, []int) { 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_rawDesc = []byte{ 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, - 0x07, 0x4e, 0x4f, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x45, - 0x58, 0x54, 0x5f, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, - 0x55, 0x44, 0x42, 0x5f, 0x50, 0x55, 0x53, 0x48, 0x5f, 0x4b, 0x45, 0x59, 0x10, 0x0a, 0x12, 0x19, - 0x0a, 0x15, 0x55, 0x44, 0x42, 0x5f, 0x50, 0x55, 0x53, 0x48, 0x5f, 0x4b, 0x45, 0x59, 0x5f, 0x52, - 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x0b, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x44, 0x42, - 0x5f, 0x47, 0x45, 0x54, 0x5f, 0x4b, 0x45, 0x59, 0x10, 0x0c, 0x12, 0x18, 0x0a, 0x14, 0x55, 0x44, - 0x42, 0x5f, 0x47, 0x45, 0x54, 0x5f, 0x4b, 0x45, 0x59, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, - 0x53, 0x45, 0x10, 0x0d, 0x12, 0x10, 0x0a, 0x0c, 0x55, 0x44, 0x42, 0x5f, 0x52, 0x45, 0x47, 0x49, - 0x53, 0x54, 0x45, 0x52, 0x10, 0x0e, 0x12, 0x19, 0x0a, 0x15, 0x55, 0x44, 0x42, 0x5f, 0x52, 0x45, - 0x47, 0x49, 0x53, 0x54, 0x45, 0x52, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, - 0x0f, 0x12, 0x0e, 0x0a, 0x0a, 0x55, 0x44, 0x42, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x10, - 0x10, 0x12, 0x17, 0x0a, 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, + 0x61, 0x72, 0x73, 0x65, 0x22, 0x4a, 0x0a, 0x0c, 0x52, 0x65, 0x6b, 0x65, 0x79, 0x54, 0x72, 0x69, + 0x67, 0x67, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, + 0x65, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x44, + 0x2a, 0xf9, 0x01, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x4f, 0x5f, + 0x54, 0x59, 0x50, 0x45, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x45, 0x58, 0x54, 0x5f, 0x4d, + 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x55, 0x44, 0x42, 0x5f, + 0x50, 0x55, 0x53, 0x48, 0x5f, 0x4b, 0x45, 0x59, 0x10, 0x0a, 0x12, 0x19, 0x0a, 0x15, 0x55, 0x44, + 0x42, 0x5f, 0x50, 0x55, 0x53, 0x48, 0x5f, 0x4b, 0x45, 0x59, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, + 0x4e, 0x53, 0x45, 0x10, 0x0b, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x44, 0x42, 0x5f, 0x47, 0x45, 0x54, + 0x5f, 0x4b, 0x45, 0x59, 0x10, 0x0c, 0x12, 0x18, 0x0a, 0x14, 0x55, 0x44, 0x42, 0x5f, 0x47, 0x45, + 0x54, 0x5f, 0x4b, 0x45, 0x59, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x0d, + 0x12, 0x10, 0x0a, 0x0c, 0x55, 0x44, 0x42, 0x5f, 0x52, 0x45, 0x47, 0x49, 0x53, 0x54, 0x45, 0x52, + 0x10, 0x0e, 0x12, 0x19, 0x0a, 0x15, 0x55, 0x44, 0x42, 0x5f, 0x52, 0x45, 0x47, 0x49, 0x53, 0x54, + 0x45, 0x52, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x0f, 0x12, 0x0e, 0x0a, + 0x0a, 0x55, 0x44, 0x42, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x10, 0x10, 0x12, 0x17, 0x0a, + 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 ( @@ -188,8 +250,10 @@ func file_types_proto_rawDescGZIP() []byte { } var file_types_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_types_proto_msgTypes = make([]protoimpl.MessageInfo, 1) 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{ 0, // [0:0] is the sub-list for method output_type @@ -204,19 +268,34 @@ func file_types_proto_init() { if File_types_proto != nil { 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{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_types_proto_rawDesc, NumEnums: 1, - NumMessages: 0, + NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_types_proto_goTypes, DependencyIndexes: file_types_proto_depIdxs, EnumInfos: file_types_proto_enumTypes, + MessageInfos: file_types_proto_msgTypes, }.Build() File_types_proto = out.File file_types_proto_rawDesc = nil diff --git a/cmixproto/types.proto b/cmixproto/types.proto index d1148aa59325349ab0befca1399d654b7fc20834..57b5796e13641843d454bd8179882535bc87f0db 100644 --- a/cmixproto/types.proto +++ b/cmixproto/types.proto @@ -109,6 +109,6 @@ enum Type { message RekeyTrigger { // PublicKey used in the registration bytes publicKey = 1; + // ID of the session used to create this session bytes SessionID = 2; - bool newSession = 3; } diff --git a/context/message.go b/context/message/message.go similarity index 89% rename from context/message.go rename to context/message/message.go index c0c9315a1759f314d022f7f1402f27ff2c00dc52..604c5c162664dcfd6c6c93e865aa886d3faf9074 100644 --- a/context/message.go +++ b/context/message/message.go @@ -1,4 +1,4 @@ -package context +package message import "gitlab.com/xx_network/primitives/id" diff --git a/context/networkManager.go b/context/networkManager.go index 595abefb364f0aa6f631600f41b721ec8b5da69d..2287265152da53b01f6af7c6323da8f418db5e14 100644 --- a/context/networkManager.go +++ b/context/networkManager.go @@ -1,6 +1,7 @@ package context import ( + "gitlab.com/elixxir/client/context/message" "gitlab.com/elixxir/client/context/params" "gitlab.com/elixxir/client/context/stoppable" "gitlab.com/elixxir/comms/network" @@ -9,8 +10,8 @@ import ( ) type NetworkManager interface { - SendE2E(m Message, e2eP params.E2E, cmixP params.CMIX) ([]id.Round, error) - SendUnsafe(m Message) ([]id.Round, error) + SendE2E(m message.Message, e2eP params.E2E, cmixP params.CMIX) ([]id.Round, error) + SendUnsafe(m message.Message) ([]id.Round, error) SendCMIX(message format.Message) (id.Round, error) GetInstance() *network.Instance Stoppable() stoppable.Stoppable diff --git a/io/keyExchange/rekey.go b/io/keyExchange/rekey.go index 45092934626f433f1b76ea395062cd90d25d028c..ea1dfcd8d96682032429d1fd6f95bc9aa3eafa28 100644 --- a/io/keyExchange/rekey.go +++ b/io/keyExchange/rekey.go @@ -1,15 +1,18 @@ package keyExchange import ( + "github.com/golang/protobuf/proto" "github.com/pkg/errors" + jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/cmixproto" "gitlab.com/elixxir/client/context" + "gitlab.com/elixxir/client/context/message" "gitlab.com/elixxir/client/context/params" "gitlab.com/elixxir/client/context/utility" "gitlab.com/elixxir/client/storage/e2e" ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/primitives/states" - jww "github.com/spf13/jwalterweatherman" "time" ) @@ -32,7 +35,8 @@ func trigger(ctx *context.Context, manager *e2e.Manager, session *e2e.Session) { // replace itself, then create the session case e2e.NewSessionTriggered: //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 session.SetNegotiationStatus(e2e.NewSessionCreated) // If the session has not successfully negotiated, redo its negotiation @@ -60,11 +64,23 @@ func negotiate(ctx *context.Context, session *e2e.Session) error { pubKey := diffieHellman.GeneratePublicKey(session.GetMyPrivKey(), 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 - m := context.Message{ + m := message.Message{ Recipient: session.GetPartner(), - Payload: pubKey.Bytes(), - MessageType: 42, + Payload: payload, + MessageType: int32(cmixproto.Type_REKEY_TRIGGER), } //send the message under the key exchange diff --git a/storage/cmix/store.go b/storage/cmix/store.go index 0188b2e1160f5697affd782020daf965813e8f8a..f3f6e904b95f92310b1d20fc90d3b0c9b16924a7 100644 --- a/storage/cmix/store.go +++ b/storage/cmix/store.go @@ -102,7 +102,6 @@ func (s *Store) Add(nid *id.ID, k *cyclic.Int) { nodekey := newKey(s.kv, k, nid) - s.nodes[*nid] = nodekey if err := s.save(); err != nil { jww.FATAL.Panicf("Failed to save nodeKey list for %s: %s", nid, err) diff --git a/storage/e2e/manager.go b/storage/e2e/manager.go index 26a437d9a1fc98ff2f907555d97feb3fe2042175..a0938315b443c74d1f103212876a31914497b59c 100644 --- a/storage/e2e/manager.go +++ b/storage/e2e/manager.go @@ -28,11 +28,11 @@ func newManager(ctx *context, partnerID *id.ID, myPrivKey *cyclic.Int, m.send = NewSessionBuff(m, "send") m.receive = NewSessionBuff(m, "receive") - sendSession := newSession(m, myPrivKey, partnerPubKey, sendParams, Send) + sendSession := newSession(m, myPrivKey, partnerPubKey, sendParams, Send, SessionID{}) m.send.AddSession(sendSession) - receiveSession := newSession(m, myPrivKey, partnerPubKey, receiveParams, Receive) + receiveSession := newSession(m, myPrivKey, partnerPubKey, receiveParams, Receive, SessionID{}) m.receive.AddSession(receiveSession) @@ -73,12 +73,12 @@ func (m *Manager) GetPartnerID() *id.ID { // 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, params SessionParams) *Session { +func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionParams, trigger SessionID) *Session { //find your last confirmed private key myPrivKey := m.send.GetNewestRekeyableSession().GetMyPrivKey() //create the session - session := newSession(m, myPrivKey, partnerPubKey, params, Receive) + session := newSession(m, myPrivKey, partnerPubKey, params, Receive, trigger) //add the session to the buffer m.receive.AddSession(session) @@ -90,12 +90,12 @@ func (m *Manager) NewReceiveSession(partnerPubKey *cyclic.Int, params SessionPar // partner and a mew private key for the user // passing in a private key is optional. a private key will be generated if // 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 partnerPubKey := m.receive.GetNewestRekeyableSession().partnerPubKey //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 m.send.AddSession(session) diff --git a/storage/e2e/session.go b/storage/e2e/session.go index 4da6aee8968e005d6be1710de1dcafb4f47f8fab..f5d313170b05f75a1f25c69832989daada34bf64 100644 --- a/storage/e2e/session.go +++ b/storage/e2e/session.go @@ -196,6 +196,11 @@ func (s *Session) GetPartnerPubKey() *cyclic.Int { 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 func (s *Session) GetID() SessionID { // no lock is needed because this cannot be edited @@ -256,6 +261,8 @@ func (s *Session) unmarshal(b []byte) error { s.partnerPubKey = grp.NewIntFromBytes(sd.PartnerPubKey) s.negotiationStatus = Negotiation(sd.Confirmation) s.ttl = sd.TTL + copy(s.trigger[:], sd.Trigger) + statesKey := makeStateVectorKey(keyEKVPrefix, s.GetID()) s.keyState, err = loadStateVector(s.manager.ctx, statesKey)