Skip to content

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

Merge remote-tracking branch 'origin/main' into feat/digicert-tls-reissue

Carlos Monastyrski73bdaa25c6d8
diff --cc backend/src/ee/services/audit-log/audit-log-types.ts
index 2f12ad56f6,2177b1c912..d16e948674
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@@ -43,16 -43,12 +43,16 @@@ import { CaStatus } from "@app/services
import { CertificateIssuanceOperation } from "@app/services/certificate-common/certificate-constants";
import { EnrollmentType } from "@app/services/certificate-profile/certificate-profile-types";
import { CertificateRequestStatus } from "@app/services/certificate-request/certificate-request-types";
-import { CertificateRenewalKeySource, TRenewalAuditChange } from "@app/services/certificate-v3/certificate-v3-types";
+import {
+ CertificateRenewalKeySource,
+ TRenewalAuditChange,
+ TRenewCertificateDTO
+} from "@app/services/certificate-v3/certificate-v3-types";
import {
CertExtendedKeyUsage,
- CertificateDeletionEligibility,
CertKeyAlgorithm,
CertKeyUsage,
+ CertStatus,
CrlReason
} from "@app/services/certificate/certificate-types";
import type { ExternalMigrationImportStatus } from "@app/services/external-migration/external-migration-types";
diff --cc backend/src/services/certificate-authority/certificate-issuance-queue.test.ts
index 0b11ae5af1,0000000000..f12c2190c5
mode 100644,000000..100644
--- a/backend/src/services/certificate-authority/certificate-issuance-queue.test.ts
+++ b/backend/src/services/certificate-authority/certificate-issuance-queue.test.ts
@@@ -1,147 -1,0 +1,148 @@@
+import { CertificateRequestStatus } from "../certificate-request/certificate-request-types";
+import { CaType } from "./certificate-authority-enums";
+import { certificateIssuanceQueueFactory, TIssueCertificateFromProfileJobData } from "./certificate-issuance-queue";
+
+const digicertFns = {
+ orderCertificate: vi.fn(),
+ reissueCertificate: vi.fn(),
+ cancelReissue: vi.fn(),
+ fetchAndAttachIssuedCertificate: vi.fn()
+};
+
+vi.mock("@app/lib/logger", () => ({ logger: { info: vi.fn(), error: vi.fn(), warn: vi.fn(), debug: vi.fn() } }));
+vi.mock("./digicert/digicert-certificate-authority-fns", () => ({
+ DigiCertCertificateAuthorityFns: () => digicertFns
+}));
+
+const CA_ID = "ca-1";
+const ORDER_ID = 7001;
+const ORIGINAL_CERTIFICATE_ID = "00000000-0000-4000-8000-000000000001";
+const CERTIFICATE_REQUEST_ID = "00000000-0000-4000-8000-000000000002";
+
+const stubDeps = () => {
+ const stubs = new Map<string, unknown>();
+ return new Proxy({} as Record<string, unknown>, {
+ get: (_target, property: string) => {
+ if (!stubs.has(property)) stubs.set(property, vi.fn());
+ return stubs.get(property);
+ }
+ });
+};
+
+const buildQueue = () => {
+ let runJob: ((job: { data: TIssueCertificateFromProfileJobData }) => Promise<void>) | undefined;
+ const queueService = {
+ start: vi.fn((_queue: string, handler: typeof runJob) => {
+ runJob = handler;
+ }),
+ queue: vi.fn()
+ };
+ const certificateAuthorityDAL = {
+ findByIdWithAssociatedCa: vi.fn().mockResolvedValue({
+ id: CA_ID,
+ projectId: "project-1",
+ externalCa: { id: "external-ca-1", type: CaType.DIGICERT }
+ })
+ };
+ const certificateDAL = {
++ primaryNode: vi.fn(),
+ findById: vi.fn().mockResolvedValue({
+ id: ORIGINAL_CERTIFICATE_ID,
+ externalMetadata: { type: CaType.DIGICERT, orderId: ORDER_ID, certificateId: 50001 }
+ })
+ };
+ const certificateRequestDAL = {
+ findById: vi.fn().mockResolvedValue({ id: CERTIFICATE_REQUEST_ID, status: CertificateRequestStatus.PENDING }),
+ setPendingMessage: vi.fn(),
+ transitionToPendingValidation: vi.fn().mockResolvedValue(true)
+ };
+
+ certificateIssuanceQueueFactory({
+ ...stubDeps(),
+ queueService,
+ certificateAuthorityDAL,
+ certificateDAL,
+ certificateRequestDAL
+ } as unknown as Parameters<typeof certificateIssuanceQueueFactory>[0]);
+
+ const run = (data: Partial<TIssueCertificateFromProfileJobData>) =>
+ runJob!({
+ data: {
+ certificateId: "renewal-1",
+ caId: CA_ID,
+ caType: CaType.DIGICERT,
+ commonName: "example.com",
+ altNames: [{ type: "dns_name", value: "example.com" }],
+ ttl: "90d",
+ signatureAlgorithm: "RSA-SHA256",
+ keyAlgorithm: "RSA_2048",
+ isRenewal: true,
+ originalCertificateId: ORIGINAL_CERTIFICATE_ID,
+ certificateRequestId: CERTIFICATE_REQUEST_ID,
+ ...data
+ }
+ });
+ return Object.assign(run, { certificateRequestDAL });
+};
+
+const digicertResult = {
+ metadata: {
+ digicert: {
+ orderId: ORDER_ID,
+ productNameId: "ssl_basic",
+ organizationId: 777,
+ orderPlacedAt: new Date().toISOString()
+ }
+ },
+ privateKey: "",
+ orderId: ORDER_ID
+};
+
+describe("certificate issuance queue, DigiCert renewals", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ digicertFns.orderCertificate.mockResolvedValue(digicertResult);
+ digicertFns.reissueCertificate.mockResolvedValue(digicertResult);
+ });
+
+ test("reissues on the original certificate's DigiCert order when reissue is requested", async () => {
+ const runJob = buildQueue();
+
+ await runJob({ externalConfiguration: { reissue: true } });
+
+ expect(digicertFns.reissueCertificate).toHaveBeenCalledWith(
+ expect.objectContaining({ caId: CA_ID, orderId: ORDER_ID, originalCertificateId: ORIGINAL_CERTIFICATE_ID })
+ );
+ expect(digicertFns.orderCertificate).not.toHaveBeenCalled();
+ });
+
+ test("places a new order linked to the original order for a plain renewal", async () => {
+ const runJob = buildQueue();
+
+ await runJob({});
+
+ expect(digicertFns.orderCertificate).toHaveBeenCalledWith(
+ expect.objectContaining({ caId: CA_ID, renewalOfOrderId: ORDER_ID })
+ );
+ expect(digicertFns.reissueCertificate).not.toHaveBeenCalled();
+ });
+
+ test("hands a reissue to the poller before DigiCert is called", async () => {
+ const runJob = buildQueue();
+ const reissueMetadata = { ...digicertResult.metadata.digicert, previousCertificateId: 50001 };
+ digicertFns.reissueCertificate.mockImplementation(
+ async ({ onBeforeSubmit }: { onBeforeSubmit: (prepared: object) => Promise<void> }) => {
+ await onBeforeSubmit({ metadata: { digicert: reissueMetadata }, privateKey: "" });
+ expect(runJob.certificateRequestDAL.transitionToPendingValidation).toHaveBeenCalledWith(
+ CERTIFICATE_REQUEST_ID,
+ expect.objectContaining({ metadata: expect.stringContaining('"previousCertificateId":50001') as string })
+ );
+ return digicertResult;
+ }
+ );
+
+ await runJob({ externalConfiguration: { reissue: true }, csr: "csr" });
+
+ expect(runJob.certificateRequestDAL.transitionToPendingValidation).toHaveBeenCalledTimes(1);
+ });
+});
diff --cc backend/src/services/certificate-authority/digicert/digicert-revocation-sync-queue.ts
index 509ed43c95,3813bb921b..a9af672c04
--- a/backend/src/services/certificate-authority/digicert/digicert-revocation-sync-queue.ts
+++ b/backend/src/services/certificate-authority/digicert/digicert-revocation-sync-queue.ts
@@@ -70,19 -56,17 +70,20 @@@ export const digicertRevocationSyncQueu
}: TDigiCertRevocationSyncQueueFactoryDep) => {
const appCfg = getConfig();
- const markCertificateRevokedLocally = async (cert: {
- id: string;
- commonName: string;
- serialNumber: string;
- projectId: string;
- applicationId?: string | null;
- deletedAt?: Date | null;
- }) => {
+ const markCertificateRevokedLocally = async (
+ cert: {
+ id: string;
+ commonName: string;
+ serialNumber: string;
+ projectId: string;
+ applicationId?: string | null;
++ deletedAt?: Date | null;
+ },
+ revokedAt = new Date()
+ ) => {
await certificateDAL.updateById(cert.id, {
status: CertStatus.REVOKED,
- revokedAt: new Date(),
+ revokedAt,
revocationReason: revocationReasonToCrlCode(CrlReason.UNSPECIFIED)
});
diff --cc backend/src/services/certificate/certificate-dal.ts
index 62c3195d5a,f216ef7574..913793a539
--- a/backend/src/services/certificate/certificate-dal.ts
+++ b/backend/src/services/certificate/certificate-dal.ts
@@@ -130,29 -132,6 +132,29 @@@ export const certificateDALFactory = (d
}
};
+ const findActiveDigiCertCertsReplacedOnOrder = async (caId: string) => {
+ try {
+ const certs = await db
+ .replicaNode()(TableName.Certificate)
+ .where({ caId, status: CertStatus.ACTIVE })
+ .where("notAfter", ">", new Date())
+ .whereRaw(`"externalMetadata"->>'type' = ?`, ["digicert"])
+ .whereExists((qb) => {
+ void qb
+ .select(db.raw("1"))
+ .from({ newer: TableName.Certificate })
+ .whereRaw(`newer."caId" = ${TableName.Certificate}."caId"`)
+ .whereRaw(`newer."externalMetadata"->>'orderId' = ${TableName.Certificate}."externalMetadata"->>'orderId'`)
+ .whereRaw(`newer."createdAt" > ${TableName.Certificate}."createdAt"`);
+ })
- .select("id", "commonName", "serialNumber", "projectId", "applicationId");
++ .select("id", "commonName", "serialNumber", "projectId", "applicationId", "deletedAt");
+
+ return certs;
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Find active DigiCert certs replaced on their order" });
+ }
+ };
+
type TInventoryFilterParams = {
friendlyName?: string;
commonName?: string;
diff --cc backend/src/services/certificate/certificate-ocsp-client.test.ts
index f8c7de531c,0000000000..0a5a58b833
mode 100644,000000..100644
--- a/backend/src/services/certificate/certificate-ocsp-client.test.ts
+++ b/backend/src/services/certificate/certificate-ocsp-client.test.ts
@@@ -1,124 -1,0 +1,124 @@@
+import { webcrypto } from "node:crypto";
+
+import * as x509 from "@peculiar/x509";
+import * as pkijs from "pkijs";
+
+import { OcspCertStatus } from "@app/ee/services/certificate-authority-ocsp/certificate-authority-ocsp-enums";
+import {
+ buildSignedOcspResponse,
+ parseOcspRequest
+} from "@app/ee/services/certificate-authority-ocsp/certificate-authority-ocsp-fns";
+import { TOcspCertStatus } from "@app/ee/services/certificate-authority-ocsp/certificate-authority-ocsp-types";
+import { asNonSharedBuffer } from "@app/lib/fn";
+import { TCaSigner } from "@app/services/certificate-authority/ca-signer";
+
+import { getCertificateOcspStatus } from "./certificate-ocsp-client";
+
+const post = vi.fn<(url: string, body: Buffer) => Promise<{ data: ArrayBuffer }>>();
+vi.mock("@app/lib/validator/safe-request", () => ({
+ safeRequest: { post: (url: string, body: Buffer) => post(url, body) }
+}));
+
+const RSA_ALG: RsaHashedKeyGenParams = {
+ name: "RSASSA-PKCS1-v1_5",
+ hash: "SHA-256",
+ publicExponent: new Uint8Array([1, 0, 1]),
+ modulusLength: 2048
+};
+const OCSP_URL = "http://ocsp.example.com";
+const REVOKED_AT = new Date("2026-10-28T09:02:41.000Z");
+
+const createCa = async (name: string) => {
+ const keys = (await webcrypto.subtle.generateKey(RSA_ALG, true, ["sign", "verify"])) as CryptoKeyPair;
+ const certificate = await x509.X509CertificateGenerator.createSelfSigned({
+ serialNumber: "01",
+ name,
+ notBefore: new Date(Date.now() - 86_400_000),
+ notAfter: new Date(Date.now() + 86_400_000),
+ signingAlgorithm: RSA_ALG,
+ keys,
+ extensions: [new x509.BasicConstraintsExtension(true, 2, true)]
+ });
+ const signer = {
+ caPublicKey: keys.publicKey,
+ signingAlgorithm: RSA_ALG,
+ signTbs: (tbs: Buffer) => webcrypto.subtle.sign(RSA_ALG, keys.privateKey, asNonSharedBuffer(tbs))
+ } as unknown as TCaSigner;
+ return { keys, certificate, signer };
+};
+
+let issuingCa: Awaited<ReturnType<typeof createCa>>;
+let otherCa: Awaited<ReturnType<typeof createCa>>;
+let leafCertificate: x509.X509Certificate;
+
+const respondWith = (status: TOcspCertStatus, responder = issuingCa) =>
+ post.mockImplementation(async (_url: string, body: Buffer) => {
+ const parsed = parseOcspRequest(body);
+ const data = await buildSignedOcspResponse({
+ signer: responder.signer,
+ caCertificate: responder.certificate,
+ statuses: parsed!.entries.map((entry) => ({ entry, status })),
+ thisUpdate: new Date(),
+ nextUpdate: new Date(Date.now() + 3_600_000)
+ });
+ return { data: new Uint8Array(data).buffer };
+ });
+
+beforeAll(async () => {
+ x509.cryptoProvider.set(webcrypto as unknown as Crypto);
+ pkijs.setEngine("test", new pkijs.CryptoEngine({ crypto: webcrypto as unknown as Crypto }));
+
+ issuingCa = await createCa("CN=Example Issuing CA");
+ otherCa = await createCa("CN=Example Other CA");
+
+ const leafKeys = (await webcrypto.subtle.generateKey(RSA_ALG, true, ["sign", "verify"])) as CryptoKeyPair;
+ leafCertificate = await x509.X509CertificateGenerator.create({
+ serialNumber: "4f2a9c1b33",
+ subject: "CN=example.com",
+ issuer: issuingCa.certificate.subject,
+ notBefore: new Date(Date.now() - 3_600_000),
+ notAfter: new Date(Date.now() + 3_600_000),
+ signingKey: issuingCa.keys.privateKey,
+ publicKey: leafKeys.publicKey,
+ signingAlgorithm: RSA_ALG,
+ extensions: [new x509.AuthorityInfoAccessExtension({ ocsp: [new x509.GeneralName("url", OCSP_URL)] })]
+ });
+});
+
+describe("getCertificateOcspStatus", () => {
+ beforeEach(() => {
+ post.mockReset();
+ });
+
+ test("reports a good certificate", async () => {
+ respondWith({ kind: OcspCertStatus.Good });
+
+ await expect(
+ getCertificateOcspStatus({ certificate: leafCertificate, issuer: issuingCa.certificate })
+ ).resolves.toEqual({ status: OcspCertStatus.Good });
- expect(post).toHaveBeenCalledWith(OCSP_URL, expect.any(Buffer), expect.any(Object));
++ expect(post).toHaveBeenCalledWith(OCSP_URL, expect.any(Buffer));
+ });
+
+ test("reports a revoked certificate with its revocation time", async () => {
+ respondWith({ kind: OcspCertStatus.Revoked, revokedAt: REVOKED_AT });
+
+ await expect(
+ getCertificateOcspStatus({ certificate: leafCertificate, issuer: issuingCa.certificate })
+ ).resolves.toEqual({ status: OcspCertStatus.Revoked, revokedAt: REVOKED_AT });
+ });
+
+ test("rejects a response signed by a CA other than the issuer", async () => {
+ respondWith({ kind: OcspCertStatus.Revoked, revokedAt: REVOKED_AT }, otherCa);
+
+ await expect(
+ getCertificateOcspStatus({ certificate: leafCertificate, issuer: issuingCa.certificate })
+ ).rejects.toThrow("failed signature verification");
+ });
+
+ test("refuses a certificate without an OCSP responder URL", async () => {
+ await expect(
+ getCertificateOcspStatus({ certificate: issuingCa.certificate, issuer: issuingCa.certificate })
+ ).rejects.toThrow("has no OCSP responder URL");
+ expect(post).not.toHaveBeenCalled();
+ });
+});
diff --cc backend/src/services/certificate/certificate-service.ts
index dcbf175bdf,2fa0a3d6b6..4e060291fc
--- a/backend/src/services/certificate/certificate-service.ts
+++ b/backend/src/services/certificate/certificate-service.ts
@@@ -674,19 -705,57 +707,27 @@@ export const certificateServiceFactory
});
}
- const metadataRows = await resourceMetadataDAL.find({ certificateId: cert.id });
- const certMetadata = metadataRows.map(({ key, value }) => ({ key, value: value || "" }));
-
- if (cert.applicationId) {
- const { permission } = await permissionService.getResourcePermission({
- actor,
- actorId,
- projectId: ca.projectId,
- resourceType: ResourceType.CertificateApplication,
- resourceId: cert.applicationId,
- actorAuthMethod,
- actorOrgId
- });
- ForbiddenError.from(permission).throwUnlessCan(
- ResourcePermissionCertificateActions.Delete,
- ResourcePermissionSub.Certificates
- );
- } else {
- const { permission } = await permissionService.getProjectPermission({
- actor,
- actorId,
- projectId: ca.projectId,
- actorAuthMethod,
- actorOrgId,
- actionProjectType: ActionProjectType.CertificateManager
- });
-
- ForbiddenError.from(permission).throwUnlessCan(
- ProjectPermissionCertificateActions.Delete,
- subject(ProjectPermissionSub.Certificates, {
- commonName: cert.commonName,
- altNames: cert.altNames?.split(",").map((s) => s.trim()),
- serialNumber: cert.serialNumber,
- friendlyName: cert.friendlyName,
- status: cert.status,
- metadata: certMetadata
- })
- );
- }
+ await assertCanRevokeCertificate({
+ certificate: { ...cert, projectId: ca.projectId },
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId,
+ permissionService,
+ resourceMetadataDAL
+ });
- if (cert.status === CertStatus.REVOKED) throw new Error("Certificate already revoked");
+ if (cert.status === CertStatus.REVOKED) {
+ throw new BadRequestError({ message: `Certificate '${getCertificateDisplayName(cert)}' is already revoked.` });
+ }
if (ca.internalCa?.id && cert.profileId && cert.source === CertificateSource.Imported) {
+ if (cert.deletedAt) {
+ throw new BadRequestError({
+ message: `Certificate '${getCertificateDisplayName(cert)}' can't be revoked because it was imported and then deleted on ${cert.deletedAt.toISOString()}.`
+ });
+ }
+
const certBody = await certificateBodyDAL.findOne({ certId: cert.id });
if (!certBody) {
throw new NotFoundError({ message: "Certificate body not found" });
diff --cc frontend/src/pages/cert-manager/CertificateDetailsByIDPage/CertificateDetailsByIDPage.tsx
index 39ce5a6eb6,2843ef08d2..a0b80d1191
--- a/frontend/src/pages/cert-manager/CertificateDetailsByIDPage/CertificateDetailsByIDPage.tsx
+++ b/frontend/src/pages/cert-manager/CertificateDetailsByIDPage/CertificateDetailsByIDPage.tsx
@@@ -481,11 -437,15 +437,16 @@@ const Page = () =>
const item = (
<DropdownMenuItem
- variant="danger"
- isDisabled={!canDeleteCertificate || Boolean(deletionBlockReason)}
- onClick={() => handlePopUpOpen("deleteCertificate")}
+ isDisabled={!canEditCertificate || profileMissing}
+ onClick={() =>
+ handlePopUpOpen("renewCertificate", {
+ certificateId: certificate.id,
- commonName: displayName
++ commonName: displayName,
++ canRevoke: canDeleteCertificate
+ })
+ }
>
- Delete Certificate
+ Renew Now
</DropdownMenuItem>
);
diff --cc frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalModal.tsx
index f9d5e04800,5dfcf81e4e..34836d4084
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalModal.tsx
@@@ -220,80 -210,6 +223,128 @@@ const EXTERNAL_TEMPLATE_OPTIONS_STEP: W
"The issuing certificate authority takes validity, key usages, extended key usages and basic constraints from its own certificate template, so they cannot be set here."
};
+const REISSUE_STEP_COPY: Partial<Record<RenewalStepKey, Partial<WizardStep>>> = {
+ setup: {
+ shortDescription: "Order and key pair",
+ subtitle: "Choose the DigiCert order and the key pair.",
+ rightDescription: "Reissuing puts the new certificate on the same DigiCert order."
+ },
+ csr: {
+ shortDescription: "CSR",
+ subtitle: "Provide the CSR for this reissue.",
+ rightDescription:
+ "The subject and key are taken from the CSR you provide, so there are no separate subject or key usage fields."
+ },
+ options: {
+ shortDescription: "Algorithms and key usage",
+ subtitle: "Set algorithms and key usages within the profile's policy."
+ }
+};
+
+type TChoiceOption<T extends string> = {
+ value: T;
+ label: string;
+ description: string;
+ isDisabled?: boolean;
+ disabledReason?: string;
+};
+
+const ChoiceCards = <T extends string>({
+ label,
+ idPrefix,
+ value,
+ onChange,
+ options
+}: {
+ label: string;
+ idPrefix: string;
+ value: T;
+ onChange: (value: T) => void;
+ options: TChoiceOption<T>[];
- }) => (
- <Field>
- <FieldLabel>{label}</FieldLabel>
- <FieldContent>
- <RadioGroup value={value} onValueChange={(next) => onChange(next as T)} className="gap-2">
- {options.map((option) => (
- <FieldLabel key={option.value} htmlFor={`${idPrefix}-${option.value}`} variant="project">
- <Field orientation="horizontal" className="items-center gap-3">
- <div className="min-w-0 flex-1 text-left">
- <p className="text-sm font-medium text-foreground">{option.label}</p>
- <p className="text-xs text-muted">
- {option.isDisabled ? option.disabledReason : option.description}
- </p>
- </div>
- <RadioGroupItem
- id={`${idPrefix}-${option.value}`}
- value={option.value}
- disabled={option.isDisabled}
- className="sr-only"
- />
- </Field>
- </FieldLabel>
- ))}
- </RadioGroup>
- </FieldContent>
- </Field>
- );
++}) => {
++ const [openReasonFor, setOpenReasonFor] = useState<T | null>(null);
++
++ return (
++ <Field>
++ <FieldLabel>{label}</FieldLabel>
++ <FieldContent>
++ <RadioGroup value={value} onValueChange={(next) => onChange(next as T)} className="gap-2">
++ {options.map((option) => {
++ const card = (
++ <FieldLabel
++ key={option.value}
++ htmlFor={`${idPrefix}-${option.value}`}
++ variant="project"
++ >
++ <Field orientation="horizontal" className="items-center gap-3">
++ <div className="min-w-0 flex-1 text-left">
++ <p className="text-sm font-medium text-foreground">{option.label}</p>
++ <p className="text-xs text-muted">
++ {option.isDisabled
++ ? "Not available for this certificate."
++ : option.description}
++ </p>
++ </div>
++ {option.isDisabled && (
++ <span id={`${idPrefix}-${option.value}-reason`} className="sr-only">
++ {option.disabledReason}
++ </span>
++ )}
++ <RadioGroupItem
++ id={`${idPrefix}-${option.value}`}
++ value={option.value}
++ disabled={option.isDisabled}
++ aria-describedby={
++ option.isDisabled ? `${idPrefix}-${option.value}-reason` : undefined
++ }
++ className="sr-only"
++ />
++ </Field>
++ </FieldLabel>
++ );
++ if (!option.isDisabled) return card;
++ return (
++ <Tooltip
++ key={option.value}
++ open={openReasonFor === option.value}
++ onOpenChange={(isReasonOpen) =>
++ setOpenReasonFor(isReasonOpen ? option.value : null)
++ }
++ >
++ <TooltipTrigger
++ asChild
++ onClick={(event) => {
++ // Radix closes a tooltip on click and never opens one on tap.
++ event.preventDefault();
++ setOpenReasonFor(option.value);
++ }}
++ >
++ {/* The disabled radio drops pointer events and focus, so the wrapper carries the hover and focus. */}
++ {/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */}
++ <span tabIndex={0} className="block">
++ {card}
++ </span>
++ </TooltipTrigger>
++ <TooltipContent side="bottom" className="max-w-80">
++ {option.disabledReason}
++ </TooltipContent>
++ </Tooltip>
++ );
++ })}
++ </RadioGroup>
++ </FieldContent>
++ </Field>
++ );
++};
+
+const REISSUE_VALIDITY_DESCRIPTION =
+ "Same as the current certificate. DigiCert caps it at 199 days and at the end of the order.";
+
+enum DigiCertOrderChoice {
+ NewOrder = "new-order",
+ Reissue = "reissue"
+}
+
const STEP_FIELDS: Record<RenewalStepKey, string[]> = {
setup: ["keySource"],
csr: ["csr", "ttl"],
diff --cc frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.test.ts
index 5f7f93fe20,87428d15ab..10806ca58b
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.test.ts
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/certificateRenewalUtils.test.ts
@@@ -1,11 -1,9 +1,16 @@@
import { describe, expect, it } from "vitest";
+ import { CertificateRenewalKeySource } from "@app/hooks/api/certificates/enums";
-import { CertSubjectAlternativeNameType } from "@app/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants";
+import {
+ CertSubjectAlternativeNameType,
+ CertSubjectAttributeType
+} from "@app/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants";
- import { buildRenewalFormDefaults, getRemovedCertificateNames } from "./certificateRenewalUtils";
-import { buildRenewalFormDefaults, buildRenewalRequestAttributes } from "./certificateRenewalUtils";
++import {
++ buildRenewalFormDefaults,
++ buildRenewalRequestAttributes,
++ getRemovedCertificateNames
++} from "./certificateRenewalUtils";
const certificate = {
id: "cert-1",
@@@ -72,57 -71,25 +78,80 @@@ describe("buildRenewalFormDefaults", (
});
});
+describe("getRemovedCertificateNames", () => {
+ const reissuedCertificate = {
+ commonName: "example.com",
+ altNames: "example.com,www.example.com"
+ };
+ const shownSections = { shouldShowSubjectSection: true, shouldShowSanSection: true };
+ const formWith = (commonName: string, altNames: string[]) => ({
+ subjectAttributes: [{ type: CertSubjectAttributeType.COMMON_NAME, value: commonName }],
+ subjectAltNames: altNames.map((value) => ({
+ type: CertSubjectAlternativeNameType.DNS_NAME,
+ value
+ }))
+ });
+
+ it("lists nothing when every name is kept, ignoring case and order", () => {
+ expect(
+ getRemovedCertificateNames({
+ certificate: reissuedCertificate,
+ formData: formWith("Example.com", ["new.example.com", "WWW.example.com", "example.com"]),
+ constraints: shownSections
+ })
+ ).toEqual([]);
+ });
+
+ it("lists an alternative name that is dropped", () => {
+ expect(
+ getRemovedCertificateNames({
+ certificate: reissuedCertificate,
+ formData: formWith("example.com", ["example.com"]),
+ constraints: shownSections
+ })
+ ).toEqual(["www.example.com"]);
+ });
+
+ it("lists the common name when it changes", () => {
+ expect(
+ getRemovedCertificateNames({
+ certificate: { commonName: "example.com", altNames: "www.example.com" },
+ formData: formWith("other.example.com", ["www.example.com"]),
+ constraints: shownSections
+ })
+ ).toEqual(["example.com"]);
+ });
+
+ it("keeps the current names of a section the policy hides", () => {
+ expect(
+ getRemovedCertificateNames({
+ certificate: reissuedCertificate,
+ formData: formWith("example.com", []),
+ constraints: { shouldShowSubjectSection: true, shouldShowSanSection: false }
+ })
+ ).toEqual([]);
+ });
+});
++
+ describe("buildRenewalRequestAttributes", () => {
+ it("submits policy-required usages even when their checkboxes were never toggled", () => {
+ const formData = {
+ ...buildRenewalFormDefaults(certificate, constraints),
+ keySource: CertificateRenewalKeySource.New,
+ keyUsages: { key_agreement: true, key_encipherment: false },
+ extendedKeyUsages: {}
+ };
+
+ const attributes = buildRenewalRequestAttributes({
+ formData,
+ constraints: {
+ ...(constraints as object),
+ requiredKeyUsages: ["digital_signature"],
+ requiredExtendedKeyUsages: ["client_auth"]
+ } as never
+ });
+
+ expect(attributes.keyUsages).toEqual(["key_agreement", "digital_signature"]);
+ expect(attributes.extendedKeyUsages).toEqual(["client_auth"]);
+ });
+ });