-
Notifications
You must be signed in to change notification settings - Fork 3
Fuse key verification #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
m-iwanicki
wants to merge
6
commits into
main
Choose a base branch
from
fuse-key-verification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8d136d2
dts-boot & dts-profile: move path exports to dts-profile
m-iwanicki 84a9a50
dts-profile: set ERR_LOG_FILE to '/dev/null'
m-iwanicki 359fb05
btg_key_validator: Parse arguments, add error checks
m-iwanicki ac591c3
dasharo-deploy: fuse_workflow: add btg signature verification
m-iwanicki 6eadecd
common-mock-func: add cap_upd_tool_mock, it shouldn't print anything
m-iwanicki db6ad78
dasharo-deploy & btg_key_validator: reword error messages
m-iwanicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,95 @@ | ||
| #!/bin/bash | ||
|
|
||
| ncm_mtl_key=e64b6b0e82c68fecc58f750d3696c26e1c98bf9e3149c81f3b2ed775eb9d2c157a99c103c62c44c0cdc61be971caeae1 | ||
| # shellcheck source=../include/dts-environment.sh | ||
| source "$DTS_ENV" | ||
| # shellcheck source=../include/dts-functions.sh | ||
| source "$DTS_FUNCS" | ||
|
|
||
| rom=flashdump.bin | ||
| print_help() { | ||
| cat <<EOF | ||
| $(basename "$0") [OPTION]... | ||
|
|
||
| echo "Reading flash..." | ||
| flashrom -p internal --ifd -i bios -i me -i fd -r $rom >/dev/null 2>&1 | ||
| Script that allows for verification whether firmware binary is signed with correct keys. | ||
| Options: | ||
| -f|--file <file> Path to firmware file for which to check key hash. | ||
| -k|--key-hash <hash> Expected key hash | ||
| -v|--verbose Enable trace output | ||
| -h|--help Print this help | ||
| EOF | ||
| } | ||
|
|
||
| parse_args() { | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| -v | --verbose) | ||
| set -x | ||
| shift | ||
| ;; | ||
| -h | --help) | ||
| print_help | ||
| exit 0 | ||
| ;; | ||
| -f | --file) | ||
| if [ ! -f "$2" ]; then | ||
| error_exit "File '$2' doesn't exist" | ||
| fi | ||
| rom="$2" | ||
| shift 2 | ||
| ;; | ||
| -k | --key-hash) | ||
| if [ -z "$2" ]; then | ||
| error_exit "--key-hash argument cannot be empty" | ||
| fi | ||
| expected_hash="$2" | ||
| shift 2 | ||
| ;; | ||
| -*) | ||
| print_help | ||
| error_exit "Unknown option $1" | ||
| ;; | ||
| *) | ||
| print_usage | ||
| error_exit "Script doesn't accept any positional arguments, but got $#" | ||
| ;; | ||
| esac | ||
| done | ||
| } | ||
|
|
||
| expected_hash= | ||
| rom="flashdump.bin" | ||
|
|
||
| parse_args "$@" | ||
|
|
||
| if [ -z "$expected_hash" ]; then | ||
| board_config | ||
| error_check "Failed to download board configuration." | ||
| if [ -z "$INTEL_BTG_HASH" ]; then | ||
| error_exit "Platform configuration is missing expected key hash. | ||
| The most likely reason is that there is no fusing binary for your platform." | ||
| fi | ||
| expected_hash="$INTEL_BTG_HASH" | ||
| fi | ||
| if [ ! -f "$rom" ]; then | ||
| echo "Reading flash..." | ||
| $FLASHROM -p "$PROGRAMMER_BIOS" --ifd -i bios -i me -i fd -r "${rom}" >>"$FLASHROM_LOG_FILE" 2>>"$ERR_LOG_FILE" | ||
| error_check "Failed to read flash" | ||
| fi | ||
|
|
||
| echo "Extracting key manifest..." | ||
| bg-prov km-export $rom km.bin >/dev/null | ||
| bg-prov km-export "${rom}" km.bin 2>>"$ERR_LOG_FILE" >&2 | ||
| error_check "Failed to export key manifest." | ||
|
|
||
| modulus=$(bg-prov km-show km.bin | grep "Key And Signature" -A 8 | grep Data | cut -d ' ' -f 10 | tail -c +11) | ||
| exponent=01000100 | ||
|
|
||
| echo $modulus$exponent | awk '{gsub(/.{2}/,"& ")}1' | xxd -r -p | sha384sum | grep -q $ncm_mtl_key | ||
| fw_key_hash="$(echo "$modulus$exponent" | awk '{gsub(/.{2}/,"& ")}1' | xxd -r -p | sha384sum | awk '{print $1}')" | ||
|
|
||
| if [ $? -eq 0 ]; then | ||
| echo "Key matches NovaCustom Meteor Lake signing key." | ||
| if grep -q "${expected_hash}" <<<"${fw_key_hash}"; then | ||
| echo_green "Firmware is signed with expected key hash:" | ||
| echo_green " ${expected_hash}" | ||
| else | ||
| echo "Key does not match NovaCustom Meteor Lake signing key!" | ||
| echo_red "Firmware signature doesn't match expected hash:" | ||
| echo_red " Expected: ${expected_hash}" | ||
| echo_red " Signed : ${fw_key_hash}" | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.