diff --git a/goKMS/gnmiHandlers/kms/assignForwardingHandler.go b/goKMS/gnmiHandlers/kms/assignForwardingHandler.go index d5edbbd6ec36192acd81ef2d39547b2ba4a7ef03..01ebfedb3ed99aca35c08a531226893702f48210 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 e8a09b4ccab0bdd8b27fb7528d8a6d47d680611d..6bce9e8e7f74c5dedf6efe18a9cc45f330518df0 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 c5e8bcfbd95a9f58e75a26839b114829d6791ac6..6440aeb09043827875e080e1b4f1706da227f865 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 4184cc5b937366facde181c8af7f0eeb575d8323..e3098811ee99bd9672dc4f9f5b8ff88b194a6cb7 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 14e926490bc655d3f399abe2609ce2e7a396c7ec..e6c9fcedb57c2913d3d6670994acacc8ec0a565f 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