1
|
from flask import Response
|
2
|
from injector import inject
|
3
|
|
4
|
from src.exceptions.certificate_not_found_exception import CertificateNotFoundException
|
5
|
from src.exceptions.private_key_not_found_exception import PrivateKeyNotFoundException
|
6
|
from src.services.crl.crl_service import CrlService
|
7
|
from src.controllers.return_codes import *
|
8
|
|
9
|
E_WRONG_PARAMETERS = {"success": False, "data": "Invalid request, wrong parameters."}
|
10
|
E_NO_CERTIFICATES_FOUND = {"success": False, "data": "No such certificate found."}
|
11
|
|
12
|
|
13
|
class CrlOcspController:
|
14
|
|
15
|
@inject
|
16
|
def __init__(self, crl_service: CrlService):
|
17
|
self.crl_service = crl_service
|
18
|
|
19
|
def get_crl(self, ca_id: str):
|
20
|
"""
|
21
|
Generate and download a CRL for a selected certificate authority
|
22
|
:param ca_id: certificate authority whose CRL is requested
|
23
|
:return: download response / error
|
24
|
"""
|
25
|
# convert id from string to int
|
26
|
try:
|
27
|
identifier = int(ca_id)
|
28
|
except ValueError:
|
29
|
return E_WRONG_PARAMETERS, C_BAD_REQUEST
|
30
|
|
31
|
# generate the CRL
|
32
|
try:
|
33
|
crl = self.crl_service.generate_crl_response(identifier)
|
34
|
except (CertificateNotFoundException, PrivateKeyNotFoundException):
|
35
|
return E_NO_CERTIFICATES_FOUND, C_NOT_FOUND
|
36
|
|
37
|
return Response(crl, mimetype="application/x-x509-ca-cert",
|
38
|
headers={"Content-Disposition": f"attachment;filename={ca_id}_crl.pem"})
|