Пример #1
0
    def finalize_options(self):
        from cryptography.hazmat.bindings.commoncrypto.binding import Binding as CommonCryptoBinding
        from cryptography.hazmat.bindings.openssl.binding import Binding as OpenSSLBinding
        from cryptography.hazmat.primitives import constant_time, padding

        self.distribution.ext_modules = [
            OpenSSLBinding().ffi.verifier.get_extension(),
            constant_time._ffi.verifier.get_extension(),
            padding._ffi.verifier.get_extension(),
        ]
        if CommonCryptoBinding.is_available():
            self.distribution.ext_modules.append(CommonCryptoBinding().ffi.verifier.get_extension())

        build.finalize_options(self)
Пример #2
0
def _available_backends():
    global _available_backends_list

    if _available_backends_list is None:
        _available_backends_list = []

        if CommonCryptoBinding.is_available():
            from cryptography.hazmat.backends import commoncrypto
            _available_backends_list.append(commoncrypto.backend)

        if OpenSSLBinding.is_available():
            from cryptography.hazmat.backends import openssl
            _available_backends_list.append(openssl.backend)

    return _available_backends_list
Пример #3
0
def get_ext_modules():
    from cryptography.hazmat.bindings.commoncrypto.binding import (
        Binding as CommonCryptoBinding)
    from cryptography.hazmat.bindings.openssl.binding import (Binding as
                                                              OpenSSLBinding)
    from cryptography.hazmat.primitives import constant_time, padding

    ext_modules = [
        OpenSSLBinding().ffi.verifier.get_extension(),
        constant_time._ffi.verifier.get_extension(),
        padding._ffi.verifier.get_extension()
    ]
    if CommonCryptoBinding.is_available():
        ext_modules.append(CommonCryptoBinding().ffi.verifier.get_extension())
    return ext_modules
Пример #4
0
def _available_backends():
    global _available_backends_list

    if _available_backends_list is None:
        _available_backends_list = []

        if CommonCryptoBinding.is_available():
            from cryptography.hazmat.backends import commoncrypto
            _available_backends_list.append(commoncrypto.backend)

        if OpenSSLBinding.is_available():
            from cryptography.hazmat.backends import openssl
            _available_backends_list.append(openssl.backend)

    return _available_backends_list
Пример #5
0
def get_ext_modules():
    from cryptography.hazmat.bindings.commoncrypto.binding import (
        Binding as CommonCryptoBinding
    )
    from cryptography.hazmat.bindings.openssl.binding import (
        Binding as OpenSSLBinding
    )
    from cryptography.hazmat.primitives import constant_time, padding

    ext_modules = [
        OpenSSLBinding().ffi.verifier.get_extension(),
        constant_time._ffi.verifier.get_extension(),
        padding._ffi.verifier.get_extension()
    ]
    if CommonCryptoBinding.is_available():
        ext_modules.append(CommonCryptoBinding().ffi.verifier.get_extension())
    return ext_modules
Пример #6
0
    def finalize_options(self):
        from cryptography.hazmat.bindings.commoncrypto.binding import (
            Binding as CommonCryptoBinding)
        from cryptography.hazmat.bindings.openssl.binding import (
            Binding as OpenSSLBinding)
        from cryptography.hazmat.primitives import constant_time, padding

        self.distribution.ext_modules = [
            OpenSSLBinding().ffi.verifier.get_extension(),
            constant_time._ffi.verifier.get_extension(),
            padding._ffi.verifier.get_extension()
        ]
        if CommonCryptoBinding.is_available():
            self.distribution.ext_modules.append(
                CommonCryptoBinding().ffi.verifier.get_extension())

        build.finalize_options(self)
Пример #7
0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from cryptography.hazmat.backends import openssl
from cryptography.hazmat.bindings.commoncrypto.binding import (
    Binding as CCBinding
)

_ALL_BACKENDS = [openssl.backend]

if CCBinding.is_available():
    from cryptography.hazmat.backends import commoncrypto
    _ALL_BACKENDS.append(commoncrypto.backend)


def default_backend():
    return openssl.backend
Пример #8
0
from cryptography import utils
from cryptography.exceptions import UnsupportedAlgorithm, InternalError
from cryptography.hazmat.bindings.commoncrypto.binding import Binding
from cryptography.hazmat.primitives import interfaces
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.base import Cipher
from cryptography.hazmat.primitives.ciphers.modes import CBC, GCM


@utils.register_interface(interfaces.CipherAlgorithm)
class DummyCipher(object):
    name = "dummy-cipher"
    block_size = 128


@pytest.mark.skipif(not Binding.is_available(),
                    reason="CommonCrypto not available")
class TestCommonCrypto(object):
    def test_supports_cipher(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
        assert backend.cipher_supported(None, None) is False

    def test_register_duplicate_cipher_adapter(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
        with pytest.raises(ValueError):
            backend._register_cipher_adapter(
                AES, backend._lib.kCCAlgorithmAES128,
                CBC, backend._lib.kCCModeCBC
            )

    def test_handle_response(self):
Пример #9
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from cryptography.hazmat.backends import openssl
from cryptography.hazmat.backends.multibackend import MultiBackend
from cryptography.hazmat.bindings.commoncrypto.binding import (
    Binding as CommonCryptoBinding)

_ALL_BACKENDS = []

if CommonCryptoBinding.is_available():
    from cryptography.hazmat.backends import commoncrypto
    _ALL_BACKENDS.append(commoncrypto.backend)

_ALL_BACKENDS.append(openssl.backend)

_default_backend = MultiBackend(_ALL_BACKENDS)


def default_backend():
    return _default_backend
Пример #10
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from cryptography.hazmat.backends import openssl
from cryptography.hazmat.backends.multibackend import MultiBackend
from cryptography.hazmat.bindings.commoncrypto.binding import (
    Binding as CommonCryptoBinding
)

_ALL_BACKENDS = [openssl.backend]

if CommonCryptoBinding.is_available():
    from cryptography.hazmat.backends import commoncrypto
    _ALL_BACKENDS.append(commoncrypto.backend)


_default_backend = MultiBackend(_ALL_BACKENDS)


def default_backend():
    return _default_backend
Пример #11
0
from cryptography.hazmat.bindings.commoncrypto.binding import Binding
from cryptography.hazmat.primitives import interfaces
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.base import Cipher
from cryptography.hazmat.primitives.ciphers.modes import CBC, GCM

from ...utils import raises_unsupported_algorithm


@utils.register_interface(interfaces.CipherAlgorithm)
class DummyCipher(object):
    name = "dummy-cipher"
    block_size = 128


@pytest.mark.skipif(not Binding.is_available(),
                    reason="CommonCrypto not available")
class TestCommonCrypto(object):
    def test_supports_cipher(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
        assert backend.cipher_supported(None, None) is False

    def test_register_duplicate_cipher_adapter(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
        with pytest.raises(ValueError):
            backend._register_cipher_adapter(
                AES, backend._lib.kCCAlgorithmAES128,
                CBC, backend._lib.kCCModeCBC
            )

    def test_handle_response(self):