@@ -23,20 +23,38 @@ const log = new Logger('lib/certs.ts')
2323
2424export let key : string ;
2525export let cert : string ;
26+ export let certBundle : string ;
2627export let ca : string [ ] = [ ] ;
2728export let peerID : string ;
2829
2930export const init = async ( ) => {
3031 log . debug ( "Reading key file" ) ;
3132 key = ( await fs . readFile ( path . join ( utils . constants . DATA_DIRECTORY , utils . constants . KEY_FILE ) ) ) . toString ( ) ;
33+ log . debug ( "Loaded key" ) ;
3234 log . debug ( "Reading cert file" ) ;
3335 cert = ( await fs . readFile ( path . join ( utils . constants . DATA_DIRECTORY , utils . constants . CERT_FILE ) ) ) . toString ( ) ;
36+
37+ log . debug ( "Loaded cert" ) ;
38+ log . debug ( cert ) ;
39+
40+ log . debug ( "Deriving peer ID from cert" ) ;
3441 const certData = utils . getCertData ( cert ) ;
3542 peerID = utils . getPeerID ( certData . organization , certData . organizationUnit ) ;
36- await loadCAs ( ) ;
43+
44+ let caCertPath = path . join ( utils . constants . DATA_DIRECTORY , utils . constants . CA_FILE ) ;
45+ if ( await utils . fileExists ( caCertPath ) ) {
46+ log . debug ( "Reading CA file" ) ;
47+ certBundle = ( await fs . readFile ( caCertPath ) ) . toString ( ) + cert ;
48+ log . debug ( "Loaded CA + cert" ) ;
49+ log . debug ( certBundle ) ;
50+ } else {
51+ certBundle = cert ;
52+ }
53+
54+ await loadPeerCAs ( ) ;
3755} ;
3856
39- export const loadCAs = async ( ) => {
57+ export const loadPeerCAs = async ( ) => {
4058 const peerCertsPath = path . join ( utils . constants . DATA_DIRECTORY , utils . constants . PEER_CERTS_SUBDIRECTORY ) ;
4159 log . debug ( `Reading peer CAs from ${ peerCertsPath } ` ) ;
4260 const peerCerts = await fs . readdir ( peerCertsPath ) ;
@@ -49,6 +67,10 @@ export const loadCAs = async () => {
4967 }
5068 }
5169 log . debug ( `Loaded ${ ca . length } peer certificate(s)` ) ;
70+ for ( const caCert of ca ) {
71+ log . debug ( "Outputting CA cert" ) ;
72+ log . debug ( caCert ) ;
73+ }
5274} ;
5375
5476export const genTLSContext = ( ) => {
0 commit comments