From e716c29bc08bdef94dd8f12021eff638e61b9812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Hejman?= Date: Tue, 29 Oct 2024 21:20:07 +0100 Subject: [PATCH] Air-gapped mode (#926) --- quesma/licensing/runner.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/quesma/licensing/runner.go b/quesma/licensing/runner.go index 991f3590b..2f8807a1a 100644 --- a/quesma/licensing/runner.go +++ b/quesma/licensing/runner.go @@ -3,6 +3,8 @@ package licensing import ( + "crypto/sha256" + "encoding/hex" "fmt" "github.com/google/uuid" "github.com/rs/zerolog" @@ -19,14 +21,33 @@ type LicenseModule struct { } const ( - installationIdFile = ".installation_id" + installationIdFile = ".installation_id" + quesmaAirGapModeEnvVar = "QUESMA_AIRGAP_KEY" ) +func isAirgapKeyValid(key string) bool { + hasher := sha256.New() + hasher.Write([]byte(key)) + keyHash := hex.EncodeToString(hasher.Sum(nil)) + return keyHash == "78b14371a310f4e4f7e6c19a444f771bbe5d2c4f2154715191334bcf58420435" +} + func Init(config *config.QuesmaConfiguration) *LicenseModule { l := &LicenseModule{ Config: config, LicenseKey: []byte(config.LicenseKey), } + if airgapKey, isSet := os.LookupEnv(quesmaAirGapModeEnvVar); isSet { + if isAirgapKeyValid(airgapKey) { + l.logInfo("Running Quesma in airgapped mode") + l.License = &License{ + InstallationID: "air-gapped-installation-id", + ClientID: "air-gapped-client-id", + } + return l + } + } + l.logInfo("Initializing license module") l.Run() return l }