From ac87bc57e957ea4679707bfd38d6840e26319bed Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Fri, 6 Jun 2025 13:53:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9F=90=E4=BA=9B=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E5=95=86=E7=9A=84=E8=AF=81=E4=B9=A6=E7=A1=AE?= =?UTF-8?q?=E5=AE=9EcommonName=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E8=AF=81=E4=B9=A6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugin/cert-plugin/cert-reader.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/cert-reader.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/cert-reader.ts index bdffbb9d..9eee841a 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/cert-reader.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/cert-reader.ts @@ -89,7 +89,10 @@ export class CertReader { getAllDomains() { const { detail } = this.getCrtDetail(); - const domains = [detail.domains.commonName]; + const domains = []; + if (detail.domains?.commonName) { + domains.push(detail.domains.commonName); + } domains.push(...detail.domains.altNames); //去重 return uniq(domains); @@ -102,12 +105,23 @@ export class CertReader { static getMainDomain(crt: string) { const { detail } = CertReader.readCertDetail(crt); - return detail.domains.commonName; + return CertReader.getMainDomainFromDetail(detail); } getMainDomain() { const { detail } = this.getCrtDetail(); - return detail.domains.commonName; + return CertReader.getMainDomainFromDetail(detail); + } + + static getMainDomainFromDetail(detail: CertificateInfo) { + let domain = detail?.domains?.commonName; + if (domain == null) { + domain = detail?.domains?.altNames?.[0]; + } + if (domain == null) { + domain = "unknown"; + } + return domain; } saveToFile(type: "crt" | "key" | "pfx" | "der" | "oc" | "one" | "ic" | "jks", filepath?: string) { @@ -179,8 +193,7 @@ export class CertReader { } buildCertFileName(suffix: string, applyTime: any, prefix = "cert") { - const detail = this.getCrtDetail(); - let domain = detail.detail.domains.commonName; + let domain = this.getMainDomain(); domain = domain.replaceAll(".", "_").replaceAll("*", "_"); const timeStr = dayjs(applyTime).format("YYYYMMDDHHmmss"); return `${prefix}_${domain}_${timeStr}.${suffix}`; @@ -188,7 +201,7 @@ export class CertReader { buildCertName() { let domain = this.getMainDomain(); - domain = domain.replaceAll("*", "_").replaceAll("*", "_"); + domain = domain.replaceAll(".", "_").replaceAll("*", "_"); return `${domain}_${dayjs().format("YYYYMMDDHHmmssSSS")}`; } }