2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
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
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>
18 #include "ssltestlib.h"
20 #include "test_main_custom.h"
23 static char *cert = NULL;
24 static char *privkey = NULL;
26 #ifndef OPENSSL_NO_OCSP
27 static const unsigned char orespder[] = "Dummy OCSP Response";
28 static int ocsp_server_called = 0;
29 static int ocsp_client_called = 0;
31 static int cdummyarg = 1;
32 static X509 *ocspcert = NULL;
35 #define NUM_EXTRA_CERTS 40
37 static int execute_test_large_message(const SSL_METHOD *smeth,
38 const SSL_METHOD *cmeth, int read_ahead)
40 SSL_CTX *cctx = NULL, *sctx = NULL;
41 SSL *clientssl = NULL, *serverssl = NULL;
44 BIO *certbio = BIO_new_file(cert, "r");
45 X509 *chaincert = NULL;
48 if (certbio == NULL) {
49 printf("Can't load the certficate file\n");
52 chaincert = PEM_read_bio_X509(certbio, NULL, NULL, NULL);
55 if (chaincert == NULL) {
56 printf("Unable to load certificate for chain\n");
60 if (!create_ssl_ctx_pair(smeth, cmeth, &sctx,
61 &cctx, cert, privkey)) {
62 printf("Unable to create SSL_CTX pair\n");
68 * Test that read_ahead works correctly when dealing with large
71 SSL_CTX_set_read_ahead(cctx, 1);
75 * We assume the supplied certificate is big enough so that if we add
76 * NUM_EXTRA_CERTS it will make the overall message large enough. The
77 * default buffer size is requested to be 16k, but due to the way BUF_MEM
78 * works, it ends up allocing a little over 21k (16 * 4/3). So, in this test
79 * we need to have a message larger than that.
81 certlen = i2d_X509(chaincert, NULL);
82 OPENSSL_assert((certlen * NUM_EXTRA_CERTS)
83 > ((SSL3_RT_MAX_PLAIN_LENGTH * 4) / 3));
84 for (i = 0; i < NUM_EXTRA_CERTS; i++) {
85 if (!X509_up_ref(chaincert)) {
86 printf("Unable to up ref cert\n");
89 if (!SSL_CTX_add_extra_chain_cert(sctx, chaincert)) {
90 printf("Unable to add extra chain cert %d\n", i);
96 if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
97 printf("Unable to create SSL objects\n");
101 if (!create_ssl_connection(serverssl, clientssl)) {
102 printf("Unable to create SSL connection\n");
107 * Calling SSL_clear() first is not required but this tests that SSL_clear()
108 * doesn't leak (when using enable-crypto-mdebug).
110 if (!SSL_clear(serverssl)) {
111 printf("Unexpected failure from SSL_clear()\n");
117 X509_free(chaincert);
126 static int test_large_message_tls(void)
128 return execute_test_large_message(TLS_server_method(), TLS_client_method(),
132 static int test_large_message_tls_read_ahead(void)
134 return execute_test_large_message(TLS_server_method(), TLS_client_method(),
138 #ifndef OPENSSL_NO_DTLS
139 static int test_large_message_dtls(void)
142 * read_ahead is not relevant to DTLS because DTLS always acts as if
145 return execute_test_large_message(DTLS_server_method(),
146 DTLS_client_method(), 0);
150 #ifndef OPENSSL_NO_OCSP
151 static int ocsp_server_cb(SSL *s, void *arg)
153 int *argi = (int *)arg;
154 unsigned char *orespdercopy = NULL;
155 STACK_OF(OCSP_RESPID) *ids = NULL;
156 OCSP_RESPID *id = NULL;
159 /* In this test we are expecting exactly 1 OCSP_RESPID */
160 SSL_get_tlsext_status_ids(s, &ids);
161 if (ids == NULL || sk_OCSP_RESPID_num(ids) != 1)
162 return SSL_TLSEXT_ERR_ALERT_FATAL;
164 id = sk_OCSP_RESPID_value(ids, 0);
165 if (id == NULL || !OCSP_RESPID_match(id, ocspcert))
166 return SSL_TLSEXT_ERR_ALERT_FATAL;
167 } else if (*argi != 1) {
168 return SSL_TLSEXT_ERR_ALERT_FATAL;
172 orespdercopy = OPENSSL_memdup(orespder, sizeof(orespder));
173 if (orespdercopy == NULL)
174 return SSL_TLSEXT_ERR_ALERT_FATAL;
176 SSL_set_tlsext_status_ocsp_resp(s, orespdercopy, sizeof(orespder));
178 ocsp_server_called = 1;
180 return SSL_TLSEXT_ERR_OK;
183 static int ocsp_client_cb(SSL *s, void *arg)
185 int *argi = (int *)arg;
186 const unsigned char *respderin;
189 if (*argi != 1 && *argi != 2)
192 len = SSL_get_tlsext_status_ocsp_resp(s, &respderin);
194 if (memcmp(orespder, respderin, len) != 0)
197 ocsp_client_called = 1;
202 static int test_tlsext_status_type(void)
204 SSL_CTX *cctx = NULL, *sctx = NULL;
205 SSL *clientssl = NULL, *serverssl = NULL;
207 STACK_OF(OCSP_RESPID) *ids = NULL;
208 OCSP_RESPID *id = NULL;
211 if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
212 &cctx, cert, privkey)) {
213 printf("Unable to create SSL_CTX pair\n");
217 if (SSL_CTX_get_tlsext_status_type(cctx) != -1) {
218 printf("Unexpected initial value for "
219 "SSL_CTX_get_tlsext_status_type()\n");
223 /* First just do various checks getting and setting tlsext_status_type */
225 clientssl = SSL_new(cctx);
226 if (SSL_get_tlsext_status_type(clientssl) != -1) {
227 printf("Unexpected initial value for SSL_get_tlsext_status_type()\n");
231 if (!SSL_set_tlsext_status_type(clientssl, TLSEXT_STATUSTYPE_ocsp)) {
232 printf("Unexpected fail for SSL_set_tlsext_status_type()\n");
236 if (SSL_get_tlsext_status_type(clientssl) != TLSEXT_STATUSTYPE_ocsp) {
237 printf("Unexpected result for SSL_get_tlsext_status_type()\n");
244 if (!SSL_CTX_set_tlsext_status_type(cctx, TLSEXT_STATUSTYPE_ocsp)) {
245 printf("Unexpected fail for SSL_CTX_set_tlsext_status_type()\n");
249 if (SSL_CTX_get_tlsext_status_type(cctx) != TLSEXT_STATUSTYPE_ocsp) {
250 printf("Unexpected result for SSL_CTX_get_tlsext_status_type()\n");
254 clientssl = SSL_new(cctx);
256 if (SSL_get_tlsext_status_type(clientssl) != TLSEXT_STATUSTYPE_ocsp) {
257 printf("Unexpected result for SSL_get_tlsext_status_type() (test 2)\n");
265 * Now actually do a handshake and check OCSP information is exchanged and
266 * the callbacks get called
269 SSL_CTX_set_tlsext_status_cb(cctx, ocsp_client_cb);
270 SSL_CTX_set_tlsext_status_arg(cctx, &cdummyarg);
271 SSL_CTX_set_tlsext_status_cb(sctx, ocsp_server_cb);
272 SSL_CTX_set_tlsext_status_arg(sctx, &cdummyarg);
274 if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
275 printf("Unable to create SSL objects\n");
279 if (!create_ssl_connection(serverssl, clientssl)) {
280 printf("Unable to create SSL connection\n");
284 if (!ocsp_client_called || !ocsp_server_called) {
285 printf("OCSP callbacks not called\n");
294 /* Try again but this time force the server side callback to fail */
295 ocsp_client_called = 0;
296 ocsp_server_called = 0;
299 if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
300 printf("Unable to create SSL objects\n");
304 /* This should fail because the callback will fail */
305 if (create_ssl_connection(serverssl, clientssl)) {
306 printf("Unexpected success creating the connection\n");
310 if (ocsp_client_called || ocsp_server_called) {
311 printf("OCSP callbacks successfully called unexpectedly\n");
321 * This time we'll get the client to send an OCSP_RESPID that it will
324 ocsp_client_called = 0;
325 ocsp_server_called = 0;
328 if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
329 printf("Unable to create SSL objects\n");
334 * We'll just use any old cert for this test - it doesn't have to be an OCSP
335 * specifc one. We'll use the server cert.
337 certbio = BIO_new_file(cert, "r");
338 if (certbio == NULL) {
339 printf("Can't load the certficate file\n");
342 id = OCSP_RESPID_new();
343 ids = sk_OCSP_RESPID_new_null();
344 ocspcert = PEM_read_bio_X509(certbio, NULL, NULL, NULL);
345 if (id == NULL || ids == NULL || ocspcert == NULL
346 || !OCSP_RESPID_set_by_key(id, ocspcert)
347 || !sk_OCSP_RESPID_push(ids, id)) {
348 printf("Unable to set OCSP_RESPIDs\n");
352 SSL_set_tlsext_status_ids(clientssl, ids);
353 /* Control has been transferred */
359 if (!create_ssl_connection(serverssl, clientssl)) {
360 printf("Unable to create SSL connection\n");
364 if (!ocsp_client_called || !ocsp_server_called) {
365 printf("OCSP callbacks not called\n");
376 sk_OCSP_RESPID_pop_free(ids, OCSP_RESPID_free);
377 OCSP_RESPID_free(id);
386 typedef struct ssl_session_test_fixture {
387 const char *test_case_name;
390 } SSL_SESSION_TEST_FIXTURE;
392 static int new_called = 0, remove_called = 0;
394 static SSL_SESSION_TEST_FIXTURE
395 ssl_session_set_up(const char *const test_case_name)
397 SSL_SESSION_TEST_FIXTURE fixture;
399 fixture.test_case_name = test_case_name;
400 fixture.use_ext_cache = 1;
401 fixture.use_int_cache = 1;
403 new_called = remove_called = 0;
408 static void ssl_session_tear_down(SSL_SESSION_TEST_FIXTURE fixture)
412 static int new_session_cb(SSL *ssl, SSL_SESSION *sess)
419 static void remove_session_cb(SSL_CTX *ctx, SSL_SESSION *sess)
424 static int execute_test_session(SSL_SESSION_TEST_FIXTURE fix)
426 SSL_CTX *sctx = NULL, *cctx = NULL;
427 SSL *serverssl1 = NULL, *clientssl1 = NULL;
428 SSL *serverssl2 = NULL, *clientssl2 = NULL;
429 #ifndef OPENSSL_NO_TLS1_1
430 SSL *serverssl3 = NULL, *clientssl3 = NULL;
432 SSL_SESSION *sess1 = NULL, *sess2 = NULL;
435 if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
436 &cctx, cert, privkey)) {
437 printf("Unable to create SSL_CTX pair\n");
441 #ifndef OPENSSL_NO_TLS1_2
442 /* Only allow TLS1.2 so we can force a connection failure later */
443 SSL_CTX_set_min_proto_version(cctx, TLS1_2_VERSION);
447 * TODO(TLS1.3): Test temporarily disabled for TLS1.3 until we've
448 * implemented session resumption.
450 SSL_CTX_set_max_proto_version(cctx, TLS1_2_VERSION);
452 /* Set up session cache */
453 if (fix.use_ext_cache) {
454 SSL_CTX_sess_set_new_cb(cctx, new_session_cb);
455 SSL_CTX_sess_set_remove_cb(cctx, remove_session_cb);
457 if (fix.use_int_cache) {
458 /* Also covers instance where both are set */
459 SSL_CTX_set_session_cache_mode(cctx, SSL_SESS_CACHE_CLIENT);
461 SSL_CTX_set_session_cache_mode(cctx,
462 SSL_SESS_CACHE_CLIENT
463 | SSL_SESS_CACHE_NO_INTERNAL_STORE);
466 if (!create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1, NULL,
468 printf("Unable to create SSL objects\n");
472 if (!create_ssl_connection(serverssl1, clientssl1)) {
473 printf("Unable to create SSL connection\n");
476 sess1 = SSL_get1_session(clientssl1);
478 printf("Unexpected NULL session\n");
482 if (fix.use_int_cache && SSL_CTX_add_session(cctx, sess1)) {
483 /* Should have failed because it should already be in the cache */
484 printf("Unexpected success adding session to cache\n");
488 if (fix.use_ext_cache && (new_called != 1 || remove_called != 0)) {
489 printf("Session not added to cache\n");
493 if (!create_ssl_objects(sctx, cctx, &serverssl2, &clientssl2, NULL, NULL)) {
494 printf("Unable to create second SSL objects\n");
498 if (!create_ssl_connection(serverssl2, clientssl2)) {
499 printf("Unable to create second SSL connection\n");
503 sess2 = SSL_get1_session(clientssl2);
505 printf("Unexpected NULL session from clientssl2\n");
509 if (fix.use_ext_cache && (new_called != 2 || remove_called != 0)) {
510 printf("Remove session callback unexpectedly called\n");
515 * This should clear sess2 from the cache because it is a "bad" session. See
516 * SSL_set_session() documentation.
518 if (!SSL_set_session(clientssl2, sess1)) {
519 printf("Unexpected failure setting session\n");
523 if (fix.use_ext_cache && (new_called != 2 || remove_called != 1)) {
524 printf("Failed to call callback to remove session\n");
529 if (SSL_get_session(clientssl2) != sess1) {
530 printf("Unexpected session found\n");
534 if (fix.use_int_cache) {
535 if (!SSL_CTX_add_session(cctx, sess2)) {
537 * Should have succeeded because it should not already be in the cache
539 printf("Unexpected failure adding session to cache\n");
543 if (!SSL_CTX_remove_session(cctx, sess2)) {
544 printf("Unexpected failure removing session from cache\n");
548 /* This is for the purposes of internal cache testing...ignore the
549 * counter for external cache
551 if (fix.use_ext_cache)
555 /* This shouldn't be in the cache so should fail */
556 if (SSL_CTX_remove_session(cctx, sess2)) {
557 printf("Unexpected success removing session from cache\n");
561 if (fix.use_ext_cache && (new_called != 2 || remove_called != 2)) {
562 printf("Failed to call callback to remove session #2\n");
566 #if !defined(OPENSSL_NO_TLS1_1) && !defined(OPENSSL_NO_TLS1_2)
567 /* Force a connection failure */
568 SSL_CTX_set_max_proto_version(sctx, TLS1_1_VERSION);
570 if (!create_ssl_objects(sctx, cctx, &serverssl3, &clientssl3, NULL, NULL)) {
571 printf("Unable to create third SSL objects\n");
575 if (!SSL_set_session(clientssl3, sess1)) {
576 printf("Unable to set session for third connection\n");
580 /* This should fail because of the mismatched protocol versions */
581 if (create_ssl_connection(serverssl3, clientssl3)) {
582 printf("Unable to create third SSL connection\n");
587 /* We should have automatically removed the session from the cache */
588 if (fix.use_ext_cache && (new_called != 2 || remove_called != 3)) {
589 printf("Failed to call callback to remove session #2\n");
593 if (fix.use_int_cache && !SSL_CTX_add_session(cctx, sess2)) {
595 * Should have succeeded because it should not already be in the cache
597 printf("Unexpected failure adding session to cache #2\n");
605 SSL_free(serverssl1);
606 SSL_free(clientssl1);
607 SSL_free(serverssl2);
608 SSL_free(clientssl2);
609 #ifndef OPENSSL_NO_TLS1_1
610 SSL_free(serverssl3);
611 SSL_free(clientssl3);
613 SSL_SESSION_free(sess1);
614 SSL_SESSION_free(sess2);
616 * Check if we need to remove any sessions up-refed for the external cache
619 SSL_SESSION_free(sess1);
621 SSL_SESSION_free(sess2);
628 static int test_session_with_only_int_cache(void)
630 SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
632 fixture.use_ext_cache = 0;
634 EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
637 static int test_session_with_only_ext_cache(void)
639 SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
641 fixture.use_int_cache = 0;
643 EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
646 static int test_session_with_both_cache(void)
648 SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
650 EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
657 #define TOTAL_SSL_SET_BIO_TESTS (3 * 3 * 3 * 3)
659 static void setupbio(BIO **res, BIO *bio1, BIO *bio2, int type)
674 static int test_ssl_set_bio(int idx)
676 SSL_CTX *ctx = SSL_CTX_new(TLS_method());
679 BIO *irbio = NULL, *iwbio = NULL, *nrbio = NULL, *nwbio = NULL;
681 int initrbio, initwbio, newrbio, newwbio;
685 printf("Failed to allocate SSL_CTX\n");
691 printf("Failed to allocate SSL object\n");
702 OPENSSL_assert(newwbio <= 2);
704 if (initrbio == USE_BIO_1 || initwbio == USE_BIO_1 || newrbio == USE_BIO_1
705 || newwbio == USE_BIO_1) {
706 bio1 = BIO_new(BIO_s_mem());
708 printf("Failed to allocate bio1\n");
713 if (initrbio == USE_BIO_2 || initwbio == USE_BIO_2 || newrbio == USE_BIO_2
714 || newwbio == USE_BIO_2) {
715 bio2 = BIO_new(BIO_s_mem());
717 printf("Failed to allocate bio2\n");
722 setupbio(&irbio, bio1, bio2, initrbio);
723 setupbio(&iwbio, bio1, bio2, initwbio);
726 * We want to maintain our own refs to these BIO, so do an up ref for each
727 * BIO that will have ownersip transferred in the SSL_set_bio() call
731 if (iwbio != NULL && iwbio != irbio)
734 SSL_set_bio(ssl, irbio, iwbio);
736 setupbio(&nrbio, bio1, bio2, newrbio);
737 setupbio(&nwbio, bio1, bio2, newwbio);
740 * We will (maybe) transfer ownership again so do more up refs.
741 * SSL_set_bio() has some really complicated ownership rules where BIOs have
744 if (nrbio != NULL && nrbio != irbio && (nwbio != iwbio || nrbio != nwbio))
746 if (nwbio != NULL && nwbio != nrbio && (nwbio != iwbio || (nwbio == iwbio && irbio == iwbio)))
749 SSL_set_bio(ssl, nrbio, nwbio);
758 * This test is checking that the ref counting for SSL_set_bio is correct.
759 * If we get here and we did too many frees then we will fail in the above
760 * functions. If we haven't done enough then this will only be detected in
761 * a crypto-mdebug build
768 typedef struct ssl_bio_test_fixture {
769 const char *test_case_name;
771 enum { NO_BIO_CHANGE, CHANGE_RBIO, CHANGE_WBIO } change_bio;
772 } SSL_BIO_TEST_FIXTURE;
774 static SSL_BIO_TEST_FIXTURE ssl_bio_set_up(const char *const test_case_name)
776 SSL_BIO_TEST_FIXTURE fixture;
778 fixture.test_case_name = test_case_name;
780 fixture.change_bio = NO_BIO_CHANGE;
785 static void ssl_bio_tear_down(SSL_BIO_TEST_FIXTURE fixture)
789 static int execute_test_ssl_bio(SSL_BIO_TEST_FIXTURE fix)
791 BIO *sslbio = NULL, *membio1 = NULL, *membio2 = NULL;
792 SSL_CTX *ctx = SSL_CTX_new(TLS_method());
797 printf("Failed to allocate SSL_CTX\n");
803 printf("Failed to allocate SSL object\n");
807 sslbio = BIO_new(BIO_f_ssl());
808 membio1 = BIO_new(BIO_s_mem());
810 if (sslbio == NULL || membio1 == NULL) {
811 printf("Malloc failure creating BIOs\n");
815 BIO_set_ssl(sslbio, ssl, BIO_CLOSE);
818 * If anything goes wrong here then we could leak memory, so this will
819 * be caught in a crypto-mdebug build
821 BIO_push(sslbio, membio1);
823 /* Verify chaning the rbio/wbio directly does not cause leaks */
824 if (fix.change_bio != NO_BIO_CHANGE) {
825 membio2 = BIO_new(BIO_s_mem());
826 if (membio2 == NULL) {
827 printf("Malloc failure creating membio2\n");
830 if (fix.change_bio == CHANGE_RBIO)
831 SSL_set0_rbio(ssl, membio2);
833 SSL_set0_wbio(ssl, membio2);
852 static int test_ssl_bio_pop_next_bio(void)
854 SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
856 EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
859 static int test_ssl_bio_pop_ssl_bio(void)
861 SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
865 EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
868 static int test_ssl_bio_change_rbio(void)
870 SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
872 fixture.change_bio = CHANGE_RBIO;
874 EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
877 static int test_ssl_bio_change_wbio(void)
879 SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
881 fixture.change_bio = CHANGE_WBIO;
883 EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
887 /* The list of sig algs */
889 /* The length of the list */
891 /* A sigalgs list in string format */
893 /* Whether setting the list should succeed */
895 /* Whether creating a connection with the list should succeed */
899 static const int validlist1[] = {NID_sha256, EVP_PKEY_RSA};
900 static const int validlist2[] = {NID_sha256, EVP_PKEY_RSA, NID_sha512, EVP_PKEY_EC};
901 static const int validlist3[] = {NID_sha512, EVP_PKEY_EC};
902 static const int invalidlist1[] = {NID_undef, EVP_PKEY_RSA};
903 static const int invalidlist2[] = {NID_sha256, NID_undef};
904 static const int invalidlist3[] = {NID_sha256, EVP_PKEY_RSA, NID_sha256};
905 static const int invalidlist4[] = {NID_sha256};
906 static const sigalgs_list testsigalgs[] = {
907 {validlist1, OSSL_NELEM(validlist1), NULL, 1, 1},
908 {validlist2, OSSL_NELEM(validlist2), NULL, 1, 1},
909 {validlist3, OSSL_NELEM(validlist3), NULL, 1, 0},
910 {NULL, 0, "RSA+SHA256", 1, 1},
911 {NULL, 0, "RSA+SHA256:ECDSA+SHA512", 1, 1},
912 {NULL, 0, "ECDSA+SHA512", 1, 0},
913 {invalidlist1, OSSL_NELEM(invalidlist1), NULL, 0, 0},
914 {invalidlist2, OSSL_NELEM(invalidlist2), NULL, 0, 0},
915 {invalidlist3, OSSL_NELEM(invalidlist3), NULL, 0, 0},
916 {invalidlist4, OSSL_NELEM(invalidlist4), NULL, 0, 0},
917 {NULL, 0, "RSA", 0, 0},
918 {NULL, 0, "SHA256", 0, 0},
919 {NULL, 0, "RSA+SHA256:SHA256", 0, 0},
920 {NULL, 0, "Invalid", 0, 0}};
922 static int test_set_sigalgs(int idx)
924 SSL_CTX *cctx = NULL, *sctx = NULL;
925 SSL *clientssl = NULL, *serverssl = NULL;
927 const sigalgs_list *curr;
930 /* Should never happen */
931 if ((size_t)idx >= OSSL_NELEM(testsigalgs) * 2)
934 testctx = ((size_t)idx < OSSL_NELEM(testsigalgs));
935 curr = testctx ? &testsigalgs[idx]
936 : &testsigalgs[idx - OSSL_NELEM(testsigalgs)];
938 if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
939 &cctx, cert, privkey)) {
940 printf("Unable to create SSL_CTX pair\n");
945 * TODO(TLS1.3): These APIs cannot set TLSv1.3 sig algs so we just test it
946 * for TLSv1.2 for now until we add a new API.
948 SSL_CTX_set_max_proto_version(cctx, TLS1_2_VERSION);
952 if (curr->list != NULL)
953 ret = SSL_CTX_set1_sigalgs(cctx, curr->list, curr->listlen);
955 ret = SSL_CTX_set1_sigalgs_list(cctx, curr->liststr);
959 printf("Unexpected failure setting sigalgs in SSL_CTX (%d)\n",
966 printf("Unexpected success setting sigalgs in SSL_CTX (%d)\n", idx);
971 if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
972 printf("Unable to create SSL objects\n");
979 if (curr->list != NULL)
980 ret = SSL_set1_sigalgs(clientssl, curr->list, curr->listlen);
982 ret = SSL_set1_sigalgs_list(clientssl, curr->liststr);
985 printf("Unexpected failure setting sigalgs in SSL (%d)\n", idx);
991 printf("Unexpected success setting sigalgs in SSL (%d)\n", idx);
996 if (curr->connsuccess != create_ssl_connection(serverssl, clientssl)) {
997 printf("Unexpected return value creating SSL connection (%d)\n", idx);
1004 SSL_free(serverssl);
1005 SSL_free(clientssl);
1012 int test_main(int argc, char *argv[])
1017 printf("Invalid argument count\n");
1024 ADD_TEST(test_large_message_tls);
1025 ADD_TEST(test_large_message_tls_read_ahead);
1026 #ifndef OPENSSL_NO_DTLS
1027 ADD_TEST(test_large_message_dtls);
1029 #ifndef OPENSSL_NO_OCSP
1030 ADD_TEST(test_tlsext_status_type);
1032 ADD_TEST(test_session_with_only_int_cache);
1033 ADD_TEST(test_session_with_only_ext_cache);
1034 ADD_TEST(test_session_with_both_cache);
1035 ADD_ALL_TESTS(test_ssl_set_bio, TOTAL_SSL_SET_BIO_TESTS);
1036 ADD_TEST(test_ssl_bio_pop_next_bio);
1037 ADD_TEST(test_ssl_bio_pop_ssl_bio);
1038 ADD_TEST(test_ssl_bio_change_rbio);
1039 ADD_TEST(test_ssl_bio_change_wbio);
1040 ADD_ALL_TESTS(test_set_sigalgs, OSSL_NELEM(testsigalgs) * 2);
1042 testresult = run_tests(argv[0]);
1044 bio_s_mempacket_test_free();