import { pki } from 'node-forge' ; param { string } certChain return { pki . Certificate [ ] } const CERT_START_KEY = '-----BEGIN CERTIFICATE-----' ; const CERT_END_KEY = '-----END CERTIFICATE-----' ; export function generateCertificatesArray ( certChain ) { const certs = [ ] ; while ( certChain . length > 0 ) { const start = certChain . indexOf ( CERT_START_KEY ) ; const end = certChain . indexOf ( CERT_END_KEY ) + CERT_END_KEY . length ; const certString = certChain . slice ( start , end ) ; certs . push ( pki . certificateFromPem ( certString ) ) ; certChain = certChain . slice ( end ) . trim ( ) ; } return certs ; } param { string [ ] } certs export function generateCAStore ( certs ) { const caStore = pki . createCaStore ( [ ] ) ; for ( const cert of certs ) { try { caStore . addCertificate ( cert ) ; } catch ( e ) { } } return caStore ; }