diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-06 18:18:02 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-07 13:13:16 +0200 |
commit | cc381d566593dc833a82038a1d620cc3f9e9b651 (patch) | |
tree | 991d1a850b612b666a05dd82f4cdfb8d59e37282 | |
parent | 1d96fd1c70a70a9ac03c56a3aefe29b9e029b5b9 (diff) | |
download | gnutls-cc381d566593dc833a82038a1d620cc3f9e9b651.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 04af0e9429..c62d15eb27 100644 --- a/src/certtool-common.c +++ b/src/certtool-common.c @@ -1190,7 +1190,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)); @@ -1202,16 +1203,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 3c736a3ce4..36704b39c1 100644 --- a/src/certtool.c +++ b/src/certtool.c @@ -1619,17 +1619,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 df2b431423..819a541afc 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 |