OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Run verified boot firmware and kernel verification tests. | 7 # Run verified boot firmware and kernel verification tests. |
8 | 8 |
| 9 # Load common constants and variables. |
| 10 . "$(dirname "$0")/common.sh" |
| 11 |
9 return_code=0 | 12 return_code=0 |
10 hash_algos=( sha1 sha256 sha512 ) | |
11 key_lengths=( 1024 2048 4096 8192 ) | |
12 TEST_FILE=test_file | |
13 TEST_FILE_SIZE=1000000 | |
14 | |
15 COL_RED='\E[31;1m' | |
16 COL_GREEN='\E[32;1m' | |
17 COL_YELLOW='\E[33;1m' | |
18 COL_BLUE='\E[34;1m' | |
19 COL_STOP='\E[0;m' | |
20 | 13 |
21 function test_firmware_verification { | 14 function test_firmware_verification { |
22 algorithmcounter=0 | 15 algorithmcounter=0 |
23 for keylen in ${key_lengths[@]} | 16 for keylen in ${key_lengths[@]} |
24 do | 17 do |
25 for hashalgo in ${hash_algos[@]} | 18 for hashalgo in ${hash_algos[@]} |
26 do | 19 do |
27 echo -e "For Root key ${COL_YELLOW}RSA-$keylen/$hashalgo${COL_STOP}:" | 20 echo -e "For Root key ${COL_YELLOW}RSA-$keylen/$hashalgo${COL_STOP}:" |
28 cd ${UTIL_DIR} && ${TEST_DIR}/firmware_image_tests $algorithmcounter \ | 21 cd ${UTIL_DIR} && ${TEST_DIR}/firmware_image_tests $algorithmcounter \ |
29 ${TEST_DIR}/testkeys/key_rsa8192.pem \ | 22 ${TESTKEY_DIR}/key_rsa8192.pem \ |
30 ${TEST_DIR}/testkeys/key_rsa8192.keyb \ | 23 ${TESTKEY_DIR}/key_rsa8192.keyb \ |
31 ${TEST_DIR}/testkeys/key_rsa${keylen}.pem \ | 24 ${TESTKEY_DIR}/key_rsa${keylen}.pem \ |
32 ${TEST_DIR}/testkeys/key_rsa${keylen}.keyb | 25 ${TESTKEY_DIR}/key_rsa${keylen}.keyb |
33 if [ $? -ne 0 ] | 26 if [ $? -ne 0 ] |
34 then | 27 then |
35 return_code=255 | 28 return_code=255 |
36 fi | 29 fi |
37 let algorithmcounter=algorithmcounter+1 | 30 let algorithmcounter=algorithmcounter+1 |
38 done | 31 done |
39 done | 32 done |
40 } | 33 } |
41 | 34 |
42 function test_kernel_verification { | 35 function test_kernel_verification { |
43 # Test for various combinations of firmware signing algorithm and | 36 # Test for various combinations of firmware signing algorithm and |
44 # kernel signing algorithm | 37 # kernel signing algorithm |
45 firmware_algorithmcounter=0 | 38 firmware_algorithmcounter=0 |
46 kernel_algorithmcounter=0 | 39 kernel_algorithmcounter=0 |
47 for firmware_keylen in ${key_lengths[@]} | 40 for firmware_keylen in ${key_lengths[@]} |
48 do | 41 do |
49 for firmware_hashalgo in ${hash_algos[@]} | 42 for firmware_hashalgo in ${hash_algos[@]} |
50 do | 43 do |
51 let kernel_algorithmcounter=0 | 44 let kernel_algorithmcounter=0 |
52 for kernel_keylen in ${key_lengths[@]} | 45 for kernel_keylen in ${key_lengths[@]} |
53 do | 46 do |
54 for kernel_hashalgo in ${hash_algos[@]} | 47 for kernel_hashalgo in ${hash_algos[@]} |
55 do | 48 do |
56 echo -e "For ${COL_YELLOW}Firmware signing algorithm \ | 49 echo -e "For ${COL_YELLOW}Firmware signing algorithm \ |
57 RSA-${firmware_keylen}/${firmware_hashalgo}${COL_STOP} \ | 50 RSA-${firmware_keylen}/${firmware_hashalgo}${COL_STOP} \ |
58 and ${COL_YELLOW}Kernel signing algorithm RSA-${kernel_keylen}/\ | 51 and ${COL_YELLOW}Kernel signing algorithm RSA-${kernel_keylen}/\ |
59 ${kernel_hashalgo}${COL_STOP}" | 52 ${kernel_hashalgo}${COL_STOP}" |
60 cd ${UTIL_DIR} && ${TEST_DIR}/kernel_image_tests \ | 53 cd ${UTIL_DIR} && ${TEST_DIR}/kernel_image_tests \ |
61 $firmware_algorithmcounter $kernel_algorithmcounter \ | 54 $firmware_algorithmcounter $kernel_algorithmcounter \ |
62 ${TEST_DIR}/testkeys/key_rsa${firmware_keylen}.pem \ | 55 ${TESTKEY_DIR}/key_rsa${firmware_keylen}.pem \ |
63 ${TEST_DIR}/testkeys/key_rsa${firmware_keylen}.keyb \ | 56 ${TESTKEY_DIR}/key_rsa${firmware_keylen}.keyb \ |
64 ${TEST_DIR}/testkeys/key_rsa${kernel_keylen}.pem \ | 57 ${TESTKEY_DIR}/key_rsa${kernel_keylen}.pem \ |
65 ${TEST_DIR}/testkeys/key_rsa${kernel_keylen}.keyb | 58 ${TESTKEY_DIR}/key_rsa${kernel_keylen}.keyb |
66 if [ $? -ne 0 ] | 59 if [ $? -ne 0 ] |
67 then | 60 then |
68 return_code=255 | 61 return_code=255 |
69 fi | 62 fi |
70 let kernel_algorithmcounter=kernel_algorithmcounter+1 | 63 let kernel_algorithmcounter=kernel_algorithmcounter+1 |
71 done | 64 done |
72 done | 65 done |
73 let firmware_algorithmcounter=firmware_algorithmcounter+1 | 66 let firmware_algorithmcounter=firmware_algorithmcounter+1 |
74 done | 67 done |
75 done | 68 done |
76 } | 69 } |
77 | 70 |
78 # Determine script directory. | 71 check_test_keys |
79 if [[ $0 == '/'* ]]; | |
80 then | |
81 SCRIPT_DIR="`dirname $0`" | |
82 elif [[ $0 == './'* ]]; | |
83 then | |
84 SCRIPT_DIR="`pwd`" | |
85 else | |
86 SCRIPT_DIR="`pwd`"/"`dirname $0`" | |
87 fi | |
88 UTIL_DIR=`dirname ${SCRIPT_DIR}`/utils | |
89 KEY_DIR=${SCRIPT_DIR}/testkeys | |
90 TEST_DIR=${SCRIPT_DIR}/ | |
91 | |
92 echo | 72 echo |
93 echo "Testing high-level firmware image verification..." | 73 echo "Testing high-level firmware image verification..." |
94 test_firmware_verification | 74 test_firmware_verification |
95 | 75 |
96 echo | 76 echo |
97 echo "Testing high-level kernel image verification..." | 77 echo "Testing high-level kernel image verification..." |
98 test_kernel_verification | 78 test_kernel_verification |
99 | 79 |
100 exit $return_code | 80 exit $return_code |
OLD | NEW |