Skip to content

Commit e9247cf

Browse files
authored
feat: non-incognito (#83)
1 parent 37d4f60 commit e9247cf

File tree

10 files changed

+225
-42
lines changed

10 files changed

+225
-42
lines changed

package-lock.json

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"lodash.tonumber": "^4.0.3",
119119
"micromodal": "^0.4.6",
120120
"multistream": "^4.1.0",
121-
"node-forge": "^0.10.0",
121+
"node-forge": "github:githoniel/forge",
122122
"pkijs": "^2.1.90",
123123
"promise-controller": "^1.0.0",
124124
"promise.prototype.finally": "^3.1.2",
@@ -129,6 +129,7 @@
129129
"stream-browserify": "^3.0.0",
130130
"typedarray-to-buffer": "^4.0.0",
131131
"url": "^0.11.0",
132-
"utf-8-validate": "^5.0.4"
132+
"utf-8-validate": "^5.0.4",
133+
"uuid": "^8.3.2"
133134
}
134-
}
135+
}

src/channel/channel.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,13 @@ module.exports = class ZitiChannel {
189189
ws: this._zws,
190190
ch: this,
191191
datacb: this._recvFromWireAfterDecrypt
192-
193192
});
193+
this._ctx.logger.debug('starting ZitiTLSConnection.pullKeyPair for: [%o]', this._tlsConn.getUUID());
194+
await this._tlsConn.pullKeyPair().catch((e) => {
195+
this._ctx.logger.error(e);
196+
throw new Error(e);
197+
});
198+
this._ctx.logger.debug('completed ZitiTLSConnection.pullKeyPair for: [%o]', this._tlsConn.getUUID());
194199

195200
this._tlsConn.create();
196201

@@ -827,7 +832,7 @@ module.exports = class ZitiChannel {
827832
*/
828833
async _recvFromWire(data) {
829834
let buffer = await data.arrayBuffer();
830-
this._ctx.logger.trace("_recvFromWire <- data len[%o]", buffer.byteLength);
835+
this._ctx.logger.debug("_recvFromWire <- data len[%o]", buffer.byteLength);
831836
let tlsBinaryString = Buffer.from(buffer).toString('binary');
832837
this._tlsConn.process(tlsBinaryString);
833838
}
@@ -892,7 +897,7 @@ module.exports = class ZitiChannel {
892897
let contentType = contentTypeView[0];
893898

894899
let sequenceView = new Int32Array(buffer, 8, 1);
895-
this._ctx.logger.trace("recv <- contentType[%o] seq[%o]", contentType, sequenceView[0]);
900+
this._ctx.logger.debug("recv <- contentType[%o] seq[%o]", contentType, sequenceView[0]);
896901

897902
let responseSequence = sequenceView[0];
898903

src/channel/tls-connection.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ const utils = require('../utils/utils');
2626
const zitiConstants = require('../constants');
2727
const forge = require('node-forge');
2828
const 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

Comments
 (0)