Add script from @jcadduono for encryption
authorSimon Sickle <simon@simonsickle.com>
Sat, 25 Nov 2017 02:38:21 +0000 (20:38 -0600)
committerSimon Sickle <simon@simonsickle.com>
Sat, 25 Nov 2017 02:38:21 +0000 (20:38 -0600)
https://github.com/TeamWin/android_device_oneplus_oneplus3/blob/android-6.0/recovery/root/sbin/setup_decrypt
Signed-off-by: Simon Sickle <simon@simonsickle.com>
recovery/root/init.recovery.qcom.rc
recovery/root/sbin/setup_decrypt [new file with mode: 0644]

index 8a5092ecbd0ce1dda63c7aec173904e2cbcbc946..95c4e7661f0bdcf07f2e1bace5d9da12444c27bb 100644 (file)
 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-on fs
-    wait /dev/block/platform/soc/1da4000.ufshc
-    symlink /dev/block/platform/soc/1da4000.ufshc /dev/block/bootdevice
+# encryption support
+on init
     chmod 0660 /dev/qseecom
     chown system drmrpc /dev/qseecom
     chmod 0664 /dev/ion
     chown system system /dev/ion
+
+on early-fs
+    start setup-decrypt
+
+on fs
+    wait /dev/block/platform/soc/1da4000.ufshc
+    symlink /dev/block/platform/soc/1da4000.ufshc /dev/block/bootdevice
     install_keyring
 
-# Separate copy needed to use /sbin/linker64 instead of /system/bin/linker64
-service sbinqseecomd /sbin/qseecomd
+on property:ro.crypto.state=encrypted
+    start qseecomd
+
+# use decryption libraries from /system if available
+service setup-decrypt /sbin/setup_decrypt
+    oneshot
+    disabled
+    user root
+    group root
+    seclabel u:r:recovery:s0
+
+# use decryption libraries from /system if available
+service setup-decrypt /sbin/setup_decrypt
+    oneshot
     disabled
     user root
     group root
     seclabel u:r:recovery:s0
 
-on boot
-    start sbinqseecomd
diff --git a/recovery/root/sbin/setup_decrypt b/recovery/root/sbin/setup_decrypt
new file mode 100644 (file)
index 0000000..4c0329e
--- /dev/null
@@ -0,0 +1,89 @@
+#!/sbin/sh
+
+log() {
+       echo "$*"
+       (echo "setup_decrypt: $*" > /dev/kmsg) 2> /dev/null
+}
+
+abort() {
+       log "Error: $*"
+       setprop ro.crypto.using_system_libs 0
+       exit 1
+}
+
+restart_crypto() {
+       crypto_state=$(getprop ro.crypto.state)
+       qsee_state=$(getprop init.svc.qseecomd)
+
+       [ "$qsee_state" = "running" ] && {
+               log "Stopping qseecomd"
+               stop qseecomd
+       }
+       [ "$crypto_state" = "encrypted" ] && {
+               log "Starting qseecomd"
+               start qseecomd
+       }
+}
+
+mountpoint -q /system || {
+       mkdir -p /system
+       log "Mounting /system read-only"
+       mount -t ext4 -o ro /dev/block/bootdevice/by-name/system /system
+}
+mountpoint -q /system || abort "Could not mount /system for crypto libs!"
+
+bin=/system/bin
+lib=/system/vendor/lib64
+hw=$lib/hw
+
+ready=true
+
+for f in \
+       "$bin/qseecomd" \
+       "$hw/keystore.msm8998.so" \
+       "$lib/libQSEEComAPI.so" \
+       "$lib/libdiag.so" \
+       "$lib/libdrmfs.so" \
+       "$lib/libdrmtime.so" \
+       "$lib/librpmb.so" \
+       "$lib/libssd.so" \
+       "$lib/libtime_genoff.so"
+do
+       [ -f "$f" ] && continue
+
+       log "Could not find crypto file: $f"
+       ready=false
+done
+
+$ready || abort "Missing one or more decryption libraries!"
+
+mkdir -p /vendor/lib64/hw/
+
+log "Copying decryption libraries from /system"
+cp -f \
+       "$bin/qseecomd" \
+       "$hw/keystore.msm8998.so" \
+       "$lib/libQSEEComAPI.so" \
+       "$lib/libdiag.so" \
+       "$lib/libdrmfs.so" \
+       "$lib/libdrmtime.so" \
+       "$lib/librpmb.so" \
+       "$lib/libssd.so" \
+       "$lib/libtime_genoff.so" \
+       /sbin/
+
+cp -f "$hw/keystore.msm8998.so" /vendor/lib64/hw/
+cp -f "$lib/libQSEEComAPI.so"   /vendor/lib64/
+
+chmod 0750 /sbin/qseecomd
+
+# we have to link qseecomd to /sbin/linker64 because /system is unmounted when it starts
+sed -i "s|/system/bin/linker|///////sbin/linker|" /sbin/qseecomd
+
+setprop ro.crypto.using_system_libs 1
+
+log "Using system decryption libraries!"
+
+restart_crypto
+
+exit 0