Skip to content

Commit a209669

Browse files
authored
Added tls bindings for new OpenSSL APIs (#5595)
fixes #5379 closes #5483
1 parent 6d858c8 commit a209669

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/_cffi_src/openssl/ssl.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
static const long Cryptography_HAS_PSK;
2525
static const long Cryptography_HAS_VERIFIED_CHAIN;
2626
static const long Cryptography_HAS_KEYLOG;
27+
static const long Cryptography_HAS_GET_PROTO_VERSION;
2728
2829
/* Internally invented symbol to tell us if SSL_MODE_RELEASE_BUFFERS is
2930
* supported
@@ -312,6 +313,16 @@
312313
long SSL_total_renegotiations(SSL *);
313314
long SSL_get_secure_renegotiation_support(SSL *);
314315
316+
long SSL_CTX_set_min_proto_version(SSL_CTX *, int);
317+
long SSL_CTX_set_max_proto_version(SSL_CTX *, int);
318+
long SSL_set_min_proto_version(SSL *, int);
319+
long SSL_set_max_proto_version(SSL *, int);
320+
321+
long SSL_CTX_get_min_proto_version(SSL_CTX *);
322+
long SSL_CTX_get_max_proto_version(SSL_CTX *);
323+
long SSL_get_min_proto_version(SSL *);
324+
long SSL_get_max_proto_version(SSL *);
325+
315326
/* Defined as unsigned long because SSL_OP_ALL is greater than signed 32-bit
316327
and Windows defines long as 32-bit. */
317328
unsigned long SSL_CTX_set_options(SSL_CTX *, unsigned long);
@@ -330,10 +341,6 @@
330341
331342
/* methods */
332343
333-
/*
334-
* TLSv1_1 and TLSv1_2 are recent additions. Only sufficiently new versions of
335-
* OpenSSL support them.
336-
*/
337344
const SSL_METHOD *TLSv1_1_method(void);
338345
const SSL_METHOD *TLSv1_1_server_method(void);
339346
const SSL_METHOD *TLSv1_1_client_method(void);
@@ -363,6 +370,10 @@
363370
const SSL_METHOD *SSLv23_server_method(void);
364371
const SSL_METHOD *SSLv23_client_method(void);
365372
373+
const SSL_METHOD *TLS_method(void);
374+
const SSL_METHOD *TLS_server_method(void);
375+
const SSL_METHOD *TLS_client_method(void);
376+
366377
/*- These aren't macros these arguments are all const X on openssl > 1.0.x -*/
367378
SSL_CTX *SSL_CTX_new(SSL_METHOD *);
368379
long SSL_CTX_get_timeout(const SSL_CTX *);
@@ -674,4 +685,15 @@
674685
#else
675686
static const long Cryptography_HAS_TLSv1_3 = 1;
676687
#endif
688+
689+
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_111 && !CRYPTOGRAPHY_IS_LIBRESSL
690+
static const long Cryptography_HAS_GET_PROTO_VERSION = 0;
691+
692+
long (*SSL_CTX_get_min_proto_version)(SSL_CTX *) = NULL;
693+
long (*SSL_CTX_get_max_proto_version)(SSL_CTX *) = NULL;
694+
long (*SSL_get_min_proto_version)(SSL *) = NULL;
695+
long (*SSL_get_max_proto_version)(SSL *) = NULL;
696+
#else
697+
static const long Cryptography_HAS_GET_PROTO_VERSION = 1;
698+
#endif
677699
"""

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

+10
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ def cryptography_has_srtp():
262262
]
263263

264264

265+
def cryptography_has_get_proto_version():
266+
return [
267+
"SSL_CTX_get_min_proto_version",
268+
"SSL_CTX_get_max_proto_version",
269+
"SSL_get_min_proto_version",
270+
"SSL_get_max_proto_version",
271+
]
272+
273+
265274
# This is a mapping of
266275
# {condition: function-returning-names-dependent-on-that-condition} so we can
267276
# loop over them and delete unsupported names at runtime. It will be removed
@@ -309,4 +318,5 @@ def cryptography_has_srtp():
309318
"Cryptography_HAS_ENGINE": cryptography_has_engine,
310319
"Cryptography_HAS_VERIFIED_CHAIN": cryptography_has_verified_chain,
311320
"Cryptography_HAS_SRTP": cryptography_has_srtp,
321+
"Cryptography_HAS_GET_PROTO_VERSION": cryptography_has_get_proto_version,
312322
}

0 commit comments

Comments
 (0)