Skip to content

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

Addressed PR comments

Carlos Monastyrski27bc8e5a58d0
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index ee5af4fb96..6ac0d24e1a 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -912,6 +912,7 @@ export enum EventType {
ENABLE_PKI_SIGNER = "enable-pki-signer",
DISABLE_PKI_SIGNER = "disable-pki-signer",
REISSUE_PKI_SIGNER_CERTIFICATE = "reissue-pki-signer-certificate",
+ IMPORT_PKI_SIGNER_CERTIFICATE = "import-pki-signer-certificate",
EXPORT_PKI_SIGNER_CERTIFICATE = "export-pki-signer-certificate",
UPDATE_PKI_SIGNER_APPROVAL_POLICY = "update-pki-signer-approval-policy",
PKI_SIGNER_REQUEST_TO_SIGN = "pki-signer-request-to-sign",
@@ -5132,18 +5133,32 @@ interface ReissuePkiSignerCertificateEvent {
signerId: string;
name: string;
caId: string;
- certificateId?: string | null;
commonName?: string;
keyAlgorithm?: string;
keySource?: string;
hsmConnectorId?: string;
- hsmKeyLabel?: string;
- hsmKeyId?: string;
hsmKeyAlgorithm?: string;
externalConfiguration?: TSignerExternalConfigurationInput;
};
}
+interface ImportPkiSignerCertificateEvent {
+ type: EventType.IMPORT_PKI_SIGNER_CERTIFICATE;
+ metadata: {
+ signerId: string;
+ name: string;
+ caId: string;
+ externalOrderId: string;
+ certificateId?: string | null;
+ commonName?: string;
+ keyAlgorithm?: string;
+ hsmConnectorId: string;
+ hsmKeyLabel: string;
+ hsmKeyId?: string;
+ certificateRenewBeforeDays?: number | null;
+ };
+}
+
interface ExportPkiSignerCertificateEvent {
type: EventType.EXPORT_PKI_SIGNER_CERTIFICATE;
metadata: {
@@ -8442,6 +8457,7 @@ export type Event =
| EnablePkiSignerEvent
| DisablePkiSignerEvent
| ReissuePkiSignerCertificateEvent
+ | ImportPkiSignerCertificateEvent
| ExportPkiSignerCertificateEvent
| UpdatePkiSignerApprovalPolicyEvent
| PkiSignerRequestToSignEvent
diff --git a/backend/src/server/routes/v1/signer-routers/certificate-router.ts b/backend/src/server/routes/v1/signer-routers/certificate-router.ts
index 74a2dfe045..9c33673ce0 100644
--- a/backend/src/server/routes/v1/signer-routers/certificate-router.ts
+++ b/backend/src/server/routes/v1/signer-routers/certificate-router.ts
@@ -9,7 +9,8 @@ import { AuthMode } from "@app/services/auth/auth-type";
import { CertKeySource } from "@app/services/signer/signer-enums";
import {
- refineSignerCertificateInput,
+ ExternalOrderIdSchema,
+ HSM_REISSUE_KEY_ALGORITHMS,
SignerCertificateInputSchema,
SignerExternalConfigurationSchema,
SignerIdParamsSchema,
@@ -33,12 +34,30 @@ export const registerSignerCertificateRouter = async (server: FastifyZodProvider
commonName: z.string().trim().min(1).max(256).optional(),
certificateTtlDays: z.number().int().min(1).max(3650).optional(),
keyAlgorithm: SignerKeyAlgorithm.schema.optional(),
- certificate: SignerCertificateInputSchema.extend({
- keySource: z.enum([CertKeySource.Infisical, CertKeySource.Hsm])
- }).optional(),
- externalConfiguration: SignerExternalConfigurationSchema.optional()
+ certificate: SignerCertificateInputSchema.pick({ hsmConnectorId: true })
+ .extend({ keySource: z.enum([CertKeySource.Infisical, CertKeySource.Hsm]) })
+ .optional(),
+ externalConfiguration: SignerExternalConfigurationSchema.omit({ importFromExternalOrderId: true })
+ .strict()
+ .optional()
})
- .superRefine(refineSignerCertificateInput),
+ .superRefine((data, ctx) => {
+ if (data.certificate?.keySource !== CertKeySource.Hsm) return;
+ if (!data.certificate.hsmConnectorId) {
+ ctx.addIssue({
+ code: "custom",
+ message: `hsmConnectorId is required when keySource = '${CertKeySource.Hsm}'`,
+ path: ["certificate", "hsmConnectorId"]
+ });
+ }
+ if (!data.keyAlgorithm || !HSM_REISSUE_KEY_ALGORITHMS.includes(data.keyAlgorithm)) {
+ ctx.addIssue({
+ code: "custom",
+ message: `keyAlgorithm must be one of ${HSM_REISSUE_KEY_ALGORITHMS.join(", ")} when keySource = '${CertKeySource.Hsm}'`,
+ path: ["keyAlgorithm"]
+ });
+ }
+ }),
response: { 200: PkiSignersSchema }
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.OAUTH]),
@@ -52,7 +71,6 @@ export const registerSignerCertificateRouter = async (server: FastifyZodProvider
actorOrgId: req.permission.orgId
});
- const isImport = Boolean(req.body.externalConfiguration?.importFromExternalOrderId);
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: signer.projectId,
@@ -62,13 +80,10 @@ export const registerSignerCertificateRouter = async (server: FastifyZodProvider
signerId: signer.id,
name: signer.name,
caId: req.body.caId,
- commonName: isImport ? (signer.commonName ?? undefined) : req.body.commonName,
- keyAlgorithm: isImport ? (signer.keyAlgorithm ?? undefined) : req.body.keyAlgorithm,
- ...(isImport ? { certificateId: signer.certificateId } : {}),
+ commonName: req.body.commonName,
+ keyAlgorithm: req.body.keyAlgorithm,
keySource: req.body.certificate?.keySource,
hsmConnectorId: req.body.certificate?.hsmConnectorId,
- hsmKeyLabel: req.body.certificate?.hsmKeyLabel,
- hsmKeyId: req.body.certificate?.hsmKeyId,
externalConfiguration: req.body.externalConfiguration
}
}
@@ -78,6 +93,74 @@ export const registerSignerCertificateRouter = async (server: FastifyZodProvider
}
});
+ server.route({
+ method: "POST",
+ url: "/:signerId/certificate/import",
+ config: { rateLimit: writeLimit },
+ schema: {
+ hide: false,
+ operationId: "importSignerCertificate",
+ tags: [ApiDocsTags.PkiSigners],
+ description:
+ "Switch the signer to the certificate already issued in an existing DigiCert order, signing with that certificate's private key on the HSM. DigiCert does not reissue or revoke anything.",
+ params: SignerIdParamsSchema,
+ body: z.object({
+ caId: z.string().uuid().describe("The DigiCert certificate authority the order belongs to."),
+ externalOrderId: ExternalOrderIdSchema.describe("The DigiCert order whose certificate the signer will use."),
+ certificate: SignerCertificateInputSchema.pick({
+ hsmConnectorId: true,
+ hsmKeyLabel: true,
+ hsmKeyId: true
+ }).required({ hsmConnectorId: true, hsmKeyLabel: true }),
+ certificateRenewBeforeDays: z
+ .number()
+ .int()
+ .min(1)
+ .max(30)
+ .nullable()
+ .optional()
+ .describe(
+ "Days before expiry to renew the certificate with the same HSM key. Must be less than the certificate's validity. Omit to keep the signer's current setting, or set to null to turn renewal off."
+ )
+ }),
+ response: { 200: PkiSignersSchema }
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.OAUTH]),
+ handler: async (req) => {
+ const signer = await server.services.pkiSigner.importCertificate({
+ signerId: req.params.signerId,
+ ...req.body,
+ actor: req.permission.type,
+ actorId: req.permission.id,
+ actorAuthMethod: req.permission.authMethod,
+ actorOrgId: req.permission.orgId
+ });
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ projectId: signer.projectId,
+ event: {
+ type: EventType.IMPORT_PKI_SIGNER_CERTIFICATE,
+ metadata: {
+ signerId: signer.id,
+ name: signer.name,
+ caId: req.body.caId,
+ externalOrderId: req.body.externalOrderId,
+ certificateId: signer.certificateId,
+ commonName: signer.commonName ?? undefined,
+ keyAlgorithm: signer.keyAlgorithm ?? undefined,
+ hsmConnectorId: req.body.certificate.hsmConnectorId,
+ hsmKeyLabel: req.body.certificate.hsmKeyLabel,
+ hsmKeyId: req.body.certificate.hsmKeyId,
+ certificateRenewBeforeDays: signer.certificateRenewBeforeDays
+ }
+ }
+ });
+
+ return signer;
+ }
+ });
+
server.route({
method: "GET",
url: "/:signerId/certificate",
diff --git a/backend/src/server/routes/v1/signer-routers/schemas.ts b/backend/src/server/routes/v1/signer-routers/schemas.ts
index f992ee4978..cca9727e69 100644
--- a/backend/src/server/routes/v1/signer-routers/schemas.ts
+++ b/backend/src/server/routes/v1/signer-routers/schemas.ts
@@ -12,7 +12,7 @@ export const SignerIdParamsSchema = z.object({ signerId: z.string().uuid() });
export const SignerRequestParamsSchema = SignerIdParamsSchema.extend({ requestId: z.string().uuid() });
-const ExternalOrderIdSchema = z.string().trim().min(1).max(32);
+export const ExternalOrderIdSchema = z.string().trim().min(1).max(32);
export const SignerExternalConfigurationSchema = z.object({
caType: z
@@ -45,7 +45,7 @@ export const SignerCertificateInputSchema = z.object({
hsmKeyLabel: HsmKeyLabelSchema.refine((v) => RE_NO_NEWLINES.test(v), "Key label must not contain newline characters")
.optional()
.describe(
- "The label of an existing private key on the HSM. Only used with externalConfiguration.importFromExternalOrderId. If more than one private key in the HSM Connector's slot has this label, also set hsmKeyId."
+ "The label of the certificate's private key on the HSM. Only used when using an existing DigiCert certificate. If more than one private key in the HSM Connector's slot has this label, also set hsmKeyId."
),
hsmKeyId: z
.string()
@@ -81,6 +81,11 @@ export const HSM_SUPPORTED_KEY_ALGORITHMS: readonly CertKeyAlgorithm[] = [
CertKeyAlgorithm.ECDSA_P384
];
+export const HSM_REISSUE_KEY_ALGORITHMS: readonly CertKeyAlgorithm[] = [
+ ...HSM_SUPPORTED_KEY_ALGORITHMS,
+ CertKeyAlgorithm.RSA_3072
+];
+
export const refineSignerCertificateInput = (
data: {
commonName?: string;
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 f721f31139..1282580d82 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
@@ -746,7 +746,7 @@ export const DigiCertCertificateAuthorityFns = ({
assertCodeSigningOrderReusable: codeSigningFns.assertCodeSigningOrderReusable,
getCodeSigningOrderStatus: codeSigningFns.getCodeSigningOrderStatus,
fetchIssuedCodeSigningCertificate: codeSigningFns.fetchIssuedCodeSigningCertificate,
- prepareCodeSigningCertificate: codeSigningFns.prepareCodeSigningCertificate,
+ prepareCodeSigningCertificateImport: codeSigningFns.prepareCodeSigningCertificateImport,
downloadCodeSigningCertificate: codeSigningFns.downloadCodeSigningCertificate
};
};
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 c2078f508f..26abdd35be 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
@@ -334,7 +334,7 @@ export const digiCertCodeSigningFns = ({
return { pemBundle, certificate };
};
- const prepareCodeSigningCertificate = async ({
+ const prepareCodeSigningCertificateImport = async ({
caId,
orderId,
digicertCertificateId,
@@ -435,9 +435,9 @@ export const digiCertCodeSigningFns = ({
};
const downloadCodeSigningCertificate = async (
- args: Parameters<typeof prepareCodeSigningCertificate>[0]
+ args: Parameters<typeof prepareCodeSigningCertificateImport>[0]
): Promise<{ certificateId: string; certificatePem: string }> => {
- const prepared = await prepareCodeSigningCertificate(args);
+ const prepared = await prepareCodeSigningCertificateImport(args);
if (!prepared.insert) {
return { certificateId: prepared.existingCertificateId, certificatePem: prepared.certificatePem };
}
@@ -462,7 +462,7 @@ export const digiCertCodeSigningFns = ({
assertCodeSigningOrderReusable,
getCodeSigningOrderStatus,
fetchIssuedCodeSigningCertificate,
- prepareCodeSigningCertificate,
+ prepareCodeSigningCertificateImport,
downloadCodeSigningCertificate
};
};
diff --git a/backend/src/services/hsm-connector/hsm-connector-types.ts b/backend/src/services/hsm-connector/hsm-connector-types.ts
index dd225ab397..d353cb66c7 100644
--- a/backend/src/services/hsm-connector/hsm-connector-types.ts
+++ b/backend/src/services/hsm-connector/hsm-connector-types.ts
@@ -69,7 +69,7 @@ export type THsmConnectorSanitized = {
};
export type THsmConnectorKey = {
- label: string;
+ keyLabel: string;
keyId: string;
keyAlgorithm: string;
};
diff --git a/backend/src/services/signer/signer-service.ts b/backend/src/services/signer/signer-service.ts
index 3214b3aa8f..d8785bf019 100644
--- a/backend/src/services/signer/signer-service.ts
+++ b/backend/src/services/signer/signer-service.ts
@@ -106,6 +106,7 @@ import {
TGetPublicKeyDTO,
TGetSignerDTO,
TGetSigningOperationDTO,
+ TImportCertificateDTO,
TListSignersDTO,
TListSigningOperationsDTO,
TReissueCertificateDTO,
@@ -181,7 +182,7 @@ type TSignerServiceFactoryDep = {
| "revokeCertificate"
| "assertCodeSigningOrderReusable"
| "fetchIssuedCodeSigningCertificate"
- | "prepareCodeSigningCertificate"
+ | "prepareCodeSigningCertificateImport"
>;
projectDAL: Pick<TProjectDALFactory, "findOne" | "updateById" | "transaction">;
kmsService: Pick<TKmsServiceFactory, "decryptWithKmsKey" | "encryptWithKmsKey" | "generateKmsKey">;
@@ -329,6 +330,12 @@ export const resolveReissueTarget = ({
const keyAlgorithm =
dto.keyAlgorithm ?? (currentCert?.keyAlgorithm as CertKeyAlgorithm | undefined) ?? CertKeyAlgorithm.RSA_2048;
const hsmKeyAlgorithm = mapCertKeyAlgorithmToHsmKeyAlgorithm(keyAlgorithm);
+ if (switchingKeySource && hsmKeyAlgorithm === HsmKeyAlgorithm.RSA_3072) {
+ throw new BadRequestError({
+ message:
+ "A new HSM key can't be RSA-3072. Choose RSA-2048, RSA-4096, ECDSA P-256, or ECDSA P-384, or keep the signer's current key."
+ });
+ }
if (!hsmConnectorId) {
throw new BadRequestError({
message: "hsmConnectorId is required to (re)issue with an HSM key source."
@@ -441,7 +448,7 @@ export const signerServiceFactory = ({
const $parseDigiCertOrderId = (
value: string | undefined,
caType: CaType | null,
- field: "reissueFromExternalOrderId" | "importFromExternalOrderId"
+ field: "reissueFromExternalOrderId" | "importFromExternalOrderId" | "externalOrderId"
): number | undefined => {
if (!value) return undefined;
if (caType !== CaType.DIGICERT) {
@@ -489,7 +496,7 @@ export const signerServiceFactory = ({
{ hsmConnectorId, projectId, hsmKeyLabel, hsmKeyId: requestedHsmKeyId, certificate }
);
- const preparedCertificate = await digicertFns.prepareCodeSigningCertificate({ caId, orderId, pemBundle });
+ const preparedCertificate = await digicertFns.prepareCodeSigningCertificateImport({ caId, orderId, pemBundle });
const validityDays = Math.round(
(certificate.notAfter.getTime() - certificate.notBefore.getTime()) / (24 * 60 * 60 * 1000)
@@ -1436,6 +1443,74 @@ export const signerServiceFactory = ({
}
};
+ const importCertificate = async (dto: TImportCertificateDTO) => {
+ const signer = await signerDAL.findById(dto.signerId);
+ if (!signer) throw new NotFoundError({ message: `Signer with ID '${dto.signerId}' not found` });
+
+ const { permission } = await $loadSignerResourcePermission(
+ signer.id,
+ signer.projectId,
+ dto.actor,
+ dto.actorId,
+ dto.actorAuthMethod,
+ dto.actorOrgId
+ );
+ ForbiddenError.from(permission).throwUnlessCan(
+ ResourcePermissionSignerActions.ReissueCertificate,
+ ResourcePermissionSub.Signer
+ );
+
+ const ca = await certificateAuthorityDAL.findByIdWithAssociatedCa(dto.caId);
+ if (!ca || ca.projectId !== signer.projectId) {
+ throw new NotFoundError({ message: `Certificate authority '${dto.caId}' not found in this organization.` });
+ }
+ if (ca.status !== CaStatus.ACTIVE) {
+ throw new BadRequestError({ message: "The selected certificate authority is not active." });
+ }
+ const caType: CaType = (ca.externalCa?.type as CaType | undefined) ?? CaType.INTERNAL;
+ const importOrderId = $parseDigiCertOrderId(dto.externalOrderId, caType, "externalOrderId") as number;
+
+ const imported = await $importExistingDigiCertCertificate({
+ caId: ca.id,
+ projectId: signer.projectId,
+ orderId: importOrderId,
+ certificate: { keySource: CertKeySource.Hsm, ...dto.certificate },
+ actor: { type: dto.actor, id: dto.actorId, authMethod: dto.actorAuthMethod, orgId: dto.actorOrgId },
+ signerId: signer.id
+ });
+ const renewBeforeDays =
+ dto.certificateRenewBeforeDays !== undefined ? dto.certificateRenewBeforeDays : signer.certificateRenewBeforeDays;
+ if (renewBeforeDays != null && renewBeforeDays >= imported.certificateTtlDays) {
+ throw new BadRequestError({
+ message: `Renew before (${renewBeforeDays}d) must be less than the validity of the certificate in DigiCert order ${importOrderId} (${imported.certificateTtlDays}d).`
+ });
+ }
+ return signerDAL
+ .transaction(async (tx) => {
+ await signerIssuanceService.cancelOpenJobs(signer.id, importOrderId, tx);
+ const importedCertificateId = await $attachImportedCertificate(imported, signer.id, tx);
+ return signerDAL.updateById(
+ signer.id,
+ {
+ caId: ca.id,
+ commonName: imported.commonName,
+ certificateTtlDays: imported.certificateTtlDays,
+ certificateRenewBeforeDays: renewBeforeDays,
+ keyAlgorithm: imported.keyAlgorithm,
+ externalCaConfig: null,
+ certificateId: importedCertificateId,
+ status: SignerStatus.Active,
+ certificateFailureReason: null
+ },
+ tx
+ );
+ })
+ .catch(async (error: unknown) => {
+ await $rethrowConcurrentImport(error, imported);
+ throw error;
+ });
+ };
+
const reissueCertificate = async (dto: TReissueCertificateDTO) => {
const signer = await signerDAL.findById(dto.signerId);
if (!signer) throw new NotFoundError({ message: `Signer with ID '${dto.signerId}' not found` });
@@ -1472,57 +1547,10 @@ export const signerServiceFactory = ({
reissueCaType,
"reissueFromExternalOrderId"
);
- const importOrderId = $parseDigiCertOrderId(
- reissueExternalConfig?.importFromExternalOrderId,
- reissueCaType,
- "importFromExternalOrderId"
- );
if (explicitReissueOrderId) {
await digicertFns.assertCodeSigningOrderReusable(ca.id, explicitReissueOrderId);
}
- if (importOrderId) {
- const imported = await $importExistingDigiCertCertificate({
- caId: ca.id,
- projectId: signer.projectId,
- orderId: importOrderId,
- certificate: dto.certificate,
- actor: { type: dto.actor, id: dto.actorId, authMethod: dto.actorAuthMethod, orgId: dto.actorOrgId },
- signerId: signer.id
- });
- if (
- signer.certificateRenewBeforeDays != null &&
- signer.certificateRenewBeforeDays >= imported.certificateTtlDays
- ) {
- throw new BadRequestError({
- message: `The certificate in DigiCert order ${importOrderId} is valid for ${imported.certificateTtlDays}d, which is not more than the signer's renew before (${signer.certificateRenewBeforeDays}d). Lower the renew-before window first.`
- });
- }
- return signerDAL
- .transaction(async (tx) => {
- await signerIssuanceService.cancelOpenJobs(signer.id, importOrderId, tx);
- const importedCertificateId = await $attachImportedCertificate(imported, signer.id, tx);
- return signerDAL.updateById(
- signer.id,
- {
- caId: ca.id,
- commonName: imported.commonName,
- certificateTtlDays: imported.certificateTtlDays,
- keyAlgorithm: imported.keyAlgorithm,
- externalCaConfig: null,
- certificateId: importedCertificateId,
- status: SignerStatus.Active,
- certificateFailureReason: null
- },
- tx
- );
- })
- .catch(async (error: unknown) => {
- await $rethrowConcurrentImport(error, imported);
- throw error;
- });
- }
-
const providedAdcsTemplate = reissueExternalConfig?.template?.trim() || undefined;
if (providedAdcsTemplate && reissueCaType !== CaType.ADCS) {
throw new BadRequestError({
@@ -2384,6 +2412,7 @@ export const signerServiceFactory = ({
enable,
disable,
reissueCertificate,
+ importCertificate,
exportCertificate,
sign,
getPublicKey,
diff --git a/backend/src/services/signer/signer-types.ts b/backend/src/services/signer/signer-types.ts
index f636963c18..7e3afe208f 100644
--- a/backend/src/services/signer/signer-types.ts
+++ b/backend/src/services/signer/signer-types.ts
@@ -143,6 +143,14 @@ export type TReissueCertificateDTO = {
externalConfiguration?: TSignerExternalConfigurationInput;
} & TActorPermission;
+export type TImportCertificateDTO = {
+ signerId: string;
+ caId: string;
+ externalOrderId: string;
+ certificate: { hsmConnectorId: string; hsmKeyLabel: string; hsmKeyId?: string };
+ certificateRenewBeforeDays?: number | null;
+} & TActorPermission;
+
export type TExportCertificateDTO = {
signerId: string;
} & TActorPermission;
diff --git a/docs/api-reference/endpoints/code-signing/signers/import-certificate.mdx b/docs/api-reference/endpoints/code-signing/signers/import-certificate.mdx
new file mode 100644
index 0000000000..7d73c3b4cc
--- /dev/null
+++ b/docs/api-reference/endpoints/code-signing/signers/import-certificate.mdx
@@ -0,0 +1,4 @@
+---
+title: "Import certificate"
+openapi: "POST /api/v1/cert-manager/signers/{signerId}/certificate/import"
+---
diff --git a/docs/docs.json b/docs/docs.json
index aa5d2ad45f..da1059a843 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -4406,6 +4406,7 @@
"api-reference/endpoints/code-signing/signers/enable",
"api-reference/endpoints/code-signing/signers/disable",
"api-reference/endpoints/code-signing/signers/reissue-certificate",
+ "api-reference/endpoints/code-signing/signers/import-certificate",
"api-reference/endpoints/code-signing/signers/list-operations"
]
},
diff --git a/docs/documentation/platform/pki/guides/code-signing/digicert-code-signing.mdx b/docs/documentation/platform/pki/guides/code-signing/digicert-code-signing.mdx
index fec3034ac3..09faaa1bdf 100644
--- a/docs/documentation/platform/pki/guides/code-signing/digicert-code-signing.mdx
+++ b/docs/documentation/platform/pki/guides/code-signing/digicert-code-signing.mdx
@@ -62,7 +62,7 @@ If the key doesn't match the certificate, the request fails and nothing changes.
To switch an existing signer to the certificate, follow the same steps in **Edit Signer**.
</Tab>
<Tab title="API">
- On [Create Signer](/api-reference/endpoints/code-signing/signers/create) or [Reissue](/api-reference/endpoints/code-signing/signers/reissue-certificate), set `externalConfiguration.importFromExternalOrderId` to the order ID and `certificate.hsmKeyLabel` to the key's label. If more than one private key in the slot has that label, also set `certificate.hsmKeyId` to the key's hex-encoded `CKA_ID`:
+ To create a signer that uses the certificate, call [the endpoint that creates a signer](/api-reference/endpoints/code-signing/signers/create) with `externalConfiguration.importFromExternalOrderId` set to the order ID and `certificate.hsmKeyLabel` set to the key's label. If more than one private key in the slot has that label, also set `certificate.hsmKeyId` to the key's hex-encoded `CKA_ID`:
```json
{
@@ -77,6 +77,8 @@ If the key doesn't match the certificate, the request fails and nothing changes.
}
}
```
+
+ To switch an existing signer to the certificate, call [the endpoint that imports a certificate into a signer](/api-reference/endpoints/code-signing/signers/import-certificate) with the order ID in `externalOrderId` and the same `certificate` fields, without `keySource`.
</Tab>
</Tabs>
diff --git a/frontend/src/hooks/api/signers/index.tsx b/frontend/src/hooks/api/signers/index.tsx
index c2da06ccfb..f5067ec942 100644
--- a/frontend/src/hooks/api/signers/index.tsx
+++ b/frontend/src/hooks/api/signers/index.tsx
@@ -8,6 +8,7 @@ export {
useDeleteSigner,
useDisableSigner,
useEnableSigner,
+ useImportSignerCertificate,
usePreApproveSigning,
useReissueSignerCertificate,
useRemoveSignerGroupMember,
diff --git a/frontend/src/hooks/api/signers/mutations.tsx b/frontend/src/hooks/api/signers/mutations.tsx
index 838ab946b2..1a14493b10 100644
--- a/frontend/src/hooks/api/signers/mutations.tsx
+++ b/frontend/src/hooks/api/signers/mutations.tsx
@@ -14,6 +14,7 @@ import {
TDeleteSignerDTO,
TDisableSignerDTO,
TEnableSignerDTO,
+ TImportSignerCertificateDTO,
TPreApproveSigningDTO,
TReissueSignerCertificateDTO,
TRemoveSignerGroupDTO,
@@ -129,16 +130,31 @@ export const useReissueSignerCertificate = () => {
);
return data;
},
- onSuccess: (signer, { externalConfiguration }) => {
+ onSuccess: (signer) => {
queryClient.invalidateQueries({ queryKey: signerKeys.byId(signer.id) });
queryClient.invalidateQueries({ queryKey: signerKeys.list(signer.projectId) });
queryClient.invalidateQueries({ queryKey: signerKeys.certificate(signer.id) });
- createNotification({
- text: externalConfiguration?.importFromExternalOrderId
- ? "Signer switched to the order's certificate"
- : "Certificate re-issue scheduled",
- type: "success"
- });
+ createNotification({ text: "Certificate re-issue scheduled", type: "success" });
+ }
+ });
+};
+
+export const useImportSignerCertificate = () => {
+ const queryClient = useQueryClient();
+
+ return useMutation<TSigner, object, TImportSignerCertificateDTO>({
+ mutationFn: async ({ signerId, ...body }) => {
+ const { data } = await apiRequest.post<TSigner>(
+ `/api/v1/cert-manager/signers/${signerId}/certificate/import`,
+ body
+ );
+ return data;
+ },
+ onSuccess: (signer) => {
+ queryClient.invalidateQueries({ queryKey: signerKeys.byId(signer.id) });
+ queryClient.invalidateQueries({ queryKey: signerKeys.list(signer.projectId) });
+ queryClient.invalidateQueries({ queryKey: signerKeys.certificate(signer.id) });
+ createNotification({ text: "Signer switched to the order's certificate", type: "success" });
}
});
};
diff --git a/frontend/src/hooks/api/signers/types.ts b/frontend/src/hooks/api/signers/types.ts
index 36ddff51a8..717d4865d5 100644
--- a/frontend/src/hooks/api/signers/types.ts
+++ b/frontend/src/hooks/api/signers/types.ts
@@ -396,6 +396,14 @@ export type TReissueSignerCertificateDTO = {
externalConfiguration?: TSignerExternalConfiguration;
};
+export type TImportSignerCertificateDTO = {
+ signerId: string;
+ caId: string;
+ externalOrderId: string;
+ certificate: { hsmConnectorId: string; hsmKeyLabel: string; hsmKeyId?: string };
+ certificateRenewBeforeDays?: number | null;
+};
+
export type TEnableSignerDTO = { signerId: string };
export type TDisableSignerDTO = { signerId: string };
diff --git a/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/schemas.ts b/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/schemas.ts
index 0af456f5d4..619cd5fcc7 100644
--- a/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/schemas.ts
+++ b/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/schemas.ts
@@ -55,6 +55,7 @@ export const certificateSchema = z
.refine(
(data) =>
data.certificateRenewBeforeDays == null ||
+ Boolean(data.externalOrderId) ||
data.certificateRenewBeforeDays < data.certificateTtlDays,
{
message: "Renew before must be less than the certificate validity (days).",
diff --git a/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerModal/EditSignerModal.tsx b/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerModal/EditSignerModal.tsx
index acb7eeda10..03c0934a64 100644
--- a/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerModal/EditSignerModal.tsx
+++ b/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerModal/EditSignerModal.tsx
@@ -24,6 +24,7 @@ import {
CertKeySource,
SignerKeyAlgorithm,
TSigner,
+ useImportSignerCertificate,
useReissueSignerCertificate,
useUpdateSigner
} from "@app/hooks/api/signers";
@@ -59,6 +60,7 @@ export const EditSignerModal = ({ isOpen, onOpenChange, signer }: Props) => {
const cas = useListCasByProjectId();
const updateSigner = useUpdateSigner();
const reissueCertificate = useReissueSignerCertificate();
+ const importCertificate = useImportSignerCertificate();
const { subscription } = useSubscription();
const { data: hsmConnectors = [], isPending: isHsmConnectorsLoading } = useListHsmConnectors({
enabled: Boolean(subscription?.hsm)
@@ -239,27 +241,28 @@ export const EditSignerModal = ({ isOpen, onOpenChange, signer }: Props) => {
const nextRenew = cert.certificateRenewBeforeDays ?? null;
const renewChanged = nextRenew !== currentRenew;
- if (shouldReissue) {
+ if (usingExistingCertificate) {
+ await importCertificate.mutateAsync({
+ signerId: signer.id,
+ caId: cert.caId,
+ externalOrderId: cert.externalOrderId ?? "",
+ certificate: {
+ hsmConnectorId: cert.hsmConnectorId ?? "",
+ hsmKeyLabel: cert.hsmKeyLabel,
+ hsmKeyId: cert.hsmKeyId || undefined
+ },
+ certificateRenewBeforeDays: renewChanged ? nextRenew : undefined
+ });
+ } else if (shouldReissue) {
await reissueCertificate.mutateAsync({
signerId: signer.id,
caId: cert.caId,
commonName: !isFromExternalOrder && subjectChanged ? cert.commonName : undefined,
certificateTtlDays:
!isFromExternalOrder && subjectChanged ? cert.certificateTtlDays : undefined,
- keyAlgorithm:
- !usingExistingCertificate && (keySourceChanged || keyAlgorithmChanged)
- ? cert.keyAlgorithm
- : undefined,
- certificate: (() => {
- if (usingExistingCertificate) {
- return {
- keySource: CertKeySource.Hsm,
- hsmConnectorId: cert.hsmConnectorId ?? undefined,
- hsmKeyLabel: cert.hsmKeyLabel,
- hsmKeyId: cert.hsmKeyId || undefined
- };
- }
- return keySourceChanged || keyAlgorithmChanged
+ keyAlgorithm: keySourceChanged || keyAlgorithmChanged ? cert.keyAlgorithm : undefined,
+ certificate:
+ keySourceChanged || keyAlgorithmChanged
? {
keySource: cert.keySource,
hsmConnectorId:
@@ -267,13 +270,10 @@ export const EditSignerModal = ({ isOpen, onOpenChange, signer }: Props) => {
? (cert.hsmConnectorId ?? undefined)
: undefined
}
- : undefined;
- })(),
+ : undefined,
externalConfiguration: (() => {
if (cert.externalOrderId) {
- return usingExistingCertificate
- ? { importFromExternalOrderId: cert.externalOrderId }
- : { reissueFromExternalOrderId: cert.externalOrderId };
+ return { reissueFromExternalOrderId: cert.externalOrderId };
}
if (isAdcs) {
return { template: cert.adcsTemplate?.trim() || undefined };
@@ -283,12 +283,13 @@ export const EditSignerModal = ({ isOpen, onOpenChange, signer }: Props) => {
});
}
- if (nameChanged || descChanged || renewChanged) {
+ const renewSavedByImport = usingExistingCertificate && renewChanged;
+ if (nameChanged || descChanged || (renewChanged && !renewSavedByImport)) {
await updateSigner.mutateAsync({
signerId: signer.id,
name: nameChanged ? basics.name : undefined,
description: descChanged ? basics.description || null : undefined,
- certificateRenewBeforeDays: renewChanged ? nextRenew : undefined
+ certificateRenewBeforeDays: renewChanged && !renewSavedByImport ? nextRenew : undefined
});
}
diff --git a/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerModal/schemas.ts b/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerModal/schemas.ts
index 29f9b1c0cc..73117a9ea0 100644
--- a/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerModal/schemas.ts
+++ b/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerModal/schemas.ts
@@ -72,6 +72,7 @@ export const createCertificateSchema = (currentKey: TCurrentSignerKey) =>
(data) =>
data.certificateRenewBeforeDays == null ||
data.certificateTtlDays == null ||
+ Boolean(data.externalOrderId) ||
data.certificateRenewBeforeDays < data.certificateTtlDays,
{
message: "Renew before must be less than the certificate validity (days).",
diff --git a/frontend/src/pages/cert-manager/components/SignerKeyStep.tsx b/frontend/src/pages/cert-manager/components/SignerKeyStep.tsx
index 29edac78eb..5518a8447f 100644
--- a/frontend/src/pages/cert-manager/components/SignerKeyStep.tsx
+++ b/frontend/src/pages/cert-manager/components/SignerKeyStep.tsx
@@ -301,8 +301,7 @@ export const SignerKeyStep = ({
<InfoIcon className="h-3.5 w-3.5 text-muted" />
</TooltipTrigger>
<TooltipContent className="max-w-xs">
- When off, a new key is generated on the HSM and DigiCert replaces the
- certificate in this order.
+ When off, DigiCert issues a new certificate into this order.
</TooltipContent>
</Tooltip>
</div>