diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-12-03 00:52:08 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-12-06 08:58:41 +0100 |
commit | 434ea3aa21e01de4fe6422392c0c76a369b60ab1 (patch) | |
tree | 51b93b8b56b5f48b6eda8d4388876c8615b8347b /tests | |
parent | dd901da76d4e1453feec20abb5287f009a9a7701 (diff) | |
download | gnutls-434ea3aa21e01de4fe6422392c0c76a369b60ab1.tar.gz |
Import PKCS #12 keys
Diffstat (limited to 'tests')
-rw-r--r-- | tests/key-openssl.c | 13 | ||||
-rw-r--r-- | tests/pkcs12_simple.c | 24 |
2 files changed, 35 insertions, 2 deletions
diff --git a/tests/key-openssl.c b/tests/key-openssl.c index 9d2ef9d460..02d174ed16 100644 --- a/tests/key-openssl.c +++ b/tests/key-openssl.c @@ -106,8 +106,21 @@ doit (void) { fail ("gnutls_x509_privkey_import_openssl (key2): %s\n", gnutls_strerror(ret)) ; } + gnutls_x509_privkey_deinit (pkey); + ret = gnutls_x509_privkey_init (&pkey); + if (ret < 0) + fail ("gnutls_x509_privkey_init: %d\n", ret); + + key.data = (void*)key1; + key.size = sizeof(key1); + ret = gnutls_x509_privkey_import2 (pkey, &key, GNUTLS_X509_FMT_PEM, "123456", 0); + if (ret < 0) + { + fail ("gnutls_x509_privkey_import2: %s\n", gnutls_strerror(ret)) ; + } + gnutls_x509_privkey_deinit (pkey); gnutls_global_deinit (); } diff --git a/tests/pkcs12_simple.c b/tests/pkcs12_simple.c index ad17c0e413..5da59ef154 100644 --- a/tests/pkcs12_simple.c +++ b/tests/pkcs12_simple.c @@ -30,6 +30,12 @@ #include <gnutls/x509.h> #include "utils.h" +static void +tls_log_func (int level, const char *str) +{ + fprintf (stderr, "<%d>| %s", level, str); +} + void doit (void) { @@ -47,6 +53,10 @@ doit (void) if (ret < 0) fail ("gnutls_global_init failed %d\n", ret); + gnutls_global_set_log_function (tls_log_func); + if (debug) + gnutls_global_set_log_level (2); + ret = gnutls_pkcs12_init(&pkcs12); if (ret < 0) fail ("initialization failed: %s\n", gnutls_strerror(ret)); @@ -70,8 +80,6 @@ doit (void) if (ret < 0) fail ("pkcs12_import failed %d: %s\n", ret, gnutls_strerror (ret)); - free(file_data); - if (debug) success ("Read file OK\n"); @@ -116,6 +124,18 @@ doit (void) for (i=0;i<extras_size;i++) gnutls_x509_crt_deinit(extras[i]); gnutls_free(extras); + + /* Try gnutls_x509_privkey_import2() */ + ret = gnutls_x509_privkey_init(&pkey); + if (ret < 0) + fail ("gnutls_x509_privkey_init failed %d: %s\n", ret, gnutls_strerror (ret)); + + ret = gnutls_x509_privkey_import2(pkey, &data, GNUTLS_X509_FMT_DER, password, 0); + if (ret < 0) + fail ("gnutls_x509_privkey_import2 failed %d: %s\n", ret, gnutls_strerror (ret)); + gnutls_x509_privkey_deinit(pkey); + + free(file_data); gnutls_global_deinit (); } |