diff --git a/lib/certUtils.js b/lib/certUtils.js index e33ebc36..9f075bcb 100644 --- a/lib/certUtils.js +++ b/lib/certUtils.js @@ -38,18 +38,10 @@ class Certificate { static #searchForCommonName(attributes) { const X509_COMMON_NAME_KEY = "2.5.4.3"; - - let commonName = ""; // Default in case no subject is found - // Search the attributes for the common name of the certificate - for (let index = 0; index < attributes.length; index++) { - const attribute = attributes[index]; - if (attribute.type === X509_COMMON_NAME_KEY) { - commonName = attribute.value.valueBlock.value; - break; - } - } - return commonName; + const commonNameAttr = attributes.find((attr) => attr.type == X509_COMMON_NAME_KEY); + // Return empty string if not found + return commonNameAttr ? commonNameAttr.value.valueBlock.value : ""; } verify() {