diff --git a/go.mod b/go.mod index 07ea101785387bf80756f5c08e4d1a62e638f872..72b5dad0526be8e5c93812cd490c05003b30a98d 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,6 @@ module code.fbi.h-da.de/m.stiemerling/proto-kms go 1.20 -replace code.fbi.h-da.de/m.stiemerling/proto-kms/kms/kmsintercom => ./kmsintercom - - require ( github.com/google/uuid v1.3.0 github.com/golang/protobuf v1.5.3 // indirect @@ -14,5 +11,4 @@ require ( google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect google.golang.org/grpc v1.56.1 // indirect google.golang.org/protobuf v1.30.0 // indirect - code.fbi.h-da.de/m.stiemerling/proto-kms/kms/kmsintercom v0.0.0 ) diff --git a/kms/kms-keystore.go b/kms/kms-keystore.go index 56d3f74b324bc40146f3a5af94a393f9ab53e451..db478e1da8b949a7a6c8d597dbd365e4d4fdb767 100644 --- a/kms/kms-keystore.go +++ b/kms/kms-keystore.go @@ -1,7 +1,6 @@ package kms import ( - "crypto/sha256" "errors" "fmt" "log" @@ -30,16 +29,14 @@ func (ks *kmsKeyStore) addKey(bulkKeyId int64, keyToadd []byte) { newKeyElement := kmsKSElement{} //generate keyID out of bulkKeyId and has of keyToadd - h := sha256.New() - hasofkey := string(h.Sum(keyToadd[:])) - newKeyElement.keyID = fmt.Sprintf("%x.%x", bulkKeyId, hasofkey) + newKeyElement.keyID = fmt.Sprintf("%x.%x", bulkKeyId, keyToadd) newKeyElement.key = keyToadd ks.keyStoreMutex.Lock() defer ks.keyStoreMutex.Unlock() // test for collisions if _, notThere := ks.keyStore[newKeyElement.keyID]; notThere { - log.Fatalf("Whop: addKey collission of key id %s for bulkKeyID %d", newKeyElement.keyID, bulkKeyId) + log.Printf("Whop: addKey collission of key id %s for bulkKeyID %d", newKeyElement.keyID, bulkKeyId) return } // ok to add diff --git a/kms/kms.go b/kms/kms.go index 68a85dd32e448d66274837b261324f81feb6af2c..90d3f558bafc6e1eb57bbb2672c8aa6839805ea7 100644 --- a/kms/kms.go +++ b/kms/kms.go @@ -108,7 +108,7 @@ func (kms *eKMS) GlobalKeyHandler(waitTime time.Duration) error { } else { // process bulkKeysRemote log.Printf("%s received %d bytes of key from remote peer", kms.kmsName, bulkKeysRemote.BulkKeyLength) - kms.QuantumElements[currentQE].keyStoreRemote.KeyChopper256Bit(&bulkKeysLocal) + kms.QuantumElements[currentQE].keyStoreRemote.KeyChopper256Bit(&bulkKeysRemote) } } time.Sleep(waitTime) diff --git a/kmsintercom/kmsintercom.go b/kms/kmsintercom.go similarity index 69% rename from kmsintercom/kmsintercom.go rename to kms/kmsintercom.go index 99078f2383df87123f49aed89fcdf9d4782dcdc3..4520079ad2504b825a781b777294ba561c4ef6c9 100644 --- a/kmsintercom/kmsintercom.go +++ b/kms/kmsintercom.go @@ -1,6 +1,4 @@ -package kmsintercom - -// +package kms import ( "context" @@ -9,7 +7,7 @@ import ( "log" "net" - pb "code.fbi.h-da.de/m.stiemerling/proto-kms/kms/kmsintercom" + pb "code.fbi.h-da.de/m.stiemerling/proto-kms/kmsintercomproto" "google.golang.org/grpc" ) @@ -18,11 +16,14 @@ var ( ) type server struct { - pb.UnimplementedKmsTalker + pb.UnimplementedKmsTalkerServer } func (s *server) Capabilities(ctx context.Context, in *pb.CapabilitiesRequest) (capReply *pb.CapabilitiesReply, err error) { - log.Printf("Received: %v", in.GetName()) + log.Printf("Received: %v", in.GetMyKmsName()) + return &pb.CapabilitiesReply{ + PeerKmsName: "whatever", + }, nil } func StartInterComm() { @@ -33,7 +34,7 @@ func StartInterComm() { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() - pb.RegisterKmsTalker(s, &server{}) + pb.RegisterKmsTalkerServer(s, &server{}) log.Printf("server listening at %v", lis.Addr()) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) diff --git a/kmsintercomproto/kmsintercom.pb.go b/kmsintercomproto/kmsintercom.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..8b7e51eebfa0da8630d2d5065fbb93814c384e31 --- /dev/null +++ b/kmsintercomproto/kmsintercom.pb.go @@ -0,0 +1,221 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.19.4 +// source: kmsintercom.proto + +package kmsintercomproto + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// The request message containing the user's name. +type CapabilitiesRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + MyKmsName string `protobuf:"bytes,1,opt,name=myKmsName,proto3" json:"myKmsName,omitempty"` +} + +func (x *CapabilitiesRequest) Reset() { + *x = CapabilitiesRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_kmsintercom_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CapabilitiesRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CapabilitiesRequest) ProtoMessage() {} + +func (x *CapabilitiesRequest) ProtoReflect() protoreflect.Message { + mi := &file_kmsintercom_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 CapabilitiesRequest.ProtoReflect.Descriptor instead. +func (*CapabilitiesRequest) Descriptor() ([]byte, []int) { + return file_kmsintercom_proto_rawDescGZIP(), []int{0} +} + +func (x *CapabilitiesRequest) GetMyKmsName() string { + if x != nil { + return x.MyKmsName + } + return "" +} + +// The response message containing the greetings +type CapabilitiesReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PeerKmsName string `protobuf:"bytes,1,opt,name=peerKmsName,proto3" json:"peerKmsName,omitempty"` +} + +func (x *CapabilitiesReply) Reset() { + *x = CapabilitiesReply{} + if protoimpl.UnsafeEnabled { + mi := &file_kmsintercom_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CapabilitiesReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CapabilitiesReply) ProtoMessage() {} + +func (x *CapabilitiesReply) ProtoReflect() protoreflect.Message { + mi := &file_kmsintercom_proto_msgTypes[1] + 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 CapabilitiesReply.ProtoReflect.Descriptor instead. +func (*CapabilitiesReply) Descriptor() ([]byte, []int) { + return file_kmsintercom_proto_rawDescGZIP(), []int{1} +} + +func (x *CapabilitiesReply) GetPeerKmsName() string { + if x != nil { + return x.PeerKmsName + } + return "" +} + +var File_kmsintercom_proto protoreflect.FileDescriptor + +var file_kmsintercom_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x6b, 0x6d, 0x73, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x6b, 0x6d, 0x73, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x63, 0x6f, 0x6d, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x33, 0x0a, 0x13, 0x43, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, + 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x6d, 0x79, 0x4b, 0x6d, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x6d, 0x79, 0x4b, 0x6d, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x35, 0x0a, 0x11, 0x43, 0x61, + 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, + 0x20, 0x0a, 0x0b, 0x70, 0x65, 0x65, 0x72, 0x4b, 0x6d, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x65, 0x65, 0x72, 0x4b, 0x6d, 0x73, 0x4e, 0x61, 0x6d, + 0x65, 0x32, 0x69, 0x0a, 0x09, 0x4b, 0x6d, 0x73, 0x54, 0x61, 0x6c, 0x6b, 0x65, 0x72, 0x12, 0x5c, + 0x0a, 0x0c, 0x43, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x12, 0x25, + 0x2e, 0x6b, 0x6d, 0x73, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2e, 0x43, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6b, 0x6d, 0x73, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, + 0x69, 0x74, 0x69, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x3b, 0x5a, 0x39, + 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x66, 0x62, 0x69, 0x2e, 0x68, 0x2d, 0x64, 0x61, 0x2e, 0x64, 0x65, + 0x2f, 0x6d, 0x2e, 0x73, 0x74, 0x69, 0x65, 0x6d, 0x65, 0x72, 0x6c, 0x69, 0x6e, 0x67, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2d, 0x6b, 0x6d, 0x73, 0x2f, 0x6b, 0x6d, 0x73, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, +} + +var ( + file_kmsintercom_proto_rawDescOnce sync.Once + file_kmsintercom_proto_rawDescData = file_kmsintercom_proto_rawDesc +) + +func file_kmsintercom_proto_rawDescGZIP() []byte { + file_kmsintercom_proto_rawDescOnce.Do(func() { + file_kmsintercom_proto_rawDescData = protoimpl.X.CompressGZIP(file_kmsintercom_proto_rawDescData) + }) + return file_kmsintercom_proto_rawDescData +} + +var file_kmsintercom_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_kmsintercom_proto_goTypes = []interface{}{ + (*CapabilitiesRequest)(nil), // 0: kmsintercomproto.CapabilitiesRequest + (*CapabilitiesReply)(nil), // 1: kmsintercomproto.CapabilitiesReply +} +var file_kmsintercom_proto_depIdxs = []int32{ + 0, // 0: kmsintercomproto.KmsTalker.Capabilities:input_type -> kmsintercomproto.CapabilitiesRequest + 1, // 1: kmsintercomproto.KmsTalker.Capabilities:output_type -> kmsintercomproto.CapabilitiesReply + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_kmsintercom_proto_init() } +func file_kmsintercom_proto_init() { + if File_kmsintercom_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_kmsintercom_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CapabilitiesRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_kmsintercom_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CapabilitiesReply); 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_kmsintercom_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_kmsintercom_proto_goTypes, + DependencyIndexes: file_kmsintercom_proto_depIdxs, + MessageInfos: file_kmsintercom_proto_msgTypes, + }.Build() + File_kmsintercom_proto = out.File + file_kmsintercom_proto_rawDesc = nil + file_kmsintercom_proto_goTypes = nil + file_kmsintercom_proto_depIdxs = nil +} diff --git a/kmsintercom/kmsintercom.proto b/kmsintercomproto/kmsintercom.proto similarity index 90% rename from kmsintercom/kmsintercom.proto rename to kmsintercomproto/kmsintercom.proto index a6dbdd7c9a86f1ee911f84a21375b7794639b87f..00b7d575d027abe09f18d2ddc58c0a3c66ea71cd 100644 --- a/kmsintercom/kmsintercom.proto +++ b/kmsintercomproto/kmsintercom.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -option go_package = "code.fbi.h-da.de/m.stiemerling/proto-kms/kmsintercom"; +option go_package = "code.fbi.h-da.de/m.stiemerling/proto-kms/kmsintercomproto"; -package kmsintercom; +package kmsintercomproto; service KmsTalker { diff --git a/kmsintercomproto/kmsintercom_grpc.pb.go b/kmsintercomproto/kmsintercom_grpc.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..1cf2527865b67b39385549dac9495cc229cd3a31 --- /dev/null +++ b/kmsintercomproto/kmsintercom_grpc.pb.go @@ -0,0 +1,107 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.4 +// source: kmsintercom.proto + +package kmsintercomproto + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// KmsTalkerClient is the client API for KmsTalker service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type KmsTalkerClient interface { + // Sends a greeting + Capabilities(ctx context.Context, in *CapabilitiesRequest, opts ...grpc.CallOption) (*CapabilitiesReply, error) +} + +type kmsTalkerClient struct { + cc grpc.ClientConnInterface +} + +func NewKmsTalkerClient(cc grpc.ClientConnInterface) KmsTalkerClient { + return &kmsTalkerClient{cc} +} + +func (c *kmsTalkerClient) Capabilities(ctx context.Context, in *CapabilitiesRequest, opts ...grpc.CallOption) (*CapabilitiesReply, error) { + out := new(CapabilitiesReply) + err := c.cc.Invoke(ctx, "/kmsintercomproto.KmsTalker/Capabilities", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// KmsTalkerServer is the server API for KmsTalker service. +// All implementations must embed UnimplementedKmsTalkerServer +// for forward compatibility +type KmsTalkerServer interface { + // Sends a greeting + Capabilities(context.Context, *CapabilitiesRequest) (*CapabilitiesReply, error) + mustEmbedUnimplementedKmsTalkerServer() +} + +// UnimplementedKmsTalkerServer must be embedded to have forward compatible implementations. +type UnimplementedKmsTalkerServer struct { +} + +func (UnimplementedKmsTalkerServer) Capabilities(context.Context, *CapabilitiesRequest) (*CapabilitiesReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Capabilities not implemented") +} +func (UnimplementedKmsTalkerServer) mustEmbedUnimplementedKmsTalkerServer() {} + +// UnsafeKmsTalkerServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to KmsTalkerServer will +// result in compilation errors. +type UnsafeKmsTalkerServer interface { + mustEmbedUnimplementedKmsTalkerServer() +} + +func RegisterKmsTalkerServer(s grpc.ServiceRegistrar, srv KmsTalkerServer) { + s.RegisterService(&KmsTalker_ServiceDesc, srv) +} + +func _KmsTalker_Capabilities_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CapabilitiesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(KmsTalkerServer).Capabilities(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/kmsintercomproto.KmsTalker/Capabilities", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(KmsTalkerServer).Capabilities(ctx, req.(*CapabilitiesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// KmsTalker_ServiceDesc is the grpc.ServiceDesc for KmsTalker service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var KmsTalker_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "kmsintercomproto.KmsTalker", + HandlerType: (*KmsTalkerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Capabilities", + Handler: _KmsTalker_Capabilities_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "kmsintercom.proto", +} diff --git a/kmsintercomproto/kmsintercomproto.go b/kmsintercomproto/kmsintercomproto.go new file mode 100644 index 0000000000000000000000000000000000000000..2d9c99146f02dab97031e6a09f6f22f54a4d8d5f --- /dev/null +++ b/kmsintercomproto/kmsintercomproto.go @@ -0,0 +1 @@ +package kmsintercomproto diff --git a/main.go b/main.go index 3142cb65f0b29d354f4f399e8b29920cf0e7a6f4..ca4dd1e1882eafc382780b30ae73bf7f906ca5f9 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ package main -// go generate protoc --proto_path=kmsintercom --go_out=kmsintercom --go_opt=paths=source_relative kmsintercom.proto +// go generate protoc --proto_path=kmsintercomproto --go_out=kmsintercomproto --go_opt=paths=source_relative --go-grpc_out=kmsintercomproto --go-grpc_opt=paths=source_relative kmsintercom.proto import ( "flag" @@ -9,7 +9,6 @@ import ( "time" "code.fbi.h-da.de/m.stiemerling/proto-kms/kms" - "code.fbi.h-da.de/m.stiemerling/proto-kms/kmsintercom" "github.com/google/uuid" ) @@ -46,7 +45,7 @@ func main() { log.Println("Welcome to the proto-kms called: ", ql1Name) - go kmsintercom.StartInterComm() + go kms.StartInterComm() if selfTesting == true { log.Printf("%s in self-testing mode", ql1Name)