當前位置: 首頁>>代碼示例>>Python>>正文


Python x509.ReasonFlags方法代碼示例

本文整理匯總了Python中cryptography.x509.ReasonFlags方法的典型用法代碼示例。如果您正苦於以下問題:Python x509.ReasonFlags方法的具體用法?Python x509.ReasonFlags怎麽用?Python x509.ReasonFlags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cryptography.x509的用法示例。


在下文中一共展示了x509.ReasonFlags方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_revocation

# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import ReasonFlags [as 別名]
def get_revocation(self):
        if self.revoked is False:
            raise ValueError('Certificate is not revoked.')

        revoked_cert = x509.RevokedCertificateBuilder().serial_number(
            self.x509.serial_number).revocation_date(self.revoked_date)

        reason = self.get_revocation_reason()
        if reason != x509.ReasonFlags.unspecified:
            # RFC 5270, 5.3.1: "reason code CRL entry extension SHOULD be absent instead of using the
            # unspecified (0) reasonCode value"
            revoked_cert = revoked_cert.add_extension(x509.CRLReason(reason), critical=False)

        compromised = self.get_compromised_time()
        if compromised:
            # RFC 5280, 5.3.2 says that this extension MUST be non-critical
            revoked_cert = revoked_cert.add_extension(x509.InvalidityDate(compromised), critical=False)

        return revoked_cert.build(default_backend()) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:21,代碼來源:models.py

示例2: __init__

# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import ReasonFlags [as 別名]
def __init__(self, data=None):
        if data is None:
            data = {}

        if isinstance(data, x509.DistributionPoint):
            self.full_name = _gnl_or_empty(data.full_name)
            self.relative_name = data.relative_name
            self.crl_issuer = _gnl_or_empty(data.crl_issuer)
            self.reasons = data.reasons
        elif isinstance(data, dict):
            self.full_name = _gnl_or_empty(data.get('full_name'))
            self.relative_name = data.get('relative_name')
            self.crl_issuer = _gnl_or_empty(data.get('crl_issuer'))
            self.reasons = data.get('reasons')

            if self.full_name is not None and self.relative_name is not None:
                raise ValueError('full_name and relative_name cannot both have a value')

            if self.relative_name is not None:
                self.relative_name = x509_relative_name(self.relative_name)
            if self.reasons is not None:
                self.reasons = frozenset([x509.ReasonFlags[r] for r in self.reasons])
        else:
            raise ValueError('data must be x509.DistributionPoint or dict') 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:26,代碼來源:extensions.py

示例3: get_revocation_reason

# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import ReasonFlags [as 別名]
def get_revocation_reason(self):
        """Get the revocation reason of this certificate."""
        if self.revoked is False:
            return

        return x509.ReasonFlags[self.revoked_reason] 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:8,代碼來源:models.py

示例4: revoke

# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import ReasonFlags [as 別名]
def revoke(self, reason='', compromised=None):
        if not reason:
            reason = ReasonFlags.unspecified

        pre_revoke_cert.send(sender=self.__class__, cert=self, reason=reason)

        self.revoked = True
        self.revoked_date = timezone.now()
        self.revoked_reason = reason.name
        self.compromised = compromised
        self.save()

        post_revoke_cert.send(sender=self.__class__, cert=self) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:15,代碼來源:models.py

示例5: test_get_revocation_reason

# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import ReasonFlags [as 別名]
def test_get_revocation_reason(self):
        cert = self.certs['child-cert']
        self.assertIsNone(cert.get_revocation_reason())

        for reason in ReasonFlags:
            cert.revoke(reason)
            got = cert.get_revocation_reason()
            self.assertIsInstance(got, x509.ReasonFlags)
            self.assertEqual(got.name, reason.name) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:11,代碼來源:tests_models.py

示例6: __init__

# 需要導入模塊: from cryptography import x509 [as 別名]
# 或者: from cryptography.x509 import ReasonFlags [as 別名]
def __init__(self, cert, issuer, algorithm, cert_status, this_update,
                 next_update, revocation_time, revocation_reason):
        if (
            not isinstance(cert, x509.Certificate) or
            not isinstance(issuer, x509.Certificate)
        ):
            raise TypeError("cert and issuer must be a Certificate")

        _verify_algorithm(algorithm)
        if not isinstance(this_update, datetime.datetime):
            raise TypeError("this_update must be a datetime object")
        if (
            next_update is not None and
            not isinstance(next_update, datetime.datetime)
        ):
            raise TypeError("next_update must be a datetime object or None")

        self._cert = cert
        self._issuer = issuer
        self._algorithm = algorithm
        self._this_update = this_update
        self._next_update = next_update

        if not isinstance(cert_status, OCSPCertStatus):
            raise TypeError(
                "cert_status must be an item from the OCSPCertStatus enum"
            )
        if cert_status is not OCSPCertStatus.REVOKED:
            if revocation_time is not None:
                raise ValueError(
                    "revocation_time can only be provided if the certificate "
                    "is revoked"
                )
            if revocation_reason is not None:
                raise ValueError(
                    "revocation_reason can only be provided if the certificate"
                    " is revoked"
                )
        else:
            if not isinstance(revocation_time, datetime.datetime):
                raise TypeError("revocation_time must be a datetime object")

            revocation_time = _convert_to_naive_utc_time(revocation_time)
            if revocation_time < _EARLIEST_UTC_TIME:
                raise ValueError('The revocation_time must be on or after'
                                 ' 1950 January 1.')

            if (
                revocation_reason is not None and
                not isinstance(revocation_reason, x509.ReasonFlags)
            ):
                raise TypeError(
                    "revocation_reason must be an item from the ReasonFlags "
                    "enum or None"
                )

        self._cert_status = cert_status
        self._revocation_time = revocation_time
        self._revocation_reason = revocation_reason 
開發者ID:tp4a,項目名稱:teleport,代碼行數:61,代碼來源:ocsp.py


注:本文中的cryptography.x509.ReasonFlags方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。