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"
19 # ifndef OPENSSL_NO_QUIC
22 * QUIC Test Server Module
23 * =======================
25 * This implements a QUIC test server. Since full QUIC server support is not yet
26 * implemented this server is limited in features and scope. It exists to
27 * provide a target for our QUIC client to talk to for testing purposes.
29 * A given QUIC test server instance supports only one client at a time.
31 * Note that this test server is not suitable for production use because it does
32 * not implement address verification, anti-amplification or retry logic.
34 typedef struct quic_tserver_st QUIC_TSERVER
;
36 typedef struct quic_tserver_args_st
{
39 BIO
*net_rbio
, *net_wbio
;
42 QUIC_TSERVER
*ossl_quic_tserver_new(const QUIC_TSERVER_ARGS
*args
,
43 const char *certfile
, const char *keyfile
);
45 void ossl_quic_tserver_free(QUIC_TSERVER
*srv
);
47 /* Set mutator callbacks for test framework support */
48 int ossl_quic_tserver_set_plain_packet_mutator(QUIC_TSERVER
*srv
,
49 ossl_mutate_packet_cb mutatecb
,
50 ossl_finish_mutate_cb finishmutatecb
,
53 int ossl_quic_tserver_set_handshake_mutator(QUIC_TSERVER
*srv
,
54 ossl_statem_mutate_handshake_cb mutate_handshake_cb
,
55 ossl_statem_finish_mutate_handshake_cb finish_mutate_handshake_cb
,
58 /* Advances the state machine. */
59 int ossl_quic_tserver_tick(QUIC_TSERVER
*srv
);
62 * Returns 1 if we have finished the TLS handshake
64 int ossl_quic_tserver_is_handshake_confirmed(const QUIC_TSERVER
*srv
);
66 /* Returns 1 if the server is in any terminating or terminated state */
67 int ossl_quic_tserver_is_term_any(const QUIC_TSERVER
*srv
);
69 QUIC_TERMINATE_CAUSE
ossl_quic_tserver_get_terminate_cause(const QUIC_TSERVER
*srv
);
71 /* Returns 1 if the server is in a terminated state */
72 int ossl_quic_tserver_is_terminated(const QUIC_TSERVER
*srv
);
74 * Attempts to read from stream 0. Writes the number of bytes read to
75 * *bytes_read and returns 1 on success. If no bytes are available, 0 is written
76 * to *bytes_read and 1 is returned (this is considered a success case).
78 * Returns 0 if connection is not currently active. If the receive part of
79 * the stream has reached the end of stream condition, returns 0; call
80 * ossl_quic_tserver_has_read_ended() to identify this condition.
82 int ossl_quic_tserver_read(QUIC_TSERVER
*srv
,
88 * Returns 1 if the read part of the stream has ended normally.
90 int ossl_quic_tserver_has_read_ended(QUIC_TSERVER
*srv
);
93 * Attempts to write to stream 0. Writes the number of bytes consumed to
94 * *bytes_written and returns 1 on success. If there is no space currently
95 * available to write any bytes, 0 is written to *consumed and 1 is returned
96 * (this is considered a success case).
98 * Note that unlike libssl public APIs, this API always works in a 'partial
101 * Returns 0 if connection is not currently active.
103 int ossl_quic_tserver_write(QUIC_TSERVER
*srv
,
104 const unsigned char *buf
,
106 size_t *bytes_written
);
109 * Signals normal end of the stream.
111 int ossl_quic_tserver_conclude(QUIC_TSERVER
*srv
);
113 BIO
*ossl_quic_tserver_get0_rbio(QUIC_TSERVER
*srv
);