| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
|
| 7 |
INCLUDES = """ |
| 8 |
#include <openssl/err.h> |
| 9 |
""" |
| 10 |
|
| 11 |
TYPES = """ |
| 12 |
static const int Cryptography_HAS_EC_CODES; |
| 13 |
static const int Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR; |
| 14 |
static const int Cryptography_HAS_EVP_R_MEMORY_LIMIT_EXCEEDED; |
| 15 |
|
| 16 |
static const int ERR_LIB_ASN1; |
| 17 |
static const int ERR_LIB_ASYNC; |
| 18 |
static const int ERR_LIB_BIO; |
| 19 |
static const int ERR_LIB_BN; |
| 20 |
static const int ERR_LIB_BUF; |
| 21 |
static const int ERR_LIB_CMP; |
| 22 |
static const int ERR_LIB_CMS; |
| 23 |
static const int ERR_LIB_COMP; |
| 24 |
static const int ERR_LIB_CONF; |
| 25 |
static const int ERR_LIB_CRMF; |
| 26 |
static const int ERR_LIB_CRYPTO; |
| 27 |
static const int ERR_LIB_CT; |
| 28 |
static const int ERR_LIB_DH; |
| 29 |
static const int ERR_LIB_DSA; |
| 30 |
static const int ERR_LIB_DSO; |
| 31 |
static const int ERR_LIB_EC; |
| 32 |
static const int ERR_LIB_ECDH; |
| 33 |
static const int ERR_LIB_ECDSA; |
| 34 |
static const int ERR_LIB_ENGINE; |
| 35 |
static const int ERR_LIB_ESS; |
| 36 |
static const int ERR_LIB_EVP; |
| 37 |
static const int ERR_LIB_FIPS; |
| 38 |
static const int ERR_LIB_HMAC; |
| 39 |
static const int ERR_LIB_HTTP; |
| 40 |
static const int ERR_LIB_KDF; |
| 41 |
static const int ERR_LIB_MASK; |
| 42 |
static const int ERR_LIB_NONE; |
| 43 |
static const int ERR_LIB_OBJ; |
| 44 |
static const int ERR_LIB_OCSP; |
| 45 |
static const int ERR_LIB_OFFSET; |
| 46 |
static const int ERR_LIB_OSSL_DECODER; |
| 47 |
static const int ERR_LIB_OSSL_ENCODER; |
| 48 |
static const int ERR_LIB_OSSL_STORE; |
| 49 |
static const int ERR_LIB_PEM; |
| 50 |
static const int ERR_LIB_PKCS12; |
| 51 |
static const int ERR_LIB_PKCS7; |
| 52 |
static const int ERR_LIB_PROP; |
| 53 |
static const int ERR_LIB_PROV; |
| 54 |
static const int ERR_LIB_RAND; |
| 55 |
static const int ERR_LIB_RSA; |
| 56 |
static const int ERR_LIB_SM2; |
| 57 |
static const int ERR_LIB_SSL; |
| 58 |
static const int ERR_LIB_SYS; |
| 59 |
static const int ERR_LIB_TS; |
| 60 |
static const int ERR_LIB_UI; |
| 61 |
static const int ERR_LIB_USER; |
| 62 |
static const int ERR_LIB_X509; |
| 63 |
static const int ERR_LIB_X509V3; |
| 64 |
|
| 65 |
static const int ERR_R_MALLOC_FAILURE; |
| 66 |
static const int EVP_R_MEMORY_LIMIT_EXCEEDED; |
| 67 |
|
| 68 |
static const int ASN1_R_BOOLEAN_IS_WRONG_LENGTH; |
| 69 |
static const int ASN1_R_BUFFER_TOO_SMALL; |
| 70 |
static const int ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER; |
| 71 |
static const int ASN1_R_DATA_IS_WRONG; |
| 72 |
static const int ASN1_R_DECODE_ERROR; |
| 73 |
static const int ASN1_R_DEPTH_EXCEEDED; |
| 74 |
static const int ASN1_R_ENCODE_ERROR; |
| 75 |
static const int ASN1_R_ERROR_GETTING_TIME; |
| 76 |
static const int ASN1_R_ERROR_LOADING_SECTION; |
| 77 |
static const int ASN1_R_MSTRING_WRONG_TAG; |
| 78 |
static const int ASN1_R_NESTED_ASN1_STRING; |
| 79 |
static const int ASN1_R_NO_MATCHING_CHOICE_TYPE; |
| 80 |
static const int ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM; |
| 81 |
static const int ASN1_R_UNKNOWN_OBJECT_TYPE; |
| 82 |
static const int ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE; |
| 83 |
static const int ASN1_R_UNKNOWN_TAG; |
| 84 |
static const int ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE; |
| 85 |
static const int ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE; |
| 86 |
static const int ASN1_R_UNSUPPORTED_TYPE; |
| 87 |
static const int ASN1_R_WRONG_TAG; |
| 88 |
static const int ASN1_R_NO_CONTENT_TYPE; |
| 89 |
static const int ASN1_R_NO_MULTIPART_BODY_FAILURE; |
| 90 |
static const int ASN1_R_NO_MULTIPART_BOUNDARY; |
| 91 |
static const int ASN1_R_HEADER_TOO_LONG; |
| 92 |
|
| 93 |
static const int DH_R_INVALID_PUBKEY; |
| 94 |
|
| 95 |
static const int EVP_F_EVP_ENCRYPTFINAL_EX; |
| 96 |
|
| 97 |
static const int EVP_R_AES_KEY_SETUP_FAILED; |
| 98 |
static const int EVP_R_BAD_DECRYPT; |
| 99 |
static const int EVP_R_CIPHER_PARAMETER_ERROR; |
| 100 |
static const int EVP_R_CTRL_NOT_IMPLEMENTED; |
| 101 |
static const int EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED; |
| 102 |
static const int EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH; |
| 103 |
static const int EVP_R_DECODE_ERROR; |
| 104 |
static const int EVP_R_DIFFERENT_KEY_TYPES; |
| 105 |
static const int EVP_R_INITIALIZATION_ERROR; |
| 106 |
static const int EVP_R_INPUT_NOT_INITIALIZED; |
| 107 |
static const int EVP_R_INVALID_KEY_LENGTH; |
| 108 |
static const int EVP_R_MISSING_PARAMETERS; |
| 109 |
static const int EVP_R_NO_CIPHER_SET; |
| 110 |
static const int EVP_R_NO_DIGEST_SET; |
| 111 |
static const int EVP_R_PUBLIC_KEY_NOT_RSA; |
| 112 |
static const int EVP_R_UNKNOWN_PBE_ALGORITHM; |
| 113 |
static const int EVP_R_UNSUPPORTED_CIPHER; |
| 114 |
static const int EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION; |
| 115 |
static const int EVP_R_UNSUPPORTED_KEYLENGTH; |
| 116 |
static const int EVP_R_UNSUPPORTED_SALT_TYPE; |
| 117 |
static const int EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM; |
| 118 |
static const int EVP_R_WRONG_FINAL_BLOCK_LENGTH; |
| 119 |
static const int EVP_R_CAMELLIA_KEY_SETUP_FAILED; |
| 120 |
|
| 121 |
static const int EC_R_UNKNOWN_GROUP; |
| 122 |
|
| 123 |
static const int PEM_R_BAD_BASE64_DECODE; |
| 124 |
static const int PEM_R_BAD_DECRYPT; |
| 125 |
static const int PEM_R_BAD_END_LINE; |
| 126 |
static const int PEM_R_BAD_IV_CHARS; |
| 127 |
static const int PEM_R_BAD_PASSWORD_READ; |
| 128 |
static const int PEM_R_ERROR_CONVERTING_PRIVATE_KEY; |
| 129 |
static const int PEM_R_NO_START_LINE; |
| 130 |
static const int PEM_R_NOT_DEK_INFO; |
| 131 |
static const int PEM_R_NOT_ENCRYPTED; |
| 132 |
static const int PEM_R_NOT_PROC_TYPE; |
| 133 |
static const int PEM_R_PROBLEMS_GETTING_PASSWORD; |
| 134 |
static const int PEM_R_READ_KEY; |
| 135 |
static const int PEM_R_SHORT_HEADER; |
| 136 |
static const int PEM_R_UNSUPPORTED_CIPHER; |
| 137 |
static const int PEM_R_UNSUPPORTED_ENCRYPTION; |
| 138 |
|
| 139 |
static const int PKCS12_R_PKCS12_CIPHERFINAL_ERROR; |
| 140 |
|
| 141 |
static const int RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE; |
| 142 |
static const int RSA_R_DATA_TOO_LARGE_FOR_MODULUS; |
| 143 |
static const int RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY; |
| 144 |
static const int RSA_R_BLOCK_TYPE_IS_NOT_01; |
| 145 |
static const int RSA_R_BLOCK_TYPE_IS_NOT_02; |
| 146 |
static const int RSA_R_PKCS_DECODING_ERROR; |
| 147 |
static const int RSA_R_OAEP_DECODING_ERROR; |
| 148 |
|
| 149 |
static const int SSL_TLSEXT_ERR_OK; |
| 150 |
static const int SSL_TLSEXT_ERR_ALERT_WARNING; |
| 151 |
static const int SSL_TLSEXT_ERR_ALERT_FATAL; |
| 152 |
static const int SSL_TLSEXT_ERR_NOACK; |
| 153 |
|
| 154 |
static const int SSL_AD_CLOSE_NOTIFY; |
| 155 |
static const int SSL_AD_UNEXPECTED_MESSAGE; |
| 156 |
static const int SSL_AD_BAD_RECORD_MAC; |
| 157 |
static const int SSL_AD_RECORD_OVERFLOW; |
| 158 |
static const int SSL_AD_DECOMPRESSION_FAILURE; |
| 159 |
static const int SSL_AD_HANDSHAKE_FAILURE; |
| 160 |
static const int SSL_AD_BAD_CERTIFICATE; |
| 161 |
static const int SSL_AD_UNSUPPORTED_CERTIFICATE; |
| 162 |
static const int SSL_AD_CERTIFICATE_REVOKED; |
| 163 |
static const int SSL_AD_CERTIFICATE_EXPIRED; |
| 164 |
static const int SSL_AD_CERTIFICATE_UNKNOWN; |
| 165 |
static const int SSL_AD_ILLEGAL_PARAMETER; |
| 166 |
static const int SSL_AD_UNKNOWN_CA; |
| 167 |
static const int SSL_AD_ACCESS_DENIED; |
| 168 |
static const int SSL_AD_DECODE_ERROR; |
| 169 |
static const int SSL_AD_DECRYPT_ERROR; |
| 170 |
static const int SSL_AD_PROTOCOL_VERSION; |
| 171 |
static const int SSL_AD_INSUFFICIENT_SECURITY; |
| 172 |
static const int SSL_AD_INTERNAL_ERROR; |
| 173 |
static const int SSL_AD_USER_CANCELLED; |
| 174 |
static const int SSL_AD_NO_RENEGOTIATION; |
| 175 |
|
| 176 |
static const int SSL_AD_UNSUPPORTED_EXTENSION; |
| 177 |
static const int SSL_AD_CERTIFICATE_UNOBTAINABLE; |
| 178 |
static const int SSL_AD_UNRECOGNIZED_NAME; |
| 179 |
static const int SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE; |
| 180 |
static const int SSL_AD_BAD_CERTIFICATE_HASH_VALUE; |
| 181 |
static const int SSL_AD_UNKNOWN_PSK_IDENTITY; |
| 182 |
|
| 183 |
static const int SSL_R_UNEXPECTED_EOF_WHILE_READING; |
| 184 |
static const int Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING; |
| 185 |
|
| 186 |
static const int X509_R_CERT_ALREADY_IN_HASH_TABLE; |
| 187 |
static const int X509_R_KEY_VALUES_MISMATCH; |
| 188 |
""" |
| 189 |
|
| 190 |
FUNCTIONS = """ |
| 191 |
void ERR_error_string_n(unsigned long, char *, size_t); |
| 192 |
const char *ERR_lib_error_string(unsigned long); |
| 193 |
const char *ERR_func_error_string(unsigned long); |
| 194 |
const char *ERR_reason_error_string(unsigned long); |
| 195 |
unsigned long ERR_get_error(void); |
| 196 |
unsigned long ERR_peek_error(void); |
| 197 |
unsigned long ERR_peek_last_error(void); |
| 198 |
void ERR_clear_error(void); |
| 199 |
|
| 200 |
int ERR_GET_LIB(unsigned long); |
| 201 |
int ERR_GET_REASON(unsigned long); |
| 202 |
|
| 203 |
""" |
| 204 |
|
| 205 |
CUSTOMIZATIONS = """ |
| 206 |
static const long Cryptography_HAS_EC_CODES = 1; |
| 207 |
|
| 208 |
#ifdef RSA_R_PKCS_DECODING_ERROR |
| 209 |
static const long Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR = 1; |
| 210 |
#else |
| 211 |
static const long Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR = 0; |
| 212 |
static const long RSA_R_PKCS_DECODING_ERROR = 0; |
| 213 |
#endif |
| 214 |
|
| 215 |
#ifdef EVP_R_MEMORY_LIMIT_EXCEEDED |
| 216 |
static const long Cryptography_HAS_EVP_R_MEMORY_LIMIT_EXCEEDED = 1; |
| 217 |
#else |
| 218 |
static const long EVP_R_MEMORY_LIMIT_EXCEEDED = 0; |
| 219 |
static const long Cryptography_HAS_EVP_R_MEMORY_LIMIT_EXCEEDED = 0; |
| 220 |
#endif |
| 221 |
|
| 222 |
#if CRYPTOGRAPHY_OPENSSL_300_OR_GREATER |
| 223 |
#else |
| 224 |
static const int ERR_LIB_CMP = -42; |
| 225 |
static const int ERR_LIB_CRMF = -42; |
| 226 |
static const int ERR_LIB_ESS = -42; |
| 227 |
static const int ERR_LIB_HTTP = -42; |
| 228 |
static const int ERR_LIB_MASK = -42; |
| 229 |
static const int ERR_LIB_OFFSET = -42; |
| 230 |
static const int ERR_LIB_OSSL_DECODER = -42; |
| 231 |
static const int ERR_LIB_OSSL_ENCODER = -42; |
| 232 |
static const int ERR_LIB_PROP = -42; |
| 233 |
static const int ERR_LIB_PROV = -42; |
| 234 |
#endif |
| 235 |
|
| 236 |
/* SSL_R_UNEXPECTED_EOF_WHILE_READING is needed for pyOpenSSL |
| 237 |
with OpenSSL 3+ */ |
| 238 |
#if defined(SSL_R_UNEXPECTED_EOF_WHILE_READING) |
| 239 |
#define Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING 1 |
| 240 |
#else |
| 241 |
#define Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING 0 |
| 242 |
#define SSL_R_UNEXPECTED_EOF_WHILE_READING 0 |
| 243 |
#endif |
| 244 |
|
| 245 |
""" |