author | Mingyen Hung <mingyen.hung@amlogic.com> | 2019-08-29 04:19:56 (GMT) |
---|---|---|
committer | Tellen Yu <tellen.yu@amlogic.com> | 2019-09-11 14:02:15 (GMT) |
commit | 2e250deaf3af165283daa265024c8c4b2b49897f (patch) | |
tree | 31156d6a91436ebbcf17935c5bee123f02f487dd | |
parent | 9425e79cf17eb8729a384e7815e12e2e185c6133 (diff) | |
download | uboot-2e250deaf3af165283daa265024c8c4b2b49897f.zip uboot-2e250deaf3af165283daa265024c8c4b2b49897f.tar.gz uboot-2e250deaf3af165283daa265024c8c4b2b49897f.tar.bz2 |
keymaster 4: Porting Trusty keymaster4 to Amlogic [3/3]
PD#SWPL-12543
Problem:
Need to add support of keymaster 4 for Android Q
Solution:
Calculate hash of public key in vbmeta(boot key) and
pass it to kernel
Verify:
Android Q + Franklin
Change-Id: Ib71c7d3d9386f08caee4205de6c4bd5e99ca40f3
Signed-off-by: Mingyen Hung <mingyen.hung@amlogic.com>
-rw-r--r-- | include/libavb/avb_slot_verify.h | 2 | ||||
-rw-r--r-- | lib/libavb/avb_cmdline.c | 8 | ||||
-rw-r--r-- | lib/libavb/avb_slot_verify.c | 13 |
3 files changed, 21 insertions, 2 deletions
diff --git a/include/libavb/avb_slot_verify.h b/include/libavb/avb_slot_verify.h index 24acf1f..e8c733c 100644 --- a/include/libavb/avb_slot_verify.h +++ b/include/libavb/avb_slot_verify.h @@ -31,7 +31,6 @@ #include "avb_ops.h" #include "avb_vbmeta_image.h" - #ifdef __cplusplus extern "C" { #endif @@ -258,6 +257,7 @@ typedef struct { size_t num_loaded_partitions; char* cmdline; uint64_t rollback_indexes[AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_LOCATIONS]; + uint8_t boot_key_hash[AVB_SHA256_DIGEST_SIZE]; } AvbSlotVerifyData; /* Frees a |AvbSlotVerifyData| including all data it points to. */ diff --git a/lib/libavb/avb_cmdline.c b/lib/libavb/avb_cmdline.c index 9627d1b..5831a8e 100644 --- a/lib/libavb/avb_cmdline.c +++ b/lib/libavb/avb_cmdline.c @@ -370,6 +370,14 @@ AvbSlotVerifyResult avb_append_options( goto out; } + if (!cmdline_append_hex(slot_data, + "androidboot.vbmeta.bootkey_hash", + slot_data->boot_key_hash, + AVB_SHA256_DIGEST_SIZE)) { + ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM; + goto out; + } + ret = AVB_SLOT_VERIFY_RESULT_OK; out: diff --git a/lib/libavb/avb_slot_verify.c b/lib/libavb/avb_slot_verify.c index 1e91dda..6b81fae 100644 --- a/lib/libavb/avb_slot_verify.c +++ b/lib/libavb/avb_slot_verify.c @@ -488,6 +488,7 @@ static AvbSlotVerifyResult load_and_verify_vbmeta( bool is_main_vbmeta; bool is_vbmeta_partition; AvbVBMetaData* vbmeta_image_data = NULL; + bool out_is_unlocked = 0; ret = AVB_SLOT_VERIFY_RESULT_OK; @@ -624,8 +625,18 @@ static AvbSlotVerifyResult load_and_verify_vbmeta( switch (vbmeta_ret) { case AVB_VBMETA_VERIFY_RESULT_OK: avb_assert(pk_data != NULL && pk_len > 0); - break; + io_ret = ops->read_is_device_unlocked(ops, &out_is_unlocked); + /* Only calculate hash for successful and locked case */ + if (io_ret == AVB_IO_RESULT_OK && !out_is_unlocked) { + AvbSHA256Ctx boot_key_sha256_ctx; + avb_sha256_init(&boot_key_sha256_ctx); + avb_sha256_update(&boot_key_sha256_ctx, pk_data, pk_len); + avb_memcpy(slot_data->boot_key_hash, + avb_sha256_final(&boot_key_sha256_ctx), + AVB_SHA256_DIGEST_SIZE); + } + break; case AVB_VBMETA_VERIFY_RESULT_OK_NOT_SIGNED: case AVB_VBMETA_VERIFY_RESULT_HASH_MISMATCH: case AVB_VBMETA_VERIFY_RESULT_SIGNATURE_MISMATCH: |