Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 80f30a68

Přidáno uživatelem David Friesecký před téměř 4 roky(ů)

Re #8589 - Implemented get_root(unique_id) in CertificateService

Zobrazit rozdíly:

src/services/certificate_service.py
569 569
                                                                identity_name,
570 570
                                                                identity_passphrase, cot_pem_list, cert_key.password)
571 571

  
572
    def get_root(self, unique_id: int):
573
        """
574
        Function that calls CertificateService.get_chain_of_trust() and extract root CA from the returned chain.
575
        :param unique_id: ID of the certificate to which to find the root CA
576
        :return: Instance of the Certificate class containing a root certificate which was found in the chain
577
        """
578
        Logger.debug("Function launched.")
579

  
580
        chain_of_trust = self.get_chain_of_trust(from_id=unique_id, exclude_root=False)
581

  
582
        if len(chain_of_trust) == 0:
583
            Logger.error(f"No such certificate found 'ID = {unique_id}'.")
584
            raise CertificateNotFoundException(unique_id)
585

  
586
        root_ca = chain_of_trust[len(chain_of_trust) - 1]
587

  
588
        if root_ca.type_id != ROOT_CA_ID or root_ca.certificate_id != root_ca.parent_id:
589
            Logger.error(f"Certificate id '{root_ca.certificate_id}' has not same parent_id '{root_ca.parent_id} "
590
                         f"or type_id '{root_ca.type_id}' is not a ROOT_CA_ID '{ROOT_CA_ID}'")
591
            raise InvalidRootCA(root_ca.type_id, root_ca.certificate_id, root_ca.parent_id)
592

  
593
        return root_ca
594

  
572 595

  
573 596
class RevocationReasonInvalidException(Exception):
574 597
    """
......
638 661

  
639 662
    def __str__(self):
640 663
        return f"""Subject attribute "{self.attribute_name}" is invalid (reason: {self.reason})."""
664

  
665

  
666
class InvalidRootCA(Exception):
667
    """
668
    Exception that denotes that certificate has invalid root CA parameters.
669
    """
670

  
671
    def __init__(self, type_id, id, parent_id):
672
        self.type_id = type_id
673
        self.id = id
674
        self.parent_id = parent_id
675

  
676
    def __str__(self):
677
        return f"Certificate id '{self.id}' has not same parent_id '{self.parent_id} " \
678
               f"or type_id '{self.type_id}' is not a ROOT_CA_ID '{ROOT_CA_ID}'"

Také k dispozici: Unified diff