diff options
author | Randall Spangler <rspangler@chromium.org> | 2016-06-03 14:00:27 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-03 17:47:13 -0700 |
commit | 158b29672a17c1d11e182f0285e0009dd39e5204 (patch) | |
tree | d15e4c2e873de2dede00a9cc5cc662b1a7a4c8a0 /host | |
parent | 46b77fb2f04941c869c3a98cd17e9209c36b2917 (diff) | |
download | vboot-158b29672a17c1d11e182f0285e0009dd39e5204.tar.gz |
futility: cmd_show uses only vboot 2.0 APIs
This removes the remaining vboot 1.0 API calls from cmd_show.
BUG=chromium:611535
BRANCH=none
TEST=make runtests
Change-Id: I03c4260aa034100efbbea1005367cd85dfff273d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/350173
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/include/util_misc.h | 15 | ||||
-rw-r--r-- | host/lib/util_misc.c | 18 | ||||
-rw-r--r-- | host/lib21/include/host_key2.h | 8 |
3 files changed, 32 insertions, 9 deletions
diff --git a/host/lib/include/util_misc.h b/host/lib/include/util_misc.h index 648f2da8..b6372db1 100644 --- a/host/lib/include/util_misc.h +++ b/host/lib/include/util_misc.h @@ -12,6 +12,7 @@ #include "vboot_struct.h" struct rsa_st; struct vb2_packed_key; +struct vb2_private_key; /** * Returns the SHA1 digest of the packed key data as a string. @@ -26,8 +27,18 @@ struct vb2_packed_key; */ const char *packed_key_sha1_string(const struct vb2_packed_key *key); -/* Prints the sha1sum of a VbPrivateKey to stdout. */ -void PrintPrivKeySha1Sum(VbPrivateKey *key); +/** + * Returns the SHA1 digest of the private key data as a string. + * + * The returned string is a global static buffer, so each call to this + * overwrites the previous digest string. So don't call this more than once + * per printf(). + * + * @param key Key to print digest for + * + * @return A string containing the SHA1 digest. + */ +const char *private_key_sha1_string(const struct vb2_private_key *key); /* * Our packed RSBPublicKey buffer (historically in files ending with ".keyb", diff --git a/host/lib/util_misc.c b/host/lib/util_misc.c index 2b0f91c8..56d21b38 100644 --- a/host/lib/util_misc.c +++ b/host/lib/util_misc.c @@ -21,6 +21,7 @@ #include "host_common.h" #include "util_misc.h" #include "vb2_common.h" +#include "host_key2.h" #include "vboot_common.h" const char *packed_key_sha1_string(const struct vb2_packed_key *key) @@ -29,10 +30,10 @@ const char *packed_key_sha1_string(const struct vb2_packed_key *key) uint32_t buflen = key->key_size; uint8_t digest[VB2_SHA1_DIGEST_SIZE]; static char dest[VB2_SHA1_DIGEST_SIZE * 2 + 1]; - char *dnext = dest; vb2_digest_buffer(buf, buflen, VB2_HASH_SHA1, digest, sizeof(digest)); + char *dnext = dest; int i; for (i = 0; i < sizeof(digest); i++) dnext += sprintf(dnext, "%02x", digest[i]); @@ -40,24 +41,27 @@ const char *packed_key_sha1_string(const struct vb2_packed_key *key) return dest; } -void PrintPrivKeySha1Sum(VbPrivateKey *key) +const char *private_key_sha1_string(const struct vb2_private_key *key) { uint8_t *buf; uint32_t buflen; uint8_t digest[VB2_SHA1_DIGEST_SIZE]; - int i; + static char dest[VB2_SHA1_DIGEST_SIZE * 2 + 1]; - if (vb_keyb_from_rsa(key->rsa_private_key, &buf, &buflen)) { - printf("<error>"); - return; + if (!key->rsa_private_key || + vb_keyb_from_rsa(key->rsa_private_key, &buf, &buflen)) { + return "<error>"; } vb2_digest_buffer(buf, buflen, VB2_HASH_SHA1, digest, sizeof(digest)); + char *dnext = dest; + int i; for (i = 0; i < sizeof(digest); i++) - printf("%02x", digest[i]); + dnext += sprintf(dnext, "%02x", digest[i]); free(buf); + return dest; } int vb_keyb_from_rsa(struct rsa_st *rsa_private_key, diff --git a/host/lib21/include/host_key2.h b/host/lib21/include/host_key2.h index 7c95ac16..e58b37d7 100644 --- a/host/lib21/include/host_key2.h +++ b/host/lib21/include/host_key2.h @@ -22,6 +22,14 @@ struct vb2_private_key { struct vb2_id id; /* Key ID */ }; +struct vb2_packed_private_key { + /* Signature algorithm used by the key (enum vb2_crypto_algorithm) */ + uint32_t algorithm; + uint32_t reserved2; + /* Key data formatted for d2i_RSAPrivateKey() */ + uint8_t key_data[0]; +}; + /* Convert between enums and human-readable form. Terminated with {0, 0}. */ struct vb2_text_vs_enum { const char *name; |