UNPKG

@camunda8/sdk

Version:

[![NPM](https://nodei.co/npm/@camunda8/sdk.png)](https://www.npmjs.com/package/@camunda8/sdk)

67 lines 2.49 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetCustomCertificateBuffer = GetCustomCertificateBuffer; const crypto_1 = require("crypto"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const debug_1 = require("debug"); const GetSystemCertificates_1 = require("./GetSystemCertificates"); const trace = (0, debug_1.debug)('camunda:certificate'); async function GetCustomCertificateBuffer(config) { const customRootCertPath = config.CAMUNDA_CUSTOM_ROOT_CERT_PATH; const customRootCert = config.CAMUNDA_CUSTOM_ROOT_CERT_STRING; if (!customRootCertPath && !customRootCert) { trace(`No custom root certificate configured`); return undefined; } const rootCerts = []; if (customRootCertPath) { trace(`Using custom root certificate from file: ${customRootCertPath}`); const cert = readRootCertificate(customRootCertPath); if (cert) { rootCerts.push(cert); } } else if (customRootCert) { trace(`Using custom root certificate from string`); rootCerts.push(customRootCert); } // (2) use certificates from OS keychain const systemCertificates = await (0, GetSystemCertificates_1.getSystemCertificates)(); rootCerts.push(...systemCertificates); if (!rootCerts.length) { trace(`No custom root certificates found`); return undefined; } const output = rootCerts.join('\n'); trace(`Custom root certificates:\n${output}`); return output; } function readRootCertificate(certPath) { let cert; try { const absolutePath = path_1.default.isAbsolute(certPath) ? certPath : path_1.default.join(process.cwd(), certPath); cert = fs_1.default.readFileSync(absolutePath); } catch (err) { console.error('Failed to read custom SSL certificate:', err); return; } let parsed; try { parsed = new crypto_1.X509Certificate(cert); } catch (err) { console.warn('Failed to parse custom SSL certificate:', err); } if (parsed && parsed.issuer !== parsed.subject) { console.warn('Custom SSL certificate appears to be not a root certificate'); } return cert; } //# sourceMappingURL=GetCustomCertificateBuffer.js.map