@naylence/advanced-security 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8240,10 +8240,40 @@ class DefaultCAService extends CAService {
8240
8240
  });
8241
8241
  console.debug("Using root CA for signing:", csr.requesterId);
8242
8242
  }
8243
- // TODO: Parse CSR, extract public key, and sign certificate
8244
- // For now, delegate to the signing service (which will throw until implemented)
8243
+ // Issue the certificate using the configured signing service
8245
8244
  try {
8246
- return await signingService.issueCertificate(csr);
8245
+ const { certificatePem, expiresAt } = await signingService.issueCertificate(csr);
8246
+ const chainParts = [certificatePem.trim()];
8247
+ const rootCertPem = credentials.rootCaCertPem?.trim();
8248
+ const signingCertPem = credentials.signingCertPem?.trim();
8249
+ const normalizeCert = (pem) => pem?.trim();
8250
+ if (credentials.intermediateChainPem) {
8251
+ const intermediateCerts = this.parseCertificateChain(credentials.intermediateChainPem);
8252
+ for (const certPem of intermediateCerts) {
8253
+ const normalized = normalizeCert(certPem);
8254
+ if (!normalized) {
8255
+ continue;
8256
+ }
8257
+ if (normalized === chainParts[0]) {
8258
+ continue;
8259
+ }
8260
+ if (rootCertPem && normalized === rootCertPem) {
8261
+ continue;
8262
+ }
8263
+ chainParts.push(normalized);
8264
+ }
8265
+ }
8266
+ else if (signingCertPem && signingCertPem !== rootCertPem) {
8267
+ if (signingCertPem !== chainParts[0]) {
8268
+ chainParts.push(signingCertPem);
8269
+ }
8270
+ }
8271
+ const certificateChainPem = chainParts.join("\n");
8272
+ return {
8273
+ certificatePem,
8274
+ certificateChainPem,
8275
+ expiresAt,
8276
+ };
8247
8277
  }
8248
8278
  catch (error) {
8249
8279
  console.error("Certificate issuance failed:", csr.requesterId, error);