fix(ssh): keep the key exchange off DH group16
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 58s
driver / test (3.12) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 28s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m8s
CI / driver (pull_request) Successful in 2m25s
driver / publish (pull_request) Skipped
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 58s
driver / test (3.12) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 28s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m8s
CI / driver (pull_request) Successful in 2m25s
driver / publish (pull_request) Skipped
The switch offers diffie-hellman-group14-sha256 and group16-sha512 only, and paramiko picks group16. On an SG2210P with firmware 5.30 that 4096-bit exchange takes 9 to 16 seconds, against netmiko's 10-second conn_timeout: paramiko then tries to log in on a transport whose key exchange has not finished and fails with "No existing session", so every other poll failed and netOrk flapped the switch between online and offline. group14 takes 1.5 seconds. group16 is now disabled by default; a disabled_algorithms passed in optional_args still wins. The netmiko arguments move into _ssh.py, so tplink_jetstream.py keeps its recorded length.
This commit is contained in:
1 parent
d7e9caa0f3
commit
d14c11e991
4 files changed
+56
-4
No files matched your search
@@ -6,6 +6,13 @@ All notable changes to this driver. The format follows
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- The SSH key exchange no longer uses `diffie-hellman-group16-sha512`. On an SG2210P
|
||||||
|
with firmware 5.30 its 4096-bit exchange took 9 to 16 seconds, against netmiko's
|
||||||
|
10-second `conn_timeout`, so every other connection failed and the switch flapped
|
||||||
|
between online and offline. `diffie-hellman-group14-sha256` takes 1.5 seconds. A
|
||||||
|
`disabled_algorithms` in `optional_args` still takes precedence.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Python 3.12 is the floor (`requires-python = ">=3.12"`): netOrk runs every driver
|
- Python 3.12 is the floor (`requires-python = ">=3.12"`): netOrk runs every driver
|
||||||
on 3.12, so 3.10 and 3.11 are no longer tested (NAPALM/driver-standard#6).
|
on 3.12, so 3.10 and 3.11 are no longer tested (NAPALM/driver-standard#6).
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
"""What the driver hands netmiko for the SSH connection."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from napalm.base.netmiko_helpers import netmiko_args
|
||||||
|
|
||||||
|
#: The switch offers DH group14 and group16 only, and paramiko picks group16. Its
|
||||||
|
#: 4096-bit exchange takes 9-16 s on an SG2210P with firmware 5.30, against
|
||||||
|
#: netmiko's 10 s conn_timeout; group14 takes 1.5 s.
|
||||||
|
SLOW_KEX: dict[str, list[str]] = {"kex": ["diffie-hellman-group16-sha512"]}
|
||||||
|
|
||||||
|
|
||||||
|
def netmiko_connect_args(optional_args: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
"""netmiko's share of ``optional_args``, without group16 unless the caller says otherwise."""
|
||||||
|
args: dict[str, Any] = netmiko_args(optional_args)
|
||||||
|
args.setdefault("disabled_algorithms", SLOW_KEX)
|
||||||
|
return args
|
||||||
@@ -32,13 +32,14 @@ from napalm.base.exceptions import (
|
|||||||
MergeConfigException,
|
MergeConfigException,
|
||||||
ReplaceConfigException,
|
ReplaceConfigException,
|
||||||
)
|
)
|
||||||
from napalm.base.netmiko_helpers import netmiko_args
|
|
||||||
from napalm_device_types import ConfigLifecycleMixin, FingerprintRule, SnmpAgentMixin, SwitchDriver
|
from napalm_device_types import ConfigLifecycleMixin, FingerprintRule, SnmpAgentMixin, SwitchDriver
|
||||||
from napalm_device_types.models import InterfaceConfigDict, VlanConfigDict
|
from napalm_device_types.models import InterfaceConfigDict, VlanConfigDict
|
||||||
from napalm_device_types.ssh_host_keys import HostKeyCheck, SshHostKeyMismatch
|
from napalm_device_types.ssh_host_keys import HostKeyCheck, SshHostKeyMismatch
|
||||||
from netmiko import ConnectHandler
|
from netmiko import ConnectHandler
|
||||||
from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutException
|
from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutException
|
||||||
|
|
||||||
|
from napalm_tplink_jetstream._ssh import netmiko_connect_args
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
#: get_users' password field: the switch never shows a password, so it stays empty.
|
#: get_users' password field: the switch never shows a password, so it stays empty.
|
||||||
@@ -96,13 +97,12 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
|||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.device: ConnectHandler | None = None
|
self.device: ConnectHandler | None = None
|
||||||
|
|
||||||
if optional_args is None:
|
optional_args = optional_args or {}
|
||||||
optional_args = {}
|
|
||||||
|
|
||||||
self.force_no_enable = optional_args.get("force_no_enable", False)
|
self.force_no_enable = optional_args.get("force_no_enable", False)
|
||||||
self.port = optional_args.get("port", 22)
|
self.port = optional_args.get("port", 22)
|
||||||
self.use_canonical_interface = optional_args.get("canonical_int_fmt", False)
|
self.use_canonical_interface = optional_args.get("canonical_int_fmt", False)
|
||||||
self.netmiko_optional_args = netmiko_args(optional_args)
|
self.netmiko_optional_args = netmiko_connect_args(optional_args)
|
||||||
# The host key to expect, and where the one seen is reported (netork#1167).
|
# The host key to expect, and where the one seen is reported (netork#1167).
|
||||||
self._host_key = HostKeyCheck(optional_args, hostname, self.port)
|
self._host_key = HostKeyCheck(optional_args, hostname, self.port)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
"""open() keeps the switch off the 4096-bit DH group, whose key exchange outlasts conn_timeout."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from napalm_tplink_jetstream.tplink_jetstream import TPLinkJetstreamDriver
|
||||||
|
|
||||||
|
HANDLER = "napalm_tplink_jetstream.tplink_jetstream.ConnectHandler"
|
||||||
|
|
||||||
|
|
||||||
|
def _connect_kwargs(optional_args: dict | None = None) -> dict:
|
||||||
|
with patch(HANDLER, return_value=MagicMock()) as handler:
|
||||||
|
TPLinkJetstreamDriver("10.0.0.8", "admin", "s3cret", optional_args=optional_args).open()
|
||||||
|
return handler.call_args.kwargs
|
||||||
|
|
||||||
|
|
||||||
|
def test_group16_is_disabled_by_default():
|
||||||
|
kwargs = _connect_kwargs()
|
||||||
|
assert kwargs["disabled_algorithms"] == {"kex": ["diffie-hellman-group16-sha512"]}
|
||||||
|
|
||||||
|
|
||||||
|
def test_disabled_algorithms_from_the_caller_win():
|
||||||
|
own = {"kex": [], "ciphers": ["3des-cbc"]}
|
||||||
|
kwargs = _connect_kwargs({"disabled_algorithms": own})
|
||||||
|
assert kwargs["disabled_algorithms"] == own
|
||||||
Reference in new issue
Block a user