Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ env:
- TOX_ENV=pep8
- TOX_ENV=py3pep8

matrix:
allow_failures:
- env: TOX_ENV=py26 OPENSSL=0.9.8
- env: TOX_ENV=py27 OPENSSL=0.9.8
- env: TOX_ENV=py32 OPENSSL=0.9.8
- env: TOX_ENV=py33 OPENSSL=0.9.8
- env: TOX_ENV=pypy OPENSSL=0.9.8
- env: TOX_ENV=py26 CC=clang OPENSSL=0.9.8
- env: TOX_ENV=py27 CC=clang OPENSSL=0.9.8
- env: TOX_ENV=py32 CC=clang OPENSSL=0.9.8
- env: TOX_ENV=py33 CC=clang OPENSSL=0.9.8
- env: TOX_ENV=pypy CC=clang OPENSSL=0.9.8

install:
- "sudo add-apt-repository \"deb http://archive.ubuntu.com/ubuntu/ lucid main\""
- sudo add-apt-repository -y ppa:pypy/ppa
Expand All @@ -47,11 +34,14 @@ install:
# This is required because we need to get rid of the Travis installed PyPy
# or it'll take precedence over the PPA installed one.
- "[[ ${TOX_ENV} == pypy ]] && sudo rm -rf /usr/local/pypy/bin || true"
- pip install tox
- pip install tox coveralls

script:
- tox -e $TOX_ENV

after_success:
- coveralls

notifications:
irc:
channels:
Expand Down
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ Cryptography
============

.. image:: https://travis-ci.org/pyca/cryptography.png?branch=master
:target: https://travis-ci.org/pyca/cryptography
:target: https://travis-ci.org/pyca/cryptography

.. image:: https://coveralls.io/repos/pyca/cryptography/badge.png?branch=master
:target: https://coveralls.io/r/pyca/cryptography?branch=master


``cryptography`` is a package designed to expose cryptographic recipes and
primitives to Python developers.

It is currently in early development and isn't recommended for general usage
yet. It targets Python 2.6-2.7, Python 3.2+, as well as PyPy.
yet. It targets Python 2.6-2.7, Python 3.2+, and PyPy.

You can find more information in the `documentation`_.

Expand Down
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/asn1.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@

BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *, BIGNUM *);
"""

CUSTOMIZATIONS = """
"""
15 changes: 9 additions & 6 deletions cryptography/hazmat/bindings/openssl/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _ensure_ffi_initialized(cls):
includes = []
functions = []
macros = []
customizations = []
for name in cls._modules:
module_name = "cryptography.hazmat.bindings.openssl." + name
__import__(module_name)
Expand All @@ -84,6 +85,7 @@ def _ensure_ffi_initialized(cls):
macros.append(module.MACROS)
functions.append(module.FUNCTIONS)
includes.append(module.INCLUDES)
customizations.append(module.CUSTOMIZATIONS)

# loop over the functions & macros after declaring all the types
# so we can set interdependent types in different files and still
Expand All @@ -102,7 +104,7 @@ def _ensure_ffi_initialized(cls):
# int foo(int);
# int foo(short);
lib = ffi.verify(
source="\n".join(includes + functions),
source="\n".join(includes + functions + customizations),
libraries=["crypto", "ssl"],
)

Expand Down Expand Up @@ -315,19 +317,20 @@ def create_ctx(self, key, hash_cls):
evp_md = self._backend.lib.EVP_get_digestbyname(
hash_cls.name.encode('ascii'))
assert evp_md != self._backend.ffi.NULL
res = self._backend.lib.HMAC_Init_ex(ctx, key, len(key), evp_md,
self._backend.ffi.NULL)
res = self._backend.lib.Cryptography_HMAC_Init_ex(
ctx, key, len(key), evp_md, self._backend.ffi.NULL
)
assert res != 0
return ctx

def update_ctx(self, ctx, data):
res = self._backend.lib.HMAC_Update(ctx, data, len(data))
res = self._backend.lib.Cryptography_HMAC_Update(ctx, data, len(data))
assert res != 0

def finalize_ctx(self, ctx, digest_size):
buf = self._backend.ffi.new("unsigned char[]", digest_size)
buflen = self._backend.ffi.new("unsigned int *", digest_size)
res = self._backend.lib.HMAC_Final(ctx, buf, buflen)
res = self._backend.lib.Cryptography_HMAC_Final(ctx, buf, buflen)
assert res != 0
self._backend.lib.HMAC_CTX_cleanup(ctx)
return self._backend.ffi.buffer(buf)[:digest_size]
Expand All @@ -337,7 +340,7 @@ def copy_ctx(self, ctx):
self._backend.lib.HMAC_CTX_init(copied_ctx)
copied_ctx = self._backend.ffi.gc(copied_ctx,
self._backend.lib.HMAC_CTX_cleanup)
res = self._backend.lib.HMAC_CTX_copy(copied_ctx, ctx)
res = self._backend.lib.Cryptography_HMAC_CTX_copy(copied_ctx, ctx)
assert res != 0
return copied_ctx

Expand Down
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/bignum.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@

MACROS = """
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/bio.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,6 @@
#define BIO_TYPE_BASE64 ...
#define BIO_TYPE_FILTER ...
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@

