]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/helpers/quictestlib.h
Add explanatory comments to say what happens during resizing of buffers
[thirdparty/openssl.git] / test / helpers / quictestlib.h
CommitLineData
adef87a2
MC
1/*
2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10#include <openssl/ssl.h>
11#include <internal/quic_tserver.h>
12
da81f1e5 13/* Type to represent the Fault Injector */
adef87a2
MC
14typedef struct ossl_quic_fault OSSL_QUIC_FAULT;
15
da81f1e5 16/*
47d905fd 17 * Structure representing a parsed EncryptedExtension message. Listeners can
da81f1e5
MC
18 * make changes to the contents of structure objects as required and the fault
19 * injector will reconstruct the message to be sent on
20 */
6d1f6933 21typedef struct ossl_qf_encrypted_extensions {
da81f1e5 22 /* EncryptedExtension messages just have an extensions block */
6d1f6933
MC
23 unsigned char *extensions;
24 size_t extensionslen;
25} OSSL_QF_ENCRYPTED_EXTENSIONS;
26
da81f1e5
MC
27/*
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
30 * instance
31 */
adef87a2
MC
32int qtest_create_quic_objects(SSL_CTX *clientctx, char *certfile, char *keyfile,
33 QUIC_TSERVER **qtserv, SSL **cssl,
34 OSSL_QUIC_FAULT **fault);
da81f1e5
MC
35
36/*
37 * Free up a Fault Injector instance
38 */
39void ossl_quic_fault_free(OSSL_QUIC_FAULT *fault);
40
41/*
42 * Run the TLS handshake to create a QUIC connection between the client and
43 * server.
44 */
adef87a2 45int qtest_create_quic_connection(QUIC_TSERVER *qtserv, SSL *clientssl);
2f1d8f85 46
da81f1e5 47/*
c88de560
MC
48 * Confirm that the server has received the given transport error code.
49 */
50int qtest_check_server_transport_err(QUIC_TSERVER *qtserv, uint64_t code);
51
52/*
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
da81f1e5 55 */
f10e5885
MC
56int qtest_check_server_protocol_err(QUIC_TSERVER *qtserv);
57
da81f1e5
MC
58/*
59 * Enable tests to listen for pre-encryption QUIC packets being sent
60 */
2f1d8f85
MC
61typedef int (*ossl_quic_fault_on_packet_plain_cb)(OSSL_QUIC_FAULT *fault,
62 QUIC_PKT_HDR *hdr,
63 unsigned char *buf,
64 size_t len,
65 void *cbarg);
66
67int ossl_quic_fault_set_packet_plain_listener(OSSL_QUIC_FAULT *fault,
68 ossl_quic_fault_on_packet_plain_cb pplaincb,
69 void *pplaincbarg);
70
da81f1e5
MC
71/*
72 * Helper function to be called from a packet_plain_listener callback if it
47d905fd
MC
73 * wants to resize the packet (either to add new data to it, or to truncate it).
74 * The buf provided to packet_plain_listener is over allocated, so this just
75 * changes the logical size and never changes the actual address of the buf.
76 * This will fail if a large resize is attempted that exceeds the over
77 * allocation.
da81f1e5 78 */
2f1d8f85 79int ossl_quic_fault_resize_plain_packet(OSSL_QUIC_FAULT *fault, size_t newlen);
6d1f6933
MC
80
81/*
82 * The general handshake message listener is sent the entire handshake message
83 * data block, including the handshake header itself
84 */
85typedef int (*ossl_quic_fault_on_handshake_cb)(OSSL_QUIC_FAULT *fault,
86 unsigned char *msg,
87 size_t msglen,
88 void *handshakecbarg);
89
90int ossl_quic_fault_set_handshake_listener(OSSL_QUIC_FAULT *fault,
91 ossl_quic_fault_on_handshake_cb handshakecb,
92 void *handshakecbarg);
93
94/*
da81f1e5 95 * Helper function to be called from a handshake_listener callback if it wants
de60deb2 96 * to resize the handshake message (either to add new data to it, or to truncate
47d905fd
MC
97 * it). newlen must include the length of the handshake message header. The
98 * handshake message buffer is over allocated, so this just changes the logical
99 * size and never changes the actual address of the buf.
100 * This will fail if a large resize is attempted that exceeds the over
101 * allocation.
6d1f6933
MC
102 */
103int ossl_quic_fault_resize_handshake(OSSL_QUIC_FAULT *fault, size_t newlen);
104
da81f1e5
MC
105/*
106 * TODO(QUIC): Add listeners for specifc types of frame here. E.g. we might
107 * expect to see an "ACK" frame listener which will be passed pre-parsed ack
108 * data that can be modified as required.
109 */
110
6d1f6933
MC
111/*
112 * Handshake message specific listeners. Unlike the general handshake message
113 * listener these messages are pre-parsed and supplied with message specific
114 * data and exclude the handshake header
115 */
116typedef int (*ossl_quic_fault_on_enc_ext_cb)(OSSL_QUIC_FAULT *fault,
117 OSSL_QF_ENCRYPTED_EXTENSIONS *ee,
118 size_t eelen,
119 void *encextcbarg);
120
121int ossl_quic_fault_set_hand_enc_ext_listener(OSSL_QUIC_FAULT *fault,
122 ossl_quic_fault_on_enc_ext_cb encextcb,
123 void *encextcbarg);
124
da81f1e5
MC
125/* TODO(QUIC): Add listeners for other types of handshake message here */
126
6d1f6933
MC
127
128/*
da81f1e5
MC
129 * Helper function to be called from message specific listener callbacks. newlen
130 * is the new length of the specific message excluding the handshake message
47d905fd
MC
131 * header. The buffers provided to the message specific listeners are over
132 * allocated, so this just changes the logical size and never changes the actual
133 * address of the buffer. This will fail if a large resize is attempted that
134 * exceeds the over allocation.
6d1f6933
MC
135 */
136int ossl_quic_fault_resize_message(OSSL_QUIC_FAULT *fault, size_t newlen);
137
138/*
da81f1e5
MC
139 * Helper function to delete an extension from an extension block. |exttype| is
140 * the type of the extension to be deleted. |ext| points to the extension block.
141 * On entry |*extlen| contains the length of the extension block. It is updated
142 * with the new length on exit.
6d1f6933
MC
143 */
144int ossl_quic_fault_delete_extension(OSSL_QUIC_FAULT *fault,
145 unsigned int exttype, unsigned char *ext,
f10e5885 146 size_t *extlen);
da81f1e5
MC
147
148/*
149 * TODO(QUIC): Add additional helper functions for querying extensions here (e.g.
150 * finding or adding them). We could also provide a "listener" API for listening
151 * for specific extension types
152 */
153
de60deb2
MC
154/*
155 * Enable tests to listen for post-encryption QUIC packets being sent
156 */
157typedef int (*ossl_quic_fault_on_packet_cipher_cb)(OSSL_QUIC_FAULT *fault,
158 /* The parsed packet header */
159 QUIC_PKT_HDR *hdr,
160 /* The packet payload data */
161 unsigned char *buf,
162 /* Length of the payload */
163 size_t len,
164 void *cbarg);
165
166int ossl_quic_fault_set_packet_cipher_listener(OSSL_QUIC_FAULT *fault,
167 ossl_quic_fault_on_packet_cipher_cb pciphercb,
168 void *picphercbarg);
e4cb6583
MC
169
170/*
171 * Enable tests to listen for datagrams being sent
172 */
173typedef int (*ossl_quic_fault_on_datagram_cb)(OSSL_QUIC_FAULT *fault,
174 BIO_MSG *m,
175 size_t stride,
176 void *cbarg);
177
178int ossl_quic_fault_set_datagram_listener(OSSL_QUIC_FAULT *fault,
179 ossl_quic_fault_on_datagram_cb datagramcb,
180 void *datagramcbarg);
181
47d905fd
MC
182/*
183 * To be called from a datagram_listener callback. The datagram buffer is over
184 * allocated, so this just changes the logical size and never changes the actual
185 * address of the buffer. This will fail if a large resize is attempted that
186 * exceeds the over allocation.
187 */
e4cb6583 188int ossl_quic_fault_resize_datagram(OSSL_QUIC_FAULT *fault, size_t newlen);