Add a test_ssl_new testcase
[openssl.git] / ssl / quic / quic_impl.c
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/macros.h>
11 #include <openssl/objects.h>
12 #include "quic_local.h"
13
14 int ossl_quic_new(SSL *s)
15 {
16     return s->method->ssl_clear(s);
17 }
18
19 void ossl_quic_free(SSL *s)
20 {
21     return;
22 }
23
24 int ossl_quic_clear(SSL *s)
25 {
26     return 1;
27 }
28
29 int ossl_quic_accept(SSL *s)
30 {
31     s->statem.in_init = 0;
32     return 1;
33 }
34
35 int ossl_quic_connect(SSL *s)
36 {
37     s->statem.in_init = 0;
38     return 1;
39 }
40
41 int ossl_quic_read(SSL *s, void *buf, size_t len, size_t *readbytes)
42 {
43     int ret;
44     BIO *rbio = SSL_get_rbio(s);
45
46     if (rbio == NULL)
47         return 0;
48
49     s->rwstate = SSL_READING;
50     ret = BIO_read_ex(rbio, buf, len, readbytes);
51     if (ret > 0 || !BIO_should_retry(rbio))
52         s->rwstate = SSL_NOTHING;
53     return ret <= 0 ? -1 : ret;
54 }
55
56 int ossl_quic_peek(SSL *s, void *buf, size_t len, size_t *readbytes)
57 {
58     return -1;
59 }
60
61 int ossl_quic_write(SSL *s, const void *buf, size_t len, size_t *written)
62 {
63     BIO *wbio = SSL_get_wbio(s);
64     int ret;
65
66     if (wbio == NULL)
67         return 0;
68
69     s->rwstate = SSL_WRITING;
70     ret = BIO_write_ex(wbio, buf, len, written);
71     if (ret > 0 || !BIO_should_retry(wbio))
72         s->rwstate = SSL_NOTHING;
73     return ret;
74 }
75
76 int ossl_quic_shutdown(SSL *s)
77 {
78     return 1;
79 }
80
81 long ossl_quic_ctrl(SSL *s, int cmd, long larg, void *parg)
82 {
83     switch(cmd) {
84     case SSL_CTRL_CHAIN:
85         if (larg)
86             return ssl_cert_set1_chain(s, NULL, (STACK_OF(X509) *)parg);
87         else
88             return ssl_cert_set0_chain(s, NULL, (STACK_OF(X509) *)parg);
89     }
90     return 0;
91 }
92
93 long ossl_quic_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
94 {
95     switch(cmd) {
96     case SSL_CTRL_CHAIN:
97         if (larg)
98             return ssl_cert_set1_chain(NULL, ctx, (STACK_OF(X509) *)parg);
99         else
100             return ssl_cert_set0_chain(NULL, ctx, (STACK_OF(X509) *)parg);
101
102     case SSL_CTRL_SET_TLSEXT_TICKET_KEYS:
103     case SSL_CTRL_GET_TLSEXT_TICKET_KEYS:
104         /* TODO(QUIC): these will have to be implemented properly */
105         return 1;
106     }
107     return 0;
108 }
109
110 long ossl_quic_callback_ctrl(SSL *s, int cmd, void (*fp) (void))
111 {
112     return 0;
113 }
114
115 long ossl_quic_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp) (void))
116 {
117     return 0;
118 }
119
120 size_t ossl_quic_pending(const SSL *s)
121 {
122     return 0;
123 }
124
125 long ossl_quic_default_timeout(void)
126 {
127     return 0;
128 }
129
130 int ossl_quic_num_ciphers(void)
131 {
132     return 1;
133 }
134
135 const SSL_CIPHER *ossl_quic_get_cipher(unsigned int u)
136 {
137     /*
138      * TODO(QUIC): This is needed so the SSL_CTX_set_cipher_list("DEFAULT");
139      * produces at least one valid TLS-1.2 cipher.
140      * Later we should allow that there are none with QUIC protocol as
141      * SSL_CTX_set_cipher_list should still allow setting a SECLEVEL.
142      */
143     static const SSL_CIPHER ciph = {
144         1,
145         TLS1_TXT_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
146         TLS1_RFC_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
147         TLS1_CK_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
148         SSL_kECDHE,
149         SSL_aRSA,
150         SSL_AES256GCM,
151         SSL_AEAD,
152         TLS1_2_VERSION, TLS1_2_VERSION,
153         DTLS1_2_VERSION, DTLS1_2_VERSION,
154         SSL_HIGH | SSL_FIPS,
155         SSL_HANDSHAKE_MAC_SHA384 | TLS1_PRF_SHA384,
156         256,
157         256
158     };
159
160     return &ciph;
161 }
162
163 int ossl_quic_renegotiate_check(SSL *ssl, int initok)
164 {
165     return 1;
166 }