当前位置: 首页>>代码示例>>Python>>正文


Python x509.UnrecognizedExtension方法代码示例

本文整理汇总了Python中cryptography.x509.UnrecognizedExtension方法的典型用法代码示例。如果您正苦于以下问题:Python x509.UnrecognizedExtension方法的具体用法?Python x509.UnrecognizedExtension怎么用?Python x509.UnrecognizedExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cryptography.x509的用法示例。


在下文中一共展示了x509.UnrecognizedExtension方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: precertificate_signed_certificate_timestamps

# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UnrecognizedExtension [as 别名]
def precertificate_signed_certificate_timestamps(self):
        try:
            ext = self.x509.extensions.get_extension_for_oid(
                ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS)
        except x509.ExtensionNotFound:
            return None

        if isinstance(ext.value, x509.UnrecognizedExtension):
            # Older versions of OpenSSL (and LibreSSL) cannot parse this extension
            # see https://github.com/pyca/cryptography/blob/master/tests/x509/test_x509_ext.py#L4455-L4459
            return UnrecognizedExtension(
                ext,
                name=get_extension_name(ext),
                error='Requires OpenSSL 1.1.0f or later')
        else:  # pragma: only SCT
            return PrecertificateSignedCertificateTimestamps(ext) 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:18,代码来源:models.py

示例2: output_template

# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UnrecognizedExtension [as 别名]
def output_template(self, obj, key):
        extension = getattr(obj, key)
        templates = ['django_ca/admin/extensions/%s.html' % key]

        if isinstance(extension, NullExtension):
            templates.append('django_ca/admin/extensions/base/null_extension.html')
        if isinstance(extension, AlternativeNameExtension):
            templates.append('django_ca/admin/extensions/base/alternative_name_extension.html')
        if isinstance(extension, CRLDistributionPointsBase):
            templates.append('django_ca/admin/extensions/base/crl_distribution_points_base.html')
        if isinstance(extension, OrderedSetExtension):
            templates.append('django_ca/admin/extensions/base/ordered_set_extension.html')
        if isinstance(extension, UnrecognizedExtension) or isinstance(extension, x509.UnrecognizedExtension):
            templates.append('django_ca/admin/extensions/base/unrecognized_extension.html')
        else:
            templates.append('django_ca/admin/extensions/base/base.html')
        return render_to_string(templates, {'obj': obj, 'extension': extension}) 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:19,代码来源:admin.py

示例3: _create_x509_extension

# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UnrecognizedExtension [as 别名]
def _create_x509_extension(self, handlers, extension):
        if isinstance(extension.value, x509.UnrecognizedExtension):
            obj = _txt2obj_gc(self, extension.oid.dotted_string)
            value = _encode_asn1_str_gc(
                self, extension.value.value, len(extension.value.value)
            )
            return self._lib.X509_EXTENSION_create_by_OBJ(
                self._ffi.NULL,
                obj,
                1 if extension.critical else 0,
                value
            )
        else:
            try:
                encode = handlers[extension.oid]
            except KeyError:
                raise NotImplementedError(
                    'Extension not supported: {0}'.format(extension.oid)
                )

            ext_struct = encode(self, extension.value)
            nid = self._lib.OBJ_txt2nid(
                extension.oid.dotted_string.encode("ascii")
            )
            backend.openssl_assert(nid != self._lib.NID_undef)
            return self._lib.X509V3_EXT_i2d(
                nid, 1 if extension.critical else 0, ext_struct
            ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:30,代码来源:backend.py

示例4: _create_x509_extension

# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UnrecognizedExtension [as 别名]
def _create_x509_extension(self, handlers, extension):
        if isinstance(extension.value, x509.UnrecognizedExtension):
            value = _encode_asn1_str_gc(
                self, extension.value.value, len(extension.value.value)
            )
            return self._create_raw_x509_extension(extension, value)
        elif isinstance(extension.value, x509.TLSFeature):
            asn1 = _Integers([x.value for x in extension.value]).dump()
            value = _encode_asn1_str_gc(self, asn1, len(asn1))
            return self._create_raw_x509_extension(extension, value)
        else:
            try:
                encode = handlers[extension.oid]
            except KeyError:
                raise NotImplementedError(
                    'Extension not supported: {0}'.format(extension.oid)
                )

            ext_struct = encode(self, extension.value)
            nid = self._lib.OBJ_txt2nid(
                extension.oid.dotted_string.encode("ascii")
            )
            backend.openssl_assert(nid != self._lib.NID_undef)
            return self._lib.X509V3_EXT_i2d(
                nid, 1 if extension.critical else 0, ext_struct
            ) 
开发者ID:tp4a,项目名称:teleport,代码行数:28,代码来源:backend.py

示例5: _create_x509_extension

# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UnrecognizedExtension [as 别名]
def _create_x509_extension(self, handlers, extension):
        if isinstance(extension.value, x509.UnrecognizedExtension):
            value = _encode_asn1_str_gc(self, extension.value.value)
            return self._create_raw_x509_extension(extension, value)
        elif isinstance(extension.value, x509.TLSFeature):
            asn1 = encode_der(
                SEQUENCE,
                *[
                    encode_der(INTEGER, encode_der_integer(x.value))
                    for x in extension.value
                ]
            )
            value = _encode_asn1_str_gc(self, asn1)
            return self._create_raw_x509_extension(extension, value)
        elif isinstance(extension.value, x509.PrecertPoison):
            value = _encode_asn1_str_gc(self, encode_der(NULL))
            return self._create_raw_x509_extension(extension, value)
        else:
            try:
                encode = handlers[extension.oid]
            except KeyError:
                raise NotImplementedError(
                    'Extension not supported: {}'.format(extension.oid)
                )

            ext_struct = encode(self, extension.value)
            nid = self._lib.OBJ_txt2nid(
                extension.oid.dotted_string.encode("ascii")
            )
            backend.openssl_assert(nid != self._lib.NID_undef)
            return self._lib.X509V3_EXT_i2d(
                nid, 1 if extension.critical else 0, ext_struct
            ) 
开发者ID:tp4a,项目名称:teleport,代码行数:35,代码来源:backend.py

示例6: _create_x509_extension

# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UnrecognizedExtension [as 别名]
def _create_x509_extension(self, handlers, extension):
        if isinstance(extension.value, x509.UnrecognizedExtension):
            value = _encode_asn1_str_gc(self, extension.value.value)
            return self._create_raw_x509_extension(extension, value)
        elif isinstance(extension.value, x509.TLSFeature):
            asn1 = _Integers([x.value for x in extension.value]).dump()
            value = _encode_asn1_str_gc(self, asn1)
            return self._create_raw_x509_extension(extension, value)
        elif isinstance(extension.value, x509.PrecertPoison):
            asn1 = asn1crypto.core.Null().dump()
            value = _encode_asn1_str_gc(self, asn1)
            return self._create_raw_x509_extension(extension, value)
        else:
            try:
                encode = handlers[extension.oid]
            except KeyError:
                raise NotImplementedError(
                    'Extension not supported: {}'.format(extension.oid)
                )

            ext_struct = encode(self, extension.value)
            nid = self._lib.OBJ_txt2nid(
                extension.oid.dotted_string.encode("ascii")
            )
            backend.openssl_assert(nid != self._lib.NID_undef)
            return self._lib.X509V3_EXT_i2d(
                nid, 1 if extension.critical else 0, ext_struct
            ) 
开发者ID:aws-quickstart,项目名称:quickstart-redhat-openshift,代码行数:30,代码来源:backend.py

示例7: parse

# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UnrecognizedExtension [as 别名]
def parse(self, backend, x509_obj):
        extensions = []
        seen_oids = set()
        for i in range(self.ext_count(backend, x509_obj)):
            ext = self.get_ext(backend, x509_obj, i)
            backend.openssl_assert(ext != backend._ffi.NULL)
            crit = backend._lib.X509_EXTENSION_get_critical(ext)
            critical = crit == 1
            oid = x509.ObjectIdentifier(
                _obj2txt(backend, backend._lib.X509_EXTENSION_get_object(ext))
            )
            if oid in seen_oids:
                raise x509.DuplicateExtension(
                    "Duplicate {0} extension found".format(oid), oid
                )
            try:
                handler = self.handlers[oid]
            except KeyError:
                if critical:
                    raise x509.UnsupportedExtension(
                        "Critical extension {0} is not currently supported"
                        .format(oid), oid
                    )
                else:
                    # Dump the DER payload into an UnrecognizedExtension object
                    data = backend._lib.X509_EXTENSION_get_data(ext)
                    backend.openssl_assert(data != backend._ffi.NULL)
                    der = backend._ffi.buffer(data.data, data.length)[:]
                    unrecognized = x509.UnrecognizedExtension(oid, der)
                    extensions.append(
                        x509.Extension(oid, critical, unrecognized)
                    )
            else:
                ext_data = backend._lib.X509V3_EXT_d2i(ext)
                if ext_data == backend._ffi.NULL:
                    backend._consume_errors()
                    raise ValueError(
                        "The {0} extension is invalid and can't be "
                        "parsed".format(oid)
                    )

                value = handler(backend, ext_data)
                extensions.append(x509.Extension(oid, critical, value))

            seen_oids.add(oid)

        return x509.Extensions(extensions) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:49,代码来源:decode_asn1.py

示例8: parse

# 需要导入模块: from cryptography import x509 [as 别名]
# 或者: from cryptography.x509 import UnrecognizedExtension [as 别名]
def parse(self, backend, x509_obj):
        extensions = []
        seen_oids = set()
        for i in range(self.ext_count(backend, x509_obj)):
            ext = self.get_ext(backend, x509_obj, i)
            backend.openssl_assert(ext != backend._ffi.NULL)
            crit = backend._lib.X509_EXTENSION_get_critical(ext)
            critical = crit == 1
            oid = x509.ObjectIdentifier(
                _obj2txt(backend, backend._lib.X509_EXTENSION_get_object(ext))
            )
            if oid in seen_oids:
                raise x509.DuplicateExtension(
                    "Duplicate {0} extension found".format(oid), oid
                )

            # This OID is only supported in OpenSSL 1.1.0+ but we want
            # to support it in all versions of OpenSSL so we decode it
            # ourselves.
            if oid == ExtensionOID.TLS_FEATURE:
                data = backend._lib.X509_EXTENSION_get_data(ext)
                parsed = _Integers.load(_asn1_string_to_bytes(backend, data))
                value = x509.TLSFeature(
                    [_TLS_FEATURE_TYPE_TO_ENUM[x.native] for x in parsed]
                )
                extensions.append(x509.Extension(oid, critical, value))
                seen_oids.add(oid)
                continue

            try:
                handler = self.handlers[oid]
            except KeyError:
                # Dump the DER payload into an UnrecognizedExtension object
                data = backend._lib.X509_EXTENSION_get_data(ext)
                backend.openssl_assert(data != backend._ffi.NULL)
                der = backend._ffi.buffer(data.data, data.length)[:]
                unrecognized = x509.UnrecognizedExtension(oid, der)
                extensions.append(
                    x509.Extension(oid, critical, unrecognized)
                )
            else:
                ext_data = backend._lib.X509V3_EXT_d2i(ext)
                if ext_data == backend._ffi.NULL:
                    backend._consume_errors()
                    raise ValueError(
                        "The {0} extension is invalid and can't be "
                        "parsed".format(oid)
                    )

                value = handler(backend, ext_data)
                extensions.append(x509.Extension(oid, critical, value))

            seen_oids.add(oid)

        return x509.Extensions(extensions) 
开发者ID:tp4a,项目名称:teleport,代码行数:57,代码来源:decode_asn1.py


注:本文中的cryptography.x509.UnrecognizedExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。