Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(pki): record external CA issued values and drop issuer-written extensions on renewal

Carlos Monastyrski27ce1eeaa79a
diff --git a/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts b/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
index 7ec5e67943..a2e662bb6f 100644
--- a/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
@@ -29,7 +29,10 @@ import { TDNSMadeEasyConnection } from "@app/services/app-connection/dns-made-ea
import { TPowerDnsConnection } from "@app/services/app-connection/powerdns/powerdns-connection-types";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
-import { extractCertificateFields, linkRenewedCertificate } from "@app/services/certificate/certificate-fns";
+import {
+ extractExternallyIssuedCertificateFields,
+ linkRenewedCertificate
+} from "@app/services/certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "@app/services/certificate/certificate-secret-dal";
import {
CertExtendedKeyUsage,
@@ -609,7 +612,7 @@ export const executeAcmeOrder = async (
})
: { cipherTextBlob: undefined };
- const parsedFields = extractCertificateFields(Buffer.from(leafCert));
+ const parsedFields = extractExternallyIssuedCertificateFields(Buffer.from(leafCert), undefined, certObj.serialNumber);
return (tx || certificateDAL).transaction(async (innerTx: Knex) => {
const cert = await certificateDAL.create(
@@ -618,7 +621,7 @@ export const executeAcmeOrder = async (
pkiSubscriberId: subscriberId,
profileId,
status: CertStatus.ACTIVE,
- friendlyName: commonName,
+ friendlyName: parsedFields.commonName ?? commonName,
commonName,
altNames: altNames?.join(","),
serialNumber: certObj.serialNumber,
diff --git a/backend/src/services/certificate-authority/adcs/adcs-certificate-authority-fns.ts b/backend/src/services/certificate-authority/adcs/adcs-certificate-authority-fns.ts
index 91b0fecd02..454bbe4385 100644
--- a/backend/src/services/certificate-authority/adcs/adcs-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/adcs/adcs-certificate-authority-fns.ts
@@ -21,13 +21,15 @@ import { AppConnection } from "@app/services/app-connection/app-connection-enums
import { TAppConnectionServiceFactory } from "@app/services/app-connection/app-connection-service";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
-import { linkRenewedCertificate } from "@app/services/certificate/certificate-fns";
+import {
+ extractExternallyIssuedCertificateFields,
+ linkRenewedCertificate
+} from "@app/services/certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "@app/services/certificate/certificate-secret-dal";
import {
CertExtendedKeyUsage,
CertKeyAlgorithm,
CertKeyUsage,
- CertSignatureAlgorithm,
CertStatus,
CrlReason
} from "@app/services/certificate/certificate-types";
@@ -35,7 +37,6 @@ import { generateLeafKeypairAndCsr } from "@app/services/certificate-common/cert
import {
findCsrCustomExtensionMismatch,
findUnsatisfiedCustomExtensionOids,
- parseIssuedCustomExtensions,
TCsrCustomExtensionMismatch,
TResolvedCustomExtension
} from "@app/services/certificate-common/certificate-extension-fns";
@@ -57,20 +58,6 @@ import {
} from "./adcs-certificate-authority-types";
import { getAdcsConnectionCredentials } from "./adcs-connection-credentials";
-// @peculiar/x509 reports the signature algorithm as { name, hash }; map it to the stored enum.
-const SIG_ALG_MAP: Record<string, Record<string, CertSignatureAlgorithm>> = {
- "RSASSA-PKCS1-v1_5": {
- "SHA-256": CertSignatureAlgorithm.RSA_SHA256,
- "SHA-384": CertSignatureAlgorithm.RSA_SHA384,
- "SHA-512": CertSignatureAlgorithm.RSA_SHA512
- },
- ECDSA: {
- "SHA-256": CertSignatureAlgorithm.ECDSA_SHA256,
- "SHA-384": CertSignatureAlgorithm.ECDSA_SHA384,
- "SHA-512": CertSignatureAlgorithm.ECDSA_SHA512
- }
-};
-
// RFC 5280 section 5.3.1 CRLReason codes, which MS-CSRA ICertAdminD::RevokeCertificate expects as `Reason`.
const ADCS_CRL_REASON_CODES: Record<CrlReason, number> = {
[CrlReason.UNSPECIFIED]: 0,
@@ -84,18 +71,6 @@ const ADCS_CRL_REASON_CODES: Record<CrlReason, number> = {
[CrlReason.A_A_COMPROMISE]: 10
};
-// The CA (not the request) decides how it signs, so read the algorithm off the issued certificate.
-const extractIssuedSignatureAlgorithm = (certObj: x509.X509Certificate): CertSignatureAlgorithm | undefined => {
- try {
- const { name } = certObj.signatureAlgorithm;
- const hashName = (certObj.signatureAlgorithm as { hash?: { name?: string } }).hash?.name;
- if (!hashName) return undefined;
- return SIG_ALG_MAP[name]?.[hashName];
- } catch {
- return undefined;
- }
-};
-
const buildSubjectDN = (commonName: string): string => {
if (!commonName || !commonName.trim()) {
throw new BadRequestError({ message: "Common Name is required and cannot be empty" });
@@ -585,6 +560,11 @@ export const ADCSCertificateAuthorityFns = ({
let certificateId: string;
const unsatisfiedOids = findUnsatisfiedCustomExtensionOids(Buffer.from(cleanedCertificatePem), customExtensions);
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(cleanedCertificatePem),
+ customExtensions,
+ certObj.serialNumber
+ );
await certificateDAL.transaction(async (tx) => {
const cert = await certificateDAL.create(
@@ -592,7 +572,7 @@ export const ADCSCertificateAuthorityFns = ({
caId: ca.id,
profileId,
status: CertStatus.ACTIVE,
- friendlyName: commonName,
+ friendlyName: parsedFields.commonName ?? commonName,
commonName,
altNames: altNames.join(","),
serialNumber: certObj.serialNumber,
@@ -601,12 +581,10 @@ export const ADCSCertificateAuthorityFns = ({
keyUsages,
extendedKeyUsages,
keyAlgorithm,
- signatureAlgorithm: extractIssuedSignatureAlgorithm(certObj) ?? signatureAlgorithm,
+ signatureAlgorithm,
projectId: ca.projectId,
- customExtensions: JSON.stringify(
- parseIssuedCustomExtensions(Buffer.from(cleanedCertificatePem), customExtensions)
- ),
- renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null
+ renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null,
+ ...parsedFields
},
tx
);
diff --git a/backend/src/services/certificate-authority/aws-acm-public-ca/aws-acm-public-ca-certificate-authority-fns.ts b/backend/src/services/certificate-authority/aws-acm-public-ca/aws-acm-public-ca-certificate-authority-fns.ts
index 0d6c64b029..5fd53fd72f 100644
--- a/backend/src/services/certificate-authority/aws-acm-public-ca/aws-acm-public-ca-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/aws-acm-public-ca/aws-acm-public-ca-certificate-authority-fns.ts
@@ -26,14 +26,13 @@ import { AppConnection, AWSRegion } from "@app/services/app-connection/app-conne
import { TAppConnectionServiceFactory } from "@app/services/app-connection/app-connection-service";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
-import { extractCertificateFields, linkRenewedCertificate } from "@app/services/certificate/certificate-fns";
+import {
+ extractExternallyIssuedCertificateFields,
+ linkRenewedCertificate
+} from "@app/services/certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "@app/services/certificate/certificate-secret-dal";
import {
- CertExtendedKeyUsage,
- CertExtendedKeyUsageOIDToName,
CertKeyAlgorithm,
- CertKeyUsage,
- CertSignatureAlgorithm,
CertStatus,
CertSubjectAlternativeNameType,
CrlReason
@@ -670,49 +669,11 @@ export const AwsAcmPublicCaCertificateAuthorityFns = ({
plainText: Buffer.from(privateKeyPem)
});
- const parsedFields = extractCertificateFields(Buffer.from(certificatePem));
-
- // Extract key usages and extended key usages from the certificate ACM actually issued —
- // ACM applies its own policy and revises it over time, so the request is not the source of truth.
- let issuedKeyUsages: CertKeyUsage[] = [];
- const keyUsagesExt = certObj.getExtension(x509.KeyUsagesExtension);
- if (keyUsagesExt) {
- issuedKeyUsages = Object.values(CertKeyUsage).filter(
- // eslint-disable-next-line no-bitwise
- (usage) => (x509.KeyUsageFlags[usage] & keyUsagesExt.usages) !== 0
- );
- }
-
- let issuedExtendedKeyUsages: CertExtendedKeyUsage[] = [];
- const extKeyUsageExt = certObj.getExtension(x509.ExtendedKeyUsageExtension);
- if (extKeyUsageExt) {
- issuedExtendedKeyUsages = extKeyUsageExt.usages
- .map((oid) => CertExtendedKeyUsageOIDToName[oid as string])
- .filter(Boolean);
- }
-
- // ACM picks the signature algorithm server-side — derive it from the issued cert
- // so the persisted value matches what was actually signed.
- const sigAlgName = certObj.signatureAlgorithm.name;
- const sigHashName = (certObj.signatureAlgorithm as unknown as { hash?: { name: string } }).hash?.name;
- let issuedSignatureAlgorithm: CertSignatureAlgorithm;
- if (sigAlgName === "RSASSA-PKCS1-v1_5" && sigHashName === "SHA-256") {
- issuedSignatureAlgorithm = CertSignatureAlgorithm.RSA_SHA256;
- } else if (sigAlgName === "RSASSA-PKCS1-v1_5" && sigHashName === "SHA-384") {
- issuedSignatureAlgorithm = CertSignatureAlgorithm.RSA_SHA384;
- } else if (sigAlgName === "RSASSA-PKCS1-v1_5" && sigHashName === "SHA-512") {
- issuedSignatureAlgorithm = CertSignatureAlgorithm.RSA_SHA512;
- } else if (sigAlgName === "ECDSA" && sigHashName === "SHA-256") {
- issuedSignatureAlgorithm = CertSignatureAlgorithm.ECDSA_SHA256;
- } else if (sigAlgName === "ECDSA" && sigHashName === "SHA-384") {
- issuedSignatureAlgorithm = CertSignatureAlgorithm.ECDSA_SHA384;
- } else if (sigAlgName === "ECDSA" && sigHashName === "SHA-512") {
- issuedSignatureAlgorithm = CertSignatureAlgorithm.ECDSA_SHA512;
- } else {
- throw new BadRequestError({
- message: `Unsupported signature algorithm from AWS ACM: ${sigAlgName} with ${sigHashName}`
- });
- }
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(certificatePem),
+ undefined,
+ certObj.serialNumber
+ );
const externalMetadata = ExternalMetadataSchema.parse({
type: CaType.AWS_ACM_PUBLIC_CA,
@@ -732,16 +693,13 @@ export const AwsAcmPublicCaCertificateAuthorityFns = ({
caId: ca.id,
profileId,
status: CertStatus.ACTIVE,
- friendlyName: commonName,
+ friendlyName: parsedFields.commonName ?? commonName,
commonName,
altNames: altNames.map((san) => san.value).join(","),
serialNumber: certObj.serialNumber,
notBefore: certObj.notBefore,
notAfter: certObj.notAfter,
keyAlgorithm,
- signatureAlgorithm: issuedSignatureAlgorithm,
- keyUsages: issuedKeyUsages,
- extendedKeyUsages: issuedExtendedKeyUsages,
projectId: ca.projectId,
externalMetadata,
renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null,
diff --git a/backend/src/services/certificate-authority/aws-pca/aws-pca-certificate-authority-fns.ts b/backend/src/services/certificate-authority/aws-pca/aws-pca-certificate-authority-fns.ts
index 14ab17c5be..6005f9d5b9 100644
--- a/backend/src/services/certificate-authority/aws-pca/aws-pca-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/aws-pca/aws-pca-certificate-authority-fns.ts
@@ -29,7 +29,10 @@ import { getAwsConnectionConfig } from "@app/services/app-connection/aws/aws-con
import { TAwsConnection } from "@app/services/app-connection/aws/aws-connection-types";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
-import { extractCertificateFields, linkRenewedCertificate } from "@app/services/certificate/certificate-fns";
+import {
+ extractExternallyIssuedCertificateFields,
+ linkRenewedCertificate
+} from "@app/services/certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "@app/services/certificate/certificate-secret-dal";
import {
CertExtendedKeyUsage,
@@ -823,7 +826,11 @@ export const AwsPcaCertificateAuthorityFns = ({
let certificateId: string;
- const parsedFields = extractCertificateFields(Buffer.from(certificatePem), customExtensions);
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(certificatePem),
+ customExtensions,
+ certObj.serialNumber
+ );
await certificateDAL.transaction(async (tx) => {
const cert = await certificateDAL.create(
@@ -831,7 +838,7 @@ export const AwsPcaCertificateAuthorityFns = ({
caId: ca.id,
profileId,
status: CertStatus.ACTIVE,
- friendlyName: commonName,
+ friendlyName: parsedFields.commonName ?? commonName,
commonName,
altNames: altNames.map((san) => san.value).join(","),
serialNumber: certObj.serialNumber,
diff --git a/backend/src/services/certificate-authority/azure-ad-cs/azure-ad-cs-certificate-authority-fns.ts b/backend/src/services/certificate-authority/azure-ad-cs/azure-ad-cs-certificate-authority-fns.ts
index 90334ecea2..9da6cccf4e 100644
--- a/backend/src/services/certificate-authority/azure-ad-cs/azure-ad-cs-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/azure-ad-cs/azure-ad-cs-certificate-authority-fns.ts
@@ -17,7 +17,11 @@ import {
} from "@app/services/app-connection/azure-adcs/azure-adcs-connection-fns";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
-import { linkRenewedCertificate, splitPemChain } from "@app/services/certificate/certificate-fns";
+import {
+ extractExternallyIssuedCertificateFields,
+ linkRenewedCertificate,
+ splitPemChain
+} from "@app/services/certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "@app/services/certificate/certificate-secret-dal";
import {
CertExtendedKeyUsage,
@@ -1046,13 +1050,19 @@ export const AzureAdCsCertificateAuthorityFns = ({
plainText: Buffer.from(skLeaf)
});
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(cleanedCertificatePem),
+ undefined,
+ certObj.serialNumber
+ );
+
await certificateDAL.transaction(async (tx) => {
const cert = await certificateDAL.create(
{
caId: ca.id,
pkiSubscriberId: subscriber.id,
status: CertStatus.ACTIVE,
- friendlyName: subscriber.commonName,
+ friendlyName: parsedFields.commonName ?? subscriber.commonName,
commonName: subscriber.commonName,
altNames: subscriber.subjectAlternativeNames.join(","),
serialNumber: certObj.serialNumber,
@@ -1060,7 +1070,8 @@ export const AzureAdCsCertificateAuthorityFns = ({
notAfter: certObj.notAfter,
keyUsages: subscriber.keyUsages as CertKeyUsage[],
extendedKeyUsages: subscriber.extendedKeyUsages as CertExtendedKeyUsage[],
- projectId: ca.projectId
+ projectId: ca.projectId,
+ ...parsedFields
},
tx
);
@@ -1414,13 +1425,19 @@ export const AzureAdCsCertificateAuthorityFns = ({
let certificateId: string;
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(cleanedCertificatePem),
+ undefined,
+ certObj.serialNumber
+ );
+
await certificateDAL.transaction(async (tx) => {
const cert = await certificateDAL.create(
{
caId: ca.id,
profileId,
status: CertStatus.ACTIVE,
- friendlyName: commonName,
+ friendlyName: parsedFields.commonName ?? commonName,
commonName,
altNames: altNames.join(","),
serialNumber: certObj.serialNumber,
@@ -1431,7 +1448,8 @@ export const AzureAdCsCertificateAuthorityFns = ({
keyAlgorithm,
signatureAlgorithm,
projectId: ca.projectId,
- renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null
+ renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null,
+ ...parsedFields
},
tx
);
diff --git a/backend/src/services/certificate-authority/digicert/digicert-certificate-authority-fns.ts b/backend/src/services/certificate-authority/digicert/digicert-certificate-authority-fns.ts
index 2cdca63d6d..3284ef5991 100644
--- a/backend/src/services/certificate-authority/digicert/digicert-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/digicert/digicert-certificate-authority-fns.ts
@@ -14,7 +14,10 @@ import { TAppConnectionServiceFactory } from "@app/services/app-connection/app-c
import { DIGICERT_CS_PRODUCT_NAME_IDS } from "@app/services/app-connection/digicert/digicert-connection-fns";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
-import { linkRenewedCertificate } from "@app/services/certificate/certificate-fns";
+import {
+ extractExternallyIssuedCertificateFields,
+ linkRenewedCertificate
+} from "@app/services/certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "@app/services/certificate/certificate-secret-dal";
import { CertKeyAlgorithm, CertStatus, CrlReason, TAltNameType } from "@app/services/certificate/certificate-types";
import {
@@ -508,6 +511,11 @@ export const DigiCertCertificateAuthorityFns = ({
const certObj = new x509.X509Certificate(leaf);
const issued = extractIssuedCertificateFields(certObj);
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(new Uint8Array(certObj.rawData)),
+ undefined,
+ certObj.serialNumber
+ );
const certificateManagerKmsId = await getProjectKmsCertificateKeyId({
projectId: ca.projectId,
@@ -532,7 +540,6 @@ export const DigiCertCertificateAuthorityFns = ({
status: CertStatus.ACTIVE,
friendlyName: issued.commonName || "",
commonName: issued.commonName || "",
- altNames: issued.altNames.length > 0 ? issued.altNames.join(",") : "",
serialNumber: certObj.serialNumber,
notBefore: certObj.notBefore,
notAfter: certObj.notAfter,
@@ -545,7 +552,8 @@ export const DigiCertCertificateAuthorityFns = ({
type: CaType.DIGICERT,
orderId: digicertOrderId
} satisfies TDigiCertExternalMetadata,
- renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null
+ renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null,
+ ...parsedFields
},
tx
);
diff --git a/backend/src/services/certificate-authority/digicert/digicert-code-signing-fns.ts b/backend/src/services/certificate-authority/digicert/digicert-code-signing-fns.ts
index a372e888fe..946e22b02b 100644
--- a/backend/src/services/certificate-authority/digicert/digicert-code-signing-fns.ts
+++ b/backend/src/services/certificate-authority/digicert/digicert-code-signing-fns.ts
@@ -9,6 +9,7 @@ import {
} from "@app/services/app-connection/digicert/digicert-connection-fns";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
+import { extractExternallyIssuedCertificateFields } from "@app/services/certificate/certificate-fns";
import { CertStatus } from "@app/services/certificate/certificate-types";
import { TDigiCertExternalMetadata } from "@app/services/certificate-common/external-metadata-schemas";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
@@ -324,6 +325,11 @@ export const digiCertCodeSigningFns = ({
const certObj = new x509.X509Certificate(leaf);
const issued = extractIssuedCertificateFields(certObj);
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(new Uint8Array(certObj.rawData)),
+ undefined,
+ certObj.serialNumber
+ );
const existingCert = await certificateDAL.findOne({ caId: ca.id, serialNumber: certObj.serialNumber });
if (existingCert) {
@@ -352,7 +358,6 @@ export const digiCertCodeSigningFns = ({
status: CertStatus.ACTIVE,
friendlyName: issued.commonName || "",
commonName: issued.commonName || "",
- altNames: issued.altNames.length > 0 ? issued.altNames.join(",") : "",
serialNumber: certObj.serialNumber,
notBefore: certObj.notBefore,
notAfter: certObj.notAfter,
@@ -364,7 +369,8 @@ export const digiCertCodeSigningFns = ({
externalMetadata: {
type: CaType.DIGICERT,
orderId
- } satisfies TDigiCertExternalMetadata
+ } satisfies TDigiCertExternalMetadata,
+ ...parsedFields
},
tx
);
diff --git a/backend/src/services/certificate-authority/godaddy/godaddy-certificate-authority-fns.ts b/backend/src/services/certificate-authority/godaddy/godaddy-certificate-authority-fns.ts
index 179ecdb025..191c3d6af2 100644
--- a/backend/src/services/certificate-authority/godaddy/godaddy-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/godaddy/godaddy-certificate-authority-fns.ts
@@ -17,7 +17,10 @@ import { getGoDaddyApiBaseUrl } from "@app/services/app-connection/godaddy/godad
import { TGoDaddyConnection } from "@app/services/app-connection/godaddy/godaddy-connection-types";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
-import { linkRenewedCertificate } from "@app/services/certificate/certificate-fns";
+import {
+ extractExternallyIssuedCertificateFields,
+ linkRenewedCertificate
+} from "@app/services/certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "@app/services/certificate/certificate-secret-dal";
import { CertKeyAlgorithm, CertStatus, CrlReason } from "@app/services/certificate/certificate-types";
import {
@@ -526,6 +529,11 @@ export const GoDaddyCertificateAuthorityFns = ({
const certObj = new x509.X509Certificate(leaf);
const issued = extractIssuedCertificateFields(certObj);
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(new Uint8Array(certObj.rawData)),
+ undefined,
+ certObj.serialNumber
+ );
if (isRenewal && originalCertificateId) {
const original = await certificateDAL.findOne({ id: originalCertificateId });
@@ -559,7 +567,6 @@ export const GoDaddyCertificateAuthorityFns = ({
status: CertStatus.ACTIVE,
friendlyName: issued.commonName || "",
commonName: issued.commonName || "",
- altNames: issued.altNames.length > 0 ? issued.altNames.join(",") : "",
serialNumber: certObj.serialNumber,
notBefore: certObj.notBefore,
notAfter: certObj.notAfter,
@@ -572,7 +579,8 @@ export const GoDaddyCertificateAuthorityFns = ({
type: CaType.GODADDY,
certificateId: godaddyCertificateId
} satisfies TGoDaddyExternalMetadata,
- renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null
+ renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null,
+ ...parsedFields
},
tx
);
diff --git a/backend/src/services/certificate-authority/venafi-tpp/venafi-tpp-certificate-authority-fns.ts b/backend/src/services/certificate-authority/venafi-tpp/venafi-tpp-certificate-authority-fns.ts
index 712edb5bec..b3b0e10ada 100644
--- a/backend/src/services/certificate-authority/venafi-tpp/venafi-tpp-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/venafi-tpp/venafi-tpp-certificate-authority-fns.ts
@@ -23,7 +23,11 @@ import {
} from "@app/services/app-connection/venafi-tpp/venafi-tpp-connection-fns";
import { TCertificateBodyDALFactory } from "@app/services/certificate/certificate-body-dal";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
-import { linkRenewedCertificate, splitPemChain } from "@app/services/certificate/certificate-fns";
+import {
+ extractExternallyIssuedCertificateFields,
+ linkRenewedCertificate,
+ splitPemChain
+} from "@app/services/certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "@app/services/certificate/certificate-secret-dal";
import {
CertExtendedKeyUsage,
@@ -841,13 +845,19 @@ export const VenafiTppCertificateAuthorityFns = ({
let certificateId: string;
+ const parsedFields = extractExternallyIssuedCertificateFields(
+ Buffer.from(cleanedCertificatePem),
+ undefined,
+ certObj.serialNumber
+ );
+
await certificateDAL.transaction(async (tx) => {
const cert = await certificateDAL.create(
{
caId: ca.id,
profileId,
status: CertStatus.ACTIVE,
- friendlyName: commonName,
+ friendlyName: parsedFields.commonName ?? commonName,
commonName,
altNames: altNames.map((san) => san.value).join(","),
serialNumber: certObj.serialNumber,
@@ -858,7 +868,8 @@ export const VenafiTppCertificateAuthorityFns = ({
keyAlgorithm,
signatureAlgorithm,
projectId: ca.projectId,
- renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null
+ renewedFromCertificateId: isRenewal && originalCertificateId ? originalCertificateId : null,
+ ...parsedFields
},
tx
);
diff --git a/backend/src/services/certificate-common/certificate-constants.ts b/backend/src/services/certificate-common/certificate-constants.ts
index c8097f677d..beb5490edb 100644
--- a/backend/src/services/certificate-common/certificate-constants.ts
+++ b/backend/src/services/certificate-common/certificate-constants.ts
@@ -399,6 +399,17 @@ export const RESERVED_CERT_EXTENSION_OID_MESSAGES: Record<string, string> = {
"Use a UPN subject alternative name instead of declaring OID 1.3.6.1.4.1.311.20.2.3 as a custom extension."
};
+// Mirrored by ISSUER_GENERATED_EXTENSION_LABELS in the frontend's shared certificate-constants.ts,
+// which filters the renewal form. Add an OID to one and the two disagree.
+export const ISSUER_GENERATED_CERT_EXTENSION_OID_LABELS: Record<string, string> = {
+ "1.3.6.1.4.1.11129.2.4.2": "signed certificate timestamp list",
+ "1.3.6.1.4.1.11129.2.4.3": "precertificate poison",
+ "1.3.6.1.4.1.11129.2.4.5": "OCSP signed certificate timestamp list",
+ "1.3.101.75": "certificate transparency information",
+ "1.3.6.1.4.1.311.21.1": "certification authority version",
+ "1.3.6.1.4.1.311.21.2": "previous certification authority certificate hash"
+};
+
export const CERT_EXTENSION_OID_PATTERN_SOURCE = "[0-2](\\.(0|[1-9][0-9]{0,14})){1,20}";
const CERT_EXTENSION_OID_PATTERN = new RE2(`^${CERT_EXTENSION_OID_PATTERN_SOURCE}$`);
diff --git a/backend/src/services/certificate-common/certificate-csr-utils.test.ts b/backend/src/services/certificate-common/certificate-csr-utils.test.ts
index af3ec82b1d..0654e575a5 100644
--- a/backend/src/services/certificate-common/certificate-csr-utils.test.ts
+++ b/backend/src/services/certificate-common/certificate-csr-utils.test.ts
@@ -1,3 +1,4 @@
+import * as x509 from "@peculiar/x509";
import { describe, expect, it } from "vitest";
import { extractCertificateRequestFromCSR } from "./certificate-csr-utils";
@@ -94,3 +95,35 @@ describe("extractCertificateRequestFromCSR domain components", () => {
expect(request.organization).toBe("Acme");
});
});
+
+describe("extractCertificateRequestFromCSR custom extensions", () => {
+ const SCT_LIST_OID = "1.3.6.1.4.1.11129.2.4.2";
+ const CUSTOM_OID = "1.3.6.1.4.1.99999.7.1";
+
+ const buildCsr = async (extensions: x509.Extension[]) => {
+ const keys = await crypto.subtle.generateKey(
+ { name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" },
+ true,
+ ["sign", "verify"]
+ );
+
+ const csr = await x509.Pkcs10CertificateRequestGenerator.create({
+ name: "CN=host",
+ keys,
+ signingAlgorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
+ extensions
+ });
+
+ return csr.toString("pem");
+ };
+
+ // openssl x509 -x509toreq copies the issuer's own extensions into the request.
+ it("does not request an issuer-generated extension a certificate-derived CSR carried over", async () => {
+ const csr = await buildCsr([
+ new x509.Extension(SCT_LIST_OID, false, Buffer.from([0x04, 0x02, 0x00, 0x42])),
+ new x509.Extension(CUSTOM_OID, false, Buffer.from([0x0c, 0x03, 0x6f, 0x70, 0x73]))
+ ]);
+
+ expect(extractCertificateRequestFromCSR(csr).customExtensions?.map((entry) => entry.oid)).toEqual([CUSTOM_OID]);
+ });
+});
diff --git a/backend/src/services/certificate-common/certificate-csr-utils.ts b/backend/src/services/certificate-common/certificate-csr-utils.ts
index c61d8bc24a..33d9cc5c8b 100644
--- a/backend/src/services/certificate-common/certificate-csr-utils.ts
+++ b/backend/src/services/certificate-common/certificate-csr-utils.ts
@@ -28,6 +28,7 @@ import {
import {
appendCustomExtensions,
describeCustomExtensionValue,
+ isIssuerGeneratedExtensionOid,
isReservedExtensionOid,
TIssuedCustomExtension
} from "./certificate-extension-fns";
@@ -124,8 +125,10 @@ export const extractCertificateRequestFromCSR = (csr: string): TCertificateReque
};
}
+ // openssl x509 -x509toreq copies the old issuer's extensions in. Asking a new CA to repeat them
+ // gets the request rejected or produces a certificate that fails validation.
const csrCustomExtensions = csrObj.extensions
- .filter((extension) => !isReservedExtensionOid(extension.type))
+ .filter((extension) => !isReservedExtensionOid(extension.type) && !isIssuerGeneratedExtensionOid(extension.type))
.map((extension) => ({
oid: extension.type,
value:
diff --git a/backend/src/services/certificate-common/certificate-extension-fns.test.ts b/backend/src/services/certificate-common/certificate-extension-fns.test.ts
index 401f98555e..da0c8eb409 100644
--- a/backend/src/services/certificate-common/certificate-extension-fns.test.ts
+++ b/backend/src/services/certificate-common/certificate-extension-fns.test.ts
@@ -12,8 +12,11 @@ import {
findUnsatisfiedCustomExtensionOids,
isReservedExtensionOid,
parseCustomExtensionsFromCertificate,
+ parseExternallyIssuedCustomExtensions,
+ parseImportedCustomExtensions,
resolveCustomExtensions,
TCustomExtensionRule,
+ toCarriedCustomExtensions,
toRequestCustomExtensions,
TProfileCustomExtension,
validateCustomExtensionValue
@@ -24,9 +27,29 @@ const TEMPLATE_NAME_OID = "1.3.6.1.4.1.311.20.2";
const TEMPLATE_INFO_OID = "1.3.6.1.4.1.311.21.7";
const CUSTOM_OID = "1.3.6.1.4.1.99999.7.1";
const OPAQUE_OID = "1.3.6.1.4.1.311.21.20";
+const SCT_LIST_OID = "1.3.6.1.4.1.11129.2.4.2";
const SID = "S-1-5-21-1004336348-1177238915-682003330-1103";
+const buildCertificateWithExtension = async (oid: string, der: Buffer) => {
+ const keys = await crypto.subtle.generateKey(
+ { name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" },
+ true,
+ ["sign", "verify"]
+ );
+ const certificate = await x509.X509CertificateGenerator.createSelfSigned({
+ serialNumber: "01",
+ name: "CN=custom-extension-test",
+ notBefore: new Date(),
+ notAfter: new Date(Date.now() + 60 * 60 * 1000),
+ keys,
+ signingAlgorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
+ extensions: [new x509.Extension(oid, false, der)]
+ });
+
+ return Buffer.from(certificate.toString("pem"));
+};
+
describe("certificateExtensionOidSchema", () => {
it.each(["1.3.6.1.4.1.311.25.2", "2.999.1", "0.9.2342"])("accepts %s", (oid) => {
expect(certificateExtensionOidSchema.safeParse(oid).success).toBe(true);
@@ -661,3 +684,73 @@ describe("preset registry", () => {
});
});
});
+
+describe("toCarriedCustomExtensions", () => {
+ it("never carries an extension the upstream CA added of its own accord", () => {
+ const stored = [
+ { oid: OPAQUE_OID, critical: false, value: "BAIAQg==", issuerAdded: true },
+ { oid: CUSTOM_OID, critical: false, value: encodeCustomExtensionValue(CUSTOM_OID, "ops-prod") }
+ ];
+
+ expect(toCarriedCustomExtensions(stored).map((entry) => entry.oid)).toEqual([CUSTOM_OID]);
+ });
+
+ // Certificates stored before the flag existed rely on the OID list alone.
+ it.each([
+ [SCT_LIST_OID, "signed certificate timestamps"],
+ ["1.3.6.1.4.1.11129.2.4.3", "precertificate poison"],
+ ["1.3.101.75", "certificate transparency information"],
+ ["1.3.6.1.4.1.311.21.1", "ADCS certification authority version"],
+ ["1.3.6.1.4.1.311.21.2", "ADCS previous certification authority certificate hash"]
+ ])("never copies %s (%s) from one certificate to the next", (oid) => {
+ expect(toCarriedCustomExtensions([{ oid, critical: false, value: "BQA=" }])).toEqual([]);
+ });
+
+ // toRequestCustomExtensions throws on a non-text value, so the filter has to run before it.
+ it("does not throw on a binary issuer-written value that a plain reissue would refuse", () => {
+ const stored = [
+ { oid: SCT_LIST_OID, critical: false, value: Buffer.from([0x04, 0x02, 0x00, 0x42]).toString("base64") }
+ ];
+
+ expect(() => toRequestCustomExtensions(stored)).toThrow(/cannot be read back into a value/);
+ expect(toCarriedCustomExtensions(stored)).toEqual([]);
+ });
+});
+
+// This used to fail renewal with the very error this change removes.
+describe("parseImportedCustomExtensions", () => {
+ it("marks every extension issuer-added so a renewal never asks for it back", async () => {
+ const mustStaple = Buffer.from([0x30, 0x03, 0x02, 0x01, 0x05]);
+ const certificate = await buildCertificateWithExtension("1.3.6.1.5.5.7.1.24", mustStaple);
+
+ const stored = parseImportedCustomExtensions(certificate);
+
+ expect(stored).toEqual([{ oid: "1.3.6.1.5.5.7.1.24", critical: false, value: "MAMCAQU=", issuerAdded: true }]);
+ expect(() => toRequestCustomExtensions(stored)).toThrow(/cannot be read back into a value/);
+ expect(toCarriedCustomExtensions(stored)).toEqual([]);
+ });
+});
+
+describe("parseExternallyIssuedCustomExtensions", () => {
+ it("flags an extension the upstream CA added and leaves a requested one unmarked", async () => {
+ const certificate = await buildCertificateWithExtension(SCT_LIST_OID, Buffer.from([0x04, 0x02, 0x00, 0x42]));
+
+ expect(parseExternallyIssuedCustomExtensions(certificate)).toEqual([
+ { oid: SCT_LIST_OID, critical: false, value: "BAIAQg==", issuerAdded: true }
+ ]);
+ expect(
+ parseExternallyIssuedCustomExtensions(certificate, [{ oid: SCT_LIST_OID, critical: false, value: "BAIAQg==" }])
+ ).toEqual([{ oid: SCT_LIST_OID, critical: false, value: "BAIAQg==" }]);
+ });
+
+ // The CA can rewrite what it was asked for, so the record has to come off the certificate.
+ it("records the value the certificate carries when the CA rewrote a requested extension", async () => {
+ const certificate = await buildCertificateWithExtension(CUSTOM_OID, Buffer.from([0x04, 0x02, 0x00, 0x43]));
+
+ expect(
+ parseExternallyIssuedCustomExtensions(certificate, [
+ { oid: CUSTOM_OID, critical: false, value: encodeCustomExtensionValue(CUSTOM_OID, "ops-prod") }
+ ])
+ ).toEqual([{ oid: CUSTOM_OID, critical: false, value: "BAIAQw==" }]);
+ });
+});
diff --git a/backend/src/services/certificate-common/certificate-extension-fns.ts b/backend/src/services/certificate-common/certificate-extension-fns.ts
index d995a40b6c..9caa019e97 100644
--- a/backend/src/services/certificate-common/certificate-extension-fns.ts
+++ b/backend/src/services/certificate-common/certificate-extension-fns.ts
@@ -9,6 +9,7 @@ import {
CERT_EXTENSION_OID_PATTERN_SOURCE,
CertExtensionCriticality,
CUSTOM_EXTENSION_PRESET_OIDS,
+ ISSUER_GENERATED_CERT_EXTENSION_OID_LABELS,
MAX_CUSTOM_EXTENSION_VALUE_BYTES,
MAX_CUSTOM_EXTENSIONS_PER_AWS_PCA_PROFILE,
RESERVED_CERT_EXTENSION_OID_MESSAGES,
@@ -20,6 +21,7 @@ export type TIssuedCustomExtension = {
critical: boolean;
value: string;
displayValue?: string;
+ issuerAdded?: boolean;
};
export type TResolvedCustomExtension = TIssuedCustomExtension;
@@ -190,6 +192,9 @@ export const isReservedExtensionOid = (oid: string): boolean =>
RESERVED_CERT_EXTENSION_OID_PREFIXES.some((prefix) => oid.startsWith(prefix)) ||
Object.hasOwn(RESERVED_CERT_EXTENSION_OID_MESSAGES, oid);
+export const isIssuerGeneratedExtensionOid = (oid: string): boolean =>
+ Object.hasOwn(ISSUER_GENERATED_CERT_EXTENSION_OID_LABELS, oid);
+
export const describeReservedExtensionOid = (oid: string): string =>
RESERVED_CERT_EXTENSION_OID_MESSAGES[oid] ??
`OID ${oid} is a standard X.509 extension that Infisical manages, so it cannot be used as a custom extension.`;
@@ -274,7 +279,23 @@ export const parseIssuedCustomExtensions = (
};
export const parseImportedCustomExtensions = (certificateDer: Buffer): TIssuedCustomExtension[] =>
- withDisplayValue(parseCustomExtensionsFromCertificate(certificateDer));
+ withDisplayValue(parseCustomExtensionsFromCertificate(certificateDer)).map((extension) => ({
+ ...extension,
+ issuerAdded: true
+ }));
+
+export const parseExternallyIssuedCustomExtensions = (
+ certificateDer: Buffer,
+ requested?: TResolvedCustomExtension[]
+): TIssuedCustomExtension[] => {
+ const requestedOids = new Set((requested ?? []).map((extension) => extension.oid));
+
+ return withDisplayValue(
+ parseCustomExtensionsFromCertificate(certificateDer).map((extension) =>
+ requestedOids.has(extension.oid) ? extension : { ...extension, issuerAdded: true }
+ )
+ );
+};
export type TCsrCustomExtensionMismatch = { oid: string; reason: "missing" | "value" | "criticality" };
@@ -317,8 +338,11 @@ export const findUnsatisfiedCustomExtensionOids = (
.map((extension) => extension.oid);
};
+const readStoredCustomExtensions = (stored: unknown): TResolvedCustomExtension[] =>
+ (stored as TResolvedCustomExtension[] | null) ?? [];
+
export const toRequestCustomExtensions = (stored: unknown): TRequestCustomExtension[] =>
- ((stored as TResolvedCustomExtension[] | null) ?? []).flatMap((extension) => {
+ readStoredCustomExtensions(stored).flatMap((extension) => {
const value = describeCustomExtensionValue(extension.oid, extension.value);
if (value === null) {
throw new BadRequestError({
@@ -334,6 +358,13 @@ export const toRequestCustomExtensions = (stored: unknown): TRequestCustomExtens
];
});
+export const toCarriedCustomExtensions = (stored: unknown): TRequestCustomExtension[] =>
+ toRequestCustomExtensions(
+ readStoredCustomExtensions(stored).filter(
+ (extension) => !extension.issuerAdded && !isIssuerGeneratedExtensionOid(extension.oid)
+ )
+ );
+
export const assertAwsPcaCustomExtensionLimit = (count: number): void => {
if (count > MAX_CUSTOM_EXTENSIONS_PER_AWS_PCA_PROFILE) {
throw new BadRequestError({
diff --git a/backend/src/services/certificate-v3/certificate-renewal-fns.ts b/backend/src/services/certificate-v3/certificate-renewal-fns.ts
index 735c19d501..3981c66820 100644
--- a/backend/src/services/certificate-v3/certificate-renewal-fns.ts
+++ b/backend/src/services/certificate-v3/certificate-renewal-fns.ts
@@ -22,7 +22,11 @@ import {
extractAlgorithmsFromCSR,
extractCertificateRequestFromCSR
} from "../certificate-common/certificate-csr-utils";
-import { toRequestCustomExtensions, TRequestCustomExtension } from "../certificate-common/certificate-extension-fns";
+import {
+ isIssuerGeneratedExtensionOid,
+ toCarriedCustomExtensions,
+ TRequestCustomExtension
+} from "../certificate-common/certificate-extension-fns";
import { mapEnumsForValidation } from "../certificate-common/certificate-utils";
import { TCertificateRequest } from "../certificate-policy/certificate-policy-types";
import { parseExtendedKeyUsages, parseKeyUsages } from "./certificate-v3-fns";
@@ -86,9 +90,11 @@ const text = (value: string | null | undefined) => value ?? "";
const describeStoredCustomExtensions = (stored: unknown): TRequestCustomExtension[] => {
try {
- return toRequestCustomExtensions(stored);
+ return toCarriedCustomExtensions(stored);
} catch {
- return ((stored as { oid: string }[] | null) ?? []).map(({ oid }) => ({ oid, value: "" }));
+ return ((stored as { oid: string; issuerAdded?: boolean }[] | null) ?? [])
+ .filter((extension) => !extension.issuerAdded && !isIssuerGeneratedExtensionOid(extension.oid))
+ .map(({ oid }) => ({ oid, value: "" }));
}
};
diff --git a/backend/src/services/certificate-v3/certificate-renewal-service.ts b/backend/src/services/certificate-v3/certificate-renewal-service.ts
index 342555c7f6..372d8979b2 100644
--- a/backend/src/services/certificate-v3/certificate-renewal-service.ts
+++ b/backend/src/services/certificate-v3/certificate-renewal-service.ts
@@ -27,7 +27,7 @@ import { assertCaInProfileProject } from "@app/services/certificate-authority/ce
import { caSupportsCapability } from "@app/services/certificate-authority/certificate-authority-maps";
import { TInternalCertificateAuthorityServiceFactory } from "@app/services/certificate-authority/internal/internal-certificate-authority-service";
import {
- toRequestCustomExtensions,
+ toCarriedCustomExtensions,
TProfileCustomExtension,
TResolvedCustomExtension
} from "@app/services/certificate-common/certificate-extension-fns";
@@ -738,7 +738,7 @@ export const certificateRenewalServiceFactory = ({
}) => {
const originalTtl = certificateSpanToTtl(originalCert.notBefore, originalCert.notAfter);
- const carriedCustomExtensions = toRequestCustomExtensions(originalCert.customExtensions);
+ const carriedCustomExtensions = toCarriedCustomExtensions(originalCert.customExtensions);
const originalRequest: TCertificateRequest = {
commonName: originalCert.commonName || undefined,
diff --git a/backend/src/services/certificate/certificate-fns.test.ts b/backend/src/services/certificate/certificate-fns.test.ts
index b28a881008..8488933021 100644
--- a/backend/src/services/certificate/certificate-fns.test.ts
+++ b/backend/src/services/certificate/certificate-fns.test.ts
@@ -8,6 +8,7 @@ import {
buildCertificateBundle,
CertificateThumbprintAlgorithm,
extractCertificateFields,
+ extractExternallyIssuedCertificateFields,
normalizeThumbprint,
parseCertificateBody
} from "./certificate-fns";
@@ -145,3 +146,106 @@ describe("parseCertificateBody usages", () => {
expect(fields.extendedKeyUsages).toEqual(["serverAuth", "smartCardLogon"]);
});
});
+
+describe("extractExternallyIssuedCertificateFields", () => {
+ x509.cryptoProvider.set(webcrypto as unknown as Crypto);
+
+ const SCT_LIST_OID = "1.3.6.1.4.1.11129.2.4.2";
+ const TEMPLATE_NAME_OID = "1.3.6.1.4.1.311.20.2";
+
+ const buildIssuedCert = async (extensions: x509.Extension[], name = "CN=issued.example.com,O=Issued Corp") => {
+ const keys = await webcrypto.subtle.generateKey(
+ {
+ name: "RSASSA-PKCS1-v1_5",
+ hash: "SHA-384",
+ publicExponent: new Uint8Array([1, 0, 1]),
+ modulusLength: 3072
+ },
+ true,
+ ["sign", "verify"]
+ );
+
+ const cert = await x509.X509CertificateGenerator.createSelfSigned({
+ serialNumber: "02",
+ name,
+ notBefore: new Date("2026-01-01"),
+ notAfter: new Date("2027-01-01"),
+ keys: keys as CryptoKeyPair,
+ signingAlgorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-384" },
+ extensions
+ });
+
+ return Buffer.from(cert.toString("pem"));
+ };
+
+ test("records every extension the certificate carries, flagging the ones the request never asked for", async () => {
+ const requestedValue = Buffer.from([0x0c, 0x07, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65]);
+ const pem = await buildIssuedCert([
+ new x509.Extension(TEMPLATE_NAME_OID, false, requestedValue),
+ new x509.Extension(SCT_LIST_OID, false, Buffer.from([0x04, 0x02, 0x00, 0x42]))
+ ]);
+
+ const fields = extractExternallyIssuedCertificateFields(pem, [
+ { oid: TEMPLATE_NAME_OID, critical: false, value: requestedValue.toString("base64") }
+ ]);
+
+ expect(JSON.parse(fields.customExtensions as string)).toEqual([
+ { oid: SCT_LIST_OID, critical: false, value: "BAIAQg==", issuerAdded: true },
+ { oid: TEMPLATE_NAME_OID, critical: false, value: requestedValue.toString("base64") }
+ ]);
+ });
+
+ test("reads the subject, algorithms and subject alternative names the CA actually issued", async () => {
+ const pem = await buildIssuedCert([
+ new x509.SubjectAlternativeNameExtension([
+ { type: "dns", value: "issued.example.com" },
+ { type: "dns", value: "added-by-ca.example.com" }
+ ])
+ ]);
+
+ const fields = extractExternallyIssuedCertificateFields(pem);
+
+ expect(fields.commonName).toBe("issued.example.com");
+ expect(fields.subjectOrganization).toBe("Issued Corp");
+ expect(fields.altNames).toBe("issued.example.com,added-by-ca.example.com");
+ expect(fields.keyAlgorithm).toBe("RSA_3072");
+ expect(fields.signatureAlgorithm).toBe("RSA-SHA384");
+ });
+
+ // Otherwise each renewal asks for the duplicate again and the list grows until it overruns 4096.
+ test("collapses a repeated subject alternative name so renewals cannot accumulate copies", async () => {
+ const pem = await buildIssuedCert([
+ new x509.SubjectAlternativeNameExtension([
+ { type: "dns", value: "issued.example.com" },
+ { type: "dns", value: "added.example.com" },
+ { type: "dns", value: "issued.example.com" }
+ ])
+ ]);
+
+ const fields = extractExternallyIssuedCertificateFields(pem);
+
+ expect(fields.altNames).toBe("issued.example.com,added.example.com");
+ });
+
+ test("drops subject alternative names that would not fit the column rather than truncating one", async () => {
+ const many = Array.from({ length: 200 }, (_, index) => ({
+ type: "dns" as const,
+ value: `host-${String(index).padStart(3, "0")}.${"padding".repeat(4)}.example.com`
+ }));
+ const pem = await buildIssuedCert([new x509.SubjectAlternativeNameExtension(many)]);
+
+ const fields = extractExternallyIssuedCertificateFields(pem);
+
+ expect(many.map((san) => san.value).join(",").length).toBeGreaterThan(4096);
+ expect(fields).not.toHaveProperty("altNames");
+ });
+
+ test("leaves the requested subject alternative names in place when the certificate carries none", async () => {
+ const pem = await buildIssuedCert([new x509.BasicConstraintsExtension(false)]);
+
+ const fields = extractExternallyIssuedCertificateFields(pem);
+
+ expect(fields).not.toHaveProperty("altNames");
+ expect({ altNames: "requested.example.com", ...fields }.altNames).toBe("requested.example.com");
+ });
+});
diff --git a/backend/src/services/certificate/certificate-fns.ts b/backend/src/services/certificate/certificate-fns.ts
index b1a47d41d6..302cfe4ea7 100644
--- a/backend/src/services/certificate/certificate-fns.ts
+++ b/backend/src/services/certificate/certificate-fns.ts
@@ -5,7 +5,13 @@ import RE2 from "re2";
import { crypto } from "@app/lib/crypto/cryptography";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
+import { logger } from "@app/lib/logger";
import {
+ PKI_ALT_NAMES_COLUMN_MAX_LENGTH,
+ SUPPORTED_GENERAL_NAME_TYPES
+} from "@app/services/certificate-common/certificate-constants";
+import {
+ parseExternallyIssuedCustomExtensions,
parseIssuedCustomExtensions,
TResolvedCustomExtension
} from "@app/services/certificate-common/certificate-extension-fns";
@@ -312,6 +318,9 @@ export const parseCertificateBody = (decryptedCertificate: Buffer): TParsedCerti
}
};
+const KEY_ALGORITHM_VALUES = new Set<string>(Object.values(CertKeyAlgorithm));
+const SIGNATURE_ALGORITHM_VALUES = new Set<string>(Object.values(CertSignatureAlgorithm));
+
const EC_CURVE_KEY_ALGORITHMS: Record<string, CertKeyAlgorithm> = {
"P-256": CertKeyAlgorithm.ECDSA_P256,
"P-384": CertKeyAlgorithm.ECDSA_P384,
@@ -413,6 +422,80 @@ export const extractCertificateFields = (decryptedCertificate: Buffer, resolved?
};
};
+const extractIssuedAltNames = (decryptedCertificate: Buffer, serialNumber?: string): string | null => {
+ try {
+ const sanExtension = new x509.X509Certificate(decryptedCertificate).getExtension("2.5.29.17");
+ if (!sanExtension) return null;
+
+ const values = [
+ ...new Set(
+ new x509.GeneralNames(sanExtension.value).items
+ .filter((item) => SUPPORTED_GENERAL_NAME_TYPES.has(item.type))
+ .map((item) => item.value)
+ )
+ ];
+
+ if (!values.length) return null;
+
+ const joined = values.join(",");
+ if (joined.length <= PKI_ALT_NAMES_COLUMN_MAX_LENGTH) return joined;
+
+ logger?.warn(
+ `Issued certificate carries ${values.length} subject alternative names, over the ${PKI_ALT_NAMES_COLUMN_MAX_LENGTH} the column holds, so none were recorded [serialNumber=${serialNumber ?? "unknown"}]`
+ );
+ return null;
+ } catch (err) {
+ logger?.warn(
+ err,
+ `Could not read the subject alternative names off an issued certificate [serialNumber=${serialNumber ?? "unknown"}]`
+ );
+ return null;
+ }
+};
+
+const safeExtractCertificateAlgorithms = (decryptedCertificate: Buffer, serialNumber?: string) => {
+ try {
+ const algorithms = extractCertificateAlgorithms(decryptedCertificate);
+
+ const offEnum = [
+ !!algorithms.keyAlgorithm && !KEY_ALGORITHM_VALUES.has(algorithms.keyAlgorithm) && algorithms.keyAlgorithm,
+ !!algorithms.signatureAlgorithm &&
+ !SIGNATURE_ALGORITHM_VALUES.has(algorithms.signatureAlgorithm) &&
+ algorithms.signatureAlgorithm
+ ].filter(Boolean);
+
+ if (offEnum.length) {
+ logger?.warn(
+ `Issued certificate uses ${offEnum.join(" and ")}, which is outside the algorithms this platform can request, so a renewal cannot ask for it again [serialNumber=${serialNumber ?? "unknown"}]`
+ );
+ }
+
+ return algorithms;
+ } catch (err) {
+ logger?.warn(
+ err,
+ `Could not name the algorithms on an issued certificate, so the requested ones stand [serialNumber=${serialNumber ?? "unknown"}]`
+ );
+ return {};
+ }
+};
+
+export const extractExternallyIssuedCertificateFields = (
+ decryptedCertificate: Buffer,
+ requestedCustomExtensions?: TResolvedCustomExtension[],
+ serialNumber?: string
+) => {
+ const issuedCustomExtensions = parseExternallyIssuedCustomExtensions(decryptedCertificate, requestedCustomExtensions);
+ const altNames = extractIssuedAltNames(decryptedCertificate, serialNumber);
+
+ return {
+ ...extractCertificateFields(decryptedCertificate),
+ ...safeExtractCertificateAlgorithms(decryptedCertificate, serialNumber),
+ ...(altNames !== null && { altNames }),
+ customExtensions: issuedCustomExtensions.length ? JSON.stringify(issuedCustomExtensions) : null
+ };
+};
+
export const linkRenewedCertificate = async (
certificateDAL: Pick<TCertificateDALFactory, "findById" | "updateById">,
originalCertificateId: string,
diff --git a/frontend/src/hooks/api/certificates/types.ts b/frontend/src/hooks/api/certificates/types.ts
index 05d24facdd..389c6282bf 100644
--- a/frontend/src/hooks/api/certificates/types.ts
+++ b/frontend/src/hooks/api/certificates/types.ts
@@ -33,6 +33,7 @@ export type TCertificateCustomExtension = {
critical: boolean;
value: string;
displayValue?: string;
+ issuerAdded?: boolean;
};
export type TCertificate = {
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.ts b/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.ts
index 57d8bbada1..7408339bf0 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.ts
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.ts
@@ -8,7 +8,8 @@ import {
CertExtendedKeyUsageType,
CertKeyUsageType,
CertSubjectAlternativeNameType,
- CertSubjectAttributeType
+ CertSubjectAttributeType,
+ isIssuerGeneratedExtensionOid
} from "@app/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants";
import type { RenewalFormData } from "./CertificateRenewalModal";
@@ -127,7 +128,12 @@ export const buildRenewalFormDefaults = (
keyUsages: toUsageFormKeys(cert.keyUsages, KEY_USAGE_BY_NAME),
extendedKeyUsages: toUsageFormKeys(cert.extendedKeyUsages, EXTENDED_KEY_USAGE_BY_NAME),
customExtensions: (cert.customExtensions ?? [])
- .filter((extension) => extension.displayValue !== undefined)
+ .filter(
+ (extension) =>
+ extension.displayValue !== undefined &&
+ !extension.issuerAdded &&
+ !isIssuerGeneratedExtensionOid(extension.oid)
+ )
.map((extension) => ({ oid: extension.oid, value: extension.displayValue as string }))
});
diff --git a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants.ts b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants.ts
index 92b6241a13..71630c2545 100644
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants.ts
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants.ts
@@ -410,8 +410,25 @@ export const getPresetExtensionCriticality = (oid: string): CertExtensionCritica
export const isPresetExtensionOid = (oid: string) => Boolean(getCustomExtensionPreset(oid));
+// Mirrored by ISSUER_GENERATED_CERT_EXTENSION_OID_LABELS in the backend's certificate-constants.ts,
+// which does the real filtering. Add an OID to one and the two disagree.
+export const ISSUER_GENERATED_EXTENSION_LABELS: Record<string, string> = {
+ "1.3.6.1.4.1.11129.2.4.2": "Signed certificate timestamps",
+ "1.3.6.1.4.1.11129.2.4.3": "Precertificate poison",
+ "1.3.6.1.4.1.11129.2.4.5": "OCSP signed certificate timestamps",
+ "1.3.101.75": "Certificate transparency information",
+ "1.3.6.1.4.1.311.21.1": "CA version",
+ "1.3.6.1.4.1.311.21.2": "Previous CA certificate hash"
+};
+
+export const isIssuerGeneratedExtensionOid = (oid: string) =>
+ Object.prototype.hasOwnProperty.call(ISSUER_GENERATED_EXTENSION_LABELS, oid);
+
export const customExtensionLabelFor = (oid: string, label?: string | null) =>
- label?.trim() || getCustomExtensionPreset(oid)?.label || oid;
+ label?.trim() ||
+ getCustomExtensionPreset(oid)?.label ||
+ ISSUER_GENERATED_EXTENSION_LABELS[oid] ||
+ oid;
export const validateCustomExtensionValue = (oid: string, value: string): string | null => {
const preset = getCustomExtensionPreset(oid);