| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
|
| 7 |
INCLUDES = """ |
| 8 |
#include <openssl/crypto.h> |
| 9 |
""" |
| 10 |
|
| 11 |
TYPES = """ |
| 12 |
static const long Cryptography_HAS_LOCKING_CALLBACKS; |
| 13 |
static const long Cryptography_HAS_MEM_FUNCTIONS; |
| 14 |
static const long Cryptography_HAS_OPENSSL_CLEANUP; |
| 15 |
|
| 16 |
static const int SSLEAY_VERSION; |
| 17 |
static const int SSLEAY_CFLAGS; |
| 18 |
static const int SSLEAY_PLATFORM; |
| 19 |
static const int SSLEAY_DIR; |
| 20 |
static const int SSLEAY_BUILT_ON; |
| 21 |
static const int OPENSSL_VERSION; |
| 22 |
static const int OPENSSL_CFLAGS; |
| 23 |
static const int OPENSSL_BUILT_ON; |
| 24 |
static const int OPENSSL_PLATFORM; |
| 25 |
static const int OPENSSL_DIR; |
| 26 |
static const int CRYPTO_MEM_CHECK_ON; |
| 27 |
static const int CRYPTO_MEM_CHECK_OFF; |
| 28 |
static const int CRYPTO_MEM_CHECK_ENABLE; |
| 29 |
static const int CRYPTO_MEM_CHECK_DISABLE; |
| 30 |
""" |
| 31 |
|
| 32 |
FUNCTIONS = """ |
| 33 |
|
| 34 |
void OPENSSL_cleanup(void); |
| 35 |
|
| 36 |
/* as of 1.1.0 OpenSSL does its own locking *angelic chorus*. This function |
| 37 |
is now a noop macro. We can delete this once we drop 1.0.2 support. */ |
| 38 |
void (*CRYPTO_get_locking_callback(void))(int, int, const char *, int); |
| 39 |
|
| 40 |
/* SSLeay was removed in 1.1.0 */ |
| 41 |
unsigned long SSLeay(void); |
| 42 |
const char *SSLeay_version(int); |
| 43 |
/* these functions were added to replace the SSLeay functions in 1.1.0 */ |
| 44 |
unsigned long OpenSSL_version_num(void); |
| 45 |
const char *OpenSSL_version(int); |
| 46 |
|
| 47 |
/* this is a macro in 1.1.0 */ |
| 48 |
void *OPENSSL_malloc(size_t); |
| 49 |
void OPENSSL_free(void *); |
| 50 |
|
| 51 |
/* Removed in 3.0.0 */ |
| 52 |
int FIPS_mode(); |
| 53 |
|
| 54 |
/* Signature changed significantly in 1.1.0, only expose there for sanity */ |
| 55 |
int Cryptography_CRYPTO_set_mem_functions( |
| 56 |
void *(*)(size_t, const char *, int), |
| 57 |
void *(*)(void *, size_t, const char *, int), |
| 58 |
void (*)(void *, const char *, int)); |
| 59 |
|
| 60 |
void *Cryptography_malloc_wrapper(size_t, const char *, int); |
| 61 |
void *Cryptography_realloc_wrapper(void *, size_t, const char *, int); |
| 62 |
void Cryptography_free_wrapper(void *, const char *, int); |
| 63 |
int CRYPTO_memcmp(const void *a, const void *b, size_t len); |
| 64 |
""" |
| 65 |
|
| 66 |
CUSTOMIZATIONS = """ |
| 67 |
/* In 1.1.0 SSLeay has finally been retired. We bidirectionally define the |
| 68 |
values so you can use either one. This is so we can use the new function |
| 69 |
names no matter what OpenSSL we're running on, but users on older pyOpenSSL |
| 70 |
releases won't see issues if they're running OpenSSL 1.1.0 */ |
| 71 |
#if !defined(SSLEAY_VERSION) |
| 72 |
# define SSLeay OpenSSL_version_num |
| 73 |
# define SSLeay_version OpenSSL_version |
| 74 |
# define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER |
| 75 |
# define SSLEAY_VERSION OPENSSL_VERSION |
| 76 |
# define SSLEAY_CFLAGS OPENSSL_CFLAGS |
| 77 |
# define SSLEAY_BUILT_ON OPENSSL_BUILT_ON |
| 78 |
# define SSLEAY_PLATFORM OPENSSL_PLATFORM |
| 79 |
# define SSLEAY_DIR OPENSSL_DIR |
| 80 |
#endif |
| 81 |
#if !defined(OPENSSL_VERSION) |
| 82 |
# define OpenSSL_version_num SSLeay |
| 83 |
# define OpenSSL_version SSLeay_version |
| 84 |
# define OPENSSL_VERSION SSLEAY_VERSION |
| 85 |
# define OPENSSL_CFLAGS SSLEAY_CFLAGS |
| 86 |
# define OPENSSL_BUILT_ON SSLEAY_BUILT_ON |
| 87 |
# define OPENSSL_PLATFORM SSLEAY_PLATFORM |
| 88 |
# define OPENSSL_DIR SSLEAY_DIR |
| 89 |
#endif |
| 90 |
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110 |
| 91 |
static const long Cryptography_HAS_LOCKING_CALLBACKS = 1; |
| 92 |
#else |
| 93 |
static const long Cryptography_HAS_LOCKING_CALLBACKS = 0; |
| 94 |
#endif |
| 95 |
|
| 96 |
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110 |
| 97 |
static const long Cryptography_HAS_OPENSSL_CLEANUP = 0; |
| 98 |
|
| 99 |
void (*OPENSSL_cleanup)(void) = NULL; |
| 100 |
|
| 101 |
/* This function has a significantly different signature pre-1.1.0. since it is |
| 102 |
* for testing only, we don't bother to expose it on older OpenSSLs. |
| 103 |
*/ |
| 104 |
static const long Cryptography_HAS_MEM_FUNCTIONS = 0; |
| 105 |
int (*Cryptography_CRYPTO_set_mem_functions)( |
| 106 |
void *(*)(size_t, const char *, int), |
| 107 |
void *(*)(void *, size_t, const char *, int), |
| 108 |
void (*)(void *, const char *, int)) = NULL; |
| 109 |
|
| 110 |
#else |
| 111 |
static const long Cryptography_HAS_OPENSSL_CLEANUP = 1; |
| 112 |
static const long Cryptography_HAS_MEM_FUNCTIONS = 1; |
| 113 |
|
| 114 |
int Cryptography_CRYPTO_set_mem_functions( |
| 115 |
void *(*m)(size_t, const char *, int), |
| 116 |
void *(*r)(void *, size_t, const char *, int), |
| 117 |
void (*f)(void *, const char *, int) |
| 118 |
) { |
| 119 |
return CRYPTO_set_mem_functions(m, r, f); |
| 120 |
} |
| 121 |
#endif |
| 122 |
|
| 123 |
void *Cryptography_malloc_wrapper(size_t size, const char *path, int line) { |
| 124 |
return malloc(size); |
| 125 |
} |
| 126 |
|
| 127 |
void *Cryptography_realloc_wrapper(void *ptr, size_t size, const char *path, |
| 128 |
int line) { |
| 129 |
return realloc(ptr, size); |
| 130 |
} |
| 131 |
|
| 132 |
void Cryptography_free_wrapper(void *ptr, const char *path, int line) { |
| 133 |
free(ptr); |
| 134 |
} |
| 135 |
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_300 |
| 136 |
#else |
| 137 |
static const int CRYPTO_MEM_CHECK_ON=0; |
| 138 |
static const int CRYPTO_MEM_CHECK_OFF=0; |
| 139 |
static const int CRYPTO_MEM_CHECK_ENABLE=0; |
| 140 |
static const int CRYPTO_MEM_CHECK_DISABLE=0; |
| 141 |
int (*FIPS_mode)() = NULL; |
| 142 |
#endif |
| 143 |
""" |