summaryrefslogtreecommitdiff
path: root/test/dtls_mtu_test.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2017-04-26 12:20:44 -0400
committerRich Salz <rsalz@openssl.org>2017-04-26 12:20:44 -0400
commit8ed9a26616a7101ea698c189fbbb663186676075 (patch)
tree3557d101c117d2060345a8197bfdf342efde3314 /test/dtls_mtu_test.c
parentaa24cd1bfbf4fb51bc51d8b3b5c68563616a28ab (diff)
downloadopenssl-new-8ed9a26616a7101ea698c189fbbb663186676075.tar.gz
Convert dtls_mtu_test, dtlsv1listentest
Also converted most of ssltestlib but left the packet_dump output as-is (for now). Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3257)
Diffstat (limited to 'test/dtls_mtu_test.c')
-rw-r--r--test/dtls_mtu_test.c133
1 files changed, 69 insertions, 64 deletions
diff --git a/test/dtls_mtu_test.c b/test/dtls_mtu_test.c
index 24d4ccc552..50f952b2ce 100644
--- a/test/dtls_mtu_test.c
+++ b/test/dtls_mtu_test.c
@@ -15,6 +15,7 @@
#include <openssl/err.h>
#include "ssltestlib.h"
+#include "testutil.h"
/* for SSL_READ_ETM() */
#include "../ssl/ssl_locl.h"
@@ -57,21 +58,19 @@ static int mtu_test(SSL_CTX *ctx, const char *cs, int no_etm)
memset(buf, 0x5a, sizeof(buf));
- if (create_ssl_objects(ctx, ctx, &srvr_ssl, &clnt_ssl, NULL, NULL) != 1)
- goto out;
+ if (!TEST_true(create_ssl_objects(ctx, ctx, &srvr_ssl, &clnt_ssl,
+ NULL, NULL)))
+ goto end;
if (no_etm)
SSL_set_options(srvr_ssl, SSL_OP_NO_ENCRYPT_THEN_MAC);
- if (SSL_set_cipher_list(srvr_ssl, cs) != 1 ||
- SSL_set_cipher_list(clnt_ssl, cs) != 1) {
- ERR_print_errors_fp(stdout);
- goto out;
- }
- sc_bio = SSL_get_rbio(srvr_ssl);
-
- if (create_ssl_connection(clnt_ssl, srvr_ssl, SSL_ERROR_NONE) != 1)
- goto out;
+ if (!TEST_true(SSL_set_cipher_list(srvr_ssl, cs))
+ || !TEST_true(SSL_set_cipher_list(clnt_ssl, cs))
+ || !TEST_ptr(sc_bio = SSL_get_rbio(srvr_ssl))
+ || !TEST_true(create_ssl_connection(clnt_ssl, srvr_ssl,
+ SSL_ERROR_NONE)))
+ goto end;
if (debug)
printf("Channel established\n");
@@ -82,28 +81,27 @@ static int mtu_test(SSL_CTX *ctx, const char *cs, int no_etm)
SSL_set_mtu(clnt_ssl, 500 + i);
mtus[i] = DTLS_get_data_mtu(clnt_ssl);
if (debug)
- printf("%s%s payload MTU for record mtu %d = %"OSSLzu"\n",
- cs, no_etm ? "-noEtM":"", 500 + i, mtus[i]);
- if (mtus[i] == 0) {
- fprintf(stderr,
- "payload MTU failed with record MTU %d for %s\n",
- 500 + i, cs);
- goto out;
+ TEST_info("%s%s MTU for record mtu %d = %lu",
+ cs, no_etm ? "-noEtM" : "",
+ 500 + i, (unsigned long)mtus[i]);
+ if (!TEST_size_t_ne(mtus[i], 0)) {
+ TEST_info("Cipher %s MTU %d", cs, 500 + i);
+ goto end;
}
}
/* Now get out of the way */
SSL_set_mtu(clnt_ssl, 1000);
- /* Now for all values in the range of payload MTUs, send
- * a payload of that size and see what actual record size
- * we end up with. */
+ /*
+ * Now for all values in the range of payload MTUs, send a payload of
+ * that size and see what actual record size we end up with.
+ */
for (s = mtus[0]; s <= mtus[29]; s++) {
size_t reclen;
- if (SSL_write(clnt_ssl, buf, s) != (int)s) {
- ERR_print_errors_fp(stdout);
- goto out;
- }
+
+ if (!TEST_int_eq(SSL_write(clnt_ssl, buf, s), (int)s))
+ goto end;
reclen = BIO_read(sc_bio, buf, sizeof(buf));
if (debug)
printf("record %"OSSLzu" for payload %"OSSLzu"\n", reclen, s);
@@ -111,53 +109,58 @@ static int mtu_test(SSL_CTX *ctx, const char *cs, int no_etm)
for (i = 0; i < 30; i++) {
/* DTLS_get_data_mtu() with record MTU 500+i returned mtus[i] ... */
- if (s <= mtus[i] && reclen > (size_t)(500 + i)) {
- /* We sent a packet smaller than or equal to mtus[j] and
- * that made a record *larger* than the record MTU 500+j! */
- fprintf(stderr,
- "%s: Payload MTU %"OSSLzu" reported for record MTU %d\n"
- "but sending a payload of %"OSSLzu" made a record of %"OSSLzu"(too large)\n",
- cs, mtus[i], 500 + i, s, reclen);
- goto out;
+ if (!TEST_false(s <= mtus[i] && reclen > (size_t)(500 + i))) {
+ /*
+ * We sent a packet smaller than or equal to mtus[j] and
+ * that made a record *larger* than the record MTU 500+j!
+ */
+ TEST_error("%s: s=%lu, mtus[i]=%lu, reclen=%lu, i=%d",
+ cs, (unsigned long)s, (unsigned long)mtus[i],
+ (unsigned long)reclen, 500 + i);
+ goto end;
}
- if (s > mtus[i] && reclen <= (size_t)(500 + i)) {
- /* We sent a *larger* packet than mtus[i] and that *still*
+ if (!TEST_false(s > mtus[i] && reclen <= (size_t)(500 + i))) {
+ /*
+ * We sent a *larger* packet than mtus[i] and that *still*
* fits within the record MTU 500+i, so DTLS_get_data_mtu()
- * was overly pessimistic. */
- fprintf(stderr,
- "%s: Payload MTU %"OSSLzu" reported for record MTU %d\n"
- "but sending a payload of %"OSSLzu" made a record of %"OSSLzu" (too small)\n",
- cs, mtus[i], 500 + i, s, reclen);
- goto out;
+ * was overly pessimistic.
+ */
+ TEST_error("%s: s=%lu, mtus[i]=%lu, reclen=%lu, i=%d",
+ cs, (unsigned long)s, (unsigned long)mtus[i],
+ (unsigned long)reclen, 500 + i);
+ goto end;
}
}
}
rv = 1;
if (SSL_READ_ETM(clnt_ssl))
rv = 2;
- out:
+ end:
SSL_free(clnt_ssl);
SSL_free(srvr_ssl);
return rv;
}
-int main(void)
+static int run_mtu_tests(void)
{
- SSL_CTX *ctx = SSL_CTX_new(DTLS_method());
+ SSL_CTX *ctx = NULL;
STACK_OF(SSL_CIPHER) *ciphers;
- int i, rv = 0;
+ int i, ret = 0;
+
+ if (!TEST_ptr(ctx = SSL_CTX_new(DTLS_method())))
+ goto end;
SSL_CTX_set_psk_server_callback(ctx, srvr_psk_callback);
SSL_CTX_set_psk_client_callback(ctx, clnt_psk_callback);
SSL_CTX_set_security_level(ctx, 0);
- /* We only care about iterating over each enc/mac; we don't
- * want to repeat the test for each auth/kx variant.
- * So keep life simple and only do (non-DH) PSK. */
- if (!SSL_CTX_set_cipher_list(ctx, "PSK")) {
- fprintf(stderr, "Failed to set PSK cipher list\n");
- goto out;
- }
+ /*
+ * We only care about iterating over each enc/mac; we don't want to
+ * repeat the test for each auth/kx variant. So keep life simple and
+ * only do (non-DH) PSK.
+ */
+ if (!TEST_true(SSL_CTX_set_cipher_list(ctx, "PSK")))
+ goto end;
ciphers = SSL_CTX_get_ciphers(ctx);
for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
@@ -165,26 +168,28 @@ int main(void)
const char *cipher_name = SSL_CIPHER_get_name(cipher);
/* As noted above, only one test for each enc/mac variant. */
- if (strncmp(cipher_name, "PSK-", 4))
+ if (strncmp(cipher_name, "PSK-", 4) != 0)
continue;
- rv = mtu_test(ctx, cipher_name, 0);
- if (!rv)
+ if (!TEST_int_gt(ret = mtu_test(ctx, cipher_name, 0), 0))
break;
-
- printf("DTLS MTU test OK for %s\n", cipher_name);
- if (rv == 1)
+ TEST_info("%s OK", cipher_name);
+ if (ret == 1)
continue;
/* mtu_test() returns 2 if it used Encrypt-then-MAC */
- rv = mtu_test(ctx, cipher_name, 1);
- if (!rv)
+ if (!TEST_int_gt(ret = mtu_test(ctx, cipher_name, 1), 0))
break;
-
- printf("DTLS MTU test OK for %s without Encrypt-then-MAC\n", cipher_name);
+ TEST_info("%s without EtM OK", cipher_name);
}
- out:
+
+ end:
SSL_CTX_free(ctx);
+ bio_s_mempacket_test_free();
+ return ret;
+}
- return !rv;
+void register_tests()
+{
+ ADD_TEST(run_mtu_tests);
}