diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-07 09:21:19 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-07 13:13:16 +0200 |
commit | de9effc17530f43a4380bd4d248cbf8225bf01b6 (patch) | |
tree | c01c945917cd5dc0d68654702534e58b2859e267 | |
parent | cc381d566593dc833a82038a1d620cc3f9e9b651 (diff) | |
download | gnutls-de9effc17530f43a4380bd4d248cbf8225bf01b6.tar.gz |
certtool: improved printing of the key PIN and key ID
That is, on private keys use the same format when printing
the public Key ID and public key PIN, as when printing it
in certificates.
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r-- | src/certtool-common.c | 4 | ||||
-rw-r--r-- | src/common.c | 22 | ||||
-rw-r--r-- | src/common.h | 1 |
3 files changed, 24 insertions, 3 deletions
diff --git a/src/certtool-common.c b/src/certtool-common.c index c62d15eb27..30f6884da5 100644 --- a/src/certtool-common.c +++ b/src/certtool-common.c @@ -1194,14 +1194,14 @@ static void privkey_info_int(FILE *outfile, common_info_st * cinfo, raw_to_base64(lbuffer, size)); fprintf(outfile, "Public Key ID:\n\tsha256:%s\n", - raw_to_string(lbuffer, size)); + raw_to_hex(lbuffer, size)); size = lbuffer_size; ret = gnutls_x509_privkey_get_key_id(key, GNUTLS_KEYID_USE_SHA1, lbuffer, &size); if (ret >= 0) { fprintf(outfile, "\tsha1:%s\n", - raw_to_string(lbuffer, size)); + raw_to_hex(lbuffer, size)); } } fprintf(outfile, "\n"); diff --git a/src/common.c b/src/common.c index 819a541afc..d82a83430c 100644 --- a/src/common.c +++ b/src/common.c @@ -53,7 +53,7 @@ const char str_unknown[] = "(unknown)"; -/* Hex encodes the given data. +/* Hex encodes the given data adding a semicolon between hex bytes. */ const char *raw_to_string(const unsigned char *raw, size_t raw_size) { @@ -74,6 +74,26 @@ const char *raw_to_string(const unsigned char *raw, size_t raw_size) return buf; } +/* Hex encodes the given data. + */ +const char *raw_to_hex(const unsigned char *raw, size_t raw_size) +{ + static char buf[1024]; + size_t i; + if (raw_size == 0) + return "(empty)"; + + if (raw_size * 2 + 1 >= sizeof(buf)) + return "(too large)"; + + for (i = 0; i < raw_size; i++) { + sprintf(&(buf[i * 2]), "%02x", raw[i]); + } + buf[sizeof(buf) - 1] = '\0'; + + return buf; +} + const char *raw_to_base64(const unsigned char *raw, size_t raw_size) { static char buf[1024]; diff --git a/src/common.h b/src/common.h index e1d9de5071..f1c828ce40 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_hex(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); |