From 947b5001b9fd8c99350cc9a0586721cf7e7d9370 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 8 Apr 2017 16:33:09 +0200 Subject: tests: combined and enhanced DH params tests Signed-off-by: Nikos Mavrogiannopoulos --- tests/anonself.c | 58 ++----------------------------------------------------- tests/utils-adv.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/utils.h | 2 ++ 3 files changed, 58 insertions(+), 56 deletions(-) diff --git a/tests/anonself.c b/tests/anonself.c index c366ec1e70..0ad4136e98 100644 --- a/tests/anonself.c +++ b/tests/anonself.c @@ -68,7 +68,6 @@ static void client(int sd) int ret, ii; gnutls_session_t session; char buffer[MAX_BUF + 1]; - gnutls_datum_t dh_pubkey; gnutls_anon_client_credentials_t anoncred; /* Need to enable anonymous KX specifically. */ @@ -108,32 +107,7 @@ static void client(int sd) success("client: Handshake was completed\n"); } - ret = gnutls_dh_get_prime_bits(session); - if (ret < 512) { - fail("client: too small prime size: %d\n", ret); - } - - ret = gnutls_dh_get_secret_bits(session); - if (ret < 256) { - fail("client: too small secret key size: %d\n", ret); - } - - ret = gnutls_dh_get_pubkey(session, &dh_pubkey); - if (ret < 0) { - fail("error retrieving the public key\n"); - } - - if (dh_pubkey.size == 0) { - fail("retrieved pubkey is empty!\n"); - } - - printf("pubkey: \n"); - for (ii=0;ii<(int)dh_pubkey.size;ii++) { - printf("%.2x", (unsigned)dh_pubkey.data[ii]); - } - printf("\n"); - - gnutls_free(dh_pubkey.data); + print_dh_params_info(session); if (debug) success("client: TLS version is: %s\n", @@ -233,8 +207,6 @@ int optval = 1; static void server(int sd) { gnutls_packet_t packet; - gnutls_datum_t dh_pubkey; - int ii; /* this must be called once in the program */ @@ -272,33 +244,7 @@ static void server(int sd) gnutls_protocol_get_name (gnutls_protocol_get_version(session))); - ret = gnutls_dh_get_prime_bits(session); - if (ret < 512) { - fail("server: too small prime size: %d\n", ret); - } - - ret = gnutls_dh_get_secret_bits(session); - if (ret < 256) { - fail("server: too small secret key size: %d\n", ret); - } - - ret = gnutls_dh_get_pubkey(session, &dh_pubkey); - if (ret < 0) { - fail("error retrieving the public key\n"); - } - - if (dh_pubkey.size == 0) { - fail("retrieved pubkey is empty!\n"); - } - - printf("pubkey: \n"); - for (ii=0;ii<(int)dh_pubkey.size;ii++) { - printf("%.2x", (unsigned)dh_pubkey.data[ii]); - } - printf("\n"); - - /* see the Getting peer's information example */ - /* print_info(session); */ + print_dh_params_info(session); for (;;) { ret = gnutls_record_recv_packet(session, &packet); diff --git a/tests/utils-adv.c b/tests/utils-adv.c index 6507a9314d..0947cd0160 100644 --- a/tests/utils-adv.c +++ b/tests/utils-adv.c @@ -334,3 +334,57 @@ test_cli_serv_vf(gnutls_certificate_credentials_t server_cred, { return _test_cli_serv(server_cred, client_cred, prio, prio, host, NULL, NULL, NULL, 1, 0, 0, 0); } + +void print_dh_params_info(gnutls_session_t session) +{ + unsigned i; + int ret; + gnutls_datum_t pubkey, gen, prime; + + ret = gnutls_dh_get_prime_bits(session); + if (ret < 512) { + fail("client: too small prime size: %d\n", ret); + } + + ret = gnutls_dh_get_secret_bits(session); + if (ret < 256) { + fail("client: too small secret key size: %d\n", ret); + } + + ret = gnutls_dh_get_pubkey(session, &pubkey); + if (ret < 0) { + fail("error retrieving the public key\n"); + } + + if (pubkey.size == 0) { + fail("retrieved pubkey is empty!\n"); + } + + printf("pubkey: \n"); + for (i=0;i