mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Solve empty password issue #2
This commit is contained in:
@@ -244,7 +244,7 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
AssignPasswordHelper assignPasswordHelper =
|
||||
new AssignPasswordHelper(this,
|
||||
masterPassword, keyFile);
|
||||
masterPasswordChecked, masterPassword, keyFileChecked, keyFile);
|
||||
assignPasswordHelper.assignPasswordInDatabase(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,8 +134,6 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
|
||||
|
||||
public void setMasterKey(String key, InputStream keyInputStream)
|
||||
throws InvalidKeyFileException, IOException {
|
||||
assert(key != null);
|
||||
|
||||
masterKey = getMasterKey(key, keyInputStream);
|
||||
}
|
||||
|
||||
@@ -220,6 +218,9 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
|
||||
}
|
||||
|
||||
public boolean validatePasswordEncoding(String key) {
|
||||
if (key == null)
|
||||
return false;
|
||||
|
||||
String encoding = getPasswordEncoding();
|
||||
|
||||
byte[] bKey;
|
||||
@@ -243,10 +244,8 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
|
||||
protected abstract String getPasswordEncoding();
|
||||
|
||||
public byte[] getPasswordKey(String key) throws IOException {
|
||||
assert(key!=null);
|
||||
|
||||
if ( key.length() == 0 )
|
||||
throw new IllegalArgumentException( "Key cannot be empty." );
|
||||
if ( key == null)
|
||||
throw new IllegalArgumentException( "Key cannot be empty." ); // TODO
|
||||
|
||||
MessageDigest md;
|
||||
try {
|
||||
|
||||
@@ -235,17 +235,18 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
|
||||
return newId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMasterKey(String key, InputStream keyInputStream)
|
||||
throws InvalidKeyFileException, IOException {
|
||||
|
||||
if (key != null && key.length() > 0 && keyInputStream != null) {
|
||||
if (key != null && keyInputStream != null) {
|
||||
return getCompositeKey(key, keyInputStream);
|
||||
} else if (key != null && key.length() > 0) {
|
||||
} else if (key != null) { // key.length() >= 0
|
||||
return getPasswordKey(key);
|
||||
} else if (keyInputStream != null) {
|
||||
} else if (keyInputStream != null) { // key == null
|
||||
return getFileKey(keyInputStream);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Key cannot be empty.");
|
||||
throw new IllegalArgumentException("Key cannot be empty."); // TODO Verify
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -338,15 +338,14 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
@Override
|
||||
public byte[] getMasterKey(String key, InputStream keyInputStream)
|
||||
throws InvalidKeyFileException, IOException {
|
||||
assert(key != null);
|
||||
|
||||
byte[] fKey = new byte[]{};
|
||||
|
||||
if ( key.length() > 0 && keyInputStream != null) {
|
||||
if (key != null && keyInputStream != null) {
|
||||
return getCompositeKey(key, keyInputStream);
|
||||
} else if ( key.length() > 0 ) {
|
||||
} else if (key != null) { // key.length() >= 0
|
||||
fKey = getPasswordKey(key);
|
||||
} else if ( keyInputStream != null) {
|
||||
} else if (keyInputStream != null) { // key == null
|
||||
fKey = getFileKey(keyInputStream);
|
||||
}
|
||||
|
||||
|
||||
@@ -524,9 +524,10 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
FileSelectActivity.this, create,
|
||||
R.string.progress_create);
|
||||
createTask.run();
|
||||
assignPasswordHelper =
|
||||
new AssignPasswordHelper(this,
|
||||
masterPassword, keyFile);
|
||||
|
||||
assignPasswordHelper = new AssignPasswordHelper(this,
|
||||
masterPasswordChecked, masterPassword, keyFileChecked, keyFile);
|
||||
|
||||
} catch (Exception e) {
|
||||
String error = "Unable to create database with this password and key file";
|
||||
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package com.kunzisoft.keepass.password;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
|
||||
@@ -35,27 +34,25 @@ public class AssignPasswordHelper {
|
||||
|
||||
private Context context;
|
||||
|
||||
private String masterPassword;
|
||||
private Uri keyfile;
|
||||
private String masterPassword = null;
|
||||
private Uri keyfile = null;
|
||||
|
||||
public AssignPasswordHelper(Context context,
|
||||
boolean withMasterPassword,
|
||||
String masterPassword,
|
||||
boolean withKeyFile,
|
||||
Uri keyfile) {
|
||||
this.context = context;
|
||||
this.masterPassword = masterPassword;
|
||||
this.keyfile = keyfile;
|
||||
if (withMasterPassword)
|
||||
this.masterPassword = masterPassword;
|
||||
if (withKeyFile)
|
||||
this.keyfile = keyfile;
|
||||
}
|
||||
|
||||
public void assignPasswordInDatabase(FileOnFinish fileOnFinish) {
|
||||
SetPassword sp = new SetPassword(context, App.getDB(), masterPassword, keyfile, new AfterSave(fileOnFinish, new Handler()));
|
||||
final ProgressTask pt = new ProgressTask(context, sp, R.string.saving_database);
|
||||
boolean valid = sp.validatePassword(context, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
pt.run();
|
||||
}
|
||||
});
|
||||
boolean valid = sp.validatePassword(context, (dialog, which) -> pt.run());
|
||||
|
||||
if (valid) {
|
||||
pt.run();
|
||||
|
||||
@@ -788,7 +788,7 @@ public class PasswordActivity extends StylishActivity
|
||||
|
||||
private void verifyCheckboxesAndLoadDatabase(String pass, Uri keyfile) {
|
||||
if (!checkboxPasswordView.isChecked()) {
|
||||
pass = "";
|
||||
pass = null;
|
||||
}
|
||||
if (!checkboxKeyfileView.isChecked()) {
|
||||
keyfile = null;
|
||||
|
||||
Reference in New Issue
Block a user