MAJOR: Updates for Authenticated Web UI and CLI #30

Open
coolaj86 wants to merge 77 commits from next into master
1 changed files with 12 additions and 8 deletions
Showing only changes of commit 1fda5b15d0 - Show all commits

View File

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