SubjectAltNames Validator¶
certmonitor.validators.subject_alt_names.SubjectAltNamesValidator ¶
Bases: BaseCertValidator
A validator for checking the Subject Alternative Names (SANs) in an SSL certificate.
This validator checks both DNS and IP Address SANs.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the validator. |
validate ¶
validate(cert: Dict[str, Any], host: str, port: int, *, alternate_names: Optional[List[str]] = None) -> Dict[str, Any]
Validates the SANs in the provided SSL certificate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cert
|
dict
|
The SSL certificate. |
required |
host
|
str
|
The hostname or IP to validate against the SANs. |
required |
port
|
int
|
The port number. |
required |
alternate_names
|
list
|
A list of alternate names to validate against the SANs. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
A dictionary containing the validation results, including whether the SANs are valid, the SANs themselves, the count of SANs, and any warnings or reasons for validation failure. |
Examples:
Example output (success): This example shows a certificate where both the main host and an alternate name are present in the DNS SANs, so validation passes for both.
```json
{
"is_valid": true,
"sans": {
"DNS": [
"example.com",
"www.example.com"
],
"IP Address": []
},
"count": 2,
"contains_host": {
"name": "example.com",
"is_valid": true,
"reason": "Matched DNS SAN"
},
"contains_alternate": {
"www.example.com": {
"name": "www.example.com",
"is_valid": true,
"reason": "Matched DNS SAN"
}
},
"warnings": []
}
```
Example output (failure): This example shows a certificate where neither the main host nor the alternate name are present in the DNS SANs, so validation fails for both and warnings are included.
```json
{
"is_valid": false,
"sans": {
"DNS": [
"demo.nautobot.com"
],
"IP Address": []
},
"count": 1,
"contains_host": {
"name": "test.example.com",
"is_valid": false,
"reason": "No match found for test.example.com in DNS SANs: demo.nautobot.com"
},
"contains_alternate": {
"example.com": {
"name": "example.com",
"is_valid": false,
"reason": "No match found for example.com in DNS SANs: demo.nautobot.com"
}
},
"warnings": [
"The hostname/IP test.example.com is not included in the SANs: No match found for test.example.com in DNS SANs: demo.nautobot.com",
"The alternate name example.com is not included in the SANs: No match found for example.com in DNS SANs: demo.nautobot.com"
]
}
```
Source code in certmonitor/validators/subject_alt_names.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 | |