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

Merged
christianmanivong merged 4 commits from fix/rest-cert-tofu-17 into main 2026-11-02 00:13:16 +00:00
4 Commits
Author SHA1 Message Date
Christian Manivong b3c239d988 chore(deps): floor napalm-device-types at 4.23.0
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m8s
driver / test (3.12) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 35s
driver / test (3.13) (pull_request) Successful in 1m14s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m10s
CI / driver (pull_request) Successful in 2m44s
driver / publish (pull_request) Skipped
4.23.0 is on PyPI with everything this branch uses, the REST
certificate check (tls_certificates) included.
2026-11-02 00:37:23 +01:00
Christian Manivong 586632efe0 Merge remote-tracking branch 'origin/main' into fix/rest-cert-tofu-17
The REST login now checks the certificate before it posts the password
(#17) and then tells a web page from a refused login (#13); the two
login-answer checks moved into _require_login so connect() stays within
the function-length limit. #13's REST tests stand in for the switch's
certificate, since connect() fetches it before the login.
2026-11-02 00:37:11 +01:00
Christian Manivong e51ddcd151 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
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
2026-11-01 22:24:30 +01:00
Christian Manivong cb7268b89c 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
2026-11-01 22:18:33 +01:00