Allow empty CN

This commit is contained in:
Fang-Pen Lin
2025-11-21 10:30:55 -08:00
parent 02c346c77a
commit cf83ae2553
7 changed files with 23 additions and 18 deletions
@@ -1577,7 +1577,8 @@ export const internalCertificateAuthorityServiceFactory = ({
keyUsages,
extendedKeyUsages,
signatureAlgorithm,
keyAlgorithm
keyAlgorithm,
allowEmptyCommonName
} = dto;
let collectionId = pkiCollectionId;
@@ -1716,12 +1717,18 @@ export const internalCertificateAuthorityServiceFactory = ({
const csrObj = new x509.Pkcs10CertificateRequest(csr);
const dn = parseDistinguishedName(csrObj.subject);
const cn = commonName || dn.commonName;
let cn = commonName || dn.commonName;
if (!cn)
if ((allowEmptyCommonName ?? false) && !cn) {
// Notice: for modern TLS certificates, the CN is deprecated, many ACME clients will generate CSRs with without a CN
// we allow empty CN here to support ACME clients mostly. Since it's unclear what's the side effect of
// allowing empty CN for legacy PKI code, let's only do it if a true allowEmptyCommonName value is provided.
cn = "";
} else if (!cn) {
throw new BadRequestError({
message: "A common name (CN) is required in the CSR or as a parameter to this endpoint"
});
}
const { caPrivateKey, caSecret } = await getCaCredentials({
caId: ca.id,
@@ -164,6 +164,7 @@ export type TSignCertFromCaDTO =
keyAlgorithm?: string;
isFromProfile?: boolean;
profileId?: string;
allowEmptyCommonName?: boolean;
}
| ({
isInternal: false;
@@ -183,6 +184,7 @@ export type TSignCertFromCaDTO =
keyAlgorithm?: string;
isFromProfile?: boolean;
profileId?: string;
allowEmptyCommonName?: boolean;
} & Omit<TProjectPermission, "projectId">);
export type TGetCaCertificateTemplatesDTO = {
@@ -511,7 +511,8 @@ export const certificateV3ServiceFactory = ({
actorAuthMethod,
actorOrgId,
enrollmentType,
removeRootsFromChain
removeRootsFromChain,
allowEmptyCommonName
}: TSignCertificateFromProfileDTO): Promise<Omit<TCertificateFromProfileResponse, "privateKey">> => {
const profile = await validateProfileAndPermissions(
profileId,
@@ -582,7 +583,8 @@ export const certificateV3ServiceFactory = ({
notAfter: normalizeDateForApi(notAfter),
signatureAlgorithm: effectiveSignatureAlgorithm,
keyAlgorithm: effectiveKeyAlgorithm,
isFromProfile: true
isFromProfile: true,
allowEmptyCommonName
});
const cert = await certificateDAL.findOne({ serialNumber, caId: ca.id });
@@ -39,6 +39,7 @@ export type TSignCertificateFromProfileDTO = {
notAfter?: Date;
enrollmentType: EnrollmentType;
removeRootsFromChain?: boolean;
allowEmptyCommonName?: boolean;
} & Omit<TProjectPermission, "projectId">;
export type TOrderCertificateFromProfileDTO = {