Skip to content

Commit

Permalink
buildIdealCertificateName now replace / or \ with _ to avoid building…
Browse files Browse the repository at this point in the history
… invalid filename from certificate CN
  • Loading branch information
erossignon committed Dec 16, 2024
1 parent 735ebe3 commit 20aee24
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/pki/certificate_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ function buildIdealCertificateName(certificate: Certificate): string {
const fingerprint = makeFingerprint(certificate);
try {
const commonName = exploreCertificate(certificate).tbsCertificate.subject.commonName || "";
return commonName + "[" + fingerprint + "]";
// commonName may contain invalid characters for a filename such as / or \ or
// that we need to replace with a valid character.
// replace / or \ with _
const sanitizedCommonName = commonName.replace(/[\/\\]/g, "_");
return sanitizedCommonName + "[" + fingerprint + "]";
} catch (err) {
// make be certificate is incorrect !
return "invalid_certificate_[" + fingerprint + "]";
Expand Down

0 comments on commit 20aee24

Please sign in to comment.