Skip to content
Snippets Groups Projects
Commit 302feb76 authored by Malte Bauch's avatar Malte Bauch Committed by Fabian Seidl
Browse files

Provide remoteKMS via AssignForwarding method

See merge request !146
parent 922c563c
No related branches found
No related tags found
1 merge request!146Provide remoteKMS via AssignForwarding method
Pipeline #203524 passed
......@@ -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(),
......
......@@ -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(),
......
......@@ -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()
......
......@@ -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)
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment