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


Python exceptions.UnsupportedAlgorithm方法代码示例

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


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

示例1: __init__

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def __init__(self, backend, algorithm, ctx=None):
        self._algorithm = algorithm
        self._backend = backend

        if ctx is None:
            try:
                methods = self._backend._hash_mapping[self.algorithm.name]
            except KeyError:
                raise UnsupportedAlgorithm(
                    "{0} is not a supported hash on this backend.".format(
                        algorithm.name),
                    _Reasons.UNSUPPORTED_HASH
                )
            ctx = self._backend._ffi.new(methods.ctx)
            res = methods.hash_init(ctx)
            assert res == 1

        self._ctx = ctx 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:20,代码来源:hashes.py

示例2: _elliptic_curve_to_nid

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def _elliptic_curve_to_nid(self, curve):
        """
        Get the NID for a curve name.
        """

        curve_aliases = {
            "secp192r1": "prime192v1",
            "secp256r1": "prime256v1"
        }

        curve_name = curve_aliases.get(curve.name, curve.name)

        curve_nid = self._lib.OBJ_sn2nid(curve_name.encode())
        if curve_nid == self._lib.NID_undef:
            raise UnsupportedAlgorithm(
                "{0} is not a supported elliptic curve".format(curve.name),
                _Reasons.UNSUPPORTED_ELLIPTIC_CURVE
            )
        return curve_nid 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:21,代码来源:backend.py

示例3: test_checkBad_KEX_INIT_CurveName

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def test_checkBad_KEX_INIT_CurveName(self):
        """
        Test that if the server received a bad name for a curve
        we raise an UnsupportedAlgorithm error.
        """
        kexmsg = (
            b"\xAA" * 16 +
            common.NS(b'ecdh-sha2-nistp256') +
            common.NS(b'ssh-rsa') +
            common.NS(b'aes256-ctr') +
            common.NS(b'aes256-ctr') +
            common.NS(b'hmac-sha1') +
            common.NS(b'hmac-sha1') +
            common.NS(b'none') +
            common.NS(b'none') +
            common.NS(b'') +
            common.NS(b'') +
            b'\x00' + b'\x00\x00\x00\x00')

        self.proto.ssh_KEXINIT(kexmsg)
        self.assertRaises(AttributeError)
        self.assertRaises(UnsupportedAlgorithm) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_transport.py

