diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..4e7b6ac65832fc233b1b06dbf7bbb5d81df62b2c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +ARG GOLANG_VERSION=1.20.5 + +FROM golang:$GOLANG_VERSION-alpine as builder +WORKDIR /proto-kms/ +RUN apk add build-base +COPY . . +RUN --mount=type=cache,target=/root/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + make build-proto-kms + +FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-buster +WORKDIR /app/ +COPY --from=builder /proto-kms/artifacts/proto-kms ./proto-kms +ENTRYPOINT ["./proto-kms"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..14dcc56834286077dea369be87ea99e25e6cfd9e --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +GOCMD=go +GOBUILD=$(GOCMD) build +GOCLEAN=$(GOCMD) clean +BUILD_ARTIFACTS_PATH=artifacts + +pre: + mkdir -p $(BUILD_ARTIFACTS_PATH) + +build-proto-kms: pre + CGO_ENABLED=0 $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/proto-kms . + +containerize-proto-kms: + docker buildx build --rm -t proto-kms --load -f Dockerfile . + +clean: + $(GOCLEAN) + rm -rf $(BUILD_ARTIFACTS_PATH) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..3ea7bcb9ed6bc615119d3730728fefaf0b4589ed --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3' + +services: + proto-kms1: + build: + dockerfile: Dockerfile + command: ["-address", "172.100.20.11:55059", "-name", "proto-kms1"] + networks: + proto-kms-net: + ipv4_address: 172.100.20.10 + + proto-kms2: + build: + dockerfile: Dockerfile + command: ["-address", "172.100.20.10:55059","-name", "proto-kms2"] + networks: + proto-kms-net: + ipv4_address: 172.100.20.11 + +networks: + proto-kms-net: + ipam: + driver: default + config: + - subnet: "172.100.20.0/24" + name: proto-kms-net + diff --git a/main.go b/main.go index 8f6ea93b3af66c07efcd10716d9ae69f5ba91511..4b14c640633766c970823ced76fcaa55825071b9 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "log" "net" @@ -9,11 +10,34 @@ import ( ) func main() { + // my own Name + var qlName1, udpQL1AddrString string + // a name for potential self-testing + var qlName2, udpQL2AddrString string + // Setup flags that allows to initially provide a address to a second + // quantumlayer so generated keys can be fetched. This is mainly to simplify + // the initial setup process. + flag.StringVar(&udpQL2AddrString, "address", "[::1]:50900", + "The UDP address for my quantumlayer so keys can be fetched") - log.Println("Welcome to the proto-kms") + flag.StringVar(&ql1Name, "name", "ekms-ql1", + "The name of the quantumlayer") - go emulatedKMS("kms-ql1", "[::1]:50900", "[::1]:50901") - emulatedKMS("kms-ql2", "[::1]:50901", "[::1]:50900") + flag.StringVar(&udpQL2AddrString, "address", "[::1]:50901", + "The UDP address to a second quantumlayer so keys can be fetched") + + flag.StringVar(&ql2Name, "name", "ekms-ql2", + "The name of the quantumlayer") + + + // Parse the provided flags + flag.Parse() + + log.Println("Welcome to the proto-kms called: ", qlName) + + go emulatedKMS(ql2Name, udpQL2AddrString, udpQL1AddrString) + emulatedKMS(ql1Name, udpQL1AddrString, udpQL2AddrString) + return } diff --git a/quantumlayer/quantumlayer-emu-prng.go b/quantumlayer/quantumlayer-emu-prng.go index 0f8e7e712d144792b9ed578e2f9c90f0a9a082cf..a074502454d58e05e618a6f73730734677fa9d4c 100644 --- a/quantumlayer/quantumlayer-emu-prng.go +++ b/quantumlayer/quantumlayer-emu-prng.go @@ -23,9 +23,9 @@ import ( ) type QuantumPayloadElement struct { - BulkKeyId int64 // the unique ID of this bulk of keys - BulkKeyLength int // the length, counted in bytes, of bulkKey - BulkKey *[]byte // the bulk key + BulkKeyId int64 `json:"bulk-key-id"` // the unique ID of this bulk of keys + BulkKeyLength int `json:"bulk-key-length"` // the length, counted in bytes, of bulkKey + BulkKey *[]byte `json:"bulk-key"` // the bulk key } type QuantumlayerEmuPRNG struct { @@ -74,6 +74,7 @@ func (qlemuprng *QuantumlayerEmuPRNG) PowerOn(localQLAddress ...string) { udpAddrString = localQLAddress[0] } log.Printf("localQLAddress is %s", localQLAddress[0]) + // This reads random numbers from other Quantum end udpSrvPort, err := net.ResolveUDPAddr("udp", udpAddrString) if err != nil { @@ -178,7 +179,6 @@ func (qlemuprng *QuantumlayerEmuPRNG) AddPeer(addr net.UDPAddr) { } } }(ctx) - } func (qlemuprng *QuantumlayerEmuPRNG) RemovePeer() { @@ -297,5 +297,4 @@ func (store *NumberStore) receiveNumbers(incoming chan QuantumPayloadElement) { store.mu.Unlock() } - }