Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b1fa358f

Přidáno uživatelem Jan Pašek před téměř 4 roky(ů)

Re #8576 - implemented CRL endpoint

Zobrazit rozdíly:

app.py
7 7
from src.config import configuration
8 8
from src.config.connection_provider import ConnectionProvider
9 9
from src.controllers.certificates_controller import CertController
10
from src.controllers.crl_ocsp_controller import CrlOcspController
10 11
from src.services.cryptography import CryptographyService, CryptographyException
11 12

  
12 13
app = Flask(__name__)
......
67 68
    return certificate_controller.get_public_key_of_a_certificate(id)
68 69

  
69 70

  
71
@app.route('/api/crl/<id>', methods=["GET"])
72
def get_crl_of_issuer(id, crl_ocsp_controller: CrlOcspController):
73
    return crl_ocsp_controller.get_crl(id)
74

  
75

  
70 76
def initialize_app(application) -> bool:
71 77
    """
72 78
    Initializes the application
src/controllers/crl_ocsp_controller.py
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"})

Také k dispozici: Unified diff