Skip to content

Test mbedtls_ssl_conf_own_cert #10217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 32 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
353eb33
Use TEST_EQUAL(a,b) instead of TEST_ASSERT(a==b)
gilles-peskine-arm May 14, 2025
b6bb3fb
Flatten out mbedtls_test_ssl_endpoint_certificate structure
gilles-peskine-arm May 26, 2025
35a2d9b
Remove testing of mbedtls_ssl_conf_own_cert(NULL)
gilles-peskine-arm May 26, 2025
0677e02
Move timer into the endpoint structure
gilles-peskine-arm May 27, 2025
2744a43
Refactor set_ciphersuites to work on the endpoint structure
gilles-peskine-arm May 27, 2025
c4949d1
mbedtls_ssl_conf_alpn_protocols: declare list elements as const
gilles-peskine-arm May 27, 2025
9b99368
mbedtls_test_ssl_perform_handshake: declare options as const
gilles-peskine-arm May 27, 2025
2996959
Move DTLS context into the endpoint structure
gilles-peskine-arm May 27, 2025
b092e78
New auxiliary function mbedtls_test_ssl_dtls_join_endpoints
gilles-peskine-arm May 27, 2025
6c154e7
Move queue management into mbedtls_test_ssl_dtls_join_endpoints
gilles-peskine-arm May 27, 2025
ca8a9ac
Remove unused parameters to endpoint init/free
gilles-peskine-arm May 27, 2025
07432b9
Unify identical code
gilles-peskine-arm May 27, 2025
e30b5c7
mbedtls_test_ssl_perform_handshake: make client, server pointers
gilles-peskine-arm May 27, 2025
78df6ae
Move renegotiation testing into its own function
gilles-peskine-arm May 27, 2025
e23a6d1
Move serialization testing into its own function
gilles-peskine-arm May 27, 2025
bd95340
Unify SSL version checks between client and server
gilles-peskine-arm May 28, 2025
7a8fd46
Separate test function to perform an SSL connection
gilles-peskine-arm May 28, 2025
27586d8
Move more endpoint configuration into the setup function
gilles-peskine-arm May 28, 2025
fb2ce05
SSL tests: make client authentication more uniform, defaulting on
gilles-peskine-arm May 28, 2025
6e4d245
Move certificate and key parsing to auxiliary functions
gilles-peskine-arm May 27, 2025
a6e71f9
Don't change the configuration after mbedtls_ssl_setup
gilles-peskine-arm Jun 1, 2025
00eb072
mbedtls_test_ssl_endpoint_init: store user_data_n in the endpoint object
gilles-peskine-arm Jun 1, 2025
6edb76c
mbedtls_test_ssl_endpoint_init: split configuration and setup
gilles-peskine-arm Jun 1, 2025
42e8d42
Expand handshake_ciphersuite_select
gilles-peskine-arm Jun 2, 2025
e9c6c85
Simplify ownership of opaque key in SSL test endpoint
gilles-peskine-arm Jun 2, 2025
f697697
Break out key and certificate loading into separate functions
gilles-peskine-arm Jun 2, 2025
972f726
Allow endpoint init to skip loading a key and certificate
gilles-peskine-arm Jun 2, 2025
3c3001e
Automate debug logs in SSL tests more
gilles-peskine-arm Jun 11, 2025
fabb20e
Show debug logs in SSL tests based on a variable
gilles-peskine-arm Jun 11, 2025
df8d383
SSL test debug logs: show endpoint name
gilles-peskine-arm Jun 11, 2025
fb7cb97
Server-side tests for mbedtls_ssl_conf_own_cert
gilles-peskine-arm Jun 12, 2025
9fff313
Comment out known broken test cases
gilles-peskine-arm Jun 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mbedtls_test_ssl_endpoint_init: split configuration and setup
Split `mbedtls_test_ssl_endpoint_init()` into two separate stages:
constructing the SSL configuration, and setting up an SSL session context
with that configuration.

No behavior change.

Signed-off-by: Gilles Peskine <[email protected]>
  • Loading branch information
gilles-peskine-arm committed Jun 1, 2025
commit 6edb76cba4655bc007e51c7f58e69631d0e4eba3
61 changes: 51 additions & 10 deletions tests/include/test/ssl_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,18 +447,59 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep,
int opaque_alg, int opaque_alg2,
int opaque_usage);

