Skip to content

Commit

Permalink
Introduce mbedtls_ssl_hs_cb_t typedef
Browse files Browse the repository at this point in the history
Inline func for mbedtls_ssl_conf_cert_cb()

Signed-off-by: Glenn Strauss <[email protected]>
  • Loading branch information
gstrauss committed Mar 30, 2022
1 parent 3304f25 commit 227930f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.d/mbedtls_ssl_hs_cb_t.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Features
* Introduce mbedtls_ssl_hs_cb_t typedef for use with
mbedtls_ssl_conf_cert_cb() and perhaps future callbacks
during TLS handshake.
35 changes: 25 additions & 10 deletions include/mbedtls/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,25 @@ typedef void mbedtls_ssl_export_keys_t( void *p_expkey,
const unsigned char server_random[32],
mbedtls_tls_prf_types tls_prf_type );

#if defined(MBEDTLS_SSL_SRV_C)
/**
* \brief Callback type: generic handshake callback
*
* \note Callbacks may use user_data funcs to set/get app user data.
* See \c mbedtls_ssl_get_user_data_p()
* \c mbedtls_ssl_get_user_data_n()
* \c mbedtls_ssl_conf_get_user_data_p()
* \c mbedtls_ssl_conf_get_user_data_n()
*
* \param ssl \c mbedtls_ssl_context on which the callback is run
*
* \return The return value of the callback is 0 if successful,
* or a specific MBEDTLS_ERR_XXX code, which will cause
* the handshake to be aborted.
*/
typedef int (*mbedtls_ssl_hs_cb_t)( mbedtls_ssl_context *ssl );
#endif

/* A type for storing user data in a library structure.
*
* The representation of type may change in future versions of the library.
Expand Down Expand Up @@ -1477,7 +1496,7 @@ struct mbedtls_ssl_config
mbedtls_ssl_user_data_t MBEDTLS_PRIVATE(user_data);

#if defined(MBEDTLS_SSL_SRV_C)
int (*MBEDTLS_PRIVATE(f_cert_cb))(mbedtls_ssl_context *); /*!< certificate selection callback */
mbedtls_ssl_hs_cb_t MBEDTLS_PRIVATE(f_cert_cb); /*!< certificate selection callback */
#endif /* MBEDTLS_SSL_SRV_C */
};

Expand Down Expand Up @@ -2231,19 +2250,15 @@ void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *ssl,
* If set, the callback is always called for each handshake,
* after `ClientHello` processing has finished.
*
* The callback has the following parameters:
* - \c mbedtls_ssl_context*: The SSL context to which
* the operation applies.
* The return value of the callback is 0 if successful,
* or a specific MBEDTLS_ERR_XXX code, which will cause
* the handshake to be aborted.
*
* \param conf The SSL configuration to register the callback with.
* \param f_cert_cb The callback for selecting server certificate after
* `ClientHello` processing has finished.
*/
void mbedtls_ssl_conf_cert_cb( mbedtls_ssl_config *conf,
int (*f_cert_cb)(mbedtls_ssl_context *) );
static inline void mbedtls_ssl_conf_cert_cb( mbedtls_ssl_config *conf,
mbedtls_ssl_hs_cb_t f_cert_cb )
{
conf->MBEDTLS_PRIVATE(f_cert_cb) = f_cert_cb;
}
#endif /* MBEDTLS_SSL_SRV_C */

/**
Expand Down
8 changes: 0 additions & 8 deletions library/ssl_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,14 +1237,6 @@ void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *ssl,
mbedtls_ssl_set_timer( ssl, 0 );
}

#if defined(MBEDTLS_SSL_SRV_C)
void mbedtls_ssl_conf_cert_cb( mbedtls_ssl_config *conf,
int (*f_cert_cb)(mbedtls_ssl_context *) )
{
conf->f_cert_cb = f_cert_cb;
}
#endif /* MBEDTLS_SSL_SRV_C */

#if defined(MBEDTLS_SSL_SRV_C)
void mbedtls_ssl_conf_session_cache( mbedtls_ssl_config *conf,
void *p_cache,
Expand Down

0 comments on commit 227930f

Please sign in to comment.