aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-09-29 22:35:41 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-09-29 22:35:41 -0500
commitb64bf82b4b5717640cf9978428bd545245e8d478 (patch)
tree2fcf4dc894ed1b7765b721d0bba11b1407d62d43 /cryptography
parentb2ab5ef112f8de507d2db72fdf4a5fa698a954e0 (diff)
downloadcryptography-b64bf82b4b5717640cf9978428bd545245e8d478.tar.gz
cryptography-b64bf82b4b5717640cf9978428bd545245e8d478.tar.bz2
cryptography-b64bf82b4b5717640cf9978428bd545245e8d478.zip
Remove deprecated RSA methods from backends, update tests
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/hazmat/backends/openssl/backend.py58
-rw-r--r--cryptography/hazmat/primitives/asymmetric/rsa.py192
2 files changed, 1 insertions, 249 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py
index 9a36674a..4e30e6f0 100644
--- a/cryptography/hazmat/backends/openssl/backend.py
+++ b/cryptography/hazmat/backends/openssl/backend.py
@@ -44,8 +44,7 @@ from cryptography.hazmat.backends.openssl.ec import (
from cryptography.hazmat.backends.openssl.hashes import _HashContext
from cryptography.hazmat.backends.openssl.hmac import _HMACContext
from cryptography.hazmat.backends.openssl.rsa import (
- _RSAPrivateKey, _RSAPublicKey, _RSASignatureContext,
- _RSAVerificationContext
+ _RSAPrivateKey, _RSAPublicKey
)
from cryptography.hazmat.bindings.openssl.binding import Binding
from cryptography.hazmat.primitives import hashes
@@ -581,39 +580,6 @@ class Backend(object):
return ctx
- def create_rsa_signature_ctx(self, private_key, padding, algorithm):
- warnings.warn(
- "create_rsa_signature_ctx is deprecated and will be removed in a "
- "future version.",
- utils.DeprecatedIn05,
- stacklevel=2
- )
- rsa_cdata = self._rsa_cdata_from_private_key(private_key)
- key = _RSAPrivateKey(self, rsa_cdata)
- return _RSASignatureContext(self, key, padding, algorithm)
-
- def create_rsa_verification_ctx(self, public_key, signature, padding,
- algorithm):
- warnings.warn(
- "create_rsa_verification_ctx is deprecated and will be removed in "
- "a future version.",
- utils.DeprecatedIn05,
- stacklevel=2
- )
- rsa_cdata = self._rsa_cdata_from_public_key(public_key)
- key = _RSAPublicKey(self, rsa_cdata)
- return _RSAVerificationContext(self, key, signature, padding,
- algorithm)
-
- def mgf1_hash_supported(self, algorithm):
- warnings.warn(
- "mgf1_hash_supported is deprecated and will be removed in "
- "a future version.",
- utils.DeprecatedIn05,
- stacklevel=2
- )
- return self._mgf1_hash_supported(algorithm)
-
def _mgf1_hash_supported(self, algorithm):
if self._lib.Cryptography_HAS_MGF1_MD:
return self.hash_supported(algorithm)
@@ -774,28 +740,6 @@ class Backend(object):
else:
return True
- def decrypt_rsa(self, private_key, ciphertext, padding):
- warnings.warn(
- "decrypt_rsa is deprecated and will be removed in a future "
- "version.",
- utils.DeprecatedIn05,
- stacklevel=2
- )
- rsa_cdata = self._rsa_cdata_from_private_key(private_key)
- key = _RSAPrivateKey(self, rsa_cdata)
- return key.decrypt(ciphertext, padding)
-
- def encrypt_rsa(self, public_key, plaintext, padding):
- warnings.warn(
- "encrypt_rsa is deprecated and will be removed in a future "
- "version.",
- utils.DeprecatedIn05,
- stacklevel=2
- )
- rsa_cdata = self._rsa_cdata_from_public_key(public_key)
- key = _RSAPublicKey(self, rsa_cdata)
- return key.encrypt(plaintext, padding)
-
def cmac_algorithm_supported(self, algorithm):
return (
self._lib.Cryptography_HAS_CMAC == 1
diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py
index 398b3763..c192811d 100644
--- a/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -13,11 +13,8 @@
from __future__ import absolute_import, division, print_function
-import warnings
-
import six
-from cryptography import utils
from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
from cryptography.hazmat.backends.interfaces import RSABackend
@@ -94,65 +91,6 @@ def _check_public_key_components(e, n):
raise ValueError("e must be odd.")
-class RSAPublicKey(object):
- def __init__(self, public_exponent, modulus):
- warnings.warn(
- "The RSAPublicKey class is deprecated and will be removed in a "
- "future version.",
- utils.DeprecatedIn05,
- stacklevel=2
- )
- if (
- not isinstance(public_exponent, six.integer_types) or
- not isinstance(modulus, six.integer_types)
- ):
- raise TypeError("RSAPublicKey arguments must be integers.")
-
- _check_public_key_components(public_exponent, modulus)
-
- self._public_exponent = public_exponent
- self._modulus = modulus
-
- def verifier(self, signature, padding, algorithm, backend):
- if not isinstance(backend, RSABackend):
- raise UnsupportedAlgorithm(
- "Backend object does not implement RSABackend.",
- _Reasons.BACKEND_MISSING_INTERFACE
- )
-
- return backend.create_rsa_verification_ctx(self, signature, padding,
- algorithm)
-
- def encrypt(self, plaintext, padding, backend):
- if not isinstance(backend, RSABackend):
- raise UnsupportedAlgorithm(
- "Backend object does not implement RSABackend.",
- _Reasons.BACKEND_MISSING_INTERFACE
- )
-
- return backend.encrypt_rsa(self, plaintext, padding)
-
- @property
- def key_size(self):
- return utils.bit_length(self.modulus)
-
- @property
- def public_exponent(self):
- return self._public_exponent
-
- @property
- def modulus(self):
- return self._modulus
-
- @property
- def e(self):
- return self.public_exponent
-
- @property
- def n(self):
- return self.modulus
-
-
def _modinv(e, m):
"""
Modular Multiplicative Inverse. Returns x such that: (x*e) mod m == 1
@@ -189,136 +127,6 @@ def rsa_crt_dmq1(private_exponent, q):
return private_exponent % (q - 1)
-class RSAPrivateKey(object):
- def __init__(self, p, q, private_exponent, dmp1, dmq1, iqmp,
- public_exponent, modulus):
- warnings.warn(
- "The RSAPrivateKey class is deprecated and will be removed in a "
- "future version.",
- utils.DeprecatedIn05,
- stacklevel=2
- )
- if (
- not isinstance(p, six.integer_types) or
- not isinstance(q, six.integer_types) or
- not isinstance(dmp1, six.integer_types) or
- not isinstance(dmq1, six.integer_types) or
- not isinstance(iqmp, six.integer_types) or
- not isinstance(private_exponent, six.integer_types) or
- not isinstance(public_exponent, six.integer_types) or
- not isinstance(modulus, six.integer_types)
- ):
- raise TypeError("RSAPrivateKey arguments must be integers.")
-
- _check_private_key_components(p, q, private_exponent, dmp1, dmq1, iqmp,
- public_exponent, modulus)
-
- self._p = p
- self._q = q
- self._dmp1 = dmp1
- self._dmq1 = dmq1
- self._iqmp = iqmp
- self._private_exponent = private_exponent
- self._public_exponent = public_exponent
- self._modulus = modulus
-
- @classmethod
- def generate(cls, public_exponent, key_size, backend):
- warnings.warn(
- "generate is deprecated and will be removed in a future version.",
- utils.DeprecatedIn05,
- stacklevel=2
- )
- if not isinstance(backend, RSABackend):
- raise UnsupportedAlgorithm(
- "Backend object does not implement RSABackend.",
- _Reasons.BACKEND_MISSING_INTERFACE
- )
-
- _verify_rsa_parameters(public_exponent, key_size)
- key = backend.generate_rsa_private_key(public_exponent, key_size)
- private_numbers = key.private_numbers()
- return RSAPrivateKey(
- p=private_numbers.p,
- q=private_numbers.q,
- dmp1=private_numbers.dmp1,
- dmq1=private_numbers.dmq1,
- iqmp=private_numbers.iqmp,
- private_exponent=private_numbers.d,
- public_exponent=private_numbers.public_numbers.e,
- modulus=private_numbers.public_numbers.n
- )
-
- def signer(self, padding, algorithm, backend):
- if not isinstance(backend, RSABackend):
- raise UnsupportedAlgorithm(
- "Backend object does not implement RSABackend.",
- _Reasons.BACKEND_MISSING_INTERFACE
- )
-
- return backend.create_rsa_signature_ctx(self, padding, algorithm)
-
- def decrypt(self, ciphertext, padding, backend):
- if not isinstance(backend, RSABackend):
- raise UnsupportedAlgorithm(
- "Backend object does not implement RSABackend.",
- _Reasons.BACKEND_MISSING_INTERFACE
- )
-
- return backend.decrypt_rsa(self, ciphertext, padding)
-
- @property
- def key_size(self):
- return utils.bit_length(self.modulus)
-
- def public_key(self):
- return RSAPublicKey(self.public_exponent, self.modulus)
-
- @property
- def p(self):
- return self._p
-
- @property
- def q(self):
- return self._q
-
- @property
- def private_exponent(self):
- return self._private_exponent
-
- @property
- def public_exponent(self):
- return self._public_exponent
-
- @property
- def modulus(self):
- return self._modulus
-
- @property
- def d(self):
- return self.private_exponent
-
- @property
- def dmp1(self):
- return self._dmp1
-
- @property
- def dmq1(self):
- return self._dmq1
-
- @property
- def iqmp(self):
- return self._iqmp
-
- @property
- def e(self):
- return self.public_exponent
-
- @property
- def n(self):
- return self.modulus
-
-
class RSAPrivateNumbers(object):
def __init__(self, p, q, d, dmp1, dmq1, iqmp,
public_numbers):