xref: /openbsd-src/lib/libssl/tls13_server.c (revision fa07df457f3952a155c61842549efde687e94760)
1 /* $OpenBSD: tls13_server.c,v 1.3 2019/11/17 14:25:03 tb Exp $ */
2 /*
3  * Copyright (c) 2019 Joel Sing <jsing@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include "ssl_locl.h"
19 
20 #include "tls13_handshake.h"
21 #include "tls13_internal.h"
22 
23 static int
24 tls13_accept(struct tls13_ctx *ctx)
25 {
26 	if (ctx->mode != TLS13_HS_SERVER)
27 		return TLS13_IO_FAILURE;
28 
29 	return tls13_handshake_perform(ctx);
30 }
31 
32 static int
33 tls13_server_init(struct tls13_ctx *ctx)
34 {
35 	SSL *s = ctx->ssl;
36 
37 	if (!ssl_supported_version_range(s, &ctx->hs->min_version,
38 	    &ctx->hs->max_version)) {
39 		SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE);
40 		return 0;
41 	}
42 
43 	/* XXX implement. */
44 
45 	return 1;
46 }
47 
48 int
49 tls13_legacy_accept(SSL *ssl)
50 {
51 	struct tls13_ctx *ctx = ssl->internal->tls13;
52 	int ret;
53 
54 	if (ctx == NULL) {
55 		if ((ctx = tls13_ctx_new(TLS13_HS_SERVER)) == NULL) {
56 			SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */
57 			return -1;
58 		}
59 		ssl->internal->tls13 = ctx;
60 		ctx->ssl = ssl;
61 		ctx->hs = &S3I(ssl)->hs_tls13;
62 
63 		if (!tls13_server_init(ctx)) {
64 			if (ERR_peek_error() == 0)
65 				SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */
66 			return -1;
67 		}
68 	}
69 
70 	S3I(ssl)->hs.state = SSL_ST_ACCEPT;
71 
72 	ret = tls13_accept(ctx);
73 	if (ret == TLS13_IO_USE_LEGACY)
74 		return ssl->method->internal->ssl_accept(ssl);
75 	if (ret == TLS13_IO_SUCCESS)
76 		S3I(ssl)->hs.state = SSL_ST_OK;
77 
78 	return tls13_legacy_return_code(ssl, ret);
79 }
80 
81 int
82 tls13_client_hello_recv(struct tls13_ctx *ctx)
83 {
84 	return 0;
85 }
86 
87 int
88 tls13_client_hello_retry_send(struct tls13_ctx *ctx)
89 {
90 	return 0;
91 }
92 
93 int
94 tls13_server_hello_retry_recv(struct tls13_ctx *ctx)
95 {
96 	return 0;
97 }
98 
99 int
100 tls13_client_hello_retry_recv(struct tls13_ctx *ctx)
101 {
102 	return 0;
103 }
104 
105 
106 int
107 tls13_client_end_of_early_data_send(struct tls13_ctx *ctx)
108 {
109 	return 0;
110 }
111 
112 int
113 tls13_client_end_of_early_data_recv(struct tls13_ctx *ctx)
114 {
115 	return 0;
116 }
117 
118 int
119 tls13_client_certificate_send(struct tls13_ctx *ctx)
120 {
121 	return 0;
122 }
123 
124 int
125 tls13_client_certificate_recv(struct tls13_ctx *ctx)
126 {
127 	return 0;
128 }
129 
130 int
131 tls13_client_certificate_verify_send(struct tls13_ctx *ctx)
132 {
133 	return 0;
134 }
135 
136 int
137 tls13_client_certificate_verify_recv(struct tls13_ctx *ctx)
138 {
139 	return 0;
140 }
141 
142 int
143 tls13_client_finished_recv(struct tls13_ctx *ctx)
144 {
145 	return 0;
146 }
147 
148 int
149 tls13_client_key_update_send(struct tls13_ctx *ctx)
150 {
151 	return 0;
152 }
153 
154 int
155 tls13_client_key_update_recv(struct tls13_ctx *ctx)
156 {
157 	return 0;
158 }
159 
160 int
161 tls13_server_hello_send(struct tls13_ctx *ctx)
162 {
163 	ctx->handshake_stage.hs_type |= NEGOTIATED;
164 
165 	return 0;
166 }
167 
168 int
169 tls13_server_hello_retry_send(struct tls13_ctx *ctx)
170 {
171 	return 0;
172 }
173 
174 int
175 tls13_server_encrypted_extensions_send(struct tls13_ctx *ctx)
176 {
177 	return 0;
178 }
179 
180 int
181 tls13_server_certificate_send(struct tls13_ctx *ctx)
182 {
183 	return 0;
184 }
185 
186 int
187 tls13_server_certificate_request_send(struct tls13_ctx *ctx)
188 {
189 	return 0;
190 }
191 
192 int
193 tls13_server_certificate_verify_send(struct tls13_ctx *ctx)
194 {
195 	return 0;
196 }
197 
198 int
199 tls13_server_finished_send(struct tls13_ctx *ctx)
200 {
201 	return 0;
202 }
203