Chain Validator¶
The chain validator inspects the full certificate chain the server presented during the TLS handshake and reports structural problems: missing intermediates, out-of-order chains, expired members, weak signature algorithms, and non-CA intermediates. It does not perform cryptographic signature verification — that is deliberately left out to keep the Rust dependency footprint minimal.
Opting in¶
The chain validator is registered but disabled by default because it performs heavier work than the other validators and needs Python 3.10 or newer to retrieve the chain. Enable it by naming it explicitly:
from certmonitor import CertMonitor
with CertMonitor(
"example.com",
enabled_validators=["expiration", "hostname", "root_certificate", "chain"],
) as monitor:
monitor.get_cert_info()
result = monitor.validate()
print(result["chain"])
Or via the environment:
ENABLED_VALIDATORS=expiration,hostname,root_certificate,chain
User-configurable arguments¶
Pass via validator_args={"chain": {...}}:
| Argument | Type | Default | Description |
|---|---|---|---|
min_chain_length |
int |
2 |
Minimum acceptable number of certificates in the chain. The default rejects servers that only send the leaf. |
require_root_in_chain |
bool |
False |
Require the chain to terminate in a self-signed root. Most well-configured public servers omit the root, so the default emits a warning rather than failing. |
allow_self_signed_leaf |
bool |
False |
Accept a self-signed leaf. Useful for internal services. |
weak_signature_algorithms |
Optional[List[str]] |
None |
Override the default weak-signature OID set. Pass [] to disable the weak-signature warning entirely. |
The default weak-signature set includes sha1WithRSAEncryption, md5WithRSAEncryption, md2WithRSAEncryption, ecdsa-with-SHA1, and dsa-with-sha1.
Output¶
{
"is_valid": true,
"chain_length": 3,
"chain_ordered": true,
"terminates_in_self_signed": true,
"certs": [
{
"position": 0,
"role": "leaf",
"subject": {"commonName": "example.com"},
"issuer": {"commonName": "Intermediate CA"},
"not_before": "2025-01-01T00:00:00+00:00",
"not_after": "2026-01-01T00:00:00+00:00",
"days_to_expiry": 180,
"is_ca": false,
"is_self_signed": false,
"signature_algorithm_oid": "1.2.840.113549.1.1.11",
"subject_key_identifier": "ac33ac35b5f88ae27b06d23dc7058997d81c2443",
"authority_key_identifier": "de1b1eed7915d43e3724c321bbec34396d42b230",
"public_key_info": {"algorithm": "ecPublicKey", "size": 256, "curve": "1.2.840.10045.2.1"},
"warnings": []
}
],
"warnings": []
}
On failure, is_valid is false and a reason field is added.
Python version requirement¶
Chain retrieval relies on SSLSocket.get_verified_chain() (Python 3.13+) or the stable _sslobj.get_unverified_chain() attribute (Python 3.10–3.12). On Python 3.8 or 3.9 the validator returns an informative error dict rather than silently degrading. The rest of CertMonitor continues to work on 3.8+.
What is out of scope¶
- Cryptographic signature verification. Structural validation (
subject(parent) == issuer(child)plus SKI/AKI matching) catches the real-world misconfigurations this validator is built for. Real signature verification would require pullingringinto the Rust dependency tree and is deliberately left for a future iteration. - OCSP / CRL revocation checks. Same reasoning — network I/O and responder parsing belong in their own validator.
- Building a path against the system trust store.
CertMonitorintentionally usesssl.CERT_NONEso it can profile misconfigured and legacy servers.
certmonitor.validators.chain.ChainValidator ¶
Bases: BaseCertValidator
Validator for the structural integrity of the TLS certificate chain.
This validator inspects the chain the server presented during the TLS
handshake (leaf through root) and checks for the problems operators
actually hit in production: missing intermediates, out-of-order chains,
expired members, weak signature algorithms, and non-CA intermediates.
It does not perform cryptographic signature verification — that is
intentionally left to Phase 2 to keep the Rust dependency footprint at
pyo3 + x509-parser.
The validator ships disabled by default. Opt in via:
CertMonitor("example.com",
enabled_validators=["expiration", "hostname",
"root_certificate", "chain"])
or by setting ENABLED_VALIDATORS in the environment.
Chain retrieval requires Python 3.10 or newer. On 3.8/3.9 this validator reports a clear error rather than silently degrading.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the validator. |
validate ¶
validate(cert: Dict[str, Any], host: str, port: int, *, min_chain_length: int = 2, require_root_in_chain: bool = False, allow_self_signed_leaf: bool = False, weak_signature_algorithms: Optional[List[str]] = None) -> Dict[str, Any]
Validate the certificate chain fetched alongside the leaf cert.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cert
|
Dict[str, Any]
|
The cert data dict built by |
required |
host
|
str
|
The hostname (unused; accepted for dispatcher compatibility). |
required |
port
|
int
|
The port (unused; accepted for dispatcher compatibility). |
required |
min_chain_length
|
int
|
Minimum acceptable chain length. Default |
2
|
require_root_in_chain
|
bool
|
If |
False
|
allow_self_signed_leaf
|
bool
|
If |
False
|
weak_signature_algorithms
|
Optional[List[str]]
|
Override the default set of weak signature algorithm OIDs. Pass an empty list to disable the weak-signature warning entirely. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
A structured report with per-cert details and a summary.
The shape is stable and documented in
|
Source code in certmonitor/validators/chain.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |