Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 253368a0 authored by Ethan Yonker's avatar Ethan Yonker Committed by Dees Troy
Browse files

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
parent 1db013bf
Loading
Loading
Loading
Loading
+6 −51
Original line number Diff line number Diff line
@@ -252,38 +252,14 @@ endif
ifeq ($(TW_NO_EXFAT_FUSE), true)
    LOCAL_CFLAGS += -DTW_NO_EXFAT_FUSE
endif
ifeq ($(TW_INCLUDE_CRYPTO), true)
    LOCAL_CFLAGS += -DTW_INCLUDE_CRYPTO
    LOCAL_CFLAGS += -DCRYPTO_FS_TYPE=\"$(TW_CRYPTO_FS_TYPE)\"
    LOCAL_CFLAGS += -DCRYPTO_REAL_BLKDEV=\"$(TW_CRYPTO_REAL_BLKDEV)\"
    LOCAL_CFLAGS += -DCRYPTO_MNT_POINT=\"$(TW_CRYPTO_MNT_POINT)\"
    LOCAL_CFLAGS += -DCRYPTO_FS_OPTIONS=\"$(TW_CRYPTO_FS_OPTIONS)\"
    LOCAL_CFLAGS += -DCRYPTO_FS_FLAGS=\"$(TW_CRYPTO_FS_FLAGS)\"
    LOCAL_CFLAGS += -DCRYPTO_KEY_LOC=\"$(TW_CRYPTO_KEY_LOC)\"
ifeq ($(TW_INCLUDE_CRYPTO_SAMSUNG), true)
    LOCAL_CFLAGS += -DTW_INCLUDE_CRYPTO_SAMSUNG=\"$(TW_INCLUDE_CRYPTO_SAMSUNG)\"
    ifdef TW_CRYPTO_SD_REAL_BLKDEV
        LOCAL_CFLAGS += -DCRYPTO_SD_REAL_BLKDEV=\"$(TW_CRYPTO_SD_REAL_BLKDEV)\"
        LOCAL_CFLAGS += -DCRYPTO_SD_FS_TYPE=\"$(TW_CRYPTO_SD_FS_TYPE)\"
    endif
    #LOCAL_LDFLAGS += -L$(TARGET_OUT_SHARED_LIBRARIES) -lsec_km
    LOCAL_LDFLAGS += -ldl
    LOCAL_STATIC_LIBRARIES += libcrypt_samsung
endif
    LOCAL_SHARED_LIBRARIES += libcryptfsics
    #LOCAL_SRC_FILES += crypto/ics/cryptfs.c
    #LOCAL_C_INCLUDES += system/extras/ext4_utils external/openssl/include
endif
ifeq ($(TW_INCLUDE_JB_CRYPTO), true)
    LOCAL_CFLAGS += -DTW_INCLUDE_CRYPTO
    LOCAL_CFLAGS += -DTW_INCLUDE_JB_CRYPTO
    LOCAL_SHARED_LIBRARIES += libcryptfsjb
    #LOCAL_SRC_FILES += crypto/jb/cryptfs.c
    #LOCAL_C_INCLUDES += system/extras/ext4_utils external/openssl/include
    TW_INCLUDE_CRYPTO := true
endif
ifeq ($(TW_INCLUDE_L_CRYPTO), true)
    TW_INCLUDE_CRYPTO := true
endif
ifeq ($(TW_INCLUDE_CRYPTO), true)
    LOCAL_CFLAGS += -DTW_INCLUDE_CRYPTO
    LOCAL_CFLAGS += -DTW_INCLUDE_L_CRYPTO
    LOCAL_SHARED_LIBRARIES += libcryptfslollipop
endif
ifeq ($(TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID), true)
@@ -374,12 +350,6 @@ endif
ifneq ($(TW_NO_EXFAT_FUSE), true)
    LOCAL_ADDITIONAL_DEPENDENCIES += exfat-fuse
endif
ifeq ($(TW_INCLUDE_CRYPTO), true)
    LOCAL_ADDITIONAL_DEPENDENCIES += cryptfs cryptsettings
endif
ifeq ($(TW_INCLUDE_JB_CRYPTO), true)
    LOCAL_ADDITIONAL_DEPENDENCIES += getfooter
endif
ifeq ($(TW_INCLUDE_FB2PNG), true)
    LOCAL_ADDITIONAL_DEPENDENCIES += fb2png
endif
@@ -513,8 +483,6 @@ include $(commands_recovery_local_path)/injecttwrp/Android.mk \
    $(commands_recovery_local_path)/flashutils/Android.mk \
    $(commands_recovery_local_path)/pigz/Android.mk \
    $(commands_recovery_local_path)/libtar/Android.mk \
    $(commands_recovery_local_path)/crypto/cryptsettings/Android.mk \
    $(commands_recovery_local_path)/crypto/cryptfs/Android.mk \
    $(commands_recovery_local_path)/libcrecovery/Android.mk \
    $(commands_recovery_local_path)/libblkid/Android.mk \
    $(commands_recovery_local_path)/minuitwrp/Android.mk \
@@ -528,19 +496,9 @@ ifneq ($(TARGET_ARCH), arm64)
    include $(commands_recovery_local_path)/dosfstools/Android.mk
endif

ifeq ($(TW_INCLUDE_CRYPTO_SAMSUNG), true)
    include $(commands_recovery_local_path)/crypto/libcrypt_samsung/Android.mk
endif

ifeq ($(TW_INCLUDE_JB_CRYPTO), true)
    include $(commands_recovery_local_path)/crypto/jb/Android.mk
    include $(commands_recovery_local_path)/crypto/fs_mgr/Android.mk
    include $(commands_recovery_local_path)/crypto/logwrapper/Android.mk
    include $(commands_recovery_local_path)/crypto/scrypt/Android.mk
    include $(commands_recovery_local_path)/crypto/crypttools/Android.mk
endif
ifeq ($(TW_INCLUDE_L_CRYPTO), true)
ifeq ($(TW_INCLUDE_CRYPTO), true)
    include $(commands_recovery_local_path)/crypto/lollipop/Android.mk
    include $(commands_recovery_local_path)/crypto/scrypt/Android.mk
endif
ifeq ($(PLATFORM_VERSION), 5.0.1)
    include $(commands_recovery_local_path)/minzip/Android.mk
@@ -558,9 +516,6 @@ endif
ifneq ($(TW_NO_EXFAT_FUSE), true)
    include $(commands_recovery_local_path)/exfat/exfat-fuse/Android.mk
endif
ifeq ($(TW_INCLUDE_CRYPTO), true)
    include $(commands_recovery_local_path)/crypto/ics/Android.mk
endif
ifneq ($(TW_OEM_BUILD),true)
    include $(commands_recovery_local_path)/orscmd/Android.mk
endif

crypto/cryptfs/Android.mk

deleted100644 → 0
+0 −54
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
ifeq ($(TW_INCLUDE_CRYPTO), true)
LOCAL_SRC_FILES:= \
	cryptfs.c

LOCAL_CFLAGS:= -g -c -W -I../fs_mgr/include
LOCAL_CFLAGS += -DTW_INCLUDE_CRYPTO
LOCAL_CFLAGS += -DCRYPTO_FS_TYPE=\"$(TW_CRYPTO_FS_TYPE)\"
LOCAL_CFLAGS += -DCRYPTO_REAL_BLKDEV=\"$(TW_CRYPTO_REAL_BLKDEV)\"
LOCAL_CFLAGS += -DCRYPTO_MNT_POINT=\"$(TW_CRYPTO_MNT_POINT)\"
LOCAL_CFLAGS += -DCRYPTO_FS_OPTIONS=\"$(TW_CRYPTO_FS_OPTIONS)\"
LOCAL_CFLAGS += -DCRYPTO_FS_FLAGS=\"$(TW_CRYPTO_FS_FLAGS)\"
LOCAL_CFLAGS += -DCRYPTO_KEY_LOC=\"$(TW_CRYPTO_KEY_LOC)\"
ifdef TW_CRYPTO_SD_REAL_BLKDEV
    LOCAL_CFLAGS += -DCRYPTO_SD_REAL_BLKDEV=\"$(TW_CRYPTO_SD_REAL_BLKDEV)\"
    LOCAL_CFLAGS += -DCRYPTO_SD_FS_TYPE=\"$(TW_CRYPTO_SD_FS_TYPE)\"
endif
ifneq ($(TW_INTERNAL_STORAGE_PATH),)
	LOCAL_CFLAGS += -DTW_INTERNAL_STORAGE_PATH=$(TW_INTERNAL_STORAGE_PATH)
endif
ifneq ($(TW_INTERNAL_STORAGE_MOUNT_POINT),)
	LOCAL_CFLAGS += -DTW_INTERNAL_STORAGE_MOUNT_POINT=$(TW_INTERNAL_STORAGE_MOUNT_POINT)
endif
ifneq ($(TW_EXTERNAL_STORAGE_PATH),)
	LOCAL_CFLAGS += -DTW_EXTERNAL_STORAGE_PATH=$(TW_EXTERNAL_STORAGE_PATH)
endif
ifneq ($(TW_EXTERNAL_STORAGE_MOUNT_POINT),)
	LOCAL_CFLAGS += -DTW_EXTERNAL_STORAGE_MOUNT_POINT=$(TW_EXTERNAL_STORAGE_MOUNT_POINT)
endif

LOCAL_C_INCLUDES += system/extras/ext4_utils external/openssl/include
LOCAL_MODULE:=cryptfs
LOCAL_MODULE_TAGS:= eng
LOCAL_SHARED_LIBRARIES += libc libcutils
LOCAL_SHARED_LIBRARIES += libcrypto


#LOCAL_LDFLAGS += -L$(TARGET_OUT_SHARED_LIBRARIES) -lsec_km -lsec_ecryptfs -ldl
LOCAL_LDFLAGS += -ldl

LOCAL_STATIC_LIBRARIES += libmtdutils
LOCAL_STATIC_LIBRARIES += libminzip libunz
LOCAL_STATIC_LIBRARIES += libpixelflinger_static libpng libmincrypttwrp
LOCAL_SHARED_LIBRARIES += libz libc libstlport libcutils libstdc++ libext4_utils
LOCAL_STATIC_LIBRARIES += libcrypt_samsung


LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UI_LIB)
#LOCAL_STATIC_LIBRARIES += libfs_mgrtwrp
LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
include $(BUILD_EXECUTABLE)
endif

crypto/cryptfs/cryptfs.c

deleted100644 → 0
+0 −74
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013 a3955269 all rights reversed, no rights reserved.
 */

#define TW_INCLUDE_CRYPTO_SAMSUNG
#include "../ics/cryptfs.c"

int dm_remove_device(const char *name)
{
    int r;
    r = delete_crypto_blk_dev(name);
    if(!r)
        printf("crypto block device '%s' deleted.\n", name);
    else
        printf("deleting crypto block device '%s' failed. [%d - %s]\n", name, r, strerror(errno));
    return r;
}

int ecryptfs_test(const char *pw)
{
   char pwbuf[256];
   int r;

   strcpy(pwbuf, pw);
   // 0: building options without file encryption filtering.
   // 1: building options with media files filtering.
   // 2: building options with all new files filtering.
   r = mount_ecryptfs_drive(pwbuf, "/emmc", "/emmc", 0);
   printf("mount_ecryptfs_drive: %d\n", r);
   r = mount("/dev/block/mmcblk1", "/emmc", "vfat", MS_RDONLY, "");
   printf("mount: %d\n", r);

   r = umount("/emmc");///dev/block/mmcblk1");
   printf("umount: %d\n", r);

   //r = unmount_ecryptfs_drive("/emmc");
   //printf("unmount_ecryptfs_drive: %d\n", r);

   return r;
}

int main(int argc, char* argv[])
{
    if(argc < 2)
    {
        printf("no args!\n");
        return 1;
    }

    property_set("ro.crypto.state", "encrypted");

    property_set("ro.crypto.fs_type", CRYPTO_FS_TYPE);
    property_set("ro.crypto.fs_real_blkdev", CRYPTO_REAL_BLKDEV);
    property_set("ro.crypto.fs_mnt_point", CRYPTO_MNT_POINT);
    property_set("ro.crypto.fs_options", CRYPTO_FS_OPTIONS);
    property_set("ro.crypto.fs_flags", CRYPTO_FS_FLAGS);
    property_set("ro.crypto.keyfile.userdata", CRYPTO_KEY_LOC);

#ifdef CRYPTO_SD_FS_TYPE
    property_set("ro.crypto.sd_fs_type", CRYPTO_SD_FS_TYPE);
    property_set("ro.crypto.sd_fs_real_blkdev", CRYPTO_SD_REAL_BLKDEV);
    property_set("ro.crypto.sd_fs_mnt_point", EXPAND(TW_INTERNAL_STORAGE_PATH));
#endif

    property_set("rw.km_fips_status", "ready");

    delete_crypto_blk_dev("userdata");
    delete_crypto_blk_dev("sdcard");
    delete_crypto_blk_dev("emmc");

    cryptfs_check_passwd(argv[1]);

    return 0;
};

crypto/cryptsettings/Android.mk

deleted100644 → 0
+0 −17
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
ifeq ($(TW_INCLUDE_CRYPTO), true)
LOCAL_SRC_FILES:= \
	cryptsettings.c
LOCAL_CFLAGS:= -g -c -W
LOCAL_MODULE:=cryptsettings
LOCAL_MODULE_TAGS:= eng
LOCAL_SHARED_LIBRARIES += libc libcutils
ifeq ($(TW_INCLUDE_JB_CRYPTO), true)
LOCAL_CFLAGS += -DTW_INCLUDE_JB_CRYPTO
LOCAL_STATIC_LIBRARIES += libfs_mgrtwrp
endif
LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
include $(BUILD_EXECUTABLE)
endif
+0 −55
Original line number Diff line number Diff line
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef TW_INCLUDE_JB_CRYPTO
#include "../crypto/fs_mgr/include/fs_mgr.h"
#endif

#include "cutils/properties.h"

#ifndef PROPERTY_VALUE_MAX
#define PROPERTY_VALUE_MAX 255
#endif
#ifndef FSTAB_PREFIX
#define FSTAB_PREFIX "/fstab."
#endif

int main(void)
{
	char prop[PROPERTY_VALUE_MAX];
	char key_loc[PROPERTY_VALUE_MAX];
	char blk_dev[PROPERTY_VALUE_MAX];
	char fstab_filename[PROPERTY_VALUE_MAX + sizeof(FSTAB_PREFIX)];

	printf("This tool will gather the build flags needed for decryption support for TWRP.\n");
	printf("This tool comes with no warranties whatsoever.\n");
	printf("http://teamw.in\n\n");
	property_get("ro.crypto.state", prop, "encrypted");
	if (strcmp(prop, "encrypted") != 0)
		printf("Your device is not encrypted, continuing anyway.\n\nTW_INCLUDE_CRYPTO := true\n");
	property_get("ro.crypto.fs_type", prop, "ERROR");
	printf("TW_CRYPTO_FS_TYPE := \"%s\"\n", prop);
	property_get("ro.crypto.fs_real_blkdev", prop, "ERROR");
	printf("TW_CRYPTO_REAL_BLKDEV := \"%s\"\n", prop);
	property_get("ro.crypto.fs_mnt_point", prop, "ERROR");
	printf("TW_CRYPTO_MNT_POINT := \"%s\"\n", prop);
	property_get("ro.crypto.fs_options", prop, "ERROR");
	printf("TW_CRYPTO_FS_OPTIONS := \"%s\"\n", prop);
	property_get("ro.crypto.fs_flags", prop, "ERROR");
	printf("TW_CRYPTO_FS_FLAGS := \"%s\"\n", prop);
	property_get("ro.crypto.keyfile.userdata", prop, "footer");
	printf("TW_CRYPTO_KEY_LOC := \"%s\"\n", prop);
#ifdef TW_INCLUDE_JB_CRYPTO
	printf("\n*** NEW FOR JELLY BEAN:\n");
	strcpy(fstab_filename, FSTAB_PREFIX);
	property_get("ro.hardware", fstab_filename + sizeof(FSTAB_PREFIX) - 1, "");
	fs_mgr_get_crypt_info(fstab_filename, key_loc, blk_dev, sizeof(key_loc));
	printf("fstab file location: '%s'\n\nTW_INCLUDE_JB_CRYPTO := true\n", fstab_filename);
#endif

	return 0;
}
Loading