bugfix key storage

This commit is contained in:
AJ ONeal 2019-03-06 23:28:28 -07:00
parent 1c9396216a
commit 1fda5b15d0
1 changed files with 12 additions and 8 deletions

View File

@ -765,19 +765,23 @@ var keystore = require('../lib/keystore.js').create(state);
var keyname = 'telebit-remote'; var keyname = 'telebit-remote';
state.keystore = keystore; state.keystore = keystore;
state.keystoreSecure = !keystore.insecure; state.keystoreSecure = !keystore.insecure;
keystore.get(keyname).then(function (jwk) { keystore.get(keyname).then(function (key) {
if (jwk && jwk.kty) { if (key && key.kty) {
state.key = jwk; state.key = key;
fs.readFile(confpath, 'utf8', parseConfig); fs.readFile(confpath, 'utf8', parseConfig);
return; return;
} }
console.info('Generating Private Key...'); var keypairs = require('keypairs');
return require('keypairs').generate().then(function (jwk) { return keypairs.generate().then(function (pair) {
var jwk = pair.private;
return keystore.set(keyname, jwk).then(function () { return keystore.set(keyname, jwk).then(function () {
console.info("Generated New %s %s Private Key.", jwk.kty, (jwk.crv || Buffer.from(jwk.n, 'base64').byteLength * 8)); return keypairs.thumbprint({ jwk: pair.public }).then(function (kid) {
state.key = jwk; var size = (jwk.crv || Buffer.from(jwk.n, 'base64').byteLength * 8);
fs.readFile(confpath, 'utf8', parseConfig); console.info("Generated new %s %s private key with thumbprint %s", jwk.kty, size, kid);
state.key = jwk;
fs.readFile(confpath, 'utf8', parseConfig);
});
}); });
}); });
}); });