@@ -621,6 +621,22 @@ bool Free_Return(bool retval, void* weaver_key, password_data_struct* pwd) {
621
621
return retval;
622
622
}
623
623
624
+ bool Decrypt_CE_storage (const userid_t user_id, int token, const std::string& secret) {
625
+ printf (" Attempting to unlock user storage\n " );
626
+ int flags = android::os::IVold::STORAGE_FLAG_CE;
627
+ if (!fscrypt_unlock_user_key (user_id, token, secret)) {
628
+ printf (" fscrypt_unlock_user_key returned fail\n " );
629
+ return false ;
630
+ }
631
+ printf (" Attempting to prepare user storage\n " );
632
+ if (!fscrypt_prepare_user_storage (" " , user_id, 0 , flags)) {
633
+ printf (" failed to fscrypt_prepare_user_storage\n " );
634
+ return false ;
635
+ }
636
+ printf (" User %i Decrypted Successfully!\n " , user_id);
637
+ return true ;
638
+ }
639
+
624
640
// /* Decrypt_User_Synth_Pass is the TWRP C++ equivalent to spBasedDoVerifyCredential
625
641
// * https://android.googlesource.com/platform/frameworks/base/+/android-8.0.0_r23/services/core/java/com/android/server/locksettings/LockSettingsService.java#1998 */
626
642
bool Decrypt_User_Synth_Pass (const userid_t user_id, const std::string& Password) {
@@ -636,7 +652,6 @@ bool Decrypt_User_Synth_Pass(const userid_t user_id, const std::string& Password
636
652
uint32_t auth_token_len = 0 ;
637
653
std::string secret; // this will be the disk decryption key that is sent to vold
638
654
int token = 0 ; // there is no token used for this kind of decrypt, key escrow is handled by weaver
639
- int flags = android::os::IVold::STORAGE_FLAG_CE;
640
655
char spblob_path_char[PATH_MAX];
641
656
sprintf (spblob_path_char, " /data/system_de/%d/spblob/" , user_id);
642
657
std::string spblob_path = spblob_path_char;
@@ -804,18 +819,10 @@ bool Decrypt_User_Synth_Pass(const userid_t user_id, const std::string& Password
804
819
return Free_Return (retval, weaver_key, &pwd);
805
820
}
806
821
807
- printf (" Attempting to unlock user storage\n " );
808
- if (!fscrypt_unlock_user_key (user_id, token, secret)) {
809
- printf (" fscrypt_unlock_user_key returned fail\n " );
822
+ if (!Decrypt_CE_storage (user_id, token, secret)) {
810
823
return Free_Return (retval, weaver_key, &pwd);
811
824
}
812
825
813
- printf (" Attempting to prepare user storage\n " );
814
- if (!fscrypt_prepare_user_storage (" " , user_id, 0 , flags)) {
815
- printf (" failed to fscrypt_prepare_user_storage\n " );
816
- return Free_Return (retval, weaver_key, &pwd);
817
- }
818
- printf (" User %i Decrypted Successfully!\n " , user_id);
819
826
retval = true ;
820
827
return Free_Return (retval, weaver_key, &pwd);
821
828
}
@@ -892,19 +899,10 @@ extern "C" bool Decrypt_User(const userid_t user_id, const std::string& Password
892
899
return false ;
893
900
}
894
901
895
- int flags = android::os::IVold::STORAGE_FLAG_CE;
896
-
897
902
if (Default_Password) {
898
- if (!fscrypt_unlock_user_key (user_id, 0 , " !" )) {
899
- printf (" unlock_user_key returned fail\n " );
903
+ if (!Decrypt_CE_storage (user_id, 0 , " !" )) {
900
904
return Decrypt_User_Synth_Pass (user_id, Password);
901
905
}
902
- printf (" Attempting to prepare user storage\n " );
903
- if (!fscrypt_prepare_user_storage (" " , user_id, 0 , flags)) {
904
- printf (" failed to fscrypt_prepare_user_storage\n " );
905
- return false ;
906
- }
907
- printf (" User %i Decrypted Successfully!\n " , user_id);
908
906
return true ;
909
907
}
910
908
if (stat (" /data/system_de/0/spblob" , &st) == 0 ) {
@@ -962,17 +960,9 @@ extern "C" bool Decrypt_User(const userid_t user_id, const std::string& Password
962
960
}
963
961
// The secret is "Android FBE credential hash" plus appended 0x00 to reach 128 bytes then append the user's password then feed that to sha512sum
964
962
std::string secret = HashPassword (Password);
965
- if (!fscrypt_unlock_user_key (user_id, 0 , secret)) {
966
- printf (" fscrypt_unlock_user_key returned fail\n " );
963
+ if (!Decrypt_CE_storage (user_id, 0 , secret)) {
967
964
return false ;
968
965
}
969
-
970
- printf (" Attempting to prepare user storage\n " );
971
- if (!fscrypt_prepare_user_storage (" " , user_id, 0 , flags)) {
972
- printf (" failed to fscrypt_prepare_user_storage\n " );
973
- return false ;
974
- }
975
- printf (" User %i Decrypted Successfully!\n " , user_id);
976
966
return true ;
977
967
}
978
968
}
0 commit comments