Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Nov 15, 2024
2 parents 4526ef6 + f7714a5 commit 9dab78c
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions phpseclib/Net/SSH2.php
Original file line number Diff line number Diff line change
Expand Up @@ -4677,41 +4677,65 @@ public function setTerminal(string $term): void
*/
public function setPreferredAlgorithms(array $methods): void
{
$keys = ['client_to_server', 'server_to_client'];

if (isset($methods['kex']) && is_string($methods['kex'])) {
$methods['kex'] = explode(',', $methods['kex']);
}

if (isset($methods['hostkey']) && is_string($methods['hostkey'])) {
$methods['hostkey'] = explode(',', $methods['hostkey']);
}

foreach ($keys as $key) {
if (isset($methods[$key])) {
$a = &$methods[$key];
if (isset($a['crypt']) && is_string($a['crypt'])) {
$a['crypt'] = explode(',', $a['crypt']);
}
if (isset($a['comp']) && is_string($a['comp'])) {
$a['comp'] = explode(',', $a['comp']);
}
if (isset($a['mac']) && is_string($a['mac'])) {
$a['mac'] = explode(',', $a['mac']);
}
}
}

$preferred = $methods;

if (isset($preferred['kex'])) {
$preferred['kex'] = array_intersect(
is_string($preferred['kex']) ? [$preferred['kex']] : $preferred['kex'],
$preferred['kex'],
static::getSupportedKEXAlgorithms()
);
}

if (isset($preferred['hostkey'])) {
$preferred['hostkey'] = array_intersect(
is_string($preferred['hostkey']) ? [$preferred['hostkey']] : $preferred['hostkey'],
$preferred['hostkey'],
static::getSupportedHostKeyAlgorithms()
);
}

$keys = ['client_to_server', 'server_to_client'];
foreach ($keys as $key) {
if (isset($preferred[$key])) {
$a = &$preferred[$key];
if (isset($a['crypt'])) {
$a['crypt'] = array_intersect(
is_string($a['crypt']) ? [$a['crypt']] : $a['crypt'],
$a['crypt'],
static::getSupportedEncryptionAlgorithms()
);
}
if (isset($a['comp'])) {
$a['comp'] = array_intersect(
is_string($a['comp']) ? [$a['comp']] : $a['comp'],
$a['comp'],
static::getSupportedCompressionAlgorithms()
);
}
if (isset($a['mac'])) {
$a['mac'] = array_intersect(
is_string($a['mac']) ? [$a['mac']] : $a['mac'],
$a['mac'],
static::getSupportedMACAlgorithms()
);
}
Expand Down

0 comments on commit 9dab78c

Please sign in to comment.