Commit Graph

100 Commits

Author SHA1 Message Date
bigbiff
e57d350820 bootctrl: TWRP shouldn't mark slots unbootable
Change-Id: I776916d42927ca5e12c4e6a416cc02d2c84d5cec
2021-08-29 19:46:08 +00:00
Ethan Yonker
deeefbdec4 Stop using boot HAL when decrypting fscrypt
Change-Id: Ia7aaf6b86c5ca456fd6651e776f4d6423b09f02e
2021-08-22 22:47:02 +00:00
bigbiff
bbbfe171f1 fscrypt: updates for wrapped key
- During OTA upgrades if security state or ROT changes then Keymaster
keys requires upgrade. So for such usescases, if the FBE ephemeral
key export fails, check whether KM key requires upgrade and try for
exporting ephemeral key again.

CRs-Fixed: 2632902
Change-Id: I3ee2fcd97a56b628dc4304867c8f2b8da875f883
Signed-off-by: Neeraj Soni <neersoni@codeaurora.org>

- Commit 77df7f2 / http://aosp/1217657 ("Refactor to use
EncryptionPolicy everywhere we used to use raw_ref") unintentionally
made fscrypt_initialize_systemwide_keys() start specifying keepOld=true
(via default parameter value) when retrieving the system DE key, and
likewise for read_or_create_volkey() and volume keys.

As a result, if the associated Keymaster key needs to be upgraded, the
upgraded key blob gets written to "keymaster_key_blob_upgraded", but it
doesn't replace the original "keymaster_key_blob", nor is the original
key deleted from Keymaster.  This happens at every boot, eventually
resulting in the RPMB partition in Keymaster becoming full.

Only the metadata encryption key ever needs keepOld=true, since it's the
only key that isn't stored in /data, and the purpose of keepOld=true is
to allow a key that isn't stored in /data to be committed or rolled back
when a userdata checkpoint is committed or rolled back.

So, fix this bug by removing the default value of keepOld, and
specifying false everywhere except the metadata encryption key.

Note that when an affected device gets this fix, it will finally upgrade
its system DE key correctly.  However, this fix doesn't free up space in
Keymaster that was consumed by this bug.

Test: On bramble:
  - Flashed rvc-d1-dev build, with wiping userdata
  - Flashed a newer build, without wiping userdata
  - Log expectedly shows key upgrades:
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key:
/metadata/vold/metadata_encryption/key
        D vold    : Upgrading key: /data/unencrypted/key
        D vold    : Upgrading key: /data/misc/vold/user_keys/de/0
        D vold    : Upgrading key:
/data/misc/vold/user_keys/ce/0/current
  - Rebooted
  - Log unexpectedly shows the system DE key being upgraded again:
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key: /data/unencrypted/key
  - "keymaster_key_blob_upgraded" unexpectedly still exists:
        $ adb shell find /data /metadata -name
