Skip to content
Snippets Groups Projects
Commit 9a4a552c authored by Neil-Jocelyn Schark's avatar Neil-Jocelyn Schark
Browse files

wip

parent 681172aa
No related branches found
No related tags found
2 merge requests!11Big boom integration,!6Draft: Akms ckms api implementation
Pipeline #180984 failed
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"code.fbi.h-da.de/danet/quant/ekms/internal/akmCkmsInterface" "code.fbi.h-da.de/danet/quant/ekms/internal/akmsCkmsServer"
"code.fbi.h-da.de/danet/quant/ekms/internal/kms" "code.fbi.h-da.de/danet/quant/ekms/internal/kms"
"github.com/google/uuid" "github.com/google/uuid"
) )
...@@ -127,7 +127,7 @@ func NewEkmsClient(bootInfo *Config) (myInfo *ekmsInfo) { ...@@ -127,7 +127,7 @@ func NewEkmsClient(bootInfo *Config) (myInfo *ekmsInfo) {
func emulatedKMS(config *Config, id uuid.UUID, peerChannel chan string) *kms.EKMS { func emulatedKMS(config *Config, id uuid.UUID, peerChannel chan string) *kms.EKMS {
// Attach to eKMS // Attach to eKMS
emuKMS := kms.NewEKMS(config.Name, id, os.Stdout, log.TraceLevel, false, config.InterComAddr) emuKMS := kms.NewEKMS(config.Name, id, os.Stdout, log.TraceLevel, false, config.InterComAddr)
akmsCkmsReceiver := akmCkmsInterface.NewAKMSReceiver("4567", emuKMS) akmsCkmsReceiverServer := akmsCkmsServer.NewAKMSReceiver("4567", emuKMS)
var qm kms.QuantumModule var qm kms.QuantumModule
var err error var err error
...@@ -169,10 +169,11 @@ func emulatedKMS(config *Config, id uuid.UUID, peerChannel chan string) *kms.EKM ...@@ -169,10 +169,11 @@ func emulatedKMS(config *Config, id uuid.UUID, peerChannel chan string) *kms.EKM
} }
} }
// Start the SDN/management, key retrieval interface and akms server // Start the SDN/management and key retrieval interface
go kms.StartETSI(config.GRPCAddr, emuKMS) go kms.StartETSI(config.GRPCAddr, emuKMS)
go akmsCkmsReceiver.Serve()
// Start the AKMSReceiverServer
go akmsCkmsReceiverServer.Serve()
return emuKMS return emuKMS
} }
......
package akmsCkmsClient
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type CkmsAkmsClient struct {
url string
}
func NewCkmsAkmsClient(url string) CkmsAkmsClient {
return CkmsAkmsClient{
url: url,
}
}
type PushKSAKeyRequest struct {
RequestID string `json:"request_ID"`
ProcessID string `json:"process_ID"`
KSAKeys []KSAKey `json:"ksa_keys"`
}
type KSAKey struct {
KeyID string `json:"key_ID"`
Key string `json:"key"`
}
func (c *CkmsAkmsClient) SendKSAKeys(requestID string, processID string, ksaKeys []KSAKey) error {
pushRequest := PushKSAKeyRequest{
RequestID: requestID,
ProcessID: processID,
KSAKeys: ksaKeys,
}
jsonData, err := json.Marshal(pushRequest)
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return err
}
resp, err := http.Post(c.url, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error sending POST request:", err)
return err
}
err = resp.Body.Close()
if err != nil {
fmt.Println("Error closing response body:", err)
}
if resp.StatusCode != http.StatusNoContent {
fmt.Println("Unexpected response status code:", resp.StatusCode)
return err
}
return nil
}
package akmCkmsInterface package akmsCkmsServer
import ( import (
"encoding/json" "encoding/json"
...@@ -7,14 +7,14 @@ import ( ...@@ -7,14 +7,14 @@ import (
"code.fbi.h-da.de/danet/quant/ekms/internal/kms" "code.fbi.h-da.de/danet/quant/ekms/internal/kms"
) )
// Define AKMSReceiver. // Define AKMSReceiverServer.
type AKMSReceiver struct { type AKMSReceiverServer struct {
ekms *kms.EKMS ekms *kms.EKMS
server *http.Server server *http.Server
} }
// create NewAKMSReceiver. // create NewAKMSReceiver.
func NewAKMSReceiver(port string, ekms *kms.EKMS) *AKMSReceiver { func NewAKMSReceiver(port string, ekms *kms.EKMS) *AKMSReceiverServer {
router := http.NewServeMux() router := http.NewServeMux()
router.HandleFunc("/ksa_key_req", ksaReqHandler) router.HandleFunc("/ksa_key_req", ksaReqHandler)
...@@ -24,7 +24,7 @@ func NewAKMSReceiver(port string, ekms *kms.EKMS) *AKMSReceiver { ...@@ -24,7 +24,7 @@ func NewAKMSReceiver(port string, ekms *kms.EKMS) *AKMSReceiver {
Handler: router, Handler: router,
} }
AKMSReceiver := &AKMSReceiver{ AKMSReceiver := &AKMSReceiverServer{
ekms: ekms, ekms: ekms,
server: server, server: server,
} }
...@@ -32,7 +32,7 @@ func NewAKMSReceiver(port string, ekms *kms.EKMS) *AKMSReceiver { ...@@ -32,7 +32,7 @@ func NewAKMSReceiver(port string, ekms *kms.EKMS) *AKMSReceiver {
return AKMSReceiver return AKMSReceiver
} }
func (akmsReceiver *AKMSReceiver) Serve() { func (akmsReceiver *AKMSReceiverServer) Serve() {
go akmsReceiver.server.ListenAndServe() //nolint:errcheck go akmsReceiver.server.ListenAndServe() //nolint:errcheck
} }
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"google.golang.org/grpc/health" "google.golang.org/grpc/health"
healthpb "google.golang.org/grpc/health/grpc_health_v1" healthpb "google.golang.org/grpc/health/grpc_health_v1"
"code.fbi.h-da.de/danet/quant/ekms/internal/akmsCkmsClient"
pbETSI "code.fbi.h-da.de/danet/quant/ekms/internal/api/gen/proto/go/kmsetsi" pbETSI "code.fbi.h-da.de/danet/quant/ekms/internal/api/gen/proto/go/kmsetsi"
pbIC "code.fbi.h-da.de/danet/quant/ekms/internal/api/gen/proto/go/kmsintercom" pbIC "code.fbi.h-da.de/danet/quant/ekms/internal/api/gen/proto/go/kmsintercom"
"code.fbi.h-da.de/danet/quant/ekms/internal/kms/event" "code.fbi.h-da.de/danet/quant/ekms/internal/kms/event"
...@@ -53,7 +54,7 @@ type EKMS struct { ...@@ -53,7 +54,7 @@ type EKMS struct {
pbIC.UnimplementedKmsTalkerServer pbIC.UnimplementedKmsTalkerServer
supportedKeyLengths map[BitKeyLength]bool supportedKeyLengths map[BitKeyLength]bool
eventBus *event.EventBus eventBus *event.EventBus
//akmsSender *http.Server ckmsAkmsClient akmsCkmsClient.CkmsAkmsClient
} }
// Will keep information about the quantum elements that this EKMS is talking to // Will keep information about the quantum elements that this EKMS is talking to
...@@ -85,6 +86,8 @@ func NewEKMS(kmsName string, kmsUUID uuid.UUID, logOutput io.Writer, logLevel lo ...@@ -85,6 +86,8 @@ func NewEKMS(kmsName string, kmsUUID uuid.UUID, logOutput io.Writer, logLevel lo
log.SetReportCaller(false) log.SetReportCaller(false)
} }
ckmsAkmsClient := akmsCkmsClient.NewCkmsAkmsClient("127.0.0.1:1234")
createdEKMS := &EKMS{ createdEKMS := &EKMS{
kmsName: kmsName, kmsName: kmsName,
kmsUUID: kmsUUID, kmsUUID: kmsUUID,
...@@ -94,13 +97,13 @@ func NewEKMS(kmsName string, kmsUUID uuid.UUID, logOutput io.Writer, logLevel lo ...@@ -94,13 +97,13 @@ func NewEKMS(kmsName string, kmsUUID uuid.UUID, logOutput io.Writer, logLevel lo
KmsPeers: make(map[string]*kmsPeer), KmsPeers: make(map[string]*kmsPeer),
supportedKeyLengths: make(map[BitKeyLength]bool), supportedKeyLengths: make(map[BitKeyLength]bool),
eventBus: event.NewEventBus(), eventBus: event.NewEventBus(),
ckmsAkmsClient: ckmsAkmsClient,
} }
createdEKMS.supportedKeyLengths[BitKeyLen256] = true createdEKMS.supportedKeyLengths[BitKeyLen256] = true
// start the inter communication gRPC server // start the inter communication gRPC server
go createdEKMS.startGRPC(interComAddr) go createdEKMS.startGRPC(interComAddr)
//go createdEKMS.akmsSender.ListenAndServe()
return createdEKMS return createdEKMS
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment