How to Append root and intermediate Certs

Aperta
#1,048 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, node.js

Direzione di ricerca

Start by reproducing the reported behavior with node-forge 1.3.1 using the provided certificate URLs and the call to pkcs12.toPkcs12Asn1. Inspect how the certificate array is encoded and verify the resulting output.pfx contains the server, intermediate, and root certificates.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hello, can someone please verify if I am doing something wrong.
I would like to append root CA and intermediate cert from Let's Encrypt that certificate would like this - see the screen.

Screenshot 2023-09-14 101606

This is the code:

const path = require('path');
const privateKeyFilePath = path.join(__dirname, 'private.key');
const certFilePath = path.join(__dirname, 'serverCert.pem');
const cert = fs.readFileSync(certFilePath, 'utf8');
const key = fs.readFileSync(privateKeyFilePath, 'utf8');

// Load your server certificate
const privateKey = forge.pki.privateKeyFromPem(key.toString());
const serverCertificate = forge.pki.certificateFromPem(cert.toString());

const intermediateCertUrl = 'https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem';
const rootCertUrl = 'https://letsencrypt.org/certs/isrgrootx1.pem';

const intermediateCertResponse = await fetch(intermediateCertUrl);
const rootCertResponse = await fetch(rootCertUrl);

const intermediateCertPem = await intermediateCertResponse.text();
const rootCertPem = await rootCertResponse.text();

const intermediateCert = forge.pki.certificateFromPem(intermediateCertPem);
const rootCert = forge.pki.certificateFromPem(rootCertPem);

// Create the certificate chain
serverCertificate.setIssuer(intermediateCert.subject.attributes);
intermediateCert.setIssuer(rootCert.subject.attributes);

// Generate the PKCS#12 certificate
const pkcs12 = forge.pkcs12.toPkcs12Asn1(privateKey, [serverCertificate, intermediateCert, rootCert], '');

// Define the file path where you want to save the PKCS#12 certificate (PFX format)
const pfxFilePath = path.join(__dirname, 'output.pfx');

// Convert the PKCS#12 certificate to binary format
const pfxDer = forge.asn1.toDer(pkcs12).getBytes();

// Write the PKCS#12 certificate to a file (PFX format)
fs.writeFileSync(pfxFilePath, pfxDer, { encoding: 'binary' });

console.log(`PKCS#12 certificate saved to ${pfxFilePath}`);

output.pfx looks like this only server certificate is present:
Screenshot 2023-09-14 101906

using latest node-forge 1.3.1

Lingua principale
JavaScript
Stelle
5.4k
Fork
874
Merge medio
3m
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di digitalbazaar/forge

Tutte le issue di digitalbazaar/forge

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.