Solve empty password issue #2

This commit is contained in:
J-Jamet
2018-04-20 15:48:53 +02:00
parent 7f5138b08b
commit e62f8bf56b
7 changed files with 28 additions and 31 deletions

View File

@@ -244,7 +244,7 @@ public abstract class ListNodesActivity extends LockingActivity
AssignPasswordHelper assignPasswordHelper =
new AssignPasswordHelper(this,
masterPassword, keyFile);
masterPasswordChecked, masterPassword, keyFileChecked, keyFile);
assignPasswordHelper.assignPasswordInDatabase(null);
}

View File

@@ -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 {

View File

@@ -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
}
}

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;