blob: 65f77f401cc71ff10a44a7383c4581f0e7faef4f [file] [log] [blame]
Doug Zongker73ae31c2009-12-09 17:01:45 -08001#!/bin/bash
2#
Doug Zongker28ce47c2011-10-28 10:33:05 -07003# A test suite for recovery's package signature verifier. Run in a
4# client where you have done envsetup, lunch, etc.
Doug Zongker73ae31c2009-12-09 17:01:45 -08005#
6# TODO: find some way to get this run regularly along with the rest of
7# the tests.
8
9EMULATOR_PORT=5580
10DATA_DIR=$ANDROID_BUILD_TOP/bootable/recovery/testdata
11
12WORK_DIR=/data/local/tmp
13
14# set to 0 to use a device instead
15USE_EMULATOR=0
16
17# ------------------------
18
19if [ "$USE_EMULATOR" == 1 ]; then
20 emulator -wipe-data -noaudio -no-window -port $EMULATOR_PORT &
21 pid_emulator=$!
22 ADB="adb -s emulator-$EMULATOR_PORT "
23else
24 ADB="adb -d "
25fi
26
27echo "waiting to connect to device"
28$ADB wait-for-device
29
30# run a command on the device; exit with the exit status of the device
31# command.
32run_command() {
33 $ADB shell "$@" \; echo \$? | awk '{if (b) {print a}; a=$0; b=1} END {exit a}'
34}
35
36testname() {
37 echo
38 echo "::: testing $1 :::"
39 testname="$1"
40}
41
42fail() {
43 echo
44 echo FAIL: $testname
45 echo
46 [ "$open_pid" == "" ] || kill $open_pid
47 [ "$pid_emulator" == "" ] || kill $pid_emulator
48 exit 1
49}
50
51
52cleanup() {
53 # not necessary if we're about to kill the emulator, but nice for
54 # running on real devices or already-running emulators.
55 run_command rm $WORK_DIR/verifier_test
56 run_command rm $WORK_DIR/package.zip
57
58 [ "$pid_emulator" == "" ] || kill $pid_emulator
59}
60
61$ADB push $ANDROID_PRODUCT_OUT/system/bin/verifier_test \
62 $WORK_DIR/verifier_test
63
64expect_succeed() {
65 testname "$1 (should succeed)"
66 $ADB push $DATA_DIR/$1 $WORK_DIR/package.zip
Doug Zongkerbac7fba2013-04-10 11:32:17 -070067 shift
68 run_command $WORK_DIR/verifier_test "$@" $WORK_DIR/package.zip || fail
Doug Zongker73ae31c2009-12-09 17:01:45 -080069}
70
71expect_fail() {
72 testname "$1 (should fail)"
73 $ADB push $DATA_DIR/$1 $WORK_DIR/package.zip
Doug Zongkerbac7fba2013-04-10 11:32:17 -070074 shift
75 run_command $WORK_DIR/verifier_test "$@" $WORK_DIR/package.zip && fail
Doug Zongker73ae31c2009-12-09 17:01:45 -080076}
77
Doug Zongkerbac7fba2013-04-10 11:32:17 -070078# not signed at all
Doug Zongker73ae31c2009-12-09 17:01:45 -080079expect_fail unsigned.zip
Doug Zongkerbac7fba2013-04-10 11:32:17 -070080# signed in the pre-donut way
Doug Zongker73ae31c2009-12-09 17:01:45 -080081expect_fail jarsigned.zip
Doug Zongkerbac7fba2013-04-10 11:32:17 -070082
83# success cases
Doug Zongker73ae31c2009-12-09 17:01:45 -080084expect_succeed otasigned.zip
Doug Zongkerbac7fba2013-04-10 11:32:17 -070085expect_succeed otasigned_f4.zip -f4
86expect_succeed otasigned_sha256.zip -sha256
87expect_succeed otasigned_f4_sha256.zip -sha256 -f4
88
89# verified against different key
90expect_fail otasigned.zip -f4
Doug Zongker17495272012-07-25 13:10:58 -070091expect_fail otasigned_f4.zip
Doug Zongkerbac7fba2013-04-10 11:32:17 -070092
93# verified against right key but wrong hash algorithm
94expect_fail otasigned.zip -sha256
95expect_fail otasigned_f4.zip -sha256 -f4
96expect_fail otasigned_sha256.zip
97expect_fail otasigned_f4_sha256.zip -f4
98
99# various other cases
Doug Zongker73ae31c2009-12-09 17:01:45 -0800100expect_fail random.zip
101expect_fail fake-eocd.zip
102expect_fail alter-metadata.zip
103expect_fail alter-footer.zip
104
105# --------------- cleanup ----------------------
106
107cleanup
108
109echo
110echo PASS
111echo