@@ -26,13 +26,12 @@ const utils = require('../utils/utils');
2626const zitiConstants = require ( '../constants' ) ;
2727const forge = require ( 'node-forge' ) ;
2828const ab2str = require ( 'arraybuffer-to-string' ) ;
29- forge . options . usePureJavaScript = true ;
29+ const isUndefined = require ( 'lodash.isundefined' ) ;
30+ const isNull = require ( 'lodash.isnull' ) ;
31+ const { v4 : uuidv4 } = require ( 'uuid' ) ;
3032
33+ forge . options . usePureJavaScript = true ;
3134
32- async function pullKeyPair ( self ) {
33- self . _clientCertPEM = await ls . getWithExpiry ( zitiConstants . get ( ) . ZITI_IDENTITY_CERT ) ;
34- self . _clientPrivateKeyPEM = await ls . getWithExpiry ( zitiConstants . get ( ) . ZITI_IDENTITY_PRIVATE_KEY ) ;
35- }
3635
3736/**
3837 * @typicalname connection
@@ -58,17 +57,41 @@ module.exports = class ZitiTLSConnection {
5857
5958 this . _connected = false ;
6059
60+ this . _uuid = uuidv4 ( ) ;
61+
62+ }
63+
64+
65+ /**
66+ * Populate this TLS Connection object with the keypair from local storage
67+ */
68+ async pullKeyPair ( ) {
6169
62- // Pull CA
63- // this._caStore = forge.pki.createCaStore([ ls.getWithExpiry(zitiConstants.get().ZITI_IDENTITY_CA) ]);
64-
65- // Pull keypair
66- pullKeyPair ( this ) ;
67- // this._clientCertPEM = ls.getWithExpiry(zitiConstants.get().ZITI_IDENTITY_CERT);
68- // this._clientPrivateKeyPEM = ls.getWithExpiry(zitiConstants.get().ZITI_IDENTITY_PRIVATE_KEY);
70+ const self = this ;
71+
72+ return new Promise ( async ( resolve , reject ) => {
73+
74+ this . _clientCertPEM = await ls . getWithExpiry ( zitiConstants . get ( ) . ZITI_IDENTITY_CERT ) ;
75+ this . _clientPrivateKeyPEM = await ls . getWithExpiry ( zitiConstants . get ( ) . ZITI_IDENTITY_PRIVATE_KEY ) ;
76+
77+ if (
78+ isUndefined ( this . _clientCertPEM ) ||
79+ isUndefined ( this . _clientPrivateKeyPEM ) ||
80+ isNull ( this . _clientCertPEM ) ||
81+ isNull ( this . _clientPrivateKeyPEM )
82+ ) {
83+ return reject ( new Error ( 'keypair nor present in local storage' ) ) ;
84+ }
85+
86+ return resolve ( ) ;
87+
88+ } ) ;
6989
70- let self = this ;
90+ }
91+
7192
93+ getUUID ( ) {
94+ return this . _uuid ;
7295 }
7396
7497
@@ -89,6 +112,8 @@ module.exports = class ZitiTLSConnection {
89112
90113 // These are the cipher suites we support (in order of preference)
91114 cipherSuites : [
115+ forge . tls . CipherSuites . TLS_RSA_WITH_AES_128_CBC_SHA256 ,
116+ // forge.tls.CipherSuites.TLS_RSA_WITH_AES_256_CBC_SHA256,
92117 forge . tls . CipherSuites . TLS_RSA_WITH_AES_128_CBC_SHA ,
93118 forge . tls . CipherSuites . TLS_RSA_WITH_AES_256_CBC_SHA
94119 ] ,
@@ -127,11 +152,13 @@ module.exports = class ZitiTLSConnection {
127152
128153 // client-side cert
129154 getCertificate : function ( connection , hint ) {
155+ self . _ctx . logger . debug ( 'getCertificate(): for: %o, [%o]' , self . _uuid , self . _clientCertPEM ) ;
130156 return self . _clientCertPEM ;
131157 } ,
132158
133159 // client-side private key
134160 getPrivateKey : function ( connection , cert ) {
161+ self . _ctx . logger . debug ( 'getPrivateKey(): for: %o, [%o]' , self . _uuid , self . _clientPrivateKeyPEM ) ;
135162 return self . _clientPrivateKeyPEM ;
136163 } ,
137164
@@ -168,6 +195,7 @@ module.exports = class ZitiTLSConnection {
168195
169196 error : function ( connection , error ) {
170197 self . _ctx . logger . error ( 'uh oh' , error ) ;
198+ throw error ;
171199 }
172200 } ) ;
173201 }
0 commit comments