X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=test%2Frecordlentest.c;h=a73e4436845c9b39974b68273768bb891e73977f;hb=5f8257494c72ba4ea2a99d693916798517a610e1;hp=6bb1db40534ad8498681dfda7c394e455b005e4c;hpb=c1074ce096e98d3175292cbd2240ead7f1f67b32;p=openssl.git diff --git a/test/recordlentest.c b/test/recordlentest.c index 6bb1db4053..a73e443684 100644 --- a/test/recordlentest.c +++ b/test/recordlentest.c @@ -1,7 +1,7 @@ /* - * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2017-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 @@ -11,7 +11,6 @@ #include "ssltestlib.h" #include "testutil.h" -#include "test_main_custom.h" static char *cert = NULL; static char *privkey = NULL; @@ -78,7 +77,7 @@ static int fail_due_to_record_overflow(int enc) return 0; } -static int test_record_plain_overflow(int idx) +static int test_record_overflow(int idx) { SSL_CTX *cctx = NULL, *sctx = NULL; SSL *clientssl = NULL, *serverssl = NULL; @@ -103,25 +102,26 @@ static int test_record_plain_overflow(int idx) ERR_clear_error(); - if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx, - &cctx, cert, privkey)) { - printf("Unable to create SSL_CTX pair\n"); + if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), + TLS1_VERSION, 0, + &sctx, &cctx, cert, privkey))) goto end; - } if (idx == TEST_ENCRYPTED_OVERFLOW_TLS1_2_OK || idx == TEST_ENCRYPTED_OVERFLOW_TLS1_2_NOT_OK) { - len = SSL3_RT_MAX_ENCRYPTED_LENGTH - SSL3_RT_MAX_COMPRESSED_OVERHEAD; + len = SSL3_RT_MAX_ENCRYPTED_LENGTH; +#ifndef OPENSSL_NO_COMP + len -= SSL3_RT_MAX_COMPRESSED_OVERHEAD; +#endif SSL_CTX_set_max_proto_version(sctx, TLS1_2_VERSION); } else if (idx == TEST_ENCRYPTED_OVERFLOW_TLS1_3_OK || idx == TEST_ENCRYPTED_OVERFLOW_TLS1_3_NOT_OK) { len = SSL3_RT_MAX_TLS13_ENCRYPTED_LENGTH; } - if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) { - printf("Unable to create SSL objects\n"); + if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl, + NULL, NULL))) goto end; - } serverbio = SSL_get_rbio(serverssl); @@ -132,29 +132,23 @@ static int test_record_plain_overflow(int idx) if (idx == TEST_PLAINTEXT_OVERFLOW_NOT_OK) len++; - if (!write_record(serverbio, len, SSL3_RT_HANDSHAKE, TLS1_VERSION)) { - printf("Unable to write plaintext record\n"); + if (!TEST_true(write_record(serverbio, len, + SSL3_RT_HANDSHAKE, TLS1_VERSION))) goto end; - } - if (SSL_accept(serverssl) > 0) { - printf("Unexpected success reading plaintext record\n"); + if (!TEST_int_le(SSL_accept(serverssl), 0)) goto end; - } overf_expected = (idx == TEST_PLAINTEXT_OVERFLOW_OK) ? 0 : 1; - if (fail_due_to_record_overflow(0) != overf_expected) { - printf("Unexpected error value received\n"); + if (!TEST_int_eq(fail_due_to_record_overflow(0), overf_expected)) goto end; - } goto success; } - if (!create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)) { - printf("Unable to create SSL connection\n"); + if (!TEST_true(create_ssl_connection(serverssl, clientssl, + SSL_ERROR_NONE))) goto end; - } if (idx == TEST_ENCRYPTED_OVERFLOW_TLS1_2_NOT_OK || idx == TEST_ENCRYPTED_OVERFLOW_TLS1_3_NOT_OK) { @@ -164,58 +158,40 @@ static int test_record_plain_overflow(int idx) overf_expected = 0; } - if (idx == TEST_ENCRYPTED_OVERFLOW_TLS1_3_OK - || idx == TEST_ENCRYPTED_OVERFLOW_TLS1_3_NOT_OK) - recversion = TLS1_VERSION; - else - recversion = TLS1_2_VERSION; + recversion = TLS1_2_VERSION; - if (!write_record(serverbio, len, SSL3_RT_APPLICATION_DATA, recversion)) { - printf("Unable to write encryprted record\n"); + if (!TEST_true(write_record(serverbio, len, SSL3_RT_APPLICATION_DATA, + recversion))) goto end; - } - if (SSL_read_ex(serverssl, &buf, sizeof(buf), &written)) { - printf("Unexpected success reading encrypted record\n"); + if (!TEST_false(SSL_read_ex(serverssl, &buf, sizeof(buf), &written))) goto end; - } - if (fail_due_to_record_overflow(1) != overf_expected) { - printf("Unexpected error value received\n"); + if (!TEST_int_eq(fail_due_to_record_overflow(1), overf_expected)) goto end; - } success: testresult = 1; end: - if(!testresult) - ERR_print_errors_fp(stdout); SSL_free(serverssl); SSL_free(clientssl); SSL_CTX_free(sctx); SSL_CTX_free(cctx); - return testresult; } -int test_main(int argc, char *argv[]) +int setup_tests(void) { - int testresult = 1; - - if (argc != 3) { - printf("Invalid argument count\n"); - return 1; - } - - cert = argv[1]; - privkey = argv[2]; - - ADD_ALL_TESTS(test_record_plain_overflow, TOTAL_RECORD_OVERFLOW_TESTS); + if (!TEST_ptr(cert = test_get_argument(0)) + || !TEST_ptr(privkey = test_get_argument(1))) + return 0; - testresult = run_tests(argv[0]); + ADD_ALL_TESTS(test_record_overflow, TOTAL_RECORD_OVERFLOW_TESTS); + return 1; +} +void cleanup_tests(void) +{ bio_s_mempacket_test_free(); - - return testresult; }