diff --git a/Makefile b/Makefile index e875b76e9552ef1685d8018f4f7da57b2221d221..fbb8641c0724fd33fecab879886821cbba4ec92e 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,8 @@ ekms-container: ekms-container-debug: docker buildx build --rm -t ekms-debug --load -f ./ekms/Dockerfile.debug --build-arg GITLAB_LOGIN=${GITLAB_LOGIN} --build-arg GITLAB_TOKEN=${GITLAB_TOKEN} --build-arg GOLANG_VERSION=${GOLANG_VERSION} . +build-images: ekms-container quantumlayer-container + compose-up: ekms-container quantumlayer-container docker-compose up -d diff --git a/akms-simulator/akms-simulator.go b/akms-simulator/akms-simulator.go index bde1596881074f7c94f60605dacb8c784bd7a549..e90d33addfe71fb7cb2dcfe99fe78f338eca59b2 100644 --- a/akms-simulator/akms-simulator.go +++ b/akms-simulator/akms-simulator.go @@ -1,30 +1,35 @@ package main import ( - "fmt" "io/ioutil" "log" "net/http" + + "github.com/sirupsen/logrus" ) func main() { - fmt.Println("Starting AKMS Simulator...") - http.HandleFunc("/push_ksa_key", handlePushKsaKey) + logrus.Info("Starting AKMS Simulator...") + + http.HandleFunc("/api/v1/keys/push_ksa_key", handlePushKsaKey) log.Fatal(http.ListenAndServe(":4444", nil)) } func handlePushKsaKey(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + logrus.Errorf("Method not allowed: %s", r.Method) return } body, err := ioutil.ReadAll(r.Body) if err != nil { http.Error(w, "Failed to read request body", http.StatusInternalServerError) + logrus.Errorf("Failed to read request body: %s", err) return } ip := r.RemoteAddr - fmt.Println("Request came from: " + ip + "; Body: " + string(body)) + logrus.Info("Request came from: " + ip + "; Body: " + string(body)) + w.WriteHeader(http.StatusNoContent) } diff --git a/config/configure-3ekms.sh b/config/configure-3ekms.sh index 0a425f7b74c78f90eef1f75affad6cab1524bdfc..295eb4b2aea7241b9f9ec5bae3c2f6ce0646a5ab 100755 --- a/config/configure-3ekms.sh +++ b/config/configure-3ekms.sh @@ -19,4 +19,4 @@ curl -X POST -H "Content-Type: application/json" -d '{ "TTL": 24 } ] -}' 'http://172.100.20.10:9696/ksa_key_req' +}' 'http://172.100.20.10:9696/api/v1/keys/ksa_key_req' diff --git a/docker-compose.yml b/docker-compose.yml index 8142b73aefdadb9bb579d080709526a5f502955f..1a3b409422520c3777316ecec7e9b1d6d6a2c158 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: ekms01: image: ekms - command: ["start", "--log", "debug", "--kms_config", "/tmp/kms/config/ekms01.yaml", "--insecure"] + command: ["start", "--log", "info", "--kms_config", "/tmp/kms/config/ekms01.yaml", "--insecure"] volumes: - ./config/ekms/example01.yaml:/tmp/kms/config/ekms01.yaml networks: @@ -12,7 +12,7 @@ services: ekms02: image: ekms - command: ["start", "--log", "debug", "--kms_config", "/tmp/kms/config/ekms02.yaml", "--insecure"] + command: ["start", "--log", "info", "--kms_config", "/tmp/kms/config/ekms02.yaml", "--insecure"] volumes: - ./config/ekms/example02.yaml:/tmp/kms/config/ekms02.yaml networks: @@ -21,7 +21,7 @@ services: ekms03: image: ekms - command: ["start", "--log", "debug", "--kms_config", "/tmp/kms/config/ekms03.yaml", "--insecure"] + command: ["start", "--log", "info", "--kms_config", "/tmp/kms/config/ekms03.yaml", "--insecure"] volumes: - ./config/ekms/example03.yaml:/tmp/kms/config/ekms03.yaml networks: @@ -69,11 +69,11 @@ services: build: context: . dockerfile: akms-simulator/Dockerfile - #command: ["--config", "/tmp/quantumlayer/config/quantumlayer02.yaml"] networks: ekms-net: ipv4_address: 172.100.20.22 + networks: ekms-net: ipam: diff --git a/ekms/Dockerfile b/ekms/Dockerfile index cbc63238929fbc6f40c16f4ccf4d71f42ca22da6..d989e05451aa0ae6828c3e0c88ca42a912f2771b 100644 --- a/ekms/Dockerfile +++ b/ekms/Dockerfile @@ -22,4 +22,3 @@ COPY --from=builder app/artifacts/ekms /usr/bin/ekms EXPOSE 7030 EXPOSE 50900 ENTRYPOINT ["/usr/bin/ekms"] -CMD [ "start", "--log", "debug" ] diff --git a/ekms/cmd/start.go b/ekms/cmd/start.go index b5ac5162962fb08f672c706c3b85d56d2587673b..d1c07cacfd0003729f64c91dbcc3be93a3fd4b96 100644 --- a/ekms/cmd/start.go +++ b/ekms/cmd/start.go @@ -83,6 +83,7 @@ var startCmd = &cobra.Command{ ll = logrus.InfoLevel } // set global log level + logrus.Info("Setting log level to ", ll) logrus.SetLevel(ll) kmsConfig := &etsiqkdnclient.Config{} diff --git a/ekms/etsiqkdnclient/etsi-qkdn-client.go b/ekms/etsiqkdnclient/etsi-qkdn-client.go index 6b8c666962f54caf10032893f173bf62a448503c..53537318daf837a343d97536f78ca15e7414f847 100644 --- a/ekms/etsiqkdnclient/etsi-qkdn-client.go +++ b/ekms/etsiqkdnclient/etsi-qkdn-client.go @@ -131,7 +131,7 @@ func NewEkmsClient(bootInfo *Config) (myInfo *ekmsInfo) { // TODO: return an error. func emulatedKMS(config *Config, id uuid.UUID, peerChannel chan string) *kms.EKMS { // Attach to eKMS - emuKMS := kms.NewEKMS(config.Name, id, os.Stdout, log.TraceLevel, false, config.InterComAddr, config.AkmsURL) + emuKMS := kms.NewEKMS(config.Name, id, os.Stdout, log.GetLevel(), false, config.InterComAddr, config.AkmsURL) var qm kms.QuantumModule var err error diff --git a/ekms/internal/akmsCkmsClient/ckmsAkmsClient.go b/ekms/internal/akmsCkmsClient/ckmsAkmsClient.go index af44b22822b4c4a75ac62de5962b9d5897a502d4..0d5a2f509196730ce4d3418ad2fe0e6d952ce823 100644 --- a/ekms/internal/akmsCkmsClient/ckmsAkmsClient.go +++ b/ekms/internal/akmsCkmsClient/ckmsAkmsClient.go @@ -3,8 +3,9 @@ package akmsCkmsClient import ( "bytes" "encoding/json" - "fmt" "net/http" + + "github.com/sirupsen/logrus" ) type CkmsAkmsClient struct { @@ -37,22 +38,24 @@ func (c *CkmsAkmsClient) SendKSAKeys(requestID string, processID string, ksaKeys jsonData, err := json.Marshal(pushRequest) if err != nil { - fmt.Println("Error marshaling JSON:", err) + logrus.Errorf("Error marshaling JSON: %s", err) return err } resp, err := http.Post(c.url, "application/json", bytes.NewBuffer(jsonData)) if err != nil { - fmt.Println("Error sending POST request:", err) + logrus.Errorf("Error sending POST request: %s", err) + logrus.Errorf("Tried to send request: %s to url: %s", jsonData, c.url) return err } err = resp.Body.Close() if err != nil { - fmt.Println("Error closing response body:", err) + logrus.Errorf("Error closing response body: %s", err) } if resp.StatusCode != http.StatusNoContent { - fmt.Println("Unexpected response status code:", resp.StatusCode) + logrus.Errorf("Unexpected response status code: %d", resp.StatusCode) + logrus.Errorf("Tried to send request: %s to url: %s", jsonData, c.url) return err } diff --git a/ekms/internal/kms/kms.go b/ekms/internal/kms/kms.go index 84b31be67c8b2f4e28d28b9835a56f97502b8ecf..04b3702bdd74a43895e270a61015f567be719fcb 100644 --- a/ekms/internal/kms/kms.go +++ b/ekms/internal/kms/kms.go @@ -151,7 +151,7 @@ func (kms *EKMS) startGRPC(interComAddr string) { func (kms *EKMS) AddQuantumElement(qm QuantumModule) error { kms.quantumModulesMutex.Lock() - log.Info(qm.Address()) + log.Infof("quantum module address: %s ", qm.Address()) kms.quantumModules[qm.Address()] = qm kms.quantumModulesMutex.Unlock() return nil @@ -260,7 +260,7 @@ func (kms *EKMS) GenerateAndSendKSAKey(address string, requestId string, number if !ok { // TODO: return proper error log.Errorf("path not found for: %s", address) - log.Info(kms.PKStore) + log.Errorf("error with he following pk store: %s", kms.PKStore) return fmt.Errorf("") } pathId, pk, err := RandomItemFromMapAndRemove[uuid.UUID, []byte](pathIds) diff --git a/ekms/internal/kms/quipsec.go b/ekms/internal/kms/quipsec.go index 62c6f8da00eeb0b7948f3aa1faac5869787a70a5..6133f11960bc7b62ac48ddd3c9b6dd44e775cf76 100644 --- a/ekms/internal/kms/quipsec.go +++ b/ekms/internal/kms/quipsec.go @@ -48,7 +48,7 @@ func (qs *quipSecServer) PushKeys(ctx context.Context, req *pb.PushKeysRequest) BulkKey: &req.GetKeyBulk().Keys, } eqm.rawBulkKeysMutex.Unlock() - logrus.Infof("%s received a new bulk with id: %s and a length of: %d", qs.eKMS.kmsName, req.GetKeyBulk().GetKeyId(), req.GetKeyBulk().GetKeyLength()) + logrus.Debugf("%s received a new bulk with id: %s and a length of: %d", qs.eKMS.kmsName, req.GetKeyBulk().GetKeyId(), req.GetKeyBulk().GetKeyLength()) return &pb.PushKeysResponse{Timestamp: time.Now().Unix()}, nil } } diff --git a/quantumlayer/quantumlayer-emu-prng.go b/quantumlayer/quantumlayer-emu-prng.go index d989fc102a6caf4be35c3673447c6fdecad79c48..3ef6c46d4a23bc22570534a4b4c6924cd5e059cc 100644 --- a/quantumlayer/quantumlayer-emu-prng.go +++ b/quantumlayer/quantumlayer-emu-prng.go @@ -366,7 +366,7 @@ func (store *NumberStore) receiveNumbers(incoming chan QuantumPayloadElement, cl store.bulkKeyStorage = append(store.bulkKeyStorage, mem) store.mu.Unlock() - log.Info(mem.BulkKeyId) + log.Debugf("Bulk key received: %d", mem.BulkKeyId) _, err := client.PushKeys(context.Background(), &pb.PushKeysRequest{ Timestamp: time.Now().Unix(),