blob: ac76116e1aa6a45865e4eb4511ed765b218495aa [file] [log] [blame]
Yanray Wang47907a42022-10-24 14:42:01 +08001/** \file ssl_helpers.h
2 *
3 * \brief This file contains helper functions to set up a TLS connection.
4 */
5
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23#ifndef SSL_HELPERS_H
24#define SSL_HELPERS_H
25
Yanray Wang4d07d1c2022-10-27 15:28:16 +080026#include "mbedtls/build_info.h"
27
28#include <string.h>
29
Yanray Wang47907a42022-10-24 14:42:01 +080030#include <test/helpers.h>
Yanray Wang4d07d1c2022-10-27 15:28:16 +080031#include <test/macros.h>
32#include <test/random.h>
33#include <test/psa_crypto_helpers.h>
34
35#if defined(MBEDTLS_SSL_TLS_C)
36#include <ssl_misc.h>
37#include <mbedtls/timing.h>
38#include <mbedtls/debug.h>
39#include "hash_info.h"
40
41#include "test/certs.h"
Yanray Wang55a66192022-10-26 09:57:53 +080042
43#if defined(MBEDTLS_SSL_CACHE_C)
44#include "mbedtls/ssl_cache.h"
45#endif
46
Yanray Wang5ba709c2023-02-03 11:07:56 +080047#if defined(MBEDTLS_USE_PSA_CRYPTO)
48#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \
49 psa_to_ssl_errors, \
50 psa_generic_status_to_mbedtls)
51#endif
52
53#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
54 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
55 defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
56#define MBEDTLS_CAN_HANDLE_RSA_TEST_KEY
57#endif
58enum {
59#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \
60 tls13_label_ ## name,
61 MBEDTLS_SSL_TLS1_3_LABEL_LIST
62#undef MBEDTLS_SSL_TLS1_3_LABEL
63};
64
Yanray Wang55a66192022-10-26 09:57:53 +080065typedef struct mbedtls_test_ssl_log_pattern {
66 const char *pattern;
67 size_t counter;
68} mbedtls_test_ssl_log_pattern;
69
70typedef struct mbedtls_test_handshake_test_options {
71 const char *cipher;
72 mbedtls_ssl_protocol_version client_min_version;
73 mbedtls_ssl_protocol_version client_max_version;
74 mbedtls_ssl_protocol_version server_min_version;
75 mbedtls_ssl_protocol_version server_max_version;
76 mbedtls_ssl_protocol_version expected_negotiated_version;
77 int expected_handshake_result;
78 int expected_ciphersuite;
79 int pk_alg;
80 int opaque_alg;
81 int opaque_alg2;
82 int opaque_usage;
83 data_t *psk_str;
84 int dtls;
85 int srv_auth_mode;
86 int serialize;
87 int mfl;
88 int cli_msg_len;
89 int srv_msg_len;
90 int expected_cli_fragments;
91 int expected_srv_fragments;
92 int renegotiate;
93 int legacy_renegotiation;
94 void *srv_log_obj;
95 void *cli_log_obj;
96 void (*srv_log_fun)(void *, int, const char *, int, const char *);
97 void (*cli_log_fun)(void *, int, const char *, int, const char *);
98 int resize_buffers;
99#if defined(MBEDTLS_SSL_CACHE_C)
100 mbedtls_ssl_cache_context *cache;
101#endif
102} mbedtls_test_handshake_test_options;
103
Yanray Wang25b766f2023-03-15 16:39:05 +0800104/*
105 * Buffer structure for custom I/O callbacks.
106 */
Yanray Wang55a66192022-10-26 09:57:53 +0800107typedef struct mbedtls_test_ssl_buffer {
108 size_t start;
109 size_t content_length;
110 size_t capacity;
111 unsigned char *buffer;
112} mbedtls_test_ssl_buffer;
113
114/*
115 * Context for a message metadata queue (fifo) that is on top of the ring buffer.
116 */
117typedef struct mbedtls_test_ssl_message_queue {
118 size_t *messages;
119 int pos;
120 int num;
121 int capacity;
122} mbedtls_test_ssl_message_queue;
123
124/*
125 * Context for the I/O callbacks simulating network connection.
126 */
127
128#define MBEDTLS_MOCK_SOCKET_CONNECTED 1
129
130typedef struct mbedtls_test_mock_socket {
131 int status;
132 mbedtls_test_ssl_buffer *input;
133 mbedtls_test_ssl_buffer *output;
134 struct mbedtls_test_mock_socket *peer;
135} mbedtls_test_mock_socket;
136
137/* Errors used in the message socket mocks */
138
139#define MBEDTLS_TEST_ERROR_CONTEXT_ERROR -55
140#define MBEDTLS_TEST_ERROR_SEND_FAILED -66
141#define MBEDTLS_TEST_ERROR_RECV_FAILED -77
142
143/*
144 * Structure used as an addon, or a wrapper, around the mocked sockets.
145 * Contains an input queue, to which the other socket pushes metadata,
146 * and an output queue, to which this one pushes metadata. This context is
147 * considered as an owner of the input queue only, which is initialized and
148 * freed in the respective setup and free calls.
149 */
150typedef struct mbedtls_test_message_socket_context {
151 mbedtls_test_ssl_message_queue *queue_input;
152 mbedtls_test_ssl_message_queue *queue_output;
153 mbedtls_test_mock_socket *socket;
154} mbedtls_test_message_socket_context;
155
156#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
157
158/*
159 * Structure with endpoint's certificates for SSL communication tests.
160 */
161typedef struct mbedtls_test_ssl_endpoint_certificate {
162 mbedtls_x509_crt *ca_cert;
163 mbedtls_x509_crt *cert;
164 mbedtls_pk_context *pkey;
165} mbedtls_test_ssl_endpoint_certificate;
166
167/*
168 * Endpoint structure for SSL communication tests.
169 */
170typedef struct mbedtls_test_ssl_endpoint {
171 const char *name;
172 mbedtls_ssl_context ssl;
173 mbedtls_ssl_config conf;
174 mbedtls_test_mock_socket socket;
175 mbedtls_test_ssl_endpoint_certificate cert;
176} mbedtls_test_ssl_endpoint;
177
178#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
Yanray Wang47907a42022-10-24 14:42:01 +0800179
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800180/*
181 * This function can be passed to mbedtls to receive output logs from it. In
182 * this case, it will count the instances of a mbedtls_test_ssl_log_pattern
183 * in the received logged messages.
184 */
185void mbedtls_test_ssl_log_analyzer(void *ctx, int level,
186 const char *file, int line,
187 const char *str);
188
189void mbedtls_test_init_handshake_options(
190 mbedtls_test_handshake_test_options *opts);
191
192void mbedtls_test_free_handshake_options(
193 mbedtls_test_handshake_test_options *opts);
194
195/*
196 * Initialises \p buf. After calling this function it is safe to call
197 * `mbedtls_test_ssl_buffer_free()` on \p buf.
198 */
199void mbedtls_test_ssl_buffer_init(mbedtls_test_ssl_buffer *buf);
200
201/*
202 * Sets up \p buf. After calling this function it is safe to call
203 * `mbedtls_test_ssl_buffer_put()` and `mbedtls_test_ssl_buffer_get()`
204 * on \p buf.
205 */
206int mbedtls_test_ssl_buffer_setup(mbedtls_test_ssl_buffer *buf,
207 size_t capacity);
208
209void mbedtls_test_ssl_buffer_free(mbedtls_test_ssl_buffer *buf);
210
211/*
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800212 * Puts \p input_len bytes from the \p input buffer into the ring buffer \p buf.
213 *
214 * \p buf must have been initialized and set up by calling
215 * `mbedtls_test_ssl_buffer_init()` and `mbedtls_test_ssl_buffer_setup()`.
216 *
217 * \retval \p input_len, if the data fits.
218 * \retval 0 <= value < \p input_len, if the data does not fit.
219 * \retval -1, if \p buf is NULL, it hasn't been set up or \p input_len is not
220 * zero and \p input is NULL.
221 */
222int mbedtls_test_ssl_buffer_put(mbedtls_test_ssl_buffer *buf,
223 const unsigned char *input, size_t input_len);
224
225/*
226 * Gets \p output_len bytes from the ring buffer \p buf into the
227 * \p output buffer. The output buffer can be NULL, in this case a part of the
228 * ring buffer will be dropped, if the requested length is available.
229 *
230 * \p buf must have been initialized and set up by calling
231 * `mbedtls_test_ssl_buffer_init()` and `mbedtls_test_ssl_buffer_setup()`.
232 *
233 * \retval \p output_len, if the data is available.
234 * \retval 0 <= value < \p output_len, if the data is not available.
235 * \retval -1, if \buf is NULL or it hasn't been set up.
236 */
237int mbedtls_test_ssl_buffer_get(mbedtls_test_ssl_buffer *buf,
238 unsigned char *output, size_t output_len);
239
240/*
241 * Errors used in the message transport mock tests
242 */
243 #define MBEDTLS_TEST_ERROR_ARG_NULL -11
244 #define MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED -44
245
246/*
247 * Setup and free functions for the message metadata queue.
248 *
249 * \p capacity describes the number of message metadata chunks that can be held
250 * within the queue.
251 *
252 * \retval 0, if a metadata queue of a given length can be allocated.
253 * \retval MBEDTLS_ERR_SSL_ALLOC_FAILED, if allocation failed.
254 */
255int mbedtls_test_ssl_message_queue_setup(
256 mbedtls_test_ssl_message_queue *queue, size_t capacity);
257
258void mbedtls_test_ssl_message_queue_free(
259 mbedtls_test_ssl_message_queue *queue);
260
261/*
262 * Push message length information onto the message metadata queue.
263 * This will become the last element to leave it (fifo).
264 *
265 * \retval MBEDTLS_TEST_ERROR_ARG_NULL, if the queue is null.
266 * \retval MBEDTLS_ERR_SSL_WANT_WRITE, if the queue is full.
267 * \retval \p len, if the push was successful.
268 */
269int mbedtls_test_ssl_message_queue_push_info(
270 mbedtls_test_ssl_message_queue *queue, size_t len);
271
272/*
273 * Pop information about the next message length from the queue. This will be
274 * the oldest inserted message length(fifo). \p msg_len can be null, in which
275 * case the data will be popped from the queue but not copied anywhere.
276 *
277 * \retval MBEDTLS_TEST_ERROR_ARG_NULL, if the queue is null.
278 * \retval MBEDTLS_ERR_SSL_WANT_READ, if the queue is empty.
279 * \retval message length, if the pop was successful, up to the given
280 \p buf_len.
281 */
282int mbedtls_test_ssl_message_queue_pop_info(
283 mbedtls_test_ssl_message_queue *queue, size_t buf_len);
284
285/*
286 * Setup and teardown functions for mock sockets.
287 */
Yanray Wang5f86a422023-03-15 16:02:29 +0800288void mbedtls_test_mock_socket_init(mbedtls_test_mock_socket *socket);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800289
290/*
291 * Closes the socket \p socket.
292 *
293 * \p socket must have been previously initialized by calling
Yanray Wang5f86a422023-03-15 16:02:29 +0800294 * mbedtls_test_mock_socket_init().
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800295 *
296 * This function frees all allocated resources and both sockets are aware of the
297 * new connection state.
298 *
299 * That is, this function does not simulate half-open TCP connections and the
300 * phenomenon that when closing a UDP connection the peer is not aware of the
301 * connection having been closed.
302 */
303void mbedtls_test_mock_socket_close(mbedtls_test_mock_socket *socket);
304
305/*
306 * Establishes a connection between \p peer1 and \p peer2.
307 *
308 * \p peer1 and \p peer2 must have been previously initialized by calling
Yanray Wang5f86a422023-03-15 16:02:29 +0800309 * mbedtls_test_mock_socket_init().
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800310 *
311 * The capacities of the internal buffers are set to \p bufsize. Setting this to
312 * the correct value allows for simulation of MTU, sanity testing the mock
313 * implementation and mocking TCP connections with lower memory cost.
314 */
315int mbedtls_test_mock_socket_connect(mbedtls_test_mock_socket *peer1,
316 mbedtls_test_mock_socket *peer2,
317 size_t bufsize);
318
319
320/*
321 * Callbacks for simulating blocking I/O over connection-oriented transport.
322 */
Yanray Wangaf727a22023-03-13 19:22:36 +0800323int mbedtls_test_mock_tcp_send_b(void *ctx,
324 const unsigned char *buf, size_t len);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800325
326int mbedtls_test_mock_tcp_recv_b(void *ctx, unsigned char *buf, size_t len);
327
328/*
329 * Callbacks for simulating non-blocking I/O over connection-oriented transport.
330 */
Yanray Wangaf727a22023-03-13 19:22:36 +0800331int mbedtls_test_mock_tcp_send_nb(void *ctx,
332 const unsigned char *buf, size_t len);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800333
334int mbedtls_test_mock_tcp_recv_nb(void *ctx, unsigned char *buf, size_t len);
335
336void mbedtls_test_message_socket_init(
337 mbedtls_test_message_socket_context *ctx);
338
339/*
340 * Setup a given message socket context including initialization of
341 * input/output queues to a chosen capacity of messages. Also set the
342 * corresponding mock socket.
343 *
344 * \retval 0, if everything succeeds.
345 * \retval MBEDTLS_ERR_SSL_ALLOC_FAILED, if allocation of a message
346 * queue failed.
347 */
348int mbedtls_test_message_socket_setup(
349 mbedtls_test_ssl_message_queue *queue_input,
350 mbedtls_test_ssl_message_queue *queue_output,
Yanray Wangd19894f2023-03-16 11:47:39 +0800351 size_t queue_capacity,
352 mbedtls_test_mock_socket *socket,
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800353 mbedtls_test_message_socket_context *ctx);
354
355/*
356 * Close a given message socket context, along with the socket itself. Free the
357 * memory allocated by the input queue.
358 */
359void mbedtls_test_message_socket_close(
360 mbedtls_test_message_socket_context *ctx);
361
362/*
363 * Send one message through a given message socket context.
364 *
365 * \retval \p len, if everything succeeds.
366 * \retval MBEDTLS_TEST_ERROR_CONTEXT_ERROR, if any of the needed context
367 * elements or the context itself is null.
368 * \retval MBEDTLS_TEST_ERROR_SEND_FAILED if
369 * mbedtls_test_mock_tcp_send_b failed.
370 * \retval MBEDTLS_ERR_SSL_WANT_WRITE, if the output queue is full.
371 *
372 * This function will also return any error from
373 * mbedtls_test_ssl_message_queue_push_info.
374 */
Yanray Wangaf727a22023-03-13 19:22:36 +0800375int mbedtls_test_mock_tcp_send_msg(void *ctx,
376 const unsigned char *buf, size_t len);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800377
378/*
379 * Receive one message from a given message socket context and return message
380 * length or an error.
381 *
382 * \retval message length, if everything succeeds.
383 * \retval MBEDTLS_TEST_ERROR_CONTEXT_ERROR, if any of the needed context
384 * elements or the context itself is null.
385 * \retval MBEDTLS_TEST_ERROR_RECV_FAILED if
386 * mbedtls_test_mock_tcp_recv_b failed.
387 *
388 * This function will also return any error other than
Yanray Wang5e22a922023-03-16 14:57:54 +0800389 * MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED from test_ssl_message_queue_peek_info.
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800390 */
Yanray Wangaf727a22023-03-13 19:22:36 +0800391int mbedtls_test_mock_tcp_recv_msg(void *ctx,
392 unsigned char *buf, size_t buf_len);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800393
394#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
395
396/*
397 * Initializes \p ep_cert structure and assigns it to endpoint
398 * represented by \p ep.
399 *
400 * \retval 0 on success, otherwise error code.
401 */
402int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep,
403 int pk_alg,
404 int opaque_alg, int opaque_alg2,
405 int opaque_usage);
406
407/*
408 * Initializes \p ep structure. It is important to call
409 * `mbedtls_test_ssl_endpoint_free()` after calling this function
410 * even if it fails.
411 *
412 * \p endpoint_type must be set as MBEDTLS_SSL_IS_SERVER or
413 * MBEDTLS_SSL_IS_CLIENT.
414 * \p pk_alg the algorithm to use, currently only MBEDTLS_PK_RSA and
415 * MBEDTLS_PK_ECDSA are supported.
416 * \p dtls_context - in case of DTLS - this is the context handling metadata.
417 * \p input_queue - used only in case of DTLS.
418 * \p output_queue - used only in case of DTLS.
419 *
420 * \retval 0 on success, otherwise error code.
421 */
422int mbedtls_test_ssl_endpoint_init(
423 mbedtls_test_ssl_endpoint *ep, int endpoint_type,
424 mbedtls_test_handshake_test_options *options,
425 mbedtls_test_message_socket_context *dtls_context,
426 mbedtls_test_ssl_message_queue *input_queue,
427 mbedtls_test_ssl_message_queue *output_queue,
428 uint16_t *group_list);
429
430/*
431 * Deinitializes endpoint represented by \p ep.
432 */
433void mbedtls_test_ssl_endpoint_free(
434 mbedtls_test_ssl_endpoint *ep,
435 mbedtls_test_message_socket_context *context);
436
437/*
438 * This function moves ssl handshake from \p ssl to prescribed \p state.
439 * /p second_ssl is used as second endpoint and their sockets have to be
440 * connected before calling this function.
441 *
442 * \retval 0 on success, otherwise error code.
443 */
444int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl,
445 mbedtls_ssl_context *second_ssl,
446 int state);
447
448#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
449
Yanray Wang1fca4de2023-02-06 12:10:48 +0800450/*
451 * Helper function setting up inverse record transformations
452 * using given cipher, hash, EtM mode, authentication tag length,
453 * and version.
454 */
455#define CHK(x) \
456 do \
457 { \
458 if (!(x)) \
459 { \
460 ret = -1; \
461 goto cleanup; \
462 } \
463 } while (0)
464
Yanray Wang25b766f2023-03-15 16:39:05 +0800465#if MBEDTLS_SSL_CID_OUT_LEN_MAX > MBEDTLS_SSL_CID_IN_LEN_MAX
466#define SSL_CID_LEN_MIN MBEDTLS_SSL_CID_IN_LEN_MAX
467#else
468#define SSL_CID_LEN_MIN MBEDTLS_SSL_CID_OUT_LEN_MAX
469#endif
470
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800471#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
472 defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_AES_C)
473int mbedtls_test_psa_cipher_encrypt_helper(mbedtls_ssl_transform *transform,
474 const unsigned char *iv,
475 size_t iv_len,
476 const unsigned char *input,
477 size_t ilen,
478 unsigned char *output,
479 size_t *olen);
480#endif /* MBEDTLS_SSL_PROTO_TLS1_2 && MBEDTLS_CIPHER_MODE_CBC &&
481 MBEDTLS_AES_C */
482
483int mbedtls_test_ssl_build_transforms(mbedtls_ssl_transform *t_in,
484 mbedtls_ssl_transform *t_out,
485 int cipher_type, int hash_id,
486 int etm, int tag_mode,
487 mbedtls_ssl_protocol_version tls_version,
488 size_t cid0_len,
489 size_t cid1_len);
490
491/*
492 * Populate a session structure for serialization tests.
493 * Choose dummy values, mostly non-0 to distinguish from the init default.
494 */
495int mbedtls_test_ssl_tls12_populate_session(mbedtls_ssl_session *session,
496 int ticket_len,
497 const char *crt_file);
498
499#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
500int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session,
501 int ticket_len,
502 int endpoint_type);
503#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
504
505/*
506 * Perform data exchanging between \p ssl_1 and \p ssl_2 and check if the
507 * message was sent in the correct number of fragments.
508 *
509 * /p ssl_1 and /p ssl_2 Endpoints represented by mbedtls_ssl_context. Both
510 * of them must be initialized and connected
511 * beforehand.
512 * /p msg_len_1 and /p msg_len_2 specify the size of the message to send.
513 * /p expected_fragments_1 and /p expected_fragments_2 determine in how many
514 * fragments the message should be sent.
515 * expected_fragments is 0: can be used for DTLS testing while the message
516 * size is larger than MFL. In that case the message
517 * cannot be fragmented and sent to the second
518 * endpoint.
519 * This value can be used for negative tests.
520 * expected_fragments is 1: can be used for TLS/DTLS testing while the
521 * message size is below MFL
522 * expected_fragments > 1: can be used for TLS testing while the message
523 * size is larger than MFL
524 *
525 * \retval 0 on success, otherwise error code.
526 */
527int mbedtls_exchange_data(mbedtls_ssl_context *ssl_1,
528 int msg_len_1, const int expected_fragments_1,
529 mbedtls_ssl_context *ssl_2,
530 int msg_len_2, const int expected_fragments_2);
531
532#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
533void mbedtls_test_ssl_perform_handshake(
534 mbedtls_test_handshake_test_options *options);
535#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
536
537#if defined(MBEDTLS_TEST_HOOKS)
538/*
539 * Tweak vector lengths in a TLS 1.3 Certificate message
540 *
541 * \param[in] buf Buffer containing the Certificate message to tweak
542 * \param[in]]out] end End of the buffer to parse
543 * \param tweak Tweak identifier (from 1 to the number of tweaks).
544 * \param[out] expected_result Error code expected from the parsing function
545 * \param[out] args Arguments of the MBEDTLS_SSL_CHK_BUF_READ_PTR call that
546 * is expected to fail. All zeroes if no
547 * MBEDTLS_SSL_CHK_BUF_READ_PTR failure is expected.
548 */
549int tweak_tls13_certificate_msg_vector_len(
550 unsigned char *buf, unsigned char **end, int tweak,
551 int *expected_result, mbedtls_ssl_chk_buf_ptr_args *args);
552#endif /* MBEDTLS_TEST_HOOKS */
Yanray Wang1db628f2023-02-03 11:01:29 +0800553
554#define ECJPAKE_TEST_PWD "bla"
555
556#if defined(MBEDTLS_USE_PSA_CRYPTO)
557#define ECJPAKE_TEST_SET_PASSWORD(exp_ret_val) \
558 ret = (use_opaque_arg) ? \
559 mbedtls_ssl_set_hs_ecjpake_password_opaque(&ssl, pwd_slot) : \
560 mbedtls_ssl_set_hs_ecjpake_password(&ssl, pwd_string, pwd_len); \
561 TEST_EQUAL(ret, exp_ret_val)
562#else
563#define ECJPAKE_TEST_SET_PASSWORD(exp_ret_val) \
564 ret = mbedtls_ssl_set_hs_ecjpake_password(&ssl, \
565 pwd_string, pwd_len); \
566 TEST_EQUAL(ret, exp_ret_val)
567#endif /* MBEDTLS_USE_PSA_CRYPTO */
568
Yanray Wang09a6f7e2023-02-03 11:04:38 +0800569#define TEST_AVAILABLE_ECC(tls_id_, group_id_, psa_family_, psa_bits_) \
570 TEST_EQUAL(mbedtls_ssl_get_ecp_group_id_from_tls_id(tls_id_), \
571 group_id_); \
572 TEST_EQUAL(mbedtls_ssl_get_tls_id_from_ecp_group_id(group_id_), \
573 tls_id_); \
574 TEST_EQUAL(mbedtls_ssl_get_psa_curve_info_from_tls_id(tls_id_, \
575 &psa_family, &psa_bits), PSA_SUCCESS); \
576 TEST_EQUAL(psa_family_, psa_family); \
577 TEST_EQUAL(psa_bits_, psa_bits);
578
579#define TEST_UNAVAILABLE_ECC(tls_id_, group_id_, psa_family_, psa_bits_) \
580 TEST_EQUAL(mbedtls_ssl_get_ecp_group_id_from_tls_id(tls_id_), \
581 MBEDTLS_ECP_DP_NONE); \
582 TEST_EQUAL(mbedtls_ssl_get_tls_id_from_ecp_group_id(group_id_), \
583 0); \
584 TEST_EQUAL(mbedtls_ssl_get_psa_curve_info_from_tls_id(tls_id_, \
585 &psa_family, &psa_bits), \
586 PSA_ERROR_NOT_SUPPORTED);
587
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800588#endif /* MBEDTLS_SSL_TLS_C */
589
Yanray Wang47907a42022-10-24 14:42:01 +0800590#endif /* SSL_HELPERS_H */