aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.rst9
-rw-r--r--cryptography/bindings/openssl/api.py17
-rw-r--r--cryptography/bindings/openssl/bio.py167
-rw-r--r--cryptography/bindings/openssl/conf.py26
-rw-r--r--cryptography/bindings/openssl/crypto.py10
-rw-r--r--cryptography/bindings/openssl/engine.py52
-rw-r--r--cryptography/bindings/openssl/err.py55
-rw-r--r--cryptography/bindings/openssl/evp.py1
8 files changed, 334 insertions, 3 deletions
diff --git a/README.rst b/README.rst
index 9e5f67ed..01f3eadd 100644
--- a/README.rst
+++ b/README.rst
@@ -16,3 +16,12 @@ yet. It targets Python 2.6-2.7, Python 3.2+, as well as PyPy.
You can find more documentation at `Read The Docs`_.
.. _`Read The Docs`: https://cryptography.readthedocs.org/
+
+Discussion
+~~~~~~~~~~
+
+We maintain a `cryptography-dev`_ mailing list for development discussion.
+
+You can also join #cryptography-dev on Freenode to ask questions or get involved.
+
+.. _`cryptography-dev`: https://mail.python.org/mailman/listinfo/cryptography-dev
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py
index c352d3b2..02ba8fd4 100644
--- a/cryptography/bindings/openssl/api.py
+++ b/cryptography/bindings/openssl/api.py
@@ -26,9 +26,13 @@ class API(object):
"""
_modules = [
"bignum",
+ "conf",
+ "bio",
"crypto",
"dh",
"dsa",
+ "engine",
+ "err",
"evp",
"rand",
"rsa",
@@ -39,16 +43,24 @@ class API(object):
self.ffi = cffi.FFI()
includes = []
functions = []
+ macros = []
for name in self._modules:
__import__("cryptography.bindings.openssl." + name)
module = sys.modules["cryptography.bindings.openssl." + name]
self.ffi.cdef(module.TYPES)
- self.ffi.cdef(module.FUNCTIONS)
- self.ffi.cdef(module.MACROS)
+ macros.append(module.MACROS)
functions.append(module.FUNCTIONS)
includes.append(module.INCLUDES)
+ # loop over the functions & macros after declaring all the types
+ # so we can set interdependent types in different files and still
+ # have them all defined before we parse the funcs & macros
+ for func in functions:
+ self.ffi.cdef(func)
+ for macro in macros:
+ self.ffi.cdef(macro)
+
# We include functions here so that if we got any of their definitions
# wrong, the underlying C compiler will explode. In C you are allowed
# to re-declare a function if it has the same signature. That is:
@@ -63,6 +75,7 @@ class API(object):
)
self.lib.OpenSSL_add_all_algorithms()
+ self.lib.SSL_load_error_strings()
def openssl_version_text(self):
"""
diff --git a/cryptography/bindings/openssl/bio.py b/cryptography/bindings/openssl/bio.py
new file mode 100644
index 00000000..de5c6c74
--- /dev/null
+++ b/cryptography/bindings/openssl/bio.py
@@ -0,0 +1,167 @@
+# 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.
+
+INCLUDES = """
+#include <openssl/bio.h>
+"""
+
+TYPES = """
+typedef struct bio_st BIO;
+typedef void bio_info_cb(BIO *, int, const char *, int, long, long);
+struct bio_method_st {
+ int type;
+ const char * name;
+ int (*bwrite)(BIO *, const char *, int);
+ int (*bread)(BIO *, char *, int);
+ int (*bputs)(BIO *, const char *);
+ int (*bgets)(BIO *, char*, int);
+ long (*ctrl)(BIO *, int, long, void *);
+ int (*create)(BIO *);
+ int (*destroy)(BIO *);
+ long (*callback_ctrl)(BIO *, int, bio_info_cb *);
+ ...;
+};
+typedef struct bio_method_st BIO_METHOD;
+struct bio_st {
+ BIO_METHOD *method;
+ long (*callback)(struct bio_st*, int, const char*, int, long, long);
+ char *cb_arg;
+ int init;
+ int shutdown;
+ int flags;
+ int retry_reason;
+ int num;
+ void *ptr;
+ struct bio_st *next_bio;
+ struct bio_st *prev_bio;
+ int references;
+ unsigned long num_read;
+ unsigned long num_write;
+ ...;
+};
+typedef ... BUF_MEM;
+"""
+
+FUNCTIONS = """
+BIO* BIO_new(BIO_METHOD *);
+int BIO_set(BIO *a, BIO_METHOD *);
+int BIO_free(BIO *);
+void BIO_vfree(BIO *);
+void BIO_free_all(BIO *);
+BIO *BIO_push(BIO *, BIO *);
+BIO *BIO_pop(BIO *);
+BIO *BIO_next(BIO *);
+BIO *BIO_find_type(BIO *, int);
+int BIO_method_type(const BIO *b);
+BIO_METHOD *BIO_s_mem(void);
+BIO *BIO_new_mem_buf(void *buf, int len);
+BIO_METHOD *BIO_s_file(void);
+BIO *BIO_new_file(const char *filename, const char *mode);
+BIO *BIO_new_fp(FILE *stream, int flags);
+BIO_METHOD *BIO_s_fd(void);
+BIO *BIO_new_fd(int fd, int close_flag);
+BIO_METHOD *BIO_s_socket(void);
+BIO *BIO_new_socket(int sock, int close_flag);
+BIO_METHOD *BIO_s_null(void);
+long BIO_ctrl(BIO *, int, long, void *);
+long BIO_callback_ctrl(BIO *, int, void (*fp)(struct bio_st *, int,
+ const char *, int, long, long));
+char* BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
+long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
+size_t BIO_ctrl_pending(BIO *b);
+size_t BIO_ctrl_wpending(BIO *b);
+int BIO_read(BIO *, void *, int);
+int BIO_gets(BIO *, char *, int);
+int BIO_write(BIO *, const void *, int);
+int BIO_puts(BIO *, const char *);
+BIO_METHOD *BIO_f_null();
+BIO_METHOD *BIO_f_buffer();
+"""
+
+MACROS = """
+long BIO_set_fd(BIO *, long, int);
+long BIO_get_fd(BIO *, char *);
+long BIO_set_mem_eof_return(BIO *, int);
+long BIO_get_mem_data(BIO *, char **);
+long BIO_set_mem_buf(BIO *, BUF_MEM *, int);
+long BIO_get_mem_ptr(BIO *, BUF_MEM **);
+long BIO_set_fp(BIO *, FILE *, int);
+long BIO_get_fp(BIO *, FILE **);
+int BIO_read_filename(BIO *, char *);
+int BIO_write_filename(BIO *, char *);
+int BIO_append_filename(BIO *, char *);
+int BIO_rw_filename(BIO *, char *);
+int BIO_should_read(BIO *);
+int BIO_should_write(BIO *);
+int BIO_should_io_special(BIO *);
+int BIO_retry_type(BIO *);
+int BIO_should_retry(BIO *);
+int BIO_reset(BIO *);
+int BIO_seek(BIO *, int);
+int BIO_tell(BIO *);
+int BIO_flush(BIO *);
+int BIO_eof(BIO *);
+int BIO_set_close(BIO *,long);
+int BIO_get_close(BIO *);
+int BIO_pending(BIO *);
+int BIO_wpending(BIO *);
+int BIO_get_info_callback(BIO *, bio_info_cb **);
+int BIO_set_info_callback(BIO *, bio_info_cb *);
+long BIO_get_buffer_num_lines(BIO *);
+long BIO_set_read_buffer_size(BIO *, long);
+long BIO_set_write_buffer_size(BIO *, long);
+long BIO_set_buffer_size(BIO *, long);
+long BIO_set_buffer_read_data(BIO *, void *, long);
+#define BIO_TYPE_MEM ...
+#define BIO_TYPE_FILE ...
+#define BIO_TYPE_FD ...
+#define BIO_TYPE_SOCKET ...
+#define BIO_TYPE_CONNECT ...
+#define BIO_TYPE_ACCEPT ...
+#define BIO_TYPE_NULL ...
+#define BIO_CLOSE ...
+#define BIO_NOCLOSE ...
+#define BIO_TYPE_SOURCE_SINK ...
+#define BIO_CTRL_RESET ...
+#define BIO_CTRL_EOF ...
+#define BIO_CTRL_SET ...
+#define BIO_CTRL_SET_CLOSE ...
+#define BIO_CTRL_FLUSH ...
+#define BIO_CTRL_DUP ...
+#define BIO_CTRL_GET_CLOSE ...
+#define BIO_CTRL_INFO ...
+#define BIO_CTRL_GET ...
+#define BIO_CTRL_PENDING ...
+#define BIO_CTRL_WPENDING ...
+#define BIO_C_FILE_SEEK ...
+#define BIO_C_FILE_TELL ...
+#define BIO_TYPE_NONE ...
+#define BIO_TYPE_PROXY_CLIENT ...
+#define BIO_TYPE_PROXY_SERVER ...
+#define BIO_TYPE_NBIO_TEST ...
+#define BIO_TYPE_BER ...
+#define BIO_TYPE_BIO ...
+#define BIO_TYPE_DESCRIPTOR ...
+#define BIO_FLAGS_READ ...
+#define BIO_FLAGS_WRITE ...
+#define BIO_FLAGS_IO_SPECIAL ...
+#define BIO_FLAGS_RWS ...
+#define BIO_FLAGS_SHOULD_RETRY ...
+#define BIO_TYPE_NULL_FILTER ...
+#define BIO_TYPE_SSL ...
+#define BIO_TYPE_MD ...
+#define BIO_TYPE_BUFFER ...
+#define BIO_TYPE_CIPHER ...
+#define BIO_TYPE_BASE64 ...
+#define BIO_TYPE_FILTER ...
+"""
diff --git a/cryptography/bindings/openssl/conf.py b/cryptography/bindings/openssl/conf.py
new file mode 100644
index 00000000..85c7a210
--- /dev/null
+++ b/cryptography/bindings/openssl/conf.py
@@ -0,0 +1,26 @@
+# 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.
+
+INCLUDES = """
+#include <openssl/conf.h>
+"""
+
+TYPES = """
+typedef ... CONF;
+"""
+
+FUNCTIONS = """
+"""
+
+MACROS = """
+"""
diff --git a/cryptography/bindings/openssl/crypto.py b/cryptography/bindings/openssl/crypto.py
index 0f40d5b6..501fb5a1 100644
--- a/cryptography/bindings/openssl/crypto.py
+++ b/cryptography/bindings/openssl/crypto.py
@@ -20,8 +20,18 @@ TYPES = """
FUNCTIONS = """
void CRYPTO_free(void *);
+int CRYPTO_mem_ctrl(int);
+int CRYPTO_is_mem_check_on();
+void CRYPTO_mem_leaks(struct bio_st *);
+void CRYPTO_cleanup_all_ex_data();
"""
MACROS = """
void CRYPTO_add(int *, int, int);
+void CRYPTO_malloc_init();
+void CRYPTO_malloc_debug_init();
+#define CRYPTO_MEM_CHECK_ON ...
+#define CRYPTO_MEM_CHECK_OFF ...
+#define CRYPTO_MEM_CHECK_ENABLE ...
+#define CRYPTO_MEM_CHECK_DISABLE ...
"""
diff --git a/cryptography/bindings/openssl/engine.py b/cryptography/bindings/openssl/engine.py
new file mode 100644
index 00000000..b3ec3125
--- /dev/null
+++ b/cryptography/bindings/openssl/engine.py
@@ -0,0 +1,52 @@
+# 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.
+
+INCLUDES = """
+#include <openssl/engine.h>
+"""
+
+TYPES = """
+typedef ... ENGINE;
+"""
+
+FUNCTIONS = """
+ENGINE *ENGINE_get_first();
+ENGINE *ENGINE_get_last();
+ENGINE *ENGINE_get_next(ENGINE *);
+ENGINE *ENGINE_get_prev(ENGINE *);
+int ENGINE_add(ENGINE *);
+int ENGINE_remove(ENGINE *);
+ENGINE *ENGINE_by_id(const char *);
+int ENGINE_init(ENGINE *);
+int ENGINE_finish(ENGINE *);
+int ENGINE_free(ENGINE *);
+void ENGINE_cleanup();
+void ENGINE_load_dynamic();
+void ENGINE_load_builtin_engines();
+int ENGINE_ctrl_cmd_string(ENGINE *, const char *, const char *, int);
+int ENGINE_set_default(ENGINE *, unsigned int);
+int ENGINE_register_complete(ENGINE *);
+"""
+
+MACROS = """
+#define ENGINE_METHOD_RSA ...
+#define ENGINE_METHOD_DSA ...
+#define ENGINE_METHOD_RAND ...
+#define ENGINE_METHOD_ECDH ...
+#define ENGINE_METHOD_ECDSA ...
+#define ENGINE_METHOD_CIPHERS ...
+#define ENGINE_METHOD_DIGESTS ...
+#define ENGINE_METHOD_STORE ...
+#define ENGINE_METHOD_ALL ...
+#define ENGINE_METHOD_NONE ...
+"""
diff --git a/cryptography/bindings/openssl/err.py b/cryptography/bindings/openssl/err.py
new file mode 100644
index 00000000..ffb6096a
--- /dev/null
+++ b/cryptography/bindings/openssl/err.py
@@ -0,0 +1,55 @@
+# 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.
+
+INCLUDES = """
+#include <openssl/err.h>
+"""
+
+TYPES = """
+struct ERR_string_data_st {
+ unsigned long error;
+ const char *string;
+};
+typedef struct ERR_string_data_st ERR_STRING_DATA;
+"""
+
+FUNCTIONS = """
+void SSL_load_error_strings();
+void ERR_load_crypto_strings();
+void ERR_free_strings();
+char* ERR_error_string(unsigned long, char *);
+void ERR_error_string_n(unsigned long, char *, size_t);
+const char* ERR_lib_error_string(unsigned long);
+const char* ERR_func_error_string(unsigned long);
+const char* ERR_reason_error_string(unsigned long);
+void ERR_print_errors(BIO *);
+void ERR_print_errors_fp(FILE *);
+unsigned long ERR_get_error();
+unsigned long ERR_peek_error();
+unsigned long ERR_peek_last_error();
+unsigned long ERR_get_error_line(const char **, int *);
+unsigned long ERR_peek_error_line(const char **, int *);
+unsigned long ERR_peek_last_error_line(const char **, int *);
+unsigned long ERR_get_error_line_data(const char **, int *,
+ const char **, int *);
+unsigned long ERR_peek_error_line_data(const char **,
+ int *, const char **, int *);
+unsigned long ERR_peek_last_error_line_data(const char **,
+ int *, const char **, int *);
+void ERR_put_error(int, int, int, const char *, int);
+void ERR_add_error_data(int, ...);
+int ERR_get_next_error_library();
+"""
+
+MACROS = """
+"""
diff --git a/cryptography/bindings/openssl/evp.py b/cryptography/bindings/openssl/evp.py
index 8afaf342..63364374 100644
--- a/cryptography/bindings/openssl/evp.py
+++ b/cryptography/bindings/openssl/evp.py
@@ -20,7 +20,6 @@ typedef struct {
...;
} EVP_CIPHER_CTX;
typedef ... EVP_CIPHER;
-typedef ... ENGINE;
"""
FUNCTIONS = """