11/// <reference path='../../../../third_party/typings/browser.d.ts' />
2+ /// <reference path='../../../../third_party/sha1/sha1.d.ts' />
23
34require ( '../social/monkey/process' ) ;
45
@@ -8,6 +9,8 @@ import logging = require('../../logging/logging');
89import promises = require( '../../promises/promises' ) ;
910import queue = require( '../../handler/queue' ) ;
1011
12+ import sha1 = require( 'crypto/sha1' ) ;
13+
1114// https://github.com/borisyankov/DefinitelyTyped/blob/master/ssh2/ssh2-tests.ts
1215import * as ssh2 from 'ssh2' ;
1316var Client = require ( 'ssh2' ) . Client ;
@@ -44,6 +47,9 @@ interface Invite {
4447 key : string ;
4548 // True iff uProxy has root access on the server, i.e. uProxy deployed it.
4649 isAdmin ?: boolean ;
50+ // Host key that should be used to verify the server, base-64 encoded
51+ // (from known_hosts file or public key)
52+ hostKey ?: string ;
4753}
4854
4955// Type of the object placed, in serialised form, in storage
@@ -474,6 +480,15 @@ class Connection {
474480 connectConfig [ 'privateKey' ] = new Buffer ( this . invite_ . key , 'base64' ) ;
475481 }
476482
483+ if ( this . invite_ . hostKey ) {
484+ connectConfig . hostHash = 'sha1' ;
485+ let keyBuffer = new Buffer ( this . invite_ . hostKey , 'base64' ) ;
486+ let expectedHash = sha1 . hex_sha1 ( keyBuffer . toString ( 'binary' ) ) ;
487+ connectConfig . hostVerifier = ( keyHash :string ) => {
488+ return keyHash === expectedHash ;
489+ } ;
490+ }
491+
477492 return new Promise < void > ( ( F , R ) => {
478493 this . connection_ . on ( 'ready' , ( ) => {
479494 // TODO: set a timeout here, too
0 commit comments