certinspect 2.4.4__tar.gz → 2.5.0__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.4/src/certinspect.egg-info → certinspect-2.5.0}/PKG-INFO +84 -60
  2. {certinspect-2.4.4 → certinspect-2.5.0}/README.md +82 -59
  3. {certinspect-2.4.4 → certinspect-2.5.0}/pyproject.toml +8 -1
  4. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/__init__.py +1 -1
  5. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/args.py +23 -3
  6. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/cli.py +44 -9
  7. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/fetch.py +24 -14
  8. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/formatter.py +99 -85
  9. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/httpfetch.py +26 -3
  10. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/models.py +15 -0
  11. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/parser.py +7 -4
  12. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/revocation.py +40 -5
  13. {certinspect-2.4.4 → certinspect-2.5.0/src/certinspect.egg-info}/PKG-INFO +84 -60
  14. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect.egg-info/requires.txt +1 -0
  15. {certinspect-2.4.4 → certinspect-2.5.0}/tests/test_cli.py +94 -0
  16. {certinspect-2.4.4 → certinspect-2.5.0}/tests/test_fetch.py +64 -0
  17. {certinspect-2.4.4 → certinspect-2.5.0}/LICENSE +0 -0
  18. {certinspect-2.4.4 → certinspect-2.5.0}/setup.cfg +0 -0
  19. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/completion.py +0 -0
  20. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/config.py +0 -0
  21. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/discover.py +0 -0
  22. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/exit_codes.py +0 -0
  23. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/render.py +0 -0
  24. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect/state.py +0 -0
  25. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect.egg-info/SOURCES.txt +0 -0
  26. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect.egg-info/dependency_links.txt +0 -0
  27. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect.egg-info/entry_points.txt +0 -0
  28. {certinspect-2.4.4 → certinspect-2.5.0}/src/certinspect.egg-info/top_level.txt +0 -0
  29. {certinspect-2.4.4 → certinspect-2.5.0}/tests/test_discover.py +0 -0
  30. {certinspect-2.4.4 → certinspect-2.5.0}/tests/test_formatter.py +0 -0
  31. {certinspect-2.4.4 → certinspect-2.5.0}/tests/test_parser.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: certinspect
3
- Version: 2.4.4
3
+ Version: 2.5.0
4
4
  Summary: Command-line TLS certificate inspector
5
5
  Author-email: Michele Angrisano <michele.angrisano@gmail.com>
6
6
  License-Expression: MIT
@@ -21,6 +21,7 @@ Requires-Dist: cryptography>=50.0.1
21
21
  Provides-Extra: dev
22
22
  Requires-Dist: pytest>=9.1.0; extra == "dev"
23
23
  Requires-Dist: ruff>=0.16.0; extra == "dev"
24
+ Requires-Dist: mypy>=2.3; extra == "dev"
24
25
  Requires-Dist: prometheus-client>=0.26.0; extra == "dev"
25
26
  Dynamic: license-file
26
27
 
