aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErik Trauschke <erik.trauschke@gmail.com>2015-09-28 08:54:47 -0700
committerErik Trauschke <erik.trauschke@gmail.com>2015-09-28 08:54:47 -0700
commitcc599440a393d6310e79494dab1461738eeede88 (patch)
tree7bd7889794be2296802d6fd77ab2835013536df3 /src
parente064f0236cd1a93a7ad434ea8dccb5b476dda90e (diff)
parenta94f97ee8b32d35fc7ed02849a807fab58147dc5 (diff)
downloadcryptography-cc599440a393d6310e79494dab1461738eeede88.tar.gz
cryptography-cc599440a393d6310e79494dab1461738eeede88.tar.bz2
cryptography-cc599440a393d6310e79494dab1461738eeede88.zip
Merge branch 'master' into crl_ossl_backend
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/exceptions.py4
-rw-r--r--src/cryptography/hazmat/backends/commoncrypto/backend.py3
-rw-r--r--src/cryptography/hazmat/backends/openssl/backend.py17
-rw-r--r--src/cryptography/hazmat/backends/openssl/ciphers.py30
-rw-r--r--src/cryptography/hazmat/bindings/commoncrypto/binding.py3
-rw-r--r--src/cryptography/hazmat/bindings/openssl/binding.py9
6 files changed, 22 insertions, 44 deletions
diff --git a/src/cryptography/exceptions.py b/src/cryptography/exceptions.py
index a4292eb8..29be22be 100644
--- a/src/cryptography/exceptions.py
+++ b/src/cryptography/exceptions.py
@@ -49,7 +49,9 @@ class InvalidSignature(Exception):
class InternalError(Exception):
- pass
+ def __init__(self, msg, err_code):
+ super(InternalError, self).__init__(msg)
+ self.err_code = err_code
class InvalidKey(Exception):
diff --git a/src/cryptography/hazmat/backends/commoncrypto/backend.py b/src/cryptography/hazmat/backends/commoncrypto/backend.py
index 091fbb7c..315d67d8 100644
--- a/src/cryptography/hazmat/backends/commoncrypto/backend.py
+++ b/src/cryptography/hazmat/backends/commoncrypto/backend.py
@@ -227,7 +227,8 @@ class Backend(object):
else:
raise InternalError(
"The backend returned an unknown error, consider filing a bug."
- " Code: {0}.".format(response)
+ " Code: {0}.".format(response),
+ response
)
def _release_cipher_ctx(self, ctx):
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
index c4cac1a6..b45c8986 100644
--- a/src/cryptography/hazmat/backends/openssl/backend.py
+++ b/src/cryptography/hazmat/backends/openssl/backend.py
@@ -15,9 +15,7 @@ import idna
import six
from cryptography import utils, x509
-from cryptography.exceptions import (
- InternalError, UnsupportedAlgorithm, _Reasons
-)
+from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
from cryptography.hazmat.backends.interfaces import (
CMACBackend, CipherBackend, DERSerializationBackend, DSABackend,
EllipticCurveBackend, HMACBackend, HashBackend, PBKDF2HMACBackend,
@@ -738,22 +736,9 @@ class Backend(object):
return self._ffi.buffer(buf)[:]
- def _err_string(self, code):
- err_buf = self._ffi.new("char[]", 256)
- self._lib.ERR_error_string_n(code, err_buf, 256)
- return self._ffi.string(err_buf, 256)[:]
-
def _consume_errors(self):
return binding._consume_errors(self._lib)
- def _unknown_error(self, error):
- return InternalError(
- "Unknown error code {0} from OpenSSL, "
- "you should probably file a bug. {1}.".format(
- error.code, self._err_string(error.code)
- )
- )
-
def _bn_to_int(self, bn):
assert bn != self._ffi.NULL
if six.PY3:
diff --git a/src/cryptography/hazmat/backends/openssl/ciphers.py b/src/cryptography/hazmat/backends/openssl/ciphers.py
index 4c1c7bc9..a80708aa 100644
--- a/src/cryptography/hazmat/backends/openssl/ciphers.py
+++ b/src/cryptography/hazmat/backends/openssl/ciphers.py
@@ -136,23 +136,21 @@ class _CipherContext(object):
if not errors and isinstance(self._mode, modes.GCM):
raise InvalidTag
- assert errors
-
- if errors[0][1:] == (
- self._backend._lib.ERR_LIB_EVP,
- self._backend._lib.EVP_F_EVP_ENCRYPTFINAL_EX,
- self._backend._lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH
- ) or errors[0][1:] == (
- self._backend._lib.ERR_LIB_EVP,
- self._backend._lib.EVP_F_EVP_DECRYPTFINAL_EX,
- self._backend._lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH
- ):
- raise ValueError(
- "The length of the provided data is not a multiple of "
- "the block length."
+ self._backend.openssl_assert(
+ errors[0][1:] == (
+ self._backend._lib.ERR_LIB_EVP,
+ self._backend._lib.EVP_F_EVP_ENCRYPTFINAL_EX,
+ self._backend._lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH
+ ) or errors[0][1:] == (
+ self._backend._lib.ERR_LIB_EVP,
+ self._backend._lib.EVP_F_EVP_DECRYPTFINAL_EX,
+ self._backend._lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH
)
- else:
- raise self._backend._unknown_error(errors[0])
+ )
+ raise ValueError(
+ "The length of the provided data is not a multiple of "
+ "the block length."
+ )
if (isinstance(self._mode, modes.GCM) and
self._operation == self._ENCRYPT):
diff --git a/src/cryptography/hazmat/bindings/commoncrypto/binding.py b/src/cryptography/hazmat/bindings/commoncrypto/binding.py
index 1695c041..dfe046b5 100644
--- a/src/cryptography/hazmat/bindings/commoncrypto/binding.py
+++ b/src/cryptography/hazmat/bindings/commoncrypto/binding.py
@@ -13,6 +13,3 @@ class Binding(object):
"""
lib = lib
ffi = ffi
-
- def __init__(self):
- pass
diff --git a/src/cryptography/hazmat/bindings/openssl/binding.py b/src/cryptography/hazmat/bindings/openssl/binding.py
index a5635f7d..47b1d6e2 100644
--- a/src/cryptography/hazmat/bindings/openssl/binding.py
+++ b/src/cryptography/hazmat/bindings/openssl/binding.py
@@ -9,6 +9,7 @@ import os
import threading
import types
+from cryptography.exceptions import InternalError
from cryptography.hazmat.bindings._openssl import ffi, lib
from cryptography.hazmat.bindings.openssl._conditional import CONDITIONAL_NAMES
@@ -17,12 +18,6 @@ _OpenSSLError = collections.namedtuple("_OpenSSLError",
["code", "lib", "func", "reason"])
-class UnhandledOpenSSLError(Exception):
- def __init__(self, msg, errors):
- super(UnhandledOpenSSLError, self).__init__(msg)
- self.errors = errors
-
-
def _consume_errors(lib):
errors = []
while True:
@@ -41,7 +36,7 @@ def _consume_errors(lib):
def _openssl_assert(lib, ok):
if not ok:
errors = _consume_errors(lib)
- raise UnhandledOpenSSLError(
+ raise InternalError(
"Unknown OpenSSL error. Please file an issue at https://github.com"
"/pyca/cryptography/issues with information on how to reproduce "
"this.",