Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fortinet _preferred_kex settings interfering with other devices #3463

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions netmiko/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,12 @@ def __init__(
self.system_host_keys = system_host_keys
self.alt_host_keys = alt_host_keys
self.alt_key_file = alt_key_file
self.disabled_algorithms = disabled_algorithms or {}

if disabled_algorithms:
self.disabled_algorithms = disabled_algorithms
else:
self.disabled_algorithms = (
{"pubkeys": ["rsa-sha2-256", "rsa-sha2-512"]}
if disable_sha2_fix
else {}
)
if disable_sha2_fix:
sha2_pubkeys = ["rsa-sha2-256", "rsa-sha2-512"]
# Merge sha2_pubkeys into pubkeys and prevent duplicates with a set
self.disabled_algorithms["pubkeys"] = list(set(self.disabled_algorithms.get("pubkeys", []) + sha2_pubkeys))

# For SSH proxy support
self.ssh_config_file = ssh_config_file
Expand Down
27 changes: 17 additions & 10 deletions netmiko/fortinet/fortinet_ssh.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import paramiko
import re
from typing import Optional
from typing import Optional, Any

from netmiko.no_config import NoConfig
from netmiko.no_enable import NoEnable
Expand All @@ -10,15 +10,22 @@
class FortinetSSH(NoConfig, NoEnable, CiscoSSHConnection):
prompt_pattern = r"[#$]"

def _modify_connection_params(self) -> None:
"""Modify connection parameters prior to SSH connection."""
paramiko_transport = getattr(paramiko, "Transport")
paramiko_transport._preferred_kex = (
"diffie-hellman-group14-sha1",
"diffie-hellman-group-exchange-sha1",
"diffie-hellman-group-exchange-sha256",
"diffie-hellman-group1-sha1",
)
def __init__(self, *args: Any, **kwargs: Any) -> None:
disabled_algorithms = kwargs.get("disabled_algorithms")
if disabled_algorithms is None:
# We only want these and disable the rest
_preferred_kex = {
"diffie-hellman-group14-sha1",
"diffie-hellman-group-exchange-sha1",
"diffie-hellman-group-exchange-sha256",
"diffie-hellman-group1-sha1",
}
paramiko_transport = getattr(paramiko, "Transport")
kwargs["disabled_algorithms"] = {
"kex": list(set(paramiko_transport._preferred_kex) - _preferred_kex)
}

super().__init__(*args, **kwargs)

def _try_session_preparation(self, force_data: bool = False) -> None:
super()._try_session_preparation(force_data=force_data)
Expand Down
Loading