blob: d3815d6f3a32c12227c16e518527cd664790486d [file] [log] [blame]
Paul Kehrer732cf642018-08-15 18:04:28 -05001OCSP
2====
3
4.. currentmodule:: cryptography.x509.ocsp
5
6.. testsetup::
7
Paul Kehrer002fa752018-08-30 10:41:32 -04008 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 ltAIUkbo8fGiVnat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vJzV+2Ag441Zeckk+bib7swduQIjIC
79 IQCqYD9pArB2SWfmhQCSZkNEATlsPIML8lvlSkbNcrmrqQ==
80 -----END CERTIFICATE-----
81 """
82 pem_responder_key = b"""
83 -----BEGIN PRIVATE KEY-----
84 MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgO+vsRu8xDIVZE+xh
85 s8ESqJqcpJlwmj8CtF8HPHxrDSGhRANCAARtDYTQ38TdHTMQb6pr7IAVcFjoW15D
86 PK8V2rsRkcOS2XJSWVpUkGttfUi1XQyVrIXDBA+Fma4s+lAHO5UrKtR9
87 -----END PRIVATE KEY-----
88 """
Paul Kehrer732cf642018-08-15 18:04:28 -050089 der_ocsp_req = (
90 b"0V0T0R0P0N0\t\x06\x05+\x0e\x03\x02\x1a\x05\x00\x04\x148\xcaF\x8c"
91 b"\x07D\x8d\xf4\x81\x96\xc7mmLpQ\x9e`\xa7\xbd\x04\x14yu\xbb\x84:\xcb"
92 b",\xdez\t\xbe1\x1bC\xbc\x1c*MSX\x02\x15\x00\x98\xd9\xe5\xc0\xb4\xc3"
93 b"sU-\xf7|]\x0f\x1e\xb5\x12\x8eIE\xf9"
94 )
Paul Kehrera07de312018-10-02 07:54:31 +080095 der_ocsp_resp_unauth = b"0\x03\n\x01\x06"
Paul Kehrer732cf642018-08-15 18:04:28 -050096
97OCSP (Online Certificate Status Protocol) is a method of checking the
98revocation status of certificates. It is specified in :rfc:`6960`, as well
99as other obsoleted RFCs.
100
101
102Loading Requests
103~~~~~~~~~~~~~~~~
104
105.. function:: load_der_ocsp_request(data)
106
107 .. versionadded:: 2.4
108
109 Deserialize an OCSP request from DER encoded data.
110
111 :param bytes data: The DER encoded OCSP request data.
112
113 :returns: An instance of :class:`~cryptography.x509.ocsp.OCSPRequest`.
114
115 .. doctest::
116
117 >>> from cryptography.x509 import ocsp
118 >>> ocsp_req = ocsp.load_der_ocsp_request(der_ocsp_req)
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400119 >>> print(ocsp_req.serial_number)
Paul Kehrer732cf642018-08-15 18:04:28 -0500120 872625873161273451176241581705670534707360122361
121
122
Paul Kehrer002fa752018-08-30 10:41:32 -0400123Creating Requests
124~~~~~~~~~~~~~~~~~
125
126.. class:: OCSPRequestBuilder
127
128 .. versionadded:: 2.4
129
130 This class is used to create :class:`~cryptography.x509.ocsp.OCSPRequest`
131 objects.
132
133
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400134 .. method:: add_certificate(cert, issuer, algorithm)
Paul Kehrer002fa752018-08-30 10:41:32 -0400135
136 Adds a request using a certificate, issuer certificate, and hash
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400137 algorithm. This can only be called once.
Paul Kehrer002fa752018-08-30 10:41:32 -0400138
139 :param cert: The :class:`~cryptography.x509.Certificate` whose validity
140 is being checked.
141
142 :param issuer: The issuer :class:`~cryptography.x509.Certificate` of
143 the certificate that is being checked.
144
145 :param algorithm: A
146 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
147 instance. For OCSP only
148 :class:`~cryptography.hazmat.primitives.hashes.SHA1`,
149 :class:`~cryptography.hazmat.primitives.hashes.SHA224`,
150 :class:`~cryptography.hazmat.primitives.hashes.SHA256`,
151 :class:`~cryptography.hazmat.primitives.hashes.SHA384`, and
152 :class:`~cryptography.hazmat.primitives.hashes.SHA512` are allowed.
153
Paul Kehrer0c075802018-10-07 10:10:09 +0800154 .. method:: add_extension(extension, critical)
155
156 Adds an extension to the request.
157
158 :param extension: An extension conforming to the
159 :class:`~cryptography.x509.ExtensionType` interface.
160
161 :param critical: Set to ``True`` if the extension must be understood and
162 handled.
163
Paul Kehrer002fa752018-08-30 10:41:32 -0400164 .. method:: build()
165
166 :returns: A new :class:`~cryptography.x509.ocsp.OCSPRequest`.
167
168 .. doctest::
169
170 >>> from cryptography.hazmat.backends import default_backend
171 >>> from cryptography.hazmat.primitives import serialization
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400172 >>> from cryptography.hazmat.primitives.hashes import SHA1
Paul Kehrer002fa752018-08-30 10:41:32 -0400173 >>> from cryptography.x509 import load_pem_x509_certificate, ocsp
174 >>> cert = load_pem_x509_certificate(pem_cert, default_backend())
175 >>> issuer = load_pem_x509_certificate(pem_issuer, default_backend())
176 >>> builder = ocsp.OCSPRequestBuilder()
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400177 >>> # SHA1 is in this example because RFC 5019 mandates its use.
178 >>> builder = builder.add_certificate(cert, issuer, SHA1())
Paul Kehrer002fa752018-08-30 10:41:32 -0400179 >>> req = builder.build()
180 >>> base64.b64encode(req.public_bytes(serialization.Encoding.DER))
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400181 b'MEMwQTA/MD0wOzAJBgUrDgMCGgUABBRAC0Z68eay0wmDug1gfn5ZN0gkxAQUw5zz/NNGCDS7zkZ/oHxb8+IIy1kCAj8g'
Paul Kehrer002fa752018-08-30 10:41:32 -0400182
Paul Kehrera07de312018-10-02 07:54:31 +0800183Loading Responses
184~~~~~~~~~~~~~~~~~
185
186.. function:: load_der_ocsp_response(data)
187
188 .. versionadded:: 2.4
189
190 Deserialize an OCSP response from DER encoded data.
191
192 :param bytes data: The DER encoded OCSP response data.
193
194 :returns: An instance of :class:`~cryptography.x509.ocsp.OCSPResponse`.
195
196 .. doctest::
197
198 >>> from cryptography.x509 import ocsp
199 >>> ocsp_resp = ocsp.load_der_ocsp_response(der_ocsp_resp_unauth)
200 >>> print(ocsp_resp.response_status)
201 OCSPResponseStatus.UNAUTHORIZED
202
Paul Kehrer002fa752018-08-30 10:41:32 -0400203
Paul Kehrere617c5a2018-10-29 05:36:34 +0800204Creating Responses
205~~~~~~~~~~~~~~~~~~
206
207.. class:: OCSPResponseBuilder
208
209 .. versionadded:: 2.4
210
211 This class is used to create :class:`~cryptography.x509.ocsp.OCSPResponse`
212 objects. You cannot set ``produced_at`` on OCSP responses at this time.
213 Instead the field is set to current UTC time when calling ``sign``. For
214 unsuccessful statuses call the class method
215 :meth:`~cryptography.x509.ocsp.OCSPResponseBuilder.build_unsuccessful`.
216
217 .. method:: add_response(cert, issuer, algorithm, cert_status, this_update, next_update, revocation_time, revocation_reason)
218
219 This method adds status information about the certificate that was
220 requested to the response.
221
222 :param cert: The :class:`~cryptography.x509.Certificate` whose validity
223 is being checked.
224
225 :param issuer: The issuer :class:`~cryptography.x509.Certificate` of
226 the certificate that is being checked.
227
228 :param algorithm: A
229 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
230 instance. For OCSP only
231 :class:`~cryptography.hazmat.primitives.hashes.SHA1`,
232 :class:`~cryptography.hazmat.primitives.hashes.SHA224`,
233 :class:`~cryptography.hazmat.primitives.hashes.SHA256`,
234 :class:`~cryptography.hazmat.primitives.hashes.SHA384`, and
235 :class:`~cryptography.hazmat.primitives.hashes.SHA512` are allowed.
236
237 :param cert_status: An item from the
238 :class:`~cryptography.x509.ocsp.OCSPCertStatus` enumeration.
239
240 :param this_update: A naïve :class:`datetime.datetime` object
241 representing the most recent time in UTC at which the status being
242 indicated is known by the responder to be correct.
243
244 :param next_update: A naïve :class:`datetime.datetime` object or
245 ``None``. The time in UTC at or before which newer information will
246 be available about the status of the certificate.
247
248 :param revocation_time: A naïve :class:`datetime.datetime` object or
249 ``None`` if the ``cert`` is not revoked. The time in UTC at which
250 the certificate was revoked.
251
252 :param revocation_reason: An item from the
253 :class:`~cryptography.x509.ReasonFlags` enumeration or ``None`` if
254 the ``cert`` is not revoked.
255
256 .. method:: certificates(certs)
257
258 Add additional certificates that should be used to verify the
259 signature on the response. This is typically used when the responder
260 utilizes an OCSP delegate.
261
262 :param list certs: A list of :class:`~cryptography.x509.Certificate`
263 objects.
264
265 .. method:: responder_id(encoding, responder_cert)
266
267 Set the ``responderID`` on the OCSP response. This is the data a
268 client will use to determine what certificate signed the response.
269
270 :param responder_cert: The :class:`~cryptography.x509.Certificate`
271 object for the certificate whose private key will sign the
272 OCSP response. If the certificate and key do not match an
273 error will be raised when calling ``sign``.
274 :param encoding: Either
275 :attr:`~cryptography.x509.ocsp.OCSPResponderEncoding.HASH` or
276 :attr:`~cryptography.x509.ocsp.OCSPResponderEncoding.NAME`.
277
278 .. method:: add_extension(extension, critical)
279
280 Adds an extension to the response.
281
282 :param extension: An extension conforming to the
283 :class:`~cryptography.x509.ExtensionType` interface.
284
285 :param critical: Set to ``True`` if the extension must be understood and
286 handled.
287
288 .. method:: sign(private_key, algorithm)
289
290 Creates the OCSP response that can then be serialized and sent to
291 clients. This method will create a
292 :attr:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL` response.
293
294 :param private_key: The
295 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`
296 or
297 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
298 that will be used to sign the certificate.
299
300 :param algorithm: The
301 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
302 will be used to generate the signature.
303
304 :returns: A new :class:`~cryptography.x509.ocsp.OCSPResponse`.
305
306 .. doctest::
307
308 >>> import datetime
309 >>> from cryptography.hazmat.backends import default_backend
310 >>> from cryptography.hazmat.primitives import hashes, serialization
311 >>> from cryptography.x509 import load_pem_x509_certificate, ocsp
312 >>> cert = load_pem_x509_certificate(pem_cert, default_backend())
313 >>> issuer = load_pem_x509_certificate(pem_issuer, default_backend())
314 >>> responder_cert = load_pem_x509_certificate(pem_responder_cert, default_backend())
315 >>> responder_key = serialization.load_pem_private_key(pem_responder_key, None, default_backend())
316 >>> builder = ocsp.OCSPResponseBuilder()
317 >>> # SHA1 is in this example because RFC 5019 mandates its use.
318 >>> builder = builder.add_response(
319 ... cert=cert, issuer=issuer, algorithm=hashes.SHA1(),
320 ... cert_status=ocsp.OCSPCertStatus.GOOD,
321 ... this_update=datetime.datetime.now(),
322 ... next_update=datetime.datetime.now(),
323 ... revocation_time=None, revocation_reason=None
324 ... ).responder_id(
325 ... ocsp.OCSPResponderEncoding.HASH, responder_cert
326 ... )
327 >>> response = builder.sign(responder_key, hashes.SHA256())
328 >>> response.certificate_status
329 <OCSPCertStatus.GOOD: 0>
330
331 .. classmethod:: build_unsuccessful(response_status)
332
333 Creates an unsigned OCSP response which can then be serialized and
334 sent to clients. ``build_unsuccessful`` may only be called with a
335 :class:`~cryptography.x509.ocsp.OCSPResponseStatus` that is not
336 ``SUCCESSFUL``. Since this is a class method note that no other
337 methods can or should be called as unsuccessful statuses do not
338 encode additional data.
339
340 :returns: A new :class:`~cryptography.x509.ocsp.OCSPResponse`.
341
342 .. doctest::
343
344 >>> from cryptography.hazmat.backends import default_backend
345 >>> from cryptography.hazmat.primitives import hashes, serialization
346 >>> from cryptography.x509 import load_pem_x509_certificate, ocsp
347 >>> response = ocsp.OCSPResponseBuilder.build_unsuccessful(
348 ... ocsp.OCSPResponseStatus.UNAUTHORIZED
349 ... )
350 >>> response.response_status
351 <OCSPResponseStatus.UNAUTHORIZED: 6>
352
353
Paul Kehrer732cf642018-08-15 18:04:28 -0500354Interfaces
355~~~~~~~~~~
356
357.. class:: OCSPRequest
358
359 .. versionadded:: 2.4
360
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400361 An ``OCSPRequest`` is an object containing information about a certificate
362 whose status is being checked.
Paul Kehrer732cf642018-08-15 18:04:28 -0500363
364 .. attribute:: issuer_key_hash
365
366 :type: bytes
367
368 The hash of the certificate issuer's key. The hash algorithm used
369 is defined by the ``hash_algorithm`` property.
370
371 .. attribute:: issuer_name_hash
372
373 :type: bytes
374
375 The hash of the certificate issuer's name. The hash algorithm used
376 is defined by the ``hash_algorithm`` property.
377
378 .. attribute:: hash_algorithm
379
Paul Kehreredfedc12018-09-14 18:24:20 -0400380 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer732cf642018-08-15 18:04:28 -0500381
382 The algorithm used to generate the ``issuer_key_hash`` and
383 ``issuer_name_hash``.
384
385 .. attribute:: serial_number
386
387 :type: int
388
389 The serial number of the certificate to check.
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400390
Paul Kehrer09403102018-09-09 21:57:21 -0500391 .. attribute:: extensions
392
393 :type: :class:`~cryptography.x509.Extensions`
394
395 The extensions encoded in the request.
396
Paul Kehrer0f629bb2018-08-31 10:47:56 -0400397 .. method:: public_bytes(encoding)
398
399 :param encoding: The encoding to use. Only
400 :attr:`~cryptography.hazmat.primitives.serialization.Encoding.DER`
401 is supported.
402
403 :return bytes: The serialized OCSP request.
Paul Kehrerd3601b12018-09-01 11:58:24 -0400404
405.. class:: OCSPResponse
406
407 .. versionadded:: 2.4
408
409 An ``OCSPResponse`` is the data provided by an OCSP responder in response
410 to an ``OCSPRequest``.
411
412 .. attribute:: response_status
413
414 :type: :class:`~cryptography.x509.ocsp.OCSPResponseStatus`
415
416 The status of the response.
417
418 .. attribute:: signature_algorithm_oid
419
420 :type: :class:`~cryptography.x509.ObjectIdentifier`
421
422 Returns the object identifier of the signature algorithm used
423 to sign the response. This will be one of the OIDs from
424 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
425
Paul Kehrer26c425d2018-09-01 16:58:26 -0400426 :raises ValueError: If ``response_status`` is not
427 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
428
Paul Kehrer60f264b2019-01-10 15:37:03 -0800429 .. attribute:: signature_hash_algorithm
430
431 .. versionadded:: 2.5
432
433 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
434
435 Returns the
436 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
437 was used in signing this response.
438
Paul Kehrerd3601b12018-09-01 11:58:24 -0400439 .. attribute:: signature
440
441 :type: bytes
442
443 The signature bytes.
444
Paul Kehrer26c425d2018-09-01 16:58:26 -0400445 :raises ValueError: If ``response_status`` is not
446 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
447
Paul Kehrerd3601b12018-09-01 11:58:24 -0400448 .. attribute:: tbs_response_bytes
449
450 :type: bytes
451
452 The DER encoded bytes payload that is hashed and then signed. This
453 data may be used to validate the signature on the OCSP response.
454
Paul Kehrer26c425d2018-09-01 16:58:26 -0400455 :raises ValueError: If ``response_status`` is not
456 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
457
Paul Kehrerd3601b12018-09-01 11:58:24 -0400458 .. attribute:: certificates
459
460 :type: list
461
462 A list of zero or more :class:`~cryptography.x509.Certificate` objects
463 used to help build a chain to verify the OCSP response. This situation
464 occurs when the OCSP responder uses a delegate certificate.
465
Paul Kehrer26c425d2018-09-01 16:58:26 -0400466 :raises ValueError: If ``response_status`` is not
467 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
468
Paul Kehrerd3601b12018-09-01 11:58:24 -0400469 .. attribute:: responder_key_hash
470
471 :type: bytes or None
472
473 The responder's key hash or ``None`` if the response has a
474 ``responder_name``.
475
Paul Kehrer26c425d2018-09-01 16:58:26 -0400476 :raises ValueError: If ``response_status`` is not
477 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
478
Paul Kehrerd3601b12018-09-01 11:58:24 -0400479 .. attribute:: responder_name
480
481 :type: :class:`~cryptography.x509.Name` or None
482
483 The responder's ``Name`` or ``None`` if the response has a
484 ``responder_key_hash``.
485
Paul Kehrer26c425d2018-09-01 16:58:26 -0400486 :raises ValueError: If ``response_status`` is not
487 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
488
Paul Kehrerd3601b12018-09-01 11:58:24 -0400489 .. attribute:: produced_at
490
491 :type: :class:`datetime.datetime`
492
493 A naïve datetime representing the time when the response was produced.
494
Paul Kehrer26c425d2018-09-01 16:58:26 -0400495 :raises ValueError: If ``response_status`` is not
496 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
497
Paul Kehrerd3601b12018-09-01 11:58:24 -0400498 .. attribute:: certificate_status
499
500 :type: :class:`~cryptography.x509.ocsp.OCSPCertStatus`
501
502 The status of the certificate being checked.
503
Paul Kehrer26c425d2018-09-01 16:58:26 -0400504 :raises ValueError: If ``response_status`` is not
505 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
506
Paul Kehrerd3601b12018-09-01 11:58:24 -0400507 .. attribute:: revocation_time
508
509 :type: :class:`datetime.datetime` or None
510
511 A naïve datetime representing the time when the certificate was revoked
512 or ``None`` if the certificate has not been revoked.
513
Paul Kehrer26c425d2018-09-01 16:58:26 -0400514 :raises ValueError: If ``response_status`` is not
515 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
516
Paul Kehrerd3601b12018-09-01 11:58:24 -0400517 .. attribute:: revocation_reason
518
519 :type: :class:`~cryptography.x509.ReasonFlags` or None
520
521 The reason the certificate was revoked or ``None`` if not specified or
522 not revoked.
523
Paul Kehrer26c425d2018-09-01 16:58:26 -0400524 :raises ValueError: If ``response_status`` is not
525 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
526
Paul Kehrerd3601b12018-09-01 11:58:24 -0400527 .. attribute:: this_update
528
529 :type: :class:`datetime.datetime`
530
531 A naïve datetime representing the most recent time at which the status
532 being indicated is known by the responder to have been correct.
533
Paul Kehrer26c425d2018-09-01 16:58:26 -0400534 :raises ValueError: If ``response_status`` is not
535 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
536
Paul Kehrerd3601b12018-09-01 11:58:24 -0400537 .. attribute:: next_update
538
539 :type: :class:`datetime.datetime`
540
541 A naïve datetime representing the time when newer information will
542 be available.
543
Paul Kehrer26c425d2018-09-01 16:58:26 -0400544 :raises ValueError: If ``response_status`` is not
545 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
546
Paul Kehrerd3601b12018-09-01 11:58:24 -0400547 .. attribute:: issuer_key_hash
548
549 :type: bytes
550
551 The hash of the certificate issuer's key. The hash algorithm used
552 is defined by the ``hash_algorithm`` property.
553
Paul Kehrer26c425d2018-09-01 16:58:26 -0400554 :raises ValueError: If ``response_status`` is not
555 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
556
Paul Kehrerd3601b12018-09-01 11:58:24 -0400557 .. attribute:: issuer_name_hash
558
559 :type: bytes
560
561 The hash of the certificate issuer's name. The hash algorithm used
562 is defined by the ``hash_algorithm`` property.
563
Paul Kehrer26c425d2018-09-01 16:58:26 -0400564 :raises ValueError: If ``response_status`` is not
565 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
566
Paul Kehrerd3601b12018-09-01 11:58:24 -0400567 .. attribute:: hash_algorithm
568
Paul Kehreredfedc12018-09-14 18:24:20 -0400569 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerd3601b12018-09-01 11:58:24 -0400570
571 The algorithm used to generate the ``issuer_key_hash`` and
572 ``issuer_name_hash``.
573
Paul Kehrer26c425d2018-09-01 16:58:26 -0400574 :raises ValueError: If ``response_status`` is not
575 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
576
Paul Kehrerd3601b12018-09-01 11:58:24 -0400577 .. attribute:: serial_number
578
579 :type: int
580
581 The serial number of the certificate that was checked.
582
Paul Kehrer26c425d2018-09-01 16:58:26 -0400583 :raises ValueError: If ``response_status`` is not
584 :class:`~cryptography.x509.ocsp.OCSPResponseStatus.SUCCESSFUL`.
585
Paul Kehrerb8db6682018-10-07 03:44:30 +0800586 .. attribute:: extensions
587
588 :type: :class:`~cryptography.x509.Extensions`
589
590 The extensions encoded in the response.
Paul Kehrerd3601b12018-09-01 11:58:24 -0400591
Paul Kehrer788b8592018-10-07 11:07:14 +0800592 .. method:: public_bytes(encoding)
593
594 :param encoding: The encoding to use. Only
595 :attr:`~cryptography.hazmat.primitives.serialization.Encoding.DER`
596 is supported.
597
598 :return bytes: The serialized OCSP response.
599
Paul Kehrerd3601b12018-09-01 11:58:24 -0400600.. class:: OCSPResponseStatus
601
602 .. versionadded:: 2.4
603
604 An enumeration of response statuses.
605
606 .. attribute:: SUCCESSFUL
607
608 Represents a successful OCSP response.
609
610 .. attribute:: MALFORMED_REQUEST
611
612 May be returned by an OCSP responder that is unable to parse a
613 given request.
614
615 .. attribute:: INTERNAL_ERROR
616
617 May be returned by an OCSP responder that is currently experiencing
618 operational problems.
619
620 .. attribute:: TRY_LATER
621
622 May be returned by an OCSP responder that is overloaded.
623
624 .. attribute:: SIG_REQUIRED
625
626 May be returned by an OCSP responder that requires signed OCSP
627 requests.
628
629 .. attribute:: UNAUTHORIZED
630
631 May be returned by an OCSP responder when queried for a certificate for
632 which the responder is unaware or an issuer for which the responder is
633 not authoritative.
634
635
636.. class:: OCSPCertStatus
637
638 .. versionadded:: 2.4
639
640 An enumeration of certificate statuses in an OCSP response.
641
642 .. attribute:: GOOD
643
644 The value for a certificate that is not revoked.
645
646 .. attribute:: REVOKED
647
648 The certificate being checked is revoked.
649
650 .. attribute:: UNKNOWN
651
652 The certificate being checked is not known to the OCSP responder.
Paul Kehrere617c5a2018-10-29 05:36:34 +0800653
654.. class:: OCSPResponderEncoding
655
656 .. versionadded:: 2.4
657
658 An enumeration of ``responderID`` encodings that can be passed to
659 :meth:`~cryptography.x509.ocsp.OCSPResponseBuilder.responder_id`.
660
661 .. attribute:: HASH
662
663 Encode the hash of the public key whose corresponding private key
664 signed the response.
665
666 .. attribute:: NAME
667
668 Encode the X.509 ``Name`` of the certificate whose private key signed
669 the response.