SSH2: move $this->send_seq_no++

This commit is contained in:
terrafrost 2019-09-10 23:43:09 -05:00
parent eab705fbb5
commit a06a166db6

View File

@ -1800,7 +1800,7 @@ class SSH2
if (!$this->decrypt->usesNonce()) { if (!$this->decrypt->usesNonce()) {
list($this->hmac_check, $checkKeyLength) = self::mac_algorithm_to_hash_instance($mac_algorithm); list($this->hmac_check, $checkKeyLength) = self::mac_algorithm_to_hash_instance($mac_algorithm);
$this->hmac_size = $this->getLengthInBytes(); $this->hmac_size = $this->hmac_check->getLengthInBytes();
} else { } else {
$this->hmac_check = new \stdClass; $this->hmac_check = new \stdClass;
$this->hmac_check->name = $mac_algorithm; $this->hmac_check->name = $mac_algorithm;
@ -3823,8 +3823,6 @@ class SSH2
} }
} }
$this->send_seq_no++;
if ($this->encrypt) { if ($this->encrypt) {
switch ($this->encrypt->name) { switch ($this->encrypt->name) {
case 'aes128-gcm@openssh.com': case 'aes128-gcm@openssh.com':
@ -3838,7 +3836,7 @@ class SSH2
$packet = $temp . $this->encrypt->encrypt(substr($packet, 4)); $packet = $temp . $this->encrypt->encrypt(substr($packet, 4));
break; break;
case 'chacha20-poly1305@openssh.com': case 'chacha20-poly1305@openssh.com':
$nonce = pack('N2', 0, $this->send_seq_no - 1); $nonce = pack('N2', 0, $this->send_seq_no);
$this->encrypt->setNonce($nonce); $this->encrypt->setNonce($nonce);
$this->lengthEncrypt->setNonce($nonce); $this->lengthEncrypt->setNonce($nonce);
@ -3865,13 +3863,15 @@ class SSH2
if ($this->hmac_create instanceof Hash && $this->hmac_create->etm) { if ($this->hmac_create instanceof Hash && $this->hmac_create->etm) {
if (($this->hmac_create->getHash() & "\xFF\xFF\xFF\xFF") == 'umac') { if (($this->hmac_create->getHash() & "\xFF\xFF\xFF\xFF") == 'umac') {
$this->hmac_create->setNonce("\0\0\0\0" . pack('N', $this->send_seq_no - 1)); $this->hmac_create->setNonce("\0\0\0\0" . pack('N', $this->send_seq_no));
$hmac = $this->hmac_create->hash($packet); $hmac = $this->hmac_create->hash($packet);
} else { } else {
$hmac = $this->hmac_create->hash(pack('Na*', $this->send_seq_no - 1, $packet)); $hmac = $this->hmac_create->hash(pack('Na*', $this->send_seq_no, $packet));
} }
} }
$this->send_seq_no++;
$packet.= $this->encrypt && $this->encrypt->usesNonce() ? $this->encrypt->getTag() : $hmac; $packet.= $this->encrypt && $this->encrypt->usesNonce() ? $this->encrypt->getTag() : $hmac;
$start = microtime(true); $start = microtime(true);