AArch64 assembly pack: authenticate return addresses.
[openssl.git] / test / recordlentest.c
index b9d868f6aef7cb85b09c4b74a4e49c3a9b538c3d..457335d308b84817a12dace59d6060f0621f78db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
  * this file except in compliance with the License.  You can obtain a copy
@@ -11,7 +11,6 @@
 
 #include "ssltestlib.h"
 #include "testutil.h"
-#include "test_main_custom.h"
 
 static char *cert = NULL;
 static char *privkey = NULL;
@@ -103,11 +102,10 @@ static int test_record_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, TLS_MAX_VERSION,
+                                       &sctx, &cctx, cert, privkey)))
         goto end;
-    }
 
     if (idx == TEST_ENCRYPTED_OVERFLOW_TLS1_2_OK
             || idx == TEST_ENCRYPTED_OVERFLOW_TLS1_2_NOT_OK) {
@@ -121,10 +119,9 @@ static int test_record_overflow(int idx)
         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);
 
@@ -135,29 +132,23 @@ static int test_record_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) {
@@ -167,58 +158,40 @@ static int test_record_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 encrypted 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];
+    if (!TEST_ptr(cert = test_get_argument(0))
+            || !TEST_ptr(privkey = test_get_argument(1)))
+        return 0;
 
     ADD_ALL_TESTS(test_record_overflow, TOTAL_RECORD_OVERFLOW_TESTS);
+    return 1;
+}
 
-    testresult = run_tests(argv[0]);
-
+void cleanup_tests(void)
+{
     bio_s_mempacket_test_free();
-
-    return testresult;
 }