Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Unified Diff: utility/vbutil_key.c

Issue 3300006: Enhance output and helpfulness of --unpack options for vbutil_key (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utility/vbutil_key.c
diff --git a/utility/vbutil_key.c b/utility/vbutil_key.c
index 7d048ac06002338e754fb765d84b13d3c786a44d..c076bfff0fa7a2afb47f490218f0bcc74cf3b360 100644
--- a/utility/vbutil_key.c
+++ b/utility/vbutil_key.c
@@ -24,6 +24,7 @@ enum {
OPT_ALGORITHM,
OPT_MODE_PACK,
OPT_MODE_UNPACK,
+ OPT_COPYTO,
};
static struct option long_opts[] = {
@@ -32,6 +33,7 @@ static struct option long_opts[] = {
{"algorithm", 1, 0, OPT_ALGORITHM },
{"pack", 1, 0, OPT_MODE_PACK },
{"unpack", 1, 0, OPT_MODE_UNPACK },
+ {"copyto", 1, 0, OPT_COPYTO },
{NULL, 0, 0, 0}
};
@@ -62,6 +64,10 @@ static int PrintHelp(char *progname) {
fprintf(stderr,
"\nOR\n\n"
"Usage: %s --unpack <infile>\n"
+ "\n"
+ " Optional parameters:\n"
+ " --copyto <file> "
+ "Write a copy of the key to this file.\n"
"\n",
progname);
@@ -95,13 +101,22 @@ static int Pack(const char *infile, const char *outfile, uint64_t algorithm,
}
Free(privkey);
return 0;
- }
+ }
error("Unable to parse either .keyb or .pem from %s\n", infile);
return 1;
}
+static void PrintDigest(const uint8_t* buf, uint64_t buflen) {
+ uint8_t *digest = DigestBuf(buf, buflen, SHA1_DIGEST_ALGORITHM);
+ int i;
+ for (i=0; i<SHA1_DIGEST_SIZE; i++)
+ printf("%02x", digest[i]);
+ printf("\n");
+ Free(digest);
+}
+
/* Unpack a .vbpubk or .vbprivk */
static int Unpack(const char *infile, const char *outfile) {
VbPublicKey* pubkey;
@@ -118,6 +133,15 @@ static int Unpack(const char *infile, const char *outfile) {
(pubkey->algorithm < kNumAlgorithms ?
algo_strings[pubkey->algorithm] : "(invalid)"));
printf("Key Version: %" PRIu64 "\n", pubkey->key_version);
+ printf("Key sha1sum: ");
+ PrintDigest(((uint8_t *)pubkey) + pubkey->key_offset, pubkey->key_size);
+ if (outfile) {
+ if (0 != PublicKeyWrite(outfile, pubkey)) {
+ fprintf(stderr, "vbutil_key: Error writing key copy.\n");
+ Free(pubkey);
+ return 1;
+ }
+ }
Free(pubkey);
return 0;
}
@@ -128,13 +152,17 @@ static int Unpack(const char *infile, const char *outfile) {
printf("Algorithm: %" PRIu64 " %s\n", privkey->algorithm,
(privkey->algorithm < kNumAlgorithms ?
algo_strings[privkey->algorithm] : "(invalid)"));
+ if (outfile) {
+ if (0 != PrivateKeyWrite(outfile, privkey)) {
+ fprintf(stderr, "vbutil_key: Error writing key copy.\n");
+ Free(privkey);
+ return 1;
+ }
+ }
Free(privkey);
return 0;
}
-
- /* TODO: write key data, if any */
-
error("Unable to parse either .vbpubk or vbprivk from %s\n", infile);
return 1;
}
@@ -194,6 +222,10 @@ int main(int argc, char* argv[]) {
mode = i;
infile = optarg;
break;
+
+ case OPT_COPYTO:
+ outfile = optarg;
+ break;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698