diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-08-04 10:21:06 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-08-04 12:08:36 +0200 |
commit | 6e86c87353f8748991090d59161c04a91671a411 (patch) | |
tree | 42614ce80c2c0e32395fe3fb08d7ff6c796ba883 | |
parent | 0416d1f94f36b703de46fa00e465b2bac24063ea (diff) | |
download | gnutls-6e86c87353f8748991090d59161c04a91671a411.tar.gz |
x509/output: print error on invalid public key parameters on certificate
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r-- | lib/x509/output.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/x509/output.c b/lib/x509/output.c index 21373ddb6f..ead49f7552 100644 --- a/lib/x509/output.c +++ b/lib/x509/output.c @@ -1438,27 +1438,37 @@ static int print_crt_pubkey(gnutls_buffer_st * str, gnutls_x509_crt_t crt, gnutls_certificate_print_formats_t format) { - gnutls_pubkey_t pubkey; + gnutls_pubkey_t pubkey = NULL; gnutls_x509_spki_st params; - int ret; + int ret, pk; ret = _gnutls_x509_crt_read_spki_params(crt, ¶ms); if (ret < 0) return ret; + pk = gnutls_x509_crt_get_pk_algorithm(crt, NULL); + if (pk < 0) + pk = GNUTLS_PK_UNKNOWN; + + if (pk == GNUTLS_PK_UNKNOWN) + goto cleanup; /* print basic info only */ + ret = gnutls_pubkey_init(&pubkey); if (ret < 0) return ret; ret = gnutls_pubkey_import_x509(pubkey, crt, 0); - if (ret < 0) + if (ret < 0) { + addf(str, "error importing public key: %s\n", gnutls_strerror(ret)); goto cleanup; + } print_pubkey(str, _("Subject "), pubkey, ¶ms, format); ret = 0; - cleanup: - gnutls_pubkey_deinit(pubkey); + cleanup: + if (pubkey) + gnutls_pubkey_deinit(pubkey); if (ret < 0) { /* print only name */ const char *p; |