summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2017-04-08 16:14:06 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2017-04-08 17:17:44 +0200
commitf37564c76f883edf2e2e79f8e85d414a57a24380 (patch)
treef510a7d353361aaada55f731cd9245509830a988
parent35b7b13cb8895f1d684b97d7a1846d448a9a59ee (diff)
downloadgnutls-f37564c76f883edf2e2e79f8e85d414a57a24380.tar.gz
tests: test gnutls_dh_get_pubkey in anonymous auth
Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
-rw-r--r--tests/anonself.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/anonself.c b/tests/anonself.c
index e3e0008e58..28d2b0014f 100644
--- a/tests/anonself.c
+++ b/tests/anonself.c
@@ -68,6 +68,7 @@ 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. */
@@ -109,13 +110,30 @@ static void client(int sd)
ret = gnutls_dh_get_prime_bits(session);
if (ret < 512) {
- fail("server: too small prime size: %d\n", ret);
+ fail("client: 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);
+ 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);
if (debug)
success("client: TLS version is: %s\n",
@@ -188,6 +206,7 @@ static gnutls_session_t initialize_tls_session(void)
"NONE:+VERS-TLS-ALL:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-DH",
NULL);
+ gnutls_handshake_set_timeout(session, 20 * 1000);
gnutls_credentials_set(session, GNUTLS_CRD_ANON, anoncred);
gnutls_dh_set_prime_bits(session, DH_BITS);
@@ -219,6 +238,8 @@ 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
*/
@@ -266,6 +287,21 @@ static void server(int sd)
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); */