summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cve-2008-4989.c52
-rw-r--r--tests/pkcs12_encode.c76
2 files changed, 100 insertions, 28 deletions
diff --git a/tests/cve-2008-4989.c b/tests/cve-2008-4989.c
index 3c672be645..c054426b7f 100644
--- a/tests/cve-2008-4989.c
+++ b/tests/cve-2008-4989.c
@@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <error.h>
#include <string.h>
#include <utils.h>
@@ -166,30 +165,42 @@ main (int argc, char *argv[])
{
ret = gnutls_x509_crt_init (&certs[i]);
if (ret < 0)
- error (EXIT_FAILURE, 0, "gnutls_x509_crt_init[%d]: %s", (int) i,
+ {
+ fprintf (stderr, "gnutls_x509_crt_init[%d]: %s", (int) i,
gnutls_strerror (ret));
+ exit(1);
+ }
tmp.data = (unsigned char *) pem_certs[i];
tmp.size = strlen (pem_certs[i]);
ret = gnutls_x509_crt_import (certs[i], &tmp, GNUTLS_X509_FMT_PEM);
if (ret < 0)
- error (EXIT_FAILURE, 0, "gnutls_x509_crt_import[%d]: %s", (int) i,
+ {
+ fprintf (stderr, "gnutls_x509_crt_import[%d]: %s", (int) i,
gnutls_strerror (ret));
+ exit(1);
+ }
}
ret = gnutls_x509_crt_init (&ca);
if (ret < 0)
- error (EXIT_FAILURE, 0, "gnutls_x509_crt_init: %s",
+ {
+ fprintf(stderr, "gnutls_x509_crt_init: %s",
gnutls_strerror (ret));
+ exit(1);
+ }
tmp.data = (unsigned char *) pem_ca;
tmp.size = strlen (pem_ca);
ret = gnutls_x509_crt_import (ca, &tmp, GNUTLS_X509_FMT_PEM);
if (ret < 0)
- error (EXIT_FAILURE, 0, "gnutls_x509_crt_import: %s",
+ {
+ fprintf(stderr, "gnutls_x509_crt_import: %s",
gnutls_strerror (ret));
+ exit(1);
+ }
ret = gnutls_x509_crt_list_verify (certs, CHAIN_LENGTH,
&ca, 1,
@@ -197,11 +208,17 @@ main (int argc, char *argv[])
GNUTLS_VERIFY_DISABLE_TIME_CHECKS,
&verify_status);
if (ret < 0)
- error (EXIT_FAILURE, 0, "gnutls_x509_crt_list_verify[%d]: %s", (int) i,
+ {
+ fprintf(stderr, "gnutls_x509_crt_list_verify[%d]: %s", (int) i,
gnutls_strerror (ret));
+ exit(1);
+ }
if (verify_status != (GNUTLS_CERT_SIGNER_NOT_FOUND | GNUTLS_CERT_INVALID))
- error (EXIT_FAILURE, 0, "verify_status: %d", verify_status);
+ {
+ fprintf( stderr, "verify_status: %d", verify_status);
+ exit(1);
+ }
gnutls_x509_crt_deinit (ca);
for (i = 0; i < CHAIN_LENGTH; i++)
@@ -212,28 +229,39 @@ main (int argc, char *argv[])
ret = gnutls_x509_crt_init (&self_cert);
if (ret < 0)
- error (EXIT_FAILURE, 0, "gnutls_x509_crt_init: %s",
+ {
+ fprintf( stderr, "gnutls_x509_crt_init: %s",
gnutls_strerror (ret));
+ exit(1);
+ }
tmp.data = (unsigned char *) pem_self_cert;
tmp.size = strlen (pem_self_cert);
ret = gnutls_x509_crt_import (self_cert, &tmp, GNUTLS_X509_FMT_PEM);
if (ret < 0)
- error (EXIT_FAILURE, 0, "gnutls_x509_crt_import: %s",
+ {
+ fprintf (stderr, "gnutls_x509_crt_import: %s",
gnutls_strerror (ret));
-
+ exit(1);
+ }
ret = gnutls_x509_crt_list_verify (&self_cert, 1,
&self_cert, 1,
NULL, 0,
GNUTLS_VERIFY_DISABLE_TIME_CHECKS,
&verify_status);
if (ret < 0)
- error (EXIT_FAILURE, 0, "gnutls_x509_crt_list_verify[%d]: %s", (int) i,
+ {
+ fprintf(stderr, "gnutls_x509_crt_list_verify[%d]: %s", (int) i,
gnutls_strerror (ret));
+ exit(1);
+ }
if (verify_status != 0)
- error (EXIT_FAILURE, 0, "verify_status: %d", verify_status);
+ {
+ fprintf(stderr, "verify_status: %d", verify_status);
+ exit(1);
+ }
gnutls_x509_crt_deinit (self_cert);
diff --git a/tests/pkcs12_encode.c b/tests/pkcs12_encode.c
index 632418396a..caa3ce88f5 100644
--- a/tests/pkcs12_encode.c
+++ b/tests/pkcs12_encode.c
@@ -30,7 +30,6 @@
#include "utils.h"
-#include <error.h>
#include <stdio.h>
#include <stdlib.h>
@@ -87,7 +86,10 @@ doit (void)
ret = global_init ();
if (ret < 0)
- error (EXIT_FAILURE, 0, "global_init %d", ret);
+ {
+ fprintf(stderr, "global_init %d", ret);
+ exit(1);
+ }
gnutls_global_set_log_function (tls_log_func);
if (debug)
@@ -96,66 +98,102 @@ doit (void)
/* Read certs. */
ret = gnutls_x509_crt_init (&client);
if (ret < 0)
- error (EXIT_FAILURE, 0, "crt_init: %d", ret);
+ {
+ fprintf(stderr, "crt_init: %d", ret);
+ exit(1);
+ }
ret = gnutls_x509_crt_import (client, &client_dat, GNUTLS_X509_FMT_PEM);
if (ret < 0)
- error (EXIT_FAILURE, 0, "crt_import: %d", ret);
+ {
+ fprintf(stderr, "crt_import: %d", ret);
+ exit(1);
+ }
ret = gnutls_x509_crt_init (&ca);
if (ret < 0)
- error (EXIT_FAILURE, 0, "ca_init: %d", ret);
+ {
+ fprintf(stderr, "ca_init: %d", ret);
+ exit(1);
+ }
ret = gnutls_x509_crt_import (ca, &ca_dat, GNUTLS_X509_FMT_PEM);
if (ret < 0)
- error (EXIT_FAILURE, 0, "ca_import: %d", ret);
+ {
+ fprintf(stderr, "ca_import: %d", ret);
+ exit(1);
+ }
/* Create PKCS#12 structure. */
ret = gnutls_pkcs12_init (&pkcs12);
if (ret < 0)
- error (EXIT_FAILURE, 0, "pkcs12_init: %d", ret);
+ {
+ fprintf(stderr, "pkcs12_init: %d", ret);
+ exit(1);
+ }
/* Generate and add PKCS#12 cert bags. */
for (i = 0; i < 2; i++)
{
ret = gnutls_pkcs12_bag_init (&bag);
if (ret < 0)
- error (EXIT_FAILURE, 0, "bag_init: %d", ret);
+ {
+ fprintf(stderr, "bag_init: %d", ret);
+ exit(1);
+ }
ret = gnutls_pkcs12_bag_set_crt (bag, i == 0 ? client : ca);
if (ret < 0)
- error (EXIT_FAILURE, 0, "set_crt: %d", ret);
+ {
+ fprintf(stderr, "set_crt: %d", ret);
+ exit(1);
+ }
indx = ret;
ret = gnutls_pkcs12_bag_set_friendly_name (bag, indx,
i == 0 ? "client" : "ca");
if (ret < 0)
- error (EXIT_FAILURE, 0, "set_friendly_name: %d", ret);
+ {
+ fprintf(stderr, "set_friendly_name: %d", ret);
+ exit(1);
+ }
size = sizeof (key_id_buf);
ret = gnutls_x509_crt_get_key_id (i == 0 ? client : ca, 0,
key_id_buf, &size);
if (ret < 0)
- error (EXIT_FAILURE, 0, "get_key_id: %d", ret);
+ {
+ fprintf(stderr, "get_key_id: %d", ret);
+ exit(1);
+ }
key_id.data = key_id_buf;
key_id.size = size;
ret = gnutls_pkcs12_bag_set_key_id (bag, indx, &key_id);
if (ret < 0)
- error (EXIT_FAILURE, 0, "bag_set_key_id: %d", ret);
+ {
+ fprintf(stderr, "bag_set_key_id: %d", ret);
+ exit(1);
+ }
ret = gnutls_pkcs12_bag_encrypt (bag, "pass",
i == 0 ? GNUTLS_PKCS8_USE_PKCS12_3DES
: GNUTLS_PKCS_USE_PKCS12_RC2_40);
if (ret < 0)
- error (EXIT_FAILURE, 0, "bag_encrypt: %d: %s", ret,
+ {
+ fprintf(stderr, "bag_encrypt: %d: %s", ret,
i == 0 ? "3DES" : "RC2-40");
+ exit(1);
+ }
ret = gnutls_pkcs12_set_bag (pkcs12, bag);
if (ret < 0)
- error (EXIT_FAILURE, 0, "set_bag: %d", ret);
+ {
+ fprintf(stderr, "set_bag: %d", ret);
+ exit(1);
+ }
gnutls_pkcs12_bag_deinit (bag);
}
@@ -163,12 +201,18 @@ doit (void)
/* MAC the structure, export and print. */
ret = gnutls_pkcs12_generate_mac (pkcs12, "pass");
if (ret < 0)
- error (EXIT_FAILURE, 0, "generate_mac: %d", ret);
+ {
+ fprintf(stderr, "generate_mac: %d", ret);
+ exit(1);
+ }
size = sizeof (outbuf);
ret = gnutls_pkcs12_export (pkcs12, GNUTLS_X509_FMT_PEM, outbuf, &size);
if (ret < 0)
- error (EXIT_FAILURE, 0, "pkcs12_export: %d", ret);
+ {
+ fprintf(stderr, "pkcs12_export: %d", ret);
+ exit(1);
+ }
if (debug)
fwrite (outbuf, size, 1, stdout);