@@ -129,6 +130,7 @@ $ echo $? # 0 = healthy, 3 = expiring, 4 = expired, 6 = revoked, ...
129
130
  - [`--field`](#--field-name)
130
131
  - [`--exit-zero`](#--exit-zero)
131
132
  - [`--export`](#--export-path)
133
+ - [`--export-chain`](#--export-chain-path)
132
134
  - [`--starttls`](#--starttls-smtpimappop3ftp)
133
135
  - [`--concurrency`](#--concurrency-n)
134
136
  - [`--exporter`](#--exporter-nagiosprometheus)
@@ -616,62 +618,63 @@ certinspect example.com --export ./example.com.pem
616
618
 
617
619
  ## Options
618
620
 
619
- | Option | Description |
620
- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
621
- | `target...` | One or more domains, URLs or `host:port` to inspect. Omit when using `--file`. |
622
- | `--config PATH` | Load default option values from a TOML file (keys use the argparse destination name); an explicit flag always overrides it. Auto-discovered at `~/.config/certinspect/config.toml` when omitted. |
623
- | `--file PATH` | Inspect a local certificate (PEM or DER) instead of a host. Use `-` to read from standard input. Repeatable to inspect several files in one run; cannot be combined with host targets. |
624
- | `--port N` | TCP port to connect to (default: 443). |
625
- | `--timeout N` | Connection timeout in seconds (default: 5). Used for both connect and read unless the two below are set. |
626
- | `--connect-timeout N` | TCP connect timeout in seconds (default: `--timeout`). |
627
- | `--read-timeout N` | Handshake/read timeout in seconds (default: `--timeout`). |
628
- | `--retries N` | Retry transient connection failures (timeouts, refused/reset, DNS) this many times (default: 0). |
629
- | `--json` | Print the result as JSON instead of human-readable text. |
630
- | `--csv` | Print the results as CSV (one row per target, with a header). |
631
- | `--csv-delimiter SEP` | Field separator for `--csv` (default `,`). Use `;` for Numbers/Excel in locales that expect it. |
632
- | `--quiet` | Only print certificates that have a problem. |
633
- | `--schema {1,2}` | JSON schema version for `--json` (default `2`, the nested/versioned document). `--schema 1` is the legacy flat array. |
634
- | `--verify` | Force chain verification (already the default). A verified handshake plus OCSP/CRL revocation for a host, or the bundle validated offline for `--file`. |
635
- | `--no-verify` | Skip chain verification (and revocation for hosts); only inspect the certificate itself. |
636
- | `--cafile PATH` | Verify the chain against this CA bundle (PEM) instead of the system trust store; for internal/private PKI. Incompatible with `--no-verify`. |
637
- | `--capath DIR` | Verify the chain against the hashed CA certificates in this directory (OpenSSL `c_rehash` layout). Incompatible with `--no-verify`; may be combined with `--cafile`. |
638
- | `--chain` | Show the certificate chain: presented by the server for a host, or every certificate in the bundle for `--file`. |
639
- | `--client-cert PATH` | Present a client certificate (PEM) for mutual-TLS endpoints (host targets only). Use `--client-key` when the key is stored separately. |
640
- | `--client-key PATH` | Private key (PEM) for `--client-cert` when stored separately from the certificate. |
641
- | `--proxy URL` | Tunnel the connection through an HTTP CONNECT proxy, e.g. `http://proxy:8080` or `http://user:pass@proxy:8080` (host targets only). Without it, the environment proxy (`HTTPS_PROXY`, honouring `NO_PROXY`) is used, like curl. |
642
- | `--no-proxy` | Force a direct connection, ignoring any proxy set in the environment. Mutually exclusive with `--proxy`. |
643
- | `--pin SHA256` | Fail (exit 7) unless the SHA-256 fingerprint matches (colons/case ignored). |
644
- | `--servername NAME` | Override the SNI hostname sent in the handshake (hosts only); the hostname match is checked against `NAME`. For reaching a backend by IP behind a load balancer. |
645
- | `--expect-san NAME` | Assert the certificate's SAN covers `NAME` (wildcards honored); exit 8 if missing. Repeatable; works for host and `--file` targets. |
646
- | `--not-after-max N` | Fail (exit 9) when the total validity exceeds N days (use 398 for the CA/Browser Forum maximum). Opt-in; works for host and `--file` targets. |
647
- | `--cab-forum` | Fail (exit 9) when the total validity exceeds the CA/Browser Forum maximum in effect today (398 days now, then 200, 100 and 47 on 2026/2027/2029-03-15). Date-aware shorthand for `--not-after-max`; mutually exclusive with it. |
648
- | `--min-key-size N` | Fail (exit 9) when an RSA/DSA public key is smaller than N bits (e.g. 2048). EC/EdDSA keys are not size-checked. Opt-in. |
649
- | `--fail-weak` | Turn the weak-crypto warnings (small key, SHA-1/MD5 signature) into a hard failure (exit 9) instead of a mere warning. |
650
- | `--require-sct` | Fail (exit 9) when the certificate embeds no Signed Certificate Timestamps (Certificate Transparency). Checks embedded SCTs only, not those from the TLS handshake or OCSP. Opt-in. |
651
- | `--require-must-staple` | Fail (exit 9) when the certificate lacks the OCSP Must-Staple extension (RFC 7633 TLS Feature `status_request`). Opt-in. |
652
- | `--require-revocation-check` | Fail (exit 9) unless OCSP or CRL returns a definitive `GOOD` revocation verdict. Host targets only; incompatible with `--no-verify`. Opt-in. |
653
- | `--min-tls-version VER` | Fail (exit 9) when the connection negotiates a TLS version older than `VER` (`TLSv1`, `TLSv1.1`, `TLSv1.2`, `TLSv1.3`). Host targets only; opt-in. |
654
- | `--profile {lenient,standard,strict}` | Apply a named bundle of the opt-in policy checks in one go (exit 9 on violation). Intensity ladder, not an official standard; explicit flags override it. See [Policy profiles](#policy-profiles). |
655
- | `--input PATH` | Read extra targets from a file, one per line ('-' for stdin). |
656
- | `--discover DOMAIN` | Discover hostnames from Certificate Transparency logs (crt.sh) for DOMAIN and inspect each one, surfacing forgotten or shadow certificates. Repeatable (queried concurrently per `--concurrency`); host targets only. |
657
- | `--discover-only` | With `--discover`, list the CT inventory (expiry, issuer, hostnames, soonest expiry first, wildcards included) for the domain(s) without connecting, then exit. Good for a fast audit or spotting a certificate from an unexpected CA. Supports `--json`/`--csv`. |
658
- | `--expect-issuer SUBSTRING` | With `--discover-only`, flag any certificate whose issuer matches none of these substrings (case-insensitive) and exit 9 — a Certificate Transparency mis-issuance check. Repeatable. |
659
- | `--discover-timeout N` | Timeout in seconds for the `--discover` crt.sh query (default: 30), separate from `--timeout` since a log search can be slower than a handshake. |
660
- | `--days N` | Warn if the certificate expires within N days (default: 30). |
661
- | `--critical-days N` | Escalate to CRITICAL (exit code 4) when the certificate expires within N days. Must be `<= --days`; feeds Nagios CRITICAL and the `--summary` `critical` count. |
662
- | `--max-days N` | Only show certificates expiring within N days (expired ones always shown; filters display only). |
663
- | `--sort host\|expiry` | Sort the output by host (alphabetical) or by soonest expiry (display only; does not affect exit code). |
664
- | `--summary` | Print a one-line tally (valid/expiring/expired/errors) to stderr; counts every target before filtering. |
665
- | `--field NAME` | Print only the given field(s), one tab-separated line per target (repeatable; `target` for the host). For scripting without a JSON tool. |
666
- | `--exit-zero` | Always exit 0, even on problems or fetch errors. Report-only mode for dashboards/CI that read the output, not the exit code. |
667
- | `--export PATH` | Save the inspected certificate as a PEM file at PATH. Single target only. |
668
- | `--starttls {smtp,imap,pop3,ftp}` | Upgrade a plaintext connection to TLS before inspecting (standard port unless `--port` is given). |
669
- | `--exporter {nagios,prometheus}` | Emit machine-readable monitoring output (ignores `--quiet`). |
670
- | `--concurrency N` | Inspect up to N hosts in parallel in batch mode (default: 1; order is preserved). Also governs `--discover`'s per-domain concurrency. |
671
- | `--state-file PATH` | Persist each host target's status across runs at PATH (JSON) and compare against the previous run. Host targets only. |
672
- | `--only-changed` | Show only targets whose status differs from the previous `--state-file` run (a first-seen target counts as changed). Requires `--state-file`; display only. |
673
- | `--print-completion {bash,zsh}` | Print a shell completion script for bash or zsh to stdout, then exit. Generated from the parser, so it always matches the installed flags. |
674
- | `--version` | Print the version and exit. |
621
+ | Option | Description |
622
+ | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
623
+ | `target...` | One or more domains, URLs or `host:port` to inspect. Omit when using `--file`. |
624
+ | `--config PATH` | Load default option values from a TOML file (keys use the argparse destination name); an explicit flag always overrides it. Auto-discovered at `~/.config/certinspect/config.toml` when omitted. |
625
+ | `--file PATH` | Inspect a local certificate (PEM or DER) instead of a host. Use `-` to read from standard input. Repeatable to inspect several files in one run; cannot be combined with host targets. |
626
+ | `--port N` | TCP port to connect to (default: 443). |
627
+ | `--timeout N` | Connection timeout in seconds (default: 5). Used for both connect and read unless the two below are set. |
628
+ | `--connect-timeout N` | TCP connect timeout in seconds (default: `--timeout`). |
629
+ | `--read-timeout N` | Handshake/read timeout in seconds (default: `--timeout`). |
630
+ | `--retries N` | Retry transient connection failures (timeouts, refused/reset, DNS) this many times (default: 0). |
631
+ | `--json` | Print the result as JSON instead of human-readable text. |
632
+ | `--csv` | Print the results as CSV (one row per target, with a header). |
633
+ | `--csv-delimiter SEP` | Field separator for `--csv` (default `,`). Use `;` for Numbers/Excel in locales that expect it. |
634
+ | `--quiet` | Only print certificates that have a problem. |
635
+ | `--schema {1,2}` | JSON schema version for `--json` (default `2`, the nested/versioned document). `--schema 1` is the legacy flat array. |
636
+ | `--verify` | Force chain verification (already the default). A verified handshake plus OCSP/CRL revocation for a host, or the bundle validated offline for `--file`. |
637
+ | `--no-verify` | Skip chain verification (and revocation for hosts); only inspect the certificate itself. |
638
+ | `--cafile PATH` | Verify the chain against this CA bundle (PEM) instead of the system trust store; for internal/private PKI. Incompatible with `--no-verify`. |
639
+ | `--capath DIR` | Verify the chain against the hashed CA certificates in this directory (OpenSSL `c_rehash` layout). Incompatible with `--no-verify`; may be combined with `--cafile`. |
640
+ | `--chain` | Show the certificate chain: presented by the server for a host, or every certificate in the bundle for `--file`. |
641
+ | `--client-cert PATH` | Present a client certificate (PEM) for mutual-TLS endpoints (host targets only). Use `--client-key` when the key is stored separately. |
642
+ | `--client-key PATH` | Private key (PEM) for `--client-cert` when stored separately from the certificate. |
643
+ | `--proxy URL` | Tunnel the connection through an HTTP CONNECT proxy, e.g. `http://proxy:8080` or `http://user:pass@proxy:8080` (host targets only); OCSP/CRL/CA-Issuer/CT-log requests use it too. Without it, the environment proxy (`HTTPS_PROXY`, honouring `NO_PROXY`) is used, like curl. |
644
+ | `--no-proxy` | Force direct connections (OCSP/CRL requests included), ignoring any proxy set in the environment. Mutually exclusive with `--proxy`. |
645
+ | `--pin SHA256` | Fail (exit 7) unless the SHA-256 fingerprint matches (colons/case ignored). |
646
+ | `--servername NAME` | Override the SNI hostname sent in the handshake (hosts only); the hostname match is checked against `NAME`. For reaching a backend by IP behind a load balancer. |
647
+ | `--expect-san NAME` | Assert the certificate's SAN covers `NAME` (wildcards honored); exit 8 if missing. Repeatable; works for host and `--file` targets. |
648
+ | `--not-after-max N` | Fail (exit 9) when the total validity exceeds N days (use 398 for the CA/Browser Forum maximum). Opt-in; works for host and `--file` targets. |
649
+ | `--cab-forum` | Fail (exit 9) when the total validity exceeds the CA/Browser Forum maximum in effect today (398 days now, then 200, 100 and 47 on 2026/2027/2029-03-15). Date-aware shorthand for `--not-after-max`; mutually exclusive with it. |
650
+ | `--min-key-size N` | Fail (exit 9) when an RSA/DSA public key is smaller than N bits (e.g. 2048). EC/EdDSA keys are not size-checked. Opt-in. |
651
+ | `--fail-weak` | Turn the weak-crypto warnings (small key, SHA-1/MD5 signature) into a hard failure (exit 9) instead of a mere warning. |
652
+ | `--require-sct` | Fail (exit 9) when the certificate embeds no Signed Certificate Timestamps (Certificate Transparency). Checks embedded SCTs only, not those from the TLS handshake or OCSP. Opt-in. |
653
+ | `--require-must-staple` | Fail (exit 9) when the certificate lacks the OCSP Must-Staple extension (RFC 7633 TLS Feature `status_request`). Opt-in. |
654
+ | `--require-revocation-check` | Fail (exit 9) unless OCSP or CRL returns a definitive `GOOD` revocation verdict. Host targets only; incompatible with `--no-verify`. Opt-in. |
655
+ | `--min-tls-version VER` | Fail (exit 9) when the connection negotiates a TLS version older than `VER` (`TLSv1`, `TLSv1.1`, `TLSv1.2`, `TLSv1.3`). Host targets only; opt-in. |
656
+ | `--profile {lenient,standard,strict}` | Apply a named bundle of the opt-in policy checks in one go (exit 9 on violation). Intensity ladder, not an official standard; explicit flags override it. See [Policy profiles](#policy-profiles). |
657
+ | `--input PATH` | Read extra targets from a file, one per line ('-' for stdin). |
658
+ | `--discover DOMAIN` | Discover hostnames from Certificate Transparency logs (crt.sh) for DOMAIN and inspect each one, surfacing forgotten or shadow certificates. Repeatable (queried concurrently per `--concurrency`); host targets only. |
659
+ | `--discover-only` | With `--discover`, list the CT inventory (expiry, issuer, hostnames, soonest expiry first, wildcards included) for the domain(s) without connecting, then exit. Good for a fast audit or spotting a certificate from an unexpected CA. Supports `--json`/`--csv`. |
660
+ | `--expect-issuer SUBSTRING` | With `--discover-only`, flag any certificate whose issuer matches none of these substrings (case-insensitive) and exit 9 — a Certificate Transparency mis-issuance check. Repeatable. |
661
+ | `--discover-timeout N` | Timeout in seconds for the `--discover` crt.sh query (default: 30), separate from `--timeout` since a log search can be slower than a handshake. |
662
+ | `--days N` | Warn if the certificate expires within N days (default: 30). |
663
+ | `--critical-days N` | Escalate to CRITICAL (exit code 4) when the certificate expires within N days. Must be `<= --days`; feeds Nagios CRITICAL and the `--summary` `critical` count. |
664
+ | `--max-days N` | Only show certificates expiring within N days (expired ones always shown; filters display only). |
665
+ | `--sort host\|expiry` | Sort the output by host (alphabetical) or by soonest expiry (display only; does not affect exit code). |
666
+ | `--summary` | Print a one-line tally (valid/expiring/expired/errors) to stderr; counts every target before filtering. |
667
+ | `--field NAME` | Print only the given field(s), one tab-separated line per target (repeatable; `target` for the host). For scripting without a JSON tool. |
668
+ | `--exit-zero` | Always exit 0, even on problems or fetch errors. Report-only mode for dashboards/CI that read the output, not the exit code. |
669
+ | `--export PATH` | Save the inspected certificate as a PEM file at PATH. Single target only. |
670
+ | `--export-chain PATH` | Rebuild the chain of the `--file` certificate (missing issuers fetched via AIA) and save it as PEM. Add `--include-root` to include the root. Single `--file` only. |
671
+ | `--starttls {smtp,imap,pop3,ftp}` | Upgrade a plaintext connection to TLS before inspecting (standard port unless `--port` is given). |
672
+ | `--exporter {nagios,prometheus}` | Emit machine-readable monitoring output (ignores `--quiet`). |
673
+ | `--concurrency N` | Inspect up to N hosts in parallel in batch mode (default: 1; order is preserved). Also governs `--discover`'s per-domain concurrency. |
674
+ | `--state-file PATH` | Persist each host target's status across runs at PATH (JSON) and compare against the previous run. Host targets only. |
675
+ | `--only-changed` | Show only targets whose status differs from the previous `--state-file` run (a first-seen target counts as changed). Requires `--state-file`; display only. |
676
+ | `--print-completion {bash,zsh}` | Print a shell completion script for bash or zsh to stdout, then exit. Generated from the parser, so it always matches the installed flags. |
677
+ | `--version` | Print the version and exit. |
675
678
 
676
679
  ## Options in action
677
680
 
@@ -995,12 +998,16 @@ Status: VALID
995
998
 
996
999
  Tunnel the TLS connection through an HTTP `CONNECT` proxy, so a host reachable
997
1000
  only through a corporate/cloud egress proxy can still be inspected. Basic proxy
998
- auth is supported via `user:pass@`.
1001
+ auth is supported via `user:pass@`. The OCSP, CRL, CA-Issuer and CT-log
1002
+ (`--discover`) requests use the same proxy, so revocation still works where
1003
+ only the proxy reaches the Internet. Their host names are still resolved
1004
+ locally for the internal-address check.
999
1005
 
1000
1006
  Like curl, certinspect also uses the environment proxy automatically when
1001
1007
  `--proxy` is not given: it reads `HTTPS_PROXY`/`HTTP_PROXY` (and the system
1002
- proxy on macOS/Windows) and honours `NO_PROXY`. Use `--no-proxy` to force a
1003
- direct connection regardless of the environment.
1008
+ proxy on macOS/Windows) and honours `NO_PROXY`. Use `--no-proxy` to force
1009
+ direct connections, for the OCSP/CRL requests too, regardless of the
1010
+ environment.
1004
1011
 
1005
1012
  ```console
1006
1013
  $ certinspect example.com --proxy http://proxy.corp:8080 # explicit
@@ -1361,6 +1368,23 @@ $ head -1 ./fetched.pem
1361
1368
  -----BEGIN CERTIFICATE-----
1362
1369
  ```
1363
1370
 
1371
+ ### `--export-chain PATH`
1372
+
1373
+ Rebuild the chain of a certificate file that holds only the leaf (or a partial
1374
+ bundle) and save it as PEM, leaf first. Missing issuers are downloaded from the
1375
+ certificate's AIA "CA Issuers" URL and kept only if they really signed the
1376
+ previous certificate. The self-signed root is left out (clients already trust
1377
+ it); add `--include-root` to write it too. If an issuer cannot be found, the
1378
+ chain built so far is still written and a warning goes to stderr. It takes a
1379
+ single `--file`.
1380
+
1381
+ ```console
1382
+ $ certinspect --file ./cert.pem --no-verify --export-chain ./fullchain.pem
1383
+ ...
1384
+ $ grep -c BEGIN ./fullchain.pem
1385
+ 2
1386
+ ```
1387
+
1364
1388
  ### `--starttls {smtp,imap,pop3,ftp}`
1365
1389
 
1366
1390
  Upgrade a plaintext protocol to TLS before inspecting (the protocol's standard
@@ -103,6 +103,7 @@ $ echo $? # 0 = healthy, 3 = expiring, 4 = expired, 6 = revoked, ...
103
103
  - [`--field`](#--field-name)
104
104
  - [`--exit-zero`](#--exit-zero)
105
105
  - [`--export`](#--export-path)
106
+ - [`--export-chain`](#--export-chain-path)
106
107
  - [`--starttls`](#--starttls-smtpimappop3ftp)
107
108
  - [`--concurrency`](#--concurrency-n)
108
109
  - [`--exporter`](#--exporter-nagiosprometheus)
@@ -590,62 +591,63 @@ certinspect example.com --export ./example.com.pem
590
591
 
591
592
  ## Options
592
593
 
593
- | Option | Description |
594
- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
595
- | `target...` | One or more domains, URLs or `host:port` to inspect. Omit when using `--file`. |
596
- | `--config PATH` | Load default option values from a TOML file (keys use the argparse destination name); an explicit flag always overrides it. Auto-discovered at `~/.config/certinspect/config.toml` when omitted. |
597
- | `--file PATH` | Inspect a local certificate (PEM or DER) instead of a host. Use `-` to read from standard input. Repeatable to inspect several files in one run; cannot be combined with host targets. |
598
- | `--port N` | TCP port to connect to (default: 443). |
599
- | `--timeout N` | Connection timeout in seconds (default: 5). Used for both connect and read unless the two below are set. |
600
- | `--connect-timeout N` | TCP connect timeout in seconds (default: `--timeout`). |
601
- | `--read-timeout N` | Handshake/read timeout in seconds (default: `--timeout`). |
602
- | `--retries N` | Retry transient connection failures (timeouts, refused/reset, DNS) this many times (default: 0). |
603
- | `--json` | Print the result as JSON instead of human-readable text. |
604
- | `--csv` | Print the results as CSV (one row per target, with a header). |
605
- | `--csv-delimiter SEP` | Field separator for `--csv` (default `,`). Use `;` for Numbers/Excel in locales that expect it. |
606
- | `--quiet` | Only print certificates that have a problem. |
607
- | `--schema {1,2}` | JSON schema version for `--json` (default `2`, the nested/versioned document). `--schema 1` is the legacy flat array. |
608
- | `--verify` | Force chain verification (already the default). A verified handshake plus OCSP/CRL revocation for a host, or the bundle validated offline for `--file`. |
609
- | `--no-verify` | Skip chain verification (and revocation for hosts); only inspect the certificate itself. |
610
- | `--cafile PATH` | Verify the chain against this CA bundle (PEM) instead of the system trust store; for internal/private PKI. Incompatible with `--no-verify`. |
611
- | `--capath DIR` | Verify the chain against the hashed CA certificates in this directory (OpenSSL `c_rehash` layout). Incompatible with `--no-verify`; may be combined with `--cafile`. |
612
- | `--chain` | Show the certificate chain: presented by the server for a host, or every certificate in the bundle for `--file`. |
613
- | `--client-cert PATH` | Present a client certificate (PEM) for mutual-TLS endpoints (host targets only). Use `--client-key` when the key is stored separately. |
614
- | `--client-key PATH` | Private key (PEM) for `--client-cert` when stored separately from the certificate. |
615
- | `--proxy URL` | Tunnel the connection through an HTTP CONNECT proxy, e.g. `http://proxy:8080` or `http://user:pass@proxy:8080` (host targets only). Without it, the environment proxy (`HTTPS_PROXY`, honouring `NO_PROXY`) is used, like curl. |
616
- | `--no-proxy` | Force a direct connection, ignoring any proxy set in the environment. Mutually exclusive with `--proxy`. |
617
- | `--pin SHA256` | Fail (exit 7) unless the SHA-256 fingerprint matches (colons/case ignored). |
618
- | `--servername NAME` | Override the SNI hostname sent in the handshake (hosts only); the hostname match is checked against `NAME`. For reaching a backend by IP behind a load balancer. |
619
- | `--expect-san NAME` | Assert the certificate's SAN covers `NAME` (wildcards honored); exit 8 if missing. Repeatable; works for host and `--file` targets. |
620
- | `--not-after-max N` | Fail (exit 9) when the total validity exceeds N days (use 398 for the CA/Browser Forum maximum). Opt-in; works for host and `--file` targets. |
621
- | `--cab-forum` | Fail (exit 9) when the total validity exceeds the CA/Browser Forum maximum in effect today (398 days now, then 200, 100 and 47 on 2026/2027/2029-03-15). Date-aware shorthand for `--not-after-max`; mutually exclusive with it. |
622
- | `--min-key-size N` | Fail (exit 9) when an RSA/DSA public key is smaller than N bits (e.g. 2048). EC/EdDSA keys are not size-checked. Opt-in. |
623
- | `--fail-weak` | Turn the weak-crypto warnings (small key, SHA-1/MD5 signature) into a hard failure (exit 9) instead of a mere warning. |
624
- | `--require-sct` | Fail (exit 9) when the certificate embeds no Signed Certificate Timestamps (Certificate Transparency). Checks embedded SCTs only, not those from the TLS handshake or OCSP. Opt-in. |
625
- | `--require-must-staple` | Fail (exit 9) when the certificate lacks the OCSP Must-Staple extension (RFC 7633 TLS Feature `status_request`). Opt-in. |
626
- | `--require-revocation-check` | Fail (exit 9) unless OCSP or CRL returns a definitive `GOOD` revocation verdict. Host targets only; incompatible with `--no-verify`. Opt-in. |
627
- | `--min-tls-version VER` | Fail (exit 9) when the connection negotiates a TLS version older than `VER` (`TLSv1`, `TLSv1.1`, `TLSv1.2`, `TLSv1.3`). Host targets only; opt-in. |
628
- | `--profile {lenient,standard,strict}` | Apply a named bundle of the opt-in policy checks in one go (exit 9 on violation). Intensity ladder, not an official standard; explicit flags override it. See [Policy profiles](#policy-profiles). |
629
- | `--input PATH` | Read extra targets from a file, one per line ('-' for stdin). |
630
- | `--discover DOMAIN` | Discover hostnames from Certificate Transparency logs (crt.sh) for DOMAIN and inspect each one, surfacing forgotten or shadow certificates. Repeatable (queried concurrently per `--concurrency`); host targets only. |
631
- | `--discover-only` | With `--discover`, list the CT inventory (expiry, issuer, hostnames, soonest expiry first, wildcards included) for the domain(s) without connecting, then exit. Good for a fast audit or spotting a certificate from an unexpected CA. Supports `--json`/`--csv`. |
632
- | `--expect-issuer SUBSTRING` | With `--discover-only`, flag any certificate whose issuer matches none of these substrings (case-insensitive) and exit 9 — a Certificate Transparency mis-issuance check. Repeatable. |
633
- | `--discover-timeout N` | Timeout in seconds for the `--discover` crt.sh query (default: 30), separate from `--timeout` since a log search can be slower than a handshake. |
634
- | `--days N` | Warn if the certificate expires within N days (default: 30). |
635
- | `--critical-days N` | Escalate to CRITICAL (exit code 4) when the certificate expires within N days. Must be `<= --days`; feeds Nagios CRITICAL and the `--summary` `critical` count. |
636
- | `--max-days N` | Only show certificates expiring within N days (expired ones always shown; filters display only). |
637
- | `--sort host\|expiry` | Sort the output by host (alphabetical) or by soonest expiry (display only; does not affect exit code). |
638
- | `--summary` | Print a one-line tally (valid/expiring/expired/errors) to stderr; counts every target before filtering. |
639
- | `--field NAME` | Print only the given field(s), one tab-separated line per target (repeatable; `target` for the host). For scripting without a JSON tool. |
640
- | `--exit-zero` | Always exit 0, even on problems or fetch errors. Report-only mode for dashboards/CI that read the output, not the exit code. |
641
- | `--export PATH` | Save the inspected certificate as a PEM file at PATH. Single target only. |
642
- | `--starttls {smtp,imap,pop3,ftp}` | Upgrade a plaintext connection to TLS before inspecting (standard port unless `--port` is given). |
643
- | `--exporter {nagios,prometheus}` | Emit machine-readable monitoring output (ignores `--quiet`). |
644
- | `--concurrency N` | Inspect up to N hosts in parallel in batch mode (default: 1; order is preserved). Also governs `--discover`'s per-domain concurrency. |
645
- | `--state-file PATH` | Persist each host target's status across runs at PATH (JSON) and compare against the previous run. Host targets only. |
646
- | `--only-changed` | Show only targets whose status differs from the previous `--state-file` run (a first-seen target counts as changed). Requires `--state-file`; display only. |
647
- | `--print-completion {bash,zsh}` | Print a shell completion script for bash or zsh to stdout, then exit. Generated from the parser, so it always matches the installed flags. |
648
- | `--version` | Print the version and exit. |
594
+ | Option | Description |
595
+ | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
596
+ | `target...` | One or more domains, URLs or `host:port` to inspect. Omit when using `--file`. |
597
+ | `--config PATH` | Load default option values from a TOML file (keys use the argparse destination name); an explicit flag always overrides it. Auto-discovered at `~/.config/certinspect/config.toml` when omitted. |
598
+ | `--file PATH` | Inspect a local certificate (PEM or DER) instead of a host. Use `-` to read from standard input. Repeatable to inspect several files in one run; cannot be combined with host targets. |
599
+ | `--port N` | TCP port to connect to (default: 443). |
600
+ | `--timeout N` | Connection timeout in seconds (default: 5). Used for both connect and read unless the two below are set. |
601
+ | `--connect-timeout N` | TCP connect timeout in seconds (default: `--timeout`). |
602
+ | `--read-timeout N` | Handshake/read timeout in seconds (default: `--timeout`). |
603
+ | `--retries N` | Retry transient connection failures (timeouts, refused/reset, DNS) this many times (default: 0). |
604
+ | `--json` | Print the result as JSON instead of human-readable text. |
605
+ | `--csv` | Print the results as CSV (one row per target, with a header). |
606
+ | `--csv-delimiter SEP` | Field separator for `--csv` (default `,`). Use `;` for Numbers/Excel in locales that expect it. |
607
+ | `--quiet` | Only print certificates that have a problem. |
608
+ | `--schema {1,2}` | JSON schema version for `--json` (default `2`, the nested/versioned document). `--schema 1` is the legacy flat array. |
609
+ | `--verify` | Force chain verification (already the default). A verified handshake plus OCSP/CRL revocation for a host, or the bundle validated offline for `--file`. |
610
+ | `--no-verify` | Skip chain verification (and revocation for hosts); only inspect the certificate itself. |
611
+ | `--cafile PATH` | Verify the chain against this CA bundle (PEM) instead of the system trust store; for internal/private PKI. Incompatible with `--no-verify`. |
612
+ | `--capath DIR` | Verify the chain against the hashed CA certificates in this directory (OpenSSL `c_rehash` layout). Incompatible with `--no-verify`; may be combined with `--cafile`. |
613
+ | `--chain` | Show the certificate chain: presented by the server for a host, or every certificate in the bundle for `--file`. |
614
+ | `--client-cert PATH` | Present a client certificate (PEM) for mutual-TLS endpoints (host targets only). Use `--client-key` when the key is stored separately. |
615
+ | `--client-key PATH` | Private key (PEM) for `--client-cert` when stored separately from the certificate. |
616
+ | `--proxy URL` | Tunnel the connection through an HTTP CONNECT proxy, e.g. `http://proxy:8080` or `http://user:pass@proxy:8080` (host targets only); OCSP/CRL/CA-Issuer/CT-log requests use it too. Without it, the environment proxy (`HTTPS_PROXY`, honouring `NO_PROXY`) is used, like curl. |
617
+ | `--no-proxy` | Force direct connections (OCSP/CRL requests included), ignoring any proxy set in the environment. Mutually exclusive with `--proxy`. |
618
+ | `--pin SHA256` | Fail (exit 7) unless the SHA-256 fingerprint matches (colons/case ignored). |
619
+ | `--servername NAME` | Override the SNI hostname sent in the handshake (hosts only); the hostname match is checked against `NAME`. For reaching a backend by IP behind a load balancer. |
620
+ | `--expect-san NAME` | Assert the certificate's SAN covers `NAME` (wildcards honored); exit 8 if missing. Repeatable; works for host and `--file` targets. |
621
+ | `--not-after-max N` | Fail (exit 9) when the total validity exceeds N days (use 398 for the CA/Browser Forum maximum). Opt-in; works for host and `--file` targets. |
622
+ | `--cab-forum` | Fail (exit 9) when the total validity exceeds the CA/Browser Forum maximum in effect today (398 days now, then 200, 100 and 47 on 2026/2027/2029-03-15). Date-aware shorthand for `--not-after-max`; mutually exclusive with it. |
623
+ | `--min-key-size N` | Fail (exit 9) when an RSA/DSA public key is smaller than N bits (e.g. 2048). EC/EdDSA keys are not size-checked. Opt-in. |
624
+ | `--fail-weak` | Turn the weak-crypto warnings (small key, SHA-1/MD5 signature) into a hard failure (exit 9) instead of a mere warning. |
625
+ | `--require-sct` | Fail (exit 9) when the certificate embeds no Signed Certificate Timestamps (Certificate Transparency). Checks embedded SCTs only, not those from the TLS handshake or OCSP. Opt-in. |
626
+ | `--require-must-staple` | Fail (exit 9) when the certificate lacks the OCSP Must-Staple extension (RFC 7633 TLS Feature `status_request`). Opt-in. |
627
+ | `--require-revocation-check` | Fail (exit 9) unless OCSP or CRL returns a definitive `GOOD` revocation verdict. Host targets only; incompatible with `--no-verify`. Opt-in. |
628
+ | `--min-tls-version VER` | Fail (exit 9) when the connection negotiates a TLS version older than `VER` (`TLSv1`, `TLSv1.1`, `TLSv1.2`, `TLSv1.3`). Host targets only; opt-in. |
629
+ | `--profile {lenient,standard,strict}` | Apply a named bundle of the opt-in policy checks in one go (exit 9 on violation). Intensity ladder, not an official standard; explicit flags override it. See [Policy profiles](#policy-profiles). |
630
+ | `--input PATH` | Read extra targets from a file, one per line ('-' for stdin). |
631
+ | `--discover DOMAIN` | Discover hostnames from Certificate Transparency logs (crt.sh) for DOMAIN and inspect each one, surfacing forgotten or shadow certificates. Repeatable (queried concurrently per `--concurrency`); host targets only. |
632
+ | `--discover-only` | With `--discover`, list the CT inventory (expiry, issuer, hostnames, soonest expiry first, wildcards included) for the domain(s) without connecting, then exit. Good for a fast audit or spotting a certificate from an unexpected CA. Supports `--json`/`--csv`. |
633
+ | `--expect-issuer SUBSTRING` | With `--discover-only`, flag any certificate whose issuer matches none of these substrings (case-insensitive) and exit 9 — a Certificate Transparency mis-issuance check. Repeatable. |
634
+ | `--discover-timeout N` | Timeout in seconds for the `--discover` crt.sh query (default: 30), separate from `--timeout` since a log search can be slower than a handshake. |
635
+ | `--days N` | Warn if the certificate expires within N days (default: 30). |
636
+ | `--critical-days N` | Escalate to CRITICAL (exit code 4) when the certificate expires within N days. Must be `<= --days`; feeds Nagios CRITICAL and the `--summary` `critical` count. |
637
+ | `--max-days N` | Only show certificates expiring within N days (expired ones always shown; filters display only). |
638
+ | `--sort host\|expiry` | Sort the output by host (alphabetical) or by soonest expiry (display only; does not affect exit code). |
639
+ | `--summary` | Print a one-line tally (valid/expiring/expired/errors) to stderr; counts every target before filtering. |
640
+ | `--field NAME` | Print only the given field(s), one tab-separated line per target (repeatable; `target` for the host). For scripting without a JSON tool. |
641
+ | `--exit-zero` | Always exit 0, even on problems or fetch errors. Report-only mode for dashboards/CI that read the output, not the exit code. |
642
+ | `--export PATH` | Save the inspected certificate as a PEM file at PATH. Single target only. |
643
+ | `--export-chain PATH` | Rebuild the chain of the `--file` certificate (missing issuers fetched via AIA) and save it as PEM. Add `--include-root` to include the root. Single `--file` only. |
644
+ | `--starttls {smtp,imap,pop3,ftp}` | Upgrade a plaintext connection to TLS before inspecting (standard port unless `--port` is given). |
645
+ | `--exporter {nagios,prometheus}` | Emit machine-readable monitoring output (ignores `--quiet`). |
646
+ | `--concurrency N` | Inspect up to N hosts in parallel in batch mode (default: 1; order is preserved). Also governs `--discover`'s per-domain concurrency. |
647
+ | `--state-file PATH` | Persist each host target's status across runs at PATH (JSON) and compare against the previous run. Host targets only. |
648
+ | `--only-changed` | Show only targets whose status differs from the previous `--state-file` run (a first-seen target counts as changed). Requires `--state-file`; display only. |
649
+ | `--print-completion {bash,zsh}` | Print a shell completion script for bash or zsh to stdout, then exit. Generated from the parser, so it always matches the installed flags. |
650
+ | `--version` | Print the version and exit. |
649
651
 
650
652
  ## Options in action
651
653
 
@@ -969,12 +971,16 @@ Status: VALID
969
971
 
970
972
  Tunnel the TLS connection through an HTTP `CONNECT` proxy, so a host reachable
971
973
  only through a corporate/cloud egress proxy can still be inspected. Basic proxy
972
- auth is supported via `user:pass@`.
974
+ auth is supported via `user:pass@`. The OCSP, CRL, CA-Issuer and CT-log
975
+ (`--discover`) requests use the same proxy, so revocation still works where
976
+ only the proxy reaches the Internet. Their host names are still resolved
977
+ locally for the internal-address check.
973
978
 
974
979
  Like curl, certinspect also uses the environment proxy automatically when
975
980
  `--proxy` is not given: it reads `HTTPS_PROXY`/`HTTP_PROXY` (and the system
976
- proxy on macOS/Windows) and honours `NO_PROXY`. Use `--no-proxy` to force a
977
- direct connection regardless of the environment.
981
+ proxy on macOS/Windows) and honours `NO_PROXY`. Use `--no-proxy` to force
982
+ direct connections, for the OCSP/CRL requests too, regardless of the
983
+ environment.
978
984
 
979
985
  ```console
980
986
  $ certinspect example.com --proxy http://proxy.corp:8080 # explicit
@@ -1335,6 +1341,23 @@ $ head -1 ./fetched.pem
1335
1341
  -----BEGIN CERTIFICATE-----
1336
1342
  ```
1337
1343
 
1344
+ ### `--export-chain PATH`
1345
+
1346
+ Rebuild the chain of a certificate file that holds only the leaf (or a partial
1347
+ bundle) and save it as PEM, leaf first. Missing issuers are downloaded from the
1348
+ certificate's AIA "CA Issuers" URL and kept only if they really signed the
1349
+ previous certificate. The self-signed root is left out (clients already trust
1350
+ it); add `--include-root` to write it too. If an issuer cannot be found, the
1351
+ chain built so far is still written and a warning goes to stderr. It takes a
1352
+ single `--file`.
1353
+
1354
+ ```console
1355
+ $ certinspect --file ./cert.pem --no-verify --export-chain ./fullchain.pem
1356
+ ...
1357
+ $ grep -c BEGIN ./fullchain.pem
1358
+ 2
1359
+ ```
1360
+
1338
1361
  ### `--starttls {smtp,imap,pop3,ftp}`
1339
1362
 
1340
1363
  Upgrade a plaintext protocol to TLS before inspecting (the protocol's standard
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "certinspect"
3
- version = "2.4.4"
3
+ version = "2.5.0"
4
4
  description = "Command-line TLS certificate inspector"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -24,6 +24,7 @@ dependencies = [
24
24
  dev = [
25
25
  "pytest>=9.1.0",
26
26
  "ruff>=0.16.0",
27
+ "mypy>=2.3",
27
28
  "prometheus-client>=0.26.0",
28
29
  ]
29
30
 
@@ -48,3 +49,9 @@ where = ["src"]
48
49
  # ruff that enables extra rule families by default must not spontaneously break
49
50
  # the build. Opt into more rules deliberately, not by tool drift.
50
51
  select = ["E4", "E7", "E9", "F"]
52
+
53
+ [tool.mypy]
54
+ # Checks the annotations that are there (CertificateInfo, ConnectionInfo, ...);
55
+ # unannotated functions are not forced to gain types.
56
+ python_version = "3.12"
57
+ warn_unused_ignores = true
@@ -1,3 +1,3 @@
1
1
  """certinspect — command-line TLS certificate inspector."""
2
2
 
3
- __version__ = "2.4.4"
3
+ __version__ = "2.5.0"
@@ -224,7 +224,8 @@ def build_parser() -> argparse.ArgumentParser:
224
224
  help=(
225
225
  "Tunnel the connection through an HTTP CONNECT proxy, e.g. "
226
226
  "http://proxy:8080 or http://user:pass@proxy:8080 (host targets "
227
- "only). With no --proxy the environment proxy (HTTPS_PROXY, honouring "
227
+ "only); the OCSP, CRL, CA-Issuer and CT-log requests go through it "
228
+ "too. With no --proxy the environment proxy (HTTPS_PROXY, honouring "
228
229
  "NO_PROXY) is used automatically, like curl."
229
230
  ),
230
231
  )
@@ -233,8 +234,9 @@ def build_parser() -> argparse.ArgumentParser:
233
234
  action="store_true",
234
235
  dest="no_proxy",
235
236
  help=(
236
- "Force a direct connection, ignoring any proxy set in the "
237
- "environment. Mutually exclusive with --proxy."
237
+ "Force direct connections, the OCSP/CRL/CA-Issuer/CT-log requests "
238
+ "included, ignoring any proxy set in the environment. Mutually "
239
+ "exclusive with --proxy."
238
240
  ),
239
241
  )
240
242
  parser.add_argument(
@@ -450,6 +452,24 @@ def build_parser() -> argparse.ArgumentParser:
450
452
  "single target (host or --file)."
451
453
  ),
452
454
  )
455
+ parser.add_argument(
456
+ "--export-chain",
457
+ metavar="PATH",
458
+ dest="export_chain",
459
+ help=(
460
+ "Rebuild the certificate chain of the --file certificate and save "
461
+ "it as a PEM file at PATH (leaf first). Missing intermediates are "
462
+ 'downloaded from the AIA "CA Issuers" URLs and checked by '
463
+ "signature. The self-signed root is left out unless "
464
+ "--include-root is given. Needs a single --file."
465
+ ),
466
+ )
467
+ parser.add_argument(
468
+ "--include-root",
469
+ action="store_true",
470
+ dest="include_root",
471
+ help="Also write the self-signed root to the --export-chain file.",
472
+ )
453
473
  parser.add_argument(
454
474
  "--starttls",
455
475
  choices=tuple(STARTTLS_PORTS),