Commit Graph

47 Commits

Author SHA1 Message Date
nkk71
5073003302 cryptfs: Remove dm-crypt device on failed table load
* The dm-crypt device needs to be removed from
   the device-mapper driver list otherwise it will
   remain busy and cannot be used later on by
   other processes (eg vold_decrypt) or for further
   testing/debugging in recovery.

Change-Id: I35e43a79ecc3de234ddb9f87f7d75c6439ea7454
2017-05-23 14:59:57 +02:00
nkk71
201d4b21bc vold_decrypt: Add back missing xml and get rid of compiler warning
Change-Id: I883112e2618f560e96002e2076e2735cc20cfac3
2017-03-06 21:39:10 +01:00
nkk71
71c6c50d0d crypto: Use system's vold for decryption
If TWRP crypto fails to decrypt partition, mount the system
  partition and use system's own vold to attempt decryption.
  This provides a fallback for proprietary OEM encryption as well as
  encryption methods which TWRP hasn't been updated for.

  Requirements in device tree:
  * fstab.{ro.hardware} in device/recovery/root
    The fstab does not need to be complete, but it does need the
    data partition and the encryption entries.

  * 'TW_CRYPTO_USE_SYSTEM_VOLD := true' in BoardConfig
  or
  * 'TW_CRYPTO_USE_SYSTEM_VOLD := <list of services>'

  Notes:
  * Setting the flag to 'true' will just use system's vdc+vold
    or
  * Setting the flag with additional services, will also start them
    prior to attempting vdc+vold decryption, eg: for qualcomm based
    devices you usually need 'TW_CRYPTO_USE_SYSTEM_VOLD := qseecomd'

  * For each service listed an additional import will be automatically
    added to the vold_decrypt.rc file in the form of
    init.recovery.vold_decrypt.{service}.rc
    You will need to add any not already existing .rc files in
    your device/recovery/root folder.

  * The service names specified in the vold_decrypt.{service}.rc files
    have to be named 'sys_{service}'
    eg: 'service sys_qseecomd /system/bin/qseecomd'

  * Any service already existing in TWRP as {service} or sbin{service} will
    be stopped and restarted as needed.

  * You can override the default init.recovery.vold_decrypt.rc file(s)
    by placing same named ones in your device/recovery/root folder.
    If you do, you'll need to manually add the needed imports.

  * If /vendor and /firmware folders are temporarily moved and symlinked
    to the folders and files in the system partition, the properties
    'vold_decrypt.symlinked_vendor' and 'vold_decrypt.symlinked_firmware'
    will be set to 1.
    This allows for additional control in the .rc files for any extra
    actions (symlinks, cp files, etc) that may be needed for decryption
    by using: on property:vold_decrypt.symlinked_vendor=1 and/or
    on property:vold_decrypt.symlinked_firmware=1 triggers.

  Debug mode: 'TW_CRYPTO_SYSTEM_VOLD_DEBUG := true' in BoardConfig
  * Specifying this flag, will enable strace on init and vdc, which will
    create separate log files in /tmp for every process created, allowing
    for detailed analysis of which services and files are being accessed.
  * Note that enabling strace will expose the password in the logs!!
  * You need to manually add strace to your build.

Thanks to @Captain_Throwback for co-authoring and testing.

Tested successfully on HTC devices:
M8 (KK through MM), M9 (MM and N), A9 (N), 10 (N), Bolt (N),
Desire 626s (MM), U Ultra (N)

HTC One X9 (MTK device)

And by Nikolay Jeliazkov on: Xiaomi Mi Max

Change-Id: I4d22ab55baf6a2a50adde2e4c1c510c142714227
2017-03-06 18:50:52 +02:00
nijel8
2dd66f4962 cryptfs: Fix encryption issue due to stack corruption.
Ioctl BLKGETSIZE expects pointer to unsigned long as argument.

On 64bit target using pointer to unsigned int can cause stack
corruption due to type mismatch.

