Document what EXFLAG_SET is for in x509v3.h
[openssl.git] / test / sslapitest.c
1 /*
2  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (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 <string.h>
11
12 #include <openssl/opensslconf.h>
13 #include <openssl/bio.h>
14 #include <openssl/crypto.h>
15 #include <openssl/ssl.h>
16 #include <openssl/ocsp.h>
17
18 #include "ssltestlib.h"
19 #include "testutil.h"
20 #include "test_main_custom.h"
21 #include "e_os.h"
22
23 static char *cert = NULL;
24 static char *privkey = NULL;
25
26 #define LOG_BUFFER_SIZE 1024
27 static char server_log_buffer[LOG_BUFFER_SIZE + 1] = {0};
28 static int server_log_buffer_index = 0;
29 static char client_log_buffer[LOG_BUFFER_SIZE + 1] = {0};
30 static int client_log_buffer_index = 0;
31 static int error_writing_log = 0;
32
33 #ifndef OPENSSL_NO_OCSP
34 static const unsigned char orespder[] = "Dummy OCSP Response";
35 static int ocsp_server_called = 0;
36 static int ocsp_client_called = 0;
37
38 static int cdummyarg = 1;
39 static X509 *ocspcert = NULL;
40 #endif
41
42 #define NUM_EXTRA_CERTS 40
43
44 static void client_keylog_callback(const SSL *ssl, const char *line) {
45     int line_length = strlen(line);
46
47     /* If the log doesn't fit, error out. */
48     if ((client_log_buffer_index + line_length) > LOG_BUFFER_SIZE) {
49         printf("No room in client log\n");
50         error_writing_log = 1;
51         return;
52     }
53
54     strcat(client_log_buffer, line);
55     client_log_buffer_index += line_length;
56     client_log_buffer[client_log_buffer_index] = '\n';
57     client_log_buffer_index += 1;
58
59     return;
60 }
61
62 static void server_keylog_callback(const SSL *ssl, const char *line) {
63     int line_length = strlen(line);
64
65     /* If the log doesn't fit, error out. */
66     if ((server_log_buffer_index + line_length) > LOG_BUFFER_SIZE) {
67         printf("No room in server log\n");
68         error_writing_log = 1;
69         return;
70     }
71
72     strcat(server_log_buffer, line);
73     server_log_buffer_index += line_length;
74     server_log_buffer[server_log_buffer_index] = '\n';
75     server_log_buffer_index += 1;
76
77     return;
78 }
79
80 static int compare_hex_encoded_buffer(const char *hex_encoded,
81                                       size_t hex_length,
82                                       const uint8_t *raw,
83                                       size_t raw_length) {
84     size_t i;
85     size_t j;
86
87     /* One byte too big, just to be safe. */
88     char hexed[3] = {0};
89
90     if ((raw_length * 2) != hex_length) {
91         printf("Inconsistent hex encoded lengths.\n");
92         return 1;
93     }
94
95     for (i = j = 0; (i < raw_length) && ((j + 1) < hex_length); i++) {
96         sprintf(hexed, "%02x", raw[i]);
97         if ((hexed[0] != hex_encoded[j]) || (hexed[1] != hex_encoded[j + 1])) {
98             printf("Hex output does not match.\n");
99             return 1;
100         }
101         j += 2;
102     }
103
104     return 0;
105 }
106
107 static int test_keylog_output(char *buffer, const SSL *ssl,
108                               const SSL_SESSION *session) {
109     int saw_client_random = 0;
110     char *token = NULL;
111     unsigned char actual_client_random[SSL3_RANDOM_SIZE] = {0};
112     size_t client_random_size = SSL3_RANDOM_SIZE;
113     unsigned char actual_master_key[SSL_MAX_MASTER_KEY_LENGTH] = {0};
114     size_t master_key_size = SSL_MAX_MASTER_KEY_LENGTH;
115
116     token = strtok(buffer, " \n");
117     while (token) {
118         if (strcmp(token, "RSA") == 0) {
119             /* Premaster secret. Tokens should be: 16 ASCII bytes of
120              * hex-encoded encrypted secret, then the hex-encoded pre-master
121              * secret.
122              */
123             token = strtok(NULL, " \n");
124             if (!token) {
125                 printf("Unexpectedly short premaster secret log.\n");
126                 return -1;
127             }
128             if (strlen(token) != 16) {
129                 printf("Bad value for encrypted secret: %s\n", token);
130                 return -1;
131             }
132             token = strtok(NULL, " \n");
133             if (!token) {
134                 printf("Unexpectedly short premaster secret log.\n");
135                 return -1;
136             }
137             /* TODO: Can I check this sensibly? */
138         } else if (strcmp(token, "CLIENT_RANDOM") == 0) {
139             /* Master secret. Tokens should be: 64 ASCII bytes of hex-encoded
140              * client random, then the hex-encoded master secret.
141              */
142             client_random_size = SSL_get_client_random(ssl,
143                                                        actual_client_random,
144                                                        SSL3_RANDOM_SIZE);
145             if (client_random_size != SSL3_RANDOM_SIZE) {
146                 printf("Unexpected short client random.\n");
147                 return -1;
148             }
149
150             token = strtok(NULL, " \n");
151             if (!token) {
152                 printf("Unexpected short master secret log.\n");
153                 return -1;
154             }
155             if (strlen(token) != 64) {
156                 printf("Bad value for client random: %s\n", token);
157                 return -1;
158             }
159             if (compare_hex_encoded_buffer(token, 64, actual_client_random,
160                                            client_random_size)) {
161                 printf("Bad value for client random: %s\n", token);
162                 return -1;
163             }
164
165             token = strtok(NULL, " \n");
166             if (!token) {
167                 printf("Unexpectedly short master secret log.\n");
168                 return -1;
169             }
170
171             master_key_size = SSL_SESSION_get_master_key(session,
172                                                          actual_master_key,
173                                                          master_key_size);
174             if (!master_key_size) {
175                 printf("Error getting master key to compare.\n");
176                 return -1;
177             }
178             if (compare_hex_encoded_buffer(token, strlen(token),
179                                            actual_master_key,
180                                            master_key_size)) {
181                 printf("Bad value for master key: %s\n", token);
182                 return -1;
183             }
184
185             saw_client_random = 1;
186         } else {
187             printf("Unexpected token in buffer: %s\n", token);
188             return -1;
189         }
190
191         token = strtok(NULL, " \n");
192     }
193
194     return saw_client_random;
195 }
196
197 static int test_keylog(void) {
198     SSL_CTX *cctx = NULL, *sctx = NULL;
199     SSL *clientssl = NULL, *serverssl = NULL;
200     int testresult = 0;
201     int rc;
202
203     /* Clean up logging space */
204     memset(client_log_buffer, 0, LOG_BUFFER_SIZE + 1);
205     memset(server_log_buffer, 0, LOG_BUFFER_SIZE + 1);
206     client_log_buffer_index = 0;
207     server_log_buffer_index = 0;
208     error_writing_log = 0;
209
210     if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
211                              &cctx, cert, privkey)) {
212         printf("Unable to create SSL_CTX pair\n");
213         return 0;
214     }
215
216     /* We cannot log the master secret for TLSv1.3, so we should forbid it. */
217     SSL_CTX_set_options(cctx, SSL_OP_NO_TLSv1_3);
218     SSL_CTX_set_options(sctx, SSL_OP_NO_TLSv1_3);
219
220     /* We also want to ensure that we use RSA-based key exchange. */
221     rc = SSL_CTX_set_cipher_list(cctx, "RSA");
222     if (rc == 0) {
223         printf("Unable to restrict to RSA key exchange.\n");
224         goto end;
225     }
226
227     if (SSL_CTX_get_keylog_callback(cctx)) {
228         printf("Unexpected initial value for client "
229                "SSL_CTX_get_keylog_callback()\n");
230         goto end;
231     }
232     if (SSL_CTX_get_keylog_callback(sctx)) {
233         printf("Unexpected initial value for server "
234                "SSL_CTX_get_keylog_callback()\n");
235         goto end;
236     }
237
238     SSL_CTX_set_keylog_callback(cctx, client_keylog_callback);
239     SSL_CTX_set_keylog_callback(sctx, server_keylog_callback);
240
241     if (SSL_CTX_get_keylog_callback(cctx) != client_keylog_callback) {
242         printf("Unexpected set value for client "
243                "SSL_CTX_get_keylog_callback()\n");
244     }
245
246     if (SSL_CTX_get_keylog_callback(sctx) != server_keylog_callback) {
247         printf("Unexpected set value for server "
248                "SSL_CTX_get_keylog_callback()\n");
249     }
250
251     /* Now do a handshake and check that the logs have been written to. */
252     if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
253         printf("Unable to create SSL objects\n");
254         goto end;
255     }
256
257     if (!create_ssl_connection(serverssl, clientssl)) {
258         printf("Unable to create SSL connection\n");
259         goto end;
260     }
261
262     if (error_writing_log) {
263         printf("Error encountered while logging\n");
264         goto end;
265     }
266
267     if ((client_log_buffer_index == 0) || (server_log_buffer_index == 0)) {
268         printf("No logs written\n");
269         goto end;
270     }
271
272     /* Now we want to test that our output data was vaguely sensible. We
273      * do that by using strtok and confirming that we have more or less the
274      * data we expect.
275      */
276     if (test_keylog_output(client_log_buffer, clientssl,
277                            SSL_get_session(clientssl)) != 1) {
278         printf("Error encountered in client log buffer\n");
279         goto end;
280     }
281     if (test_keylog_output(server_log_buffer, serverssl,
282                            SSL_get_session(serverssl)) != 1) {
283         printf("Error encountered in server log buffer\n");
284         goto end;
285     }
286
287     testresult = 1;
288
289 end:
290     SSL_free(serverssl);
291     SSL_free(clientssl);
292     SSL_CTX_free(sctx);
293     SSL_CTX_free(cctx);
294
295     return testresult;
296 }
297
298 #ifndef OPENSSL_NO_TLS1_3
299 static int test_keylog_no_master_key(void) {
300     SSL_CTX *cctx = NULL, *sctx = NULL;
301     SSL *clientssl = NULL, *serverssl = NULL;
302     int testresult = 0;
303
304     /* Clean up logging space */
305     memset(client_log_buffer, 0, LOG_BUFFER_SIZE + 1);
306     memset(server_log_buffer, 0, LOG_BUFFER_SIZE + 1);
307     client_log_buffer_index = 0;
308     server_log_buffer_index = 0;
309     error_writing_log = 0;
310
311     if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
312                              &cctx, cert, privkey)) {
313         printf("Unable to create SSL_CTX pair\n");
314         return 0;
315     }
316
317     if (SSL_CTX_get_keylog_callback(cctx)) {
318         printf("Unexpected initial value for client "
319                "SSL_CTX_get_keylog_callback()\n");
320         goto end;
321     }
322     if (SSL_CTX_get_keylog_callback(sctx)) {
323         printf("Unexpected initial value for server "
324                "SSL_CTX_get_keylog_callback()\n");
325         goto end;
326     }
327
328     SSL_CTX_set_keylog_callback(cctx, client_keylog_callback);
329     SSL_CTX_set_keylog_callback(sctx, server_keylog_callback);
330
331     if (SSL_CTX_get_keylog_callback(cctx) != client_keylog_callback) {
332         printf("Unexpected set value for client "
333                "SSL_CTX_get_keylog_callback()\n");
334     }
335
336     if (SSL_CTX_get_keylog_callback(sctx) != server_keylog_callback) {
337         printf("Unexpected set value for server "
338                "SSL_CTX_get_keylog_callback()\n");
339     }
340
341     /* Now do a handshake and check that the logs have been written to. */
342     if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
343         printf("Unable to create SSL objects\n");
344         goto end;
345     }
346
347     if (!create_ssl_connection(serverssl, clientssl)) {
348         printf("Unable to create SSL connection\n");
349         goto end;
350     }
351
352     if (error_writing_log) {
353         printf("Error encountered while logging\n");
354         goto end;
355     }
356
357     /* Now we want to test that our output data was vaguely sensible. For this
358      * test, we expect no CLIENT_RANDOM entry.
359      */
360     if (test_keylog_output(client_log_buffer, clientssl,
361                            SSL_get_session(clientssl)) != 0) {
362         printf("Error encountered in client log buffer\n");
363         goto end;
364     }
365     if (test_keylog_output(server_log_buffer, serverssl,
366                            SSL_get_session(serverssl)) != 0) {
367         printf("Error encountered in server log buffer\n");
368         goto end;
369     }
370
371     testresult = 1;
372
373 end:
374     SSL_free(serverssl);
375     SSL_free(clientssl);
376     SSL_CTX_free(sctx);
377     SSL_CTX_free(cctx);
378
379     return testresult;
380 }
381 #endif
382
383 static int execute_test_large_message(const SSL_METHOD *smeth,
384                                       const SSL_METHOD *cmeth, int read_ahead)
385 {
386     SSL_CTX *cctx = NULL, *sctx = NULL;
387     SSL *clientssl = NULL, *serverssl = NULL;
388     int testresult = 0;
389     int i;
390     BIO *certbio = BIO_new_file(cert, "r");
391     X509 *chaincert = NULL;
392     int certlen;
393
394     if (certbio == NULL) {
395         printf("Can't load the certficate file\n");
396         goto end;
397     }
398     chaincert = PEM_read_bio_X509(certbio, NULL, NULL, NULL);
399     BIO_free(certbio);
400     certbio = NULL;
401     if (chaincert == NULL) {
402         printf("Unable to load certificate for chain\n");
403         goto end;
404     }
405
406     if (!create_ssl_ctx_pair(smeth, cmeth, &sctx,
407                              &cctx, cert, privkey)) {
408         printf("Unable to create SSL_CTX pair\n");
409         goto end;
410     }
411
412     if(read_ahead) {
413         /*
414          * Test that read_ahead works correctly when dealing with large
415          * records
416          */
417         SSL_CTX_set_read_ahead(cctx, 1);
418     }
419
420     /*
421      * We assume the supplied certificate is big enough so that if we add
422      * NUM_EXTRA_CERTS it will make the overall message large enough. The
423      * default buffer size is requested to be 16k, but due to the way BUF_MEM
424      * works, it ends up allocing a little over 21k (16 * 4/3). So, in this test
425      * we need to have a message larger than that.
426      */
427     certlen = i2d_X509(chaincert, NULL);
428     OPENSSL_assert((certlen * NUM_EXTRA_CERTS)
429                    > ((SSL3_RT_MAX_PLAIN_LENGTH * 4) / 3));
430     for (i = 0; i < NUM_EXTRA_CERTS; i++) {
431         if (!X509_up_ref(chaincert)) {
432             printf("Unable to up ref cert\n");
433             goto end;
434         }
435         if (!SSL_CTX_add_extra_chain_cert(sctx, chaincert)) {
436             printf("Unable to add extra chain cert %d\n", i);
437             X509_free(chaincert);
438             goto end;
439         }
440     }
441
442     if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
443         printf("Unable to create SSL objects\n");
444         goto end;
445     }
446
447     if (!create_ssl_connection(serverssl, clientssl)) {
448         printf("Unable to create SSL connection\n");
449         goto end;
450     }
451
452     /*
453      * Calling SSL_clear() first is not required but this tests that SSL_clear()
454      * doesn't leak (when using enable-crypto-mdebug).
455      */
456     if (!SSL_clear(serverssl)) {
457         printf("Unexpected failure from SSL_clear()\n");
458         goto end;
459     }
460
461     testresult = 1;
462  end:
463     X509_free(chaincert);
464     SSL_free(serverssl);
465     SSL_free(clientssl);
466     SSL_CTX_free(sctx);
467     SSL_CTX_free(cctx);
468
469     return testresult;
470 }
471
472 static int test_large_message_tls(void)
473 {
474     return execute_test_large_message(TLS_server_method(), TLS_client_method(),
475                                       0);
476 }
477
478 static int test_large_message_tls_read_ahead(void)
479 {
480     return execute_test_large_message(TLS_server_method(), TLS_client_method(),
481                                       1);
482 }
483
484 #ifndef OPENSSL_NO_DTLS
485 static int test_large_message_dtls(void)
486 {
487     /*
488      * read_ahead is not relevant to DTLS because DTLS always acts as if
489      * read_ahead is set.
490      */
491     return execute_test_large_message(DTLS_server_method(),
492                                       DTLS_client_method(), 0);
493 }
494 #endif
495
496 #ifndef OPENSSL_NO_OCSP
497 static int ocsp_server_cb(SSL *s, void *arg)
498 {
499     int *argi = (int *)arg;
500     unsigned char *orespdercopy = NULL;
501     STACK_OF(OCSP_RESPID) *ids = NULL;
502     OCSP_RESPID *id = NULL;
503
504     if (*argi == 2) {
505         /* In this test we are expecting exactly 1 OCSP_RESPID */
506         SSL_get_tlsext_status_ids(s, &ids);
507         if (ids == NULL || sk_OCSP_RESPID_num(ids) != 1)
508             return SSL_TLSEXT_ERR_ALERT_FATAL;
509
510         id = sk_OCSP_RESPID_value(ids, 0);
511         if (id == NULL || !OCSP_RESPID_match(id, ocspcert))
512             return SSL_TLSEXT_ERR_ALERT_FATAL;
513     } else if (*argi != 1) {
514         return SSL_TLSEXT_ERR_ALERT_FATAL;
515     }
516
517
518     orespdercopy = OPENSSL_memdup(orespder, sizeof(orespder));
519     if (orespdercopy == NULL)
520         return SSL_TLSEXT_ERR_ALERT_FATAL;
521
522     SSL_set_tlsext_status_ocsp_resp(s, orespdercopy, sizeof(orespder));
523
524     ocsp_server_called = 1;
525
526     return SSL_TLSEXT_ERR_OK;
527 }
528
529 static int ocsp_client_cb(SSL *s, void *arg)
530 {
531     int *argi = (int *)arg;
532     const unsigned char *respderin;
533     size_t len;
534
535     if (*argi != 1 && *argi != 2)
536         return 0;
537
538     len = SSL_get_tlsext_status_ocsp_resp(s, &respderin);
539
540     if (memcmp(orespder, respderin, len) != 0)
541         return 0;
542
543     ocsp_client_called = 1;
544
545     return 1;
546 }
547
548 static int test_tlsext_status_type(void)
549 {
550     SSL_CTX *cctx = NULL, *sctx = NULL;
551     SSL *clientssl = NULL, *serverssl = NULL;
552     int testresult = 0;
553     STACK_OF(OCSP_RESPID) *ids = NULL;
554     OCSP_RESPID *id = NULL;
555     BIO *certbio = NULL;
556
557     if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
558                              &cctx, cert, privkey)) {
559         printf("Unable to create SSL_CTX pair\n");
560         return 0;
561     }
562
563     if (SSL_CTX_get_tlsext_status_type(cctx) != -1) {
564         printf("Unexpected initial value for "
565                "SSL_CTX_get_tlsext_status_type()\n");
566         goto end;
567     }
568
569     /* First just do various checks getting and setting tlsext_status_type */
570
571     clientssl = SSL_new(cctx);
572     if (SSL_get_tlsext_status_type(clientssl) != -1) {
573         printf("Unexpected initial value for SSL_get_tlsext_status_type()\n");
574         goto end;
575     }
576
577     if (!SSL_set_tlsext_status_type(clientssl, TLSEXT_STATUSTYPE_ocsp)) {
578         printf("Unexpected fail for SSL_set_tlsext_status_type()\n");
579         goto end;
580     }
581
582     if (SSL_get_tlsext_status_type(clientssl) != TLSEXT_STATUSTYPE_ocsp) {
583         printf("Unexpected result for SSL_get_tlsext_status_type()\n");
584         goto end;
585     }
586
587     SSL_free(clientssl);
588     clientssl = NULL;
589
590     if (!SSL_CTX_set_tlsext_status_type(cctx, TLSEXT_STATUSTYPE_ocsp)) {
591         printf("Unexpected fail for SSL_CTX_set_tlsext_status_type()\n");
592         goto end;
593     }
594
595     if (SSL_CTX_get_tlsext_status_type(cctx) != TLSEXT_STATUSTYPE_ocsp) {
596         printf("Unexpected result for SSL_CTX_get_tlsext_status_type()\n");
597         goto end;
598     }
599
600     clientssl = SSL_new(cctx);
601
602     if (SSL_get_tlsext_status_type(clientssl) != TLSEXT_STATUSTYPE_ocsp) {
603         printf("Unexpected result for SSL_get_tlsext_status_type() (test 2)\n");
604         goto end;
605     }
606
607     SSL_free(clientssl);
608     clientssl = NULL;
609
610     /*
611      * Now actually do a handshake and check OCSP information is exchanged and
612      * the callbacks get called
613      */
614
615     SSL_CTX_set_tlsext_status_cb(cctx, ocsp_client_cb);
616     SSL_CTX_set_tlsext_status_arg(cctx, &cdummyarg);
617     SSL_CTX_set_tlsext_status_cb(sctx, ocsp_server_cb);
618     SSL_CTX_set_tlsext_status_arg(sctx, &cdummyarg);
619
620     if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
621         printf("Unable to create SSL objects\n");
622         goto end;
623     }
624
625     if (!create_ssl_connection(serverssl, clientssl)) {
626         printf("Unable to create SSL connection\n");
627         goto end;
628     }
629
630     if (!ocsp_client_called || !ocsp_server_called) {
631         printf("OCSP callbacks not called\n");
632         goto end;
633     }
634
635     SSL_free(serverssl);
636     SSL_free(clientssl);
637     serverssl = NULL;
638     clientssl = NULL;
639
640     /* Try again but this time force the server side callback to fail */
641     ocsp_client_called = 0;
642     ocsp_server_called = 0;
643     cdummyarg = 0;
644
645     if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
646         printf("Unable to create SSL objects\n");
647         goto end;
648     }
649
650     /* This should fail because the callback will fail */
651     if (create_ssl_connection(serverssl, clientssl)) {
652         printf("Unexpected success creating the connection\n");
653         goto end;
654     }
655
656     if (ocsp_client_called || ocsp_server_called) {
657         printf("OCSP callbacks successfully called unexpectedly\n");
658         goto end;
659     }
660
661     SSL_free(serverssl);
662     SSL_free(clientssl);
663     serverssl = NULL;
664     clientssl = NULL;
665
666     /*
667      * This time we'll get the client to send an OCSP_RESPID that it will
668      * accept.
669      */
670     ocsp_client_called = 0;
671     ocsp_server_called = 0;
672     cdummyarg = 2;
673
674     if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
675         printf("Unable to create SSL objects\n");
676         goto end;
677     }
678
679     /*
680      * We'll just use any old cert for this test - it doesn't have to be an OCSP
681      * specifc one. We'll use the server cert.
682      */
683     certbio = BIO_new_file(cert, "r");
684     if (certbio == NULL) {
685         printf("Can't load the certficate file\n");
686         goto end;
687     }
688     id = OCSP_RESPID_new();
689     ids = sk_OCSP_RESPID_new_null();
690     ocspcert = PEM_read_bio_X509(certbio, NULL, NULL, NULL);
691     if (id == NULL || ids == NULL || ocspcert == NULL
692             || !OCSP_RESPID_set_by_key(id, ocspcert)
693             || !sk_OCSP_RESPID_push(ids, id)) {
694         printf("Unable to set OCSP_RESPIDs\n");
695         goto end;
696     }
697     id = NULL;
698     SSL_set_tlsext_status_ids(clientssl, ids);
699     /* Control has been transferred */
700     ids = NULL;
701
702     BIO_free(certbio);
703     certbio = NULL;
704
705     if (!create_ssl_connection(serverssl, clientssl)) {
706         printf("Unable to create SSL connection\n");
707         goto end;
708     }
709
710     if (!ocsp_client_called || !ocsp_server_called) {
711         printf("OCSP callbacks not called\n");
712         goto end;
713     }
714
715     testresult = 1;
716
717  end:
718     SSL_free(serverssl);
719     SSL_free(clientssl);
720     SSL_CTX_free(sctx);
721     SSL_CTX_free(cctx);
722     sk_OCSP_RESPID_pop_free(ids, OCSP_RESPID_free);
723     OCSP_RESPID_free(id);
724     BIO_free(certbio);
725     X509_free(ocspcert);
726     ocspcert = NULL;
727
728     return testresult;
729 }
730 #endif
731
732 typedef struct ssl_session_test_fixture {
733     const char *test_case_name;
734     int use_ext_cache;
735     int use_int_cache;
736 } SSL_SESSION_TEST_FIXTURE;
737
738 static int new_called = 0, remove_called = 0;
739
740 static SSL_SESSION_TEST_FIXTURE
741 ssl_session_set_up(const char *const test_case_name)
742 {
743     SSL_SESSION_TEST_FIXTURE fixture;
744
745     fixture.test_case_name = test_case_name;
746     fixture.use_ext_cache = 1;
747     fixture.use_int_cache = 1;
748
749     new_called = remove_called = 0;
750
751     return fixture;
752 }
753
754 static void ssl_session_tear_down(SSL_SESSION_TEST_FIXTURE fixture)
755 {
756 }
757
758 static int new_session_cb(SSL *ssl, SSL_SESSION *sess)
759 {
760     new_called++;
761
762     return 1;
763 }
764
765 static void remove_session_cb(SSL_CTX *ctx, SSL_SESSION *sess)
766 {
767     remove_called++;
768 }
769
770 static int execute_test_session(SSL_SESSION_TEST_FIXTURE fix)
771 {
772     SSL_CTX *sctx = NULL, *cctx = NULL;
773     SSL *serverssl1 = NULL, *clientssl1 = NULL;
774     SSL *serverssl2 = NULL, *clientssl2 = NULL;
775 #ifndef OPENSSL_NO_TLS1_1
776     SSL *serverssl3 = NULL, *clientssl3 = NULL;
777 #endif
778     SSL_SESSION *sess1 = NULL, *sess2 = NULL;
779     int testresult = 0;
780
781     if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
782                              &cctx, cert, privkey)) {
783         printf("Unable to create SSL_CTX pair\n");
784         return 0;
785     }
786
787 #ifndef OPENSSL_NO_TLS1_2
788     /* Only allow TLS1.2 so we can force a connection failure later */
789     SSL_CTX_set_min_proto_version(cctx, TLS1_2_VERSION);
790 #endif
791
792     /*
793      * TODO(TLS1.3): Test temporarily disabled for TLS1.3 until we've
794      * implemented session resumption.
795      */
796     SSL_CTX_set_max_proto_version(cctx, TLS1_2_VERSION);
797
798     /* Set up session cache */
799     if (fix.use_ext_cache) {
800         SSL_CTX_sess_set_new_cb(cctx, new_session_cb);
801         SSL_CTX_sess_set_remove_cb(cctx, remove_session_cb);
802     }
803     if (fix.use_int_cache) {
804         /* Also covers instance where both are set */
805         SSL_CTX_set_session_cache_mode(cctx, SSL_SESS_CACHE_CLIENT);
806     } else {
807         SSL_CTX_set_session_cache_mode(cctx,
808                                        SSL_SESS_CACHE_CLIENT
809                                        | SSL_SESS_CACHE_NO_INTERNAL_STORE);
810     }
811
812     if (!create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1, NULL,
813                                NULL)) {
814         printf("Unable to create SSL objects\n");
815         goto end;
816     }
817
818     if (!create_ssl_connection(serverssl1, clientssl1)) {
819         printf("Unable to create SSL connection\n");
820         goto end;
821     }
822     sess1 = SSL_get1_session(clientssl1);
823     if (sess1 == NULL) {
824         printf("Unexpected NULL session\n");
825         goto end;
826     }
827
828     if (fix.use_int_cache && SSL_CTX_add_session(cctx, sess1)) {
829         /* Should have failed because it should already be in the cache */
830         printf("Unexpected success adding session to cache\n");
831         goto end;
832     }
833
834     if (fix.use_ext_cache && (new_called != 1 || remove_called != 0)) {
835         printf("Session not added to cache\n");
836         goto end;
837     }
838
839     if (!create_ssl_objects(sctx, cctx, &serverssl2, &clientssl2, NULL, NULL)) {
840         printf("Unable to create second SSL objects\n");
841         goto end;
842     }
843
844     if (!create_ssl_connection(serverssl2, clientssl2)) {
845         printf("Unable to create second SSL connection\n");
846         goto end;
847     }
848
849     sess2 = SSL_get1_session(clientssl2);
850     if (sess2 == NULL) {
851         printf("Unexpected NULL session from clientssl2\n");
852         goto end;
853     }
854
855     if (fix.use_ext_cache && (new_called != 2 || remove_called != 0)) {
856         printf("Remove session callback unexpectedly called\n");
857         goto end;
858     }
859
860     /*
861      * This should clear sess2 from the cache because it is a "bad" session. See
862      * SSL_set_session() documentation.
863      */
864     if (!SSL_set_session(clientssl2, sess1)) {
865         printf("Unexpected failure setting session\n");
866         goto end;
867     }
868
869     if (fix.use_ext_cache && (new_called != 2 || remove_called != 1)) {
870         printf("Failed to call callback to remove session\n");
871         goto end;
872     }
873
874
875     if (SSL_get_session(clientssl2) != sess1) {
876         printf("Unexpected session found\n");
877         goto end;
878     }
879
880     if (fix.use_int_cache) {
881         if (!SSL_CTX_add_session(cctx, sess2)) {
882             /*
883              * Should have succeeded because it should not already be in the cache
884              */
885             printf("Unexpected failure adding session to cache\n");
886             goto end;
887         }
888
889         if (!SSL_CTX_remove_session(cctx, sess2)) {
890             printf("Unexpected failure removing session from cache\n");
891             goto end;
892         }
893
894         /* This is for the purposes of internal cache testing...ignore the
895          * counter for external cache
896          */
897         if (fix.use_ext_cache)
898             remove_called--;
899     }
900
901     /* This shouldn't be in the cache so should fail */
902     if (SSL_CTX_remove_session(cctx, sess2)) {
903         printf("Unexpected success removing session from cache\n");
904         goto end;
905     }
906
907     if (fix.use_ext_cache && (new_called != 2 || remove_called != 2)) {
908         printf("Failed to call callback to remove session #2\n");
909         goto end;
910     }
911
912 #if !defined(OPENSSL_NO_TLS1_1) && !defined(OPENSSL_NO_TLS1_2)
913     /* Force a connection failure */
914     SSL_CTX_set_max_proto_version(sctx, TLS1_1_VERSION);
915
916     if (!create_ssl_objects(sctx, cctx, &serverssl3, &clientssl3, NULL, NULL)) {
917         printf("Unable to create third SSL objects\n");
918         goto end;
919     }
920
921     if (!SSL_set_session(clientssl3, sess1)) {
922         printf("Unable to set session for third connection\n");
923         goto end;
924     }
925
926     /* This should fail because of the mismatched protocol versions */
927     if (create_ssl_connection(serverssl3, clientssl3)) {
928         printf("Unable to create third SSL connection\n");
929         goto end;
930     }
931
932
933     /* We should have automatically removed the session from the cache */
934     if (fix.use_ext_cache && (new_called != 2 || remove_called != 3)) {
935         printf("Failed to call callback to remove session #2\n");
936         goto end;
937     }
938
939     if (fix.use_int_cache && !SSL_CTX_add_session(cctx, sess2)) {
940         /*
941          * Should have succeeded because it should not already be in the cache
942          */
943         printf("Unexpected failure adding session to cache #2\n");
944         goto end;
945     }
946 #endif
947
948     testresult = 1;
949
950  end:
951     SSL_free(serverssl1);
952     SSL_free(clientssl1);
953     SSL_free(serverssl2);
954     SSL_free(clientssl2);
955 #ifndef OPENSSL_NO_TLS1_1
956     SSL_free(serverssl3);
957     SSL_free(clientssl3);
958 #endif
959     SSL_SESSION_free(sess1);
960     SSL_SESSION_free(sess2);
961     /*
962      * Check if we need to remove any sessions up-refed for the external cache
963      */
964     if (new_called >= 1)
965         SSL_SESSION_free(sess1);
966     if (new_called >= 2)
967         SSL_SESSION_free(sess2);
968     SSL_CTX_free(sctx);
969     SSL_CTX_free(cctx);
970
971     return testresult;
972 }
973
974 static int test_session_with_only_int_cache(void)
975 {
976     SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
977
978     fixture.use_ext_cache = 0;
979
980     EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
981 }
982
983 static int test_session_with_only_ext_cache(void)
984 {
985     SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
986
987     fixture.use_int_cache = 0;
988
989     EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
990 }
991
992 static int test_session_with_both_cache(void)
993 {
994     SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
995
996     EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
997 }
998
999 #define USE_NULL    0
1000 #define USE_BIO_1   1
1001 #define USE_BIO_2   2
1002
1003 #define TOTAL_SSL_SET_BIO_TESTS (3 * 3 * 3 * 3)
1004
1005 static void setupbio(BIO **res, BIO *bio1, BIO *bio2, int type)
1006 {
1007     switch (type) {
1008     case USE_NULL:
1009         *res = NULL;
1010         break;
1011     case USE_BIO_1:
1012         *res = bio1;
1013         break;
1014     case USE_BIO_2:
1015         *res = bio2;
1016         break;
1017     }
1018 }
1019
1020 static int test_ssl_set_bio(int idx)
1021 {
1022     SSL_CTX *ctx = SSL_CTX_new(TLS_method());
1023     BIO *bio1 = NULL;
1024     BIO *bio2 = NULL;
1025     BIO *irbio = NULL, *iwbio = NULL, *nrbio = NULL, *nwbio = NULL;
1026     SSL *ssl = NULL;
1027     int initrbio, initwbio, newrbio, newwbio;
1028     int testresult = 0;
1029
1030     if (ctx == NULL) {
1031         printf("Failed to allocate SSL_CTX\n");
1032         goto end;
1033     }
1034
1035     ssl = SSL_new(ctx);
1036     if (ssl == NULL) {
1037         printf("Failed to allocate SSL object\n");
1038         goto end;
1039     }
1040
1041     initrbio = idx % 3;
1042     idx /= 3;
1043     initwbio = idx % 3;
1044     idx /= 3;
1045     newrbio = idx % 3;
1046     idx /= 3;
1047     newwbio = idx;
1048     OPENSSL_assert(newwbio <= 2);
1049
1050     if (initrbio == USE_BIO_1 || initwbio == USE_BIO_1 || newrbio == USE_BIO_1
1051             || newwbio == USE_BIO_1) {
1052         bio1 = BIO_new(BIO_s_mem());
1053         if (bio1 == NULL) {
1054             printf("Failed to allocate bio1\n");
1055             goto end;
1056         }
1057     }
1058
1059     if (initrbio == USE_BIO_2 || initwbio == USE_BIO_2 || newrbio == USE_BIO_2
1060             || newwbio == USE_BIO_2) {
1061         bio2 = BIO_new(BIO_s_mem());
1062         if (bio2 == NULL) {
1063             printf("Failed to allocate bio2\n");
1064             goto end;
1065         }
1066     }
1067
1068     setupbio(&irbio, bio1, bio2, initrbio);
1069     setupbio(&iwbio, bio1, bio2, initwbio);
1070
1071     /*
1072      * We want to maintain our own refs to these BIO, so do an up ref for each
1073      * BIO that will have ownersip transferred in the SSL_set_bio() call
1074      */
1075     if (irbio != NULL)
1076         BIO_up_ref(irbio);
1077     if (iwbio != NULL && iwbio != irbio)
1078         BIO_up_ref(iwbio);
1079
1080     SSL_set_bio(ssl, irbio, iwbio);
1081
1082     setupbio(&nrbio, bio1, bio2, newrbio);
1083     setupbio(&nwbio, bio1, bio2, newwbio);
1084
1085     /*
1086      * We will (maybe) transfer ownership again so do more up refs.
1087      * SSL_set_bio() has some really complicated ownership rules where BIOs have
1088      * already been set!
1089      */
1090     if (nrbio != NULL && nrbio != irbio && (nwbio != iwbio || nrbio != nwbio))
1091         BIO_up_ref(nrbio);
1092     if (nwbio != NULL && nwbio != nrbio && (nwbio != iwbio || (nwbio == iwbio && irbio == iwbio)))
1093         BIO_up_ref(nwbio);
1094
1095     SSL_set_bio(ssl, nrbio, nwbio);
1096
1097     testresult = 1;
1098
1099  end:
1100     SSL_free(ssl);
1101     BIO_free(bio1);
1102     BIO_free(bio2);
1103     /*
1104      * This test is checking that the ref counting for SSL_set_bio is correct.
1105      * If we get here and we did too many frees then we will fail in the above
1106      * functions. If we haven't done enough then this will only be detected in
1107      * a crypto-mdebug build
1108      */
1109     SSL_CTX_free(ctx);
1110
1111     return testresult;
1112 }
1113
1114 typedef struct ssl_bio_test_fixture {
1115     const char *test_case_name;
1116     int pop_ssl;
1117     enum { NO_BIO_CHANGE, CHANGE_RBIO, CHANGE_WBIO } change_bio;
1118 } SSL_BIO_TEST_FIXTURE;
1119
1120 static SSL_BIO_TEST_FIXTURE ssl_bio_set_up(const char *const test_case_name)
1121 {
1122     SSL_BIO_TEST_FIXTURE fixture;
1123
1124     fixture.test_case_name = test_case_name;
1125     fixture.pop_ssl = 0;
1126     fixture.change_bio = NO_BIO_CHANGE;
1127
1128     return fixture;
1129 }
1130
1131 static void ssl_bio_tear_down(SSL_BIO_TEST_FIXTURE fixture)
1132 {
1133 }
1134
1135 static int execute_test_ssl_bio(SSL_BIO_TEST_FIXTURE fix)
1136 {
1137     BIO *sslbio = NULL, *membio1 = NULL, *membio2 = NULL;
1138     SSL_CTX *ctx = SSL_CTX_new(TLS_method());
1139     SSL *ssl = NULL;
1140     int testresult = 0;
1141
1142     if (ctx == NULL) {
1143         printf("Failed to allocate SSL_CTX\n");
1144         return 0;
1145     }
1146
1147     ssl = SSL_new(ctx);
1148     if (ssl == NULL) {
1149         printf("Failed to allocate SSL object\n");
1150         goto end;
1151     }
1152
1153     sslbio = BIO_new(BIO_f_ssl());
1154     membio1 = BIO_new(BIO_s_mem());
1155
1156     if (sslbio == NULL || membio1 == NULL) {
1157         printf("Malloc failure creating BIOs\n");
1158         goto end;
1159     }
1160
1161     BIO_set_ssl(sslbio, ssl, BIO_CLOSE);
1162
1163     /*
1164      * If anything goes wrong here then we could leak memory, so this will
1165      * be caught in a crypto-mdebug build
1166      */
1167     BIO_push(sslbio, membio1);
1168
1169     /* Verify chaning the rbio/wbio directly does not cause leaks */
1170     if (fix.change_bio != NO_BIO_CHANGE) {
1171         membio2 = BIO_new(BIO_s_mem());
1172         if (membio2 == NULL) {
1173             printf("Malloc failure creating membio2\n");
1174             goto end;
1175         }
1176         if (fix.change_bio == CHANGE_RBIO)
1177             SSL_set0_rbio(ssl, membio2);
1178         else
1179             SSL_set0_wbio(ssl, membio2);
1180     }
1181     ssl = NULL;
1182
1183     if (fix.pop_ssl)
1184         BIO_pop(sslbio);
1185     else
1186         BIO_pop(membio1);
1187
1188     testresult = 1;
1189  end:
1190     BIO_free(membio1);
1191     BIO_free(sslbio);
1192     SSL_free(ssl);
1193     SSL_CTX_free(ctx);
1194
1195     return testresult;
1196 }
1197
1198 static int test_ssl_bio_pop_next_bio(void)
1199 {
1200     SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
1201
1202     EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
1203 }
1204
1205 static int test_ssl_bio_pop_ssl_bio(void)
1206 {
1207     SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
1208
1209     fixture.pop_ssl = 1;
1210
1211     EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
1212 }
1213
1214 static int test_ssl_bio_change_rbio(void)
1215 {
1216     SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
1217
1218     fixture.change_bio = CHANGE_RBIO;
1219
1220     EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
1221 }
1222
1223 static int test_ssl_bio_change_wbio(void)
1224 {
1225     SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
1226
1227     fixture.change_bio = CHANGE_WBIO;
1228
1229     EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
1230 }
1231
1232 typedef struct {
1233     /* The list of sig algs */
1234     const int *list;
1235     /* The length of the list */
1236     size_t listlen;
1237     /* A sigalgs list in string format */
1238     const char *liststr;
1239     /* Whether setting the list should succeed */
1240     int valid;
1241     /* Whether creating a connection with the list should succeed */
1242     int connsuccess;
1243 } sigalgs_list;
1244
1245 static const int validlist1[] = {NID_sha256, EVP_PKEY_RSA};
1246 #ifndef OPENSSL_NO_EC
1247 static const int validlist2[] = {NID_sha256, EVP_PKEY_RSA, NID_sha512, EVP_PKEY_EC};
1248 static const int validlist3[] = {NID_sha512, EVP_PKEY_EC};
1249 #endif
1250 static const int invalidlist1[] = {NID_undef, EVP_PKEY_RSA};
1251 static const int invalidlist2[] = {NID_sha256, NID_undef};
1252 static const int invalidlist3[] = {NID_sha256, EVP_PKEY_RSA, NID_sha256};
1253 static const int invalidlist4[] = {NID_sha256};
1254 static const sigalgs_list testsigalgs[] = {
1255     {validlist1, OSSL_NELEM(validlist1), NULL, 1, 1},
1256 #ifndef OPENSSL_NO_EC
1257     {validlist2, OSSL_NELEM(validlist2), NULL, 1, 1},
1258     {validlist3, OSSL_NELEM(validlist3), NULL, 1, 0},
1259 #endif
1260     {NULL, 0, "RSA+SHA256", 1, 1},
1261 #ifndef OPENSSL_NO_EC
1262     {NULL, 0, "RSA+SHA256:ECDSA+SHA512", 1, 1},
1263     {NULL, 0, "ECDSA+SHA512", 1, 0},
1264 #endif
1265     {invalidlist1, OSSL_NELEM(invalidlist1), NULL, 0, 0},
1266     {invalidlist2, OSSL_NELEM(invalidlist2), NULL, 0, 0},
1267     {invalidlist3, OSSL_NELEM(invalidlist3), NULL, 0, 0},
1268     {invalidlist4, OSSL_NELEM(invalidlist4), NULL, 0, 0},
1269     {NULL, 0, "RSA", 0, 0},
1270     {NULL, 0, "SHA256", 0, 0},
1271     {NULL, 0, "RSA+SHA256:SHA256", 0, 0},
1272     {NULL, 0, "Invalid", 0, 0}};
1273
1274 static int test_set_sigalgs(int idx)
1275 {
1276     SSL_CTX *cctx = NULL, *sctx = NULL;
1277     SSL *clientssl = NULL, *serverssl = NULL;
1278     int testresult = 0;
1279     const sigalgs_list *curr;
1280     int testctx;
1281
1282     /* Should never happen */
1283     if ((size_t)idx >= OSSL_NELEM(testsigalgs) * 2)
1284         return 0;
1285
1286     testctx = ((size_t)idx < OSSL_NELEM(testsigalgs));
1287     curr = testctx ? &testsigalgs[idx]
1288                    : &testsigalgs[idx - OSSL_NELEM(testsigalgs)];
1289
1290     if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
1291                              &cctx, cert, privkey)) {
1292         printf("Unable to create SSL_CTX pair\n");
1293         return 0;
1294     }
1295
1296     /*
1297      * TODO(TLS1.3): These APIs cannot set TLSv1.3 sig algs so we just test it
1298      * for TLSv1.2 for now until we add a new API.
1299      */
1300     SSL_CTX_set_max_proto_version(cctx, TLS1_2_VERSION);
1301
1302     if (testctx) {
1303         int ret;
1304         if (curr->list != NULL)
1305             ret = SSL_CTX_set1_sigalgs(cctx, curr->list, curr->listlen);
1306         else
1307             ret = SSL_CTX_set1_sigalgs_list(cctx, curr->liststr);
1308
1309         if (!ret) {
1310             if (curr->valid)
1311                 printf("Unexpected failure setting sigalgs in SSL_CTX (%d)\n",
1312                        idx);
1313             else
1314                 testresult = 1;
1315             goto end;
1316         }
1317         if (!curr->valid) {
1318             printf("Unexpected success setting sigalgs in SSL_CTX (%d)\n", idx);
1319             goto end;
1320         }
1321     }
1322
1323     if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
1324         printf("Unable to create SSL objects\n");
1325         goto end;
1326     }
1327
1328     if (!testctx) {
1329         int ret;
1330
1331         if (curr->list != NULL)
1332             ret = SSL_set1_sigalgs(clientssl, curr->list, curr->listlen);
1333         else
1334             ret = SSL_set1_sigalgs_list(clientssl, curr->liststr);
1335         if (!ret) {
1336             if (curr->valid)
1337                 printf("Unexpected failure setting sigalgs in SSL (%d)\n", idx);
1338             else
1339                 testresult = 1;
1340             goto end;
1341         }
1342         if (!curr->valid) {
1343             printf("Unexpected success setting sigalgs in SSL (%d)\n", idx);
1344             goto end;
1345         }
1346     }
1347
1348     if (curr->connsuccess != create_ssl_connection(serverssl, clientssl)) {
1349         printf("Unexpected return value creating SSL connection (%d)\n", idx);
1350         goto end;
1351     }
1352
1353     testresult = 1;
1354
1355  end:
1356     SSL_free(serverssl);
1357     SSL_free(clientssl);
1358     SSL_CTX_free(sctx);
1359     SSL_CTX_free(cctx);
1360
1361     return testresult;
1362 }
1363
1364 int test_main(int argc, char *argv[])
1365 {
1366     int testresult = 1;
1367
1368     if (argc != 3) {
1369         printf("Invalid argument count\n");
1370         return 1;
1371     }
1372
1373     cert = argv[1];
1374     privkey = argv[2];
1375
1376     ADD_TEST(test_large_message_tls);
1377     ADD_TEST(test_large_message_tls_read_ahead);
1378 #ifndef OPENSSL_NO_DTLS
1379     ADD_TEST(test_large_message_dtls);
1380 #endif
1381 #ifndef OPENSSL_NO_OCSP
1382     ADD_TEST(test_tlsext_status_type);
1383 #endif
1384     ADD_TEST(test_session_with_only_int_cache);
1385     ADD_TEST(test_session_with_only_ext_cache);
1386     ADD_TEST(test_session_with_both_cache);
1387     ADD_ALL_TESTS(test_ssl_set_bio, TOTAL_SSL_SET_BIO_TESTS);
1388     ADD_TEST(test_ssl_bio_pop_next_bio);
1389     ADD_TEST(test_ssl_bio_pop_ssl_bio);
1390     ADD_TEST(test_ssl_bio_change_rbio);
1391     ADD_TEST(test_ssl_bio_change_wbio);
1392     ADD_ALL_TESTS(test_set_sigalgs, OSSL_NELEM(testsigalgs) * 2);
1393     ADD_TEST(test_keylog);
1394 #ifndef OPENSSL_NO_TLS1_3
1395     ADD_TEST(test_keylog_no_master_key);
1396 #endif
1397
1398     testresult = run_tests(argv[0]);
1399
1400     bio_s_mempacket_test_free();
1401
1402     return testresult;
1403 }