Skip to content

Commit 8e49ebb

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 c7ee0a0 commit 8e49ebb

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/_cffi_src/openssl/ssl.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
static const long Cryptography_HAS_SRTP;
3232
static const long Cryptography_HAS_DTLS_GET_DATA_MTU;
3333
static const long Cryptography_HAS_SSL_GET0_GROUP_NAME;
34+
static const long Cryptography_HAS_CLIENT_HELLO_CB;
3435
3536
static const long SSL_FILETYPE_PEM;
3637
static const long SSL_FILETYPE_ASN1;
@@ -391,6 +392,18 @@
391392
int DTLSv1_listen(SSL *, BIO_ADDR *);
392393
size_t DTLS_get_data_mtu(SSL *);
393394
395+
/* Client hello callback support */
396+
void SSL_CTX_set_client_hello_cb(
397+
SSL_CTX *c,
398+
int (*)(SSL *, int *, void *),
399+
void *arg);
400+
int SSL_client_hello_get1_extensions_present(
401+
SSL *s, int **out,
402+
size_t *outlen);
403+
int SSL_client_hello_get0_ext(
404+
SSL *s, unsigned int type,
405+
const unsigned char **out,
406+
size_t *outlen);
394407
395408
/* Custom extensions. */
396409
typedef int (*custom_ext_add_cb)(SSL *, unsigned int,
@@ -685,4 +698,21 @@
685698
static const long Cryptography_HAS_SSL_GET0_GROUP_NAME = 0;
686699
const char *(*SSL_get0_group_name)(SSL *) = NULL;
687700
#endif
701+
702+
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL
703+
static const long Cryptography_HAS_CLIENT_HELLO_CB = 0;
704+
void (*SSL_CTX_set_client_hello_cb)(
705+
SSL_CTX *c,
706+
int (*)(SSL *, int *, void *),
707+
void *arg) = NULL;
708+
int (*SSL_client_hello_get1_extensions_present)(
709+
SSL *s, int **out,
710+
size_t *outlen) = NULL;
711+
int (*SSL_client_hello_get0_ext)(
712+
SSL *s, unsigned int type,
713+
const unsigned char **out,
714+
size_t *outlen) = NULL;
715+
#else
716+
static const long Cryptography_HAS_CLIENT_HELLO_CB = 1;
717+
#endif
688718
"""

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ def cryptography_has_get_extms_support() -> list[str]:
164164
def cryptography_has_ssl_get0_group_name() -> list[str]:
165165
return ["SSL_get0_group_name"]
166166

167+
def cryptography_has_client_hello_cb() -> list[str]:
168+
return [
169+
"SSL_CTX_set_client_hello_cb",
170+
"SSL_client_hello_get1_extensions_present",
171+
"SSL_client_hello_get0_ext"
172+
]
167173

168174
# This is a mapping of
169175
# {condition: function-returning-names-dependent-on-that-condition} so we can
@@ -204,4 +210,5 @@ def cryptography_has_ssl_get0_group_name() -> list[str]:
204210
"Cryptography_HAS_SSL_GET0_GROUP_NAME": (
205211
cryptography_has_ssl_get0_group_name
206212
),
213+
"Cryptography_HAS_CLIENT_HELLO_CB": cryptography_has_client_hello_cb,
207214
}

0 commit comments

Comments
 (0)