diff --git a/crypto/fscrypt/Decrypt.cpp b/crypto/fscrypt/Decrypt.cpp index 00554715..02173588 100755 --- a/crypto/fscrypt/Decrypt.cpp +++ b/crypto/fscrypt/Decrypt.cpp @@ -1080,15 +1080,21 @@ int Get_Password_Type(const userid_t user_id, std::string& filename) { printf("Failed to Get_Password_Data\n"); return 0; } - if (pwd.password_type == 1) { // In Android this means pattern + // In Android type 1 is pattern + // In Android <11 type 2 is PIN or password + // In Android 11+ type 3 is PIN and type 4 is password + if (pwd.password_type == 2) { + printf("password type: password/PIN\n"); + return 1; // In TWRP this means password or PIN (Android <11) + } else if (pwd.password_type == 4) { + printf("password type: password\n"); + return 1; // In TWRP this means password + } else if (pwd.password_type == 1) { printf("password type: pattern\n"); return 2; // In TWRP this means pattern - } - // In Android <11 type 2 is PIN or password - // In Android 11 type 3 is PIN and type 4 is password - else if (pwd.password_type > 1) { - printf("password type: pin\n"); - return 1; // In TWRP this means PIN or password + } else if (pwd.password_type == 3) { + printf("password type: PIN\n"); + return 3; // In TWRP this means PIN } printf("using default password\n"); return 0; // We'll try the default password diff --git a/crypto/fscrypt/KeyStorage.cpp b/crypto/fscrypt/KeyStorage.cpp index edb23a27..8afc5792 100755 --- a/crypto/fscrypt/KeyStorage.cpp +++ b/crypto/fscrypt/KeyStorage.cpp @@ -62,6 +62,8 @@ static constexpr size_t STRETCHED_BYTES = 1 << 6; static constexpr uint32_t AUTH_TIMEOUT = 30; // Seconds +static const std::string kPkmBlob("pKMblob\x00", 8); + static const char* kCurrentVersion = "1"; static const char* kRmPath = "/system/bin/rm"; static const char* kSecdiscardPath = "/system/bin/secdiscard"; @@ -247,6 +249,10 @@ static KeymasterOperation begin(Keymaster& keymaster, const std::string& dir, auto kmKeyPath = dir + "/" + kFn_keymaster_key_blob; std::string kmKey; if (!readFileToString(kmKeyPath, &kmKey)) return KeymasterOperation(); + // In A12 keymaster_key_blob format changed: + // it have useless for us bytes in beginning, so remove them to correctly handle key + if (!kmKey.compare(0, kPkmBlob.size(), kPkmBlob)) + kmKey.erase(0, kPkmBlob.size()); km::AuthorizationSet inParams(keyParams); inParams.append(opParams.begin(), opParams.end()); for (;;) { @@ -590,6 +596,10 @@ bool retrieveKey(const std::string& dir, const KeyAuthentication& auth, KeyBuffe static bool deleteKey(const std::string& dir) { std::string kmKey; if (!readFileToString(dir + "/" + kFn_keymaster_key_blob, &kmKey)) return false; + // In A12 keymaster_key_blob format changed: + // it have useless for us bytes in beginning, so remove them to correctly handle key + if (!kmKey.compare(0, kPkmBlob.size(), kPkmBlob)) + kmKey.erase(0, kPkmBlob.size()); Keymaster keymaster; if (!keymaster) return false; if (!keymaster.deleteKey(kmKey)) return false; diff --git a/crypto/fscrypt/MetadataCrypt.cpp b/crypto/fscrypt/MetadataCrypt.cpp index e9b19672..853e81eb 100755 --- a/crypto/fscrypt/MetadataCrypt.cpp +++ b/crypto/fscrypt/MetadataCrypt.cpp @@ -174,7 +174,7 @@ static bool read_key(const std::string& metadata_key_dir, const KeyGeneration& g unlink(newKeyPath.c_str()); } bool needs_cp = cp_needsCheckpoint(); - if (!retrieveOrGenerateKey(dir, temp, kEmptyAuthentication, gen, key, needs_cp)) return false; + if (!retrieveOrGenerateKey(dir, temp, kEmptyAuthentication, gen, key, true)) return false; if (needs_cp && pathExists(newKeyPath)) std::thread(commit_key, dir).detach(); return true; } diff --git a/gui/action.cpp b/gui/action.cpp index 96727518..819e4ad8 100755 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -1942,15 +1942,15 @@ int GUIAction::setbootslot(std::string arg) { operation_start("Set Boot Slot"); if (!simulate) { - if (!PartitionManager.UnMount_By_Path("/vendor", false)) { - // PartitionManager failed to unmount /vendor, this should not happen, - // but in case it does, do a lazy unmount - LOGINFO("WARNING: vendor partition could not be unmounted normally!\n"); - umount2("/vendor", MNT_DETACH); - PartitionManager.Set_Active_Slot(arg); - } else { - PartitionManager.Set_Active_Slot(arg); + if (PartitionManager.Find_Partition_By_Path("/vendor")) { + if (!PartitionManager.UnMount_By_Path("/vendor", false)) { + // PartitionManager failed to unmount /vendor, this should not happen, + // but in case it does, do a lazy unmount + LOGINFO("WARNING: vendor partition could not be unmounted normally!\n"); + umount2("/vendor", MNT_DETACH); + } } + PartitionManager.Set_Active_Slot(arg); } else { simulate_progress_bar(); } diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml index fa00b8d8..157b4612 100755 --- a/gui/theme/common/landscape.xml +++ b/gui/theme/common/landscape.xml @@ -2196,6 +2196,83 @@ select_storage + + + + restore_pin + + + + + + + + restore_read + + + + + + main + + + + + main + + + + + +