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
improvement(pki): show SAN/CN in keystore review and guard non-RSA PKCS#12 export
Saif9841e29d1a2b
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 7683d29c24..d4cb77a4ee 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -2131,6 +2131,7 @@ export const CERTIFICATES = {alias: "The friendly name the keystore records for this entry, if it has one.",subject: "The distinguished name of the certificate.",commonName: "The common name of the certificate, if it has one.",+ altNames: "The subject alternative names of the certificate, comma separated, if it has any.",keyAlgorithm: "The algorithm and size of the private key, such as 'RSA 2048' or 'ECDSA P-256'.",entrySerialNumber: "The serial number of the certificate.",notBefore: "The date the certificate becomes valid.",diff --git a/backend/src/server/routes/v1/certificate-router.ts b/backend/src/server/routes/v1/certificate-router.tsindex 652a49eccf..762a9b07e6 100644--- a/backend/src/server/routes/v1/certificate-router.ts+++ b/backend/src/server/routes/v1/certificate-router.ts@@ -1618,6 +1618,7 @@ export const registerCertificateRouter = async (server: FastifyZodProvider) => {alias: z.string().max(1024).nullable().describe(CERTIFICATES.EXTRACT_PKCS12.alias),subject: z.string().max(2048).describe(CERTIFICATES.EXTRACT_PKCS12.subject),commonName: z.string().max(1024).nullable().describe(CERTIFICATES.EXTRACT_PKCS12.commonName),+ altNames: z.string().max(2048).nullable().describe(CERTIFICATES.EXTRACT_PKCS12.altNames),keyAlgorithm: z.string().max(64).describe(CERTIFICATES.EXTRACT_PKCS12.keyAlgorithm),serialNumber: z.string().max(256).describe(CERTIFICATES.EXTRACT_PKCS12.entrySerialNumber),notBefore: z.string().describe(CERTIFICATES.EXTRACT_PKCS12.notBefore),diff --git a/backend/src/services/certificate/certificate-fns.ts b/backend/src/services/certificate/certificate-fns.tsindex 57db69718b..a31d721f41 100644--- a/backend/src/services/certificate/certificate-fns.ts+++ b/backend/src/services/certificate/certificate-fns.ts@@ -159,10 +159,19 @@ export const generatePkcs12FromCertificate = async ({throw new BadRequestError({ message: "Password is required for PKCS12 keystore generation" });}- // node-forge doesn't support PQC keys+ // node-forge only builds keystores from RSA keys, and cannot read PQC keys at all+ let keyType: string | undefined;try {- crypto.nativeCrypto.createPrivateKey({ key: privateKey, format: "pem", type: "pkcs8" });+ keyType = crypto.nativeCrypto.createPrivateKey({+ key: privateKey,+ format: "pem",+ type: "pkcs8"+ }).asymmetricKeyType;} catch {+ keyType = undefined;+ }++ if (keyType !== "rsa") {throw new BadRequestError({message: "PKCS#12 export is not supported for this key type. Use PEM format instead."});diff --git a/backend/src/services/certificate/certificate-pkcs12-fns.ts b/backend/src/services/certificate/certificate-pkcs12-fns.tsindex df5876c6f1..f4f1294b7e 100644--- a/backend/src/services/certificate/certificate-pkcs12-fns.ts+++ b/backend/src/services/certificate/certificate-pkcs12-fns.ts@@ -79,6 +79,21 @@ const keyBagToPem = (bag: forge.pkcs12.Bag) => {return toPem("PRIVATE KEY", forge.asn1.toDer(asn1).getBytes());};+const readAltNames = (cert: x509.X509Certificate) => {+ const extension = cert.extensions.find((ext) => ext.type === "2.5.29.17");+ if (!extension) return null;++ try {+ const names = new x509.GeneralNames(extension.value);+ return names.items+ .map((name) => name.value)+ .join(", ")+ .slice(0, MAX_SUBJECT_LENGTH);+ } catch {+ return null;+ }+};+const sha256Fingerprint = (der: Buffer) => {const hex = crypto.createHash("sha256").update(der).digest("hex").toUpperCase();return new RE2(".{2}", "g").match(hex)?.join(":") ?? hex;@@ -120,6 +135,7 @@ const describeKey = (key: crypto.KeyObject) => {}if (type === "ed25519") return "Ed25519";if (type === "ed448") return "Ed448";+ if (type === "unknown") return "";return type.toUpperCase();};@@ -281,6 +297,7 @@ export const extractPkcs12Entries = async ({const describeCert = (cert: TParsedCert) => ({subject: cert.cert.subject.slice(0, MAX_SUBJECT_LENGTH),commonName: cert.cert.subjectName.getField("CN")[0]?.slice(0, MAX_SUBJECT_LENGTH) ?? null,+ altNames: readAltNames(cert.cert),serialNumber: cert.cert.serialNumber.slice(0, MAX_SERIAL_LENGTH),notBefore: cert.cert.notBefore.toISOString(),notAfter: cert.cert.notAfter.toISOString(),diff --git a/frontend/src/hooks/api/certificates/types.ts b/frontend/src/hooks/api/certificates/types.tsindex e7a220e34c..e01d4b4d01 100644--- a/frontend/src/hooks/api/certificates/types.ts+++ b/frontend/src/hooks/api/certificates/types.ts@@ -90,6 +90,7 @@ export type TPkcs12Entry = {alias: string | null;subject: string;commonName: string | null;+ altNames: string | null;keyAlgorithm: string;serialNumber: string;notBefore: string;diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateImportModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateImportModal.tsxindex 2040c493c6..7c66019593 100644--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateImportModal.tsx+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateImportModal.tsx@@ -93,7 +93,8 @@ const toBase64 = (buffer: ArrayBuffer) => {return btoa(binary);};-const entryLabel = (entry: TPkcs12Entry) => entry.commonName || entry.alias || entry.subject;+const entryLabel = (entry: TPkcs12Entry) =>+ entry.altNames || entry.commonName || entry.alias || entry.subject;export const CertificateImportModal = ({ popUp, handlePopUpToggle, applicationId }: Props) => {const [certificateDetails, setCertificateDetails] = useState<TCertificateDetails | null>(null);@@ -313,7 +314,7 @@ export const CertificateImportModal = ({ popUp, handlePopUpToggle, applicationId}/></TableHead>- <TableHead>Subject</TableHead>+ <TableHead>SAN / CN</TableHead><TableHead className="w-40">Key</TableHead><TableHead className="w-24">Chain</TableHead><TableHead className="w-44">Expires</TableHead>@@ -337,7 +338,7 @@ export const CertificateImportModal = ({ popUp, handlePopUpToggle, applicationId<TableCell className="max-w-0"><div className="truncate">{entryLabel(entry)}</div></TableCell>- <TableCell>{entry.privateKeyPem ? entry.keyAlgorithm : "—"}</TableCell>+ <TableCell>{(entry.privateKeyPem && entry.keyAlgorithm) || "—"}</TableCell><TableCell>{entry.chainWarning ? (<Tooltip>