summaryrefslogtreecommitdiff
path: root/src/regress/lib/libssl/server/servertest.c
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2022-10-20 07:33:15 +0000
committercvs2svn <admin@example.com>2022-10-20 07:33:15 +0000
commit963a7b06e7d578322df5c53439ac3f52eae54095 (patch)
tree47b3068b3442e2e9768ae23e8bcf303231adf015 /src/regress/lib/libssl/server/servertest.c
parent6ef02c2707dc554983552781e5b767ae8103de15 (diff)
downloadopenbsd-tb_20221020.tar.gz
openbsd-tb_20221020.tar.bz2
openbsd-tb_20221020.zip
This commit was manufactured by cvs2git to create tag 'tb_20221020'.tb_20221020
Diffstat (limited to 'src/regress/lib/libssl/server/servertest.c')
-rw-r--r--src/regress/lib/libssl/server/servertest.c203
1 files changed, 0 insertions, 203 deletions
diff --git a/src/regress/lib/libssl/server/servertest.c b/src/regress/lib/libssl/server/servertest.c
deleted file mode 100644
index 3367836dbd..0000000000
--- a/src/regress/lib/libssl/server/servertest.c
+++ /dev/null
@@ -1,203 +0,0 @@
1/* $OpenBSD: servertest.c,v 1.7 2022/06/10 22:00:15 tb Exp $ */
2/*
3 * Copyright (c) 2015, 2016, 2017 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 <openssl/ssl.h>
19
20#include <openssl/err.h>
21#include <openssl/dtls1.h>
22#include <openssl/ssl3.h>
23
24#include <err.h>
25#include <stdio.h>
26#include <string.h>
27
28const SSL_METHOD *tls_legacy_method(void);
29
30char *server_ca_file;
31char *server_cert_file;
32char *server_key_file;
33
34static unsigned char sslv2_client_hello_tls10[] = {
35 0x80, 0x6a, 0x01, 0x03, 0x01, 0x00, 0x51, 0x00,
36 0x00, 0x00, 0x10, 0x00, 0x00, 0x39, 0x00, 0x00,
37 0x38, 0x00, 0x00, 0x35, 0x00, 0x00, 0x16, 0x00,
38 0x00, 0x13, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x33,
39 0x00, 0x00, 0x32, 0x00, 0x00, 0x2f, 0x00, 0x00,
40 0x07, 0x00, 0x00, 0x66, 0x00, 0x00, 0x05, 0x00,
41 0x00, 0x04, 0x00, 0x00, 0x63, 0x00, 0x00, 0x62,
42 0x00, 0x00, 0x61, 0x00, 0x00, 0x15, 0x00, 0x00,
43 0x12, 0x00, 0x00, 0x09, 0x00, 0x00, 0x65, 0x00,
44 0x00, 0x64, 0x00, 0x00, 0x60, 0x00, 0x00, 0x14,
45 0x00, 0x00, 0x11, 0x00, 0x00, 0x08, 0x00, 0x00,
46 0x06, 0x00, 0x00, 0x03, 0xdd, 0xb6, 0x59, 0x26,
47 0x46, 0xe6, 0x79, 0x77, 0xf4, 0xec, 0x42, 0x76,
48 0xc8, 0x73, 0xad, 0x9c,
49};
50
51static unsigned char sslv2_client_hello_tls12[] = {
52 0x80, 0xcb, 0x01, 0x03, 0x03, 0x00, 0xa2, 0x00,
53 0x00, 0x00, 0x20, 0x00, 0x00, 0xa5, 0x00, 0x00,
54 0xa3, 0x00, 0x00, 0xa1, 0x00, 0x00, 0x9f, 0x00,
55 0x00, 0x6b, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x69,
56 0x00, 0x00, 0x68, 0x00, 0x00, 0x39, 0x00, 0x00,
57 0x38, 0x00, 0x00, 0x37, 0x00, 0x00, 0x36, 0x00,
58 0x00, 0x88, 0x00, 0x00, 0x87, 0x00, 0x00, 0x86,
59 0x00, 0x00, 0x85, 0x00, 0x00, 0x9d, 0x00, 0x00,
60 0x3d, 0x00, 0x00, 0x35, 0x00, 0x00, 0x84, 0x00,
61 0x00, 0xa4, 0x00, 0x00, 0xa2, 0x00, 0x00, 0xa0,
62 0x00, 0x00, 0x9e, 0x00, 0x00, 0x67, 0x00, 0x00,
63 0x40, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x3e, 0x00,
64 0x00, 0x33, 0x00, 0x00, 0x32, 0x00, 0x00, 0x31,
65 0x00, 0x00, 0x30, 0x00, 0x00, 0x9a, 0x00, 0x00,
66 0x99, 0x00, 0x00, 0x98, 0x00, 0x00, 0x97, 0x00,
67 0x00, 0x45, 0x00, 0x00, 0x44, 0x00, 0x00, 0x43,
68 0x00, 0x00, 0x42, 0x00, 0x00, 0x9c, 0x00, 0x00,
69 0x3c, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x96, 0x00,
70 0x00, 0x41, 0x00, 0x00, 0x07, 0x00, 0x00, 0x05,
71 0x00, 0x00, 0x04, 0x00, 0x00, 0x16, 0x00, 0x00,
72 0x13, 0x00, 0x00, 0x10, 0x00, 0x00, 0x0d, 0x00,
73 0x00, 0x0a, 0x00, 0x00, 0xff, 0x1d, 0xfd, 0x90,
74 0x03, 0x61, 0x3c, 0x5a, 0x22, 0x83, 0xed, 0x11,
75 0x85, 0xf4, 0xea, 0x36, 0x59, 0xd9, 0x1b, 0x27,
76 0x22, 0x01, 0x14, 0x07, 0x66, 0xb2, 0x24, 0xf5,
77 0x4e, 0x7d, 0x9d, 0x9c, 0x52,
78};
79
80struct server_hello_test {
81 const unsigned char *desc;
82 unsigned char *client_hello;
83 const size_t client_hello_len;
84 const SSL_METHOD *(*ssl_method)(void);
85 const long ssl_clear_options;
86 const long ssl_set_options;
87};
88
89static struct server_hello_test server_hello_tests[] = {
90 {
91 .desc = "TLSv1.0 in SSLv2 record",
92 .client_hello = sslv2_client_hello_tls10,
93 .client_hello_len = sizeof(sslv2_client_hello_tls10),
94 .ssl_method = tls_legacy_method,
95 .ssl_clear_options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1,
96 .ssl_set_options = 0,
97 },
98 {
99 .desc = "TLSv1.2 in SSLv2 record",
100 .client_hello = sslv2_client_hello_tls12,
101 .client_hello_len = sizeof(sslv2_client_hello_tls12),
102 .ssl_method = tls_legacy_method,
103 .ssl_clear_options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1,
104 .ssl_set_options = 0,
105 },
106};
107
108#define N_SERVER_HELLO_TESTS \
109 (sizeof(server_hello_tests) / sizeof(*server_hello_tests))
110
111static int
112server_hello_test(int testno, struct server_hello_test *sht)
113{
114 BIO *rbio = NULL, *wbio = NULL;
115 SSL_CTX *ssl_ctx = NULL;
116 SSL *ssl = NULL;
117 int ret = 1;
118
119 fprintf(stderr, "Test %d - %s\n", testno, sht->desc);
120
121 if ((rbio = BIO_new_mem_buf(sht->client_hello,
122 sht->client_hello_len)) == NULL) {
123 fprintf(stderr, "Failed to setup rbio\n");
124 goto failure;
125 }
126 if ((wbio = BIO_new(BIO_s_mem())) == NULL) {
127 fprintf(stderr, "Failed to setup wbio\n");
128 goto failure;
129 }
130
131 if ((ssl_ctx = SSL_CTX_new(sht->ssl_method())) == NULL) {
132 fprintf(stderr, "SSL_CTX_new() returned NULL\n");
133 goto failure;
134 }
135
136 if (SSL_CTX_use_certificate_file(ssl_ctx, server_cert_file,
137 SSL_FILETYPE_PEM) != 1) {
138 fprintf(stderr, "Failed to load server certificate");
139 goto failure;
140 }
141 if (SSL_CTX_use_PrivateKey_file(ssl_ctx, server_key_file,
142 SSL_FILETYPE_PEM) != 1) {
143 fprintf(stderr, "Failed to load server private key");
144 goto failure;
145 }
146
147 SSL_CTX_set_dh_auto(ssl_ctx, 1);
148 SSL_CTX_set_ecdh_auto(ssl_ctx, 1);
149
150 SSL_CTX_clear_options(ssl_ctx, sht->ssl_clear_options);
151 SSL_CTX_set_options(ssl_ctx, sht->ssl_set_options);
152
153 if ((ssl = SSL_new(ssl_ctx)) == NULL) {
154 fprintf(stderr, "SSL_new() returned NULL\n");
155 goto failure;
156 }
157
158 BIO_up_ref(rbio);
159 BIO_up_ref(wbio);
160 SSL_set_bio(ssl, rbio, wbio);
161
162 if (SSL_accept(ssl) != 0) {
163 fprintf(stderr, "SSL_accept() returned non-zero\n");
164 ERR_print_errors_fp(stderr);
165 goto failure;
166 }
167
168 ret = 0;
169
170 failure:
171 SSL_CTX_free(ssl_ctx);
172 SSL_free(ssl);
173
174 BIO_free(rbio);
175 BIO_free(wbio);
176
177 return (ret);
178}
179
180int
181main(int argc, char **argv)
182{
183 int failed = 0;
184 size_t i;
185
186 if (argc != 4) {
187 fprintf(stderr, "usage: %s keyfile certfile cafile\n",
188 argv[0]);
189 exit(1);
190 }
191
192 server_key_file = argv[1];
193 server_cert_file = argv[2];
194 server_ca_file = argv[3];
195
196 SSL_library_init();
197 SSL_load_error_strings();
198
199 for (i = 0; i < N_SERVER_HELLO_TESTS; i++)
200 failed |= server_hello_test(i, &server_hello_tests[i]);
201
202 return (failed);
203}