diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-06 18:18:02 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-07 10:55:17 +0200 |
commit | ed749edbe058b9c33dc1a2b758fcc92e1e7ddde5 (patch) | |
tree | 564bad907c4eece3cd3244ea098c65d72271cd89 | |
parent | f971a1da022ef9cf0e5455780a790ff2ad287fbb (diff) | |
download | gnutls-ed749edbe058b9c33dc1a2b758fcc92e1e7ddde5.tar.gz |
certtool: print the key PIN on private and public keys
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r-- | src/certtool-common.c | 13 | ||||
-rw-r--r-- | src/certtool.c | 11 | ||||
-rw-r--r-- | src/common.c | 20 | ||||
-rw-r--r-- | src/common.h | 1 |
4 files changed, 23 insertions, 22 deletions
diff --git a/src/certtool-common.c b/src/certtool-common.c index 1cfb056026..2003188b57 100644 --- a/src/certtool-common.c +++ b/src/certtool-common.c @@ -1211,7 +1211,8 @@ static void privkey_info_int(FILE *outfile, common_info_st * cinfo, fprintf(stderr, "Error in key id calculation: %s\n", gnutls_strerror(ret)); } else { - gnutls_datum_t art; + fprintf(outfile, "Public Key PIN:\n\tpin-sha256:%s\n", + raw_to_base64(lbuffer, size)); fprintf(outfile, "Public Key ID:\n\tsha256:%s\n", raw_to_string(lbuffer, size)); @@ -1223,16 +1224,6 @@ static void privkey_info_int(FILE *outfile, common_info_st * cinfo, fprintf(outfile, "\tsha1:%s\n", raw_to_string(lbuffer, size)); } - - ret = - gnutls_random_art(GNUTLS_RANDOM_ART_OPENSSH, cprint, - bits, lbuffer, size, &art); - if (ret >= 0) { - fprintf(outfile, "Public key's random art:\n%s\n", - art.data); - gnutls_free(art.data); - } - } fprintf(outfile, "\n"); diff --git a/src/certtool.c b/src/certtool.c index bf564529de..79813fe458 100644 --- a/src/certtool.c +++ b/src/certtool.c @@ -1632,17 +1632,6 @@ void pgp_privkey_info(void) fprintf(outfile, "Fingerprint: %s\n", raw_to_string(lbuffer, size)); - - ret = - gnutls_random_art(GNUTLS_RANDOM_ART_OPENSSH, - cprint, bits, lbuffer, size, - &art); - if (ret >= 0) { - fprintf(outfile, - "Fingerprint's random art:\n%s\n\n", - art.data); - gnutls_free(art.data); - } } } diff --git a/src/common.c b/src/common.c index f8e8f0ede2..0c2844d82d 100644 --- a/src/common.c +++ b/src/common.c @@ -74,6 +74,26 @@ const char *raw_to_string(const unsigned char *raw, size_t raw_size) return buf; } +const char *raw_to_base64(const unsigned char *raw, size_t raw_size) +{ + static char buf[1024]; + gnutls_datum_t data = {(unsigned char*)raw, raw_size}; + size_t buf_size; + int ret; + + if (raw_size == 0) + return "(empty)"; + + buf_size = sizeof(buf); + ret = gnutls_pem_base64_encode(NULL, &data, buf, &buf_size); + if (ret < 0) + return "(error)"; + + buf[sizeof(buf) - 1] = '\0'; + + return buf; +} + static void print_x509_info_compact(gnutls_session_t session) { gnutls_x509_crt_t crt; diff --git a/src/common.h b/src/common.h index 8cd321e040..e1d9de5071 100644 --- a/src/common.h +++ b/src/common.h @@ -67,6 +67,7 @@ void print_list(const char *priorities, int verbose); int cert_verify(gnutls_session_t session, const char *hostname, const char *purpose); const char *raw_to_string(const unsigned char *raw, size_t raw_size); +const char *raw_to_base64(const unsigned char *raw, size_t raw_size); int check_command(gnutls_session_t session, const char *str); int |