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
warn on non supported
Thiago Araujo da Silva3feb3e938e81
diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.tsindex 2e94f6eec4..f1946d3e42 100644--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts@@ -11,6 +11,7 @@ import {parseCertificateSubjectAltNames,parseSubjectDetails,permitsClientAuth,+ readSubjectAltNames,TCertificateSanItem,verifyClientCertificateChain} from "./identity-tls-cert-auth-fns";@@ -310,6 +311,52 @@ describe("permitsClientAuth", () => {});});+describe("readSubjectAltNames", () => {+ x509.cryptoProvider.set(crypto.webcrypto as Crypto);++ const makeLeafWithSans = async (sans?: { type: "dns" | "url"; value: string }[]) => {+ const keys = await crypto.webcrypto.subtle.generateKey(+ { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256", publicExponent: new Uint8Array([1, 0, 1]), modulusLength: 2048 },+ true,+ ["sign", "verify"]+ );+ const cert = await x509.X509CertificateGenerator.createSelfSigned({+ serialNumber: "05",+ name: "CN=workload",+ notBefore: new Date("2026-06-01T00:00:00Z"),+ notAfter: new Date("2030-01-01T00:00:00Z"),+ keys,+ extensions: [+ new x509.BasicConstraintsExtension(false),+ ...(sans ? [new x509.SubjectAlternativeNameExtension(sans)] : [])+ ]+ });+ return new crypto.X509Certificate(Buffer.from(cert.rawData));+ };++ test("reads the subject alternative names a certificate carries", async () => {+ const cert = await makeLeafWithSans([{ type: "dns", value: "svc.example.com" }]);+ expect(readSubjectAltNames(cert)?.map(({ type, value }) => ({ type, value }))).toEqual([+ { type: "dns", value: "svc.example.com" }+ ]);+ });++ test("returns undefined for a certificate with no subject alternative names", async () => {+ expect(readSubjectAltNames(await makeLeafWithSans())).toBeUndefined();+ });++ // Denies rather than throwing, for the reason given on the equivalent permitsClientAuth test.+ test("returns undefined for a certificate whose extensions cannot be parsed", () => {+ const unparseable = {+ raw: Buffer.from("not a certificate"),+ subject: "CN=broken"+ } as unknown as crypto.X509Certificate;++ expect(readSubjectAltNames(unparseable)).toBeUndefined();+ expect(isSubjectAltNameAllowed(["dns:svc.example.com"], readSubjectAltNames(unparseable))).toBe(false);+ });+});+describe("verifyClientCertificateChain", () => {const alg: RsaHashedKeyGenParams = {name: "RSASSA-PKCS1-v1_5",@@ -944,4 +991,82 @@ describe("verifyClientCertificateChain", () => {});expect(result).toEqual({ ok: false, reasonCode: "certificate_expired" });});++ describe("Ed25519", () => {+ const edAlg = { name: "Ed25519" } as unknown as EcKeyGenParams;++ const makeEdRoot = async (name: string, extraExtensions: x509.Extension[] = []) => {+ const keys = (await crypto.webcrypto.subtle.generateKey(edAlg, true, ["sign", "verify"])) as CryptoKeyPair;+ const cert = await x509.X509CertificateGenerator.createSelfSigned({+ serialNumber: "01",+ name: `CN=${name}`,+ notBefore: NOT_BEFORE,+ notAfter: FAR_FUTURE,+ keys,+ signingAlgorithm: edAlg,+ extensions: [new x509.BasicConstraintsExtension(true, undefined, true), ...extraExtensions]+ });+ return { cert, keys };+ };++ const makeEdLeaf = async (name: string, issuer: { cert: x509.X509Certificate; keys: CryptoKeyPair }) => {+ const keys = (await crypto.webcrypto.subtle.generateKey(edAlg, true, ["sign", "verify"])) as CryptoKeyPair;+ const cert = await x509.X509CertificateGenerator.create({+ serialNumber: "02",+ subject: `CN=${name}`,+ issuer: issuer.cert.subject,+ notBefore: NOT_BEFORE,+ notAfter: FAR_FUTURE,+ signingKey: issuer.keys.privateKey,+ publicKey: keys.publicKey,+ signingAlgorithm: edAlg,+ extensions: [+ new x509.BasicConstraintsExtension(false),+ new x509.SubjectAlternativeNameExtension([{ type: "dns", value: `${name}.example.com` }])+ ]+ });+ return { cert, keys };+ };++ test("accepts an Ed25519 chain", async () => {+ const edRoot = await makeEdRoot("Ed Root");+ const leaf = await makeEdLeaf("workload", edRoot);++ const result = await verifyClientCertificateChain({+ leaf: toNative(leaf.cert),+ presentedChain: [],+ trustAnchor: toNative(edRoot.cert),+ now: NOW+ });+ expect(result).toEqual({ ok: true });+ });++ // Name constraint checking runs through pkijs, whose own crypto engine covers only RSA and+ // ECDSA, so these two cover the Ed25519 verification `ChainCryptoEngine` adds on top of it.+ test("accepts an Ed25519 chain whose CA asserts name constraints the leaf complies with", async () => {+ const edRoot = await makeEdRoot("Ed Constrained Root", [permittedDnsConstraint(["example.com"])]);+ const leaf = await makeEdLeaf("workload", edRoot);++ const result = await verifyClientCertificateChain({+ leaf: toNative(leaf.cert),+ presentedChain: [],+ trustAnchor: toNative(edRoot.cert),+ now: NOW+ });+ expect(result).toEqual({ ok: true });+ });++ test("rejects an Ed25519 leaf outside the namespace its CA is permitted to certify", async () => {+ const edRoot = await makeEdRoot("Ed Constrained Root", [permittedDnsConstraint(["allowed.example.com"])]);+ const leaf = await makeEdLeaf("workload", edRoot);++ const result = await verifyClientCertificateChain({+ leaf: toNative(leaf.cert),+ presentedChain: [],+ trustAnchor: toNative(edRoot.cert),+ now: NOW+ });+ expect(result).toEqual({ ok: false, reasonCode: "name_constraint_violation" });+ });+ });});diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.tsindex 7ddd7c6e96..4dd5fd9305 100644--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts@@ -39,7 +39,34 @@ const EXCLUDED_SUBTREE_VIOLATION_CODE = 42;const MAX_CANDIDATE_PATHS = 8;const MAX_SEARCH_PATH_STEPS = 2000;-const pkiCryptoEngine = new CryptoEngine({ name: "identity-tls-cert-auth", crypto: webcrypto as Crypto });+const ED25519_SIGNATURE_OID = "1.3.101.112";++/**+ * pkijs re-verifies every signature on the path with its own crypto engine, and that engine's+ * algorithm table covers only RSA and ECDSA. An Ed25519 chain Node already verified therefore comes+ * back from pkijs as unbuildable rather than as a constraint decision, which would deny a valid+ * client the moment its CA asserts name constraints. Node's WebCrypto does implement Ed25519, so+ * route that one algorithm to it and leave every other signature to pkijs.+ *+ * Ed448 is deliberately not routed here: Node still marks it experimental, and this is an+ * authentication path. Such a chain keeps failing closed, with the reason logged.+ */+class ChainCryptoEngine extends CryptoEngine {+ async verifyWithPublicKey(...args: Parameters<CryptoEngine["verifyWithPublicKey"]>): Promise<boolean> {+ const [data, signature, publicKeyInfo, signatureAlgorithm] = args;+ if (signatureAlgorithm.algorithmId !== ED25519_SIGNATURE_OID) {+ return super.verifyWithPublicKey(...args);+ }++ const algorithm = { name: "Ed25519" };+ const publicKey = await webcrypto.subtle.importKey("spki", publicKeyInfo.toSchema().toBER(false), algorithm, true, [+ "verify"+ ]);+ return webcrypto.subtle.verify(algorithm, publicKey, signature.valueBlock.valueHexView, data);+ }+}++const pkiCryptoEngine = new ChainCryptoEngine({ name: "identity-tls-cert-auth", crypto: webcrypto as Crypto });const isWithinValidityWindow = (cert: TNativeX509, at: Date): boolean =>new Date(cert.validFrom) <= at && at <= new Date(cert.validTo);@@ -103,7 +130,7 @@ const enforceNameConstraints = async (orderedPath: TNativeX509[], now: Date): PrcheckDate: now});- const { result, resultCode } = await engine.verify(+ const { result, resultCode, resultMessage } = await engine.verify({initialPermittedSubtreesSet: anchorConstraints?.permittedSubtrees ?? [],initialExcludedSubtreesSet: anchorConstraints?.excludedSubtrees ?? []@@ -115,6 +142,10 @@ const enforceNameConstraints = async (orderedPath: TNativeX509[], now: Date): Prif (resultCode === PERMITTED_SUBTREE_VIOLATION_CODE || resultCode === EXCLUDED_SUBTREE_VIOLATION_CODE) {return { ok: false, reasonCode: "name_constraint_violation" };}++ logger.warn(+ `TLS certificate auth: name constraint validation could not confirm the chain [resultCode=${resultCode}] [resultMessage=${resultMessage}] [leafSubject=${orderedPath[0].subject}] [anchorSubject=${orderedPath[orderedPath.length - 1].subject}]`+ );return { ok: false, reasonCode: "ca_verification_failed" };};@@ -134,7 +165,7 @@ const enforceNameConstraints = async (orderedPath: TNativeX509[], now: Date): Pr* established it and is denied rather than failing the request as an internal error.*/export const permitsClientAuth = (cert: TNativeX509): boolean => {- let usages: readonly string[] | undefined;+ let usages: x509.ExtendedKeyUsageExtension["usages"] | undefined;try {usages = new x509.X509Certificate(cert.raw).getExtension(x509.ExtendedKeyUsageExtension)?.usages;} catch (err) {@@ -373,6 +404,21 @@ type CanonicalSanType = "dns" | "ip" | "email" | "uri";export type TCertificateSanItem = { type: string; value: string };+/**+ * Reading the subject alternative names is what establishes that the certificate carries one the+ * identity allows, so a certificate whose extensions @peculiar/x509 cannot parse has not established+ * it and is treated as carrying none, which denies. See `permitsClientAuth` for why a certificate+ * Node accepted can still fail to parse here.+ */+export const readSubjectAltNames = (cert: TNativeX509): ReadonlyArray<TCertificateSanItem> | undefined => {+ try {+ return new x509.X509Certificate(cert.raw).getExtension(x509.SubjectAlternativeNameExtension)?.names.items;+ } catch (err) {+ logger.warn(err, `TLS certificate auth: could not read subject alternative names [subject=${cert.subject}]`);+ return undefined;+ }+};+const peculiarTypeToCanonical = (type: string): CanonicalSanType | null => {switch (type.trim().toLowerCase()) {case "dns":diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.tsindex 4914926b98..540d1aa6ce 100644--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts@@ -1,6 +1,5 @@import { ForbiddenError, subject } from "@casl/ability";import { requestContext } from "@fastify/request-context";-import * as x509 from "@peculiar/x509";import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";@@ -49,6 +48,7 @@ import {parseAllowedSubjectAltNames,parseSubjectDetails,permitsClientAuth,+ readSubjectAltNames,serializeAllowedSubjectAltNames,TVerifyClientCertificateChainResult,verifyClientCertificateChain@@ -273,13 +273,9 @@ export const identityTlsCertAuthServiceFactory = ({}if (identityTlsCertAuth.allowedSubjectAltNames) {- const sanExtension = new x509.X509Certificate(clientCertificateX509.raw).getExtension(- x509.SubjectAlternativeNameExtension- );-const isValidSubjectAltName = isSubjectAltNameAllowed(parseAllowedSubjectAltNames(identityTlsCertAuth.allowedSubjectAltNames),- sanExtension?.names.items+ readSubjectAltNames(clientCertificateX509));if (!isValidSubjectAltName) {throw new UnauthorizedError({