Skip to content

Commit 3c985f6

Browse files
committed
Add client hello callback related functions
This exposes the OpenSSL functions SSL_CTX_set_client_hello_cb, SSL_client_hello_get0_ext and SSL_client_hello_get1_extensions_present. These are required to implement to the client hello callback functionality in pyOpenSSL. Signed-off-by: Arne Schwabe <arne@rfc2549.org>
1 parent 1b46d7c commit 3c985f6

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/_cffi_src/openssl/ssl.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
static const long Cryptography_HAS_SRTP;
3131
static const long Cryptography_HAS_DTLS_GET_DATA_MTU;
3232
static const long Cryptography_HAS_SSL_GET0_GROUP_NAME;
33+
static const long Cryptography_HAS_CLIENT_HELLO_CB;
3334
3435
static const long SSL_FILETYPE_PEM;
3536
static const long SSL_FILETYPE_ASN1;
@@ -390,6 +391,18 @@
390391
int DTLSv1_listen(SSL *, BIO_ADDR *);
391392
size_t DTLS_get_data_mtu(SSL *);
392393
394+
/* Client hello callback support */
395+
void SSL_CTX_set_client_hello_cb(
396+
SSL_CTX *,
397+
int (*)(SSL *, int *, void *),
398+
void *);
399+
int SSL_client_hello_get1_extensions_present(
400+
SSL *, int **,
401+
size_t *);
402+
int SSL_client_hello_get0_ext(
403+
SSL *, unsigned int,
404+
const unsigned char **,
405+
size_t *);
393406
394407
/* Custom extensions. */
395408
typedef int (*custom_ext_add_cb)(SSL *, unsigned int,
@@ -677,4 +690,21 @@
677690
static const long Cryptography_HAS_SSL_GET0_GROUP_NAME = 0;
678691
const char *(*SSL_get0_group_name)(SSL *) = NULL;
679692
#endif
693+
694+
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL
695+
static const long Cryptography_HAS_CLIENT_HELLO_CB = 0;
696+
void (*SSL_CTX_set_client_hello_cb)(
697+
SSL_CTX *,
698+
int (*)(SSL *, int *, void *),
699+
void *) = NULL;
700+
int (*SSL_client_hello_get1_extensions_present)(
701+
SSL *, int **,
702+
size_t *) = NULL;
703+
int (*SSL_client_hello_get0_ext)(
704+
SSL *s, unsigned int,
705+
const unsigned char **,
706+
size_t *) = NULL;
707+
#else
708+
static const long Cryptography_HAS_CLIENT_HELLO_CB = 1;
709+
#endif
680710
"""

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ def cryptography_has_ssl_get0_group_name() -> list[str]:
159159
return ["SSL_get0_group_name"]
160160

161161

162+
def cryptography_has_client_hello_cb() -> list[str]:
163+
return [
164+
"SSL_CTX_set_client_hello_cb",
165+
"SSL_client_hello_get1_extensions_present",
166+
"SSL_client_hello_get0_ext",
167+
]
168+
169+
162170
# This is a mapping of
163171
# {condition: function-returning-names-dependent-on-that-condition} so we can
164172
# loop over them and delete unsupported names at runtime. It will be removed
@@ -195,4 +203,5 @@ def cryptography_has_ssl_get0_group_name() -> list[str]:
195203
"Cryptography_HAS_SSL_GET0_GROUP_NAME": (
196204
cryptography_has_ssl_get0_group_name
197205
),
206+
"Cryptography_HAS_CLIENT_HELLO_CB": cryptography_has_client_hello_cb,
198207
}

0 commit comments

Comments
 (0)