From 302feb7642c5e396d4d88231d728224ede69677f Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@h-da.de> Date: Mon, 10 Jun 2024 07:43:11 +0000 Subject: [PATCH] Provide remoteKMS via AssignForwarding method See merge request danet/quant!146 --- .../kms/assignForwardingHandler.go | 5 +++-- .../kms/keyRoutingSessionsHandler.go | 5 +++-- goKMS/kms/kms.go | 20 ++++++------------- goKMS/kms/peers/peers.go | 3 ++- goKMS/kms/util/util.go | 6 ++++++ 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/goKMS/gnmiHandlers/kms/assignForwardingHandler.go b/goKMS/gnmiHandlers/kms/assignForwardingHandler.go index d5edbbd6..01ebfedb 100644 --- a/goKMS/gnmiHandlers/kms/assignForwardingHandler.go +++ b/goKMS/gnmiHandlers/kms/assignForwardingHandler.go @@ -5,6 +5,7 @@ import ( "code.fbi.h-da.de/danet/gnmi-target/handler" "code.fbi.h-da.de/danet/quant/goKMS/kms" + "code.fbi.h-da.de/danet/quant/goKMS/kms/util" gnmitargetygot "code.fbi.h-da.de/danet/quant/goKMS/model" "github.com/openconfig/gnmi/proto/gnmi" "github.com/openconfig/ygot/ygot" @@ -60,7 +61,7 @@ func (yh *AssignForwardingHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnmi prevHopString = prevHop.GetNodeId() } - var initKMS *kms.RemoteKMS + var initKMS *util.RemoteKMS // check if initiating kms address is set if initiatingKmsAddress := forwarding.GetInitiatingKmsAddress(); initiatingKmsAddress != nil { addressPrefix := "" @@ -73,7 +74,7 @@ func (yh *AssignForwardingHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnmi return fmt.Errorf("initiatingKmsAddress must have either an IP address or a hostname") } - initKMS = &kms.RemoteKMS{ + initKMS = &util.RemoteKMS{ Id: initiatingKmsAddress.GetNodeId(), Address: addressPrefix, Port: initiatingKmsAddress.GetPort(), diff --git a/goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go b/goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go index e8a09b4c..6bce9e8e 100644 --- a/goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go +++ b/goKMS/gnmiHandlers/kms/keyRoutingSessionsHandler.go @@ -6,6 +6,7 @@ import ( "code.fbi.h-da.de/danet/gnmi-target/handler" "code.fbi.h-da.de/danet/quant/goKMS/kms" "code.fbi.h-da.de/danet/quant/goKMS/kms/event" + "code.fbi.h-da.de/danet/quant/goKMS/kms/util" gnmitargetygot "code.fbi.h-da.de/danet/quant/goKMS/model" "github.com/openconfig/gnmi/proto/gnmi" "github.com/openconfig/ygot/ygot" @@ -113,7 +114,7 @@ func (yh *KeyRoutingSessionHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnm prevHopString = prevHop.GetNodeId() } - var initKMS *kms.RemoteKMS + var initKMS *util.RemoteKMS // check if initiating kms address is set if initiatingKmsAddress := routingSession.GetInitiatingKmsAddress(); initiatingKmsAddress != nil { addressPrefix := "" @@ -126,7 +127,7 @@ func (yh *KeyRoutingSessionHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnm return fmt.Errorf("initiatingKmsAddress must have either an IP address or a hostname") } - initKMS = &kms.RemoteKMS{ + initKMS = &util.RemoteKMS{ Id: initiatingKmsAddress.GetNodeId(), Address: addressPrefix, Port: initiatingKmsAddress.GetPort(), diff --git a/goKMS/kms/kms.go b/goKMS/kms/kms.go index c5e8bcfb..6440aeb0 100644 --- a/goKMS/kms/kms.go +++ b/goKMS/kms/kms.go @@ -37,13 +37,7 @@ type Route struct { PathId uuid.UUID Previous *peers.Peer Next *peers.Peer - RemoteKMS *RemoteKMS -} - -type RemoteKMS struct { - Id string - Address string - Port uint16 + RemoteKMS *util.RemoteKMS } type BitKeyLength string @@ -68,7 +62,7 @@ type KMS struct { quantumAddress string tlsConfig config.TLSConfig // TODO create a mapping between ids and address - remoteKMSMapping map[string]*RemoteKMS + remoteKMSMapping map[string]*util.RemoteKMS remoteKMSMappingMutex sync.RWMutex quantumModules map[string]peers.QuantumModule quantumModulesMutex sync.RWMutex @@ -124,7 +118,7 @@ func NewKMS(kmsUUID uuid.UUID, logOutput io.Writer, logLevel log.Level, logInJso interComAddr: config.InterComAddr, quantumAddress: config.QuantumAddr, tlsConfig: config.KmsTLS, - remoteKMSMapping: make(map[string]*RemoteKMS), + remoteKMSMapping: make(map[string]*util.RemoteKMS), quantumModules: make(map[string]peers.QuantumModule), routingTable: make(map[uuid.UUID]*Route), PKStore: make(map[string]map[uuid.UUID]*PlatformKey), @@ -301,7 +295,7 @@ func (kms *KMS) AddPeer(peerKmsId string, kmsPeerSocket string, servingQLE peers return peer, nil } -func (kms *KMS) AssignForwardingRoute(pId, pHop, nHop string, remoteKMS *RemoteKMS) error { +func (kms *KMS) AssignForwardingRoute(pId, pHop, nHop string, remoteKMS *util.RemoteKMS) error { pathId, err := uuid.Parse(pId) if err != nil { return fmt.Errorf("the given path id %s is no uuid; err = %w", pathId, err) @@ -357,9 +351,7 @@ func (kms *KMS) AssignForwardingRoute(pId, pHop, nHop string, remoteKMS *RemoteK // update PKStore kms.AddSpecificPlatformKey(tmpRoute.RemoteKMS.Id, pathId, processId, pk) - remoteKMSAdrress := fmt.Sprintf("%s:%d", remoteKMS.Address, remoteKMS.Port) - - err = tmpRoute.Next.SendInitialPayloadBasedOnGRPCClient(pk, tmpRoute.PathId, processId, kms.kmsUUID.String(), remoteKMSAdrress) + err = tmpRoute.Next.SendInitialPayloadBasedOnGRPCClient(pk, tmpRoute.PathId, processId, kms.kmsUUID.String(), remoteKMS) if err != nil { log.Error(err) return err @@ -423,7 +415,7 @@ func (kms *KMS) GetRandomItemFromPKStore(remoteKMSId string) (uuid.UUID, *Platfo return util.RandomItemFromMapAndRemove(keyIds) } -func (kms *KMS) GetRemoteKMS(remoteKMSId string) (*RemoteKMS, error) { +func (kms *KMS) GetRemoteKMS(remoteKMSId string) (*util.RemoteKMS, error) { kms.remoteKMSMappingMutex.RLock() defer kms.remoteKMSMappingMutex.RUnlock() diff --git a/goKMS/kms/peers/peers.go b/goKMS/kms/peers/peers.go index 4184cc5b..e3098811 100644 --- a/goKMS/kms/peers/peers.go +++ b/goKMS/kms/peers/peers.go @@ -10,6 +10,7 @@ import ( pbIC "code.fbi.h-da.de/danet/quant/goKMS/api/gen/proto/go/kmsintercom" "code.fbi.h-da.de/danet/quant/goKMS/kms/crypto" "code.fbi.h-da.de/danet/quant/goKMS/kms/event" + "code.fbi.h-da.de/danet/quant/goKMS/kms/util" "github.com/google/uuid" log "github.com/sirupsen/logrus" ) @@ -133,7 +134,7 @@ func (ph *Peer) TransportKeyNegotiation() error { return nil } -func (ph *Peer) SendInitialPayloadBasedOnGRPCClient(key *crypto.Key, pathId, processId uuid.UUID, kmsId string, remoteKMSAddress string) error { +func (ph *Peer) SendInitialPayloadBasedOnGRPCClient(key *crypto.Key, pathId, processId uuid.UUID, kmsId string, remoteKMS *util.RemoteKMS) error { if ph.peerClient.KmsTalkerClient != nil { return ph.SendPayload(key, pathId, processId) } diff --git a/goKMS/kms/util/util.go b/goKMS/kms/util/util.go index 14e92649..e6c9fced 100644 --- a/goKMS/kms/util/util.go +++ b/goKMS/kms/util/util.go @@ -8,6 +8,12 @@ import ( "github.com/hashicorp/go-multierror" ) +type RemoteKMS struct { + Id string + Address string + Port uint16 +} + func RandomItemFromMap[T comparable, M any](m map[T]M) (T, M, error) { for key, item := range m { return key, item, nil -- GitLab