MACROS = """
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@
#define CRYPTO_MEM_CHECK_ENABLE ...
#define CRYPTO_MEM_CHECK_DISABLE ...
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/dh.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@

MACROS = """
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@

MACROS = """
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@
#define ENGINE_METHOD_ALL ...
#define ENGINE_METHOD_NONE ...
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/err.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@
int ERR_GET_REASON(unsigned long);
int ERR_FATAL_ERROR(unsigned long);
"""

CUSTOMIZATIONS = """
"""
18 changes: 15 additions & 3 deletions cryptography/hazmat/bindings/openssl/evp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
} EVP_PKEY;
static const int EVP_PKEY_RSA;
static const int EVP_PKEY_DSA;
static const int EVP_CTRL_GCM_SET_IVLEN;
static const int EVP_CTRL_GCM_GET_TAG;
static const int EVP_CTRL_GCM_SET_TAG;
static const int Cryptography_EVP_CTRL_GCM_SET_IVLEN;
static const int Cryptography_EVP_CTRL_GCM_GET_TAG;
static const int Cryptography_EVP_CTRL_GCM_SET_TAG;
"""

FUNCTIONS = """
Expand Down Expand Up @@ -95,3 +95,15 @@
int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *);
int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *, int, int, void *);
"""

CUSTOMIZATIONS = """
#ifdef EVP_CTRL_GCM_SET_TAG
const int Cryptography_EVP_CTRL_GCM_GET_TAG = EVP_CTRL_GCM_GET_TAG;
const int Cryptography_EVP_CTRL_GCM_SET_TAG = EVP_CTRL_GCM_SET_TAG;
const int Cryptography_EVP_CTRL_GCM_SET_IVLEN = EVP_CTRL_GCM_SET_IVLEN;
#else
const int Cryptography_EVP_CTRL_GCM_GET_TAG = -1;
const int Cryptography_EVP_CTRL_GCM_SET_TAG = -1;
const int Cryptography_EVP_CTRL_GCM_SET_IVLEN = -1;
#endif
"""
66 changes: 62 additions & 4 deletions cryptography/hazmat/bindings/openssl/hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,69 @@
FUNCTIONS = """
void HMAC_CTX_init(HMAC_CTX *);
void HMAC_CTX_cleanup(HMAC_CTX *);
int HMAC_Init_ex(HMAC_CTX *, const void *, int, const EVP_MD *, ENGINE *);
int HMAC_Update(HMAC_CTX *, const unsigned char *, size_t);
int HMAC_Final(HMAC_CTX *, unsigned char *, unsigned int *);
int HMAC_CTX_copy(HMAC_CTX *, HMAC_CTX *);

