Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 313b647b

Přidáno uživatelem Stanislav Král před asi 4 roky(ů)

Re #8472 - Finished implementation of create_root_ca method in CertificateService

Zobrazit rozdíly:

src/services/certificate_service.py
1
from src.constants import ROOT_CA_ID
1 2
from src.dao.certificate_repository import CertificateRepository
2
from src.dao.private_key_repository import PrivateKeyRepository
3 3
from src.model.certificate import Certificate
4
from src.model.private_key import PrivateKey
4 5
from src.model.subject import Subject
5 6
from src.services.cryptography import CryptographyService
6 7

  
8
import time
9

  
10
DATE_FORMAT = "%d.%m.%Y %H:%M:%S"
11

  
7 12

  
8 13
class CertificateService:
9 14

  
......
12 17
        self.certificate_repository = certificate_repository
13 18

  
14 19
    # TODO key passphrase is not present in class diagram
15
    def create_root_ca(self, key: PrivateKeyRepository, subject: Subject, extensions: str, config: str,
16
                       key_passphrase: str):
17
        cert_pem = self.cryptography_service.create_sscrt(subject, key, key_pass=key_passphrase, extensions=extensions,
18
                                                      config=config)
20
    def create_root_ca(self, key: PrivateKey, subject: Subject, extensions: str = "", config: str = ""):
21
        # create a new self signed  certificate
22
        cert_pem = self.cryptography_service.create_sscrt(subject, key.private_key, key_pass=key.password,
23
                                                          extensions=extensions, config=config)
24

  
25
        # parse the generated pem for subject and notBefore/notAfter fields
26
        subj, not_before, not_after = self.cryptography_service.parse_cert_pem(cert_pem)
27

  
28
        # format the parsed date
29
        not_before_formatted = time.strftime(DATE_FORMAT, not_before)
30
        not_after_formatted = time.strftime(DATE_FORMAT, not_after)
31

  
32
        # create a certificate wrapper
33
        certificate = Certificate(-1, subject.common_name, not_before_formatted, not_after_formatted, cert_pem,
34
                                  key.private_key_id, ROOT_CA_ID, 0, {})
35

  
36
        # store the wrapper into the repository
37
        created_id = self.certificate_repository.create(certificate)
38

  
39
        # assign the generated ID to the inserted certificate
40
        certificate.certificate_id = created_id
19 41

  
20
        certificate = Certificate(-1, subject.common_name, subject)
42
        return certificate

Také k dispozici: Unified diff