Revize 1de95cdf
Přidáno uživatelem Michal Seják před téměř 4 roky(ů)
src/controllers/crl_ocsp_controller.py | ||
---|---|---|
1 | 1 |
from flask import Response |
2 | 2 |
from injector import inject |
3 |
import base64 |
|
3 | 4 |
|
4 | 5 |
from src.exceptions.certificate_not_found_exception import CertificateNotFoundException |
5 | 6 |
from src.exceptions.private_key_not_found_exception import PrivateKeyNotFoundException |
... | ... | |
36 | 37 |
|
37 | 38 |
return Response(crl, mimetype="application/x-x509-ca-cert", |
38 | 39 |
headers={"Content-Disposition": f"attachment;filename={ca_id}_crl.pem"}) |
40 |
|
|
41 |
def get_ocsp_from_base64(self, ca_id, base64_der_ocsp_request): |
|
42 |
""" |
|
43 |
Generate an OCSP Response for a base-64 encoded DER encoded OCSP Request. |
|
44 |
:param ca_id: certificate authority ID |
|
45 |
:param base64_der_ocsp_request: encoded request |
|
46 |
:return: DER OCSP response |
|
47 |
""" |
|
48 |
return self.get_ocsp_from_der(ca_id, base64.b64decode(base64_der_ocsp_request)) |
|
49 |
|
|
50 |
def get_ocsp_from_der(self, ca_id, der_ocsp_request): |
|
51 |
""" |
|
52 |
Generate an OCSP Response for a DER encoded OCSP Request. |
|
53 |
:param ca_id: certificate authority ID |
|
54 |
:param der_ocsp_request: encoded request |
|
55 |
:return: DER OCSP response |
|
56 |
""" |
|
57 |
if len(der_ocsp_request) == 0: |
|
58 |
return E_WRONG_PARAMETERS, C_BAD_REQUEST |
|
59 |
|
|
60 |
try: |
|
61 |
ca_id = int(ca_id) |
|
62 |
except ValueError: |
|
63 |
return E_WRONG_PARAMETERS, C_BAD_REQUEST |
|
64 |
|
|
65 |
try: |
|
66 |
ocsp_response = self.crl_service.generate_ocsp_response(ca_id, der_ocsp_request) |
|
67 |
except CertificateNotFoundException or PrivateKeyNotFoundException: |
|
68 |
return E_NO_CERTIFICATES_FOUND, C_NOT_FOUND |
|
69 |
|
|
70 |
return Response(ocsp_response, mimetype="application/ocsp-response") |
Také k dispozici: Unified diff
Re #8577 - Added handle methods for OCSP to the CrlOcspController.