]>
Commit | Line | Data |
---|---|---|
51a168b8 HL |
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 | #ifndef OSSL_QUIC_TSERVER_H | |
11 | # define OSSL_QUIC_TSERVER_H | |
12 | ||
13 | # include <openssl/ssl.h> | |
0c593328 | 14 | # include <openssl/bio.h> |
51a168b8 | 15 | # include "internal/quic_stream.h" |
149a8e6c | 16 | # include "internal/quic_channel.h" |
d03fe5de | 17 | # include "internal/statem.h" |
51a168b8 HL |
18 | |
19 | # ifndef OPENSSL_NO_QUIC | |
20 | ||
21 | /* | |
22 | * QUIC Test Server Module | |
23 | * ======================= | |
24 | * | |
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. | |
28 | * | |
29 | * A given QUIC test server instance supports only one client at a time. | |
30 | * | |
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. | |
33 | */ | |
34 | typedef struct quic_tserver_st QUIC_TSERVER; | |
35 | ||
36 | typedef struct quic_tserver_args_st { | |
37 | OSSL_LIB_CTX *libctx; | |
38 | const char *propq; | |
39 | BIO *net_rbio, *net_wbio; | |
40 | } QUIC_TSERVER_ARGS; | |
41 | ||
4e3a55fd MC |
42 | QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args, |
43 | const char *certfile, const char *keyfile); | |
51a168b8 HL |
44 | |
45 | void ossl_quic_tserver_free(QUIC_TSERVER *srv); | |
46 | ||
14e31409 | 47 | /* Set mutator callbacks for test framework support */ |
d03fe5de MC |
48 | int ossl_quic_tserver_set_plain_packet_mutator(QUIC_TSERVER *srv, |
49 | ossl_mutate_packet_cb mutatecb, | |
50 | ossl_finish_mutate_cb finishmutatecb, | |
51 | void *mutatearg); | |
52 | ||
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, | |
56 | void *mutatearg); | |
14e31409 | 57 | |
51a168b8 HL |
58 | /* Advances the state machine. */ |
59 | int ossl_quic_tserver_tick(QUIC_TSERVER *srv); | |
60 | ||
f10e5885 MC |
61 | /* |
62 | * Returns 1 if we have finished the TLS handshake | |
63 | */ | |
45bb98bf | 64 | int ossl_quic_tserver_is_handshake_confirmed(const QUIC_TSERVER *srv); |
51a168b8 | 65 | |
adef87a2 | 66 | /* Returns 1 if the server is in any terminating or terminated state */ |
45bb98bf | 67 | int ossl_quic_tserver_is_term_any(const QUIC_TSERVER *srv); |
c12e1113 | 68 | |
45bb98bf | 69 | QUIC_TERMINATE_CAUSE ossl_quic_tserver_get_terminate_cause(const QUIC_TSERVER *srv); |
adef87a2 | 70 | |
149a8e6c | 71 | /* Returns 1 if the server is in a terminated state */ |
45bb98bf | 72 | int ossl_quic_tserver_is_terminated(const QUIC_TSERVER *srv); |
51a168b8 HL |
73 | /* |
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). | |
77 | * | |
a9979965 HL |
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. | |
51a168b8 HL |
81 | */ |
82 | int ossl_quic_tserver_read(QUIC_TSERVER *srv, | |
83 | unsigned char *buf, | |
84 | size_t buf_len, | |
85 | size_t *bytes_read); | |
86 | ||
a9979965 HL |
87 | /* |
88 | * Returns 1 if the read part of the stream has ended normally. | |
89 | */ | |
90 | int ossl_quic_tserver_has_read_ended(QUIC_TSERVER *srv); | |
91 | ||
51a168b8 HL |
92 | /* |
93 | * Attempts to write to stream 0. Writes the number of bytes consumed to | |
091f532e HL |
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). | |
51a168b8 HL |
97 | * |
98 | * Note that unlike libssl public APIs, this API always works in a 'partial | |
99 | * write' mode. | |
100 | * | |
101 | * Returns 0 if connection is not currently active. | |
102 | */ | |
103 | int ossl_quic_tserver_write(QUIC_TSERVER *srv, | |
104 | const unsigned char *buf, | |
105 | size_t buf_len, | |
106 | size_t *bytes_written); | |
107 | ||
a9979965 HL |
108 | /* |
109 | * Signals normal end of the stream. | |
110 | */ | |
111 | int ossl_quic_tserver_conclude(QUIC_TSERVER *srv); | |
112 | ||
0c593328 MC |
113 | BIO *ossl_quic_tserver_get0_rbio(QUIC_TSERVER *srv); |
114 | ||
51a168b8 HL |
115 | # endif |
116 | ||
117 | #endif |