fix(rest): verify the API certificate by its fingerprint

The REST login never verified the switch in practice: with ssl_verify
off nothing was checked, and with it on a self-signed certificate (the
one every ProCurve ships) failed the CA check and the login was retried
with verification off. Either way the password went to whatever answered
on port 443.

The certificate is now checked by its SHA-256 fingerprint, trust on
first use (napalm-device-types tls_certificates): the caller passes the
fingerprint to expect in optional_args["tls_fingerprints"] and receives
every one seen through optional_args["tls_certificate_observer"]. A
different certificate ends open() with TlsCertificateMismatch before the
password is sent, without trying SSH or Telnet, which would reach the
same host with the same password. The session is pinned to the checked
certificate for every later connection. ssl_verify no longer has an
effect, and the unverified retry is gone.

Closes #17
This commit is contained in:
Christian Manivong committed 2026-11-01 22:18:33 +01:00
1 parent 58428042f1
commit cb7268b89c
6 files changed
+320 -54

No files matched your search

+14
View File
@@ -6,7 +6,21 @@ All notable changes to this driver. The format follows
## [Unreleased]
### Fixed
- The REST API's certificate is verified. A switch's self-signed certificate is checked
by its SHA-256 fingerprint, not by a CA, with trust on first use:
`optional_args["tls_fingerprints"]` (`{"443": "SHA256:AB:CD:…"}`) holds the fingerprint
to expect and `optional_args["tls_certificate_observer"]` receives every one seen. A
different certificate is refused before the password is sent and ends `open()` with
`TlsCertificateMismatch` (a `ConnectionException` naming both fingerprints); the driver
does not fall back to SSH or Telnet then. Every connection of the REST session is held
to the certificate checked (#17).
- A REST login that failed is no longer retried with certificate verification turned off.
### Changed
- `ssl_verify` (`verify_ssl`, `verify`) no longer has any effect: the REST certificate is
verified by its fingerprint instead. Callers that set it to `True` had their login
retried without verification whenever the self-signed certificate failed the CA check.
- 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).
- The floor on napalm is 5.1: older releases import `pkg_resources`, which a Python