keymaster_key_blob_upgraded
        /data/unencrypted/key/keymaster_key_blob_upgraded
  - Applied this fix and flashed, without wiping userdata
  - Log shows system DE key being upgraded (expected because due to the
    bug, the upgraded key didn't replace the original one before)
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key: /data/unencrypted/key
  - "keymaster_key_blob_upgraded" expectedly no longer exists
        $ adb shell find /data /metadata -name
keymaster_key_blob_upgraded
  - Rebooted
  - Log expectedly doesn't show any more key upgrades
        $ adb logcat | grep 'Upgrading key'
Bug: 171944521
Bug: 172019387
(cherry picked from commit c493903732d0c17b33091cf722cbcc3262292801)
Merged-In: I42d3f5fbe32cb2ec229f4b614cfb271412a3ed29
Change-Id: I42d3f5fbe32cb2ec229f4b614cfb271412a3ed29

Change-Id: I0449b812e91c13020a8b653f2149c33e46027b97
2021-06-25 18:42:20 -04:00
bigbiff
2e344ab7fb fscrypt: integrate v1 processing into TWRP
Change-Id: I3bf9c14b818f9c3e0570c44c82bf0769fcec907f
2021-05-18 20:35:53 -04:00
bigbiff
a957f078be FsCrypt update: support fscrypt policies v1 and v2
This patchset introduces support decryption for Android 11.

In this update we deprecate ext4crypt. To specify the
policy version to use, use TW_USE_FSCRYPT_POLICY := 1 or
TW_USE_FSCRYPT_POLICY := 2. By default policy version will
be set to 2 if this variable is omitted.

Change-Id: I62a29c1bef36c259ec4b11259f71be613d20a112
2021-05-18 20:35:51 -04:00
Peter Cai
8d7d4aed04 cryptfs: add support for keymaster 2
Change-Id: I1c4f06551897c8964ac2d40c9e785d527cc83847
2021-02-15 12:29:07 -05:00
Alexander Sulfrian
8dfcf2a186 Update lock pattern types for android 11
The stored id for the different types of the lock pattern was chnaged
with Android 11. You can find the updated list in the LockPatternUtils:

    https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-11.0.0_r25/core/java/com/android/internal/widget/LockPatternUtils.java#113

It was changed in 5e891bcc04556a3595ab349381acc2a2e36a69d1:

    5e891bcc04

The old CREDENTIAL_TYPE_PASSWORD_OR_PIN was essentialy split in
CREDENTIAL_TYPE_PASSWORD and CREDENTIAL_TYPE_PASSWORD_OR_PIN.

This code updates the matching in twrp, so that the correct unlocking
method for file base decryption can be found. Without these changes twrp
always try to use the default password and obviously fails. With these
changes the usual password dialog is shown and the decryption is
successfully.

Change-Id: Ia8d47223b30a5301d4b9d2230241039612055ebb
Signed-off-by: Alexander Sulfrian <asulfrian@zedat.fu-berlin.de>
Co-authored-by: althafvly <althafvly@gmail.com>
2021-02-15 12:25:16 -05:00
bigbiff
673c7ae01e Merge tag 'android-11.0.0_r16' into android-10.0
Android 11.0.0 release 16 - twrp bringup patch
2020-12-16 19:06:18 -05:00
Noah Jacobson
81d638d235 Add support for multi-user decryption
* Add CLI support using the command "twrp decrypt <PASSWORD> [USER ID]"
* Add GUI support using the menu Advanced --> Decrypt User

multiuser: Parse users only when Decrypt_DE runs successfully

multiuser: Warn when not all users are decrypted

Change-Id: Ia5e943b13c2d5ec5c34ae97661133c19ff471e6d
2020-10-23 00:52:04 +00:00
bigbiff
ad58e1bfae repack: move sbin to /system ramdisk and update repacking
for android-10

This will support updating the ramdisk to a different
compression format and co-exist with magisk.

We are also cleaning up and removing non android-10
api makefile actions.

We are also moving twrp repacking to its own class. We
check the new ramdisk format and if it's different
we have magisk compress using the new ramdisk format.

Change-Id: I770030aae7797e75817178b2f0fccd9f39dc23af
2020-09-08 10:08:33 -04:00
mauronofrio matarrese
e50fde5c78 Set proper filesystem during decryption
Change-Id: I0bb9d4ceab83feff19571004f7dccd360ddceac0
2020-06-23 14:46:23 +00:00
mauronofrio
539597deed Rework is_metadata_wrappedkey_is_supported
Change-Id: Ia3c266bb32e31354375b633c4801e486f664539a
2020-06-23 14:45:20 +00:00
mauronofrio matarrese
f1079ed67b fscrypt: : Use wrapped key for metadata encryption
Importing of this commit:
944c48d5a4

Change-Id: I048a6c2aeff2591135f47223a99af5ddd215703c
2020-06-23 14:44:34 +00:00
mauronofrio matarrese
bd79db4d6d fscrypt: change to upgrade key if export fails
Importing this commit:
f999d65b23

Change-Id: If73dc534ddf6c8b96ce2789789f25ce432428aa5
2020-06-23 14:44:12 +00:00
mauronofrio matarrese
17fb1210a9 Rework is_wrapped_key_supported_common
Importing is_wrapped_key_supported_common from android-9.0 branch

Change-Id: I7a13b40e365a984a90a661e6c2c71cfa5b725a11
2020-06-23 14:43:47 +00:00
mauronofrio matarrese
7982032fcd fscrypt: Wrapped key support for FBE
Commit imported from:

https: //github.com/LineageOS/android_system_vold/commit/ce024f07c23d0649635a336fff389332b9806f48
Change-Id: I924a9fcbac7d790609fbafcf8c12654fdb267e32
2020-06-23 14:43:17 +00:00
bigbiff
7ba7500953 decrypt: AOSP 10 requires the use of fscrypt
fscrypt aosp doc: https://source.android.com/security/encryption/file-based
kernel fscrypt doc: https://www.kernel.org/doc/html/v4.18/filesystems/fscrypt.html

This commit implements the ability for TWRP to use fscrypt to decrypt
files on the fscrypt implementation. It has been implemented mostly
in a new successor library to e4crypt called libtwrpfscrypt. Most of the
code was ported from AOSP vold.

Notable updates include:
 - updated policy storage by libtar
 - lookup of fbe policies by libtwrpfscrypt
 - threaded keystore operations

Big thanks to Dees_Troy for the initial trailblazing
of encryption in TWRP.

Change-Id: I69cd2eba3693a9914e00213d4943229635d0cdae
2020-06-22 12:17:22 +02:00
Mohd Faraz
fb62b1806e crypto: Update crypto fde
* Some missed in 191a6948d9

* Crypto msg from https://source.codeaurora.org/quic/la/platform/system/vold/commit/cryptfs.cpp?h=LA.UM.8.1.r1-13500-sm8150.0&id=e1a7e772699216121dd8fa774381ffeedb076139

* As devices required to update 'Upgraded key' through keymaster in v4.0.

Change-Id: Ia66be6917c4690f0d70ba89ea33ebfa2fcb6974a
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
(cherry picked from commit b51f4af5286750bf15ffe61fd85e8600cbfd15c5)
2020-05-29 14:07:53 +00:00
bigbiff
adc599e005 Revert "Add support for multi-user decryption"
This reverts commit 0b25b1d79b.

Reason for revert: Changes need to be made to libtwrpfscrypt to include this patchset. Will cherry-pick this patch later and make necessary modifications.

Change-Id: I7601d7b820129709b05d9b4368573b6f1048de02
2020-05-28 19:36:30 +00:00
Noah Jacobson
0b25b1d79b Add support for multi-user decryption
* Add CLI support using the command "twrp decrypt <PASSWORD> [USER ID]"
* Add GUI support using the menu Advanced --> Decrypt User

Change-Id: Id2681bc2b1012a0571417f7a6e0b980b1b25c61c
(cherry picked from commit 5a79f67a1b1bd1bcadeca0a4896a871646652534)
2020-05-20 19:11:15 -04:00
bigbiff
d4aed46c04 vold_decrypt: add missing includes for ext4 policies
Change-Id: Ic68360a13ee8b54cff1f7ec01d4ab1be00673266
(cherry picked from commit 5db50ded70efcea4fe8286689a764860861fdc16)
2020-05-19 14:53:54 +00:00
Captain Throwback
89a03ccd36 vold_decrypt: automatically set Android version & patch level
- Requires TW_INCLUDE_LIBRESETPROP
  (set automatically if TW_OEM_BUILD is not set)
- Set based on installed system (if present)
- Will set values back to TWRP defaults
  after decryption completes
- Only included/run on Oreo+ systems

Change-Id: I41fcc1af8cd4b15329574f7403f7491320199f48
(cherry picked from commit 3284a66e23fbc6e1a82df668b497ef931d9c0081)
2020-05-11 15:22:14 +00:00
bigbiff
d58ba18272 AOSP10 TWRP Merge: fix conflicts and update libraries needed
This allows flame to boot TWRP. Still will need to work on
super partition for vendor and system access.

The plan will be to cherry-pick any updates to android-9.0
through gerrit.twrp.me to this branch as a WIP.
2020-03-23 11:18:29 -04:00
Mohd Faraz
191a6948d9 crypto: fde: decrypt master key first
* Some devices like lavender, etc. getting failed to decrypt

Change-Id: I63ca05c4f87cdd17d48d4541a5a8121c736beb02
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
2020-03-09 23:19:54 +00:00
Captain Throwback
a5283b3570 crypto: add more missing newlines
Change-Id: I158b2a8fee89c2543a0b809af8e278702466b106
2020-03-08 02:13:03 +00:00
Captain Throwback
49cfb7e537 crypto: add some missing newlines
Change-Id: I6bc6b512fe6e841703229d45333421532ecebb83
2020-01-28 17:46:23 -05:00
bigbiff bigbiff
0be03b3217 Encryption: try wrapped key if the first time decryption fails
Change-Id: I108b7aeea41c6b85c851f40c1c4a7e25012e2463
2019-09-01 13:38:44 -04:00
Peter Cai
05cd3f8616 ext4crypt: change to upgrade key if export fails
Add support to upgrade key when export fails with KEY_REQUIRES_UPGRADE.

Ported from
https://source.codeaurora.org/quic/la/platform/system/vold/commit/?h=LA.UM.7.9.r1-06100-sm6150.0&id=85c46eaacc60290db5e71380d89eb4d99ed67995

Change-Id: Ic64be8ade00c0b0d014370ecc9341b1ecc9b0d7a
2019-09-01 19:34:09 +02:00
Peter Cai
90edd2e867 ext4crypt: support wrappedkey for FBE
Qualcomm devices use a special `wrappedkey` mode for FBE. This is ported
from CAF
https://source.codeaurora.org/quic/la/platform/system/vold/commit/?h=LA.UM.7.8.r4-01000-SDM710.0&id=9229262d893a8592f7bc1b4e8a8dab7aad8df68c,
originally by folks at Mokee for vold
https://mokeedev.review/c/MoKee/android_system_vold/+/34102.

This patch ports the above changes to `ext4crypt`, which we can use in
recovery. Note that since we do not have `fs_mgr` in the recovery, we
cannot read the `wrappedkey` flag from fstab. Instead, similar to
`fbe.contents`, we use a special property `fbe.data.wrappedkey` to
indicate support for wrappedkey mode. Devices that need to use this
should set this property to `true` to activate corresponding code.

Change-Id: I79c2855d577156670b45c10c7c7b1fcd9fece8d9
2019-09-01 19:33:30 +02:00
big biff
0bd7c59026 Merge "ext4crypt: support synthetic keys v3 on May update" into android-9.0 2019-06-25 02:01:42 +02:00
Ethan Yonker
abf1fb0086 Switch between dependencies and modules
Use LOCAL_REQUIRED_MODULES for Pie and up and
LOCAL_ADDITIONAL_DEPENDENCIES for Oreo and down.

Change-Id: I5365e782f98f3bbf4bf246be22c8f573824b65ee
2019-05-24 22:39:12 +02:00
Peter Cai
ea1764c9fa ext4crypt: support synthetic keys v3 on May update
Re-implemented SP800Derive in C++, which is added as the new key
derivation function in Android 9.0 May update. From file
services/core/java/com/android/server/locksettings/SP800Derive.java in
frameworks/base.

This is required to get TWRP working on any Android device that has a
screen lock set up after the May update.

Change-Id: I5c1a51b110033f2b0b75d5e36fd8098c05e95179
2019-05-24 20:41:12 +08:00
codeworkx
22e3aa9ed6 ext4crypt: add missing cflag
Avoid calling e4crypt_prepare_user_storage with wrong input parameters.

Change-Id: I5c8945370cb642e46f08c65090c0290c15fe0b57
libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 632 (recovery), pid 564 (recovery)
2019-04-23 12:07:43 +02:00
Ethan Yonker
98661c1a29 Update FDE decrypt to pie from CAF
cryptfs.cpp based on CAF tag LA.UM.7.3.r1-05900-sdm845.0
Used CAF because AOSP no longer contains code for qcom's hardware
crypto.

Change-Id: I921cbe9bed70989f91449e23b5ac3ec1037b7b97
2019-03-20 15:33:48 -05:00
nijel8
2c821a8c0a vold_decrypt: Add android 9.0 support
* build modified vdc_pie binary with 'checkpw' command support
  if building with Android 9.0 platform. That command and others
  we don't care about, are removed from Pie vdc. Our vdc_pie will
  run if system sdk version is > 27, otherwise system vdc is used.
  Code adapted from Android 9.0 system/vold/vdc.

* include prebuilt vdc_pie(arm, arm64) binary if building with lower
  than Android 9.0 platform - vdc_pie cannot be build from source
  with those platforms without additional imports from Android 9.0

* skip vdc "getpwtype" command for Pie - vds communicates with vold
  directly, no need for connection retries first

* add /system/bin/servicemanager to required services

* mount per-devive additional partitions needed for decryption
  listed with device BoardConfig.mk TW_CRYPTO_SYSTEM_VOLD_MOUNT
  flag like(space separated):
  TW_CRYPTO_SYSTEM_VOLD_MOUNT := vendor cust odm

* add function to backup crypto footer before running vdc commands
  and restore it after - on Xiaomi Mi Max 3 both Oreo and Pie stock
  roms vold alters cripto footer when decrypting data in recovery
  which causes system to ask for crypto password at next reboot
  although password stays unchanged. Crypto footer backup/restore
  added as workaround for systems whit ro.build.version.sdk > 25.
  Also to preserve crypto footer integrity decryption attempts are
  skipped if footer backup fails to ensure no data loss.
  Code adapted from
  https://gerrit.omnirom.org/#/c/android_bootable_recovery/+/31206/

Change-Id: I0a383f3843578fa55595cfea3b7c9c4431646a1a
2019-02-01 21:36:23 -05:00
Ethan Yonker
933828251d Add metadata decrypt support for FBE
Change-Id: Ie0292f4ffea5993a4ae74fa04fc5c8252ca2cfcf
2019-01-17 14:14:59 -06:00
Captain Throwback
6ac30afd69 vold_decrypt: use ANDROID_ROOT for additional compatibility
Rather than using hard-coded system, use ANDROID_ROOT
environment variable to allow AB devices to mount
system_root at a custom path. This allows the /system
path to be bind mounted from $ANDROID_ROOT/system
so that the vold_decrypt paths can remain unchanged.

Change-Id: I9a7b13385e43f169f1df4c75b2a003fc6913952c
2018-12-25 17:57:47 +01:00
Ethan Yonker
e9afc3de0f Decrypt FBE on 9.0 (backwards compatible)
Building in 9.0 may require you to add a flag to your twrp fstab
with the fileencryption details like:
fileencryption=ice:aes-256-heh

Verify this against your device's stock fstab of course.

Change-Id: If9286f5d5787280814daca9fbc8f5191ff26a839
2018-08-31 10:37:08 -05:00
Ethan Yonker
58f2132bc3 Merge AOSP android-9.0.0_r3
Fix conflicts and make it build in 5.1, 6.0, 7.1, 8.1, and 9.0

Change-Id: Ida0a64c29ff27d339b7f42a18d820930964ac6e4
2018-08-24 11:17:39 -05:00
Logan Chien
597fbc00ce Enable arm64 neon scrypt implementation
It seems that old Scrypt-config.mk is unaware of arm64 architecture.
In fact, crypto_scrypt-neon.c can be compiled into arm64 as well.  This
CL adds an arch section for arm64.

Bug: 65425184
Test: adb shell /data/nativetest64/scrypt_test/scrypt_test
Change-Id: Ib451de642c7cc4548bfdc0879781981654b21b8f
Merged-In: If40a30378b8038324aad44071107130d7722e28d
2018-05-25 18:47:28 +02:00
nailyk-fr
ca3fd0c0fa TWRP: vold_crypto: Allow custom strace path
* Allow custom definition of strace path with TW_ flags.
 * `TW_CRYPTO_SYSTEM_VOLD_DEBUG := true`
    will use default path: /sbin/strace.
 * `TW_CRYPTO_SYSTEM_VOLD_DEBUG := /system/xbin/strace`
    will use the provided `/system/xbin/strace` path.

Change-Id: I5e12a10176d17a4f26487de0976a776d48c4142e
Signed-off-by: nailyk-fr <nailyk_git@nailyk.fr>
2018-05-25 18:24:09 +02:00
nkk71
37625a4488 vold_decrypt: Code cleanup
* Separate stdout and stderr buffers:
  vdc's return codes get sent to stdout, but the possible presence of
  other error messages in the output buffer will cause a valid return
  from vdc not to be parsed properly, and subsequent decryption to fail
  due to "misunderstood" return code.
  eg on the U11+ (htc_ocm) libc will generate an error to stderr due to
  a missing property area resulting a proper connection to vold being
  incorrectly parsed, and breaking decryption.

* Improve logging.

Change-Id: I57987ebe4ee6754a78e79ca177506098f8301f8f
2018-05-25 18:19:17 +02:00
Steven Moreland
cc825781e7 external/scrypt: use proper nativehelper headers
libnativeheader exports headers under nativeheader. These were
available before incorrectly as global headers in order to give
access to jni.h.

Test: modules using external/scrypt find headers
Bug: 63762847
Change-Id: I9baf896015a1920f8a26daa2a0c549169628890f
2018-04-22 21:57:35 +03:00
Elliott Hughes
87b59b88f7 scrypt doesn't need <machine/cpu-features.h>.
Bug: http://b/18556103
Change-Id: Ibccef334b4d1a2e68e327fc8b73e62e62d13df32
2018-04-22 21:57:35 +03:00
Dan Albert
01396f1b13 scrypt: Don't hardcode gtest path.
Bug: http://b/16574165
Change-Id: Ieb63fb6a73f0fb2ab3260bc5eabca7d86d892fbd
2018-04-22 21:57:35 +03:00
big biff
a185c6ced7 Merge "ext4crypt: keymaster: fix missing include" into android-8.1 2018-03-24 14:14:47 +01:00
Ethan Yonker
c5dd579168 FBE: Decrypt spblob v2 (February security patch)
Change-Id: Iad82fa5d90ce7f3e4b1cf5cd5c6d6fef644f6762
2018-03-09 04:30:57 +01:00
Ethan Yonker
e131bec179 Add spblob decrypt for secdis method (Pixel 1 non-weaver)
Support decrypting Pixel 1 devices using secdis method with the
gatekeeper instead of weaver.

Add a bit of a dirty workaround to a permissions issue that the
keystore presents because the keystore checks the uid of the
calling process and refuses to let the root user add authorization
tokens. We write the auth token to a file and start a separate
service that runs under the system user. The service reads the
token from the file and adds it to the keystore. You must define
this service in your init.recovery.{hardware}.rc file:

service keystore_auth /sbin/keystore_auth
    disabled
    oneshot
    user system
    group root
    seclabel u:r:recovery:s0

TWRP will run this service when needed.

Change-Id: I0ff48d3355f03dc0be8e75cddb8b484bdef98772
2018-01-04 07:40:22 -06:00
codeworkx
071526bd13 ext4crypt: keymaster: fix missing include
Change-Id: I9a6c5a1384bed7f0169d9af94ff8cb22913ff8e4
2017-12-26 20:41:55 +01:00
Ethan Yonker
31344a3b2f Better compatibility across 8.0.0 trees
Change-Id: Ic8200da4e99826736e002a1ab5f9e5f967e84193
2017-11-29 13:23:50 -06:00