| OLD | NEW |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 * | 4 * |
| 5 * Verified boot key utility | 5 * Verified boot key utility |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <getopt.h> | 8 #include <getopt.h> |
| 9 #include <inttypes.h> /* For PRIu64 */ | 9 #include <inttypes.h> /* For PRIu64 */ |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 Free(privkey); | 102 Free(privkey); |
| 103 return 0; | 103 return 0; |
| 104 } | 104 } |
| 105 | 105 |
| 106 error("Unable to parse either .keyb or .pem from %s\n", infile); | 106 error("Unable to parse either .keyb or .pem from %s\n", infile); |
| 107 return 1; | 107 return 1; |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 |
| 111 static void PrintDigest(const uint8_t* buf, uint64_t buflen) { | |
| 112 uint8_t *digest = DigestBuf(buf, buflen, SHA1_DIGEST_ALGORITHM); | |
| 113 int i; | |
| 114 for (i=0; i<SHA1_DIGEST_SIZE; i++) | |
| 115 printf("%02x", digest[i]); | |
| 116 printf("\n"); | |
| 117 Free(digest); | |
| 118 } | |
| 119 | |
| 120 /* Unpack a .vbpubk or .vbprivk */ | 111 /* Unpack a .vbpubk or .vbprivk */ |
| 121 static int Unpack(const char *infile, const char *outfile) { | 112 static int Unpack(const char *infile, const char *outfile) { |
| 122 VbPublicKey* pubkey; | 113 VbPublicKey* pubkey; |
| 123 VbPrivateKey* privkey; | 114 VbPrivateKey* privkey; |
| 124 | 115 |
| 125 if (!infile) { | 116 if (!infile) { |
| 126 fprintf(stderr, "Need file to unpack\n"); | 117 fprintf(stderr, "Need file to unpack\n"); |
| 127 return 1; | 118 return 1; |
| 128 } | 119 } |
| 129 | 120 |
| 130 if ((pubkey = PublicKeyRead(infile))) { | 121 if ((pubkey = PublicKeyRead(infile))) { |
| 131 printf("Public Key file: %s\n", infile); | 122 printf("Public Key file: %s\n", infile); |
| 132 printf("Algorithm: %" PRIu64 " %s\n", pubkey->algorithm, | 123 printf("Algorithm: %" PRIu64 " %s\n", pubkey->algorithm, |
| 133 (pubkey->algorithm < kNumAlgorithms ? | 124 (pubkey->algorithm < kNumAlgorithms ? |
| 134 algo_strings[pubkey->algorithm] : "(invalid)")); | 125 algo_strings[pubkey->algorithm] : "(invalid)")); |
| 135 printf("Key Version: %" PRIu64 "\n", pubkey->key_version); | 126 printf("Key Version: %" PRIu64 "\n", pubkey->key_version); |
| 136 printf("Key sha1sum: "); | 127 printf("Key sha1sum: "); |
| 137 PrintDigest(((uint8_t *)pubkey) + pubkey->key_offset, pubkey->key_size); | 128 PrintPubKeySha1Sum(pubkey); |
| 129 printf("\n"); |
| 138 if (outfile) { | 130 if (outfile) { |
| 139 if (0 != PublicKeyWrite(outfile, pubkey)) { | 131 if (0 != PublicKeyWrite(outfile, pubkey)) { |
| 140 fprintf(stderr, "vbutil_key: Error writing key copy.\n"); | 132 fprintf(stderr, "vbutil_key: Error writing key copy.\n"); |
| 141 Free(pubkey); | 133 Free(pubkey); |
| 142 return 1; | 134 return 1; |
| 143 } | 135 } |
| 144 } | 136 } |
| 145 Free(pubkey); | 137 Free(pubkey); |
| 146 return 0; | 138 return 0; |
| 147 } | 139 } |
| 148 | 140 |
| 149 | |
| 150 if ((privkey = PrivateKeyRead(infile))) { | 141 if ((privkey = PrivateKeyRead(infile))) { |
| 151 printf("Private Key file: %s\n", infile); | 142 printf("Private Key file: %s\n", infile); |
| 152 printf("Algorithm: %" PRIu64 " %s\n", privkey->algorithm, | 143 printf("Algorithm: %" PRIu64 " %s\n", privkey->algorithm, |
| 153 (privkey->algorithm < kNumAlgorithms ? | 144 (privkey->algorithm < kNumAlgorithms ? |
| 154 algo_strings[privkey->algorithm] : "(invalid)")); | 145 algo_strings[privkey->algorithm] : "(invalid)")); |
| 155 if (outfile) { | 146 if (outfile) { |
| 156 if (0 != PrivateKeyWrite(outfile, privkey)) { | 147 if (0 != PrivateKeyWrite(outfile, privkey)) { |
| 157 fprintf(stderr, "vbutil_key: Error writing key copy.\n"); | 148 fprintf(stderr, "vbutil_key: Error writing key copy.\n"); |
| 158 Free(privkey); | 149 Free(privkey); |
| 159 return 1; | 150 return 1; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 switch(mode) { | 226 switch(mode) { |
| 236 case OPT_MODE_PACK: | 227 case OPT_MODE_PACK: |
| 237 return Pack(infile, outfile, algorithm, version); | 228 return Pack(infile, outfile, algorithm, version); |
| 238 case OPT_MODE_UNPACK: | 229 case OPT_MODE_UNPACK: |
| 239 return Unpack(infile, outfile); | 230 return Unpack(infile, outfile); |
| 240 default: | 231 default: |
| 241 printf("Must specify a mode.\n"); | 232 printf("Must specify a mode.\n"); |
| 242 return PrintHelp(progname); | 233 return PrintHelp(progname); |
| 243 } | 234 } |
| 244 } | 235 } |
| OLD | NEW |