summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2015-08-04 13:55:56 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2015-08-04 14:01:00 +0200
commitaa41de6724c059da8f8266cf3bf734e38f9cd15d (patch)
treeff22e6cdfe4b81df310626b856a7859d6d2ce745
parent9581394223754ddeeebd3ffa97aa495bb5c09511 (diff)
downloadgnutls-aa41de6724c059da8f8266cf3bf734e38f9cd15d.tar.gz
tests: added check for decoding of a PKCS #8 key as fallback
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/pkcs8-key-decode.c74
2 files changed, 75 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c24eea4e13..8e5c173e5c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -88,7 +88,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \
mini-record-retvals mini-server-name mini-etm mini-x509-cert-callback \
sign-md5-rep keygen mini-tls-nonblock no-signal pkcs7-gen \
x509sign-verify2 mini-alignment oids atfork prf \
- status-request status-request-ok fallback-scsv
+ status-request status-request-ok fallback-scsv pkcs8-key-decode
mini_dtls_pthread_LDADD = $(LDADD) -lpthread
diff --git a/tests/pkcs8-key-decode.c b/tests/pkcs8-key-decode.c
new file mode 100644
index 0000000000..a36c4af8ea
--- /dev/null
+++ b/tests/pkcs8-key-decode.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * Author: Daniel Berrange
+ *
+ * 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
+ */
+
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+# define PRIVATE_KEY \
+ "-----BEGIN PRIVATE KEY-----\n" \
+ "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALVcr\n" \
+ "BL40Tm6yq88FBhJNw1aaoCjmtg0l4dWQZ/e9Fimx4ARxFpT+ji4FE\n" \
+ "Cgl9s/SGqC+1nvlkm9ViSo0j7MKDbnDB+VRHDvMAzQhA2X7e8M0n9\n" \
+ "rPolUY2lIVC83q0BBaOBkCj2RSmT2xTEbbC2xLukSrg2WP/ihVOxc\n" \
+ "kXRuyFtzAgMBAAECgYB7slBexDwXrtItAMIH6m/U+LUpNe0Xx48OL\n" \
+ "IOn4a4whNgO/o84uIwygUK27ZGFZT0kAGAk8CdF9hA6ArcbQ62s1H\n" \
+ "myxrUbF9/mrLsQw1NEqpuUk9Ay2Tx5U/wPx35S3W/X2AvR/ZpTnCn\n" \
+ "2q/7ym9fyiSoj86drD7BTvmKXlOnOwQJBAPOFMp4mMa9NGpGuEssO\n" \
+ "m3Uwbp6lhcP0cA9MK+iOmeANpoKWfBdk5O34VbmeXnGYWEkrnX+9J\n" \
+ "bM4wVhnnBWtgBMCQQC+qAEmvwcfhauERKYznMVUVksyeuhxhCe7EK\n" \
+ "mPh+U2+g0WwdKvGDgO0PPt1gq0ILEjspMDeMHVdTwkaVBo/uMhAkA\n" \
+ "Z5SsZyCP2aTOPFDypXRdI4eqRcjaEPOUBq27r3uYb/jeboVb2weLa\n" \
+ "L1MmVuHiIHoa5clswPdWVI2y0em2IGoDAkBPSp/v9VKJEZabk9Frd\n" \
+ "a+7u4fanrM9QrEjY3KhduslSilXZZSxrWjjAJPyPiqFb3M8XXA26W\n" \
+ "nz1KYGnqYKhLcBAkB7dt57n9xfrhDpuyVEv+Uv1D3VVAhZlsaZ5Pp\n" \
+ "dcrhrkJn2sa/+O8OKvdrPSeeu/N5WwYhJf61+CPoenMp7IFci\n" \
+ "-----END PRIVATE KEY-----\n"
+
+
+int main(void) {
+ gnutls_x509_privkey_t key;
+ const gnutls_datum_t data = {
+ (unsigned char *)PRIVATE_KEY,
+ strlen(PRIVATE_KEY)
+ };
+ int err;
+
+ if ((err = gnutls_x509_privkey_init(&key)) < 0) {
+ fprintf(stderr, "Failed to init key %s\n", gnutls_strerror(err));
+ exit(1);
+ }
+
+ if ((err = gnutls_x509_privkey_import(key, &data,
+ GNUTLS_X509_FMT_PEM)) < 0) {
+ fprintf(stderr, "Failed to import key %s\n", gnutls_strerror(err));
+ exit(1);
+ }
+
+#if 0
+ fprintf(stderr, "Loaded key\n%s", PRIVATE_KEY);
+#endif
+ gnutls_x509_privkey_deinit(key);
+ return 0;
+}