mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Move the renamed typedef statements to ssl_helpers.h
With this change, the renamed typedef statements (commit abfdcd8
)
are moved from test_suite_ssl.function into ssl_helpers.h
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
@ -25,4 +25,124 @@
|
|||||||
|
|
||||||
#include <test/helpers.h>
|
#include <test/helpers.h>
|
||||||
|
|
||||||
|
#include <mbedtls/ssl.h>
|
||||||
|
#include <mbedtls/ctr_drbg.h>
|
||||||
|
#include <mbedtls/entropy.h>
|
||||||
|
|
||||||
|
typedef struct mbedtls_test_ssl_log_pattern {
|
||||||
|
const char *pattern;
|
||||||
|
size_t counter;
|
||||||
|
} mbedtls_test_ssl_log_pattern;
|
||||||
|
|
||||||
|
/* Invalid minor version used when not specifying a min/max version or expecting a test to fail */
|
||||||
|
#define TEST_SSL_MINOR_VERSION_NONE -1
|
||||||
|
|
||||||
|
typedef struct mbedtls_test_handshake_test_options {
|
||||||
|
const char *cipher;
|
||||||
|
int client_min_version;
|
||||||
|
int client_max_version;
|
||||||
|
int server_min_version;
|
||||||
|
int server_max_version;
|
||||||
|
int expected_negotiated_version;
|
||||||
|
int pk_alg;
|
||||||
|
data_t *psk_str;
|
||||||
|
int dtls;
|
||||||
|
int srv_auth_mode;
|
||||||
|
int serialize;
|
||||||
|
int mfl;
|
||||||
|
int cli_msg_len;
|
||||||
|
int srv_msg_len;
|
||||||
|
int expected_cli_fragments;
|
||||||
|
int expected_srv_fragments;
|
||||||
|
int renegotiate;
|
||||||
|
int legacy_renegotiation;
|
||||||
|
void *srv_log_obj;
|
||||||
|
void *cli_log_obj;
|
||||||
|
void (*srv_log_fun)(void *, int, const char *, int, const char *);
|
||||||
|
void (*cli_log_fun)(void *, int, const char *, int, const char *);
|
||||||
|
int resize_buffers;
|
||||||
|
} mbedtls_test_handshake_test_options;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Buffer structure for custom I/O callbacks.
|
||||||
|
*/
|
||||||
|
typedef struct mbedtls_test_ssl_buffer {
|
||||||
|
size_t start;
|
||||||
|
size_t content_length;
|
||||||
|
size_t capacity;
|
||||||
|
unsigned char *buffer;
|
||||||
|
} mbedtls_test_ssl_buffer;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Context for a message metadata queue (fifo) that is on top of the ring buffer.
|
||||||
|
*/
|
||||||
|
typedef struct mbedtls_test_ssl_message_queue {
|
||||||
|
size_t *messages;
|
||||||
|
int pos;
|
||||||
|
int num;
|
||||||
|
int capacity;
|
||||||
|
} mbedtls_test_ssl_message_queue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Context for the I/O callbacks simulating network connection.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MBEDTLS_MOCK_SOCKET_CONNECTED 1
|
||||||
|
|
||||||
|
typedef struct mbedtls_test_mock_socket {
|
||||||
|
int status;
|
||||||
|
mbedtls_test_ssl_buffer *input;
|
||||||
|
mbedtls_test_ssl_buffer *output;
|
||||||
|
struct mbedtls_test_mock_socket *peer;
|
||||||
|
} mbedtls_test_mock_socket;
|
||||||
|
|
||||||
|
/* Errors used in the message socket mocks */
|
||||||
|
|
||||||
|
#define MBEDTLS_TEST_ERROR_CONTEXT_ERROR -55
|
||||||
|
#define MBEDTLS_TEST_ERROR_SEND_FAILED -66
|
||||||
|
#define MBEDTLS_TEST_ERROR_RECV_FAILED -77
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure used as an addon, or a wrapper, around the mocked sockets.
|
||||||
|
* Contains an input queue, to which the other socket pushes metadata,
|
||||||
|
* and an output queue, to which this one pushes metadata. This context is
|
||||||
|
* considered as an owner of the input queue only, which is initialized and
|
||||||
|
* freed in the respective setup and free calls.
|
||||||
|
*/
|
||||||
|
typedef struct mbedtls_test_message_socket_context {
|
||||||
|
mbedtls_test_ssl_message_queue *queue_input;
|
||||||
|
mbedtls_test_ssl_message_queue *queue_output;
|
||||||
|
mbedtls_test_mock_socket *socket;
|
||||||
|
} mbedtls_test_message_socket_context;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \
|
||||||
|
defined(MBEDTLS_CERTS_C) && \
|
||||||
|
defined(MBEDTLS_ENTROPY_C) && \
|
||||||
|
defined(MBEDTLS_CTR_DRBG_C)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure with endpoint's certificates for SSL communication tests.
|
||||||
|
*/
|
||||||
|
typedef struct mbedtls_test_ssl_endpoint_certificate {
|
||||||
|
mbedtls_x509_crt *ca_cert;
|
||||||
|
mbedtls_x509_crt *cert;
|
||||||
|
mbedtls_pk_context *pkey;
|
||||||
|
} mbedtls_test_ssl_endpoint_certificate;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Endpoint structure for SSL communication tests.
|
||||||
|
*/
|
||||||
|
typedef struct mbedtls_test_ssl_endpoint {
|
||||||
|
const char *name;
|
||||||
|
mbedtls_ssl_context ssl;
|
||||||
|
mbedtls_ssl_config conf;
|
||||||
|
mbedtls_ctr_drbg_context ctr_drbg;
|
||||||
|
mbedtls_entropy_context entropy;
|
||||||
|
mbedtls_test_mock_socket socket;
|
||||||
|
mbedtls_test_ssl_endpoint_certificate cert;
|
||||||
|
} mbedtls_test_ssl_endpoint;
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C &&
|
||||||
|
MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
|
||||||
|
|
||||||
#endif /* SSL_HELPERS_H */
|
#endif /* SSL_HELPERS_H */
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
/* BEGIN_HEADER */
|
/* BEGIN_HEADER */
|
||||||
#include <mbedtls/ssl.h>
|
|
||||||
#include <mbedtls/ssl_internal.h>
|
#include <mbedtls/ssl_internal.h>
|
||||||
#include <mbedtls/ctr_drbg.h>
|
|
||||||
#include <mbedtls/entropy.h>
|
|
||||||
#include <mbedtls/certs.h>
|
#include <mbedtls/certs.h>
|
||||||
#include <mbedtls/timing.h>
|
#include <mbedtls/timing.h>
|
||||||
#include <mbedtls/debug.h>
|
#include <mbedtls/debug.h>
|
||||||
@ -26,11 +23,6 @@ enum {
|
|||||||
#undef MBEDTLS_SSL_TLS1_3_LABEL
|
#undef MBEDTLS_SSL_TLS1_3_LABEL
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct mbedtls_test_ssl_log_pattern {
|
|
||||||
const char *pattern;
|
|
||||||
size_t counter;
|
|
||||||
} mbedtls_test_ssl_log_pattern;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function can be passed to mbedtls to receive output logs from it. In
|
* This function can be passed to mbedtls to receive output logs from it. In
|
||||||
* this case, it will count the instances of a mbedtls_test_ssl_log_pattern in the received
|
* this case, it will count the instances of a mbedtls_test_ssl_log_pattern in the received
|
||||||
@ -53,35 +45,6 @@ void log_analyzer(void *ctx, int level,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invalid minor version used when not specifying a min/max version or expecting a test to fail */
|
|
||||||
#define TEST_SSL_MINOR_VERSION_NONE -1
|
|
||||||
|
|
||||||
typedef struct mbedtls_test_handshake_test_options {
|
|
||||||
const char *cipher;
|
|
||||||
int client_min_version;
|
|
||||||
int client_max_version;
|
|
||||||
int server_min_version;
|
|
||||||
int server_max_version;
|
|
||||||
int expected_negotiated_version;
|
|
||||||
int pk_alg;
|
|
||||||
data_t *psk_str;
|
|
||||||
int dtls;
|
|
||||||
int srv_auth_mode;
|
|
||||||
int serialize;
|
|
||||||
int mfl;
|
|
||||||
int cli_msg_len;
|
|
||||||
int srv_msg_len;
|
|
||||||
int expected_cli_fragments;
|
|
||||||
int expected_srv_fragments;
|
|
||||||
int renegotiate;
|
|
||||||
int legacy_renegotiation;
|
|
||||||
void *srv_log_obj;
|
|
||||||
void *cli_log_obj;
|
|
||||||
void (*srv_log_fun)(void *, int, const char *, int, const char *);
|
|
||||||
void (*cli_log_fun)(void *, int, const char *, int, const char *);
|
|
||||||
int resize_buffers;
|
|
||||||
} mbedtls_test_handshake_test_options;
|
|
||||||
|
|
||||||
void init_handshake_options(mbedtls_test_handshake_test_options *opts)
|
void init_handshake_options(mbedtls_test_handshake_test_options *opts)
|
||||||
{
|
{
|
||||||
opts->cipher = "";
|
opts->cipher = "";
|
||||||
@ -108,16 +71,6 @@ void init_handshake_options(mbedtls_test_handshake_test_options *opts)
|
|||||||
opts->cli_log_fun = NULL;
|
opts->cli_log_fun = NULL;
|
||||||
opts->resize_buffers = 1;
|
opts->resize_buffers = 1;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Buffer structure for custom I/O callbacks.
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct mbedtls_test_ssl_buffer {
|
|
||||||
size_t start;
|
|
||||||
size_t content_length;
|
|
||||||
size_t capacity;
|
|
||||||
unsigned char *buffer;
|
|
||||||
} mbedtls_test_ssl_buffer;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialises \p buf. After calling this function it is safe to call
|
* Initialises \p buf. After calling this function it is safe to call
|
||||||
@ -260,16 +213,6 @@ int mbedtls_test_buffer_get(mbedtls_test_ssl_buffer *buf,
|
|||||||
#define MBEDTLS_TEST_ERROR_ARG_NULL -11
|
#define MBEDTLS_TEST_ERROR_ARG_NULL -11
|
||||||
#define MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED -44
|
#define MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED -44
|
||||||
|
|
||||||
/*
|
|
||||||
* Context for a message metadata queue (fifo) that is on top of the ring buffer.
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_test_ssl_message_queue {
|
|
||||||
size_t *messages;
|
|
||||||
int pos;
|
|
||||||
int num;
|
|
||||||
int capacity;
|
|
||||||
} mbedtls_test_ssl_message_queue;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup and free functions for the message metadata queue.
|
* Setup and free functions for the message metadata queue.
|
||||||
*
|
*
|
||||||
@ -391,18 +334,6 @@ int mbedtls_test_message_queue_peek_info(mbedtls_test_ssl_message_queue *queue,
|
|||||||
*msg_len = queue->messages[queue->pos];
|
*msg_len = queue->messages[queue->pos];
|
||||||
return (*msg_len > buf_len) ? MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED : 0;
|
return (*msg_len > buf_len) ? MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED : 0;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Context for the I/O callbacks simulating network connection.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MBEDTLS_MOCK_SOCKET_CONNECTED 1
|
|
||||||
|
|
||||||
typedef struct mbedtls_test_mock_socket {
|
|
||||||
int status;
|
|
||||||
mbedtls_test_ssl_buffer *input;
|
|
||||||
mbedtls_test_ssl_buffer *output;
|
|
||||||
struct mbedtls_test_mock_socket *peer;
|
|
||||||
} mbedtls_test_mock_socket;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup and teardown functions for mock sockets.
|
* Setup and teardown functions for mock sockets.
|
||||||
@ -564,25 +495,6 @@ int mbedtls_mock_tcp_recv_nb(void *ctx, unsigned char *buf, size_t len)
|
|||||||
return mbedtls_test_buffer_get(socket->input, buf, len);
|
return mbedtls_test_buffer_get(socket->input, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Errors used in the message socket mocks */
|
|
||||||
|
|
||||||
#define MBEDTLS_TEST_ERROR_CONTEXT_ERROR -55
|
|
||||||
#define MBEDTLS_TEST_ERROR_SEND_FAILED -66
|
|
||||||
#define MBEDTLS_TEST_ERROR_RECV_FAILED -77
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Structure used as an addon, or a wrapper, around the mocked sockets.
|
|
||||||
* Contains an input queue, to which the other socket pushes metadata,
|
|
||||||
* and an output queue, to which this one pushes metadata. This context is
|
|
||||||
* considered as an owner of the input queue only, which is initialized and
|
|
||||||
* freed in the respective setup and free calls.
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_test_message_socket_context {
|
|
||||||
mbedtls_test_ssl_message_queue *queue_input;
|
|
||||||
mbedtls_test_ssl_message_queue *queue_output;
|
|
||||||
mbedtls_test_mock_socket *socket;
|
|
||||||
} mbedtls_test_message_socket_context;
|
|
||||||
|
|
||||||
void mbedtls_message_socket_init(mbedtls_test_message_socket_context *ctx)
|
void mbedtls_message_socket_init(mbedtls_test_message_socket_context *ctx)
|
||||||
{
|
{
|
||||||
ctx->queue_input = NULL;
|
ctx->queue_input = NULL;
|
||||||
@ -733,28 +645,6 @@ int mbedtls_mock_tcp_recv_msg(void *ctx, unsigned char *buf, size_t buf_len)
|
|||||||
defined(MBEDTLS_ENTROPY_C) && \
|
defined(MBEDTLS_ENTROPY_C) && \
|
||||||
defined(MBEDTLS_CTR_DRBG_C)
|
defined(MBEDTLS_CTR_DRBG_C)
|
||||||
|
|
||||||
/*
|
|
||||||
* Structure with endpoint's certificates for SSL communication tests.
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_test_ssl_endpoint_certificate {
|
|
||||||
mbedtls_x509_crt *ca_cert;
|
|
||||||
mbedtls_x509_crt *cert;
|
|
||||||
mbedtls_pk_context *pkey;
|
|
||||||
} mbedtls_test_ssl_endpoint_certificate;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Endpoint structure for SSL communication tests.
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_test_ssl_endpoint {
|
|
||||||
const char *name;
|
|
||||||
mbedtls_ssl_context ssl;
|
|
||||||
mbedtls_ssl_config conf;
|
|
||||||
mbedtls_ctr_drbg_context ctr_drbg;
|
|
||||||
mbedtls_entropy_context entropy;
|
|
||||||
mbedtls_test_mock_socket socket;
|
|
||||||
mbedtls_test_ssl_endpoint_certificate cert;
|
|
||||||
} mbedtls_test_ssl_endpoint;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deinitializes certificates from endpoint represented by \p ep.
|
* Deinitializes certificates from endpoint represented by \p ep.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user