@@ -23,20 +23,36 @@ 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+ let caCertPath = path . join ( utils . constants . DATA_DIRECTORY , utils . constants . CA_FILE ) ;
38+ if ( await utils . fileExists ( caCertPath ) ) {
39+ log . debug ( "Reading CA file" ) ;
40+ certBundle = ( await fs . readFile ( caCertPath ) ) . toString ( ) + cert ;
41+ log . debug ( "Loaded CA + cert" ) ;
42+ } else {
43+ certBundle = cert ;
44+ log . debug ( "Loaded cert" ) ;
45+ }
46+ log . debug ( "\n" + certBundle ) ;
47+
48+ log . debug ( "Deriving peer ID from cert" ) ;
3449 const certData = utils . getCertData ( cert ) ;
3550 peerID = utils . getPeerID ( certData . organization , certData . organizationUnit ) ;
36- await loadCAs ( ) ;
51+
52+ await loadPeerCAs ( ) ;
3753} ;
3854
39- export const loadCAs = async ( ) => {
55+ export const loadPeerCAs = async ( ) => {
4056 const peerCertsPath = path . join ( utils . constants . DATA_DIRECTORY , utils . constants . PEER_CERTS_SUBDIRECTORY ) ;
4157 log . debug ( `Reading peer CAs from ${ peerCertsPath } ` ) ;
4258 const peerCerts = await fs . readdir ( peerCertsPath ) ;
@@ -49,6 +65,10 @@ export const loadCAs = async () => {
4965 }
5066 }
5167 log . debug ( `Loaded ${ ca . length } peer certificate(s)` ) ;
68+ for ( const caCert of ca ) {
69+ log . debug ( "Outputting CA cert" ) ;
70+ log . debug ( caCert ) ;
71+ }
5272} ;
5373
5474export const genTLSContext = ( ) => {
0 commit comments