summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/cert-common.h98
-rw-r--r--tests/set_x509_pkcs12_key.c104
3 files changed, 203 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 60bd75e07f..f11057366a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -103,7 +103,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \
system-prio-file name-constraints-merge crl-basic crq-basic \
send-client-cert custom-urls-override hex rehandshake-switch-psk-id \
rehandshake-switch-srp-id base64 srpbase64 pkcs1-digest-info set_x509_key \
- set_x509_key_file_der
+ set_x509_key_file_der set_x509_pkcs12_key
if HAVE_SECCOMP_TESTS
ctests += dtls-with-seccomp tls-with-seccomp dtls-client-with-seccomp tls-client-with-seccomp
diff --git a/tests/cert-common.h b/tests/cert-common.h
index 69f44ae760..0b51e22e8f 100644
--- a/tests/cert-common.h
+++ b/tests/cert-common.h
@@ -634,3 +634,101 @@ static char unknown_ca_cert_pem[] =
const gnutls_datum_t unknown_ca_cert = { (void*)unknown_ca_cert_pem,
sizeof(unknown_ca_cert_pem)
};
+
+static const char server_ca3_pkcs12_pem[] =
+ "-----BEGIN PKCS12-----\n"
+ "MIIQvwIBAzCCEIcGCSqGSIb3DQEHAaCCEHgEghB0MIIQcDCCBOcGCSqGSIb3DQEH\n"
+ "BqCCBNgwggTUAgEAMIIEzQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQMwDgQIGlbZ\n"
+ "V1qak5wCAhTsgIIEoLClLTWuG7yxoUp9Jw34KHHgK5jun/kkUN8RcUDDCOWUsuJG\n"
+ "HPV9TPAG2LpS39Leg+Uo4NpTTUp8RVnbo2I+jR9Bl/cL6zqG0Y+bpaGKsFwZqYQu\n"
+ "wbKctXL/yJhPKJ13paJB2W6kvU05KbC/6Zq69zYxfMkm0fPGnruGBenMUYbP/BKM\n"
+ "6xXmqztGCMHrh9dGyGs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dVPAvF+ASmR+\n"
+ "whTJxkfH5mRO1/0/kgtSH/J37HtkAQC7OAUMycdrEC8r2+TKk/CMV00UIEzfCEo1\n"
+ "kfdSiRB+oBDStE1TJ8X6l0slr7BUNjuinU3Waq5FtybC2cI6MkGq0Dj+1qQflqs6\n"
+ "eT2SM8MN2v/9ktqDqGqWGuIByxMHJTRcithOhdClCfj2VYWQsp4L6lWtE5EDgEbG\n"
+ "d3UjaRGUPH58peE3vOziC1sruMN9hEbQU1JYRWerQlBYjt2RAHuSzQhSbu3GKJNV\n"
+ "1KVDTxVxIpuTcdqKenGTJvA79TPnM/fCVbwgW18DAUhFruqgfCTU8EVMLgqDecnR\n"
+ "v4YzX3weMpYuhnPqhcOkgImvRJv7C0b/yjV/0ctW0uQxtTD8nAN0wmQyCfY4RTFC\n"
+ "MBsGCSqGSIb3DQEJFDEOHgwAcwBlAHIAdgBlAHIwIwYJKoZIhvcNAQkVMRYEFDOd\n"
+ "4SfTi9X86wX8tceBaU9eO9nWMC8wHzAHBgUrDgMCGgQUSrnTiqr47JA4mCEpQDQX\n"
+ "JMU7QdMECJJR3+yAuOeDAgIoAA==\n"
+ "-----END PKCS12-----\n";
+
+const gnutls_datum_t server_ca3_pkcs12 = { (void*)server_ca3_pkcs12_pem,
+ sizeof(server_ca3_pkcs12_pem)-1
+};
diff --git a/tests/set_x509_pkcs12_key.c b/tests/set_x509_pkcs12_key.c
new file mode 100644
index 0000000000..110404d117
--- /dev/null
+++ b/tests/set_x509_pkcs12_key.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2014-2016 Nikos Mavrogiannopoulos
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GnuTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+#include "cert-common.h"
+#include "utils.h"
+
+static void compare(const gnutls_datum_t *der, const void *ipem)
+{
+ gnutls_datum_t pem = {(void*)ipem, strlen((char*)ipem)};
+ gnutls_datum_t new_der;
+ int ret;
+
+ ret = gnutls_pem_base64_decode2("CERTIFICATE", &pem, &new_der);
+ if (ret < 0) {
+ fail("error: %s\n", gnutls_strerror(ret));
+ }
+
+ if (der->size != new_der.size || memcmp(der->data, new_der.data, der->size) != 0) {
+ fail("error in %d: %s\n", __LINE__, "cert don't match");
+ exit(1);
+ }
+ gnutls_free(new_der.data);
+ return;
+}
+
+void doit(void)
+{
+ int ret;
+ gnutls_certificate_credentials_t xcred;
+ const char *certfile = "does-not-exist.pem";
+ gnutls_datum_t tcert;
+ FILE *fp;
+
+ global_init();
+ assert(gnutls_certificate_allocate_credentials(&xcred) >= 0);
+
+ /* this will fail */
+ ret = gnutls_certificate_set_x509_simple_pkcs12_file(xcred, certfile,
+ GNUTLS_X509_FMT_PEM, "1234");
+ if (ret != GNUTLS_E_FILE_ERROR)
+ fail("gnutls_certificate_set_x509_simple_pkcs12_file failed: %s\n", gnutls_strerror(ret));
+
+ gnutls_certificate_free_credentials(xcred);
+
+ assert(gnutls_certificate_allocate_credentials(&xcred) >= 0);
+
+ certfile = tmpnam(NULL);
+
+ fp = fopen(certfile, "w");
+ if (fp == NULL)
+ fail("error in fopen\n");
+
+ assert(fwrite(server_ca3_pkcs12_pem, 1, strlen((char*)server_ca3_pkcs12_pem), fp)>0);
+ fclose(fp);
+
+ ret = gnutls_certificate_set_x509_simple_pkcs12_file(xcred, certfile,
+ GNUTLS_X509_FMT_PEM, "1234");
+ if (ret < 0)
+ fail("gnutls_certificate_set_x509_simple_pkcs12_file failed: %s\n", gnutls_strerror(ret));
+
+ /* verify whether the stored certificate match the ones we have */
+ ret = gnutls_certificate_get_crt_raw(xcred, 0, 0, &tcert);
+ if (ret < 0) {
+ fail("error in %d: %s\n", __LINE__, gnutls_strerror(ret));
+ exit(1);
+ }
+
+ compare(&tcert, server_ca3_cert_pem);
+
+ remove(certfile);
+
+ gnutls_certificate_free_credentials(xcred);
+ gnutls_global_deinit();
+}