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 inspects the presented structure. Cryptographic signature and trust-path verification are handled separately by RootCertificate.
Opting in¶
The chain validator is registered but disabled by default because chain analysis is an additional policy check. 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:
User-configurable arguments¶
Pass via validator_args={"chain": {...}}. Each argument, its type, and its default are documented in the reference below, straight from the validator's docstring.
The default weak-signature set includes sha1WithRSAEncryption, md5WithRSAEncryption, md2WithRSAEncryption, ecdsa-with-SHA1, and dsa-with-sha1.
How it decides¶
The chain is fetched, each certificate is inspected, and is_valid is the AND of every structural condition. Per-certificate warnings are collected regardless; on failure the first warning becomes the top-level reason.
flowchart TD
A[validate called] --> B{Chain fetched?<br/>retrieval API available, no error}
B -- No --> Z["is_valid: false + reason"]
B -- Yes --> C[Inspect each certificate:<br/>expiry, weak signature, CA flag, role]
C --> D{All structural conditions hold?}
D --> D1["length ≥ min_chain_length<br/>chain ordered<br/>no expired / not-yet-valid member<br/>leaf not self-signed unless allowed<br/>issuers have CA flag<br/>no weak signatures if rejected<br/>terminates in root if required"]
D1 -- All true --> G["is_valid: true"]
D1 -- Any false --> H["is_valid: false<br/>reason = first warning"]
Output¶
Illustrative historical scan, abbreviated to show only the leaf entry in certs. A complete result has one entry per certificate (three in this example).
These examples show selected fields from illustrative scans. validate() also adds status and code, described in the result contract.
{
"is_valid": true,
"structural_valid": true,
"trust_verified": false,
"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": "secp256r1"},
"warnings": []
}
],
"warnings": []
}
On failure, is_valid is false and a reason field is added.
How the chain is retrieved¶
Chain retrieval uses the available socket chain API, with private _sslobj fallbacks on older interpreters. Private APIs are implementation details and may be unavailable; retrieval failures produce structured errors. Even a method named get_verified_chain() does not establish trust on CertMonitor's permissive collection socket.
The result includes structural_valid and trust_verified: false. Non-CA
issuers fail. Weak signatures also fail by default; set
reject_weak_signatures=False to retain warnings without rejection.
Issuer/subject equality, including the is_self_signed label, does not
verify a signature.
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. Cryptographic trust verification runs separately in RootCertificate, using OpenSSL. - 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. Collection intentionally uses
ssl.CERT_NONEso it can profile misconfigured and legacy servers. The separate root-certificate check uses the system or configured CA store.
A presented chain is not a built trust path
Servers normally omit the root. CertMonitor does not fetch missing intermediates from AIA URLs. The minimum-length rule is your structural policy: a single leaf can be sufficient for a certificate signed directly by a trusted root, even though it fails the default length of two.
Reference¶
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
performed separately by the root_certificate trust check using Python's
standard-library ssl module.
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 uses available socket APIs, with private fallbacks on older interpreters. If retrieval is unavailable, a structured error is returned.
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: list[str] | None = None, reject_weak_signatures: bool = True) -> ChainResult
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
|
list[str] | None
|
Override the default set of weak signature algorithm OIDs. Pass an empty list to disable the weak-signature policy entirely. |
None
|
reject_weak_signatures
|
bool
|
Reject weak signatures by default. False retains warnings while allowing structural policy to pass. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
ChainResult
|
A structured report with per-cert details and a summary.
The shape is stable and documented in
|
Source code in certmonitor/validators/chain.py
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 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |