certinspect 2.4.3__tar.gz → 2.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {certinspect-2.4.3/src/certinspect.egg-info → certinspect-2.4.4}/PKG-INFO +5 -2
  2. {certinspect-2.4.3 → certinspect-2.4.4}/README.md +4 -1
  3. {certinspect-2.4.3 → certinspect-2.4.4}/pyproject.toml +1 -1
  4. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/__init__.py +1 -1
  5. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/cli.py +13 -2
  6. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/fetch.py +7 -3
  7. {certinspect-2.4.3 → certinspect-2.4.4/src/certinspect.egg-info}/PKG-INFO +5 -2
  8. {certinspect-2.4.3 → certinspect-2.4.4}/tests/test_cli.py +35 -0
  9. {certinspect-2.4.3 → certinspect-2.4.4}/LICENSE +0 -0
  10. {certinspect-2.4.3 → certinspect-2.4.4}/setup.cfg +0 -0
  11. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/args.py +0 -0
  12. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/completion.py +0 -0
  13. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/config.py +0 -0
  14. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/discover.py +0 -0
  15. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/exit_codes.py +0 -0
  16. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/formatter.py +0 -0
  17. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/httpfetch.py +0 -0
  18. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/models.py +0 -0
  19. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/parser.py +0 -0
  20. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/render.py +0 -0
  21. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/revocation.py +0 -0
  22. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect/state.py +0 -0
  23. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect.egg-info/SOURCES.txt +0 -0
  24. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect.egg-info/dependency_links.txt +0 -0
  25. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect.egg-info/entry_points.txt +0 -0
  26. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect.egg-info/requires.txt +0 -0
  27. {certinspect-2.4.3 → certinspect-2.4.4}/src/certinspect.egg-info/top_level.txt +0 -0
  28. {certinspect-2.4.3 → certinspect-2.4.4}/tests/test_discover.py +0 -0
  29. {certinspect-2.4.3 → certinspect-2.4.4}/tests/test_fetch.py +0 -0
  30. {certinspect-2.4.3 → certinspect-2.4.4}/tests/test_formatter.py +0 -0
  31. {certinspect-2.4.3 → certinspect-2.4.4}/tests/test_parser.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: certinspect
3
- Version: 2.4.3
3
+ Version: 2.4.4
4
4
  Summary: Command-line TLS certificate inspector
5
5
  Author-email: Michele Angrisano <michele.angrisano@gmail.com>
6
6
  License-Expression: MIT
@@ -339,7 +339,10 @@ SAN:
339
339
 
340
340
  By default certinspect opens a fully verified TLS handshake (chain +
341
341
  hostname against the Python/OpenSSL trust store) and, when the certificate
342
- advertises an OCSP responder, queries it for the revocation status. If OCSP is
342
+ advertises an OCSP responder, queries it for the revocation status. The
343
+ verified handshake is a second connection: if the server presents a different
344
+ certificate on it (a load balancer mid-rotation, say), the chain is reported
345
+ as not trusted instead of vouching for a certificate that was not inspected. If OCSP is
343
346
  unavailable, certinspect falls back to the certificate's CRL distribution
344
347
  points (downloaded over HTTP and verified against the issuer). Both checks are
345
348
  soft-fail: when neither OCSP nor the CRL gives an answer the status is
@@ -313,7 +313,10 @@ SAN:
313
313
 
314
314
  By default certinspect opens a fully verified TLS handshake (chain +
315
315
  hostname against the Python/OpenSSL trust store) and, when the certificate
316
- advertises an OCSP responder, queries it for the revocation status. If OCSP is
316
+ advertises an OCSP responder, queries it for the revocation status. The
317
+ verified handshake is a second connection: if the server presents a different
318
+ certificate on it (a load balancer mid-rotation, say), the chain is reported
319
+ as not trusted instead of vouching for a certificate that was not inspected. If OCSP is
317
320
  unavailable, certinspect falls back to the certificate's CRL distribution
318
321
  points (downloaded over HTTP and verified against the issuer). Both checks are
319
322
  soft-fail: when neither OCSP nor the CRL gives an answer the status is
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "certinspect"
3
- version = "2.4.3"
3
+ version = "2.4.4"
4
4
  description = "Command-line TLS certificate inspector"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -1,3 +1,3 @@
1
1
  """certinspect — command-line TLS certificate inspector."""
2
2
 
3
- __version__ = "2.4.3"
3
+ __version__ = "2.4.4"
@@ -254,7 +254,9 @@ def _inspect(
254
254
  if opts.file and (opts.verify or opts.chain):
255
255
  file_bundle = load_certificates(der)
256
256
 
257
- override, chain_certs = _check_chain(info, target, port, conn, opts, file_bundle)
257
+ override, chain_certs = _check_chain(
258
+ info, target, port, cert, conn, opts, file_bundle
259
+ )
258
260
  codes.append(override)
259
261
  if opts.verify and target:
260
262
  codes.append(_check_revocation(info, cert, chain_certs, opts))
@@ -288,6 +290,7 @@ def _check_chain(
288
290
  info: CertificateInfo,
289
291
  target: str | None,
290
292
  port: int,
293
+ cert,
291
294
  conn: dict | None,
292
295
  opts: InspectOptions,
293
296
  file_bundle: list | None,
@@ -298,7 +301,9 @@ def _check_chain(
298
301
  Sets ``chain_trusted``/``chain_error`` and, when it fails,
299
302
  ``chain_diagnosis``. Returns UNTRUSTED_OR_REVOKED when the chain is not
300
303
  trusted (else None) and the verified chain, leaf first ([] when
301
- unavailable).
304
+ unavailable). A host whose verification handshake presented a different
305
+ leaf than ``cert`` (a load balancer mid-rotation, say) is not trusted: the
306
+ verdict would belong to another certificate.
302
307
  """
303
308
  if not opts.verify:
304
309
  return None, []
@@ -315,6 +320,12 @@ def _check_chain(
315
320
  opts.retries,
316
321
  )
317
322
  presented = conn.get("chain") if conn else None
323
+ if trusted and verified and verified[0] != cert:
324
+ trusted, verified = False, []
325
+ reason = (
326
+ "the server presented a different certificate on the "
327
+ "verification handshake"
328
+ )
318
329
  else:
319
330
  return None, []
320
331
 
@@ -350,8 +350,9 @@ def verify_chain(
350
350
 
351
351
  Open a fully verified TLS handshake (system trust store, hostname check)
352
352
  as a browser would. Return ``(trusted, reason, chain)`` where ``chain`` is
353
- the verified certificate chain (leaf first) when the interpreter exposes
354
- it (Python 3.13+) and verification succeeds, otherwise an empty list.
353
+ the verified certificate chain (leaf first) on success — just the leaf on
354
+ interpreters without ``get_verified_chain`` (before 3.13) — and an empty
355
+ list on failure.
355
356
  ``reason`` is None on success or the verification message on failure.
356
357
  Network-level failures are left to propagate. When ``starttls`` is set the
357
358
  plaintext protocol is upgraded to TLS before the handshake.
@@ -381,7 +382,10 @@ def verify_chain(
381
382
  if starttls:
382
383
  _negotiate_starttls(sock, starttls, read_timeout)
383
384
  with context.wrap_socket(sock, server_hostname=servername or host) as ssock:
384
- return True, None, _chain(ssock, "get_verified_chain")
385
+ chain = _chain(ssock, "get_verified_chain") or [
386
+ x509.load_der_x509_certificate(ssock.getpeercert(binary_form=True))
387
+ ]
388
+ return True, None, chain
385
389
  except ssl.SSLCertVerificationError as err:
386
390
  return False, err.verify_message or str(err), []
387
391
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: certinspect
3
- Version: 2.4.3
3
+ Version: 2.4.4
4
4
  Summary: Command-line TLS certificate inspector
5
5
  Author-email: Michele Angrisano <michele.angrisano@gmail.com>
6
6
  License-Expression: MIT
@@ -339,7 +339,10 @@ SAN:
339
339
 
340
340
  By default certinspect opens a fully verified TLS handshake (chain +
341
341
  hostname against the Python/OpenSSL trust store) and, when the certificate
342
- advertises an OCSP responder, queries it for the revocation status. If OCSP is
342
+ advertises an OCSP responder, queries it for the revocation status. The
343
+ verified handshake is a second connection: if the server presents a different
344
+ certificate on it (a load balancer mid-rotation, say), the chain is reported
345
+ as not trusted instead of vouching for a certificate that was not inspected. If OCSP is
343
346
  unavailable, certinspect falls back to the certificate's CRL distribution
344
347
  points (downloaded over HTTP and verified against the issuer). Both checks are
345
348
  soft-fail: when neither OCSP nor the CRL gives an answer the status is
@@ -1723,6 +1723,41 @@ def test_main_verify_revocation_unavailable_is_soft_fail(
1723
1723
  assert code == 0
1724
1724
 
1725
1725
 
1726
+ def _verified_leaf(der):
1727
+ """Return a verify_chain replacement trusting a chain whose leaf is ``der``."""
1728
+ from cryptography import x509
1729
+
1730
+ leaf = x509.load_der_x509_certificate(der)
1731
+ return lambda *a, **k: (True, None, [leaf])
1732
+
1733
+
1734
+ def test_main_verify_rejects_a_different_leaf_on_the_verification_handshake(
1735
+ monkeypatch, capsys, make_cert
1736
+ ):
1737
+ """A load balancer serving another certificate to the verification
1738
+ handshake must not make the inspected certificate look trusted."""
1739
+ inspected = make_cert(san=["example.com"])
1740
+ monkeypatch.setattr("certinspect.cli.get_server_cert", _const_fetch(inspected))
1741
+ monkeypatch.setattr(
1742
+ "certinspect.cli.verify_chain", _verified_leaf(make_cert(san=["example.com"]))
1743
+ )
1744
+ code = _run_main(monkeypatch, ["example.com", "--json"])
1745
+ result = json.loads(capsys.readouterr().out)["results"][0]
1746
+ assert code == 6
1747
+ assert result["chain"]["trusted"] is False
1748
+ assert "different certificate" in result["chain"]["error"]
1749
+
1750
+
1751
+ def test_main_verify_trusts_the_same_leaf(monkeypatch, capsys, make_cert):
1752
+ inspected = make_cert(san=["example.com"])
1753
+ monkeypatch.setattr("certinspect.cli.get_server_cert", _const_fetch(inspected))
1754
+ monkeypatch.setattr("certinspect.cli.verify_chain", _verified_leaf(inspected))
1755
+ code = _run_main(monkeypatch, ["example.com", "--json"])
1756
+ result = json.loads(capsys.readouterr().out)["results"][0]
1757
+ assert code == 0
1758
+ assert result["chain"]["trusted"] is True
1759
+
1760
+
1726
1761
  def test_main_file_verify_reports_untrusted_self_signed(
1727
1762
  monkeypatch, capsys, tmp_path, make_cert
1728
1763
  ):
File without changes
File without changes