From f0033c9f2a89d14ff69fdc38f982c8f1a94a9570 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Fri, 16 Oct 2015 13:16:36 +0200 Subject: tools: allow importing a pubkey from a certificate --- src/certtool-common.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/certtool-common.c') diff --git a/src/certtool-common.c b/src/certtool-common.c index 55c4c25c43..41b1655f19 100644 --- a/src/certtool-common.c +++ b/src/certtool-common.c @@ -638,22 +638,21 @@ gnutls_pubkey_t load_pubkey(int mand, common_info_st * info) } ret = gnutls_pubkey_import(key, &dat, info->incert_format); - - free(dat.data); - if (ret == GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR) { - fprintf(stderr, - "import error: could not find a valid PEM header; " - "check if your key has the PUBLIC KEY header\n"); - exit(1); - } - - if (ret < 0) { + ret = gnutls_pubkey_import_x509_raw(key, &dat, info->incert_format, 0); + if (ret < 0) { + fprintf(stderr, + "import error: could not find a valid PEM header; " + "check if your key has the PUBLIC KEY header\n"); + exit(1); + } + } else if (ret < 0) { fprintf(stderr, "importing --load-pubkey: %s: %s\n", info->pubkey, gnutls_strerror(ret)); exit(1); } + free(dat.data); return key; } -- cgit v1.2.1