@@ -15,9 +15,9 @@ typedef enum ssl_select_cert_result_t (*select_certificate_cb_t)(const SSL_CLIEN
1515 * in_select_certificate_cb(ssl) function to query whether or not we are
1616 * executing within a SSL_CTX_set_select_certificate_cb() callback for that SSL
1717 * object, or not.
18- *
19- * This mechanism is used by the SSL_get_servername() function to provide a
20- * different implementation depending on it's invocation context.
18+ *
19+ * This mechanism is used by SSL_get_servername() & SSL_set_ocsp_response()
20+ * to provide different behavior depending on invocation context.
2121 */
2222class ActiveSelectCertificateCb {
2323 public:
@@ -27,14 +27,14 @@ class ActiveSelectCertificateCb {
2727 ~ActiveSelectCertificateCb () {
2828 SSL_set_ex_data (ssl_, index (), nullptr );
2929 }
30+ static bool isActive (const SSL *ssl) {
31+ return SSL_get_ex_data (ssl, index ()) != nullptr ;
32+ }
33+ private:
3034 static int index () {
31- static int index = SSL_get_ex_new_index (0 , nullptr , nullptr , nullptr ,
32- +[](void *, void *ptr, CRYPTO_EX_DATA *, int , long , void *) {
33- if (ptr) ossl_OPENSSL_free (ptr);
34- });
35+ static int index = SSL_get_ex_new_index (0 , nullptr , nullptr , nullptr , nullptr );
3536 return index;
3637 }
37- private:
3838 SSL *ssl_;
3939};
4040
@@ -43,7 +43,7 @@ class ActiveSelectCertificateCb {
4343 * callback invocation for the specified SSL object.
4444 */
4545bool in_select_certificate_cb (const SSL *ssl) {
46- return SSL_get_ex_data (ssl, ActiveSelectCertificateCb::index ()) != nullptr ;
46+ return ActiveSelectCertificateCb::isActive (ssl) ;
4747}
4848
4949
@@ -101,15 +101,19 @@ static int ssl_ctx_client_hello_cb(SSL *ssl, int *alert, void *arg) {
101101 return ossl_SSL_CLIENT_HELLO_ERROR;
102102 }
103103
104+ // Ensure extensions are freed even if the callback throws
105+ std::unique_ptr<uint8_t , decltype (&OPENSSL_free)> cleanup (
106+ const_cast <uint8_t *>(client_hello.extensions ),
107+ OPENSSL_free
108+ );
109+
104110 enum ssl_select_cert_result_t result;
105111
106112 {
107113 ActiveSelectCertificateCb active (ssl);
108114 result = callback (&client_hello);
109115 }
110116
111- OPENSSL_free ((void *)client_hello.extensions );
112-
113117 switch (result) {
114118 case ssl_select_cert_success: return ossl_SSL_CLIENT_HELLO_SUCCESS;
115119 case ssl_select_cert_retry: return ossl_SSL_CLIENT_HELLO_RETRY;
0 commit comments