New module napalm_device_types/tls_certificates.py, the HTTPS counterpart of ssh_host_keys: trust on first use by certificate fingerprint.
In:optional_args["tls_fingerprints"] = {"443": "SHA256:AB:CD:…"} (SHA-256 of the DER certificate; prefix, colons, spaces and case optional on input).
Out:optional_args["tls_certificate_observer"] receives {host, port, seen: {fingerprint}, expected: {fingerprint} | None, accepted}; a failing observer is logged, not raised.
CertificateCheck: verify_server(timeout) (own stdlib-ssl handshake, no CA/hostname check), pin(session) (requests adapter with urllib3 assert_fingerprint, so every later connection must present the checked certificate), refusing() (maps urllib3's mismatch to TlsCertificateMismatch), observe().
TlsCertificateMismatch(ConnectionException) names both fingerprints.
requests>=2.25.0 is now a declared dependency.
Why: NAPALM/napalm-hpe-aruba-procurve#17 — the REST transport never verified the switch's (self-signed) certificate in practice. Decision: pin by fingerprint on first use, like SSH host keys.
Tested: tests/test_tls_certificates.py (real TLS over a socket pair with a generated self-signed certificate; failed first). pytest 1069 passed, coverage 99 % on the module, ruff, mypy strict, napalm-standard check/ratchet green. CHANGELOG [Unreleased] → Added (MINOR).
Merge order: this → release → napalm-hpe-aruba-procurve fix/rest-cert-tofu-17 (floor) → netOrk fix/rest-cert-tofu (pins; netOrk imports tls_certificates at module level).
New module `napalm_device_types/tls_certificates.py`, the HTTPS counterpart of `ssh_host_keys`: trust on first use by certificate fingerprint.
- **In:** `optional_args["tls_fingerprints"]` = `{"443": "SHA256:AB:CD:…"}` (SHA-256 of the DER certificate; prefix, colons, spaces and case optional on input).
- **Out:** `optional_args["tls_certificate_observer"]` receives `{host, port, seen: {fingerprint}, expected: {fingerprint} | None, accepted}`; a failing observer is logged, not raised.
- `CertificateCheck`: `verify_server(timeout)` (own stdlib-ssl handshake, no CA/hostname check), `pin(session)` (requests adapter with urllib3 `assert_fingerprint`, so every later connection must present the checked certificate), `refusing()` (maps urllib3's mismatch to `TlsCertificateMismatch`), `observe()`.
- `TlsCertificateMismatch(ConnectionException)` names both fingerprints.
- `requests>=2.25.0` is now a declared dependency.
Why: NAPALM/napalm-hpe-aruba-procurve#17 — the REST transport never verified the switch's (self-signed) certificate in practice. Decision: pin by fingerprint on first use, like SSH host keys.
Tested: `tests/test_tls_certificates.py` (real TLS over a socket pair with a generated self-signed certificate; failed first). pytest 1069 passed, coverage 99 % on the module, ruff, mypy strict, `napalm-standard check`/`ratchet` green. CHANGELOG [Unreleased] → Added (MINOR).
Merge order: this → release → napalm-hpe-aruba-procurve `fix/rest-cert-tofu-17` (floor) → netOrk `fix/rest-cert-tofu` (pins; netOrk imports `tls_certificates` at module level).
Devices ship self-signed certificates, so a driver either fails the CA
check on every one of them or turns verification off and sends the
login to whatever answers on the address. tls_certificates pins the
certificate by its SHA-256 fingerprint instead, shaped like
ssh_host_keys: the caller passes the fingerprint to expect by port
(optional_args["tls_fingerprints"]), the driver refuses any other
certificate before a request carries credentials, and every certificate
seen goes to optional_args["tls_certificate_observer"]. Without a
fingerprint the first certificate is accepted.
CertificateCheck checks the certificate in a handshake of its own, then
pins a requests session to it (urllib3's assert_fingerprint, direct and
through a proxy), so no other host can step in between the check and
the login.
Refs NAPALM/napalm-hpe-aruba-procurve#17
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
New module
napalm_device_types/tls_certificates.py, the HTTPS counterpart ofssh_host_keys: trust on first use by certificate fingerprint.optional_args["tls_fingerprints"]={"443": "SHA256:AB:CD:…"}(SHA-256 of the DER certificate; prefix, colons, spaces and case optional on input).optional_args["tls_certificate_observer"]receives{host, port, seen: {fingerprint}, expected: {fingerprint} | None, accepted}; a failing observer is logged, not raised.CertificateCheck:verify_server(timeout)(own stdlib-ssl handshake, no CA/hostname check),pin(session)(requests adapter with urllib3assert_fingerprint, so every later connection must present the checked certificate),refusing()(maps urllib3's mismatch toTlsCertificateMismatch),observe().TlsCertificateMismatch(ConnectionException)names both fingerprints.requests>=2.25.0is now a declared dependency.Why: NAPALM/napalm-hpe-aruba-procurve#17 — the REST transport never verified the switch's (self-signed) certificate in practice. Decision: pin by fingerprint on first use, like SSH host keys.
Tested:
tests/test_tls_certificates.py(real TLS over a socket pair with a generated self-signed certificate; failed first). pytest 1069 passed, coverage 99 % on the module, ruff, mypy strict,napalm-standard check/ratchetgreen. CHANGELOG [Unreleased] → Added (MINOR).Merge order: this → release → napalm-hpe-aruba-procurve
fix/rest-cert-tofu-17(floor) → netOrkfix/rest-cert-tofu(pins; netOrk importstls_certificatesat module level).