Skip to content

Commit eb49820

Browse files
amauryfareaperhulk
authored andcommitted
Add more SSL_CIPHER_* functions, necessary to implement ctx.get_ciphers() in PyPy (pyca#4364)
* Add more SSL_CIPHER_* functions, necessary to implement ctx.get_ciphers() added by Python 3.6.1. * Add placeholders for other versions * Remove parameter names * LibreSSL 2.7 has the new functions * Add entries in _conditional.py * SSL_CIPHER_get_id returns int, not char*
1 parent fcf431a commit eb49820

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/_cffi_src/openssl/ssl.py

+19
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
static const long Cryptography_HAS_GENERIC_DTLS_METHOD;
3030
static const long Cryptography_HAS_SIGALGS;
3131
static const long Cryptography_HAS_PSK;
32+
static const long Cryptography_HAS_CIPHER_DETAILS;
3233
3334
/* Internally invented symbol to tell us if SNI is supported */
3435
static const long Cryptography_HAS_TLSEXT_HOSTNAME;
@@ -284,6 +285,12 @@
284285
/* Information about actually used cipher */
285286
const char *SSL_CIPHER_get_name(const SSL_CIPHER *);
286287
int SSL_CIPHER_get_bits(const SSL_CIPHER *, int *);
288+
uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *);
289+
int SSL_CIPHER_is_aead(const SSL_CIPHER *);
290+
int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *);
291+
int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *);
292+
int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *);
293+
int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *);
287294
288295
size_t SSL_get_finished(const SSL *, void *, size_t);
289296
size_t SSL_get_peer_finished(const SSL *, void *, size_t);
@@ -790,4 +797,16 @@
790797
791798
int (*SSL_extension_supported)(unsigned int) = NULL;
792799
#endif
800+
801+
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110 && !CRYPTOGRAPHY_LIBRESSL_27_OR_GREATER
802+
int (*SSL_CIPHER_is_aead)(const SSL_CIPHER *) = NULL;
803+
int (*SSL_CIPHER_get_cipher_nid)(const SSL_CIPHER *) = NULL;
804+
int (*SSL_CIPHER_get_digest_nid)(const SSL_CIPHER *) = NULL;
805+
int (*SSL_CIPHER_get_kx_nid)(const SSL_CIPHER *) = NULL;
806+
int (*SSL_CIPHER_get_auth_nid)(const SSL_CIPHER *) = NULL;
807+
static const long Cryptography_HAS_CIPHER_DETAILS = 0;
808+
#else
809+
static const long Cryptography_HAS_CIPHER_DETAILS = 1;
810+
#endif
811+
793812
"""

src/cryptography/hazmat/bindings/openssl/_conditional.py

+11
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ def cryptography_has_openssl_cleanup():
246246
]
247247

248248

249+
def cryptography_has_cipher_details():
250+
return [
251+
"SSL_CIPHER_is_aead",
252+
"SSL_CIPHER_get_cipher_nid",
253+
"SSL_CIPHER_get_digest_nid",
254+
"SSL_CIPHER_get_kx_nid",
255+
"SSL_CIPHER_get_auth_nid",
256+
]
257+
258+
249259
# This is a mapping of
250260
# {condition: function-returning-names-dependent-on-that-condition} so we can
251261
# loop over them and delete unsupported names at runtime. It will be removed
@@ -299,4 +309,5 @@ def cryptography_has_openssl_cleanup():
299309
"Cryptography_HAS_PSK": cryptography_has_psk,
300310
"Cryptography_HAS_CUSTOM_EXT": cryptography_has_custom_ext,
301311
"Cryptography_HAS_OPENSSL_CLEANUP": cryptography_has_openssl_cleanup,
312+
"Cryptography_HAS_CIPHER_DETAILS": cryptography_has_cipher_details,
302313
}

0 commit comments

Comments
 (0)