props to f8b8787317

Change-Id: I1d76c65e29479c8f0cd44b6892069b21b8249b95
2017-02-19 21:34:12 +01:00
James Christopher Adduono
c51bd35040 Try mounting different filesystems during decryption
Based on Dees_Troy's approach.

Change-Id: Id9aafb6d0c64ab43e2711720a26e30ac86b90235
2017-01-21 00:31:36 -05:00
Ethan Yonker
79f88bdf8d Support backup/restore of FBE policies
Change-Id: Iba8ef20f57b0fb57bb9406c53148a806441d0b59
2016-12-13 14:25:04 -06:00
Ethan Yonker
bd7492de28 Support File Based Encryption
Change-Id: Ib688ddd0c32d3999590cacd86b6d9b18eac336e9
2016-12-13 21:16:42 +01:00
maxwen
ad05c6dce4 recovery: allow usage of TARGET_CRYPTFS_HW_PATH
only if not defined fallback to the default
more flexible device config where the cryptfs_hw is located

Change-Id: I7d1c18eeae877e48dceff06a7cfead28c89797b4
2016-08-10 20:38:26 +02:00
Captain Throwback
35df638965 crypto: remove redundant convert_key_to_hex_ascii call
- Breaks decryption on some hw_crypto devices
- Default value already defined in preceding ifdef
- PS2: Move crypt_params definition prior to ifdef
  (matches corresponding code from CAF)

Huge thanks to @beaups for figuring out the issue!

Change-Id: I1fd4e3a4862f022b17a555773feb1d6deac9d34c
2016-05-17 14:26:43 -04:00
Ethan Yonker
9f1f2f744b Fix decrypt of odd number length PIN on hardware crypto
I am not sure if we are really fixing anything other than we are
allowing the decrypt process to continue. On hardware crypto the
password never seems to match what is expected from the data in
the footer, probably because the data is not stored in the footer
and TZ does all the work. Still, if it works, it is hard to fault
the patch.

Change-Id: Ibbb286382e82523bec2064f51fa07194f84820c2
2016-04-28 16:46:46 +01:00
Ethan Yonker
d3e96ff43e Restore some old decrypt functionality
Some of the convoluted convert_hex_ascii_to_key code is needed to
properly decrypt CM 12.1 patterns where grid size is larger than
3x3.

Change-Id: I497e17980046c60d2c69ba56e4b83c8b64b0b80e
2016-02-17 13:36:54 -06:00
Sultan Qasim Khan
a7e63a28c8 cryptfs: major overhaul and cleanup
- Don't upgrade HW encrypted Lollipop devices to Marshmallow crypto
- Fix support for passwords and patterns with an odd number of elements
- Remove unused code
- Fix build warnings

Change-Id: I25f015085e5c859d0353f42f6a2fbc7ccecd48ed
2016-02-16 13:32:22 -05:00
Ethan Yonker
66a1949df9 Adopted Storage support
-Detects, decrypts, and mounts an adopted SD card if a
  secondary block device is defined (usually mmcblk1)
 -Handles unified storage
 -Displays the adopted storage in MTP along with internal
 -Factory Reset - wiped just like a data media device, we
  retain the keys folder and the storage.xml during a
  factory reset
 -Backup / Restore
 -Disable mass storage when adopted storage is present
 -Read storage nickname from storage.xml and apply it to
  display names in the GUI
 -Read storage.xml and determine what storage location is in
  use for /sdcard and remap accordingly

libgpt_twrp is source code mostly kanged from an efimanager
project. It is GPL v2 or higher, so we will opt for GPL v3.

