From 61ffe1a147973947195bc1c8390b2fc8c50f2145 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 7 Jan 2020 00:20:47 -0600 Subject: [PATCH] SSH2: fix rare key exchange issue --- phpseclib/Net/SSH2.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 0e58b643..59fba230 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -1616,7 +1616,9 @@ class SSH2 $temp = unpack('Nlength', substr($this->signature, 0, 4)); $this->signature_format = substr($this->signature, 4, $temp['length']); $keyBytes = DH::computeSecret($ourPrivate, $theirPublicBytes); - if (($keyBytes[0] & "\x80") === "\x80") { + if (($keyBytes & "\xFF\x80") === "\x00\x00") { + $keyBytes = substr($keyBytes, 1); + } elseif (($keyBytes[0] & "\x80") === "\x80") { $keyBytes = "\0$keyBytes"; }