@@ -928,6 +928,10 @@ struct mbedtls_ssl_config
928
928
mbedtls_ssl_key_cert * key_cert ; /*!< own certificate/key pair(s) */
929
929
mbedtls_x509_crt * ca_chain ; /*!< trusted CAs */
930
930
mbedtls_x509_crl * ca_crl ; /*!< trusted CAs CRLs */
931
+ #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK )
932
+ mbedtls_x509_crt_ca_cb_t f_ca_cb ;
933
+ void * p_ca_cb ;
934
+ #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
931
935
#endif /* MBEDTLS_X509_CRT_PARSE_C */
932
936
933
937
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE )
@@ -1090,6 +1094,12 @@ struct mbedtls_ssl_context
1090
1094
unsigned badmac_seen ; /*!< records with a bad MAC received */
1091
1095
#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
1092
1096
1097
+ #if defined(MBEDTLS_X509_CRT_PARSE_C )
1098
+ /** Callback to customize X.509 certificate chain verification */
1099
+ int (* f_vrfy )(void * , mbedtls_x509_crt * , int , uint32_t * );
1100
+ void * p_vrfy ; /*!< context for X.509 verify callback */
1101
+ #endif
1102
+
1093
1103
mbedtls_ssl_send_t * f_send ; /*!< Callback for network send */
1094
1104
mbedtls_ssl_recv_t * f_recv ; /*!< Callback for network receive */
1095
1105
mbedtls_ssl_recv_timeout_t * f_recv_timeout ;
@@ -1366,13 +1376,17 @@ void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
1366
1376
/**
1367
1377
* \brief Set the verification callback (Optional).
1368
1378
*
1369
- * If set, the verify callback is called for each
1370
- * certificate in the chain. For implementation
1371
- * information, please see \c mbedtls_x509_crt_verify()
1379
+ * If set, the provided verify callback is called for each
1380
+ * certificate in the peer's CRT chain, including the trusted
1381
+ * root. For more information, please see the documentation of
1382
+ * \c mbedtls_x509_crt_verify().
1372
1383
*
1373
- * \param conf SSL configuration
1374
- * \param f_vrfy verification function
1375
- * \param p_vrfy verification parameter
1384
+ * \note For per context callbacks and contexts, please use
1385
+ * mbedtls_ssl_set_verify() instead.
1386
+ *
1387
+ * \param conf The SSL configuration to use.
1388
+ * \param f_vrfy The verification callback to use during CRT verification.
1389
+ * \param p_vrfy The opaque context to be passed to the callback.
1376
1390
*/
1377
1391
void mbedtls_ssl_conf_verify ( mbedtls_ssl_config * conf ,
1378
1392
int (* f_vrfy )(void * , mbedtls_x509_crt * , int , uint32_t * ),
@@ -1490,6 +1504,30 @@ void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
1490
1504
void mbedtls_ssl_set_mtu ( mbedtls_ssl_context * ssl , uint16_t mtu );
1491
1505
#endif /* MBEDTLS_SSL_PROTO_DTLS */
1492
1506
1507
+ #if defined(MBEDTLS_X509_CRT_PARSE_C )
1508
+ /**
1509
+ * \brief Set a connection-specific verification callback (optional).
1510
+ *
1511
+ * If set, the provided verify callback is called for each
1512
+ * certificate in the peer's CRT chain, including the trusted
1513
+ * root. For more information, please see the documentation of
1514
+ * \c mbedtls_x509_crt_verify().
1515
+ *
1516
+ * \note This call is analogous to mbedtls_ssl_conf_verify() but
1517
+ * binds the verification callback and context to an SSL context
1518
+ * as opposed to an SSL configuration.
1519
+ * If mbedtls_ssl_conf_verify() and mbedtls_ssl_set_verify()
1520
+ * are both used, mbedtls_ssl_set_verify() takes precedence.
1521
+ *
1522
+ * \param ssl The SSL context to use.
1523
+ * \param f_vrfy The verification callback to use during CRT verification.
1524
+ * \param p_vrfy The opaque context to be passed to the callback.
1525
+ */
1526
+ void mbedtls_ssl_set_verify ( mbedtls_ssl_context * ssl ,
1527
+ int (* f_vrfy )(void * , mbedtls_x509_crt * , int , uint32_t * ),
1528
+ void * p_vrfy );
1529
+ #endif /* MBEDTLS_X509_CRT_PARSE_C */
1530
+
1493
1531
/**
1494
1532
* \brief Set the timeout period for mbedtls_ssl_read()
1495
1533
* (Default: no timeout.)
@@ -2071,6 +2109,63 @@ void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf,
2071
2109
mbedtls_x509_crt * ca_chain ,
2072
2110
mbedtls_x509_crl * ca_crl );
2073
2111
2112
+ #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK )
2113
+ /**
2114
+ * \brief Set the trusted certificate callback.
2115
+ *
2116
+ * This API allows to register the set of trusted certificates
2117
+ * through a callback, instead of a linked list as configured
2118
+ * by mbedtls_ssl_conf_ca_chain().
2119
+ *
2120
+ * This is useful for example in contexts where a large number
2121
+ * of CAs are used, and the inefficiency of maintaining them
2122
+ * in a linked list cannot be tolerated. It is also useful when
2123
+ * the set of trusted CAs needs to be modified frequently.
2124
+ *
2125
+ * See the documentation of `mbedtls_x509_crt_ca_cb_t` for
2126
+ * more information.
2127
+ *
2128
+ * \param conf The SSL configuration to register the callback with.
2129
+ * \param f_ca_cb The trusted certificate callback to use when verifying
2130
+ * certificate chains.
2131
+ * \param p_ca_cb The context to be passed to \p f_ca_cb (for example,
2132
+ * a reference to a trusted CA database).
2133
+ *
2134
+ * \note This API is incompatible with mbedtls_ssl_conf_ca_chain():
2135
+ * Any call to this function overwrites the values set through
2136
+ * earlier calls to mbedtls_ssl_conf_ca_chain() or
2137
+ * mbedtls_ssl_conf_ca_cb().
2138
+ *
2139
+ * \note This API is incompatible with CA indication in
2140
+ * CertificateRequest messages: A server-side SSL context which
2141
+ * is bound to an SSL configuration that uses a CA callback
2142
+ * configured via mbedtls_ssl_conf_ca_cb(), and which requires
2143
+ * client authentication, will send an empty CA list in the
2144
+ * corresponding CertificateRequest message.
2145
+ *
2146
+ * \note This API is incompatible with mbedtls_ssl_set_hs_ca_chain():
2147
+ * If an SSL context is bound to an SSL configuration which uses
2148
+ * CA callbacks configured via mbedtls_ssl_conf_ca_cb(), then
2149
+ * calls to mbedtls_ssl_set_hs_ca_chain() have no effect.
2150
+ *
2151
+ * \note The use of this API disables the use of restartable ECC
2152
+ * during X.509 CRT signature verification (but doesn't affect
2153
+ * other uses).
2154
+ *
2155
+ * \warning This API is incompatible with the use of CRLs. Any call to
2156
+ * mbedtls_ssl_conf_ca_cb() unsets CRLs configured through
2157
+ * earlier calls to mbedtls_ssl_conf_ca_chain().
2158
+ *
2159
+ * \warning In multi-threaded environments, the callback \p f_ca_cb
2160
+ * must be thread-safe, and it is the user's responsibility
2161
+ * to guarantee this (for example through a mutex
2162
+ * contained in the callback context pointed to by \p p_ca_cb).
2163
+ */
2164
+ void mbedtls_ssl_conf_ca_cb ( mbedtls_ssl_config * conf ,
2165
+ mbedtls_x509_crt_ca_cb_t f_ca_cb ,
2166
+ void * p_ca_cb );
2167
+ #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
2168
+
2074
2169
/**
2075
2170
* \brief Set own certificate chain and private key
2076
2171
*
0 commit comments