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
Small improvements on PQC
Carlos Monastyrskif0799bfccb6d
diff --git a/backend/src/lib/crypto/pqc/pqc-crypto.ts b/backend/src/lib/crypto/pqc/pqc-crypto.tsindex 39b3465103..4ac8c04dbf 100644--- a/backend/src/lib/crypto/pqc/pqc-crypto.ts+++ b/backend/src/lib/crypto/pqc/pqc-crypto.ts@@ -34,7 +34,10 @@ const extractRawKeyFromPkcs8 = (der: Buffer): Buffer => {// Guarded with try/catch because a raw key can naturally start with 0x04.if (raw[0] === 0x04) {try {- return Buffer.from(AsnConvert.parse(raw, OctetString).buffer);+ const inner = Buffer.from(AsnConvert.parse(raw, OctetString).buffer);+ if (inner.length < raw.length) {+ return inner;+ }} catch {// Not actually double-wrapped — use raw bytes directly}@@ -180,16 +183,15 @@ const pqcImportKey = (keyUsages: KeyUsage[]): PqcCryptoKey => {const derBuf = Buffer.from(keyData as ArrayBuffer);- const isPrivate = keyUsages.includes("sign");- if (format === "pkcs8" && isPrivate) {+ if (format === "pkcs8") {const rawKey = extractRawKeyFromPkcs8(derBuf);const actualAlg =detectPqcVariantFromDer(derBuf) || detectPqcVariantFromKeySize(rawKey.length, "private") || algName;return new PqcCryptoKey(rawKey, actualAlg, "private", keyUsages, derBuf);}- if (format === "spki" && !isPrivate) {+ if (format === "spki") {const rawKey = extractRawKeyFromSpki(derBuf);const actualAlg =detectPqcVariantFromDer(derBuf) || detectPqcVariantFromKeySize(rawKey.length, "public") || algName;diff --git a/backend/src/lib/crypto/pqc/pqc-openssl.ts b/backend/src/lib/crypto/pqc/pqc-openssl.tsindex aeb62df083..8db3d12c6b 100644--- a/backend/src/lib/crypto/pqc/pqc-openssl.ts+++ b/backend/src/lib/crypto/pqc/pqc-openssl.ts@@ -113,7 +113,7 @@ export const opensslVerify = async (publicDer: Buffer, signature: Buffer, data:writeFile(sigPath, signature, { mode: 0o600 }),writeFile(dataPath, data, { mode: 0o600 })]);- const { code } = await execOpenSSL([+ const { code, stderr } = await execOpenSSL(["pkeyutl","-verify","-pubin",@@ -126,7 +126,11 @@ export const opensslVerify = async (publicDer: Buffer, signature: Buffer, data:"-in",dataPath]);- return code === 0;+ if (code === 0) return true;++ if (stderr.includes("Signature Verification Failure")) return false;++ throw new Error(`PQC OpenSSL verification failed (exit ${code}): ${stderr}`);});};diff --git a/backend/src/services/certificate-common/certificate-issuance-utils.ts b/backend/src/services/certificate-common/certificate-issuance-utils.tsindex c03385bfc5..311e98bcba 100644--- a/backend/src/services/certificate-common/certificate-issuance-utils.ts+++ b/backend/src/services/certificate-common/certificate-issuance-utils.ts@@ -295,8 +295,22 @@ export const generateSelfSignedCertificate = async ({policy?.sans);+ if (isPqcAlgorithm(effectiveKeyAlgorithm) && certificateRequest.keyUsages?.length) {+ const invalidForPqc = [+ CertKeyUsageType.KEY_ENCIPHERMENT,+ CertKeyUsageType.KEY_AGREEMENT,+ CertKeyUsageType.DATA_ENCIPHERMENT+ ];+ const requested = certificateRequest.keyUsages.filter((ku) => invalidForPqc.includes(ku));+ if (requested.length > 0) {+ throw new BadRequestError({+ message: `Key usages ${requested.join(", ")} are not valid for PQC signature-only algorithms`+ });+ }+ }+const keyGenAlg = keyAlgorithmToAlgCfg(effectiveKeyAlgorithm);- const keyGenCrypto = isPqcAlgorithm(effectiveKeyAlgorithm) ? getPqcCrypto() : globalThis.crypto;+ const keyGenCrypto = isPqcAlgorithm(effectiveKeyAlgorithm) ? getPqcCrypto() : crypto.nativeCrypto;const keyPair = await keyGenCrypto.subtle.generateKey(keyGenAlg as RsaHashedKeyGenParams, true, ["sign", "verify"]);const signatureAlgorithmConfig = signatureAlgorithmToAlgCfg(effectiveSignatureAlgorithm, effectiveKeyAlgorithm);