add client otp

This commit is contained in:
AJ ONeal 2018-06-13 14:40:44 -06:00
parent ee15f1be9c
commit bff71aa813
2 changed files with 32 additions and 10 deletions

View File

@ -102,7 +102,12 @@ function serveControls() {
if (/\btelebit\.cloud\b/i.test(state.config.relay) && state.config.email && !state.token) { if (/\btelebit\.cloud\b/i.test(state.config.relay) && state.config.email && !state.token) {
dumpy.code = "AWAIT_AUTH"; dumpy.code = "AWAIT_AUTH";
dumpy.message = "Check your email. You must verify your email address to activate this device."; dumpy.message = [
"Check your email."
, "You must verify your email address to activate this device."
, ""
, " Login Code (if needed): " + state.otp
].join('\n');
} }
res.end(JSON.stringify(dumpy)); res.end(JSON.stringify(dumpy));
@ -465,6 +470,16 @@ function connectTunnel() {
tun.end(); tun.end();
controlServer.close(); controlServer.close();
} }
// reverse 2FA otp
function leftpad(i, n, c) {
while (i.toString().length < (n || 4)) {
i = (c || '0') + i;
}
return i;
}
function getOtp() {
return leftpad(Math.random() * 9999, 4, '0');
}
process.on('SIGINT', sigHandler); process.on('SIGINT', sigHandler);
state.net = state.net || { state.net = state.net || {
createConnection: function (info, cb) { createConnection: function (info, cb) {
@ -477,6 +492,7 @@ function connectTunnel() {
} }
}; };
state.otp = getOtp();
state.greenlock = state.config.greenlock || {}; state.greenlock = state.config.greenlock || {};
state.sortingHat = state.config.sortingHat || path.resolve(__dirname, '..', 'lib/sorting-hat.js'); state.sortingHat = state.config.sortingHat || path.resolve(__dirname, '..', 'lib/sorting-hat.js');
@ -484,15 +500,19 @@ function connectTunnel() {
if (state.config.email && !state.token) { if (state.config.email && !state.token) {
console.info(); console.info();
console.info('=================================='); console.info('====================================');
console.info('= HEY! LISTEN! ='); console.info('= HEY! LISTEN! =');
console.info('=================================='); console.info('====================================');
console.info('= ='); console.info('= =');
console.info('= 1. Open your email ='); console.info('= 1. Open your email =');
console.info('= =');
console.info('= 2. Click the magic login link ='); console.info('= 2. Click the magic login link =');
console.info('= Login Code (if needed): 0000 ='.replace('0000', state.otp));
console.info('= =');
console.info('= 3. Check back here for deets ='); console.info('= 3. Check back here for deets =');
console.info('= ='); console.info('= =');
console.info('=================================='); console.info('= =');
console.info('====================================');
console.info(); console.info();
} }
// TODO Check undefined vs false for greenlock config // TODO Check undefined vs false for greenlock config
@ -579,6 +599,7 @@ function connectTunnel() {
var tun = remote.connect({ var tun = remote.connect({
relay: state.relay relay: state.relay
, config: state.config , config: state.config
, otp: state.otp
, sortingHat: state.sortingHat , sortingHat: state.sortingHat
, net: state.net , net: state.net
, insecure: state.insecure , insecure: state.insecure

View File

@ -485,6 +485,7 @@ function _connect(state) {
, subject_scheme: 'mailto' , subject_scheme: 'mailto'
// TODO create domains list earlier // TODO create domains list earlier
, scope: Object.keys(state.config.servernames || {}).join(',') , scope: Object.keys(state.config.servernames || {}).join(',')
, otp: state.otp
, hostname: os.hostname() , hostname: os.hostname()
// Used for User-Agent // Used for User-Agent
, os_type: os.type() , os_type: os.type()