From 0a668f50b8d56b7bc48d5cc1f07aeefb0646ae8e Mon Sep 17 00:00:00 2001 From: Trevor Johnston Date: Thu, 12 Nov 2015 18:11:29 -0500 Subject: [PATCH] read keys from invite codes, and prefer them --- src/cloud/social/provider.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/cloud/social/provider.ts b/src/cloud/social/provider.ts index e147a84..623ca5d 100644 --- a/src/cloud/social/provider.ts +++ b/src/cloud/social/provider.ts @@ -31,6 +31,8 @@ interface Invite { user?: string; // Password. pass?: string; + // Private key, base64-encoded. + key?: string; } // Type of the object placed, in serialised form, in storage @@ -365,6 +367,22 @@ class Connection { } this.state_ = ConnectionState.CONNECTING; + let connectConfig: ssh2.ConnectConfig = { + host: this.invite_.host, + port: SSH_SERVER_PORT, + username: this.invite_.user, + // Remaining fields only for type-correctness. + tryKeyboard: false, + debug: undefined + }; + + if (this.invite_.key) { + connectConfig['privateKey'] = new Buffer(this.invite_.key, 'base64'); + } else { + log.warn('using password-based auth, support will be removed soon!'); + connectConfig['password'] = this.invite_.pass; + } + return new Promise((F, R) => { this.client_.on('ready', () => { this.setState_(ConnectionState.ESTABLISHING_TUNNEL); @@ -446,12 +464,7 @@ class Connection { // TODO: when does this occur? don't see it on normal close or failure log.debug('%1: connection close: %2', this.name_, hadError); this.close(); - }).connect({ - host: this.invite_.host, - port: SSH_SERVER_PORT, - username: this.invite_.user, - password: this.invite_.pass - }); + }).connect(connectConfig); }); }