X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=test%2Fclienthellotest.c;h=0afad6dbd609db9fe0d93eda4bddf631a99c8af0;hb=fd3a904636aa45401c40e8b86ebacd5135fea2f1;hp=2de85128e33cbfe36c8738bdfbaedb9437b45b7a;hpb=a9c6d221055c3a85edb23b1364cd60baafed4b9f;p=openssl.git diff --git a/test/clienthellotest.c b/test/clienthellotest.c index 2de85128e3..0afad6dbd6 100644 --- a/test/clienthellotest.c +++ b/test/clienthellotest.c @@ -1,7 +1,7 @@ /* - * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -40,14 +40,15 @@ */ #define TEST_ADD_PADDING_AND_PSK 3 -#define F5_WORKAROUND_MIN_MSG_LEN 0xff +#define F5_WORKAROUND_MIN_MSG_LEN 0x7f #define F5_WORKAROUND_MAX_MSG_LEN 0x200 static const char *sessionfile = NULL; /* Dummy ALPN protocols used to pad out the size of the ClientHello */ static const char alpn_prots[] = "0123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789"; + "0123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789"; static int test_client_hello(int currtest) { @@ -70,6 +71,10 @@ static int test_client_hello(int currtest) return 1; #endif + memset(&pkt, 0, sizeof(pkt)); + memset(&pkt2, 0, sizeof(pkt2)); + memset(&pkt3, 0, sizeof(pkt3)); + /* * For each test set up an SSL_CTX and SSL and see what ClientHello gets * produced when we try to connect @@ -77,31 +82,56 @@ static int test_client_hello(int currtest) ctx = SSL_CTX_new(TLS_method()); if (!TEST_ptr(ctx)) goto end; + if (!TEST_true(SSL_CTX_set_max_proto_version(ctx, 0))) + goto end; switch(currtest) { case TEST_SET_SESSION_TICK_DATA_VER_NEG: +#if !defined(OPENSSL_NO_TLS1_3) && defined(OPENSSL_NO_TLS1_2) + /* TLSv1.3 is enabled and TLSv1.2 is disabled so can't do this test */ + return 1; +#else /* Testing for session tickets <= TLS1.2; not relevant for 1.3 */ if (!TEST_true(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION))) goto end; +#endif break; case TEST_ADD_PADDING_AND_PSK: + /* + * In this case we're doing TLSv1.3 and we're sending a PSK so the + * ClientHello is already going to be quite long. To avoid getting one + * that is too long for this test we use a restricted ciphersuite list + */ + if (!TEST_false(SSL_CTX_set_cipher_list(ctx, ""))) + goto end; + ERR_clear_error(); + /* Fall through */ case TEST_ADD_PADDING: case TEST_PADDING_NOT_NEEDED: SSL_CTX_set_options(ctx, SSL_OP_TLSEXT_PADDING); + /* Make sure we get a consistent size across TLS versions */ + SSL_CTX_clear_options(ctx, SSL_OP_ENABLE_MIDDLEBOX_COMPAT); /* - * Add lots of ciphersuites so that the ClientHello is at least + * Add some dummy ALPN protocols so that the ClientHello is at least * F5_WORKAROUND_MIN_MSG_LEN bytes long - meaning padding will be - * needed. Also add some dummy ALPN protocols in case we still don't - * have enough. + * needed. */ - if (currtest == TEST_ADD_PADDING - && (!TEST_true(SSL_CTX_set_cipher_list(ctx, "ALL")) - || !TEST_false(SSL_CTX_set_alpn_protos(ctx, - (unsigned char *)alpn_prots, - sizeof(alpn_prots) - 1)))) + if (currtest == TEST_ADD_PADDING) { + if (!TEST_false(SSL_CTX_set_alpn_protos(ctx, + (unsigned char *)alpn_prots, + sizeof(alpn_prots) - 1))) + goto end; + /* + * Otherwise we need to make sure we have a small enough message to + * not need padding. + */ + } else if (!TEST_true(SSL_CTX_set_cipher_list(ctx, + "AES128-SHA")) + || !TEST_true(SSL_CTX_set_ciphersuites(ctx, + "TLS_AES_128_GCM_SHA256"))) { goto end; - + } break; default: @@ -127,7 +157,7 @@ static int test_client_hello(int currtest) * We reset the creation time so that we don't discard the session as * too old. */ - if (!TEST_true(SSL_SESSION_set_time(sess, time(NULL))) + if (!TEST_true(SSL_SESSION_set_time(sess, (long)time(NULL))) || !TEST_true(SSL_set_session(con, sess))) goto end; } @@ -215,14 +245,13 @@ end: return testresult; } -int test_main(int argc, char *argv[]) -{ - if (argc != 2) - return EXIT_FAILURE; +OPT_TEST_DECLARE_USAGE("sessionfile\n") - sessionfile = argv[1]; +int setup_tests(void) +{ + if (!TEST_ptr(sessionfile = test_get_argument(0))) + return 0; ADD_ALL_TESTS(test_client_hello, TOTAL_NUM_TESTS); - - return run_tests(argv[0]); + return 1; }