Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 1 | # This file is dual licensed under the terms of the Apache License, Version |
| 2 | # 2.0, and the BSD License. See the LICENSE file in the root of this repository |
| 3 | # for complete details. |
| 4 | |
| 5 | from __future__ import absolute_import, division, print_function |
| 6 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 7 | import abc |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 8 | import ipaddress |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 9 | from enum import Enum |
| 10 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 11 | import six |
| 12 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 13 | from cryptography import utils |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 14 | from cryptography.hazmat.primitives import hashes |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 15 | |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 16 | |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 17 | _OID_NAMES = { |
| 18 | "2.5.4.3": "commonName", |
| 19 | "2.5.4.6": "countryName", |
| 20 | "2.5.4.7": "localityName", |
| 21 | "2.5.4.8": "stateOrProvinceName", |
| 22 | "2.5.4.10": "organizationName", |
| 23 | "2.5.4.11": "organizationalUnitName", |
| 24 | "2.5.4.5": "serialNumber", |
| 25 | "2.5.4.4": "surname", |
| 26 | "2.5.4.42": "givenName", |
| 27 | "2.5.4.12": "title", |
| 28 | "2.5.4.44": "generationQualifier", |
| 29 | "2.5.4.46": "dnQualifier", |
| 30 | "2.5.4.65": "pseudonym", |
| 31 | "0.9.2342.19200300.100.1.25": "domainComponent", |
| 32 | "1.2.840.113549.1.9.1": "emailAddress", |
Paul Kehrer | 71d40c6 | 2015-02-19 08:21:04 -0600 | [diff] [blame] | 33 | "1.2.840.113549.1.1.4": "md5WithRSAEncryption", |
| 34 | "1.2.840.113549.1.1.5": "sha1WithRSAEncryption", |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 35 | "1.2.840.113549.1.1.14": "sha224WithRSAEncryption", |
| 36 | "1.2.840.113549.1.1.11": "sha256WithRSAEncryption", |
| 37 | "1.2.840.113549.1.1.12": "sha384WithRSAEncryption", |
| 38 | "1.2.840.113549.1.1.13": "sha512WithRSAEncryption", |
Paul Kehrer | 71d40c6 | 2015-02-19 08:21:04 -0600 | [diff] [blame] | 39 | "1.2.840.10045.4.3.1": "ecdsa-with-SHA224", |
| 40 | "1.2.840.10045.4.3.2": "ecdsa-with-SHA256", |
| 41 | "1.2.840.10045.4.3.3": "ecdsa-with-SHA384", |
| 42 | "1.2.840.10045.4.3.4": "ecdsa-with-SHA512", |
| 43 | "1.2.840.10040.4.3": "dsa-with-sha1", |
| 44 | "2.16.840.1.101.3.4.3.1": "dsa-with-sha224", |
| 45 | "2.16.840.1.101.3.4.3.2": "dsa-with-sha256", |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 46 | "1.3.6.1.5.5.7.3.1": "serverAuth", |
| 47 | "1.3.6.1.5.5.7.3.2": "clientAuth", |
| 48 | "1.3.6.1.5.5.7.3.3": "codeSigning", |
| 49 | "1.3.6.1.5.5.7.3.4": "emailProtection", |
| 50 | "1.3.6.1.5.5.7.3.8": "timeStamping", |
| 51 | "1.3.6.1.5.5.7.3.9": "OCSPSigning", |
Paul Kehrer | d08b549 | 2015-04-04 15:19:16 -0500 | [diff] [blame] | 52 | "2.5.29.9": "subjectDirectoryAttributes", |
| 53 | "2.5.29.14": "subjectKeyIdentifier", |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 54 | "2.5.29.15": "keyUsage", |
Paul Kehrer | d08b549 | 2015-04-04 15:19:16 -0500 | [diff] [blame] | 55 | "2.5.29.17": "subjectAltName", |
| 56 | "2.5.29.18": "issuerAltName", |
| 57 | "2.5.29.19": "basicConstraints", |
| 58 | "2.5.29.30": "nameConstraints", |
| 59 | "2.5.29.31": "cRLDistributionPoints", |
| 60 | "2.5.29.32": "certificatePolicies", |
| 61 | "2.5.29.33": "policyMappings", |
| 62 | "2.5.29.35": "authorityKeyIdentifier", |
| 63 | "2.5.29.36": "policyConstraints", |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 64 | "2.5.29.37": "extendedKeyUsage", |
Paul Kehrer | d08b549 | 2015-04-04 15:19:16 -0500 | [diff] [blame] | 65 | "2.5.29.46": "freshestCRL", |
| 66 | "2.5.29.54": "inhibitAnyPolicy", |
| 67 | "1.3.6.1.5.5.7.1.1": "authorityInfoAccess", |
| 68 | "1.3.6.1.5.5.7.1.11": "subjectInfoAccess", |
| 69 | "1.3.6.1.5.5.7.48.1.5": "OCSPNoCheck", |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame^] | 70 | "1.3.6.1.5.5.7.48.2": "caIssuers", |
| 71 | "1.3.6.1.5.5.7.48.1": "OCSP", |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | |
Paul Kehrer | 9089c91 | 2015-04-20 22:15:20 -0500 | [diff] [blame] | 75 | _GENERAL_NAMES = { |
| 76 | 0: "otherName", |
| 77 | 1: "rfc822Name", |
| 78 | 2: "dNSName", |
| 79 | 3: "x400Address", |
| 80 | 4: "directoryName", |
| 81 | 5: "ediPartyName", |
| 82 | 6: "uniformResourceIdentifier", |
| 83 | 7: "iPAddress", |
| 84 | 8: "registeredID", |
| 85 | } |
| 86 | |
| 87 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 88 | class Version(Enum): |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 89 | v1 = 0 |
| 90 | v3 = 2 |
| 91 | |
| 92 | |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 93 | def load_pem_x509_certificate(data, backend): |
| 94 | return backend.load_pem_x509_certificate(data) |
| 95 | |
| 96 | |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 97 | def load_der_x509_certificate(data, backend): |
| 98 | return backend.load_der_x509_certificate(data) |
Paul Kehrer | a68fd33 | 2014-11-27 07:08:40 -1000 | [diff] [blame] | 99 | |
| 100 | |
Paul Kehrer | 31e3988 | 2015-03-11 11:37:04 -0500 | [diff] [blame] | 101 | def load_pem_x509_csr(data, backend): |
| 102 | return backend.load_pem_x509_csr(data) |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 103 | |
| 104 | |
Paul Kehrer | 1effb6e | 2015-03-30 15:05:59 -0500 | [diff] [blame] | 105 | def load_der_x509_csr(data, backend): |
| 106 | return backend.load_der_x509_csr(data) |
| 107 | |
| 108 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 109 | class InvalidVersion(Exception): |
Paul Kehrer | d5cccf7 | 2014-12-15 17:20:33 -0600 | [diff] [blame] | 110 | def __init__(self, msg, parsed_version): |
| 111 | super(InvalidVersion, self).__init__(msg) |
| 112 | self.parsed_version = parsed_version |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 113 | |
| 114 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 115 | class DuplicateExtension(Exception): |
| 116 | def __init__(self, msg, oid): |
| 117 | super(DuplicateExtension, self).__init__(msg) |
| 118 | self.oid = oid |
| 119 | |
| 120 | |
| 121 | class UnsupportedExtension(Exception): |
| 122 | def __init__(self, msg, oid): |
| 123 | super(UnsupportedExtension, self).__init__(msg) |
| 124 | self.oid = oid |
| 125 | |
| 126 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 127 | class ExtensionNotFound(Exception): |
| 128 | def __init__(self, msg, oid): |
| 129 | super(ExtensionNotFound, self).__init__(msg) |
| 130 | self.oid = oid |
| 131 | |
| 132 | |
Paul Kehrer | 9089c91 | 2015-04-20 22:15:20 -0500 | [diff] [blame] | 133 | class UnsupportedGeneralNameType(Exception): |
Paul Kehrer | bed0735 | 2015-04-21 08:31:10 -0500 | [diff] [blame] | 134 | def __init__(self, msg, type): |
| 135 | super(UnsupportedGeneralNameType, self).__init__(msg) |
| 136 | self.type = type |
Paul Kehrer | 9089c91 | 2015-04-20 22:15:20 -0500 | [diff] [blame] | 137 | |
| 138 | |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 139 | class NameAttribute(object): |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 140 | def __init__(self, oid, value): |
| 141 | if not isinstance(oid, ObjectIdentifier): |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 142 | raise TypeError( |
| 143 | "oid argument must be an ObjectIdentifier instance." |
| 144 | ) |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 145 | |
| 146 | self._oid = oid |
| 147 | self._value = value |
| 148 | |
| 149 | oid = utils.read_only_property("_oid") |
| 150 | value = utils.read_only_property("_value") |
| 151 | |
| 152 | def __eq__(self, other): |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 153 | if not isinstance(other, NameAttribute): |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 154 | return NotImplemented |
| 155 | |
| 156 | return ( |
| 157 | self.oid == other.oid and |
| 158 | self.value == other.value |
| 159 | ) |
| 160 | |
| 161 | def __ne__(self, other): |
| 162 | return not self == other |
| 163 | |
Paul Kehrer | a498be8 | 2015-02-12 15:00:56 -0600 | [diff] [blame] | 164 | def __repr__(self): |
Alex Gaynor | d6b63da | 2015-03-23 00:25:44 -0400 | [diff] [blame] | 165 | return "<NameAttribute(oid={0.oid}, value={0.value!r})>".format(self) |
Paul Kehrer | a498be8 | 2015-02-12 15:00:56 -0600 | [diff] [blame] | 166 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 167 | |
| 168 | class ObjectIdentifier(object): |
Paul Kehrer | d44f9a6 | 2015-02-04 14:47:34 -0600 | [diff] [blame] | 169 | def __init__(self, dotted_string): |
| 170 | self._dotted_string = dotted_string |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 171 | |
| 172 | def __eq__(self, other): |
| 173 | if not isinstance(other, ObjectIdentifier): |
| 174 | return NotImplemented |
| 175 | |
Paul Kehrer | d44f9a6 | 2015-02-04 14:47:34 -0600 | [diff] [blame] | 176 | return self._dotted_string == other._dotted_string |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 177 | |
| 178 | def __ne__(self, other): |
| 179 | return not self == other |
| 180 | |
| 181 | def __repr__(self): |
| 182 | return "<ObjectIdentifier(oid={0}, name={1})>".format( |
Paul Kehrer | d44f9a6 | 2015-02-04 14:47:34 -0600 | [diff] [blame] | 183 | self._dotted_string, |
| 184 | _OID_NAMES.get(self._dotted_string, "Unknown OID") |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 185 | ) |
| 186 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 187 | def __hash__(self): |
| 188 | return hash(self.dotted_string) |
| 189 | |
Paul Kehrer | d44f9a6 | 2015-02-04 14:47:34 -0600 | [diff] [blame] | 190 | dotted_string = utils.read_only_property("_dotted_string") |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 191 | |
| 192 | |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 193 | class Name(object): |
| 194 | def __init__(self, attributes): |
| 195 | self._attributes = attributes |
| 196 | |
Paul Kehrer | e901d64 | 2015-02-11 18:50:58 -0600 | [diff] [blame] | 197 | def get_attributes_for_oid(self, oid): |
Alex Gaynor | f957423 | 2015-02-19 13:56:50 -0800 | [diff] [blame] | 198 | return [i for i in self if i.oid == oid] |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 199 | |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 200 | def __eq__(self, other): |
| 201 | if not isinstance(other, Name): |
| 202 | return NotImplemented |
| 203 | |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 204 | return self._attributes == other._attributes |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 205 | |
| 206 | def __ne__(self, other): |
| 207 | return not self == other |
| 208 | |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 209 | def __iter__(self): |
Paul Kehrer | 8b21a4a | 2015-02-14 07:56:36 -0600 | [diff] [blame] | 210 | return iter(self._attributes) |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 211 | |
| 212 | def __len__(self): |
| 213 | return len(self._attributes) |
| 214 | |
Paul Kehrer | 1fb35c9 | 2015-04-11 15:42:54 -0400 | [diff] [blame] | 215 | def __repr__(self): |
Paul Kehrer | f4ed10a | 2015-04-11 15:53:12 -0400 | [diff] [blame] | 216 | return "<Name({0!r})>".format(self._attributes) |
Paul Kehrer | 1fb35c9 | 2015-04-11 15:42:54 -0400 | [diff] [blame] | 217 | |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 218 | |
Paul Kehrer | d08b549 | 2015-04-04 15:19:16 -0500 | [diff] [blame] | 219 | OID_SUBJECT_DIRECTORY_ATTRIBUTES = ObjectIdentifier("2.5.29.9") |
| 220 | OID_SUBJECT_KEY_IDENTIFIER = ObjectIdentifier("2.5.29.14") |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 221 | OID_KEY_USAGE = ObjectIdentifier("2.5.29.15") |
Paul Kehrer | d08b549 | 2015-04-04 15:19:16 -0500 | [diff] [blame] | 222 | OID_SUBJECT_ALTERNATIVE_NAME = ObjectIdentifier("2.5.29.17") |
| 223 | OID_ISSUER_ALTERNATIVE_NAME = ObjectIdentifier("2.5.29.18") |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 224 | OID_BASIC_CONSTRAINTS = ObjectIdentifier("2.5.29.19") |
Paul Kehrer | d08b549 | 2015-04-04 15:19:16 -0500 | [diff] [blame] | 225 | OID_NAME_CONSTRAINTS = ObjectIdentifier("2.5.29.30") |
| 226 | OID_CRL_DISTRIBUTION_POINTS = ObjectIdentifier("2.5.29.31") |
| 227 | OID_CERTIFICATE_POLICIES = ObjectIdentifier("2.5.29.32") |
| 228 | OID_POLICY_MAPPINGS = ObjectIdentifier("2.5.29.33") |
| 229 | OID_AUTHORITY_KEY_IDENTIFIER = ObjectIdentifier("2.5.29.35") |
| 230 | OID_POLICY_CONSTRAINTS = ObjectIdentifier("2.5.29.36") |
| 231 | OID_EXTENDED_KEY_USAGE = ObjectIdentifier("2.5.29.37") |
| 232 | OID_FRESHEST_CRL = ObjectIdentifier("2.5.29.46") |
| 233 | OID_INHIBIT_ANY_POLICY = ObjectIdentifier("2.5.29.54") |
| 234 | OID_AUTHORITY_INFORMATION_ACCESS = ObjectIdentifier("1.3.6.1.5.5.7.1.1") |
| 235 | OID_SUBJECT_INFORMATION_ACCESS = ObjectIdentifier("1.3.6.1.5.5.7.1.11") |
| 236 | OID_OCSP_NO_CHECK = ObjectIdentifier("1.3.6.1.5.5.7.48.1.5") |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 237 | |
| 238 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 239 | class Extensions(object): |
| 240 | def __init__(self, extensions): |
| 241 | self._extensions = extensions |
| 242 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 243 | def get_extension_for_oid(self, oid): |
| 244 | for ext in self: |
| 245 | if ext.oid == oid: |
| 246 | return ext |
| 247 | |
| 248 | raise ExtensionNotFound("No {0} extension was found".format(oid), oid) |
| 249 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 250 | def __iter__(self): |
| 251 | return iter(self._extensions) |
| 252 | |
| 253 | def __len__(self): |
| 254 | return len(self._extensions) |
| 255 | |
| 256 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 257 | class Extension(object): |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 258 | def __init__(self, oid, critical, value): |
| 259 | if not isinstance(oid, ObjectIdentifier): |
| 260 | raise TypeError( |
| 261 | "oid argument must be an ObjectIdentifier instance." |
| 262 | ) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 263 | |
| 264 | if not isinstance(critical, bool): |
| 265 | raise TypeError("critical must be a boolean value") |
| 266 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 267 | self._oid = oid |
| 268 | self._critical = critical |
| 269 | self._value = value |
| 270 | |
| 271 | oid = utils.read_only_property("_oid") |
| 272 | critical = utils.read_only_property("_critical") |
| 273 | value = utils.read_only_property("_value") |
| 274 | |
| 275 | def __repr__(self): |
Paul Kehrer | 58b7569 | 2015-03-22 23:24:58 -0500 | [diff] [blame] | 276 | return ("<Extension(oid={0.oid}, critical={0.critical}, " |
| 277 | "value={0.value})>").format(self) |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 278 | |
| 279 | |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 280 | class ExtendedKeyUsage(object): |
| 281 | def __init__(self, usages): |
Paul Kehrer | b047617 | 2015-05-02 19:34:51 -0500 | [diff] [blame] | 282 | if not all(isinstance(x, ObjectIdentifier) for x in usages): |
| 283 | raise TypeError( |
| 284 | "Every item in the usages list must be an ObjectIdentifier" |
| 285 | ) |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 286 | |
| 287 | self._usages = usages |
| 288 | |
| 289 | def __iter__(self): |
| 290 | return iter(self._usages) |
| 291 | |
| 292 | def __len__(self): |
| 293 | return len(self._usages) |
| 294 | |
Paul Kehrer | 23d10c3 | 2015-04-02 23:12:32 -0500 | [diff] [blame] | 295 | def __repr__(self): |
| 296 | return "<ExtendedKeyUsage({0})>".format(self._usages) |
| 297 | |
Paul Kehrer | b047617 | 2015-05-02 19:34:51 -0500 | [diff] [blame] | 298 | def __eq__(self, other): |
| 299 | if not isinstance(other, ExtendedKeyUsage): |
| 300 | return NotImplemented |
| 301 | |
Paul Kehrer | f24bad7 | 2015-05-02 19:36:20 -0500 | [diff] [blame] | 302 | return self._usages == other._usages |
Paul Kehrer | b047617 | 2015-05-02 19:34:51 -0500 | [diff] [blame] | 303 | |
| 304 | def __ne__(self, other): |
| 305 | return not self == other |
| 306 | |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 307 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 308 | class BasicConstraints(object): |
| 309 | def __init__(self, ca, path_length): |
| 310 | if not isinstance(ca, bool): |
| 311 | raise TypeError("ca must be a boolean value") |
| 312 | |
Paul Kehrer | 611d3d3 | 2015-03-22 13:31:18 -0500 | [diff] [blame] | 313 | if path_length is not None and not ca: |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 314 | raise ValueError("path_length must be None when ca is False") |
| 315 | |
Paul Kehrer | a5c6e9a | 2015-03-23 19:23:43 -0500 | [diff] [blame] | 316 | if ( |
Paul Kehrer | 5553d57 | 2015-03-23 21:08:01 -0500 | [diff] [blame] | 317 | path_length is not None and |
| 318 | (not isinstance(path_length, six.integer_types) or path_length < 0) |
Paul Kehrer | a5c6e9a | 2015-03-23 19:23:43 -0500 | [diff] [blame] | 319 | ): |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 320 | raise TypeError( |
| 321 | "path_length must be a non-negative integer or None" |
| 322 | ) |
| 323 | |
| 324 | self._ca = ca |
| 325 | self._path_length = path_length |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 326 | |
| 327 | ca = utils.read_only_property("_ca") |
| 328 | path_length = utils.read_only_property("_path_length") |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 329 | |
| 330 | def __repr__(self): |
Paul Kehrer | 58b7569 | 2015-03-22 23:24:58 -0500 | [diff] [blame] | 331 | return ("<BasicConstraints(ca={0.ca}, " |
| 332 | "path_length={0.path_length})>").format(self) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 333 | |
| 334 | |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 335 | class KeyUsage(object): |
| 336 | def __init__(self, digital_signature, content_commitment, key_encipherment, |
| 337 | data_encipherment, key_agreement, key_cert_sign, crl_sign, |
| 338 | encipher_only, decipher_only): |
| 339 | if not key_agreement and (encipher_only or decipher_only): |
| 340 | raise ValueError( |
| 341 | "encipher_only and decipher_only can only be true when " |
| 342 | "key_agreement is true" |
| 343 | ) |
| 344 | |
| 345 | self._digital_signature = digital_signature |
| 346 | self._content_commitment = content_commitment |
| 347 | self._key_encipherment = key_encipherment |
| 348 | self._data_encipherment = data_encipherment |
| 349 | self._key_agreement = key_agreement |
| 350 | self._key_cert_sign = key_cert_sign |
| 351 | self._crl_sign = crl_sign |
| 352 | self._encipher_only = encipher_only |
| 353 | self._decipher_only = decipher_only |
| 354 | |
| 355 | digital_signature = utils.read_only_property("_digital_signature") |
| 356 | content_commitment = utils.read_only_property("_content_commitment") |
| 357 | key_encipherment = utils.read_only_property("_key_encipherment") |
| 358 | data_encipherment = utils.read_only_property("_data_encipherment") |
| 359 | key_agreement = utils.read_only_property("_key_agreement") |
| 360 | key_cert_sign = utils.read_only_property("_key_cert_sign") |
| 361 | crl_sign = utils.read_only_property("_crl_sign") |
| 362 | |
| 363 | @property |
| 364 | def encipher_only(self): |
| 365 | if not self.key_agreement: |
| 366 | raise ValueError( |
| 367 | "encipher_only is undefined unless key_agreement is true" |
| 368 | ) |
| 369 | else: |
| 370 | return self._encipher_only |
| 371 | |
| 372 | @property |
| 373 | def decipher_only(self): |
| 374 | if not self.key_agreement: |
| 375 | raise ValueError( |
| 376 | "decipher_only is undefined unless key_agreement is true" |
| 377 | ) |
| 378 | else: |
| 379 | return self._decipher_only |
| 380 | |
Paul Kehrer | ac3e5bb | 2015-04-02 23:07:10 -0500 | [diff] [blame] | 381 | def __repr__(self): |
| 382 | try: |
| 383 | encipher_only = self.encipher_only |
| 384 | decipher_only = self.decipher_only |
| 385 | except ValueError: |
Paul Kehrer | b372e67 | 2015-04-15 11:05:24 -0400 | [diff] [blame] | 386 | encipher_only = None |
| 387 | decipher_only = None |
Paul Kehrer | ac3e5bb | 2015-04-02 23:07:10 -0500 | [diff] [blame] | 388 | |
| 389 | return ("<KeyUsage(digital_signature={0.digital_signature}, " |
| 390 | "content_commitment={0.content_commitment}, " |
| 391 | "key_encipherment={0.key_encipherment}, " |
| 392 | "data_encipherment={0.data_encipherment}, " |
| 393 | "key_agreement={0.key_agreement}, " |
| 394 | "key_cert_sign={0.key_cert_sign}, crl_sign={0.crl_sign}, " |
| 395 | "encipher_only={1}, decipher_only={2})>").format( |
| 396 | self, encipher_only, decipher_only) |
| 397 | |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 398 | |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame^] | 399 | class AuthorityInformationAccess(object): |
| 400 | def __init__(self, descriptions): |
| 401 | if not all(isinstance(x, AccessDescription) for x in descriptions): |
| 402 | raise TypeError( |
| 403 | "Every item in the descriptions list must be an " |
| 404 | "AccessDescription" |
| 405 | ) |
| 406 | |
| 407 | self._descriptions = descriptions |
| 408 | |
| 409 | def __iter__(self): |
| 410 | return iter(self._descriptions) |
| 411 | |
| 412 | def __len__(self): |
| 413 | return len(self._descriptions) |
| 414 | |
| 415 | def __repr__(self): |
| 416 | return "<AuthorityInformationAccess({0})>".format(self._descriptions) |
| 417 | |
| 418 | def __eq__(self, other): |
| 419 | if not isinstance(other, AuthorityInformationAccess): |
| 420 | return NotImplemented |
| 421 | |
| 422 | return self._descriptions == other._descriptions |
| 423 | |
| 424 | def __ne__(self, other): |
| 425 | return not self == other |
| 426 | |
| 427 | |
| 428 | class AccessDescription(object): |
| 429 | def __init__(self, access_method, access_location): |
| 430 | if not (access_method == OID_OCSP or access_method == OID_CA_ISSUERS): |
| 431 | raise TypeError("access_method must be OID_OCSP or OID_CA_ISSUERS") |
| 432 | |
| 433 | if not isinstance(access_location, GeneralName): |
| 434 | raise TypeError("access_location must be a GeneralName") |
| 435 | |
| 436 | self._access_method = access_method |
| 437 | self._access_location = access_location |
| 438 | |
| 439 | def __repr__(self): |
| 440 | return ( |
| 441 | "<AccessDescription(access_method={0.access_method}, access_locati" |
| 442 | "on={0.access_location})>".format(self) |
| 443 | ) |
| 444 | |
| 445 | def __eq__(self, other): |
| 446 | if not isinstance(other, AccessDescription): |
| 447 | return NotImplemented |
| 448 | |
| 449 | return ( |
| 450 | self.access_method == other.access_method and |
| 451 | self.access_location == other.access_location |
| 452 | ) |
| 453 | |
| 454 | def __ne__(self, other): |
| 455 | return not self == other |
| 456 | |
| 457 | access_method = utils.read_only_property("_access_method") |
| 458 | access_location = utils.read_only_property("_access_location") |
| 459 | |
| 460 | |
Paul Kehrer | 1eb82a6 | 2015-03-31 20:00:33 -0500 | [diff] [blame] | 461 | class SubjectKeyIdentifier(object): |
| 462 | def __init__(self, digest): |
| 463 | self._digest = digest |
| 464 | |
| 465 | digest = utils.read_only_property("_digest") |
| 466 | |
Paul Kehrer | 1eb82a6 | 2015-03-31 20:00:33 -0500 | [diff] [blame] | 467 | def __repr__(self): |
Paul Kehrer | cbfb101 | 2015-04-10 20:57:20 -0400 | [diff] [blame] | 468 | return "<SubjectKeyIdentifier(digest={0!r})>".format(self.digest) |
Paul Kehrer | 1eb82a6 | 2015-03-31 20:00:33 -0500 | [diff] [blame] | 469 | |
| 470 | def __eq__(self, other): |
| 471 | if not isinstance(other, SubjectKeyIdentifier): |
| 472 | return NotImplemented |
| 473 | |
| 474 | return ( |
| 475 | self.digest == other.digest |
| 476 | ) |
| 477 | |
| 478 | def __ne__(self, other): |
| 479 | return not self == other |
| 480 | |
| 481 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 482 | @six.add_metaclass(abc.ABCMeta) |
| 483 | class GeneralName(object): |
| 484 | @abc.abstractproperty |
| 485 | def value(self): |
| 486 | """ |
| 487 | Return the value of the object |
| 488 | """ |
| 489 | |
| 490 | |
| 491 | @utils.register_interface(GeneralName) |
| 492 | class RFC822Name(object): |
| 493 | def __init__(self, value): |
| 494 | if not isinstance(value, six.text_type): |
| 495 | raise TypeError("value must be a unicode string") |
| 496 | |
| 497 | self._value = value |
| 498 | |
| 499 | value = utils.read_only_property("_value") |
| 500 | |
| 501 | def __repr__(self): |
| 502 | return "<RFC822Name(value={0})>".format(self.value) |
| 503 | |
| 504 | def __eq__(self, other): |
| 505 | if not isinstance(other, RFC822Name): |
| 506 | return NotImplemented |
| 507 | |
| 508 | return self.value == other.value |
| 509 | |
| 510 | def __ne__(self, other): |
| 511 | return not self == other |
| 512 | |
| 513 | |
| 514 | @utils.register_interface(GeneralName) |
| 515 | class DNSName(object): |
| 516 | def __init__(self, value): |
| 517 | if not isinstance(value, six.text_type): |
| 518 | raise TypeError("value must be a unicode string") |
| 519 | |
| 520 | self._value = value |
| 521 | |
| 522 | value = utils.read_only_property("_value") |
| 523 | |
| 524 | def __repr__(self): |
| 525 | return "<DNSName(value={0})>".format(self.value) |
| 526 | |
| 527 | def __eq__(self, other): |
| 528 | if not isinstance(other, DNSName): |
| 529 | return NotImplemented |
| 530 | |
| 531 | return self.value == other.value |
| 532 | |
| 533 | def __ne__(self, other): |
| 534 | return not self == other |
| 535 | |
| 536 | |
| 537 | @utils.register_interface(GeneralName) |
| 538 | class UniformResourceIdentifier(object): |
| 539 | def __init__(self, value): |
| 540 | if not isinstance(value, six.text_type): |
| 541 | raise TypeError("value must be a unicode string") |
| 542 | |
| 543 | self._value = value |
| 544 | |
| 545 | value = utils.read_only_property("_value") |
| 546 | |
| 547 | def __repr__(self): |
| 548 | return "<UniformResourceIdentifier(value={0})>".format(self.value) |
| 549 | |
| 550 | def __eq__(self, other): |
| 551 | if not isinstance(other, UniformResourceIdentifier): |
| 552 | return NotImplemented |
| 553 | |
| 554 | return self.value == other.value |
| 555 | |
| 556 | def __ne__(self, other): |
| 557 | return not self == other |
| 558 | |
| 559 | |
| 560 | @utils.register_interface(GeneralName) |
| 561 | class DirectoryName(object): |
| 562 | def __init__(self, value): |
| 563 | if not isinstance(value, Name): |
| 564 | raise TypeError("value must be a Name") |
| 565 | |
| 566 | self._value = value |
| 567 | |
| 568 | value = utils.read_only_property("_value") |
| 569 | |
| 570 | def __repr__(self): |
| 571 | return "<DirectoryName(value={0})>".format(self.value) |
| 572 | |
| 573 | def __eq__(self, other): |
| 574 | if not isinstance(other, DirectoryName): |
| 575 | return NotImplemented |
| 576 | |
| 577 | return self.value == other.value |
| 578 | |
| 579 | def __ne__(self, other): |
| 580 | return not self == other |
| 581 | |
| 582 | |
| 583 | @utils.register_interface(GeneralName) |
| 584 | class RegisteredID(object): |
| 585 | def __init__(self, value): |
| 586 | if not isinstance(value, ObjectIdentifier): |
| 587 | raise TypeError("value must be an ObjectIdentifier") |
| 588 | |
| 589 | self._value = value |
| 590 | |
| 591 | value = utils.read_only_property("_value") |
| 592 | |
| 593 | def __repr__(self): |
| 594 | return "<RegisteredID(value={0})>".format(self.value) |
| 595 | |
| 596 | def __eq__(self, other): |
| 597 | if not isinstance(other, RegisteredID): |
| 598 | return NotImplemented |
| 599 | |
| 600 | return self.value == other.value |
| 601 | |
| 602 | def __ne__(self, other): |
| 603 | return not self == other |
| 604 | |
| 605 | |
| 606 | @utils.register_interface(GeneralName) |
| 607 | class IPAddress(object): |
| 608 | def __init__(self, value): |
| 609 | if not isinstance( |
| 610 | value, (ipaddress.IPv4Address, ipaddress.IPv6Address) |
| 611 | ): |
| 612 | raise TypeError( |
| 613 | "value must be an instance of ipaddress.IPv4Address or " |
| 614 | "ipaddress.IPv6Address" |
| 615 | ) |
| 616 | |
| 617 | self._value = value |
| 618 | |
| 619 | value = utils.read_only_property("_value") |
| 620 | |
| 621 | def __repr__(self): |
| 622 | return "<IPAddress(value={0})>".format(self.value) |
| 623 | |
| 624 | def __eq__(self, other): |
| 625 | if not isinstance(other, IPAddress): |
| 626 | return NotImplemented |
| 627 | |
| 628 | return self.value == other.value |
| 629 | |
| 630 | def __ne__(self, other): |
| 631 | return not self == other |
| 632 | |
| 633 | |
| 634 | class SubjectAlternativeName(object): |
| 635 | def __init__(self, general_names): |
Paul Kehrer | d04b39b | 2015-04-21 08:44:17 -0500 | [diff] [blame] | 636 | if not all(isinstance(x, GeneralName) for x in general_names): |
| 637 | raise TypeError( |
| 638 | "Every item in the general_names list must be an " |
| 639 | "object conforming to the GeneralName interface" |
| 640 | ) |
| 641 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 642 | self._general_names = general_names |
| 643 | |
| 644 | def __iter__(self): |
| 645 | return iter(self._general_names) |
| 646 | |
| 647 | def __len__(self): |
| 648 | return len(self._general_names) |
| 649 | |
| 650 | def get_values_for_type(self, type): |
| 651 | return [i.value for i in self if isinstance(i, type)] |
| 652 | |
| 653 | def __repr__(self): |
| 654 | return "<SubjectAlternativeName({0})>".format(self._general_names) |
| 655 | |
| 656 | |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 657 | class AuthorityKeyIdentifier(object): |
| 658 | def __init__(self, key_identifier, authority_cert_issuer, |
| 659 | authority_cert_serial_number): |
| 660 | if authority_cert_issuer or authority_cert_serial_number: |
| 661 | if not authority_cert_issuer or not authority_cert_serial_number: |
| 662 | raise ValueError( |
| 663 | "authority_cert_issuer and authority_cert_serial_number " |
| 664 | "must both be present or both None" |
| 665 | ) |
| 666 | |
| 667 | if not isinstance(authority_cert_issuer, Name): |
| 668 | raise TypeError("authority_cert_issuer must be a Name") |
| 669 | |
| 670 | if not isinstance(authority_cert_serial_number, six.integer_types): |
| 671 | raise TypeError( |
| 672 | "authority_cert_serial_number must be an integer" |
| 673 | ) |
| 674 | |
| 675 | self._key_identifier = key_identifier |
| 676 | self._authority_cert_issuer = authority_cert_issuer |
| 677 | self._authority_cert_serial_number = authority_cert_serial_number |
| 678 | |
| 679 | def __repr__(self): |
| 680 | return ( |
| 681 | "<AuthorityKeyIdentifier(key_identifier={0.key_identifier!r}, " |
| 682 | "authority_cert_issuer={0.authority_cert_issuer}, " |
| 683 | "authority_cert_serial_number={0.authority_cert_serial_number}" |
| 684 | ")>".format(self) |
| 685 | ) |
| 686 | |
| 687 | key_identifier = utils.read_only_property("_key_identifier") |
| 688 | authority_cert_issuer = utils.read_only_property("_authority_cert_issuer") |
| 689 | authority_cert_serial_number = utils.read_only_property( |
| 690 | "_authority_cert_serial_number" |
| 691 | ) |
| 692 | |
| 693 | |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 694 | OID_COMMON_NAME = ObjectIdentifier("2.5.4.3") |
| 695 | OID_COUNTRY_NAME = ObjectIdentifier("2.5.4.6") |
| 696 | OID_LOCALITY_NAME = ObjectIdentifier("2.5.4.7") |
| 697 | OID_STATE_OR_PROVINCE_NAME = ObjectIdentifier("2.5.4.8") |
| 698 | OID_ORGANIZATION_NAME = ObjectIdentifier("2.5.4.10") |
| 699 | OID_ORGANIZATIONAL_UNIT_NAME = ObjectIdentifier("2.5.4.11") |
| 700 | OID_SERIAL_NUMBER = ObjectIdentifier("2.5.4.5") |
| 701 | OID_SURNAME = ObjectIdentifier("2.5.4.4") |
| 702 | OID_GIVEN_NAME = ObjectIdentifier("2.5.4.42") |
| 703 | OID_TITLE = ObjectIdentifier("2.5.4.12") |
| 704 | OID_GENERATION_QUALIFIER = ObjectIdentifier("2.5.4.44") |
| 705 | OID_DN_QUALIFIER = ObjectIdentifier("2.5.4.46") |
| 706 | OID_PSEUDONYM = ObjectIdentifier("2.5.4.65") |
| 707 | OID_DOMAIN_COMPONENT = ObjectIdentifier("0.9.2342.19200300.100.1.25") |
| 708 | OID_EMAIL_ADDRESS = ObjectIdentifier("1.2.840.113549.1.9.1") |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 709 | |
Paul Kehrer | 1a7ba87 | 2015-02-19 18:09:05 -0600 | [diff] [blame] | 710 | OID_RSA_WITH_MD5 = ObjectIdentifier("1.2.840.113549.1.1.4") |
| 711 | OID_RSA_WITH_SHA1 = ObjectIdentifier("1.2.840.113549.1.1.5") |
| 712 | OID_RSA_WITH_SHA224 = ObjectIdentifier("1.2.840.113549.1.1.14") |
| 713 | OID_RSA_WITH_SHA256 = ObjectIdentifier("1.2.840.113549.1.1.11") |
| 714 | OID_RSA_WITH_SHA384 = ObjectIdentifier("1.2.840.113549.1.1.12") |
| 715 | OID_RSA_WITH_SHA512 = ObjectIdentifier("1.2.840.113549.1.1.13") |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 716 | OID_ECDSA_WITH_SHA224 = ObjectIdentifier("1.2.840.10045.4.3.1") |
| 717 | OID_ECDSA_WITH_SHA256 = ObjectIdentifier("1.2.840.10045.4.3.2") |
| 718 | OID_ECDSA_WITH_SHA384 = ObjectIdentifier("1.2.840.10045.4.3.3") |
| 719 | OID_ECDSA_WITH_SHA512 = ObjectIdentifier("1.2.840.10045.4.3.4") |
| 720 | OID_DSA_WITH_SHA1 = ObjectIdentifier("1.2.840.10040.4.3") |
| 721 | OID_DSA_WITH_SHA224 = ObjectIdentifier("2.16.840.1.101.3.4.3.1") |
| 722 | OID_DSA_WITH_SHA256 = ObjectIdentifier("2.16.840.1.101.3.4.3.2") |
| 723 | |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 724 | _SIG_OIDS_TO_HASH = { |
Paul Kehrer | 1a7ba87 | 2015-02-19 18:09:05 -0600 | [diff] [blame] | 725 | OID_RSA_WITH_MD5.dotted_string: hashes.MD5(), |
| 726 | OID_RSA_WITH_SHA1.dotted_string: hashes.SHA1(), |
| 727 | OID_RSA_WITH_SHA224.dotted_string: hashes.SHA224(), |
| 728 | OID_RSA_WITH_SHA256.dotted_string: hashes.SHA256(), |
| 729 | OID_RSA_WITH_SHA384.dotted_string: hashes.SHA384(), |
| 730 | OID_RSA_WITH_SHA512.dotted_string: hashes.SHA512(), |
Paul Kehrer | 42a87cb | 2015-02-13 18:53:24 -0600 | [diff] [blame] | 731 | OID_ECDSA_WITH_SHA224.dotted_string: hashes.SHA224(), |
| 732 | OID_ECDSA_WITH_SHA256.dotted_string: hashes.SHA256(), |
| 733 | OID_ECDSA_WITH_SHA384.dotted_string: hashes.SHA384(), |
| 734 | OID_ECDSA_WITH_SHA512.dotted_string: hashes.SHA512(), |
| 735 | OID_DSA_WITH_SHA1.dotted_string: hashes.SHA1(), |
| 736 | OID_DSA_WITH_SHA224.dotted_string: hashes.SHA224(), |
| 737 | OID_DSA_WITH_SHA256.dotted_string: hashes.SHA256() |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 738 | } |
| 739 | |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 740 | OID_SERVER_AUTH = ObjectIdentifier("1.3.6.1.5.5.7.3.1") |
| 741 | OID_CLIENT_AUTH = ObjectIdentifier("1.3.6.1.5.5.7.3.2") |
| 742 | OID_CODE_SIGNING = ObjectIdentifier("1.3.6.1.5.5.7.3.3") |
| 743 | OID_EMAIL_PROTECTION = ObjectIdentifier("1.3.6.1.5.5.7.3.4") |
| 744 | OID_TIME_STAMPING = ObjectIdentifier("1.3.6.1.5.5.7.3.8") |
| 745 | OID_OCSP_SIGNING = ObjectIdentifier("1.3.6.1.5.5.7.3.9") |
| 746 | |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame^] | 747 | OID_CA_ISSUERS = ObjectIdentifier("1.3.6.1.5.5.7.48.2") |
| 748 | OID_OCSP = ObjectIdentifier("1.3.6.1.5.5.7.48.1") |
| 749 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 750 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 751 | @six.add_metaclass(abc.ABCMeta) |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 752 | class Certificate(object): |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 753 | @abc.abstractmethod |
| 754 | def fingerprint(self, algorithm): |
| 755 | """ |
| 756 | Returns bytes using digest passed. |
| 757 | """ |
| 758 | |
| 759 | @abc.abstractproperty |
| 760 | def serial(self): |
| 761 | """ |
| 762 | Returns certificate serial number |
| 763 | """ |
| 764 | |
| 765 | @abc.abstractproperty |
| 766 | def version(self): |
| 767 | """ |
| 768 | Returns the certificate version |
| 769 | """ |
| 770 | |
| 771 | @abc.abstractmethod |
| 772 | def public_key(self): |
| 773 | """ |
| 774 | Returns the public key |
| 775 | """ |
| 776 | |
| 777 | @abc.abstractproperty |
| 778 | def not_valid_before(self): |
| 779 | """ |
| 780 | Not before time (represented as UTC datetime) |
| 781 | """ |
| 782 | |
| 783 | @abc.abstractproperty |
| 784 | def not_valid_after(self): |
| 785 | """ |
| 786 | Not after time (represented as UTC datetime) |
| 787 | """ |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 788 | |
| 789 | @abc.abstractproperty |
| 790 | def issuer(self): |
| 791 | """ |
| 792 | Returns the issuer name object. |
| 793 | """ |
| 794 | |
| 795 | @abc.abstractproperty |
| 796 | def subject(self): |
| 797 | """ |
| 798 | Returns the subject name object. |
| 799 | """ |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 800 | |
| 801 | @abc.abstractproperty |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 802 | def signature_hash_algorithm(self): |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 803 | """ |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 804 | Returns a HashAlgorithm corresponding to the type of the digest signed |
| 805 | in the certificate. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 806 | """ |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 807 | |
Paul Kehrer | 8bbdc6f | 2015-04-30 16:47:16 -0500 | [diff] [blame] | 808 | @abc.abstractmethod |
| 809 | def __eq__(self, other): |
| 810 | """ |
| 811 | Checks equality. |
| 812 | """ |
| 813 | |
| 814 | @abc.abstractmethod |
| 815 | def __ne__(self, other): |
| 816 | """ |
| 817 | Checks not equal. |
| 818 | """ |
| 819 | |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 820 | |
| 821 | @six.add_metaclass(abc.ABCMeta) |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 822 | class CertificateSigningRequest(object): |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 823 | @abc.abstractmethod |
| 824 | def public_key(self): |
| 825 | """ |
| 826 | Returns the public key |
| 827 | """ |
| 828 | |
| 829 | @abc.abstractproperty |
| 830 | def subject(self): |
| 831 | """ |
| 832 | Returns the subject name object. |
| 833 | """ |
| 834 | |
| 835 | @abc.abstractproperty |
| 836 | def signature_hash_algorithm(self): |
| 837 | """ |
| 838 | Returns a HashAlgorithm corresponding to the type of the digest signed |
| 839 | in the certificate. |
| 840 | """ |