summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-03-15 23:42:52 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-03-15 23:42:52 +0100
commita32853d3da525ceb4211e869b6dfa4e5a469e7c8 (patch)
tree5354dae5cf51b3774c1a71ff73b7cd8968e5643f /tests
parenta7e2d0836f52d4fb641aae20c91def82973653a7 (diff)
downloadgnutls-a32853d3da525ceb4211e869b6dfa4e5a469e7c8.tar.gz
Test openpgp authentication with DSA-2048 bit keys as well.
Diffstat (limited to 'tests')
-rw-r--r--tests/openpgpself.c381
1 files changed, 257 insertions, 124 deletions
diff --git a/tests/openpgpself.c b/tests/openpgpself.c
index e3f2c9ffd2..bbaf61d28e 100644
--- a/tests/openpgpself.c
+++ b/tests/openpgpself.c
@@ -100,12 +100,14 @@ static unsigned char key_txt[] =
"AAULBwoDBAMVAwIDFgIBAheAAAoJEDUUXOqn2Tw/llgAnjBPQdWxIqBCQGlcI2K/\n"
"gLkZR1ARAJ9kaAeJYERc0bV/vlm0ot7UDdr+bQ==\n"
"=4M0W\n" "-----END PGP PRIVATE KEY BLOCK-----\n";
+
const gnutls_datum_t key = { key_txt, sizeof (key_txt) };
+
static void
client (void)
{
- int ret, sd, ii;
+ int ret, sd, ii, j;
gnutls_session_t session;
char buffer[MAX_BUF + 1];
gnutls_certificate_credentials_t xcred;
@@ -114,7 +116,7 @@ client (void)
gnutls_global_set_log_function (tls_log_func);
if (debug)
- gnutls_global_set_log_level (2);
+ gnutls_global_set_log_level (5);
gnutls_certificate_allocate_credentials (&xcred);
@@ -124,87 +126,95 @@ client (void)
success ("Setting key files...\n");
ret = gnutls_certificate_set_openpgp_key_mem (xcred, &cert, &key,
- GNUTLS_OPENPGP_FMT_BASE64);
+ GNUTLS_OPENPGP_FMT_BASE64);
if (ret < 0)
{
fail ("Could not set key files...\n");
+ return;
}
- /* Initialize TLS session
- */
- gnutls_init (&session, GNUTLS_CLIENT);
+ for (j = 0; j < 2; j++)
+ {
- /* Use default priorities */
- gnutls_set_default_priority (session);
- /* put the x509 credentials to the current session
- */
- gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
+ /* Initialize TLS session
+ */
+ gnutls_init (&session, GNUTLS_CLIENT);
- /* connect to the peer
- */
- if (debug)
- success ("Connecting...\n");
- sd = tcp_connect ();
+ /* Use default priorities */
+ gnutls_priority_set_direct (session, "NORMAL", NULL);
- gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
+ /* put the x509 credentials to the current session
+ */
+ gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
- /* Perform the TLS handshake
- */
- ret = gnutls_handshake (session);
+ /* connect to the peer
+ */
+ if (debug)
+ success ("Connecting...\n");
+ sd = tcp_connect ();
- if (ret < 0)
- {
- fail ("client: Handshake failed\n");
- gnutls_perror (ret);
- goto end;
- }
- else if (debug)
- {
- success ("client: Handshake was completed\n");
- }
+ gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
- if (debug)
- success ("client: TLS version is: %s\n",
- gnutls_protocol_get_name (gnutls_protocol_get_version
- (session)));
+ /* Perform the TLS handshake
+ */
+ ret = gnutls_handshake (session);
- /* see the Getting peer's information example */
- if (debug)
- print_info (session);
+ if (ret < 0)
+ {
+ fail ("client: Handshake %d failed\n", j);
+ gnutls_perror (ret);
+ goto end;
+ }
+ else if (debug)
+ {
+ success ("client: Handshake %d was completed\n", j);
+ }
- gnutls_record_send (session, MSG, strlen (MSG));
+ if (debug)
+ success ("client: TLS version is: %s\n",
+ gnutls_protocol_get_name (gnutls_protocol_get_version
+ (session)));
- ret = gnutls_record_recv (session, buffer, MAX_BUF);
- if (ret == 0)
- {
+ /* see the Getting peer's information example */
if (debug)
- success ("client: Peer has closed the TLS connection\n");
- goto end;
- }
- else if (ret < 0)
- {
- fail ("client: Error: %s\n", gnutls_strerror (ret));
- goto end;
- }
+ print_info (session);
- if (debug)
- {
- printf ("- Received %d bytes: ", ret);
- for (ii = 0; ii < ret; ii++)
+ gnutls_record_send (session, MSG, strlen (MSG));
+
+ ret = gnutls_record_recv (session, buffer, MAX_BUF);
+ if (ret == 0)
{
- fputc (buffer[ii], stdout);
+ if (debug)
+ success ("client: Peer has closed the TLS connection\n");
+ goto end;
+ }
+ else if (ret < 0)
+ {
+ fail ("client: Error: %s\n", gnutls_strerror (ret));
+ goto end;
+ }
+
+ if (debug)
+ {
+ printf ("- Received %d bytes: ", ret);
+ for (ii = 0; ii < ret; ii++)
+ {
+ fputc (buffer[ii], stdout);
+ }
+ fputs ("\n", stdout);
}
- fputs ("\n", stdout);
- }
- gnutls_bye (session, GNUTLS_SHUT_RDWR);
+ gnutls_bye (session, GNUTLS_SHUT_RDWR);
-end:
- tcp_close (sd);
+ tcp_close (sd);
- gnutls_deinit (session);
+ gnutls_deinit (session);
+
+ }
+
+end:
gnutls_certificate_free_credentials (xcred);
@@ -232,7 +242,7 @@ initialize_tls_session (void)
/* avoid calling all the priority functions, since the defaults
* are adequate.
*/
- gnutls_set_default_priority (session);
+ gnutls_priority_set_direct (session, "NORMAL", NULL);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, pgp_cred);
@@ -345,6 +355,111 @@ static unsigned char server_key_txt[] =
"=mZnW\n" "-----END PGP PRIVATE KEY BLOCK-----\n";
const gnutls_datum_t server_key = { server_key_txt, sizeof (server_key_txt) };
+static unsigned char cert2048_txt[] =
+"-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
+"Version: GnuPG v1.4.10 (GNU/Linux)\n"
+"Comment: Test key for GnuTLS\n"
+"\n"
+"mQMuBE1/6bQRCAD8TQlwbkkX3bLJvemSA/BqT/z0OrJsuXKFQqK5Pp0BRTwC4iCg\n"
+"wnUFrr012up66YTzaA0aQpkf48gqxZ1XTGZtZ13+aAArChqKiffR7OS+BnROd+D3\n"
+"NkPF0tWDAqRFsybIej1GcdSyPw+neExSfoeYzNpUW9oX2iLh5QZC/x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
+"66In56DCQJS+K19AR+fRYPro8+MavAQlirEK1uOjidoKykVziqO7B6Z4DAaZZBDP\n"
+"h8HwYANauwlfapGuZ5/rLPNCFi5VEJjX/9t0ECCgPOOEK8qWA5ljw35K6W/3CVX7\n"
+"hKNflAx1BGBr0GfrJo/EsneeBEsKPk/hge5uPr+wkDqdXq/7qxCSHhT3OQpiOW65\n"
+"dyBX/44XAVQaWtf6DJc84nWDYsCgscEZzGAUyBY8Fw9S7We5OFLNcYWIwQQYEQgA\n"
+"CQUCTX/ptAIbIgBqCRB7/ynKCzvfuF8gBBkRCAAGBQJNf+m0AAoJEEPv0WrPxcc9\n"
+"aJwA/0zWQ0RfRhlC1nbf7ISEOF36WQjslGKXjf6z6rSNgphoAP4119FDX9jaW0B8\n"
+"HL9p+XRZTOTSo5GMLUTH5zo+zpTbB2cxAP9moc/i1z2D8AXTnUk7YfSm+o7rFThu\n"
+"2Cx0oO7h1g0MjQD6A/6e68DhK9altb/xqtHeG0jbLmvFRtkC0zu7WZjvSbc=\n"
+"=v3gg\n"
+"-----END PGP PUBLIC KEY BLOCK-----\n";
+
+const gnutls_datum_t cert2048 = { cert2048_txt, sizeof (cert2048_txt) };
+
+static unsigned char key2048_txt[] =
+"-----BEGIN PGP PRIVATE KEY BLOCK-----\n"
+"Version: GnuPG v1.4.10 (GNU/Linux)\n"
+"Comment: Test key for GnuTLS\n"
+"\n"
+"lQNTBE1/6bQRCAD8TQlwbkkX3bLJvemSA/BqT/z0OrJsuXKFQqK5Pp0BRTwC4iCg\n"
+"wnUFrr012up66YTzaA0aQpkf48gqxZ1XTGZtZ13+aAArChqKiffR7OS+BnROd+D3\n"
+"NkPF0tWDAqRFsybIej1GcdSyPw+neExSfoeYzNpUW9oX2iLh5QZC/xt++kE8tOr8\n"
+"BXiDW/+rudjf8Rc0ZI10vi12rb64eYd7szE49crS2YsjqarnncN+J7RX3jSifKrZ\n"
+"XqP/F5s/0a1Nfd4xQU2fsnbQwiIuKTQjU6BHD/2ILn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n"
+"rmef6yzzQhYuVRCY1//bdBAgoDzjhCvKlgOZY8N+Sulv9wlV+4SjX5QMdQRga9Bn\n"
+"6yaPxLJ3ngRLCj5P4YHubj6/sJA6nV6v+6sQkh4U9zkKYjluuXcgV/+OFwFUGlrX\n"
+"+gyXPOJ1g2LAoLHBGcxgFMgWPBcPUu1nuThSzXGFAAEAgj6e0tgxENBORrJkBCl6\n"
+"xfV6iTNXa3HDArTNTyURRzEN0YjBBBgRCAAJBQJNf+m0AhsiAGoJEHv/KcoLO9+4\n"
+"XyAEGREIAAYFAk1/6bQACgkQQ+/Ras/Fxz1onAD/W3lWDopZrH9R66tiyjYOX4sV\n"
+"b1SoPlKRJngsHouxc4oA/RYoFGrhoY+nL22eza/Ku/SUnVrufZ/jIvQakhpmrLD/\n"
+"ZzEBAJ1w0ez3wUJbsfGlWBkb16pYpIh68/qvTTj84v5N0picAQC1p8JjouN88BJw\n"
+"9UquUquXdK1TY965biHIQ70uaOU4Hw==\n"
+"=Rrkw\n"
+"-----END PGP PRIVATE KEY BLOCK-----\n";
+
+const gnutls_datum_t key2048 = { key2048_txt, sizeof (key2048_txt) };
+
+
static void
server_start (void)
{
@@ -389,94 +504,112 @@ server_start (void)
static void
server (void)
{
+ int j;
/* this must be called once in the program
*/
gnutls_global_init ();
gnutls_global_set_log_function (tls_log_func);
if (debug)
- gnutls_global_set_log_level (2);
-
- gnutls_certificate_allocate_credentials (&pgp_cred);
-
- ret = gnutls_certificate_set_openpgp_key_mem2 (pgp_cred, &server_crt,
- &server_key, "auto",
- GNUTLS_OPENPGP_FMT_BASE64);
- if (err < 0)
- {
- fail ("Could not set server key files...\n");
- }
+ gnutls_global_set_log_level (5);
if (debug)
success ("Launched, setting DH parameters...\n");
generate_dh_params ();
- gnutls_certificate_set_dh_params (pgp_cred, dh_params);
-
client_len = sizeof (sa_cli);
- session = initialize_tls_session ();
-
- sd = accept (listen_sd, (SA *) & sa_cli, &client_len);
-
- if (debug)
- success ("server: connection from %s, port %d\n",
- inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf,
- sizeof (topbuf)), ntohs (sa_cli.sin_port));
-
- gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
- ret = gnutls_handshake (session);
- if (ret < 0)
+ for (j = 0; j < 2; j++)
{
- close (sd);
- gnutls_deinit (session);
- fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret));
- return;
- }
- if (debug)
- success ("server: Handshake was completed\n");
+ if (j==0)
+ {
+ gnutls_certificate_allocate_credentials (&pgp_cred);
+ ret = gnutls_certificate_set_openpgp_key_mem2 (pgp_cred, &server_crt,
+ &server_key, "auto",
+ GNUTLS_OPENPGP_FMT_BASE64);
+ }
+ else
+ {
+ gnutls_certificate_free_credentials (pgp_cred);
+ gnutls_certificate_allocate_credentials (&pgp_cred);
+ ret =
+ gnutls_certificate_set_openpgp_key_mem2 (pgp_cred, &cert2048, &key2048,
+ "auto", GNUTLS_OPENPGP_FMT_BASE64);
+ }
+
+ if (ret < 0)
+ {
+ fail ("Could not set server key files...\n");
+ goto end;
+ }
- if (debug)
- success ("server: TLS version is: %s\n",
- gnutls_protocol_get_name (gnutls_protocol_get_version
- (session)));
+ gnutls_certificate_set_dh_params (pgp_cred, dh_params);
- /* see the Getting peer's information example */
- if (debug)
- print_info (session);
+ session = initialize_tls_session ();
- i = 0;
- for (;;)
- {
- memset (buffer, 0, MAX_BUF + 1);
- ret = gnutls_record_recv (session, buffer, MAX_BUF);
+ sd = accept (listen_sd, (SA *) & sa_cli, &client_len);
- if (ret == 0)
- {
- if (debug)
- success ("server: Peer has closed the GnuTLS connection\n");
- break;
- }
- else if (ret < 0)
+ if (debug)
+ success ("server: connection from %s, port %d\n",
+ inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf,
+ sizeof (topbuf)), ntohs (sa_cli.sin_port));
+
+ gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
+ ret = gnutls_handshake (session);
+ if (ret < 0)
{
- fail ("server: Received corrupted data(%d). Closing...\n", ret);
- break;
+ close (sd);
+ gnutls_deinit (session);
+ fail ("server: Handshake %d has failed (%s)\n\n",
+ j, gnutls_strerror (ret));
+ goto end;
}
- else if (ret > 0)
+ if (debug)
+ success ("server: Handshake %d was completed\n", j);
+
+ if (debug)
+ success ("server: TLS version is: %s\n",
+ gnutls_protocol_get_name (gnutls_protocol_get_version
+ (session)));
+
+ /* see the Getting peer's information example */
+ if (debug)
+ print_info (session);
+
+ i = 0;
+ for (;;)
{
- /* echo data back to the client
- */
- gnutls_record_send (session, buffer, strlen (buffer));
+ memset (buffer, 0, MAX_BUF + 1);
+ ret = gnutls_record_recv (session, buffer, MAX_BUF);
+
+ if (ret == 0)
+ {
+ if (debug)
+ success ("server: Peer has closed the GnuTLS connection\n");
+ break;
+ }
+ else if (ret < 0)
+ {
+ fail ("server: Received corrupted data(%d). Closing...\n", ret);
+ goto end;
+ }
+ else if (ret > 0)
+ {
+ /* echo data back to the client
+ */
+ gnutls_record_send (session, buffer, strlen (buffer));
+ }
}
- }
- /* do not wait for the peer to close the connection.
- */
- gnutls_bye (session, GNUTLS_SHUT_WR);
+ /* do not wait for the peer to close the connection.
+ */
+ gnutls_bye (session, GNUTLS_SHUT_WR);
- close (sd);
- gnutls_deinit (session);
+ close (sd);
+ gnutls_deinit (session);
+ }
+end:
close (listen_sd);
gnutls_certificate_free_credentials (pgp_cred);