Change-Id: Ieda0030bec5155ba8d2b9167dc0016cebbf39d55
2016-01-25 23:59:17 +01:00
Ethan Yonker
ba95ad18ac Update qcom hardware crypto code
Change-Id: I4608c45b3f71b53e0988ca0248d3438110a40149
2016-01-19 23:13:17 +01:00
Ethan Yonker
ceb1e8a5fc Fix CLANG error in cryptfs.c
Change-Id: If5af8f634bc016160aebaf7d4e6cda6c5650a077
2015-12-22 11:41:40 -06:00
Ethan Yonker
c798c9cd24 Merge up to AOSP marshmallow-release
In order to maintain compatibility with older trees, we now have
minadbd.old and minui.old. I had to use a TARGET_GLOBAL_CFLAG to
handle ifdef issues in minui/minui.d because healthd includes
minui/minui.h and there was no other alternative to make minui.h
compatible with older trees without having to modify healthd rules
which is outside of TWRP.

Note that the new minui does not currently have support for qcom
overlay graphics. Support for this graphics mode will likely be
added in a later patch set. If you are building in a 6.0 tree and
have a device that needs qcom overlay graphics, be warned, as off
mode charging may not work properly. A dead battery in this case
could potentially brick your device if it is unable to charge as
healthd handles charging duties.

Update rules for building toolbox and add rules for making toybox

Use permissive.sh in init.rc which will follow symlinks so we do
not have to worry about what binary is supplying the setenforce
functionality (toolbox, toybox, or busybox).

Fix a few warnings in the main recovery binary source code.

Fix a few includes that were missing that prevented compiling in
6.0

Change-Id: Ia67aa2107d260883da5e365475a19bea538e8b97
2015-10-09 11:15:29 -05:00
Dees Troy
c657cc0037 Support Qualcomm hardware decrypt
Change-Id: I121ef0f5da209be48f6d87559d539c7fc6d85336
2015-05-15 10:52:46 -05:00
that
183a6f88d0 crypto: remove unused libs and clean up makefile
libsoftkeymaster and its dependencies appear to be unused.

Change-Id: Ib720f5e4d2750a739ba6b65b346c0e167df279d3
2015-01-05 03:14:28 +01:00
Ethan Yonker
d79d9bceb3 Allow non datamedia devices to wipe encryption
With 5.0 L, we decrypt automatically if the default_password is
used. Non datamedia devices do not get the format data button so
they cannot wipe encryption off the device. This patch add a wipe
encryption button where the format data button would normally be
located on the Wipe page.

This patch also attempts to remove / delete the dm-crypt block
device before formatting.

Change-Id: I100d5d154d6c49254fd48e23279df973db5f23ae
2014-12-21 23:30:17 +01:00
Ethan Yonker
b7896268ed Fix include paths in crypto
Change-Id: Ia9fd0cd75bd6ee6e14909890cb18a8edb3b22267
2014-12-18 15:30:31 -06:00
Dees Troy
87da424556 Fixes for compiling crypto in older trees
Some of these fixes needed to be made anyway. Note that older
trees will still need to have files / repos copied into them from
newer trees. Namely we need:
system/security/softkeymaster
hardware/libhardware/include/hardware/keymaster.h

Maybe others as I did not document very carefully what I was
pulling in.

Change-Id: I465fd1fbe228803ec02fba047b151f07ea13d5ca
2014-12-12 18:50:11 +00:00
that
ceb7b8e576 crypto: fix build in < 5.0 tree
Change-Id: Ie4ed3e91cfb7e509bac1d6db885bd3f415d2b168
2014-12-10 17:22:09 +01:00
Ethan Yonker
253368a072 Reduce libs needed for decrypt and clean up old decypt files
Trim cryptfs.c to remove functions that TWRP does not use for
decrypt and remove the need for libfs_mgr from cryptfs.c by
passing some items to cryptfs.c from the partition manager.

Add support for new fstab flags:
encryptable and forceencrypt=/path/to/cryptokey
For example:
flags=forceencrypt=/dev/block/platform/sdhci-tegra.3/by-name/MD1
Note that "footer" is the default, so you do not need to set this
flag on devices that use the footer for the crypto key.
Also add mounttodecrypt if you need to mount a partition during
the decrypt cycle for firmware of proprietary libs.

Clean up decrypt and only support one version

Android 5.0 lollipop decrypt should be backwards compatible with
older versions so we will only support one version, 1.3 that came
with 5.0 lollipop.

Remove support for Samsung TouchWiz decrypt. It does not work with
the latest versions of Samsung encryption anyway and it has not
been updated to work with any AOSP decryption higher than 1.1

Change-Id: I2d9c6e31df50268c91ee642c2fa090f901d9d5c9
2014-12-04 17:30:16 +01:00
Ethan Yonker
cceebb8189 Tweak 5.0 L decrypt
Mount the vendor partition if it exists so we can use any
proprietary files we may need.
Relocate auto decrypt when default_password is in use to after all
partitions are added so that we can mount the vendor partition.

Change-Id: I93455a35695779f53ef57a82d3d45c7216c13639
2014-11-18 10:18:14 -06:00
Ethan Yonker
560e65f899 Make libmincrypttwrp a shared library
Change-Id: I8c3f084fc34b00edb4cd1b652290df8bc80ea1db
2014-11-17 11:37:20 -06:00
Ethan Yonker
4eca40d7d8 Add lollipop decrypt support
Kang in cryptfs.c and cryptfs.h from vold.
Use TW_INCLUDE_L_CRYPTO := true to enable.
Ramdisk must contain the normal fstab file in the root in the
usual format of:
fstab.{ro.hardware}
For examble for Nexus 5:
fstab.hammerhead
Or on many Qualcomm devices:
fstab.qcom

Tested against Android 5.0 lollipop on Nexus 7 2012 grouper. Not
sure if or how this will work when we are dealing with a device
with a hardware keystore. Long term we need to add a GUI element
to allow entering a pattern. For now you can decrypt a pattern
unlock by converting the dots to numbers in the following format:
123
456
789

So an upper-case L would translate to 14789 as a password entered
on the keyboard.

Change-Id: I02c29e1f1c2eb29bf002c9fe0fc118357300b5b3
2014-11-12 18:07:24 +01:00
Ethan Yonker
c30edd12c5 Fix potential tree conflicts with scrypt
Change-Id: Iac40957e40cb9c10795dd6a1f67ca902c95dd9bc
2014-11-08 07:05:47 -06:00
Rob
12f1187e7f Recovery: Fix my-dir must be called before including any other makefile
Change-Id: I70c867961ae779bd99839e4ce7cb1dc8d154158f
2014-11-06 22:16:31 +01:00
Matt Mower
db22044901 Fix some module tags
There is no LOCAL_MODULES_TAGS. Fix by combining with LOCAL_MODULE_TAGS.

Change-Id: I1cacef2f8123af3632ff6a52aa62c2f2e15ac37d
2014-11-04 08:49:09 -06:00
Matt Mower
031163b2c6 Remove dependence on build hax in makefiles
Update makefiles to no longer rely on INTERNAL_RECOVERY_FILES. Define
LOCAL_ADDITIONAL_DEPENDENCIES instead.

Set LOCAL_LDFLAGS to properly link recovery executable.

Change-Id: I4542104c69399b5a19674b9772ab89c3709efa72
2014-11-03 13:36:03 -06:00
Matt Mower
55c75cad80 Build block TWRP with RECOVERY_VARIANT
Enable TWRP to reside alongside other recoveries with the naming
convention: bootable/recovery(-flag). If TWRP resides at
bootable/recovery and a device does not specify RECOVERY_VARIANT, then
it will build like normal. If TWRP resides at bootable/recovery-twrp,
then its makefiles will only be parsed if a device specifies
'RECOVERY_VARIANT := twrp'. This prevents TWRP specific makefile
warnings/errors (notably, missing DEVICE_RESOLUTION) when another
recovery is being built.

Change-Id: I8f02fffcd79c309c7123b9428eedc69af02e126e
2014-09-03 10:53:37 -05:00
Ethan Yonker
71413f4ee9 Check crypto footer before offering to decrypt
Verify that we have a valid footer with proper magic before
setting things up for decryption to help prevent user confusion
when dealing with data partitions that fail to mount. Also check
to make sure that the block device for /data is present.

Change-Id: Ie87818fe4505a8bf71df7d3934c114e7328ef3ca
2014-02-26 13:37:35 -06:00
OliverG96
06b91e7965 crypto: Fix crypto dependencies for ICS/Samsung methods
- libmincrypt renamed to libmincrypttwrp that is an static library
- libjpegtwrp does not exist
- libfs_mgrtwrp is for JB decryption methods

This fixes making full builds when TW_INCLUDE_CRYPTO_SAMSUNG := true and TW_INCLUDE_CRYPTO := true are set.
Somehow typing make recoveryimage doesnt push the mentioned issue.

Change-Id: I7cad5db4f51152a1a8209e619b188ca88d7c74d1
2013-12-19 17:08:31 +00:00
Dees Troy
8931007340 Add getfooter tool for crypto debugging
Change-Id: I3b9e5f72f3c1c77e41a45d3c94a44f36cc5cbc3c
2013-11-11 15:15:30 +00:00
Dees Troy
4dff2e6234 Update decrypt for 4.4
Change-Id: I8d5d7b6a49890e4707d70de8b429563de0d2ad99
2013-11-10 04:11:48 +00:00
Dees_Troy
066eb30abf Fix AOSP decrypt when TouchWiz code is present 2013-08-23 17:22:37 +00:00
Dees_Troy
b8934dd456 Fix conflict with getline in 4.3 tree
Change-Id: I5accf8731829229d153a657c9290a7be83f87a03
2013-08-11 13:43:12 +00:00
Trevor Drake
27fab9b26a Add additional build variable checks to Android.mk files
This was causing the mm command to fail when it was run from
bootable/recovery and no crypto features had been specified in
a device's configuration files

Change-Id: Iddbeea5349bbf75cddb0250cd71821dfe3b7b9d8
2013-07-03 18:13:43 +00:00
Dees_Troy
2c4e4437b3 Fix CFLAGS for Samsung decrypt 2013-04-18 16:38:28 +00:00
Dees_Troy
2673cec07a Move all AOSP code out of recovery binary
Improves license compatibility between GPL and Apache

Change-Id: I2b165aa575bb6213af6b07936f99610c113443f0
2013-04-04 18:57:34 +00:00
Dees_Troy
a13d74fc95 Add partition list GUI element
Add partition list GUI element and update backup, restore, mount,
storage selection, and wipe sections of GUI and partition manager
code to reflect the new GUI element. Update ORS engine to handle
new backup and restore setup.

Fix a bug with decrypt.
Add 1080x1920 layout.

Change-Id: Iaa2f44cb707167e66f935452f076ba00e68a2aa4
2013-03-30 08:56:39 -05:00
Dees_Troy
c8bafa1cc1 More Samsung sdcard crypto fixes 2013-01-10 15:43:00 +00:00
Dees_Troy
85f44ed751 Improve remounting sdcard with ecryptfs 2013-01-09 18:44:25 +00:00
a3955269
6ff55cefd0 Add Samsung TouchWiz decryption
Change-Id: I418680e59372160dabfe3e2d5f0208229aa151ae
2013-01-08 20:09:56 +00:00
Dees_Troy
014c894af2 Workaround for crypto quirk on Nexus 10 2012-11-19 17:10:46 +00:00
Dees_Troy
ab10ee2098 Fix special partition handling 2012-09-21 14:27:30 -04:00
Dees_Troy
51a0e82eb2 TWRP-ify AOSP code
Pull in most TWRP sources
Stub out partition management code
Make it compile -- probably will not boot
Kind of a mess but have to start somewhere
2012-09-05 15:24:31 -04:00