Paul Kehrer | 732cf64 | 2018-08-15 18:04:28 -0500 | [diff] [blame] | 1 | OCSP |
| 2 | ==== |
| 3 | |
| 4 | .. currentmodule:: cryptography.x509.ocsp |
| 5 | |
| 6 | .. testsetup:: |
| 7 | |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 8 | import base64 |
| 9 | pem_cert = b""" |
| 10 | -----BEGIN CERTIFICATE----- |
| 11 | MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx |
| 12 | FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1 |
| 13 | NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR |
| 14 | BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t |
| 15 | L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh |
| 16 | bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5 |
| 17 | LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s |
| 18 | itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR |
| 19 | PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ |
| 20 | CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu |
| 21 | 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y |
| 22 | 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/ |
| 23 | r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW |
| 24 | ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx |
| 25 | diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi |
| 26 | gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu |
| 27 | YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74 |
| 28 | FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc |
| 29 | 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT |
| 30 | aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi |
| 31 | LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB |
| 32 | BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw |
| 33 | dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv |
| 34 | bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw |
| 35 | LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G |
| 36 | CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc |
| 37 | dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt |
| 38 | Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF |
| 39 | 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH |
| 40 | aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i |
| 41 | GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP |
| 42 | -----END CERTIFICATE----- |
| 43 | """ |
| 44 | pem_issuer = b""" |
| 45 | -----BEGIN CERTIFICATE----- |
| 46 | MIIEJTCCAw2gAwIBAgIDAjp3MA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNVBAYTAlVT |
| 47 | MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i |
| 48 | YWwgQ0EwHhcNMTQwODI5MjEzOTMyWhcNMjIwNTIwMjEzOTMyWjBHMQswCQYDVQQG |
| 49 | EwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEgMB4GA1UEAxMXUmFwaWRTU0wg |
| 50 | U0hBMjU2IENBIC0gRzMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCv |
| 51 | VJvZWF0eLFbG1eh/9H0WA//Qi1rkjqfdVC7UBMBdmJyNkA+8EGVf2prWRHzAn7Xp |
| 52 | SowLBkMEu/SW4ib2YQGRZjEiwzQ0Xz8/kS9EX9zHFLYDn4ZLDqP/oIACg8PTH2lS |
| 53 | 1p1kD8mD5xvEcKyU58Okaiy9uJ5p2L4KjxZjWmhxgHsw3hUEv8zTvz5IBVV6s9cQ |
| 54 | DAP8m/0Ip4yM26eO8R5j3LMBL3+vV8M8SKeDaCGnL+enP/C1DPz1hNFTvA5yT2AM |
| 55 | QriYrRmIV9cE7Ie/fodOoyH5U/02mEiN1vi7SPIpyGTRzFRIU4uvt2UevykzKdkp |
| 56 | YEj4/5G8V1jlNS67abZZAgMBAAGjggEdMIIBGTAfBgNVHSMEGDAWgBTAephojYn7 |
| 57 | qwVkDBF9qn1luMrMTjAdBgNVHQ4EFgQUw5zz/NNGCDS7zkZ/oHxb8+IIy1kwEgYD |
| 58 | VR0TAQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAQYwNQYDVR0fBC4wLDAqoCig |
| 59 | JoYkaHR0cDovL2cuc3ltY2IuY29tL2NybHMvZ3RnbG9iYWwuY3JsMC4GCCsGAQUF |
| 60 | BwEBBCIwIDAeBggrBgEFBQcwAYYSaHR0cDovL2cuc3ltY2QuY29tMEwGA1UdIARF |
| 61 | MEMwQQYKYIZIAYb4RQEHNjAzMDEGCCsGAQUFBwIBFiVodHRwOi8vd3d3Lmdlb3Ry |
| 62 | dXN0LmNvbS9yZXNvdXJjZXMvY3BzMA0GCSqGSIb3DQEBCwUAA4IBAQCjWB7GQzKs |
| 63 | rC+TeLfqrlRARy1+eI1Q9vhmrNZPc9ZE768LzFvB9E+aj0l+YK/CJ8cW8fuTgZCp |
| 64 | fO9vfm5FlBaEvexJ8cQO9K8EWYOHDyw7l8NaEpt7BDV7o5UzCHuTcSJCs6nZb0+B |
| 65 | kvwHtnm8hEqddwnxxYny8LScVKoSew26T++TGezvfU5ho452nFnPjJSxhJf3GrkH |
| 66 | uLLGTxN5279PURt/aQ1RKsHWFf83UTRlUfQevjhq7A6rvz17OQV79PP7GqHQyH5O |
| 67 | ZI3NjGFVkP46yl0lD/gdo0p0Vk8aVUBwdSWmMy66S6VdU5oNMOGNX2Esr8zvsJmh |
| 68 | gP8L8mJMcCaY |
| 69 | -----END CERTIFICATE----- |
| 70 | """ |
Paul Kehrer | 732cf64 | 2018-08-15 18:04:28 -0500 | [diff] [blame] | 71 | der_ocsp_req = ( |
| 72 | b"0V0T0R0P0N0\t\x06\x05+\x0e\x03\x02\x1a\x05\x00\x04\x148\xcaF\x8c" |
| 73 | b"\x07D\x8d\xf4\x81\x96\xc7mmLpQ\x9e`\xa7\xbd\x04\x14yu\xbb\x84:\xcb" |
| 74 | b",\xdez\t\xbe1\x1bC\xbc\x1c*MSX\x02\x15\x00\x98\xd9\xe5\xc0\xb4\xc3" |
| 75 | b"sU-\xf7|]\x0f\x1e\xb5\x12\x8eIE\xf9" |
| 76 | ) |
Paul Kehrer | a07de31 | 2018-10-02 07:54:31 +0800 | [diff] [blame] | 77 | der_ocsp_resp_unauth = b"0\x03\n\x01\x06" |
Paul Kehrer | 732cf64 | 2018-08-15 18:04:28 -0500 | [diff] [blame] | 78 | |
| 79 | OCSP (Online Certificate Status Protocol) is a method of checking the |
| 80 | revocation status of certificates. It is specified in :rfc:`6960`, as well |
| 81 | as other obsoleted RFCs. |
| 82 | |
| 83 | |
| 84 | Loading Requests |
| 85 | ~~~~~~~~~~~~~~~~ |
| 86 | |
| 87 | .. function:: load_der_ocsp_request(data) |
| 88 | |
| 89 | .. versionadded:: 2.4 |
| 90 | |
| 91 | Deserialize an OCSP request from DER encoded data. |
| 92 | |
| 93 | :param bytes data: The DER encoded OCSP request data. |
| 94 | |
| 95 | :returns: An instance of :class:`~cryptography.x509.ocsp.OCSPRequest`. |
| 96 | |
| 97 | .. doctest:: |
| 98 | |
| 99 | >>> from cryptography.x509 import ocsp |
| 100 | >>> ocsp_req = ocsp.load_der_ocsp_request(der_ocsp_req) |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 101 | >>> print(ocsp_req.serial_number) |
Paul Kehrer | 732cf64 | 2018-08-15 18:04:28 -0500 | [diff] [blame] | 102 | 872625873161273451176241581705670534707360122361 |
| 103 | |
| 104 | |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 105 | Creating Requests |
| 106 | ~~~~~~~~~~~~~~~~~ |
| 107 | |
| 108 | .. class:: OCSPRequestBuilder |
| 109 | |
| 110 | .. versionadded:: 2.4 |
| 111 | |
| 112 | This class is used to create :class:`~cryptography.x509.ocsp.OCSPRequest` |
| 113 | objects. |
| 114 | |
| 115 | |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 116 | .. method:: add_certificate(cert, issuer, algorithm) |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 117 | |
| 118 | Adds a request using a certificate, issuer certificate, and hash |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 119 | algorithm. This can only be called once. |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 120 | |
| 121 | :param cert: The :class:`~cryptography.x509.Certificate` whose validity |
| 122 | is being checked. |
| 123 | |
| 124 | :param issuer: The issuer :class:`~cryptography.x509.Certificate` of |
| 125 | the certificate that is being checked. |
| 126 | |
| 127 | :param algorithm: A |
| 128 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 129 | instance. For OCSP only |
| 130 | :class:`~cryptography.hazmat.primitives.hashes.SHA1`, |
| 131 | :class:`~cryptography.hazmat.primitives.hashes.SHA224`, |
| 132 | :class:`~cryptography.hazmat.primitives.hashes.SHA256`, |
| 133 | :class:`~cryptography.hazmat.primitives.hashes.SHA384`, and |
| 134 | :class:`~cryptography.hazmat.primitives.hashes.SHA512` are allowed. |
| 135 | |
Paul Kehrer | 0c07580 | 2018-10-07 10:10:09 +0800 | [diff] [blame^] | 136 | .. method:: add_extension(extension, critical) |
| 137 | |
| 138 | Adds an extension to the request. |
| 139 | |
| 140 | :param extension: An extension conforming to the |
| 141 | :class:`~cryptography.x509.ExtensionType` interface. |
| 142 | |
| 143 | :param critical: Set to ``True`` if the extension must be understood and |
| 144 | handled. |
| 145 | |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 146 | .. method:: build() |
| 147 | |
| 148 | :returns: A new :class:`~cryptography.x509.ocsp.OCSPRequest`. |
| 149 | |
| 150 | .. doctest:: |
| 151 | |
| 152 | >>> from cryptography.hazmat.backends import default_backend |
| 153 | >>> from cryptography.hazmat.primitives import serialization |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 154 | >>> from cryptography.hazmat.primitives.hashes import SHA1 |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 155 | >>> from cryptography.x509 import load_pem_x509_certificate, ocsp |
| 156 | >>> cert = load_pem_x509_certificate(pem_cert, default_backend()) |
| 157 | >>> issuer = load_pem_x509_certificate(pem_issuer, default_backend()) |
| 158 | >>> builder = ocsp.OCSPRequestBuilder() |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 159 | >>> # SHA1 is in this example because RFC 5019 mandates its use. |
| 160 | >>> builder = builder.add_certificate(cert, issuer, SHA1()) |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 161 | >>> req = builder.build() |
| 162 | >>> base64.b64encode(req.public_bytes(serialization.Encoding.DER)) |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 163 | b'MEMwQTA/MD0wOzAJBgUrDgMCGgUABBRAC0Z68eay0wmDug1gfn5ZN0gkxAQUw5zz/NNGCDS7zkZ/oHxb8+IIy1kCAj8g' |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 164 | |
Paul Kehrer | a07de31 | 2018-10-02 07:54:31 +0800 | [diff] [blame] | 165 | Loading Responses |
| 166 | ~~~~~~~~~~~~~~~~~ |
| 167 | |
| 168 | .. function:: load_der_ocsp_response(data) |
| 169 | |
| 170 | .. versionadded:: 2.4 |
| 171 | |
| 172 | Deserialize an OCSP response from DER encoded data. |
| 173 | |
| 174 | :param bytes data: The DER encoded OCSP response data. |
| 175 | |
| 176 | :returns: An instance of :class:`~cryptography.x509.ocsp.OCSPResponse`. |
| 177 | |
| 178 | .. doctest:: |
| 179 | |
| 180 | >>> from cryptography.x509 import ocsp |
| 181 | >>> ocsp_resp = ocsp.load_der_ocsp_response(der_ocsp_resp_unauth) |
| 182 | >>> print(ocsp_resp.response_status) |
| 183 | OCSPResponseStatus.UNAUTHORIZED |
| 184 | |
Paul Kehrer | 002fa75 | 2018-08-30 10:41:32 -0400 | [diff] [blame] | 185 | |
Paul Kehrer | 732cf64 | 2018-08-15 18:04:28 -0500 | [diff] [blame] | 186 | Interfaces |
| 187 | ~~~~~~~~~~ |
| 188 | |
| 189 | .. class:: OCSPRequest |
| 190 | |
| 191 | .. versionadded:: 2.4 |
| 192 | |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 193 | An ``OCSPRequest`` is an object containing information about a certificate |
| 194 | whose status is being checked. |
Paul Kehrer | 732cf64 | 2018-08-15 18:04:28 -0500 | [diff] [blame] | 195 | |
| 196 | .. attribute:: issuer_key_hash |
| 197 | |
| 198 | :type: bytes |
| 199 | |
| 200 | The hash of the certificate issuer's key. The hash algorithm used |
| 201 | is defined by the ``hash_algorithm`` property. |
| 202 | |
| 203 | .. attribute:: issuer_name_hash |
| 204 | |
| 205 | :type: bytes |
| 206 | |
| 207 | The hash of the certificate issuer's name. The hash algorithm used |
| 208 | is defined by the ``hash_algorithm`` property. |
| 209 | |
| 210 | .. attribute:: hash_algorithm |
| 211 | |
Paul Kehrer | edfedc1 | 2018-09-14 18:24:20 -0400 | [diff] [blame] | 212 | :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | 732cf64 | 2018-08-15 18:04:28 -0500 | [diff] [blame] | 213 | |
| 214 | The algorithm used to generate the ``issuer_key_hash`` and |
| 215 | ``issuer_name_hash``. |
| 216 | |
| 217 | .. attribute:: serial_number |
| 218 | |
| 219 | :type: int |
| 220 | |
| 221 | The serial number of the certificate to check. |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 222 | |
Paul Kehrer | 0940310 | 2018-09-09 21:57:21 -0500 | [diff] [blame] | 223 | .. attribute:: extensions |
| 224 | |
| 225 | :type: :class:`~cryptography.x509.Extensions` |
| 226 | |
| 227 | The extensions encoded in the request. |
| 228 | |
Paul Kehrer | 0f629bb | 2018-08-31 10:47:56 -0400 | [diff] [blame] | 229 | .. method:: public_bytes(encoding) |
| 230 | |
| 231 | :param encoding: The encoding to use. Only |
| 232 | :attr:`~cryptography.hazmat.primitives.serialization.Encoding.DER` |
| 233 | is supported. |
| 234 | |
| 235 | :return bytes: The serialized OCSP request. |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 236 | |
| 237 | .. class:: OCSPResponse |
| 238 | |
| 239 | .. versionadded:: 2.4 |
| 240 | |
| 241 | An ``OCSPResponse`` is the data provided by an OCSP responder in response |
| 242 | to an ``OCSPRequest``. |
| 243 | |
| 244 | .. attribute:: response_status |
| 245 | |
| 246 | :type: :class:`~cryptography.x509.ocsp.OCSPResponseStatus` |
| 247 | |
| 248 | The status of the response. |
| 249 | |
| 250 | .. attribute:: signature_algorithm_oid |
| 251 | |
| 252 | :type: :class:`~cryptography.x509.ObjectIdentifier` |
| 253 | |
| 254 | Returns the object identifier of the signature algorithm used |
| 255 | to sign the response. This will be one of the OIDs from |
| 256 | :class:`~cryptography.x509.oid.SignatureAlgorithmOID`. |
| 257 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 258 | :raises ValueError: If ``response_status`` is not |
| 259 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 260 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 261 | .. attribute:: signature |
| 262 | |
| 263 | :type: bytes |
| 264 | |
| 265 | The signature bytes. |
| 266 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 267 | :raises ValueError: If ``response_status`` is not |
| 268 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 269 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 270 | .. attribute:: tbs_response_bytes |
| 271 | |
| 272 | :type: bytes |
| 273 | |
| 274 | The DER encoded bytes payload that is hashed and then signed. This |
| 275 | data may be used to validate the signature on the OCSP response. |
| 276 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 277 | :raises ValueError: If ``response_status`` is not |
| 278 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 279 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 280 | .. attribute:: certificates |
| 281 | |
| 282 | :type: list |
| 283 | |
| 284 | A list of zero or more :class:`~cryptography.x509.Certificate` objects |
| 285 | used to help build a chain to verify the OCSP response. This situation |
| 286 | occurs when the OCSP responder uses a delegate certificate. |
| 287 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 288 | :raises ValueError: If ``response_status`` is not |
| 289 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 290 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 291 | .. attribute:: responder_key_hash |
| 292 | |
| 293 | :type: bytes or None |
| 294 | |
| 295 | The responder's key hash or ``None`` if the response has a |
| 296 | ``responder_name``. |
| 297 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 298 | :raises ValueError: If ``response_status`` is not |
| 299 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 300 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 301 | .. attribute:: responder_name |
| 302 | |
| 303 | :type: :class:`~cryptography.x509.Name` or None |
| 304 | |
| 305 | The responder's ``Name`` or ``None`` if the response has a |
| 306 | ``responder_key_hash``. |
| 307 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 308 | :raises ValueError: If ``response_status`` is not |
| 309 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 310 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 311 | .. attribute:: produced_at |
| 312 | |
| 313 | :type: :class:`datetime.datetime` |
| 314 | |
| 315 | A naïve datetime representing the time when the response was produced. |
| 316 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 317 | :raises ValueError: If ``response_status`` is not |
| 318 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 319 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 320 | .. attribute:: certificate_status |
| 321 | |
| 322 | :type: :class:`~cryptography.x509.ocsp.OCSPCertStatus` |
| 323 | |
| 324 | The status of the certificate being checked. |
| 325 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 326 | :raises ValueError: If ``response_status`` is not |
| 327 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 328 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 329 | .. attribute:: revocation_time |
| 330 | |
| 331 | :type: :class:`datetime.datetime` or None |
| 332 | |
| 333 | A naïve datetime representing the time when the certificate was revoked |
| 334 | or ``None`` if the certificate has not been revoked. |
| 335 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 336 | :raises ValueError: If ``response_status`` is not |
| 337 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 338 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 339 | .. attribute:: revocation_reason |
| 340 | |
| 341 | :type: :class:`~cryptography.x509.ReasonFlags` or None |
| 342 | |
| 343 | The reason the certificate was revoked or ``None`` if not specified or |
| 344 | not revoked. |
| 345 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 346 | :raises ValueError: If ``response_status`` is not |
| 347 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 348 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 349 | .. attribute:: this_update |
| 350 | |
| 351 | :type: :class:`datetime.datetime` |
| 352 | |
| 353 | A naïve datetime representing the most recent time at which the status |
| 354 | being indicated is known by the responder to have been correct. |
| 355 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 356 | :raises ValueError: If ``response_status`` is not |
| 357 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 358 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 359 | .. attribute:: next_update |
| 360 | |
| 361 | :type: :class:`datetime.datetime` |
| 362 | |
| 363 | A naïve datetime representing the time when newer information will |
| 364 | be available. |
| 365 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 366 | :raises ValueError: If ``response_status`` is not |
| 367 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 368 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 369 | .. attribute:: issuer_key_hash |
| 370 | |
| 371 | :type: bytes |
| 372 | |
| 373 | The hash of the certificate issuer's key. The hash algorithm used |
| 374 | is defined by the ``hash_algorithm`` property. |
| 375 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 376 | :raises ValueError: If ``response_status`` is not |
| 377 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 378 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 379 | .. attribute:: issuer_name_hash |
| 380 | |
| 381 | :type: bytes |
| 382 | |
| 383 | The hash of the certificate issuer's name. The hash algorithm used |
| 384 | is defined by the ``hash_algorithm`` property. |
| 385 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 386 | :raises ValueError: If ``response_status`` is not |
| 387 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 388 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 389 | .. attribute:: hash_algorithm |
| 390 | |
Paul Kehrer | edfedc1 | 2018-09-14 18:24:20 -0400 | [diff] [blame] | 391 | :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 392 | |
| 393 | The algorithm used to generate the ``issuer_key_hash`` and |
| 394 | ``issuer_name_hash``. |
| 395 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 396 | :raises ValueError: If ``response_status`` is not |
| 397 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 398 | |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 399 | .. attribute:: serial_number |
| 400 | |
| 401 | :type: int |
| 402 | |
| 403 | The serial number of the certificate that was checked. |
| 404 | |
Paul Kehrer | 26c425d | 2018-09-01 16:58:26 -0400 | [diff] [blame] | 405 | :raises ValueError: If ``response_status`` is not |
| 406 | :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`. |
| 407 | |
Paul Kehrer | b8db668 | 2018-10-07 03:44:30 +0800 | [diff] [blame] | 408 | .. attribute:: extensions |
| 409 | |
| 410 | :type: :class:`~cryptography.x509.Extensions` |
| 411 | |
| 412 | The extensions encoded in the response. |
Paul Kehrer | d3601b1 | 2018-09-01 11:58:24 -0400 | [diff] [blame] | 413 | |
| 414 | .. class:: OCSPResponseStatus |
| 415 | |
| 416 | .. versionadded:: 2.4 |
| 417 | |
| 418 | An enumeration of response statuses. |
| 419 | |
| 420 | .. attribute:: SUCCESSFUL |
| 421 | |
| 422 | Represents a successful OCSP response. |
| 423 | |
| 424 | .. attribute:: MALFORMED_REQUEST |
| 425 | |
| 426 | May be returned by an OCSP responder that is unable to parse a |
| 427 | given request. |
| 428 | |
| 429 | .. attribute:: INTERNAL_ERROR |
| 430 | |
| 431 | May be returned by an OCSP responder that is currently experiencing |
| 432 | operational problems. |
| 433 | |
| 434 | .. attribute:: TRY_LATER |
| 435 | |
| 436 | May be returned by an OCSP responder that is overloaded. |
| 437 | |
| 438 | .. attribute:: SIG_REQUIRED |
| 439 | |
| 440 | May be returned by an OCSP responder that requires signed OCSP |
| 441 | requests. |
| 442 | |
| 443 | .. attribute:: UNAUTHORIZED |
| 444 | |
| 445 | May be returned by an OCSP responder when queried for a certificate for |
| 446 | which the responder is unaware or an issuer for which the responder is |
| 447 | not authoritative. |
| 448 | |
| 449 | |
| 450 | .. class:: OCSPCertStatus |
| 451 | |
| 452 | .. versionadded:: 2.4 |
| 453 | |
| 454 | An enumeration of certificate statuses in an OCSP response. |
| 455 | |
| 456 | .. attribute:: GOOD |
| 457 | |
| 458 | The value for a certificate that is not revoked. |
| 459 | |
| 460 | .. attribute:: REVOKED |
| 461 | |
| 462 | The certificate being checked is revoked. |
| 463 | |
| 464 | .. attribute:: UNKNOWN |
| 465 | |
| 466 | The certificate being checked is not known to the OCSP responder. |