Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
smaller fixes
Daniel Hougaard0f925cfaad3f
diff --git a/backend/src/db/migrations/utils/services.ts b/backend/src/db/migrations/utils/services.tsindex 26640e38e7..e4b675f7e0 100644--- a/backend/src/db/migrations/utils/services.ts+++ b/backend/src/db/migrations/utils/services.ts@@ -68,13 +68,13 @@ export const getMigrationEncryptionServices = async ({ envConfig, db, keyStore }// ----- HSM startup -----const hsmModule = initializeHsmModule(envConfig);+ hsmModule.initialize();const hsmService = hsmServiceFactory({hsmModule: hsmModule.getModule(),envConfig});- hsmModule.initialize();await hsmService.startService();const hsmStatus = await isHsmActiveAndEnabled({diff --git a/backend/src/ee/services/hsm/hsm-fns.ts b/backend/src/ee/services/hsm/hsm-fns.tsindex 352a364437..2603f80bda 100644--- a/backend/src/ee/services/hsm/hsm-fns.ts+++ b/backend/src/ee/services/hsm/hsm-fns.ts@@ -35,6 +35,7 @@ export const initializeHsmModule = (envConfig: Pick<TEnvConfig, "isHsmConfiguredif ((error as { message?: string })?.message === "CKR_CRYPTOKI_ALREADY_INITIALIZED") {logger.info("Skipping HSM initialization because it's already initialized.");+ isInitialized = true;} else {logger.error(error, "Failed to initialize PKCS#11 module");throw error;@@ -83,7 +84,7 @@ export const isHsmActiveAndEnabled = async ({const rootKmsConfig = await kmsRootConfigDAL.findById(KMS_ROOT_CONFIG_UUID).catch(() => null);- rootKmsConfigEncryptionStrategy = rootKmsConfig?.encryptionStrategy as RootKeyEncryptionStrategy | null;+ rootKmsConfigEncryptionStrategy = (rootKmsConfig?.encryptionStrategy || null) as RootKeyEncryptionStrategy | null;if (rootKmsConfigEncryptionStrategy === RootKeyEncryptionStrategy.HSM && !licenseService.onPremFeatures.hsm) {throw new BadRequestError({message: "Your license does not include HSM integration. Please upgrade to the Enterprise plan to use HSM."diff --git a/backend/src/ee/services/hsm/hsm-service.ts b/backend/src/ee/services/hsm/hsm-service.tsindex 0ed4c5fafd..3b332e446a 100644--- a/backend/src/ee/services/hsm/hsm-service.ts+++ b/backend/src/ee/services/hsm/hsm-service.ts@@ -460,10 +460,23 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon}};+ const randomBytes = async (length: number) => {+ if (!pkcs11 || !isInitialized) {+ throw new Error("PKCS#11 module is not initialized");+ }++ const randomData = await $withSession((sessionHandle) =>+ pkcs11.C_GenerateRandom(sessionHandle, Buffer.alloc(length))+ );++ return randomData;+ };+return {encrypt,startService,isActive,- decrypt+ decrypt,+ randomBytes};};diff --git a/backend/src/services/kms/kms-service.ts b/backend/src/services/kms/kms-service.tsindex 035b3db026..5b35f2f63b 100644--- a/backend/src/services/kms/kms-service.ts+++ b/backend/src/services/kms/kms-service.ts@@ -1083,8 +1083,8 @@ export const kmsServiceFactory = ({const isHsmActive = hsmStatus.isHsmConfigured;- logger.info("KMS: Generating new ROOT Key");- const newRootKey = crypto.randomBytes(32);+ logger.info(`KMS: Generating new ROOT Key with ${isHsmActive ? "HSM" : "software"} encryption`);+ const newRootKey = isHsmActive ? await hsmService.randomBytes(32) : crypto.randomBytes(32);const encryptionStrategy = isHsmActive ? RootKeyEncryptionStrategy.HSM : RootKeyEncryptionStrategy.Software;