aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/__init__.py9
-rw-r--r--src/cryptography/hazmat/bindings/openssl/evp.py2
-rw-r--r--src/cryptography/hazmat/bindings/openssl/ssl.py1
-rw-r--r--src/cryptography/hazmat/bindings/openssl/x509.py5
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/__init__.py183
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/asymmetric/__init__.py5
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py93
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/asymmetric/ec.py87
8 files changed, 221 insertions, 164 deletions
diff --git a/src/cryptography/hazmat/backends/__init__.py b/src/cryptography/hazmat/backends/__init__.py
index 24c029f6..256fee39 100644
--- a/src/cryptography/hazmat/backends/__init__.py
+++ b/src/cryptography/hazmat/backends/__init__.py
@@ -17,8 +17,13 @@ def _available_backends():
if _available_backends_list is None:
_available_backends_list = [
- backend.load(require=False)
- for backend in pkg_resources.iter_entry_points(
+ # setuptools 11.3 deprecated support for the require parameter to
+ # load(), and introduced the new resolve() method instead.
+ # This can be removed if/when we can assume setuptools>=11.3. At
+ # some point we may wish to add a warning, to push people along,
+ # but at present this would result in too many warnings.
+ ep.resolve() if hasattr(ep, "resolve") else ep.load(require=False)
+ for ep in pkg_resources.iter_entry_points(
"cryptography.backends"
)
]
diff --git a/src/cryptography/hazmat/bindings/openssl/evp.py b/src/cryptography/hazmat/bindings/openssl/evp.py
index f00c2f0d..780ce900 100644
--- a/src/cryptography/hazmat/bindings/openssl/evp.py
+++ b/src/cryptography/hazmat/bindings/openssl/evp.py
@@ -119,6 +119,8 @@ int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *, const char *, int,
const unsigned char *, int);
int EVP_PKEY_cmp(const EVP_PKEY *, const EVP_PKEY *);
+
+EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *);
"""
MACROS = """
diff --git a/src/cryptography/hazmat/bindings/openssl/ssl.py b/src/cryptography/hazmat/bindings/openssl/ssl.py
index 91ae36ac..bf627139 100644
--- a/src/cryptography/hazmat/bindings/openssl/ssl.py
+++ b/src/cryptography/hazmat/bindings/openssl/ssl.py
@@ -302,6 +302,7 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *);
long SSL_CTX_get_timeout(const SSL_CTX *);
const SSL_CIPHER *SSL_get_current_cipher(const SSL *);
+int SSL_version(const SSL *);
/* SNI APIs were introduced in OpenSSL 1.0.0. To continue to support
* earlier versions some special handling of these is necessary.
diff --git a/src/cryptography/hazmat/bindings/openssl/x509.py b/src/cryptography/hazmat/bindings/openssl/x509.py
index f51b0e59..e30d23b7 100644
--- a/src/cryptography/hazmat/bindings/openssl/x509.py
+++ b/src/cryptography/hazmat/bindings/openssl/x509.py
@@ -71,6 +71,8 @@ typedef struct {
typedef ... NETSCAPE_SPKI;
+typedef ... PKCS8_PRIV_KEY_INFO;
+
static const int X509_FLAG_COMPAT;
static const int X509_FLAG_NO_HEADER;
static const int X509_FLAG_NO_VERSION;
@@ -224,6 +226,9 @@ DSA *d2i_DSA_PUBKEY_bio(BIO *, DSA **);
int i2d_DSA_PUBKEY_bio(BIO *, DSA *);
DSA *d2i_DSAPrivateKey_bio(BIO *, DSA **);
int i2d_DSAPrivateKey_bio(BIO *, DSA *);
+
+PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *,
+ PKCS8_PRIV_KEY_INFO **);
"""
MACROS = """
diff --git a/src/cryptography/hazmat/primitives/interfaces/__init__.py b/src/cryptography/hazmat/primitives/interfaces/__init__.py
index fd1b25f3..fb5ceeae 100644
--- a/src/cryptography/hazmat/primitives/interfaces/__init__.py
+++ b/src/cryptography/hazmat/primitives/interfaces/__init__.py
@@ -8,6 +8,15 @@ import abc
import six
+from cryptography.hazmat.primitives.interfaces.asymmetric.dsa import (
+ DSAParameters, DSAParametersWithNumbers, DSAPrivateKey,
+ DSAPrivateKeyWithNumbers, DSAPublicKey, DSAPublicKeyWithNumbers
+)
+from cryptography.hazmat.primitives.interfaces.asymmetric.ec import (
+ EllipticCurve, EllipticCurvePrivateKey, EllipticCurvePrivateKeyWithNumbers,
+ EllipticCurvePublicKey, EllipticCurvePublicKeyWithNumbers,
+ EllipticCurveSignatureAlgorithm
+)
from cryptography.hazmat.primitives.interfaces.ciphers import (
BlockCipherAlgorithm, CipherAlgorithm, Mode,
ModeWithAuthenticationTag, ModeWithInitializationVector, ModeWithNonce
@@ -16,6 +25,18 @@ from cryptography.hazmat.primitives.interfaces.ciphers import (
__all__ = [
"BlockCipherAlgorithm",
"CipherAlgorithm",
+ "DSAParameters",
+ "DSAParametersWithNumbers",
+ "DSAPrivateKey",
+ "DSAPrivateKeyWithNumbers",
+ "DSAPublicKey",
+ "DSAPublicKeyWithNumbers",
+ "EllipticCurve",
+ "EllipticCurvePrivateKey",
+ "EllipticCurvePrivateKeyWithNumbers",
+ "EllipticCurvePublicKey",
+ "EllipticCurvePublicKeyWithNumbers",
+ "EllipticCurveSignatureAlgorithm",
"Mode",
"ModeWithAuthenticationTag",
"ModeWithInitializationVector",
@@ -188,90 +209,6 @@ class RSAPublicKeyWithNumbers(RSAPublicKey):
@six.add_metaclass(abc.ABCMeta)
-class DSAParameters(object):
- @abc.abstractmethod
- def generate_private_key(self):
- """
- Generates and returns a DSAPrivateKey.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAParametersWithNumbers(DSAParameters):
- @abc.abstractmethod
- def parameter_numbers(self):
- """
- Returns a DSAParameterNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPrivateKey(object):
- @abc.abstractproperty
- def key_size(self):
- """
- The bit length of the prime modulus.
- """
-
- @abc.abstractmethod
- def public_key(self):
- """
- The DSAPublicKey associated with this private key.
- """
-
- @abc.abstractmethod
- def parameters(self):
- """
- The DSAParameters object associated with this private key.
- """
-
- @abc.abstractmethod
- def signer(self, signature_algorithm):
- """
- Returns an AsymmetricSignatureContext used for signing data.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPrivateKeyWithNumbers(DSAPrivateKey):
- @abc.abstractmethod
- def private_numbers(self):
- """
- Returns a DSAPrivateNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPublicKey(object):
- @abc.abstractproperty
- def key_size(self):
- """
- The bit length of the prime modulus.
- """
-
- @abc.abstractmethod
- def parameters(self):
- """
- The DSAParameters object associated with this public key.
- """
-
- @abc.abstractmethod
- def verifier(self, signature, signature_algorithm):
- """
- Returns an AsymmetricVerificationContext used for signing data.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPublicKeyWithNumbers(DSAPublicKey):
- @abc.abstractmethod
- def public_numbers(self):
- """
- Returns a DSAPublicNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
class AsymmetricSignatureContext(object):
@abc.abstractmethod
def update(self, data):
@@ -329,84 +266,6 @@ class KeyDerivationFunction(object):
@six.add_metaclass(abc.ABCMeta)
-class EllipticCurve(object):
- @abc.abstractproperty
- def name(self):
- """
- The name of the curve. e.g. secp256r1.
- """
-
- @abc.abstractproperty
- def key_size(self):
- """
- The bit length of the base point of the curve.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurveSignatureAlgorithm(object):
- @abc.abstractproperty
- def algorithm(self):
- """
- The digest algorithm used with this signature.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePrivateKey(object):
- @abc.abstractmethod
- def signer(self, signature_algorithm):
- """
- Returns an AsymmetricSignatureContext used for signing data.
- """
-
- @abc.abstractmethod
- def public_key(self):
- """
- The EllipticCurvePublicKey for this private key.
- """
-
- @abc.abstractproperty
- def curve(self):
- """
- The EllipticCurve that this key is on.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePrivateKeyWithNumbers(EllipticCurvePrivateKey):
- @abc.abstractmethod
- def private_numbers(self):
- """
- Returns an EllipticCurvePrivateNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePublicKey(object):
- @abc.abstractmethod
- def verifier(self, signature, signature_algorithm):
- """
- Returns an AsymmetricVerificationContext used for signing data.
- """
-
- @abc.abstractproperty
- def curve(self):
- """
- The EllipticCurve that this key is on.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePublicKeyWithNumbers(EllipticCurvePublicKey):
- @abc.abstractmethod
- def public_numbers(self):
- """
- Returns an EllipticCurvePublicNumbers.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
class MACContext(object):
@abc.abstractmethod
def update(self, data):
diff --git a/src/cryptography/hazmat/primitives/interfaces/asymmetric/__init__.py b/src/cryptography/hazmat/primitives/interfaces/asymmetric/__init__.py
new file mode 100644
index 00000000..4b540884
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/interfaces/asymmetric/__init__.py
@@ -0,0 +1,5 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
diff --git a/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py b/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py
new file mode 100644
index 00000000..acfc8973
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py
@@ -0,0 +1,93 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import abc
+
+import six
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAParameters(object):
+ @abc.abstractmethod
+ def generate_private_key(self):
+ """
+ Generates and returns a DSAPrivateKey.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAParametersWithNumbers(DSAParameters):
+ @abc.abstractmethod
+ def parameter_numbers(self):
+ """
+ Returns a DSAParameterNumbers.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAPrivateKey(object):
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The bit length of the prime modulus.
+ """
+
+ @abc.abstractmethod
+ def public_key(self):
+ """
+ The DSAPublicKey associated with this private key.
+ """
+
+ @abc.abstractmethod
+ def parameters(self):
+ """
+ The DSAParameters object associated with this private key.
+ """
+
+ @abc.abstractmethod
+ def signer(self, signature_algorithm):
+ """
+ Returns an AsymmetricSignatureContext used for signing data.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAPrivateKeyWithNumbers(DSAPrivateKey):
+ @abc.abstractmethod
+ def private_numbers(self):
+ """
+ Returns a DSAPrivateNumbers.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAPublicKey(object):
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The bit length of the prime modulus.
+ """
+
+ @abc.abstractmethod
+ def parameters(self):
+ """
+ The DSAParameters object associated with this public key.
+ """
+
+ @abc.abstractmethod
+ def verifier(self, signature, signature_algorithm):
+ """
+ Returns an AsymmetricVerificationContext used for signing data.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class DSAPublicKeyWithNumbers(DSAPublicKey):
+ @abc.abstractmethod
+ def public_numbers(self):
+ """
+ Returns a DSAPublicNumbers.
+ """
diff --git a/src/cryptography/hazmat/primitives/interfaces/asymmetric/ec.py b/src/cryptography/hazmat/primitives/interfaces/asymmetric/ec.py
new file mode 100644
index 00000000..2a624576
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/interfaces/asymmetric/ec.py
@@ -0,0 +1,87 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import abc
+
+import six
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurve(object):
+ @abc.abstractproperty
+ def name(self):
+ """
+ The name of the curve. e.g. secp256r1.
+ """
+
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The bit length of the base point of the curve.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurveSignatureAlgorithm(object):
+ @abc.abstractproperty
+ def algorithm(self):
+ """
+ The digest algorithm used with this signature.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurvePrivateKey(object):
+ @abc.abstractmethod
+ def signer(self, signature_algorithm):
+ """
+ Returns an AsymmetricSignatureContext used for signing data.
+ """
+
+ @abc.abstractmethod
+ def public_key(self):
+ """
+ The EllipticCurvePublicKey for this private key.
+ """
+
+ @abc.abstractproperty
+ def curve(self):
+ """
+ The EllipticCurve that this key is on.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurvePrivateKeyWithNumbers(EllipticCurvePrivateKey):
+ @abc.abstractmethod
+ def private_numbers(self):
+ """
+ Returns an EllipticCurvePrivateNumbers.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurvePublicKey(object):
+ @abc.abstractmethod
+ def verifier(self, signature, signature_algorithm):
+ """
+ Returns an AsymmetricVerificationContext used for signing data.
+ """
+
+ @abc.abstractproperty
+ def curve(self):
+ """
+ The EllipticCurve that this key is on.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class EllipticCurvePublicKeyWithNumbers(EllipticCurvePublicKey):
+ @abc.abstractmethod
+ def public_numbers(self):
+ """
+ Returns an EllipticCurvePublicNumbers.
+ """