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 #ifndef OSSL_QUIC_TSERVER_H
11 # define OSSL_QUIC_TSERVER_H
13 # include <openssl/ssl.h>
14 # include <openssl/bio.h>
15 # include "internal/quic_stream.h"
16 # include "internal/quic_channel.h"
17 # include "internal/statem.h"
18 # include "internal/time.h"
20 # ifndef OPENSSL_NO_QUIC
23 * QUIC Test Server Module
24 * =======================
26 * This implements a QUIC test server. Since full QUIC server support is not yet
27 * implemented this server is limited in features and scope. It exists to
28 * provide a target for our QUIC client to talk to for testing purposes.
30 * A given QUIC test server instance supports only one client at a time.
32 * Note that this test server is not suitable for production use because it does
33 * not implement address verification, anti-amplification or retry logic.
35 typedef struct quic_tserver_st QUIC_TSERVER
;
37 typedef struct quic_tserver_args_st
{
41 BIO
*net_rbio
, *net_wbio
;
42 OSSL_TIME (*now_cb
)(void *arg
);
44 const unsigned char *alpn
;
48 QUIC_TSERVER
*ossl_quic_tserver_new(const QUIC_TSERVER_ARGS
*args
,
49 const char *certfile
, const char *keyfile
);
51 void ossl_quic_tserver_free(QUIC_TSERVER
*srv
);
53 /* Set mutator callbacks for test framework support */
54 int ossl_quic_tserver_set_plain_packet_mutator(QUIC_TSERVER
*srv
,
55 ossl_mutate_packet_cb mutatecb
,
56 ossl_finish_mutate_cb finishmutatecb
,
59 int ossl_quic_tserver_set_handshake_mutator(QUIC_TSERVER
*srv
,
60 ossl_statem_mutate_handshake_cb mutate_handshake_cb
,
61 ossl_statem_finish_mutate_handshake_cb finish_mutate_handshake_cb
,
64 /* Advances the state machine. */
65 int ossl_quic_tserver_tick(QUIC_TSERVER
*srv
);
67 /* Returns 1 if we have a (non-terminated) client. */
68 int ossl_quic_tserver_is_connected(QUIC_TSERVER
*srv
);
71 * Returns 1 if we have finished the TLS handshake
73 int ossl_quic_tserver_is_handshake_confirmed(const QUIC_TSERVER
*srv
);
75 /* Returns 1 if the server is in any terminating or terminated state */
76 int ossl_quic_tserver_is_term_any(const QUIC_TSERVER
*srv
);
78 const QUIC_TERMINATE_CAUSE
*
79 ossl_quic_tserver_get_terminate_cause(const QUIC_TSERVER
*srv
);
81 /* Returns 1 if the server is in a terminated state */
82 int ossl_quic_tserver_is_terminated(const QUIC_TSERVER
*srv
);
85 * Attempts to read from stream 0. Writes the number of bytes read to
86 * *bytes_read and returns 1 on success. If no bytes are available, 0 is written
87 * to *bytes_read and 1 is returned (this is considered a success case).
89 * Returns 0 if connection is not currently active. If the receive part of
90 * the stream has reached the end of stream condition, returns 0; call
91 * ossl_quic_tserver_has_read_ended() to identify this condition.
93 int ossl_quic_tserver_read(QUIC_TSERVER
*srv
,
100 * Returns 1 if the read part of the stream has ended normally.
102 int ossl_quic_tserver_has_read_ended(QUIC_TSERVER
*srv
, uint64_t stream_id
);
105 * Attempts to write to the given stream. Writes the number of bytes consumed to
106 * *bytes_written and returns 1 on success. If there is no space currently
107 * available to write any bytes, 0 is written to *consumed and 1 is returned
108 * (this is considered a success case).
110 * Note that unlike libssl public APIs, this API always works in a 'partial
113 * Returns 0 if connection is not currently active.
115 int ossl_quic_tserver_write(QUIC_TSERVER
*srv
,
117 const unsigned char *buf
,
119 size_t *bytes_written
);
122 * Signals normal end of the stream.
124 int ossl_quic_tserver_conclude(QUIC_TSERVER
*srv
, uint64_t stream_id
);
127 * Create a server-initiated stream. The stream ID of the newly
128 * created stream is written to *stream_id.
130 int ossl_quic_tserver_stream_new(QUIC_TSERVER
*srv
,
132 uint64_t *stream_id
);
134 BIO
*ossl_quic_tserver_get0_rbio(QUIC_TSERVER
*srv
);
136 SSL_CTX
*ossl_quic_tserver_get0_ssl_ctx(QUIC_TSERVER
*srv
);
139 * Returns 1 if the peer has sent a STOP_SENDING frame for a stream.
140 * app_error_code is written if this returns 1.
142 int ossl_quic_tserver_stream_has_peer_stop_sending(QUIC_TSERVER
*srv
,
144 uint64_t *app_error_code
);
147 * Returns 1 if the peer has sent a RESET_STREAM frame for a stream.
148 * app_error_code is written if this returns 1.
150 int ossl_quic_tserver_stream_has_peer_reset_stream(QUIC_TSERVER
*srv
,
152 uint64_t *app_error_code
);
155 * Replaces existing local connection ID in the underlying QUIC_CHANNEL.
157 int ossl_quic_tserver_set_new_local_cid(QUIC_TSERVER
*srv
,
158 const QUIC_CONN_ID
*conn_id
);
161 * Returns the stream ID of the next incoming stream, or UINT64_MAX if there
164 uint64_t ossl_quic_tserver_pop_incoming_stream(QUIC_TSERVER
*srv
);
167 * Returns 1 if all data sent on the given stream_id has been acked by the peer.
169 int ossl_quic_tserver_is_stream_totally_acked(QUIC_TSERVER
*srv
,
172 /* Returns 1 if we are currently interested in reading data from the network */
173 int ossl_quic_tserver_get_net_read_desired(QUIC_TSERVER
*srv
);
175 /* Returns 1 if we are currently interested in writing data to the network */
176 int ossl_quic_tserver_get_net_write_desired(QUIC_TSERVER
*srv
);
178 /* Returns the next event deadline */
179 OSSL_TIME
ossl_quic_tserver_get_deadline(QUIC_TSERVER
*srv
);
182 * Shutdown the QUIC connection. Returns 1 if the connection is terminated and
185 int ossl_quic_tserver_shutdown(QUIC_TSERVER
*srv
);
187 /* Force generation of an ACK-eliciting packet. */
188 int ossl_quic_tserver_ping(QUIC_TSERVER
*srv
);