int Cryptography_HMAC_Init_ex(HMAC_CTX *, const void *, int, const EVP_MD *,
ENGINE *);
int Cryptography_HMAC_Update(HMAC_CTX *, const unsigned char *, size_t);
int Cryptography_HMAC_Final(HMAC_CTX *, unsigned char *, unsigned int *);
int Cryptography_HMAC_CTX_copy(HMAC_CTX *, HMAC_CTX *);
"""

MACROS = """
"""

CUSTOMIZATIONS = """
int Cryptography_HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
const EVP_MD *md, ENGINE *impl) {
#if OPENSSL_VERSION_NUMBER >= 0x010000000
return HMAC_Init_ex(ctx, key, key_len, md, impl);
#else
HMAC_Init_ex(ctx, key, key_len, md, impl);
return 1;
#endif
}

int Cryptography_HMAC_Update(HMAC_CTX *ctx, const unsigned char *data,
size_t data_len) {
#if OPENSSL_VERSION_NUMBER >= 0x010000000
return HMAC_Update(ctx, data, data_len);
#else
HMAC_Update(ctx, data, data_len);
return 1;
#endif
}

int Cryptography_HMAC_Final(HMAC_CTX *ctx, unsigned char *digest,
unsigned int *digest_len) {
#if OPENSSL_VERSION_NUMBER >= 0x010000000
return HMAC_Final(ctx, digest, digest_len);
#else
HMAC_Final(ctx, digest, digest_len);
return 1;
#endif
}

int Cryptography_HMAC_CTX_copy(HMAC_CTX *dst_ctx, HMAC_CTX *src_ctx) {
#if OPENSSL_VERSION_NUMBER >= 0x010000000
return HMAC_CTX_copy(dst_ctx, src_ctx);
#else
HMAC_CTX_init(dst_ctx);
if (!EVP_MD_CTX_copy_ex(&dst_ctx->i_ctx, &src_ctx->i_ctx)) {
goto err;
}
if (!EVP_MD_CTX_copy_ex(&dst_ctx->o_ctx, &src_ctx->o_ctx)) {
goto err;
}
if (!EVP_MD_CTX_copy_ex(&dst_ctx->md_ctx, &src_ctx->md_ctx)) {
goto err;
}
memcpy(dst_ctx->key, src_ctx->key, HMAC_MAX_MD_CBLOCK);
dst_ctx->key_length = src_ctx->key_length;
dst_ctx->md = src_ctx->md;
return 1;

err:
return 0;
#endif
}
"""
9 changes: 7 additions & 2 deletions cryptography/hazmat/bindings/openssl/nid.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
static const int NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
"""

FUNCTIONS = ""
FUNCTIONS = """
"""

MACROS = """
"""

MACROS = ""
CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/opensslv.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@

MACROS = """
"""

CUSTOMIZATIONS = """
"""
6 changes: 5 additions & 1 deletion cryptography/hazmat/bindings/openssl/pem.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@
DH *PEM_read_bio_DHparams(BIO *, DH **, pem_password_cb *, void *);
"""

MACROS = ""
MACROS = """
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/pkcs12.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@
PKCS12 *PKCS12_create(char *, char *, EVP_PKEY *, X509 *,
struct stack_st_X509 *, int, int, int, int, int);
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/pkcs7.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@
int PKCS7_type_is_signedAndEnveloped(PKCS7 *);
int PKCS7_type_is_data(PKCS7 *);
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/rand.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@

MACROS = """
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@

MACROS = """
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@

MACROS = """
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,6 @@
int X509_CRL_set_lastUpdate(X509_CRL *, const ASN1_TIME *);
int X509_CRL_set_nextUpdate(X509_CRL *, const ASN1_TIME *);
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/x509name.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@
X509_NAME *sk_X509_NAME_value(struct stack_st_X509_NAME *, int);
void sk_X509_NAME_free(struct stack_st_X509_NAME *);
"""

CUSTOMIZATIONS = """
"""
3 changes: 3 additions & 0 deletions cryptography/hazmat/bindings/openssl/x509v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@
const X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *);
const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int);
"""

CUSTOMIZATIONS = """
"""
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deps =
pretend
commands =
coverage run --source=cryptography/,tests/ -m pytest
coverage report -m --fail-under 100
coverage report -m

[testenv:docs]
deps = sphinx
Expand Down