blob: aba53b01f6873b35b7eb8b930aebc0d40d958da5 [file] [log] [blame]
Ricardo Cerqueiraaff5e542014-05-09 22:24:12 +01001#!/sbin/sh
2
3# Validate that the incoming OTA is compatible with an already-installed
4# system
5
Brint E. Kriebel84ec9f52014-09-24 12:46:09 -07006grep -q "Command:.*\"--wipe\_data\"" /tmp/recovery.log
7if [ $? -eq 0 ]; then
8 echo "Data will be wiped after install; skipping signature check..."
9 exit 0
10fi
11
Brint E. Kriebel1d055a32014-11-28 17:39:21 -080012grep -q "Command:.*\"--headless\"" /tmp/recovery.log
13if [ $? -eq 0 ]; then
14 echo "Headless mode install; skipping signature check..."
15 exit 0
16fi
17
Tom Marshall322cc5a2015-12-02 13:24:54 -080018if [ -f "/data/system/packages.xml" -a -f "/tmp/releasekey" ]; then
19 relkey=$(cat "/tmp/releasekey")
20 OLDIFS="$IFS"
21 IFS=""
22 while read line; do
Tom Marshall139e7982015-12-18 14:45:25 -080023 if [ "${#line}" -gt 4094 ]; then
24 continue
25 fi
Tom Marshall322cc5a2015-12-02 13:24:54 -080026 params=${line# *<package *}
27 if [ "$line" != "$params" ]; then
28 kvp=${params%% *}
29 params=${params#* }
30 while [ "$kvp" != "$params" ]; do
31 key=${kvp%%=*}
32 val=${kvp#*=}
33 vlen=$(( ${#val} - 2 ))
34 val=${val:1:$vlen}
35 if [ "$key" = "name" ]; then
36 package="$val"
37 fi
38 kvp=${params%% *}
39 params=${params#* }
40 done
41 continue
42 fi
43 params=${line# *<cert *}
44 if [ "$line" != "$params" ]; then
45 keyidx=""
46 keyval=""
47 kvp=${params%% *}
48 params=${params#* }
49 while [ "$kvp" != "$params" ]; do
50 key=${kvp%%=*}
51 val=${kvp#*=}
52 vlen=$(( ${#val} - 2 ))
53 val=${val:1:$vlen}
54 if [ "$key" = "index" ]; then
55 keyidx="$val"
56 fi
57 if [ "$key" = "key" ]; then
58 keyval="$val"
59 fi
60 kvp=${params%% *}
61 params=${params#* }
62 done
63 if [ -n "$keyidx" ]; then
64 if [ "$package" = "com.android.htmlviewer" ]; then
65 cert_idx="$keyidx"
66 fi
67 fi
68 if [ -n "$keyval" ]; then
69 eval "key_$keyidx=$keyval"
70 fi
71 continue
72 fi
73 done < "/data/system/packages.xml"
74 IFS="$OLDIFS"
Ricardo Cerqueiraaff5e542014-05-09 22:24:12 +010075
Ricardo Cerqueirad2248b22014-12-01 15:15:15 +000076 # Tools missing? Err on the side of caution and exit cleanly
Tom Marshall322cc5a2015-12-02 13:24:54 -080077 if [ -z "$cert_idx" ]; then
78 echo "Package cert index not found; skipping signature check..."
79 exit 0
80 fi
Ricardo Cerqueirad2248b22014-12-01 15:15:15 +000081
Tom Marshall322cc5a2015-12-02 13:24:54 -080082 varname="key_$cert_idx"
83 eval "pkgkey=\$$varname"
84
85 if [ "$pkgkey" != "$relkey" ]; then
Ricardo Cerqueiraaff5e542014-05-09 22:24:12 +010086 echo "You have an installed system that isn't signed with this build's key, aborting..."
Ricardo Cerqueirad2248b22014-12-01 15:15:15 +000087 exit 124
Ricardo Cerqueiraaff5e542014-05-09 22:24:12 +010088 fi
89fi
90
91exit 0