3 # Copyright (c) 2013, Google Inc.
5 # Simple Verified Boot Test Script
7 # SPDX-License-Identifier: GPL-2.0+
11 # Run U-Boot and report the result
15 echo -n "Test Verified Boot Run: $1: "
16 ${uboot} -d sandbox-u-boot.dtb >${tmp} -c '
17 sb load host 0 100 test.fit;
21 if ! grep -q "$2" ${tmp}; then
23 echo "Verified boot key check failed, output follows:"
31 echo "Simple Verified Boot Test"
32 echo "========================="
34 echo "Please see doc/uImage.FIT/verified-boot.txt for more information"
38 tmp=/tmp/vboot_test.$$
47 dtc="-I dts -O dtb -p 2000"
49 mkimage="${O}/tools/mkimage"
50 keys="${dir}/dev-keys"
51 echo ${mkimage} -D "${dtc}"
56 # Create an RSA key pair
57 openssl genrsa -F4 -out ${keys}/dev.key 2048 2>/dev/null
59 # Create a certificate containing the public key
60 openssl req -batch -new -x509 -key ${keys}/dev.key -out ${keys}/dev.crt
62 pushd ${dir} >/dev/null
66 # Compile our device tree files for kernel and U-Boot
67 dtc -p 0x1000 sandbox-kernel.dts -O dtb -o sandbox-kernel.dtb
68 dtc -p 0x1000 sandbox-u-boot.dts -O dtb -o sandbox-u-boot.dtb
70 # Create a number kernel image with zeroes
71 head -c 5000 /dev/zero >test-kernel.bin
73 # Build the FIT, but don't sign anything yet
74 echo Build FIT with signed images
75 ${mkimage} -D "${dtc}" -f sign-images-$sha.its test.fit >${tmp}
77 run_uboot "unsigned signatures:" "dev-"
79 # Sign images with our dev keys
81 ${mkimage} -D "${dtc}" -F -k dev-keys -K sandbox-u-boot.dtb \
84 run_uboot "signed images" "dev+"
87 # Create a fresh .dtb without the public keys
88 dtc -p 0x1000 sandbox-u-boot.dts -O dtb -o sandbox-u-boot.dtb
90 echo Build FIT with signed configuration
91 ${mkimage} -D "${dtc}" -f sign-configs-$sha.its test.fit >${tmp}
93 run_uboot "unsigned config" $sha"+ OK"
95 # Sign images with our dev keys
97 ${mkimage} -D "${dtc}" -F -k dev-keys -K sandbox-u-boot.dtb \
100 run_uboot "signed config" "dev+"
102 # Increment the first byte of the signature, which should cause failure
103 sig=$(fdtget -t bx test.fit /configurations/conf@1/signature@1 value)
104 newbyte=$(printf %x $((0x${sig:0:2} + 1)))
105 sig="${newbyte} ${sig:2}"
106 fdtput -t bx test.fit /configurations/conf@1/signature@1 value ${sig}
108 run_uboot "signed config with bad hash" "Bad Data Hash"