/*
* Initializes \p ep structure. It is important to call
* `mbedtls_test_ssl_endpoint_free()` after calling this function
* even if it fails.
/** Initialize the configuration in an SSL endpoint structure.
*
* \note You must call `mbedtls_test_ssl_endpoint_free()` after
* calling this function, even if it fails. This is necessary to
* free data that may have been stored in the endpoint structure.
*
* \param[out] ep The endpoint structure to configure.
* \param endpoint_type #MBEDTLS_SSL_IS_SERVER or #MBEDTLS_SSL_IS_CLIENT.
* \param[in] options The options to use for configuring the endpoint
* structure.
*
* \retval 0 on success, otherwise error code.
*/
int mbedtls_test_ssl_endpoint_init_conf(
mbedtls_test_ssl_endpoint *ep, int endpoint_type,
const mbedtls_test_handshake_test_options *options);

/** Initialize the session context in an endpoint structure.
*
* \note The endpoint structure must have been set up with
* mbedtls_test_ssl_endpoint_init_conf() with the same \p options.
* Between calling mbedtls_test_ssl_endpoint_init_conf() and
* mbedtls_test_ssl_endpoint_init_ssl(), you may configure `ep->ssl`
* further if you know what you're doing.
*
* \note You must call `mbedtls_test_ssl_endpoint_free()` after
* calling this function, even if it fails. This is necessary to
* free data that may have been stored in the endpoint structure.
*
* \param[out] ep The endpoint structure to set up.
* \param[in] options The options used for configuring the endpoint
* structure.
*
* \retval 0 on success, otherwise error code.
*/
int mbedtls_test_ssl_endpoint_init_ssl(
mbedtls_test_ssl_endpoint *ep,
const mbedtls_test_handshake_test_options *options);

/** Initialize the configuration and a context in an SSL endpoint structure.
*
* This function is equivalent to calling
* mbedtls_test_ssl_endpoint_init_conf() followed by
* mbedtls_test_ssl_endpoint_init_ssl().
*
* \note For DTLS, after calling this function on both endpoints,
* call mbedtls_test_ssl_dtls_join_endpoints().
* \note You must call `mbedtls_test_ssl_endpoint_free()` after
* calling this function, even if it fails. This is necessary to
* free data that may have been stored in the endpoint structure.
*
* \p endpoint_type must be set as MBEDTLS_SSL_IS_SERVER or
* MBEDTLS_SSL_IS_CLIENT.
* \p pk_alg the algorithm to use, currently only MBEDTLS_PK_RSA and
* MBEDTLS_PK_ECDSA are supported.
* \param[out] ep The endpoint structure to configure.
* \param endpoint_type #MBEDTLS_SSL_IS_SERVER or #MBEDTLS_SSL_IS_CLIENT.
* \param[in] options The options to use for configuring the endpoint
* structure.
*
* \retval 0 on success, otherwise error code.
*/
Expand Down
31 changes: 29 additions & 2 deletions tests/src/test_helpers/ssl_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep,
return ret;
}

int mbedtls_test_ssl_endpoint_init(
int mbedtls_test_ssl_endpoint_init_conf(
mbedtls_test_ssl_endpoint *ep, int endpoint_type,
const mbedtls_test_handshake_test_options *options)
{
Expand Down Expand Up @@ -968,7 +968,22 @@ int mbedtls_test_ssl_endpoint_init(
ep->user_data_cookie);
mbedtls_ssl_conf_set_user_data_p(&ep->conf, ep);

/* We've finished the configuration. Now set up a context. */
return 0;

exit:
if (ret == 0) {
/* Exiting due to a test assertion that isn't ret == 0 */
ret = -1;
}
return ret;
}

int mbedtls_test_ssl_endpoint_init_ssl(
mbedtls_test_ssl_endpoint *ep,
const mbedtls_test_handshake_test_options *options)
{
int endpoint_type = mbedtls_ssl_conf_get_endpoint(&ep->conf);
int ret = -1;

ret = mbedtls_ssl_setup(&(ep->ssl), &(ep->conf));
TEST_EQUAL(ret, 0);
Expand Down Expand Up @@ -1009,6 +1024,18 @@ int mbedtls_test_ssl_endpoint_init(
return ret;
}

int mbedtls_test_ssl_endpoint_init(
mbedtls_test_ssl_endpoint *ep, int endpoint_type,
const mbedtls_test_handshake_test_options *options)
{
int ret = mbedtls_test_ssl_endpoint_init_conf(ep, endpoint_type, options);
if (ret != 0) {
return ret;
}
ret = mbedtls_test_ssl_endpoint_init_ssl(ep, options);
return ret;
}

void mbedtls_test_ssl_endpoint_free(
mbedtls_test_ssl_endpoint *ep)
{
Expand Down