From f292931aed9d3929b4acf618166492d713d93012 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 4 Jul 2012 13:36:26 -0500 Subject: [PATCH] - make Net_SSH2 return more printer friendly server public host keys --- phpseclib/Crypt/RSA.php | 3 ++- phpseclib/Net/SSH2.php | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 84d511ae..b8cc5429 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -1110,8 +1110,9 @@ class Crypt_RSA { return false; } extract(unpack('Nlength', $this->_string_shift($key, 4))); + $realModulus = new Math_BigInteger($this->_string_shift($key, $length), -256); return strlen($key) ? false : array( - 'modulus' => new Math_BigInteger($this->_string_shift($key, $length), -256), + 'modulus' => $realModulus, 'publicExponent' => $modulus ); } else { diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 3a7c330d..f7d0ed89 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -198,7 +198,7 @@ class Net_SSH2 { * @var String * @access private */ - var $identifier = 'SSH-2.0-phpseclib_0.2'; + var $identifier = 'SSH-2.0-phpseclib_0.3'; /** * The Socket Object @@ -671,6 +671,14 @@ class Net_SSH2 { */ var $realtime_log_size; + /** + * Has the signature been validated? + * + * @see Net_SSH2::getServerPublicHostKey() + * @access private + */ + var $signature_validated = false; + /** * Real-time log file wrap boolean * @@ -2773,6 +2781,14 @@ class Net_SSH2 { extract(unpack('Nlength', $this->_string_shift($server_public_host_key, 4))); $this->_string_shift($server_public_host_key, $length); + if ($this->signature_validated) { + return $this->bitmap ? + $this->signature_format . ' ' . base64_encode($this->server_public_host_key) : + false; + } + + $this->signature_validated = true; + switch ($this->signature_format) { case 'ssh-dss': $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4)); @@ -2874,8 +2890,12 @@ class Net_SSH2 { user_error('Bad server signature', E_USER_NOTICE); return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE); } + break; + default: + user_error('Unsupported signature format', E_USER_NOTICE); + return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE); } - return $this->server_public_host_key; + return $this->signature_format . ' ' . base64_encode($this->server_public_host_key); } } \ No newline at end of file