From 6ef5252fcf343b0d7404702185ef61c111be609c Mon Sep 17 00:00:00 2001 From: Fabian Seidl <fabian.seidl@h-da.de> Date: Tue, 28 May 2024 11:03:47 +0000 Subject: [PATCH] Dealing with minor TODOs See merge request danet/quant!133 --- goKMS/gnmiHandlers/kms/assignForwardingHandler.go | 5 ++--- goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go | 11 +++++------ goKMS/kms/crypto/crypto.go | 3 +-- goKMS/kms/event/bus.go | 1 - goKMS/kms/kms.go | 8 ++++++-- goKMS/kms/kmsintercom.go | 4 +++- goKMS/kms/peers/peers.go | 5 ++--- goKMS/kms/peers/qmodule.go | 1 - 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/goKMS/gnmiHandlers/kms/assignForwardingHandler.go b/goKMS/gnmiHandlers/kms/assignForwardingHandler.go index 6f8d4682..d5edbbd6 100644 --- a/goKMS/gnmiHandlers/kms/assignForwardingHandler.go +++ b/goKMS/gnmiHandlers/kms/assignForwardingHandler.go @@ -52,7 +52,6 @@ func (yh *AssignForwardingHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnmi var nextHopString string var prevHopString string - var initiatingKmsAddressString string if nextHop != nil { nextHopString = nextHop.GetNodeId() @@ -73,10 +72,10 @@ func (yh *AssignForwardingHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnmi log.Error("initiatingKmsAddress must have either an IP address or a hostname") return fmt.Errorf("initiatingKmsAddress must have either an IP address or a hostname") } - initiatingKmsAddressString = fmt.Sprintf("%s:%d", addressPrefix, initiatingKmsAddress.GetPort()) + initKMS = &kms.RemoteKMS{ Id: initiatingKmsAddress.GetNodeId(), - Address: initiatingKmsAddressString, + Address: addressPrefix, Port: initiatingKmsAddress.GetPort(), } } diff --git a/goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go b/goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go index 6572621a..e8a09b4c 100644 --- a/goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go +++ b/goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go @@ -2,7 +2,6 @@ package kmsHandler import ( "fmt" - "strings" "code.fbi.h-da.de/danet/gnmi-target/handler" "code.fbi.h-da.de/danet/quant/goKMS/kms" @@ -106,7 +105,7 @@ func (yh *KeyRoutingSessionHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnm var nextHopString string var prevHopString string - var initiatingKmsAddressString string + if nextHop != nil { nextHopString = nextHop.GetNodeId() } @@ -126,10 +125,10 @@ func (yh *KeyRoutingSessionHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnm log.Error("initiatingKmsAddress must have either an IP address or a hostname") return fmt.Errorf("initiatingKmsAddress must have either an IP address or a hostname") } - initiatingKmsAddressString = fmt.Sprintf("%s:%d", addressPrefix, initiatingKmsAddress.GetPort()) + initKMS = &kms.RemoteKMS{ Id: initiatingKmsAddress.GetNodeId(), - Address: initiatingKmsAddressString, + Address: addressPrefix, Port: initiatingKmsAddress.GetPort(), } } @@ -181,9 +180,9 @@ func (yh *KeyRoutingSessionHandler) updateOrCreateKeyRoutingSessions(kms *kms.KM if route.RemoteKMS != nil { confTempRoutingSessionInitAddress := confTempRoutingSession.GetOrCreateInitiatingKmsAddress() if route.RemoteKMS.Address != "" { - confTempRoutingSessionInitAddress.IpAddress = ygot.String(strings.Split(route.RemoteKMS.Address, ":")[0]) // TODO: maybe split address in remote kms and not in one string? + confTempRoutingSessionInitAddress.IpAddress = ygot.String(route.RemoteKMS.Address) confTempRoutingSessionInitAddress.Port = ygot.Uint16(route.RemoteKMS.Port) - confTempRoutingSessionInitAddress.Hostname = ygot.String(strings.Split(route.RemoteKMS.Address, ":")[0]) // TODO: get real hostname here + confTempRoutingSessionInitAddress.Hostname = ygot.String(route.RemoteKMS.Address) // TODO: get real hostname here } if route.RemoteKMS.Id != "" { confTempRoutingSessionInitAddress.NodeId = ygot.String(route.RemoteKMS.Id) diff --git a/goKMS/kms/crypto/crypto.go b/goKMS/kms/crypto/crypto.go index 40667457..1fe6c939 100644 --- a/goKMS/kms/crypto/crypto.go +++ b/goKMS/kms/crypto/crypto.go @@ -46,8 +46,7 @@ func (a *AES) Decrypt(nonce, ciphertext []byte, key []byte) ([]byte, error) { return nil, err } - // TODO: Not sure if we should assume that we get non standard nonce sizes - // here. Normally it would be 12 bytes. + // Note: This works under the assumption of every other implementation using the commonly used nonce size of 12 bytes. gcm, err := cipher.NewGCM(c) if err != nil { return nil, err diff --git a/goKMS/kms/event/bus.go b/goKMS/kms/event/bus.go index a1c297ba..301b883b 100644 --- a/goKMS/kms/event/bus.go +++ b/goKMS/kms/event/bus.go @@ -30,7 +30,6 @@ func (b *EventBus) Subscribe(topic Topic) (<-chan Event, error) { return newSubChan, nil } -// TODO: check the functionality of this method. func (b *EventBus) Publish(event Event) error { subs, ok := b.subscribers[event.Topic()] if !ok { diff --git a/goKMS/kms/kms.go b/goKMS/kms/kms.go index d9c64995..44220445 100644 --- a/goKMS/kms/kms.go +++ b/goKMS/kms/kms.go @@ -375,7 +375,9 @@ func (kms *KMS) AssignForwardingRoute(pId, pHop, nHop string, remoteKMS *RemoteK log.Debug("Current PKSTORE: ", kms.PKStore) kms.PKStoreMutex.Unlock() - err = tmpRoute.Next.SendInitialPayloadBasedOnGRPCClient(pk, tmpRoute.PathId, processId, kms.kmsUUID.String(), remoteKMS.Address) + remoteKMSAdrress := fmt.Sprintf("%s:%d", remoteKMS.Address, remoteKMS.Port) + + err = tmpRoute.Next.SendInitialPayloadBasedOnGRPCClient(pk, tmpRoute.PathId, processId, kms.kmsUUID.String(), remoteKMSAdrress) if err != nil { log.Error(err) return err @@ -460,7 +462,9 @@ func (kms *KMS) GenerateAndSendKSAKey(remoteKMSId string, pathId uuid.UUID, requ akmsKSAKeys[i] = *akmsKSAKey } - err = kms.sendKSAKeysToPlatformKmsPeer(remoteKMS.Address, platformKey.Id.String(), requestID, ksaKeys) + remoteKMSAdrress := fmt.Sprintf("%s:%d", remoteKMS.Address, remoteKMS.Port) + + err = kms.sendKSAKeysToPlatformKmsPeer(remoteKMSAdrress, platformKey.Id.String(), requestID, ksaKeys) if err != nil { log.Error(err) return err diff --git a/goKMS/kms/kmsintercom.go b/goKMS/kms/kmsintercom.go index 73536849..42eb8afc 100644 --- a/goKMS/kms/kmsintercom.go +++ b/goKMS/kms/kmsintercom.go @@ -262,7 +262,9 @@ func (s *kmsTalkerServer) KeyForwarding(ctx context.Context, in *pb.KeyForwardin s.storeReceivedPlatformKey(route.RemoteKMS.Id, in.GetProcessId(), keyID, decryptedKey) - err = s.sendAcknowledgeKeyForwarding(ctx, route.RemoteKMS.Address, in.PathId, in.ProcessId, in.GetKey().GetId()) + remoteKMSAdrress := fmt.Sprintf("%s:%d", route.RemoteKMS.Address, route.RemoteKMS.Port) + + err = s.sendAcknowledgeKeyForwarding(ctx, remoteKMSAdrress, in.PathId, in.ProcessId, in.GetKey().GetId()) if err != nil { return nil, err } diff --git a/goKMS/kms/peers/peers.go b/goKMS/kms/peers/peers.go index fbdfddca..4184cc5b 100644 --- a/goKMS/kms/peers/peers.go +++ b/goKMS/kms/peers/peers.go @@ -79,9 +79,8 @@ func NewKmsPeer(peerKmsId string, servQM QuantumModule, tcpSocketStr string, int // We need multiple peer clients! peerClient: client, // TODO: change this, only for demo purposes - peerStatus: KmsPeerUp, - peerKmsId: peerKmsIdUUID, - // TODO: move this into a config + peerStatus: KmsPeerUp, + peerKmsId: peerKmsIdUUID, interComAddr: interComAddr, // NOTE a peer could have multiple quantum modules servingQuantumModul: servQM, diff --git a/goKMS/kms/peers/qmodule.go b/goKMS/kms/peers/qmodule.go index 8af73685..5d140f3e 100644 --- a/goKMS/kms/peers/qmodule.go +++ b/goKMS/kms/peers/qmodule.go @@ -91,7 +91,6 @@ func (eqe *EmulatedQuantumModule) Sync() error { bulkKey, ok := eqe.RawBulkKeys[initialPeerSetupResponse.BulkId] if !ok { - // TODO: add proper error message return fmt.Errorf("could not find raw bulk key with id: %d", initialPeerSetupResponse.BulkId) } -- GitLab