SSH2: update setPreferredAlgorithms() to accept csv's

This commit is contained in:
terrafrost 2024-11-14 20:13:31 -06:00
parent 40e13eff99
commit 2b3d219fb4

View File

@ -5133,42 +5133,66 @@ class Net_SSH2
*/ */
function setPreferredAlgorithms($methods) function setPreferredAlgorithms($methods)
{ {
$keys = array('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; $preferred = $methods;
if (isset($preferred['kex'])) { if (isset($preferred['kex'])) {
$preferred['kex'] = array_intersect( $preferred['kex'] = array_intersect(
is_string($preferred['kex']) ? array($preferred['kex']) : $preferred['kex'], $preferred['kex'],
$this->getSupportedKEXAlgorithms() static::getSupportedKEXAlgorithms()
); );
} }
if (isset($preferred['hostkey'])) { if (isset($preferred['hostkey'])) {
$preferred['hostkey'] = array_intersect( $preferred['hostkey'] = array_intersect(
is_string($preferred['hostkey']) ? array($preferred['hostkey']) : $preferred['hostkey'], $preferred['hostkey'],
$this->getSupportedHostKeyAlgorithms() static::getSupportedHostKeyAlgorithms()
); );
} }
$keys = array('client_to_server', 'server_to_client');
foreach ($keys as $key) { foreach ($keys as $key) {
if (isset($preferred[$key])) { if (isset($preferred[$key])) {
$a = &$preferred[$key]; $a = &$preferred[$key];
if (isset($a['crypt'])) { if (isset($a['crypt'])) {
$a['crypt'] = array_intersect( $a['crypt'] = array_intersect(
is_string($a['crypt']) ? array($a['crypt']) : $a['crypt'], $a['crypt'],
$this->getSupportedEncryptionAlgorithms() static::getSupportedEncryptionAlgorithms()
); );
} }
if (isset($a['comp'])) { if (isset($a['comp'])) {
$a['comp'] = array_intersect( $a['comp'] = array_intersect(
is_string($a['comp']) ? array($a['comp']) : $a['comp'], $a['comp'],
$this->getSupportedCompressionAlgorithms() static::getSupportedCompressionAlgorithms()
); );
} }
if (isset($a['mac'])) { if (isset($a['mac'])) {
$a['mac'] = array_intersect( $a['mac'] = array_intersect(
is_string($a['mac']) ? array($a['mac']) : $a['mac'], $a['mac'],
$this->getSupportedMACAlgorithms() static::getSupportedMACAlgorithms()
); );
} }
} }