fix(rest): no plain-HTTP login for a switch with a pinned certificate
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Failing after 1m9s
driver / test (3.13) (pull_request) Failing after 1m0s
driver / lowest (pull_request) Failing after 29s
driver / build (pull_request) Successful in 37s
driver / security (pull_request) Successful in 1m17s
CI / driver (pull_request) Failing after 3m1s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Failing after 1m9s
driver / test (3.13) (pull_request) Failing after 1m0s
driver / lowest (pull_request) Failing after 29s
driver / build (pull_request) Successful in 37s
driver / security (pull_request) Successful in 1m17s
CI / driver (pull_request) Failing after 3m1s
driver / publish (pull_request) Skipped
The probe falls back to HTTP when HTTPS does not answer. For a switch known by its certificate that is a downgrade anyone who blocks port 443 can force: the login would go out in clear text, unchecked. With a pinned fingerprint the REST API is skipped then and the CLI transports are tried; without one, plain HTTP is used as before. Refs #17
This commit is contained in:
1 parent
cb7268b89c
commit
e51ddcd151
5 files changed
+46
-4
No files matched your search
@@ -41,7 +41,7 @@ from napalm_device_types.ssh_host_keys import (
|
||||
HostKeyCheck,
|
||||
SshHostKeyMismatch,
|
||||
)
|
||||
from napalm_device_types.tls_certificates import TlsCertificateMismatch
|
||||
from napalm_device_types.tls_certificates import CertificateCheck, TlsCertificateMismatch
|
||||
from netmiko import ConnectHandler
|
||||
from netmiko.exceptions import (
|
||||
NetmikoAuthenticationException,
|
||||
@@ -49,7 +49,7 @@ from netmiko.exceptions import (
|
||||
)
|
||||
|
||||
from napalm_procurve import parsers
|
||||
from napalm_procurve.api_client import ProcurveApiClient
|
||||
from napalm_procurve.api_client import HTTPS_PORT, ProcurveApiClient
|
||||
|
||||
logger = logging.getLogger("napalm_procurve")
|
||||
|
||||
@@ -275,6 +275,10 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
logger.warning("REST API not detected on %s — falling back to CLI", self.hostname)
|
||||
self._attempts.append("api: not detected")
|
||||
return False
|
||||
if proto == "http" and self._certificate_pinned():
|
||||
# Port 443 blocked would otherwise downgrade the login to clear text (#17).
|
||||
self._attempts.append("api: only plain HTTP answered, the certificate is pinned")
|
||||
return False
|
||||
|
||||
client = ProcurveApiClient(
|
||||
hostname=self.hostname,
|
||||
@@ -297,6 +301,9 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
logger.info("Connected to %s via REST API (%s %s)", self.hostname, proto, ver)
|
||||
return True
|
||||
|
||||
def _certificate_pinned(self) -> bool:
|
||||
return CertificateCheck(self._optional_args, self.hostname, HTTPS_PORT).expected is not None
|
||||
|
||||
def _netmiko_kwargs(self, legacy: bool = False) -> dict:
|
||||
"""Return kwargs for ConnectHandler, merging explicit fields with netmiko_optional_args.
|
||||
|
||||
|
||||
Reference in new issue
Block a user