From 8b72741bd7ab7069c4df471b9fa55e6e9ec51147 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 30 Apr 2022 14:08:56 -0600 Subject: [PATCH] add a a constant for pyOpenSSL with OpenSSL 3 (#7157) --- src/_cffi_src/openssl/err.py | 13 +++++++++++++ .../hazmat/bindings/openssl/_conditional.py | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/_cffi_src/openssl/err.py b/src/_cffi_src/openssl/err.py index 216c3f95845b..dc27abba364c 100644 --- a/src/_cffi_src/openssl/err.py +++ b/src/_cffi_src/openssl/err.py @@ -29,6 +29,10 @@ static const int SSL_TLSEXT_ERR_NOACK; static const int X509_R_CERT_ALREADY_IN_HASH_TABLE; + +static const int SSL_R_UNEXPECTED_EOF_WHILE_READING; + +static const int Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING; """ FUNCTIONS = """ @@ -67,4 +71,13 @@ #else static const int CIPHER_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH = 0; #endif + +/* SSL_R_UNEXPECTED_EOF_WHILE_READING is needed for pyOpenSSL + with OpenSSL 3+ */ +#if defined(SSL_R_UNEXPECTED_EOF_WHILE_READING) +#define Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING 1 +#else +#define Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING 0 +#define SSL_R_UNEXPECTED_EOF_WHILE_READING 0 +#endif """ diff --git a/src/cryptography/hazmat/bindings/openssl/_conditional.py b/src/cryptography/hazmat/bindings/openssl/_conditional.py index 5c194721b6dd..ed81b849701e 100644 --- a/src/cryptography/hazmat/bindings/openssl/_conditional.py +++ b/src/cryptography/hazmat/bindings/openssl/_conditional.py @@ -301,6 +301,10 @@ def cryptography_has_300_evp_cipher() -> typing.List[str]: return ["EVP_CIPHER_fetch", "EVP_CIPHER_free"] +def cryptography_has_unexpected_eof_while_reading() -> typing.List[str]: + return ["SSL_R_UNEXPECTED_EOF_WHILE_READING"] + + # This is a mapping of # {condition: function-returning-names-dependent-on-that-condition} so we can # loop over them and delete unsupported names at runtime. It will be removed @@ -357,4 +361,7 @@ def cryptography_has_300_evp_cipher() -> typing.List[str]: "Cryptography_HAS_BN_FLAGS": cryptography_has_bn_flags, "Cryptography_HAS_EVP_PKEY_DH": cryptography_has_evp_pkey_dh, "Cryptography_HAS_300_EVP_CIPHER": cryptography_has_300_evp_cipher, + "Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING": ( + cryptography_has_unexpected_eof_while_reading + ), }