Skip to content
Snippets Groups Projects
Commit f200a63b authored by Malte Bauch's avatar Malte Bauch
Browse files

Change QuantumElements map and make id public

- QuantumElements map[qlElementId]*QuantumElement changed to
  QuantumElements map[uint32]*QuantumElement

- qlID qlElementId changed to QlID uint32 for a QuantumElement
parent 2cd943a8
No related branches found
No related tags found
1 merge request!9First working draft version
......@@ -6,8 +6,8 @@ package kms
import (
"crypto/rand"
"encoding/binary"
"log"
"math/big"
"sync"
"time"
......@@ -24,7 +24,6 @@ type Qkdnkms interface {
RemovePeer(kmsPeerSocket string)
}
type qlElementId uint64
type qlElementLinkID int
// The general emulated KMS
......@@ -32,7 +31,7 @@ type EKMS struct {
kmsName string
kmsUUID uuid.UUID
qleMapMutex sync.Mutex
QuantumElements map[qlElementId]*QuantumElement
QuantumElements map[uint32]*QuantumElement
kmsPeersMutex sync.Mutex
KmsPeers map[string]*kmsPeer
pbETSI.UnimplementedKmsETSIServer
......@@ -48,7 +47,7 @@ type QuantumElementInterface interface {
}*/
type QuantumElement struct {
qlID qlElementId
QlID uint32
QuantumElementLink *quantumlayer.QuantumlayerEmuPRNG // contains information about the quantum links
//key stores go here
keyStoreLocal *kmsKeyStore // the keys this local entity has produced and are ready to use
......@@ -60,7 +59,7 @@ func NewEKMS(kmsName string, kmsUUID uuid.UUID) (newEKMS *EKMS) {
return &EKMS{
kmsName: kmsName,
kmsUUID: kmsUUID,
QuantumElements: make(map[qlElementId]*QuantumElement),
QuantumElements: make(map[uint32]*QuantumElement),
KmsPeers: make(map[string]*kmsPeer),
}
}
......@@ -87,13 +86,13 @@ func (kms *EKMS) AddQuantumElement(kmsUDPAddrr string) *QuantumElement {
// generate a ID for this quantum element that is unique locally
var randError error
qle.qlID, randError = kms.GenerateNewQleID()
qle.QlID, randError = kms.GenerateNewQleID()
if randError != nil {
log.Fatalf("GenerateNewQleID: %s", randError)
return nil
}
kms.QuantumElements[qle.qlID] = &qle
kms.QuantumElements[qle.QlID] = &qle
return &qle
}
......@@ -134,14 +133,18 @@ func (kms *EKMS) GlobalKeyHandler(waitTime time.Duration) error {
// This has a design flaw, as the generated ID is returned to the calling function and used there.
// However, when being used a potential other caller might received the same qlElementId
// TODO/XXX: This would be collision and must be eventually avoided
func (kms *EKMS) GenerateNewQleID() (qlElementId, error) {
func (kms *EKMS) GenerateNewQleID() (uint32, error) {
for { // this needs a condiction to stop!
bigRand, randError := rand.Int(rand.Reader, big.NewInt(100000))
if randError != nil {
return 0, randError
// create buffer for uint32, so reserve 4 bytes
buf := make([]byte, 4)
// fill the buffer from rand
_, err := rand.Read(buf)
if err != nil {
return 0, err
}
propopsedQlElementID := qlElementId(bigRand.Uint64())
propopsedQlElementID := binary.BigEndian.Uint32(buf)
// check if ID is already taken
if kms.QuantumElements[propopsedQlElementID] == nil {
......
......@@ -35,7 +35,7 @@ func (es *etsiServer) ETSIGetQuantumInterfaces(ctx context.Context, in *pb.ETSIK
// Walk through QuantumLayerInterfaces and return their information
for _, qlWorks := range es.handlingEkms.QuantumElements {
qleElement := pb.QuantumElementInfo{
QleID: uint64(qlWorks.qlID),
QleID: uint64(qlWorks.QlID),
UdpAddr: fmt.Sprintf("%s:%d", qlWorks.QuantumElementLink.GetLocalQLPort().IP.String(), qlWorks.QuantumElementLink.GetLocalQLPort().Port),
}
qleList = append(qleList, &qleElement)
......@@ -51,7 +51,7 @@ func (es *etsiServer) ETSIAddKMSPeer(ctx context.Context, in *pb.ETSIKMSPeerRequ
// Check first if KmsLocalQLEId is actually one of ours...
qleID := in.KmsLocalQLEId
servingQLE, _ := es.handlingEkms.QuantumElements[qlElementId(qleID)]
servingQLE, _ := es.handlingEkms.QuantumElements[qleID]
if servingQLE == nil {
//no such element!
err := errors.New(fmt.Sprintf("Unknown local quantum element with ID %d", qleID))
......
......@@ -85,5 +85,5 @@ func (ph *kmsPeer) GetKmsPeerId() uuid.UUID {
}
func (ph *kmsPeer) GetKmsPeerQkdiId() uint32 {
return uint32(ph.servingQLE.qlID)
return uint32(ph.servingQLE.QlID)
}
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v3.19.4
// protoc v3.21.12
// source: kmsetsiproto.proto
package kmsetsiproto
......@@ -263,7 +263,7 @@ type ETSIKMSPeerRequest struct {
unknownFields protoimpl.UnknownFields
KmsPeerSocket string `protobuf:"bytes,1,opt,name=kmsPeerSocket,proto3" json:"kmsPeerSocket,omitempty"`
KmsLocalQLEId uint64 `protobuf:"varint,2,opt,name=kmsLocalQLEId,proto3" json:"kmsLocalQLEId,omitempty"`
KmsLocalQLEId uint32 `protobuf:"varint,2,opt,name=kmsLocalQLEId,proto3" json:"kmsLocalQLEId,omitempty"`
}
func (x *ETSIKMSPeerRequest) Reset() {
......@@ -305,7 +305,7 @@ func (x *ETSIKMSPeerRequest) GetKmsPeerSocket() string {
return ""
}
func (x *ETSIKMSPeerRequest) GetKmsLocalQLEId() uint64 {
func (x *ETSIKMSPeerRequest) GetKmsLocalQLEId() uint32 {
if x != nil {
return x.KmsLocalQLEId
}
......@@ -632,7 +632,7 @@ var file_kmsetsiproto_proto_rawDesc = []byte{
0x6f, 0x63, 0x6b, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6b, 0x6d, 0x73,
0x50, 0x65, 0x65, 0x72, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x6b, 0x6d,
0x73, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x51, 0x4c, 0x45, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x04, 0x52, 0x0d, 0x6b, 0x6d, 0x73, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x51, 0x4c, 0x45, 0x49, 0x64,
0x0d, 0x52, 0x0d, 0x6b, 0x6d, 0x73, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x51, 0x4c, 0x45, 0x49, 0x64,
0x22, 0x34, 0x0a, 0x10, 0x45, 0x54, 0x53, 0x49, 0x4b, 0x4d, 0x53, 0x50, 0x65, 0x65, 0x72, 0x52,
0x65, 0x70, 0x6c, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x6d, 0x73, 0x50, 0x65, 0x65, 0x72, 0x4e,
0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x6d, 0x73, 0x50, 0x65,
......
......@@ -18,7 +18,7 @@ service KmsETSI {
message ETSICapabilitiesRequest {
string myKmsName = 1;
}
// The response message containing the greetings
message ETSICapabilitiesReply {
string peerKmsName = 1;
......@@ -35,13 +35,13 @@ message QuantumElementInfo {
}
message ETSIKMSQuantumInterfaceListReply {
repeated QuantumElementInfo qlElementInfo = 1;
repeated QuantumElementInfo qlElementInfo = 1;
}
message ETSIKMSPeerRequest {
string kmsPeerSocket = 1;
uint64 kmsLocalQLEId = 2;
uint32 kmsLocalQLEId = 2;
}
message ETSIKMSPeerReply {
......@@ -76,6 +76,3 @@ message ETSIGetEncryptKeys256BitReply {
string keyID = 1;
bytes key = 2;
}
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.19.4
// - protoc v3.21.12
// source: kmsetsiproto.proto
package kmsetsiproto
......@@ -26,7 +26,7 @@ type KmsETSIClient interface {
ETSICapabilities(ctx context.Context, in *ETSICapabilitiesRequest, opts ...grpc.CallOption) (*ETSICapabilitiesReply, error)
ETSIGetQuantumInterfaces(ctx context.Context, in *ETSIKMSQuantumInterfaceListRequest, opts ...grpc.CallOption) (*ETSIKMSQuantumInterfaceListReply, error)
ETSIAddKMSPeer(ctx context.Context, in *ETSIKMSPeerRequest, opts ...grpc.CallOption) (*ETSIKMSPeerReply, error)
ETSIRemovEKMSPeer(ctx context.Context, in *ETSIKMSPeerRequest, opts ...grpc.CallOption) (*ETSIKMSPeerReply, error)
ETSIRemoveKMSPeer(ctx context.Context, in *ETSIKMSPeerRequest, opts ...grpc.CallOption) (*ETSIKMSPeerReply, error)
ETSIGetPeerList(ctx context.Context, in *ETSIKMSPeerListRequest, opts ...grpc.CallOption) (*ETSIKMSPeerListReply, error)
ETSIGetEncryptKeys256Bit(ctx context.Context, in *ETSIGetEncryptKeys256BitRequest, opts ...grpc.CallOption) (*ETSIGetEncryptKeys256BitReply, error)
}
......@@ -66,9 +66,9 @@ func (c *kmsETSIClient) ETSIAddKMSPeer(ctx context.Context, in *ETSIKMSPeerReque
return out, nil
}
func (c *kmsETSIClient) ETSIRemovEKMSPeer(ctx context.Context, in *ETSIKMSPeerRequest, opts ...grpc.CallOption) (*ETSIKMSPeerReply, error) {
func (c *kmsETSIClient) ETSIRemoveKMSPeer(ctx context.Context, in *ETSIKMSPeerRequest, opts ...grpc.CallOption) (*ETSIKMSPeerReply, error) {
out := new(ETSIKMSPeerReply)
err := c.cc.Invoke(ctx, "/kmsetsiproto.KmsETSI/ETSIRemovEKMSPeer", in, out, opts...)
err := c.cc.Invoke(ctx, "/kmsetsiproto.KmsETSI/ETSIRemoveKMSPeer", in, out, opts...)
if err != nil {
return nil, err
}
......@@ -101,7 +101,7 @@ type KmsETSIServer interface {
ETSICapabilities(context.Context, *ETSICapabilitiesRequest) (*ETSICapabilitiesReply, error)
ETSIGetQuantumInterfaces(context.Context, *ETSIKMSQuantumInterfaceListRequest) (*ETSIKMSQuantumInterfaceListReply, error)
ETSIAddKMSPeer(context.Context, *ETSIKMSPeerRequest) (*ETSIKMSPeerReply, error)
ETSIRemovEKMSPeer(context.Context, *ETSIKMSPeerRequest) (*ETSIKMSPeerReply, error)
ETSIRemoveKMSPeer(context.Context, *ETSIKMSPeerRequest) (*ETSIKMSPeerReply, error)
ETSIGetPeerList(context.Context, *ETSIKMSPeerListRequest) (*ETSIKMSPeerListReply, error)
ETSIGetEncryptKeys256Bit(context.Context, *ETSIGetEncryptKeys256BitRequest) (*ETSIGetEncryptKeys256BitReply, error)
mustEmbedUnimplementedKmsETSIServer()
......@@ -120,8 +120,8 @@ func (UnimplementedKmsETSIServer) ETSIGetQuantumInterfaces(context.Context, *ETS
func (UnimplementedKmsETSIServer) ETSIAddKMSPeer(context.Context, *ETSIKMSPeerRequest) (*ETSIKMSPeerReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method ETSIAddKMSPeer not implemented")
}
func (UnimplementedKmsETSIServer) ETSIRemovEKMSPeer(context.Context, *ETSIKMSPeerRequest) (*ETSIKMSPeerReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method ETSIRemovEKMSPeer not implemented")
func (UnimplementedKmsETSIServer) ETSIRemoveKMSPeer(context.Context, *ETSIKMSPeerRequest) (*ETSIKMSPeerReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method ETSIRemoveKMSPeer not implemented")
}
func (UnimplementedKmsETSIServer) ETSIGetPeerList(context.Context, *ETSIKMSPeerListRequest) (*ETSIKMSPeerListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method ETSIGetPeerList not implemented")
......@@ -131,10 +131,10 @@ func (UnimplementedKmsETSIServer) ETSIGetEncryptKeys256Bit(context.Context, *ETS
}
func (UnimplementedKmsETSIServer) mustEmbedUnimplementedKmsETSIServer() {}
// UnsafEKMSETSIServer may be embedded to opt out of forward compatibility for this service.
// UnsafeKmsETSIServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to KmsETSIServer will
// result in compilation errors.
type UnsafEKMSETSIServer interface {
type UnsafeKmsETSIServer interface {
mustEmbedUnimplementedKmsETSIServer()
}
......@@ -196,20 +196,20 @@ func _KmsETSI_ETSIAddKMSPeer_Handler(srv interface{}, ctx context.Context, dec f
return interceptor(ctx, in, info, handler)
}
func _KmsETSI_ETSIRemovEKMSPeer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
func _KmsETSI_ETSIRemoveKMSPeer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ETSIKMSPeerRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KmsETSIServer).ETSIRemovEKMSPeer(ctx, in)
return srv.(KmsETSIServer).ETSIRemoveKMSPeer(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/kmsetsiproto.KmsETSI/ETSIRemovEKMSPeer",
FullMethod: "/kmsetsiproto.KmsETSI/ETSIRemoveKMSPeer",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KmsETSIServer).ETSIRemovEKMSPeer(ctx, req.(*ETSIKMSPeerRequest))
return srv.(KmsETSIServer).ETSIRemoveKMSPeer(ctx, req.(*ETSIKMSPeerRequest))
}
return interceptor(ctx, in, info, handler)
}
......@@ -270,8 +270,8 @@ var KmsETSI_ServiceDesc = grpc.ServiceDesc{
Handler: _KmsETSI_ETSIAddKMSPeer_Handler,
},
{
MethodName: "ETSIRemovEKMSPeer",
Handler: _KmsETSI_ETSIRemovEKMSPeer_Handler,
MethodName: "ETSIRemoveKMSPeer",
Handler: _KmsETSI_ETSIRemoveKMSPeer_Handler,
},
{
MethodName: "ETSIGetPeerList",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment