libcryfs: Fix password length bug

This commit is contained in:
Matéo Duparc 2022-09-21 19:09:59 +02:00
parent 7bc65e9bde
commit c0600c2624
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
1 changed files with 3 additions and 3 deletions

View File

@ -47,7 +47,7 @@ cryfs_init(JNIEnv *env, jstring jbaseDir, jstring jlocalStateDir, jbyteArray jpa
credentials.givenHash.size = env->GetArrayLength(jgivenHash);
} else {
jbyte* password = env->GetByteArrayElements(jpassword, NULL);
credentials.password = string(reinterpret_cast<const char*>(password));
credentials.password = string(reinterpret_cast<const char*>(password), env->GetArrayLength(jpassword));
env->ReleaseByteArrayElements(jpassword, password, 0);
if (jreturnedHash != NULL) {
credentials.returnedHash = &returnedHash;
@ -86,7 +86,7 @@ extern "C" jboolean cryfs_change_encryption_key(JNIEnv* env, jstring jbaseDir, j
} else {
jbyte* currentPassword = env->GetByteArrayElements(jcurrentPassword, NULL);
currentKeyProvider = std::make_unique<CryPresetPasswordBasedKeyProvider>(
reinterpret_cast<const char*>(currentPassword),
string(reinterpret_cast<const char*>(currentPassword), env->GetArrayLength(jcurrentPassword)),
cpputils::make_unique_ref<SCrypt>(SCrypt::DefaultSettings),
nullptr
);
@ -95,7 +95,7 @@ extern "C" jboolean cryfs_change_encryption_key(JNIEnv* env, jstring jbaseDir, j
struct SizedData returnedHash = {nullptr, 0};
jbyte* newPassword = env->GetByteArrayElements(jnewPassword, NULL);
cpputils::unique_ref<CryKeyProvider> newKeyProvider = cpputils::make_unique_ref<CryPresetPasswordBasedKeyProvider>(
reinterpret_cast<const char*>(newPassword),
string(reinterpret_cast<const char*>(newPassword), env->GetArrayLength(jnewPassword)),
cpputils::make_unique_ref<SCrypt>(SCrypt::DefaultSettings),
jreturnedHash == NULL ? nullptr : &returnedHash
);