2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/ssl.h>
11 #include <internal/quic_tserver.h>
13 /* Type to represent the Fault Injector */
14 typedef struct qtest_fault QTEST_FAULT
;
17 * Structure representing a parsed EncryptedExtension message. Listeners can
18 * make changes to the contents of structure objects as required and the fault
19 * injector will reconstruct the message to be sent on
21 typedef struct qtest_fault_encrypted_extensions
{
22 /* EncryptedExtension messages just have an extensions block */
23 unsigned char *extensions
;
25 } QTEST_ENCRYPTED_EXTENSIONS
;
28 * Given an SSL_CTX for the client and filenames for the server certificate and
29 * keyfile, create a server and client instances as well as a fault injector
32 int qtest_create_quic_objects(SSL_CTX
*clientctx
, char *certfile
, char *keyfile
,
33 QUIC_TSERVER
**qtserv
, SSL
**cssl
,
37 * Free up a Fault Injector instance
39 void qtest_fault_free(QTEST_FAULT
*fault
);
42 * Run the TLS handshake to create a QUIC connection between the client and
45 int qtest_create_quic_connection(QUIC_TSERVER
*qtserv
, SSL
*clientssl
);
48 * Confirm that the server has received the given transport error code.
50 int qtest_check_server_transport_err(QUIC_TSERVER
*qtserv
, uint64_t code
);
53 * Confirm the server has received a protocol error. Equivalent to calling
54 * qtest_check_server_transport_err with a code of QUIC_ERR_PROTOCOL_VIOLATION
56 int qtest_check_server_protocol_err(QUIC_TSERVER
*qtserv
);
59 * Enable tests to listen for pre-encryption QUIC packets being sent
61 typedef int (*qtest_fault_on_packet_plain_cb
)(QTEST_FAULT
*fault
,
67 int qtest_fault_set_packet_plain_listener(QTEST_FAULT
*fault
,
68 qtest_fault_on_packet_plain_cb pplaincb
,
73 * Helper function to be called from a packet_plain_listener callback if it
74 * wants to resize the packet (either to add new data to it, or to truncate it).
75 * The buf provided to packet_plain_listener is over allocated, so this just
76 * changes the logical size and never changes the actual address of the buf.
77 * This will fail if a large resize is attempted that exceeds the over
80 int qtest_fault_resize_plain_packet(QTEST_FAULT
*fault
, size_t newlen
);
83 * Prepend frame data into a packet. To be called from a packet_plain_listener
86 int qtest_fault_prepend_frame(QTEST_FAULT
*fault
, unsigned char *frame
,
90 * The general handshake message listener is sent the entire handshake message
91 * data block, including the handshake header itself
93 typedef int (*qtest_fault_on_handshake_cb
)(QTEST_FAULT
*fault
,
96 void *handshakecbarg
);
98 int qtest_fault_set_handshake_listener(QTEST_FAULT
*fault
,
99 qtest_fault_on_handshake_cb handshakecb
,
100 void *handshakecbarg
);
103 * Helper function to be called from a handshake_listener callback if it wants
104 * to resize the handshake message (either to add new data to it, or to truncate
105 * it). newlen must include the length of the handshake message header. The
106 * handshake message buffer is over allocated, so this just changes the logical
107 * size and never changes the actual address of the buf.
108 * This will fail if a large resize is attempted that exceeds the over
111 int qtest_fault_resize_handshake(QTEST_FAULT
*fault
, size_t newlen
);
114 * TODO(QUIC): Add listeners for specifc types of frame here. E.g. we might
115 * expect to see an "ACK" frame listener which will be passed pre-parsed ack
116 * data that can be modified as required.
120 * Handshake message specific listeners. Unlike the general handshake message
121 * listener these messages are pre-parsed and supplied with message specific
122 * data and exclude the handshake header
124 typedef int (*qtest_fault_on_enc_ext_cb
)(QTEST_FAULT
*fault
,
125 QTEST_ENCRYPTED_EXTENSIONS
*ee
,
129 int qtest_fault_set_hand_enc_ext_listener(QTEST_FAULT
*fault
,
130 qtest_fault_on_enc_ext_cb encextcb
,
133 /* TODO(QUIC): Add listeners for other types of handshake message here */
137 * Helper function to be called from message specific listener callbacks. newlen
138 * is the new length of the specific message excluding the handshake message
139 * header. The buffers provided to the message specific listeners are over
140 * allocated, so this just changes the logical size and never changes the actual
141 * address of the buffer. This will fail if a large resize is attempted that
142 * exceeds the over allocation.
144 int qtest_fault_resize_message(QTEST_FAULT
*fault
, size_t newlen
);
147 * Helper function to delete an extension from an extension block. |exttype| is
148 * the type of the extension to be deleted. |ext| points to the extension block.
149 * On entry |*extlen| contains the length of the extension block. It is updated
150 * with the new length on exit.
152 int qtest_fault_delete_extension(QTEST_FAULT
*fault
,
153 unsigned int exttype
, unsigned char *ext
,
157 * TODO(QUIC): Add additional helper functions for querying extensions here (e.g.
158 * finding or adding them). We could also provide a "listener" API for listening
159 * for specific extension types
163 * Enable tests to listen for post-encryption QUIC packets being sent
165 typedef int (*qtest_fault_on_packet_cipher_cb
)(QTEST_FAULT
*fault
,
166 /* The parsed packet header */
168 /* The packet payload data */
170 /* Length of the payload */
174 int qtest_fault_set_packet_cipher_listener(QTEST_FAULT
*fault
,
175 qtest_fault_on_packet_cipher_cb pciphercb
,
179 * Enable tests to listen for datagrams being sent
181 typedef int (*qtest_fault_on_datagram_cb
)(QTEST_FAULT
*fault
,
186 int qtest_fault_set_datagram_listener(QTEST_FAULT
*fault
,
187 qtest_fault_on_datagram_cb datagramcb
,
188 void *datagramcbarg
);
191 * To be called from a datagram_listener callback. The datagram buffer is over
192 * allocated, so this just changes the logical size and never changes the actual
193 * address of the buffer. This will fail if a large resize is attempted that
194 * exceeds the over allocation.
196 int qtest_fault_resize_datagram(QTEST_FAULT
*fault
, size_t newlen
);