UNPKG

@azure/identity

Version:

Provides credential implementations for Azure SDK libraries that can authenticate with Microsoft Entra ID

61 lines (60 loc) • 2.23 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var certificatesUtils_exports = {}; __export(certificatesUtils_exports, { canParseAsX509Certificate: () => canParseAsX509Certificate, extractPemCertificateKeys: () => extractPemCertificateKeys }); module.exports = __toCommonJS(certificatesUtils_exports); var import_crypto = require("crypto"); function extractPemCertificateKeys(pemContent) { const certificatePattern = /(-+BEGIN CERTIFICATE-+)(\n\r?|\r\n?)([A-Za-z0-9+/\n\r]+=*)(\n\r?|\r\n?)(-+END CERTIFICATE-+)/g; const publicKeys = []; let match; do { match = certificatePattern.exec(pemContent); if (match) { publicKeys.push(match[3]); } } while (match); if (publicKeys.length === 0) { throw new Error("The file at the specified path does not contain a PEM-encoded certificate."); } return publicKeys; } function canParseAsX509Certificate(pemCert) { try { const pemContents = extractPemCertificateKeys(pemCert); for (let i = 0; i < pemContents.length; i++) { const pemContent = pemContents[i]; const fullPemCertificate = `-----BEGIN CERTIFICATE----- ${pemContent} -----END CERTIFICATE-----`; new import_crypto.X509Certificate(fullPemCertificate); } return true; } catch (extractError) { return false; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { canParseAsX509Certificate, extractPemCertificateKeys }); //# sourceMappingURL=certificatesUtils.js.map