summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@crystal.(none)>2008-11-05 22:51:45 +0200
committerNikos Mavrogiannopoulos <nmav@crystal.(none)>2008-11-05 22:51:45 +0200
commit126cf449f0239e3c209acd21294f4ca0cb6a5247 (patch)
tree7451b682d6f7a5717cd6f77a4d09ba1632c1411c /tests
parentea0180b372f3fbc2b6f28b762f9d9b2fb4a8a799 (diff)
downloadgnutls-126cf449f0239e3c209acd21294f4ca0cb6a5247.tar.gz
* Added gnutls_certificate_set_x509_simple_pkcs12_mem
* Made gnutls_certificate_set_x509_simple_pkcs12_file() more advanced. It will return a corresponding certificate and key pair. [The previous version would return the first ones found]. Eliminated memory leaks on error conditions on these functions.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/pkcs12-decode/pkcs12_2certs.p12bin0 -> 5853 bytes
-rw-r--r--tests/set_pkcs12_cred.c28
3 files changed, 30 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d750df012f..6304877065 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -76,4 +76,6 @@ TESTS = $(ctests)
TESTS_ENVIRONMENT = \
PKCS12FILE=$(srcdir)/pkcs12-decode/client.p12 \
PKCS12PASSWORD=foobar \
+ PKCS12FILE_2=$(srcdir)/pkcs12-decode/pkcs12_2certs.p12 \
+ PKCS12PASSWORD_2="" \
$(VALGRIND)
diff --git a/tests/pkcs12-decode/pkcs12_2certs.p12 b/tests/pkcs12-decode/pkcs12_2certs.p12
new file mode 100644
index 0000000000..bcbf48b4de
--- /dev/null
+++ b/tests/pkcs12-decode/pkcs12_2certs.p12
Binary files differ
diff --git a/tests/set_pkcs12_cred.c b/tests/set_pkcs12_cred.c
index 8e292d484b..c0349a24c3 100644
--- a/tests/set_pkcs12_cred.c
+++ b/tests/set_pkcs12_cred.c
@@ -64,5 +64,33 @@ doit (void)
gnutls_certificate_free_credentials (x509cred);
+ /* try now if we can read correctly from a pkcs12 file that
+ * contains two certificates (one unrelated with key)
+ */
+ ret = gnutls_certificate_allocate_credentials (&x509cred);
+ if (ret < 0)
+ fail ("gnutls_certificate_allocate_credentials failed %d\n", ret);
+
+ file = getenv ("PKCS12FILE_2");
+ password = getenv ("PKCS12PASSWORD_2");
+
+ if (!file)
+ file = "pkcs12-decode/pkcs12_2certs.p12";
+ if (!password)
+ password = "";
+
+ success ("Reading PKCS#12 blob from `%s' using password `%s'.\n",
+ file, password);
+ ret = gnutls_certificate_set_x509_simple_pkcs12_file (x509cred,
+ file,
+ GNUTLS_X509_FMT_DER,
+ password);
+ if (ret < 0)
+ fail ("x509_pkcs12 failed %d: %s\n", ret, gnutls_strerror (ret));
+
+ success ("Read file OK\n");
+
+ gnutls_certificate_free_credentials (x509cred);
+
gnutls_global_deinit ();
}