summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/s_time.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/openssl/s_time.c')
-rw-r--r--src/usr.bin/openssl/s_time.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/usr.bin/openssl/s_time.c b/src/usr.bin/openssl/s_time.c
index d6f012fd41..7eed6d486e 100644
--- a/src/usr.bin/openssl/s_time.c
+++ b/src/usr.bin/openssl/s_time.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s_time.c,v 1.37 2023/03/05 13:12:53 tb Exp $ */ 1/* $OpenBSD: s_time.c,v 1.38 2023/03/06 14:32:06 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -113,42 +113,42 @@ static struct {
113 int verify; 113 int verify;
114 int verify_depth; 114 int verify_depth;
115 char *www_path; 115 char *www_path;
116} s_time_config; 116} cfg;
117 117
118static const struct option s_time_options[] = { 118static const struct option s_time_options[] = {
119 { 119 {
120 .name = "bugs", 120 .name = "bugs",
121 .desc = "Enable workarounds for known SSL/TLS bugs", 121 .desc = "Enable workarounds for known SSL/TLS bugs",
122 .type = OPTION_FLAG, 122 .type = OPTION_FLAG,
123 .opt.flag = &s_time_config.bugs, 123 .opt.flag = &cfg.bugs,
124 }, 124 },
125 { 125 {
126 .name = "CAfile", 126 .name = "CAfile",
127 .argname = "file", 127 .argname = "file",
128 .desc = "File containing trusted certificates in PEM format", 128 .desc = "File containing trusted certificates in PEM format",
129 .type = OPTION_ARG, 129 .type = OPTION_ARG,
130 .opt.arg = &s_time_config.CAfile, 130 .opt.arg = &cfg.CAfile,
131 }, 131 },
132 { 132 {
133 .name = "CApath", 133 .name = "CApath",
134 .argname = "path", 134 .argname = "path",
135 .desc = "Directory containing trusted certificates", 135 .desc = "Directory containing trusted certificates",
136 .type = OPTION_ARG, 136 .type = OPTION_ARG,
137 .opt.arg = &s_time_config.CApath, 137 .opt.arg = &cfg.CApath,
138 }, 138 },
139 { 139 {
140 .name = "cert", 140 .name = "cert",
141 .argname = "file", 141 .argname = "file",
142 .desc = "Client certificate to use, if one is requested", 142 .desc = "Client certificate to use, if one is requested",
143 .type = OPTION_ARG, 143 .type = OPTION_ARG,
144 .opt.arg = &s_time_config.certfile, 144 .opt.arg = &cfg.certfile,
145 }, 145 },
146 { 146 {
147 .name = "cipher", 147 .name = "cipher",
148 .argname = "list", 148 .argname = "list",
149 .desc = "List of cipher suites to send to the server", 149 .desc = "List of cipher suites to send to the server",
150 .type = OPTION_ARG, 150 .type = OPTION_ARG,
151 .opt.arg = &s_time_config.cipher, 151 .opt.arg = &cfg.cipher,
152 }, 152 },
153 { 153 {
154 .name = "connect", 154 .name = "connect",
@@ -156,39 +156,39 @@ static const struct option s_time_options[] = {
156 .desc = "Host and port to connect to (default " 156 .desc = "Host and port to connect to (default "
157 SSL_CONNECT_NAME ")", 157 SSL_CONNECT_NAME ")",
158 .type = OPTION_ARG, 158 .type = OPTION_ARG,
159 .opt.arg = &s_time_config.host, 159 .opt.arg = &cfg.host,
160 }, 160 },
161 { 161 {
162 .name = "key", 162 .name = "key",
163 .argname = "file", 163 .argname = "file",
164 .desc = "Client private key to use, if one is required", 164 .desc = "Client private key to use, if one is required",
165 .type = OPTION_ARG, 165 .type = OPTION_ARG,
166 .opt.arg = &s_time_config.keyfile, 166 .opt.arg = &cfg.keyfile,
167 }, 167 },
168 { 168 {
169 .name = "nbio", 169 .name = "nbio",
170 .desc = "Use non-blocking I/O", 170 .desc = "Use non-blocking I/O",
171 .type = OPTION_FLAG, 171 .type = OPTION_FLAG,
172 .opt.flag = &s_time_config.nbio, 172 .opt.flag = &cfg.nbio,
173 }, 173 },
174 { 174 {
175 .name = "new", 175 .name = "new",
176 .desc = "Use a new session ID for each connection", 176 .desc = "Use a new session ID for each connection",
177 .type = OPTION_VALUE, 177 .type = OPTION_VALUE,
178 .opt.value = &s_time_config.perform, 178 .opt.value = &cfg.perform,
179 .value = 1, 179 .value = 1,
180 }, 180 },
181 { 181 {
182 .name = "no_shutdown", 182 .name = "no_shutdown",
183 .desc = "Shut down the connection without notifying the server", 183 .desc = "Shut down the connection without notifying the server",
184 .type = OPTION_FLAG, 184 .type = OPTION_FLAG,
185 .opt.flag = &s_time_config.no_shutdown, 185 .opt.flag = &cfg.no_shutdown,
186 }, 186 },
187 { 187 {
188 .name = "reuse", 188 .name = "reuse",
189 .desc = "Reuse the same session ID for each connection", 189 .desc = "Reuse the same session ID for each connection",
190 .type = OPTION_VALUE, 190 .type = OPTION_VALUE,
191 .opt.value = &s_time_config.perform, 191 .opt.value = &cfg.perform,
192 .value = 2, 192 .value = 2,
193 }, 193 },
194 { 194 {
@@ -196,21 +196,21 @@ static const struct option s_time_options[] = {
196 .argname = "seconds", 196 .argname = "seconds",
197 .desc = "Duration to perform timing tests for (default 30)", 197 .desc = "Duration to perform timing tests for (default 30)",
198 .type = OPTION_ARG_TIME, 198 .type = OPTION_ARG_TIME,
199 .opt.tvalue = &s_time_config.maxtime, 199 .opt.tvalue = &cfg.maxtime,
200 }, 200 },
201 { 201 {
202 .name = "verify", 202 .name = "verify",
203 .argname = "depth", 203 .argname = "depth",
204 .desc = "Enable peer certificate verification with given depth", 204 .desc = "Enable peer certificate verification with given depth",
205 .type = OPTION_ARG_INT, 205 .type = OPTION_ARG_INT,
206 .opt.value = &s_time_config.verify_depth, 206 .opt.value = &cfg.verify_depth,
207 }, 207 },
208 { 208 {
209 .name = "www", 209 .name = "www",
210 .argname = "page", 210 .argname = "page",
211 .desc = "Page to GET from the server (default none)", 211 .desc = "Page to GET from the server (default none)",
212 .type = OPTION_ARG, 212 .type = OPTION_ARG,
213 .opt.arg = &s_time_config.www_path, 213 .opt.arg = &cfg.www_path,
214 }, 214 },
215 { NULL }, 215 { NULL },
216}; 216};
@@ -245,27 +245,27 @@ s_time_main(int argc, char **argv)
245 245
246 verify_depth = 0; 246 verify_depth = 0;
247 247
248 memset(&s_time_config, 0, sizeof(s_time_config)); 248 memset(&cfg, 0, sizeof(cfg));
249 249
250 s_time_config.host = SSL_CONNECT_NAME; 250 cfg.host = SSL_CONNECT_NAME;
251 s_time_config.maxtime = SECONDS; 251 cfg.maxtime = SECONDS;
252 s_time_config.perform = 3; 252 cfg.perform = 3;
253 s_time_config.verify = SSL_VERIFY_NONE; 253 cfg.verify = SSL_VERIFY_NONE;
254 s_time_config.verify_depth = -1; 254 cfg.verify_depth = -1;
255 255
256 if (options_parse(argc, argv, s_time_options, NULL, NULL) != 0) { 256 if (options_parse(argc, argv, s_time_options, NULL, NULL) != 0) {
257 s_time_usage(); 257 s_time_usage();
258 goto end; 258 goto end;
259 } 259 }
260 260
261 if (s_time_config.verify_depth >= 0) { 261 if (cfg.verify_depth >= 0) {
262 s_time_config.verify = SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE; 262 cfg.verify = SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE;
263 verify_depth = s_time_config.verify_depth; 263 verify_depth = cfg.verify_depth;
264 BIO_printf(bio_err, "verify depth is %d\n", verify_depth); 264 BIO_printf(bio_err, "verify depth is %d\n", verify_depth);
265 } 265 }
266 266
267 if (s_time_config.www_path != NULL && 267 if (cfg.www_path != NULL &&
268 strlen(s_time_config.www_path) > MYBUFSIZ - 100) { 268 strlen(cfg.www_path) > MYBUFSIZ - 100) {
269 BIO_printf(bio_err, "-www option too long\n"); 269 BIO_printf(bio_err, "-www option too long\n");
270 goto end; 270 goto end;
271 } 271 }
@@ -275,25 +275,25 @@ s_time_main(int argc, char **argv)
275 275
276 SSL_CTX_set_quiet_shutdown(tm_ctx, 1); 276 SSL_CTX_set_quiet_shutdown(tm_ctx, 1);
277 277
278 if (s_time_config.bugs) 278 if (cfg.bugs)
279 SSL_CTX_set_options(tm_ctx, SSL_OP_ALL); 279 SSL_CTX_set_options(tm_ctx, SSL_OP_ALL);
280 280
281 if (s_time_config.cipher != NULL) { 281 if (cfg.cipher != NULL) {
282 if (!SSL_CTX_set_cipher_list(tm_ctx, s_time_config.cipher)) { 282 if (!SSL_CTX_set_cipher_list(tm_ctx, cfg.cipher)) {
283 BIO_printf(bio_err, "error setting cipher list\n"); 283 BIO_printf(bio_err, "error setting cipher list\n");
284 ERR_print_errors(bio_err); 284 ERR_print_errors(bio_err);
285 goto end; 285 goto end;
286 } 286 }
287 } 287 }
288 288
289 SSL_CTX_set_verify(tm_ctx, s_time_config.verify, NULL); 289 SSL_CTX_set_verify(tm_ctx, cfg.verify, NULL);
290 290
291 if (!set_cert_stuff(tm_ctx, s_time_config.certfile, 291 if (!set_cert_stuff(tm_ctx, cfg.certfile,
292 s_time_config.keyfile)) 292 cfg.keyfile))
293 goto end; 293 goto end;
294 294
295 if ((!SSL_CTX_load_verify_locations(tm_ctx, s_time_config.CAfile, 295 if ((!SSL_CTX_load_verify_locations(tm_ctx, cfg.CAfile,
296 s_time_config.CApath)) || 296 cfg.CApath)) ||
297 (!SSL_CTX_set_default_verify_paths(tm_ctx))) { 297 (!SSL_CTX_set_default_verify_paths(tm_ctx))) {
298 /* 298 /*
299 * BIO_printf(bio_err,"error setting default verify 299 * BIO_printf(bio_err,"error setting default verify
@@ -304,9 +304,9 @@ s_time_main(int argc, char **argv)
304 } 304 }
305 305
306 /* Loop and time how long it takes to make connections */ 306 /* Loop and time how long it takes to make connections */
307 if (s_time_config.perform & 1) { 307 if (cfg.perform & 1) {
308 printf("Collecting connection statistics for %lld seconds\n", 308 printf("Collecting connection statistics for %lld seconds\n",
309 (long long)s_time_config.maxtime); 309 (long long)cfg.maxtime);
310 if (benchmark(0)) 310 if (benchmark(0))
311 goto end; 311 goto end;
312 } 312 }
@@ -314,7 +314,7 @@ s_time_main(int argc, char **argv)
314 * Now loop and time connections using the same session id over and 314 * Now loop and time connections using the same session id over and
315 * over 315 * over
316 */ 316 */
317 if (s_time_config.perform & 2) { 317 if (cfg.perform & 2) {
318 printf("\n\nNow timing with session id reuse.\n"); 318 printf("\n\nNow timing with session id reuse.\n");
319 if (benchmark(1)) 319 if (benchmark(1))
320 goto end; 320 goto end;
@@ -348,7 +348,7 @@ run_test(SSL *scon)
348 348
349 if ((conn = BIO_new(BIO_s_connect())) == NULL) 349 if ((conn = BIO_new(BIO_s_connect())) == NULL)
350 return 0; 350 return 0;
351 BIO_set_conn_hostname(conn, s_time_config.host); 351 BIO_set_conn_hostname(conn, cfg.host);
352 SSL_set_connect_state(scon); 352 SSL_set_connect_state(scon);
353 SSL_set_bio(scon, conn, conn); 353 SSL_set_bio(scon, conn, conn);
354 for (;;) { 354 for (;;) {
@@ -372,9 +372,9 @@ run_test(SSL *scon)
372 ERR_print_errors(bio_err); 372 ERR_print_errors(bio_err);
373 return 0; 373 return 0;
374 } 374 }
375 if (s_time_config.www_path != NULL) { 375 if (cfg.www_path != NULL) {
376 retval = snprintf(buf, sizeof buf, 376 retval = snprintf(buf, sizeof buf,
377 "GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); 377 "GET %s HTTP/1.0\r\n\r\n", cfg.www_path);
378 if (retval < 0 || retval >= sizeof buf) { 378 if (retval < 0 || retval >= sizeof buf) {
379 fprintf(stderr, "URL too long\n"); 379 fprintf(stderr, "URL too long\n");
380 return 0; 380 return 0;
@@ -384,7 +384,7 @@ run_test(SSL *scon)
384 while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) 384 while ((i = SSL_read(scon, buf, sizeof(buf))) > 0)
385 bytes_read += i; 385 bytes_read += i;
386 } 386 }
387 if (s_time_config.no_shutdown) 387 if (cfg.no_shutdown)
388 SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | 388 SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN |
389 SSL_RECEIVED_SHUTDOWN); 389 SSL_RECEIVED_SHUTDOWN);
390 else 390 else
@@ -436,7 +436,7 @@ benchmark(int reuse_session)
436 app_timer_user(TM_RESET); 436 app_timer_user(TM_RESET);
437 for (;;) { 437 for (;;) {
438 elapsed = app_timer_real(TM_GET); 438 elapsed = app_timer_real(TM_GET);
439 if (elapsed > s_time_config.maxtime) 439 if (elapsed > cfg.maxtime)
440 break; 440 break;
441 if (scon == NULL) { 441 if (scon == NULL) {
442 if ((scon = SSL_new(tm_ctx)) == NULL) 442 if ((scon = SSL_new(tm_ctx)) == NULL)