示例4: _getSupportedCiphers

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def _getSupportedCiphers():
    """
    Build a list of ciphers that are supported by the backend in use.

    @return: a list of supported ciphers.
    @rtype: L{list} of L{str}
    """
    supportedCiphers = []
    cs = [b'aes256-ctr', b'aes256-cbc', b'aes192-ctr', b'aes192-cbc',
          b'aes128-ctr', b'aes128-cbc', b'cast128-ctr', b'cast128-cbc',
          b'blowfish-ctr', b'blowfish-cbc', b'3des-ctr', b'3des-cbc']
    for cipher in cs:
        algorithmClass, keySize, modeClass = SSHCiphers.cipherMap[cipher]
        try:
            Cipher(
                algorithmClass(b' ' * keySize),
                modeClass(b' ' * (algorithmClass.block_size // 8)),
                backend=default_backend(),
            ).encryptor()
        except UnsupportedAlgorithm:
            pass
        else:
            supportedCiphers.append(cipher)
    return supportedCiphers 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:transport.py

示例5: __init__

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def __init__(self, backend, algorithm, ctx=None):
        self._algorithm = algorithm

        self._backend = backend

        if ctx is None:
            ctx = self._backend._lib.Cryptography_EVP_MD_CTX_new()
            ctx = self._backend._ffi.gc(
                ctx, self._backend._lib.Cryptography_EVP_MD_CTX_free
            )
            name = self._backend._build_openssl_digest_name(algorithm)
            evp_md = self._backend._lib.EVP_get_digestbyname(name)
            if evp_md == self._backend._ffi.NULL:
                raise UnsupportedAlgorithm(
                    "{0} is not a supported hash on this backend.".format(
                        name),
                    _Reasons.UNSUPPORTED_HASH
                )
            res = self._backend._lib.EVP_DigestInit_ex(ctx, evp_md,
                                                       self._backend._ffi.NULL)
            self._backend.openssl_assert(res != 0)

        self._ctx = ctx 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:hashes.py

示例6: test_sign_cert_invalid_algorithm

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def test_sign_cert_invalid_algorithm(self):
        self.assertRaises(
            crypto_exceptions.UnsupportedAlgorithm,
            self.cert_generator.sign_cert,
            csr=self.certificate_signing_request,
            validity=2 * 365 * 24 * 60 * 60,
            ca_cert=self.ca_certificate,
            ca_key=self.ca_private_key,
            ca_key_pass=self.ca_private_key_passphrase,
            ca_digest='not_an_algorithm'
        ) 
开发者ID:openstack,项目名称:octavia,代码行数:13,代码来源:test_local.py

示例7: clean_key

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def clean_key(self):
        """
        Checks if the submitted key data:

        - isn't larger than 100kb
        - is a valid SSH public key (e.g. dismissing if it's a private key)
        - does not match any of the :attr:`valid key data prefixes
          <~atmo.keys.models.SSHKey.VALID_PREFIXES>`
        - already exists in the database
        """
        key = self.cleaned_data["key"].strip()
        if len(key) > 100_000:
            raise ValidationError(
                "The submitted key was larger than 100kB, "
                "please submit a smaller one"
            )

        try:
            load_ssh_public_key(key.encode("utf-8"), backend=default_backend())
        except ValueError:
            raise ValidationError("The submitted key is invalid or misformatted.")
        except UnsupportedAlgorithm:
            raise ValidationError(
                "The submitted key is not supported. It should start with "
                "one of the following prefixes: %s." % ", ".join(SSHKey.VALID_PREFIXES)
            )
        fingerprint = calculate_fingerprint(key)
        if self.created_by.created_sshkeys.filter(fingerprint=fingerprint).exists():
            raise ValidationError(
                "There is already a SSH key with the fingerprint %s. "
                "Please try a different one or use the one already uploaded."
                % fingerprint
            )
        return key 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:36,代码来源:forms.py

示例8: signature_hash_algorithm

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def signature_hash_algorithm(self):
        oid = _obj2txt(self._backend, self._x509.sig_alg.algorithm)
        try:
            return x509._SIG_OIDS_TO_HASH[oid]
        except KeyError:
            raise UnsupportedAlgorithm(
                "Signature algorithm OID:{0} not recognized".format(oid)
            ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:10,代码来源:x509.py

示例9: derive_pbkdf2_hmac

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,
                           key_material):
        buf = self._ffi.new("char[]", length)
        if self._lib.Cryptography_HAS_PBKDF2_HMAC:
            evp_md = self._lib.EVP_get_digestbyname(
                algorithm.name.encode("ascii"))
            self.openssl_assert(evp_md != self._ffi.NULL)
            res = self._lib.PKCS5_PBKDF2_HMAC(
                key_material,
                len(key_material),
                salt,
                len(salt),
                iterations,
                evp_md,
                length,
                buf
            )
            self.openssl_assert(res == 1)
        else:
            if not isinstance(algorithm, hashes.SHA1):
                raise UnsupportedAlgorithm(
                    "This version of OpenSSL only supports PBKDF2HMAC with "
                    "SHA1.",
                    _Reasons.UNSUPPORTED_HASH
                )
            res = self._lib.PKCS5_PBKDF2_HMAC_SHA1(
                key_material,
                len(key_material),
                salt,
                len(salt),
                iterations,
                length,
                buf
            )
            self.openssl_assert(res == 1)

        return self._ffi.buffer(buf)[:] 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:39,代码来源:backend.py

示例10: _evp_pkey_to_public_key

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def _evp_pkey_to_public_key(self, evp_pkey):
        """
        Return the appropriate type of PublicKey given an evp_pkey cdata
        pointer.
        """

        key_type = evp_pkey.type

        if key_type == self._lib.EVP_PKEY_RSA:
            rsa_cdata = self._lib.EVP_PKEY_get1_RSA(evp_pkey)
            self.openssl_assert(rsa_cdata != self._ffi.NULL)
            rsa_cdata = self._ffi.gc(rsa_cdata, self._lib.RSA_free)
            return _RSAPublicKey(self, rsa_cdata, evp_pkey)
        elif key_type == self._lib.EVP_PKEY_DSA:
            dsa_cdata = self._lib.EVP_PKEY_get1_DSA(evp_pkey)
            self.openssl_assert(dsa_cdata != self._ffi.NULL)
            dsa_cdata = self._ffi.gc(dsa_cdata, self._lib.DSA_free)
            return _DSAPublicKey(self, dsa_cdata, evp_pkey)
        elif (self._lib.Cryptography_HAS_EC == 1 and
              key_type == self._lib.EVP_PKEY_EC):
            ec_cdata = self._lib.EVP_PKEY_get1_EC_KEY(evp_pkey)
            self.openssl_assert(ec_cdata != self._ffi.NULL)
            ec_cdata = self._ffi.gc(ec_cdata, self._lib.EC_KEY_free)
            return _EllipticCurvePublicKey(self, ec_cdata, evp_pkey)
        else:
            raise UnsupportedAlgorithm("Unsupported key type.") 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:28,代码来源:backend.py

示例11: elliptic_curve_supported

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def elliptic_curve_supported(self, curve):
        if self._lib.Cryptography_HAS_EC != 1:
            return False

        try:
            curve_nid = self._elliptic_curve_to_nid(curve)
        except UnsupportedAlgorithm:
            curve_nid = self._lib.NID_undef

        ctx = self._lib.EC_GROUP_new_by_curve_name(curve_nid)

        if ctx == self._ffi.NULL:
            errors = self._consume_errors()
            self.openssl_assert(
                curve_nid == self._lib.NID_undef or
                errors[0][1:] == (
                    self._lib.ERR_LIB_EC,
                    self._lib.EC_F_EC_GROUP_NEW_BY_CURVE_NAME,
                    self._lib.EC_R_UNKNOWN_GROUP
                )
            )
            return False
        else:
            self.openssl_assert(curve_nid != self._lib.NID_undef)
            self._lib.EC_GROUP_free(ctx)
            return True 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:28,代码来源:backend.py

示例12: generate_elliptic_curve_private_key

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def generate_elliptic_curve_private_key(self, curve):
        """
        Generate a new private key on the named curve.
        """

        if self.elliptic_curve_supported(curve):
            curve_nid = self._elliptic_curve_to_nid(curve)

            ec_cdata = self._lib.EC_KEY_new_by_curve_name(curve_nid)
            self.openssl_assert(ec_cdata != self._ffi.NULL)
            ec_cdata = self._ffi.gc(ec_cdata, self._lib.EC_KEY_free)

            res = self._lib.EC_KEY_generate_key(ec_cdata)
            self.openssl_assert(res == 1)

            res = self._lib.EC_KEY_check_key(ec_cdata)
            self.openssl_assert(res == 1)

            evp_pkey = self._ec_cdata_to_evp_pkey(ec_cdata)

            return _EllipticCurvePrivateKey(self, ec_cdata, evp_pkey)
        else:
            raise UnsupportedAlgorithm(
                "Backend object does not support {0}.".format(curve.name),
                _Reasons.UNSUPPORTED_ELLIPTIC_CURVE
            ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:28,代码来源:backend.py

示例13: create_symmetric_encryption_ctx

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def create_symmetric_encryption_ctx(self, cipher, mode):
        for b in self._filtered_backends(CipherBackend):
            try:
                return b.create_symmetric_encryption_ctx(cipher, mode)
            except UnsupportedAlgorithm:
                pass
        raise UnsupportedAlgorithm(
            "cipher {0} in {1} mode is not supported by this backend.".format(
                cipher.name, mode.name if mode else mode),
            _Reasons.UNSUPPORTED_CIPHER
        ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:13,代码来源:multibackend.py

示例14: create_symmetric_decryption_ctx

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def create_symmetric_decryption_ctx(self, cipher, mode):
        for b in self._filtered_backends(CipherBackend):
            try:
                return b.create_symmetric_decryption_ctx(cipher, mode)
            except UnsupportedAlgorithm:
                pass
        raise UnsupportedAlgorithm(
            "cipher {0} in {1} mode is not supported by this backend.".format(
                cipher.name, mode.name if mode else mode),
            _Reasons.UNSUPPORTED_CIPHER
        ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:13,代码来源:multibackend.py

示例15: create_hash_ctx

# 需要导入模块: from cryptography import exceptions [as 别名]
# 或者: from cryptography.exceptions import UnsupportedAlgorithm [as 别名]
def create_hash_ctx(self, algorithm):
        for b in self._filtered_backends(HashBackend):
            try:
                return b.create_hash_ctx(algorithm)
            except UnsupportedAlgorithm:
                pass
        raise UnsupportedAlgorithm(
            "{0} is not a supported hash on this backend.".format(
                algorithm.name),
            _Reasons.UNSUPPORTED_HASH
        ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:13,代码来源:multibackend.py


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