Skip to content
Snippets Groups Projects
Commit f0a9d5f1 authored by Martin Stiemerling's avatar Martin Stiemerling :speech_balloon:
Browse files

inital kmsintercom grcp wrks, need to fill w/ life

parent e6514d91
No related branches found
No related tags found
1 merge request!9First working draft version
...@@ -2,9 +2,6 @@ module code.fbi.h-da.de/m.stiemerling/proto-kms ...@@ -2,9 +2,6 @@ module code.fbi.h-da.de/m.stiemerling/proto-kms
go 1.20 go 1.20
replace code.fbi.h-da.de/m.stiemerling/proto-kms/kms/kmsintercom => ./kmsintercom
require ( require (
github.com/google/uuid v1.3.0 github.com/google/uuid v1.3.0
github.com/golang/protobuf v1.5.3 // indirect github.com/golang/protobuf v1.5.3 // indirect
...@@ -14,5 +11,4 @@ require ( ...@@ -14,5 +11,4 @@ require (
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.1 // indirect google.golang.org/grpc v1.56.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect google.golang.org/protobuf v1.30.0 // indirect
code.fbi.h-da.de/m.stiemerling/proto-kms/kms/kmsintercom v0.0.0
) )
package kms package kms
import ( import (
"crypto/sha256"
"errors" "errors"
"fmt" "fmt"
"log" "log"
...@@ -30,16 +29,14 @@ func (ks *kmsKeyStore) addKey(bulkKeyId int64, keyToadd []byte) { ...@@ -30,16 +29,14 @@ func (ks *kmsKeyStore) addKey(bulkKeyId int64, keyToadd []byte) {
newKeyElement := kmsKSElement{} newKeyElement := kmsKSElement{}
//generate keyID out of bulkKeyId and has of keyToadd //generate keyID out of bulkKeyId and has of keyToadd
h := sha256.New() newKeyElement.keyID = fmt.Sprintf("%x.%x", bulkKeyId, keyToadd)
hasofkey := string(h.Sum(keyToadd[:]))
newKeyElement.keyID = fmt.Sprintf("%x.%x", bulkKeyId, hasofkey)
newKeyElement.key = keyToadd newKeyElement.key = keyToadd
ks.keyStoreMutex.Lock() ks.keyStoreMutex.Lock()
defer ks.keyStoreMutex.Unlock() defer ks.keyStoreMutex.Unlock()
// test for collisions // test for collisions
if _, notThere := ks.keyStore[newKeyElement.keyID]; notThere { 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 return
} }
// ok to add // ok to add
......
...@@ -108,7 +108,7 @@ func (kms *eKMS) GlobalKeyHandler(waitTime time.Duration) error { ...@@ -108,7 +108,7 @@ func (kms *eKMS) GlobalKeyHandler(waitTime time.Duration) error {
} else { } else {
// process bulkKeysRemote // process bulkKeysRemote
log.Printf("%s received %d bytes of key from remote peer", kms.kmsName, bulkKeysRemote.BulkKeyLength) 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) time.Sleep(waitTime)
......
package kmsintercom package kms
//
import ( import (
"context" "context"
...@@ -9,7 +7,7 @@ import ( ...@@ -9,7 +7,7 @@ import (
"log" "log"
"net" "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" "google.golang.org/grpc"
) )
...@@ -18,11 +16,14 @@ var ( ...@@ -18,11 +16,14 @@ var (
) )
type server struct { type server struct {
pb.UnimplementedKmsTalker pb.UnimplementedKmsTalkerServer
} }
func (s *server) Capabilities(ctx context.Context, in *pb.CapabilitiesRequest) (capReply *pb.CapabilitiesReply, err error) { 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() { func StartInterComm() {
...@@ -33,7 +34,7 @@ func StartInterComm() { ...@@ -33,7 +34,7 @@ func StartInterComm() {
log.Fatalf("failed to listen: %v", err) log.Fatalf("failed to listen: %v", err)
} }
s := grpc.NewServer() s := grpc.NewServer()
pb.RegisterKmsTalker(s, &server{}) pb.RegisterKmsTalkerServer(s, &server{})
log.Printf("server listening at %v", lis.Addr()) log.Printf("server listening at %v", lis.Addr())
if err := s.Serve(lis); err != nil { if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err) log.Fatalf("failed to serve: %v", err)
......
// 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
}
syntax = "proto3"; 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 { service KmsTalker {
......
// 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",
}
package kmsintercomproto
package main 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 ( import (
"flag" "flag"
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"time" "time"
"code.fbi.h-da.de/m.stiemerling/proto-kms/kms" "code.fbi.h-da.de/m.stiemerling/proto-kms/kms"
"code.fbi.h-da.de/m.stiemerling/proto-kms/kmsintercom"
"github.com/google/uuid" "github.com/google/uuid"
) )
...@@ -46,7 +45,7 @@ func main() { ...@@ -46,7 +45,7 @@ func main() {
log.Println("Welcome to the proto-kms called: ", ql1Name) log.Println("Welcome to the proto-kms called: ", ql1Name)
go kmsintercom.StartInterComm() go kms.StartInterComm()
if selfTesting == true { if selfTesting == true {
log.Printf("%s in self-testing mode", ql1Name) log.Printf("%s in self-testing mode", ql1Name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment