Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 1 | From 3df1faeb7e70914cddefb4fb6ecd27bb989c4cc5 Mon Sep 17 00:00:00 2001 |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 2 | From: Jackeagle <jackeagle102@gmail.com> |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 3 | Date: Mon, 6 May 2019 19:57:11 +0200 |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 4 | Subject: [PATCH 8/8] Revert "vold: Add Hardware FDE feature" |
| 5 | |
| 6 | This reverts commit 3585008ea98f4a1caf69d10c32a02e1169eeb248. |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 7 | |
| 8 | Change-Id: I808cd01881cd9c968e9a631adccdbaf22501e650 |
| 9 | Signed-off-by: Jackeagle <jackeagle102@gmail.com> |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 10 | --- |
| 11 | Android.bp | 8 - |
| 12 | VoldNativeService.cpp | 4 +- |
| 13 | VoldNativeService.h | 2 +- |
| 14 | binder/android/os/IVold.aidl | 2 +- |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 15 | cryptfs.cpp | 638 +++-------------------------------- |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 16 | cryptfs.h | 10 +- |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 17 | 6 files changed, 50 insertions(+), 614 deletions(-) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 18 | |
| 19 | diff --git a/Android.bp b/Android.bp |
| 20 | index ffb139e..48dfaaf 100644 |
| 21 | --- a/Android.bp |
| 22 | +++ b/Android.bp |
| 23 | @@ -140,11 +140,6 @@ cc_library_static { |
| 24 | "libarcobbvolume", |
| 25 | ], |
| 26 | }, |
| 27 | - device_support_hwfde: { |
| 28 | - cflags: ["-DCONFIG_HW_DISK_ENCRYPTION"], |
| 29 | - header_libs: ["libcryptfs_hw_headers"], |
| 30 | - shared_libs: ["libcryptfs_hw"], |
| 31 | - }, |
| 32 | }, |
| 33 | } |
| 34 | |
| 35 | @@ -164,9 +159,6 @@ cc_binary { |
| 36 | "libarcobbvolume", |
| 37 | ], |
| 38 | }, |
| 39 | - device_support_hwfde: { |
| 40 | - shared_libs: ["libcryptfs_hw"], |
| 41 | - }, |
| 42 | }, |
| 43 | init_rc: [ |
| 44 | "vold.rc", |
| 45 | diff --git a/VoldNativeService.cpp b/VoldNativeService.cpp |
| 46 | index 6d6c6ec..81523c6 100644 |
| 47 | --- a/VoldNativeService.cpp |
| 48 | +++ b/VoldNativeService.cpp |
| 49 | @@ -581,11 +581,11 @@ binder::Status VoldNativeService::fdeEnable(int32_t passwordType, |
| 50 | } |
| 51 | |
| 52 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
| 53 | - const std::string& currentPassword, const std::string& password) { |
| 54 | + const std::string& password) { |
| 55 | ENFORCE_UID(AID_SYSTEM); |
| 56 | ACQUIRE_CRYPT_LOCK; |
| 57 | |
| 58 | - return translate(cryptfs_changepw(passwordType, currentPassword.c_str(), password.c_str())); |
| 59 | + return translate(cryptfs_changepw(passwordType, password.c_str())); |
| 60 | } |
| 61 | |
| 62 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
| 63 | diff --git a/VoldNativeService.h b/VoldNativeService.h |
| 64 | index da8c660..2e90101 100644 |
| 65 | --- a/VoldNativeService.h |
| 66 | +++ b/VoldNativeService.h |
| 67 | @@ -82,7 +82,7 @@ public: |
| 68 | binder::Status fdeEnable(int32_t passwordType, |
| 69 | const std::string& password, int32_t encryptionFlags); |
| 70 | binder::Status fdeChangePassword(int32_t passwordType, |
| 71 | - const std::string& currentPassword, const std::string& password); |
| 72 | + const std::string& password); |
| 73 | binder::Status fdeVerifyPassword(const std::string& password); |
| 74 | binder::Status fdeGetField(const std::string& key, std::string* _aidl_return); |
| 75 | binder::Status fdeSetField(const std::string& key, const std::string& value); |
| 76 | diff --git a/binder/android/os/IVold.aidl b/binder/android/os/IVold.aidl |
| 77 | index 9f5b21a..f386889 100644 |
| 78 | --- a/binder/android/os/IVold.aidl |
| 79 | +++ b/binder/android/os/IVold.aidl |
| 80 | @@ -65,7 +65,7 @@ interface IVold { |
| 81 | void fdeRestart(); |
| 82 | int fdeComplete(); |
| 83 | void fdeEnable(int passwordType, @utf8InCpp String password, int encryptionFlags); |
| 84 | - void fdeChangePassword(int passwordType, @utf8InCpp String currentPassword, @utf8InCpp String password); |
| 85 | + void fdeChangePassword(int passwordType, @utf8InCpp String password); |
| 86 | void fdeVerifyPassword(@utf8InCpp String password); |
| 87 | @utf8InCpp String fdeGetField(@utf8InCpp String key); |
| 88 | void fdeSetField(@utf8InCpp String key, @utf8InCpp String value); |
| 89 | diff --git a/cryptfs.cpp b/cryptfs.cpp |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 90 | index bea9b2f..7aee819 100644 |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 91 | --- a/cryptfs.cpp |
| 92 | +++ b/cryptfs.cpp |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 93 | @@ -66,9 +66,6 @@ |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 94 | #include "android-base/properties.h" |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 95 | #include "android-base/stringprintf.h" |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 96 | #include <bootloader_message/bootloader_message.h> |
| 97 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 98 | -#include <cryptfs_hw.h> |
| 99 | -#endif |
| 100 | extern "C" { |
| 101 | #include <crypto_scrypt.h> |
| 102 | } |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 103 | @@ -94,7 +91,6 @@ static_assert(INTERMEDIATE_BUF_SIZE == SCRYPT_LEN, |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 104 | |
| 105 | #define KEY_IN_FOOTER "footer" |
| 106 | |
| 107 | -#define DEFAULT_HEX_PASSWORD "64656661756c745f70617373776f7264" |
| 108 | #define DEFAULT_PASSWORD "default_password" |
| 109 | |
| 110 | #define CRYPTO_BLOCK_DEVICE "userdata" |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 111 | @@ -110,7 +106,6 @@ static_assert(INTERMEDIATE_BUF_SIZE == SCRYPT_LEN, |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 112 | #define RSA_KEY_SIZE_BYTES (RSA_KEY_SIZE / 8) |
| 113 | #define RSA_EXPONENT 0x10001 |
| 114 | #define KEYMASTER_CRYPTFS_RATE_LIMIT 1 // Maximum one try per second |
| 115 | -#define KEY_LEN_BYTES 16 |
| 116 | |
| 117 | #define RETRY_MOUNT_ATTEMPTS 10 |
| 118 | #define RETRY_MOUNT_DELAY_SECONDS 1 |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 119 | @@ -124,151 +119,6 @@ static char *saved_mount_point; |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 120 | static int master_key_saved = 0; |
| 121 | static struct crypt_persist_data *persist_data = NULL; |
| 122 | |
| 123 | -static int previous_type; |
| 124 | - |
| 125 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 126 | -static int scrypt_keymaster(const char *passwd, const unsigned char *salt, |
| 127 | - unsigned char *ikey, void *params); |
| 128 | -static void convert_key_to_hex_ascii(const unsigned char *master_key, |
| 129 | - unsigned int keysize, char *master_key_ascii); |
| 130 | -static int put_crypt_ftr_and_key(struct crypt_mnt_ftr *crypt_ftr); |
| 131 | -static int test_mount_hw_encrypted_fs(struct crypt_mnt_ftr* crypt_ftr, |
| 132 | - const char *passwd, const char *mount_point, const char *label); |
| 133 | -int cryptfs_changepw_hw_fde(int crypt_type, const char *currentpw, |
| 134 | - const char *newpw); |
| 135 | -int cryptfs_check_passwd_hw(char *passwd); |
| 136 | -int cryptfs_get_master_key(struct crypt_mnt_ftr* ftr, const char* password, |
| 137 | - unsigned char* master_key); |
| 138 | - |
| 139 | -static void convert_key_to_hex_ascii_for_upgrade(const unsigned char *master_key, |
| 140 | - unsigned int keysize, char *master_key_ascii) |
| 141 | -{ |
| 142 | - unsigned int i, a; |
| 143 | - unsigned char nibble; |
| 144 | - |
| 145 | - for (i = 0, a = 0; i < keysize; i++, a += 2) { |
| 146 | - /* For each byte, write out two ascii hex digits */ |
| 147 | - nibble = (master_key[i] >> 4) & 0xf; |
| 148 | - master_key_ascii[a] = nibble + (nibble > 9 ? 0x57 : 0x30); |
| 149 | - |
| 150 | - nibble = master_key[i] & 0xf; |
| 151 | - master_key_ascii[a + 1] = nibble + (nibble > 9 ? 0x57 : 0x30); |
| 152 | - } |
| 153 | - |
| 154 | - /* Add the null termination */ |
| 155 | - master_key_ascii[a] = '\0'; |
| 156 | -} |
| 157 | - |
| 158 | -static int get_keymaster_hw_fde_passwd(const char* passwd, unsigned char* newpw, |
| 159 | - unsigned char* salt, |
| 160 | - const struct crypt_mnt_ftr *ftr) |
| 161 | -{ |
| 162 | - /* if newpw updated, return 0 |
| 163 | - * if newpw not updated return -1 |
| 164 | - */ |
| 165 | - int rc = -1; |
| 166 | - |
| 167 | - if (should_use_keymaster()) { |
| 168 | - if (scrypt_keymaster(passwd, salt, newpw, (void*)ftr)) { |
| 169 | - SLOGE("scrypt failed"); |
| 170 | - } else { |
| 171 | - rc = 0; |
| 172 | - } |
| 173 | - } |
| 174 | - |
| 175 | - return rc; |
| 176 | -} |
| 177 | - |
| 178 | -static int verify_hw_fde_passwd(const char *passwd, struct crypt_mnt_ftr* crypt_ftr) |
| 179 | -{ |
| 180 | - unsigned char newpw[32] = {0}; |
| 181 | - int key_index; |
| 182 | - if (get_keymaster_hw_fde_passwd(passwd, newpw, crypt_ftr->salt, crypt_ftr)) |
| 183 | - key_index = set_hw_device_encryption_key(passwd, |
| 184 | - (char*) crypt_ftr->crypto_type_name); |
| 185 | - else |
| 186 | - key_index = set_hw_device_encryption_key((const char*)newpw, |
| 187 | - (char*) crypt_ftr->crypto_type_name); |
| 188 | - return key_index; |
| 189 | -} |
| 190 | - |
| 191 | -static int verify_and_update_hw_fde_passwd(const char *passwd, |
| 192 | - struct crypt_mnt_ftr* crypt_ftr) |
| 193 | -{ |
| 194 | - char* new_passwd = NULL; |
| 195 | - unsigned char newpw[32] = {0}; |
| 196 | - int key_index = -1; |
| 197 | - int passwd_updated = -1; |
| 198 | - int ascii_passwd_updated = (crypt_ftr->flags & CRYPT_ASCII_PASSWORD_UPDATED); |
| 199 | - |
| 200 | - key_index = verify_hw_fde_passwd(passwd, crypt_ftr); |
| 201 | - if (key_index < 0) { |
| 202 | - ++crypt_ftr->failed_decrypt_count; |
| 203 | - |
| 204 | - if (ascii_passwd_updated) { |
| 205 | - SLOGI("Ascii password was updated"); |
| 206 | - } else { |
| 207 | - /* Code in else part would execute only once: |
| 208 | - * When device is upgraded from L->M release. |
| 209 | - * Once upgraded, code flow should never come here. |
| 210 | - * L release passed actual password in hex, so try with hex |
| 211 | - * Each nible of passwd was encoded as a byte, so allocate memory |
| 212 | - * twice of password len plus one more byte for null termination |
| 213 | - */ |
| 214 | - if (crypt_ftr->crypt_type == CRYPT_TYPE_DEFAULT) { |
| 215 | - new_passwd = (char*)malloc(strlen(DEFAULT_HEX_PASSWORD) + 1); |
| 216 | - if (new_passwd == NULL) { |
| 217 | - SLOGE("System out of memory. Password verification incomplete"); |
| 218 | - goto out; |
| 219 | - } |
| 220 | - strlcpy(new_passwd, DEFAULT_HEX_PASSWORD, strlen(DEFAULT_HEX_PASSWORD) + 1); |
| 221 | - } else { |
| 222 | - new_passwd = (char*)malloc(strlen(passwd) * 2 + 1); |
| 223 | - if (new_passwd == NULL) { |
| 224 | - SLOGE("System out of memory. Password verification incomplete"); |
| 225 | - goto out; |
| 226 | - } |
| 227 | - convert_key_to_hex_ascii_for_upgrade((const unsigned char*)passwd, |
| 228 | - strlen(passwd), new_passwd); |
| 229 | - } |
| 230 | - key_index = set_hw_device_encryption_key((const char*)new_passwd, |
| 231 | - (char*) crypt_ftr->crypto_type_name); |
| 232 | - if (key_index >=0) { |
| 233 | - crypt_ftr->failed_decrypt_count = 0; |
| 234 | - SLOGI("Hex password verified...will try to update with Ascii value"); |
| 235 | - /* Before updating password, tie that with keymaster to tie with ROT */ |
| 236 | - |
| 237 | - if (get_keymaster_hw_fde_passwd(passwd, newpw, |
| 238 | - crypt_ftr->salt, crypt_ftr)) { |
| 239 | - passwd_updated = update_hw_device_encryption_key(new_passwd, |
| 240 | - passwd, (char*)crypt_ftr->crypto_type_name); |
| 241 | - } else { |
| 242 | - passwd_updated = update_hw_device_encryption_key(new_passwd, |
| 243 | - (const char*)newpw, (char*)crypt_ftr->crypto_type_name); |
| 244 | - } |
| 245 | - |
| 246 | - if (passwd_updated >= 0) { |
| 247 | - crypt_ftr->flags |= CRYPT_ASCII_PASSWORD_UPDATED; |
| 248 | - SLOGI("Ascii password recorded and updated"); |
| 249 | - } else { |
| 250 | - SLOGI("Passwd verified, could not update...Will try next time"); |
| 251 | - } |
| 252 | - } else { |
| 253 | - ++crypt_ftr->failed_decrypt_count; |
| 254 | - } |
| 255 | - free(new_passwd); |
| 256 | - } |
| 257 | - } else { |
| 258 | - if (!ascii_passwd_updated) |
| 259 | - crypt_ftr->flags |= CRYPT_ASCII_PASSWORD_UPDATED; |
| 260 | - } |
| 261 | -out: |
| 262 | - // update footer before leaving |
| 263 | - put_crypt_ftr_and_key(crypt_ftr); |
| 264 | - return key_index; |
| 265 | -} |
| 266 | -#endif |
| 267 | - |
| 268 | /* Should we use keymaster? */ |
| 269 | static int keymaster_check_compatibility() |
| 270 | { |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 271 | @@ -1161,40 +1011,21 @@ static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr, |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 272 | tgt->status = 0; |
| 273 | tgt->sector_start = 0; |
| 274 | tgt->length = crypt_ftr->fs_size; |
| 275 | + strlcpy(tgt->target_type, "crypt", DM_MAX_TYPE_NAME); |
| 276 | + |
| 277 | crypt_params = buffer + sizeof(struct dm_ioctl) + sizeof(struct dm_target_spec); |
| 278 | + convert_key_to_hex_ascii(master_key, crypt_ftr->keysize, master_key_ascii); |
| 279 | + |
| 280 | buff_offset = crypt_params - buffer; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 281 | + |
| 282 | SLOGI( |
| 283 | "Creating crypto dev \"%s\"; cipher=%s, keysize=%u, real_dev=%s, len=%llu, params=\"%s\"\n", |
| 284 | name, crypt_ftr->crypto_type_name, crypt_ftr->keysize, real_blk_name, tgt->length * 512, |
| 285 | extra_params); |
| 286 | - |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 287 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 288 | - if(is_hw_disk_encryption((char*)crypt_ftr->crypto_type_name)) { |
| 289 | - strlcpy(tgt->target_type, "req-crypt",DM_MAX_TYPE_NAME); |
| 290 | - if (is_ice_enabled()) |
| 291 | - convert_key_to_hex_ascii(master_key, sizeof(int), master_key_ascii); |
| 292 | - else |
| 293 | - convert_key_to_hex_ascii(master_key, crypt_ftr->keysize, master_key_ascii); |
| 294 | - } |
| 295 | - else { |
| 296 | - convert_key_to_hex_ascii(master_key, crypt_ftr->keysize, master_key_ascii); |
| 297 | - strlcpy(tgt->target_type, "crypt", DM_MAX_TYPE_NAME); |
| 298 | - } |
| 299 | - snprintf(crypt_params, sizeof(buffer) - buff_offset, "%s %s 0 %s 0 %s 0", |
| 300 | - crypt_ftr->crypto_type_name, master_key_ascii, |
| 301 | - real_blk_name, extra_params); |
| 302 | - |
| 303 | - SLOGI("target_type = %s", tgt->target_type); |
| 304 | - SLOGI("real_blk_name = %s, extra_params = %s", real_blk_name, extra_params); |
| 305 | -#else |
| 306 | - convert_key_to_hex_ascii(master_key, crypt_ftr->keysize, master_key_ascii); |
| 307 | - strlcpy(tgt->target_type, "crypt", DM_MAX_TYPE_NAME); |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 308 | |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 309 | snprintf(crypt_params, sizeof(buffer) - buff_offset, "%s %s 0 %s 0 %s", |
| 310 | crypt_ftr->crypto_type_name, master_key_ascii, real_blk_name, |
| 311 | extra_params); |
| 312 | -#endif |
| 313 | - |
| 314 | crypt_params += strlen(crypt_params) + 1; |
| 315 | crypt_params = (char *) (((unsigned long)crypt_params + 7) & ~8); /* Align to an 8 byte boundary */ |
| 316 | tgt->next = crypt_params - buffer; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 317 | @@ -1214,6 +1045,7 @@ static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr, |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
| 321 | + |
| 322 | static int get_dm_crypt_version(int fd, const char *name, int *version) |
| 323 | { |
| 324 | char buffer[DM_CRYPT_BUF_SIZE]; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 325 | @@ -1233,11 +1065,7 @@ static int get_dm_crypt_version(int fd, const char *name, int *version) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 326 | */ |
| 327 | v = (struct dm_target_versions *) &buffer[sizeof(struct dm_ioctl)]; |
| 328 | while (v->next) { |
| 329 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 330 | - if (! strcmp(v->name, "crypt") || ! strcmp(v->name, "req-crypt")) { |
| 331 | -#else |
| 332 | if (! strcmp(v->name, "crypt")) { |
| 333 | -#endif |
| 334 | /* We found the crypt driver, return the version, and get out */ |
| 335 | version[0] = v->version[0]; |
| 336 | version[1] = v->version[1]; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 337 | @@ -1250,7 +1078,6 @@ static int get_dm_crypt_version(int fd, const char *name, int *version) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 338 | return -1; |
| 339 | } |
| 340 | |
| 341 | -#ifndef CONFIG_HW_DISK_ENCRYPTION |
| 342 | static std::string extra_params_as_string(const std::vector<std::string>& extra_params_vec) { |
| 343 | if (extra_params_vec.empty()) return ""; |
| 344 | std::string extra_params = std::to_string(extra_params_vec.size()); |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 345 | @@ -1260,7 +1087,6 @@ static std::string extra_params_as_string(const std::vector<std::string>& extra_ |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 346 | } |
| 347 | return extra_params; |
| 348 | } |
| 349 | -#endif |
| 350 | |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 351 | /* |
| 352 | * If the ro.crypto.fde_sector_size system property is set, append the |
| 353 | @@ -1306,13 +1132,7 @@ static int create_crypto_blk_dev(struct crypt_mnt_ftr* crypt_ftr, const unsigned |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 354 | int retval = -1; |
| 355 | int version[3]; |
| 356 | int load_count; |
| 357 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 358 | - char encrypted_state[PROPERTY_VALUE_MAX] = {0}; |
| 359 | - char progress[PROPERTY_VALUE_MAX] = {0}; |
| 360 | - const char *extra_params; |
| 361 | -#else |
| 362 | std::vector<std::string> extra_params_vec; |
| 363 | -#endif |
| 364 | |
| 365 | if ((fd = open("/dev/device-mapper", O_RDWR | O_CLOEXEC)) < 0) { |
| 366 | SLOGE("Cannot open device-mapper\n"); |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 367 | @@ -1337,45 +1157,6 @@ static int create_crypto_blk_dev(struct crypt_mnt_ftr* crypt_ftr, const unsigned |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 368 | minor = (io->dev & 0xff) | ((io->dev >> 12) & 0xfff00); |
| 369 | snprintf(crypto_blk_name, MAXPATHLEN, "/dev/block/dm-%u", minor); |
| 370 | |
| 371 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 372 | - if(is_hw_disk_encryption((char*)crypt_ftr->crypto_type_name)) { |
| 373 | - /* Set fde_enabled if either FDE completed or in-progress */ |
| 374 | - property_get("ro.crypto.state", encrypted_state, ""); /* FDE completed */ |
| 375 | - property_get("vold.encrypt_progress", progress, ""); /* FDE in progress */ |
| 376 | - if (!strcmp(encrypted_state, "encrypted") || strcmp(progress, "")) { |
| 377 | - if (is_ice_enabled()) { |
| 378 | - if (flags & CREATE_CRYPTO_BLK_DEV_FLAGS_ALLOW_ENCRYPT_OVERRIDE) |
| 379 | - extra_params = "fde_enabled ice allow_encrypt_override"; |
| 380 | - else |
| 381 | - extra_params = "fde_enabled ice"; |
| 382 | - } else { |
| 383 | - if (flags & CREATE_CRYPTO_BLK_DEV_FLAGS_ALLOW_ENCRYPT_OVERRIDE) |
| 384 | - extra_params = "fde_enabled allow_encrypt_override"; |
| 385 | - else |
| 386 | - extra_params = "fde_enabled"; |
| 387 | - } |
| 388 | - } else { |
| 389 | - if (flags & CREATE_CRYPTO_BLK_DEV_FLAGS_ALLOW_ENCRYPT_OVERRIDE) |
| 390 | - extra_params = "fde_enabled allow_encrypt_override"; |
| 391 | - else |
| 392 | - extra_params = "fde_enabled"; |
| 393 | - } |
| 394 | - } else { |
| 395 | - extra_params = ""; |
| 396 | - if (! get_dm_crypt_version(fd, name, version)) { |
| 397 | - /* Support for allow_discards was added in version 1.11.0 */ |
| 398 | - if ((version[0] >= 2) || ((version[0] == 1) && (version[1] >= 11))) { |
| 399 | - if (flags & CREATE_CRYPTO_BLK_DEV_FLAGS_ALLOW_ENCRYPT_OVERRIDE) |
| 400 | - extra_params = "2 allow_discards allow_encrypt_override"; |
| 401 | - else |
| 402 | - extra_params = "1 allow_discards"; |
| 403 | - SLOGI("Enabling support for allow_discards in dmcrypt.\n"); |
| 404 | - } |
| 405 | - } |
| 406 | - } |
| 407 | - load_count = load_crypto_mapping_table(crypt_ftr, master_key, real_blk_name, name, fd, |
| 408 | - extra_params); |
| 409 | -#else |
| 410 | if (!get_dm_crypt_version(fd, name, version)) { |
| 411 | /* Support for allow_discards was added in version 1.11.0 */ |
| 412 | if ((version[0] >= 2) || ((version[0] == 1) && (version[1] >= 11))) { |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 413 | @@ -1391,7 +1172,6 @@ static int create_crypto_blk_dev(struct crypt_mnt_ftr* crypt_ftr, const unsigned |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 414 | } |
| 415 | load_count = load_crypto_mapping_table(crypt_ftr, master_key, real_blk_name, name, fd, |
| 416 | extra_params_as_string(extra_params_vec).c_str()); |
| 417 | -#endif |
| 418 | if (load_count < 0) { |
| 419 | SLOGE("Cannot load dm-crypt mapping table.\n"); |
| 420 | goto errout; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 421 | @@ -1526,8 +1306,7 @@ static int scrypt_keymaster(const char *passwd, const unsigned char *salt, |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 422 | static int encrypt_master_key(const char *passwd, const unsigned char *salt, |
| 423 | const unsigned char *decrypted_master_key, |
| 424 | unsigned char *encrypted_master_key, |
| 425 | - struct crypt_mnt_ftr *crypt_ftr, |
| 426 | - bool create_keymaster_key) |
| 427 | + struct crypt_mnt_ftr *crypt_ftr) |
| 428 | { |
| 429 | unsigned char ikey[INTERMEDIATE_BUF_SIZE] = { 0 }; |
| 430 | EVP_CIPHER_CTX e_ctx; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 431 | @@ -1539,7 +1318,7 @@ static int encrypt_master_key(const char *passwd, const unsigned char *salt, |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 432 | |
| 433 | switch (crypt_ftr->kdf_type) { |
| 434 | case KDF_SCRYPT_KEYMASTER: |
| 435 | - if (create_keymaster_key && keymaster_create_key(crypt_ftr)) { |
| 436 | + if (keymaster_create_key(crypt_ftr)) { |
| 437 | SLOGE("keymaster_create_key failed"); |
| 438 | return -1; |
| 439 | } |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 440 | @@ -1709,13 +1488,13 @@ static int create_encrypted_random_key(const char *passwd, unsigned char *master |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 441 | close(fd); |
| 442 | |
| 443 | /* Now encrypt it with the password */ |
| 444 | - return encrypt_master_key(passwd, salt, key_buf, master_key, crypt_ftr, true); |
| 445 | + return encrypt_master_key(passwd, salt, key_buf, master_key, crypt_ftr); |
| 446 | } |
| 447 | |
| 448 | int wait_and_unmount(const char *mountpoint, bool kill) |
| 449 | { |
| 450 | int i, err, rc; |
| 451 | -#define WAIT_UNMOUNT_COUNT 200 |
| 452 | +#define WAIT_UNMOUNT_COUNT 20 |
| 453 | |
| 454 | /* Now umount the tmpfs filesystem */ |
| 455 | for (i=0; i<WAIT_UNMOUNT_COUNT; i++) { |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 456 | @@ -1732,18 +1511,18 @@ int wait_and_unmount(const char *mountpoint, bool kill) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 457 | |
| 458 | err = errno; |
| 459 | |
| 460 | - /* If allowed, be increasingly aggressive before the last 2 seconds */ |
| 461 | + /* If allowed, be increasingly aggressive before the last two retries */ |
| 462 | if (kill) { |
| 463 | - if (i == (WAIT_UNMOUNT_COUNT - 30)) { |
| 464 | + if (i == (WAIT_UNMOUNT_COUNT - 3)) { |
| 465 | SLOGW("sending SIGHUP to processes with open files\n"); |
| 466 | android::vold::KillProcessesWithOpenFiles(mountpoint, SIGTERM); |
| 467 | - } else if (i == (WAIT_UNMOUNT_COUNT - 20)) { |
| 468 | + } else if (i == (WAIT_UNMOUNT_COUNT - 2)) { |
| 469 | SLOGW("sending SIGKILL to processes with open files\n"); |
| 470 | android::vold::KillProcessesWithOpenFiles(mountpoint, SIGKILL); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | - usleep(100000); |
| 475 | + sleep(1); |
| 476 | } |
| 477 | |
| 478 | if (i < WAIT_UNMOUNT_COUNT) { |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 479 | @@ -1910,17 +1689,6 @@ static int cryptfs_restart_internal(int restart_main) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 480 | cryptfs_reboot(RebootType::reboot); |
| 481 | } |
| 482 | } else { |
| 483 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 484 | - if (--retries) { |
| 485 | - sleep(RETRY_MOUNT_DELAY_SECONDS); |
| 486 | - } else { |
| 487 | - SLOGE("Failed to mount decrypted data"); |
| 488 | - cryptfs_set_corrupt(); |
| 489 | - cryptfs_trigger_restart_min_framework(); |
| 490 | - SLOGI("Started framework to offer wipe"); |
| 491 | - return -1; |
| 492 | - } |
| 493 | -#else |
| 494 | SLOGE("Failed to mount decrypted data"); |
| 495 | cryptfs_set_corrupt(); |
| 496 | cryptfs_trigger_restart_min_framework(); |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 497 | @@ -1929,7 +1697,6 @@ static int cryptfs_restart_internal(int restart_main) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 498 | SLOGE("Failed to setexeccon"); |
| 499 | } |
| 500 | return -1; |
| 501 | -#endif |
| 502 | } |
| 503 | } |
| 504 | if (setexeccon(NULL)) { |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 505 | @@ -2024,66 +1791,6 @@ static int do_crypto_complete(const char *mount_point) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 506 | return CRYPTO_COMPLETE_ENCRYPTED; |
| 507 | } |
| 508 | |
| 509 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 510 | -static int test_mount_hw_encrypted_fs(struct crypt_mnt_ftr* crypt_ftr, |
| 511 | - const char *passwd, const char *mount_point, const char *label) |
| 512 | -{ |
| 513 | - /* Allocate enough space for a 256 bit key, but we may use less */ |
| 514 | - unsigned char decrypted_master_key[32]; |
| 515 | - char crypto_blkdev[MAXPATHLEN]; |
| 516 | - char real_blkdev[MAXPATHLEN]; |
| 517 | - unsigned int orig_failed_decrypt_count; |
| 518 | - int rc = 0; |
| 519 | - |
| 520 | - SLOGD("crypt_ftr->fs_size = %lld\n", crypt_ftr->fs_size); |
| 521 | - orig_failed_decrypt_count = crypt_ftr->failed_decrypt_count; |
| 522 | - |
| 523 | - fs_mgr_get_crypt_info(fstab_default, 0, real_blkdev, sizeof(real_blkdev)); |
| 524 | - |
| 525 | - int key_index = 0; |
| 526 | - if(is_hw_disk_encryption((char*)crypt_ftr->crypto_type_name)) { |
| 527 | - key_index = verify_and_update_hw_fde_passwd(passwd, crypt_ftr); |
| 528 | - if (key_index < 0) { |
| 529 | - rc = crypt_ftr->failed_decrypt_count; |
| 530 | - goto errout; |
| 531 | - } |
| 532 | - else { |
| 533 | - if (is_ice_enabled()) { |
| 534 | - if (create_crypto_blk_dev(crypt_ftr, (unsigned char*)&key_index, |
| 535 | - real_blkdev, crypto_blkdev, label, 0)) { |
| 536 | - SLOGE("Error creating decrypted block device"); |
| 537 | - rc = -1; |
| 538 | - goto errout; |
| 539 | - } |
| 540 | - } else { |
| 541 | - if (create_crypto_blk_dev(crypt_ftr, decrypted_master_key, |
| 542 | - real_blkdev, crypto_blkdev, label, 0)) { |
| 543 | - SLOGE("Error creating decrypted block device"); |
| 544 | - rc = -1; |
| 545 | - goto errout; |
| 546 | - } |
| 547 | - } |
| 548 | - } |
| 549 | - } |
| 550 | - |
| 551 | - if (rc == 0) { |
| 552 | - crypt_ftr->failed_decrypt_count = 0; |
| 553 | - if (orig_failed_decrypt_count != 0) { |
| 554 | - put_crypt_ftr_and_key(crypt_ftr); |
| 555 | - } |
| 556 | - |
| 557 | - /* Save the name of the crypto block device |
| 558 | - * so we can mount it when restarting the framework. */ |
| 559 | - property_set("ro.crypto.fs_crypto_blkdev", crypto_blkdev); |
| 560 | - master_key_saved = 1; |
| 561 | - } |
| 562 | - |
| 563 | - errout: |
| 564 | - return rc; |
| 565 | -} |
| 566 | -#endif |
| 567 | - |
| 568 | - |
| 569 | static int test_mount_encrypted_fs(struct crypt_mnt_ftr* crypt_ftr, |
| 570 | const char *passwd, const char *mount_point, const char *label) |
| 571 | { |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 572 | @@ -2190,7 +1897,7 @@ static int test_mount_encrypted_fs(struct crypt_mnt_ftr* crypt_ftr, |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 573 | |
| 574 | if (upgrade) { |
| 575 | rc = encrypt_master_key(passwd, crypt_ftr->salt, saved_master_key, |
| 576 | - crypt_ftr->master_key, crypt_ftr, true); |
| 577 | + crypt_ftr->master_key, crypt_ftr); |
| 578 | if (!rc) { |
| 579 | rc = put_crypt_ftr_and_key(crypt_ftr); |
| 580 | } |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 581 | @@ -2287,66 +1994,6 @@ int check_unmounted_and_get_ftr(struct crypt_mnt_ftr* crypt_ftr) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 586 | -int cryptfs_check_passwd_hw(const char* passwd) |
| 587 | -{ |
| 588 | - struct crypt_mnt_ftr crypt_ftr; |
| 589 | - int rc; |
| 590 | - unsigned char master_key[KEY_LEN_BYTES]; |
| 591 | - |
| 592 | - /* get key */ |
| 593 | - if (get_crypt_ftr_and_key(&crypt_ftr)) { |
| 594 | - SLOGE("Error getting crypt footer and key"); |
| 595 | - return -1; |
| 596 | - } |
| 597 | - |
| 598 | - /* |
| 599 | - * in case of manual encryption (from GUI), the encryption is done with |
| 600 | - * default password |
| 601 | - */ |
| 602 | - if (crypt_ftr.flags & CRYPT_FORCE_COMPLETE) { |
| 603 | - /* compare scrypted_intermediate_key with stored scrypted_intermediate_key |
| 604 | - * which was created with actual password before reboot. |
| 605 | - */ |
| 606 | - rc = cryptfs_get_master_key(&crypt_ftr, passwd, master_key); |
| 607 | - if (rc) { |
| 608 | - SLOGE("password doesn't match"); |
| 609 | - rc = ++crypt_ftr.failed_decrypt_count; |
| 610 | - put_crypt_ftr_and_key(&crypt_ftr); |
| 611 | - return rc; |
| 612 | - } |
| 613 | - |
| 614 | - rc = test_mount_hw_encrypted_fs(&crypt_ftr, DEFAULT_PASSWORD, |
| 615 | - DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE); |
| 616 | - |
| 617 | - if (rc) { |
| 618 | - SLOGE("Default password did not match on reboot encryption"); |
| 619 | - return rc; |
| 620 | - } |
| 621 | - |
| 622 | - crypt_ftr.flags &= ~CRYPT_FORCE_COMPLETE; |
| 623 | - put_crypt_ftr_and_key(&crypt_ftr); |
| 624 | - rc = cryptfs_changepw(crypt_ftr.crypt_type, DEFAULT_PASSWORD, passwd); |
| 625 | - if (rc) { |
| 626 | - SLOGE("Could not change password on reboot encryption"); |
| 627 | - return rc; |
| 628 | - } |
| 629 | - } else |
| 630 | - rc = test_mount_hw_encrypted_fs(&crypt_ftr, passwd, |
| 631 | - DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE); |
| 632 | - |
| 633 | - if (crypt_ftr.crypt_type != CRYPT_TYPE_DEFAULT) { |
| 634 | - cryptfs_clear_password(); |
| 635 | - password = strdup(passwd); |
| 636 | - struct timespec now; |
| 637 | - clock_gettime(CLOCK_BOOTTIME, &now); |
| 638 | - password_expiry_time = now.tv_sec + password_max_age_seconds; |
| 639 | - } |
| 640 | - |
| 641 | - return rc; |
| 642 | -} |
| 643 | -#endif |
| 644 | - |
| 645 | int cryptfs_check_passwd(const char *passwd) |
| 646 | { |
| 647 | SLOGI("cryptfs_check_passwd"); |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 648 | @@ -2364,14 +2011,8 @@ int cryptfs_check_passwd(const char *passwd) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 649 | return rc; |
| 650 | } |
| 651 | |
| 652 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 653 | - if (is_hw_disk_encryption((char*)crypt_ftr.crypto_type_name)) |
| 654 | - return cryptfs_check_passwd_hw(passwd); |
| 655 | -#endif |
| 656 | - |
| 657 | rc = test_mount_encrypted_fs(&crypt_ftr, passwd, |
| 658 | DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE); |
| 659 | - |
| 660 | if (rc) { |
| 661 | SLOGE("Password did not match"); |
| 662 | return rc; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 663 | @@ -2392,7 +2033,7 @@ int cryptfs_check_passwd(const char *passwd) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 664 | |
| 665 | crypt_ftr.flags &= ~CRYPT_FORCE_COMPLETE; |
| 666 | put_crypt_ftr_and_key(&crypt_ftr); |
| 667 | - rc = cryptfs_changepw(crypt_ftr.crypt_type, DEFAULT_PASSWORD, passwd); |
| 668 | + rc = cryptfs_changepw(crypt_ftr.crypt_type, passwd); |
| 669 | if (rc) { |
| 670 | SLOGE("Could not change password on reboot encryption"); |
| 671 | return rc; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 672 | @@ -2442,24 +2083,6 @@ int cryptfs_verify_passwd(const char *passwd) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 673 | /* If the device has no password, then just say the password is valid */ |
| 674 | rc = 0; |
| 675 | } else { |
| 676 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 677 | - if(is_hw_disk_encryption((char*)crypt_ftr.crypto_type_name)) { |
| 678 | - if (verify_hw_fde_passwd(passwd, &crypt_ftr) >= 0) |
| 679 | - rc = 0; |
| 680 | - else |
| 681 | - rc = -1; |
| 682 | - } else { |
| 683 | - decrypt_master_key(passwd, decrypted_master_key, &crypt_ftr, 0, 0); |
| 684 | - if (!memcmp(decrypted_master_key, saved_master_key, crypt_ftr.keysize)) { |
| 685 | - /* They match, the password is correct */ |
| 686 | - rc = 0; |
| 687 | - } else { |
| 688 | - /* If incorrect, sleep for a bit to prevent dictionary attacks */ |
| 689 | - sleep(1); |
| 690 | - rc = 1; |
| 691 | - } |
| 692 | - } |
| 693 | -#else |
| 694 | decrypt_master_key(passwd, decrypted_master_key, &crypt_ftr, 0, 0); |
| 695 | if (!memcmp(decrypted_master_key, saved_master_key, crypt_ftr.keysize)) { |
| 696 | /* They match, the password is correct */ |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 697 | @@ -2469,7 +2092,6 @@ int cryptfs_verify_passwd(const char *passwd) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 698 | sleep(1); |
| 699 | rc = 1; |
| 700 | } |
| 701 | -#endif |
| 702 | } |
| 703 | |
| 704 | return rc; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 705 | @@ -2593,12 +2215,6 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) { |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 706 | off64_t previously_encrypted_upto = 0; |
| 707 | bool rebootEncryption = false; |
| 708 | bool onlyCreateHeader = false; |
| 709 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 710 | - unsigned char newpw[32]; |
| 711 | - int key_index = 0; |
| 712 | -#endif |
| 713 | - int index = 0; |
| 714 | - |
| 715 | int fd = -1; |
| 716 | |
| 717 | if (get_crypt_ftr_and_key(&crypt_ftr) == 0) { |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 718 | @@ -2703,6 +2319,30 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) { |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 719 | fclose(breadcrumb); |
| 720 | } |
| 721 | |
| 722 | + /* Do extra work for a better UX when doing the long inplace encryption */ |
| 723 | + if (!onlyCreateHeader) { |
| 724 | + /* Now that /data is unmounted, we need to mount a tmpfs |
| 725 | + * /data, set a property saying we're doing inplace encryption, |
| 726 | + * and restart the framework. |
| 727 | + */ |
| 728 | + if (fs_mgr_do_tmpfs_mount(DATA_MNT_POINT)) { |
| 729 | + goto error_shutting_down; |
| 730 | + } |
| 731 | + /* Tells the framework that inplace encryption is starting */ |
| 732 | + property_set("vold.encrypt_progress", "0"); |
| 733 | + |
| 734 | + /* restart the framework. */ |
| 735 | + /* Create necessary paths on /data */ |
| 736 | + prep_data_fs(); |
| 737 | + |
| 738 | + /* Ugh, shutting down the framework is not synchronous, so until it |
| 739 | + * can be fixed, this horrible hack will wait a moment for it all to |
| 740 | + * shut down before proceeding. Without it, some devices cannot |
| 741 | + * restart the graphics services. |
| 742 | + */ |
| 743 | + sleep(2); |
| 744 | + } |
| 745 | + |
| 746 | /* Start the actual work of making an encrypted filesystem */ |
| 747 | /* Initialize a crypt_mnt_ftr for the partition */ |
| 748 | if (previously_encrypted_upto == 0 && !rebootEncryption) { |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 749 | @@ -2726,11 +2366,7 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) { |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 750 | crypt_ftr.flags |= CRYPT_INCONSISTENT_STATE; |
| 751 | } |
| 752 | crypt_ftr.crypt_type = crypt_type; |
| 753 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 754 | - strlcpy((char *)crypt_ftr.crypto_type_name, "aes-xts", MAX_CRYPTO_TYPE_NAME_LEN); |
| 755 | -#else |
| 756 | strlcpy((char *)crypt_ftr.crypto_type_name, cryptfs_get_crypto_name(), MAX_CRYPTO_TYPE_NAME_LEN); |
| 757 | -#endif |
| 758 | |
| 759 | /* Make an encrypted master key */ |
| 760 | if (create_encrypted_random_key(onlyCreateHeader ? DEFAULT_PASSWORD : passwd, |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 761 | @@ -2745,7 +2381,7 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) { |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 762 | unsigned char encrypted_fake_master_key[MAX_KEY_LEN]; |
| 763 | memset(fake_master_key, 0, sizeof(fake_master_key)); |
| 764 | encrypt_master_key(passwd, crypt_ftr.salt, fake_master_key, |
| 765 | - encrypted_fake_master_key, &crypt_ftr, true); |
| 766 | + encrypted_fake_master_key, &crypt_ftr); |
| 767 | } |
| 768 | |
| 769 | /* Write the key to the end of the partition */ |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 770 | @@ -2766,57 +2402,12 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) { |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
| 774 | - /* When encryption triggered from settings, encryption starts after reboot. |
| 775 | - So set the encryption key when the actual encryption starts. |
| 776 | - */ |
| 777 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 778 | - if (previously_encrypted_upto == 0) { |
| 779 | - if (!rebootEncryption) |
| 780 | - clear_hw_device_encryption_key(); |
| 781 | - |
| 782 | - if (get_keymaster_hw_fde_passwd( |
| 783 | - onlyCreateHeader ? DEFAULT_PASSWORD : passwd, |
| 784 | - newpw, crypt_ftr.salt, &crypt_ftr)) |
| 785 | - key_index = set_hw_device_encryption_key( |
| 786 | - onlyCreateHeader ? DEFAULT_PASSWORD : passwd, |
| 787 | - (char*)crypt_ftr.crypto_type_name); |
| 788 | - else |
| 789 | - key_index = set_hw_device_encryption_key((const char*)newpw, |
| 790 | - (char*) crypt_ftr.crypto_type_name); |
| 791 | - if (key_index < 0) |
| 792 | - goto error_shutting_down; |
| 793 | - |
| 794 | - crypt_ftr.flags |= CRYPT_ASCII_PASSWORD_UPDATED; |
| 795 | - put_crypt_ftr_and_key(&crypt_ftr); |
| 796 | - } |
| 797 | -#endif |
| 798 | - |
| 799 | if (onlyCreateHeader) { |
| 800 | sleep(2); |
| 801 | cryptfs_reboot(RebootType::reboot); |
| 802 | - } else { |
| 803 | - /* Do extra work for a better UX when doing the long inplace encryption */ |
| 804 | - /* Now that /data is unmounted, we need to mount a tmpfs |
| 805 | - * /data, set a property saying we're doing inplace encryption, |
| 806 | - * and restart the framework. |
| 807 | - */ |
| 808 | - if (fs_mgr_do_tmpfs_mount(DATA_MNT_POINT)) { |
| 809 | - goto error_shutting_down; |
| 810 | - } |
| 811 | - /* Tells the framework that inplace encryption is starting */ |
| 812 | - property_set("vold.encrypt_progress", "0"); |
| 813 | - |
| 814 | - /* restart the framework. */ |
| 815 | - /* Create necessary paths on /data */ |
| 816 | - prep_data_fs(); |
| 817 | - |
| 818 | - /* Ugh, shutting down the framework is not synchronous, so until it |
| 819 | - * can be fixed, this horrible hack will wait a moment for it all to |
| 820 | - * shut down before proceeding. Without it, some devices cannot |
| 821 | - * restart the graphics services. |
| 822 | - */ |
| 823 | - sleep(2); |
| 824 | + } |
| 825 | |
| 826 | + if (!no_ui || rebootEncryption) { |
| 827 | /* startup service classes main and late_start */ |
| 828 | property_set("vold.decrypt", "trigger_restart_min_framework"); |
| 829 | SLOGD("Just triggered restart_min_framework\n"); |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 830 | @@ -2829,17 +2420,8 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) { |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | decrypt_master_key(passwd, decrypted_master_key, &crypt_ftr, 0, 0); |
| 834 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 835 | - if (is_hw_disk_encryption((char*)crypt_ftr.crypto_type_name) && is_ice_enabled()) |
| 836 | - create_crypto_blk_dev(&crypt_ftr, (unsigned char*)&key_index, real_blkdev, crypto_blkdev, |
| 837 | - CRYPTO_BLOCK_DEVICE, 0); |
| 838 | - else |
| 839 | - create_crypto_blk_dev(&crypt_ftr, decrypted_master_key, real_blkdev, crypto_blkdev, |
| 840 | - CRYPTO_BLOCK_DEVICE, 0); |
| 841 | -#else |
| 842 | create_crypto_blk_dev(&crypt_ftr, decrypted_master_key, real_blkdev, crypto_blkdev, |
| 843 | CRYPTO_BLOCK_DEVICE, 0); |
| 844 | -#endif |
| 845 | |
| 846 | /* If we are continuing, check checksums match */ |
| 847 | rc = 0; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 848 | @@ -2973,7 +2555,7 @@ int cryptfs_enable_default(int no_ui) { |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 849 | return cryptfs_enable_internal(CRYPT_TYPE_DEFAULT, DEFAULT_PASSWORD, no_ui); |
| 850 | } |
| 851 | |
| 852 | -int cryptfs_changepw(int crypt_type, const char *currentpw, const char *newpw) |
| 853 | +int cryptfs_changepw(int crypt_type, const char *newpw) |
| 854 | { |
| 855 | if (e4crypt_is_native()) { |
| 856 | SLOGE("cryptfs_changepw not valid for file encryption"); |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 857 | @@ -3000,28 +2582,6 @@ int cryptfs_changepw(int crypt_type, const char *currentpw, const char *newpw) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 858 | return -1; |
| 859 | } |
| 860 | |
| 861 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 862 | - if(is_hw_disk_encryption((char*)crypt_ftr.crypto_type_name)) |
| 863 | - return cryptfs_changepw_hw_fde(crypt_type, currentpw, newpw); |
| 864 | - else { |
| 865 | - crypt_ftr.crypt_type = crypt_type; |
| 866 | - |
| 867 | - rc = encrypt_master_key(crypt_type == CRYPT_TYPE_DEFAULT ? |
| 868 | - DEFAULT_PASSWORD : newpw, |
| 869 | - crypt_ftr.salt, |
| 870 | - saved_master_key, |
| 871 | - crypt_ftr.master_key, |
| 872 | - &crypt_ftr, false); |
| 873 | - if (rc) { |
| 874 | - SLOGE("Encrypt master key failed: %d", rc); |
| 875 | - return -1; |
| 876 | - } |
| 877 | - /* save the key */ |
| 878 | - put_crypt_ftr_and_key(&crypt_ftr); |
| 879 | - |
| 880 | - return 0; |
| 881 | - } |
| 882 | -#else |
| 883 | crypt_ftr.crypt_type = crypt_type; |
| 884 | |
| 885 | rc = encrypt_master_key(crypt_type == CRYPT_TYPE_DEFAULT ? DEFAULT_PASSWORD |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 886 | @@ -3029,7 +2589,7 @@ int cryptfs_changepw(int crypt_type, const char *currentpw, const char *newpw) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 887 | crypt_ftr.salt, |
| 888 | saved_master_key, |
| 889 | crypt_ftr.master_key, |
| 890 | - &crypt_ftr, false); |
| 891 | + &crypt_ftr); |
| 892 | if (rc) { |
| 893 | SLOGE("Encrypt master key failed: %d", rc); |
| 894 | return -1; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 895 | @@ -3037,57 +2597,8 @@ int cryptfs_changepw(int crypt_type, const char *currentpw, const char *newpw) |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 896 | /* save the key */ |
| 897 | put_crypt_ftr_and_key(&crypt_ftr); |
| 898 | |
| 899 | - return 0; |
| 900 | -#endif |
| 901 | -} |
| 902 | - |
| 903 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 904 | -int cryptfs_changepw_hw_fde(int crypt_type, const char *currentpw, const char *newpw) |
| 905 | -{ |
| 906 | - struct crypt_mnt_ftr crypt_ftr; |
| 907 | - int rc; |
| 908 | - int previous_type; |
| 909 | - |
| 910 | - /* get key */ |
| 911 | - if (get_crypt_ftr_and_key(&crypt_ftr)) { |
| 912 | - SLOGE("Error getting crypt footer and key"); |
| 913 | - return -1; |
| 914 | - } |
| 915 | - |
| 916 | - previous_type = crypt_ftr.crypt_type; |
| 917 | - int rc1; |
| 918 | - unsigned char tmp_curpw[32] = {0}; |
| 919 | - rc1 = get_keymaster_hw_fde_passwd(crypt_ftr.crypt_type == CRYPT_TYPE_DEFAULT ? |
| 920 | - DEFAULT_PASSWORD : currentpw, tmp_curpw, |
| 921 | - crypt_ftr.salt, &crypt_ftr); |
| 922 | - |
| 923 | - crypt_ftr.crypt_type = crypt_type; |
| 924 | - |
| 925 | - int ret, rc2; |
| 926 | - unsigned char tmp_newpw[32] = {0}; |
| 927 | - |
| 928 | - rc2 = get_keymaster_hw_fde_passwd(crypt_type == CRYPT_TYPE_DEFAULT ? |
| 929 | - DEFAULT_PASSWORD : newpw , tmp_newpw, |
| 930 | - crypt_ftr.salt, &crypt_ftr); |
| 931 | - |
| 932 | - if (is_hw_disk_encryption((char*)crypt_ftr.crypto_type_name)) { |
| 933 | - ret = update_hw_device_encryption_key( |
| 934 | - rc1 ? (previous_type == CRYPT_TYPE_DEFAULT ? DEFAULT_PASSWORD : currentpw) : (const char*)tmp_curpw, |
| 935 | - rc2 ? (crypt_type == CRYPT_TYPE_DEFAULT ? DEFAULT_PASSWORD : newpw): (const char*)tmp_newpw, |
| 936 | - (char*)crypt_ftr.crypto_type_name); |
| 937 | - if (ret) { |
| 938 | - SLOGE("Error updating device encryption hardware key ret %d", ret); |
| 939 | - return -1; |
| 940 | - } else { |
| 941 | - SLOGI("Encryption hardware key updated"); |
| 942 | - } |
| 943 | - } |
| 944 | - |
| 945 | - /* save the key */ |
| 946 | - put_crypt_ftr_and_key(&crypt_ftr); |
| 947 | return 0; |
| 948 | } |
| 949 | -#endif |
| 950 | |
| 951 | static unsigned int persist_get_max_entries(int encrypted) { |
| 952 | struct crypt_mnt_ftr crypt_ftr; |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 953 | @@ -3489,62 +3000,3 @@ int cryptfs_isConvertibleToFBE() |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 954 | struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab_default, DATA_MNT_POINT); |
| 955 | return fs_mgr_is_convertible_to_fbe(rec) ? 1 : 0; |
| 956 | } |
| 957 | - |
| 958 | -int cryptfs_create_default_ftr(struct crypt_mnt_ftr* crypt_ftr, __attribute__((unused))int key_length) |
| 959 | -{ |
| 960 | - if (cryptfs_init_crypt_mnt_ftr(crypt_ftr)) { |
| 961 | - SLOGE("Failed to initialize crypt_ftr"); |
| 962 | - return -1; |
| 963 | - } |
| 964 | - |
| 965 | - if (create_encrypted_random_key(DEFAULT_PASSWORD, crypt_ftr->master_key, |
| 966 | - crypt_ftr->salt, crypt_ftr)) { |
| 967 | - SLOGE("Cannot create encrypted master key\n"); |
| 968 | - return -1; |
| 969 | - } |
| 970 | - |
| 971 | - //crypt_ftr->keysize = key_length / 8; |
| 972 | - return 0; |
| 973 | -} |
| 974 | - |
| 975 | -int cryptfs_get_master_key(struct crypt_mnt_ftr* ftr, const char* password, |
| 976 | - unsigned char* master_key) |
| 977 | -{ |
| 978 | - int rc; |
| 979 | - |
| 980 | - unsigned char* intermediate_key = 0; |
| 981 | - size_t intermediate_key_size = 0; |
| 982 | - |
| 983 | - if (password == 0 || *password == 0) { |
| 984 | - password = DEFAULT_PASSWORD; |
| 985 | - } |
| 986 | - |
| 987 | - rc = decrypt_master_key(password, master_key, ftr, &intermediate_key, |
| 988 | - &intermediate_key_size); |
| 989 | - |
| 990 | - if (rc) { |
| 991 | - SLOGE("Can't calculate intermediate key"); |
| 992 | - return rc; |
| 993 | - } |
| 994 | - |
| 995 | - int N = 1 << ftr->N_factor; |
| 996 | - int r = 1 << ftr->r_factor; |
| 997 | - int p = 1 << ftr->p_factor; |
| 998 | - |
| 999 | - unsigned char scrypted_intermediate_key[sizeof(ftr->scrypted_intermediate_key)]; |
| 1000 | - |
| 1001 | - rc = crypto_scrypt(intermediate_key, intermediate_key_size, |
| 1002 | - ftr->salt, sizeof(ftr->salt), N, r, p, |
| 1003 | - scrypted_intermediate_key, |
| 1004 | - sizeof(scrypted_intermediate_key)); |
| 1005 | - |
| 1006 | - free(intermediate_key); |
| 1007 | - |
| 1008 | - if (rc) { |
| 1009 | - SLOGE("Can't scrypt intermediate key"); |
| 1010 | - return rc; |
| 1011 | - } |
| 1012 | - |
| 1013 | - return memcmp(scrypted_intermediate_key, ftr->scrypted_intermediate_key, |
| 1014 | - intermediate_key_size); |
| 1015 | -} |
| 1016 | diff --git a/cryptfs.h b/cryptfs.h |
| 1017 | index d8923db..d6c7dc5 100644 |
| 1018 | --- a/cryptfs.h |
| 1019 | +++ b/cryptfs.h |
| 1020 | @@ -66,14 +66,6 @@ |
| 1021 | complete. On next cryptkeeper entry, match |
| 1022 | the password. If it matches fix the master |
| 1023 | key and remove this flag. */ |
| 1024 | -#ifdef CONFIG_HW_DISK_ENCRYPTION |
| 1025 | -/* This flag is used to transition from L->M upgrade. L release passed |
| 1026 | - * a byte for every nible of user password while M release is passing |
| 1027 | - * ascii value of user password. |
| 1028 | - * Random flag value is chosen so that it does not conflict with other use cases |
| 1029 | - */ |
| 1030 | -#define CRYPT_ASCII_PASSWORD_UPDATED 0x1000 |
| 1031 | -#endif |
| 1032 | |
| 1033 | /* Allowed values for type in the structure below */ |
| 1034 | #define CRYPT_TYPE_PASSWORD 0 /* master_key is encrypted with a password |
| 1035 | @@ -241,7 +233,7 @@ int cryptfs_check_passwd(const char* pw); |
| 1036 | int cryptfs_verify_passwd(const char* pw); |
| 1037 | int cryptfs_restart(void); |
| 1038 | int cryptfs_enable(int type, const char* passwd, int no_ui); |
| 1039 | -int cryptfs_changepw(int type, const char *currentpw, const char* newpw); |
| 1040 | +int cryptfs_changepw(int type, const char* newpw); |
| 1041 | int cryptfs_enable_default(int no_ui); |
| 1042 | int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev, const unsigned char* key, |
| 1043 | char* out_crypto_blkdev); |
| 1044 | -- |
Jackeagle | 57acbdb | 2019-05-06 19:59:01 +0200 | [diff] [blame^] | 1045 | 2.21.0 |
Jackeagle | 1cba413 | 2018-12-19 17:08:24 +0100 | [diff] [blame] | 1046 | |