mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 17:41:54 +00:00
futility: show .vbprivk files
BUG=none BRANCH=none TEST=make runtests futility show tests/devkeys/*.vbprivk Change-Id: Ic062a193c7ee3d7f9837698e1c8fc6bb1e3d7757 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/245503 Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
committed by
ChromeOS Commit Bot
parent
04d98e399d
commit
4805f1841d
@@ -89,7 +89,7 @@ static void show_keyblock(VbKeyBlockHeader *key_block, const char *name,
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int futil_cb_show_key(struct futil_traverse_state_s *state)
|
||||
int futil_cb_show_pubkey(struct futil_traverse_state_s *state)
|
||||
{
|
||||
VbPublicKey *pubkey = (VbPublicKey *)state->my_area->buf;
|
||||
|
||||
@@ -105,6 +105,24 @@ int futil_cb_show_key(struct futil_traverse_state_s *state)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int futil_cb_show_privkey(struct futil_traverse_state_s *state)
|
||||
{
|
||||
VbPrivateKey key;
|
||||
int alg_okay;
|
||||
|
||||
key.algorithm = *(typeof(key.algorithm) *)state->my_area->buf;
|
||||
|
||||
printf("Private Key file: %s\n", state->in_filename);
|
||||
alg_okay = key.algorithm < kNumAlgorithms;
|
||||
printf(" Algorithm: %" PRIu64 " %s\n", key.algorithm,
|
||||
alg_okay ? algo_strings[key.algorithm] : "(unknown)");
|
||||
|
||||
if (alg_okay)
|
||||
state->my_area->_flags |= AREA_IS_VALID;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int futil_cb_show_gbb(struct futil_traverse_state_s *state)
|
||||
{
|
||||
uint8_t *buf = state->my_area->buf;
|
||||
|
||||
@@ -31,6 +31,7 @@ static const char * const type_strings[] = {
|
||||
"raw firmware",
|
||||
"raw kernel",
|
||||
"chromiumos disk image",
|
||||
"VbPrivateKey",
|
||||
};
|
||||
BUILD_ASSERT(ARRAY_SIZE(type_strings) == NUM_FILE_TYPES);
|
||||
|
||||
@@ -48,6 +49,7 @@ enum futil_file_type (*recognizers[])(uint8_t *buf, uint32_t len) = {
|
||||
&recognize_bios_image,
|
||||
&recognize_gbb,
|
||||
&recognize_vblock1,
|
||||
&recognize_privkey,
|
||||
};
|
||||
|
||||
/* Try to figure out what we're looking at */
|
||||
|
||||
@@ -22,6 +22,7 @@ enum futil_file_type {
|
||||
FILE_TYPE_RAW_KERNEL, /* vmlinuz, *.uimg, etc. */
|
||||
|
||||
FILE_TYPE_CHROMIUMOS_DISK, /* At least it has a GPT */
|
||||
FILE_TYPE_PRIVKEY, /* VbPrivateKey */
|
||||
|
||||
NUM_FILE_TYPES
|
||||
};
|
||||
@@ -46,5 +47,6 @@ enum futil_file_type recognize_bios_image(uint8_t *buf, uint32_t len);
|
||||
enum futil_file_type recognize_gbb(uint8_t *buf, uint32_t len);
|
||||
enum futil_file_type recognize_vblock1(uint8_t *buf, uint32_t len);
|
||||
enum futil_file_type recognize_gpt(uint8_t *buf, uint32_t len);
|
||||
enum futil_file_type recognize_privkey(uint8_t *buf, uint32_t len);
|
||||
|
||||
#endif /* VBOOT_REFERENCE_FUTILITY_FILE_TYPE_H_ */
|
||||
|
||||
@@ -23,13 +23,14 @@ static int (* const cb_show_funcs[])(struct futil_traverse_state_s *state) = {
|
||||
futil_cb_show_fw_preamble, /* CB_FMAP_VBLOCK_B */
|
||||
futil_cb_show_fw_main, /* CB_FMAP_FW_MAIN_A */
|
||||
futil_cb_show_fw_main, /* CB_FMAP_FW_MAIN_B */
|
||||
futil_cb_show_key, /* CB_PUBKEY */
|
||||
futil_cb_show_pubkey, /* CB_PUBKEY */
|
||||
futil_cb_show_keyblock, /* CB_KEYBLOCK */
|
||||
futil_cb_show_gbb, /* CB_GBB */
|
||||
futil_cb_show_fw_preamble, /* CB_FW_PREAMBLE */
|
||||
futil_cb_show_kernel_preamble, /* CB_KERN_PREAMBLE */
|
||||
NULL, /* CB_RAW_FIRMWARE */
|
||||
NULL, /* CB_RAW_KERNEL */
|
||||
futil_cb_show_privkey, /* CB_PRIVKEY */
|
||||
};
|
||||
BUILD_ASSERT(ARRAY_SIZE(cb_show_funcs) == NUM_CB_COMPONENTS);
|
||||
|
||||
@@ -49,6 +50,7 @@ static int (* const cb_sign_funcs[])(struct futil_traverse_state_s *state) = {
|
||||
futil_cb_resign_kernel_part, /* CB_KERN_PREAMBLE */
|
||||
futil_cb_sign_raw_firmware, /* CB_RAW_FIRMWARE */
|
||||
futil_cb_create_kernel_part, /* CB_RAW_KERNEL */
|
||||
NULL, /* CB_PRIVKEY */
|
||||
};
|
||||
BUILD_ASSERT(ARRAY_SIZE(cb_sign_funcs) == NUM_CB_COMPONENTS);
|
||||
|
||||
@@ -77,6 +79,7 @@ static const struct {
|
||||
{CB_RAW_FIRMWARE, "raw firmware"}, /* FILE_TYPE_RAW_FIRMWARE */
|
||||
{CB_RAW_KERNEL, "raw kernel"}, /* FILE_TYPE_RAW_KERNEL */
|
||||
{0, "chromiumos disk"}, /* FILE_TYPE_CHROMIUMOS_DISK */
|
||||
{CB_PRIVKEY, "VbPrivateKey"}, /* FILE_TYPE_PRIVKEY */
|
||||
};
|
||||
BUILD_ASSERT(ARRAY_SIZE(direct_callback) == NUM_FILE_TYPES);
|
||||
|
||||
@@ -148,10 +151,10 @@ static const char * const futil_cb_component_str[] = {
|
||||
"CB_KERN_PREAMBLE",
|
||||
"CB_RAW_FIRMWARE",
|
||||
"CB_RAW_KERNEL",
|
||||
"CB_PRIVKEY",
|
||||
};
|
||||
BUILD_ASSERT(ARRAY_SIZE(futil_cb_component_str) == NUM_CB_COMPONENTS);
|
||||
|
||||
|
||||
static int invoke_callback(struct futil_traverse_state_s *state,
|
||||
enum futil_cb_component c, const char *name,
|
||||
uint32_t offset, uint8_t *buf, uint32_t len)
|
||||
|
||||
@@ -35,6 +35,7 @@ enum futil_cb_component {
|
||||
CB_KERN_PREAMBLE,
|
||||
CB_RAW_FIRMWARE,
|
||||
CB_RAW_KERNEL,
|
||||
CB_PRIVKEY,
|
||||
|
||||
NUM_CB_COMPONENTS
|
||||
};
|
||||
@@ -75,12 +76,13 @@ int futil_traverse(uint8_t *buf, uint32_t len,
|
||||
|
||||
/* These are invoked by the traversal. They also return nonzero on error. */
|
||||
int futil_cb_show_begin(struct futil_traverse_state_s *state);
|
||||
int futil_cb_show_key(struct futil_traverse_state_s *state);
|
||||
int futil_cb_show_pubkey(struct futil_traverse_state_s *state);
|
||||
int futil_cb_show_gbb(struct futil_traverse_state_s *state);
|
||||
int futil_cb_show_keyblock(struct futil_traverse_state_s *state);
|
||||
int futil_cb_show_fw_main(struct futil_traverse_state_s *state);
|
||||
int futil_cb_show_fw_preamble(struct futil_traverse_state_s *state);
|
||||
int futil_cb_show_kernel_preamble(struct futil_traverse_state_s *state);
|
||||
int futil_cb_show_privkey(struct futil_traverse_state_s *state);
|
||||
|
||||
int futil_cb_sign_pubkey(struct futil_traverse_state_s *state);
|
||||
int futil_cb_sign_fw_main(struct futil_traverse_state_s *state);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
#include "file_type.h"
|
||||
#include "futility.h"
|
||||
@@ -737,3 +738,24 @@ enum futil_file_type recognize_vblock1(uint8_t *buf, uint32_t len)
|
||||
|
||||
return FILE_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
enum futil_file_type recognize_privkey(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
VbPrivateKey key;
|
||||
const unsigned char *start;
|
||||
|
||||
if (len < sizeof(key.algorithm))
|
||||
return FILE_TYPE_UNKNOWN;
|
||||
|
||||
key.algorithm = *(typeof(key.algorithm) *)buf;
|
||||
start = buf + sizeof(key.algorithm);
|
||||
key.rsa_private_key = d2i_RSAPrivateKey(NULL, &start,
|
||||
len - sizeof(key.algorithm));
|
||||
|
||||
if (key.rsa_private_key) {
|
||||
RSA_free(key.rsa_private_key);
|
||||
return FILE_TYPE_PRIVKEY;
|
||||
}
|
||||
|
||||
return FILE_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user