mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Remove "Rounds fix" setting no more used
This commit is contained in:
1 parent
e8a24790a5
commit
09c776fd7e
17 files changed
+15
-192
No files matched your search
@@ -20,18 +20,14 @@
|
||||
package com.kunzisoft.keepass.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
|
||||
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
|
||||
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
||||
import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
|
||||
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
||||
import com.kunzisoft.keepass.database.load.Importer;
|
||||
import com.kunzisoft.keepass.database.load.ImporterFactory;
|
||||
@@ -118,26 +114,10 @@ public class Database {
|
||||
readOnly = !file.canWrite();
|
||||
}
|
||||
|
||||
try {
|
||||
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug, 0);
|
||||
} catch (InvalidPasswordException e) {
|
||||
// Retry with rounds fix
|
||||
try {
|
||||
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug, getFixRounds(ctx));
|
||||
} catch (Exception e2) {
|
||||
// Rethrow original exception
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug);
|
||||
}
|
||||
|
||||
private long getFixRounds(Context ctx) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
return prefs.getLong(ctx.getString(R.string.roundsFix_key), ctx.getResources().getInteger(R.integer.roundsFix_default));
|
||||
}
|
||||
|
||||
|
||||
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
|
||||
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
|
||||
InputStream is, kfIs;
|
||||
try {
|
||||
is = UriUtil.getUriInputStream(ctx, uri);
|
||||
@@ -152,14 +132,14 @@ public class Database {
|
||||
Log.e("KPD", "Database::loadData", e);
|
||||
throw ContentFileNotFoundException.getInstance(keyfile);
|
||||
}
|
||||
loadData(ctx, is, password, kfIs, status, debug, roundsFix);
|
||||
loadData(ctx, is, password, kfIs, status, debug);
|
||||
}
|
||||
|
||||
public void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, boolean debug) throws IOException, InvalidDBException {
|
||||
loadData(ctx, is, password, keyFileInputStream, null, debug, 0);
|
||||
loadData(ctx, is, password, keyFileInputStream, null, debug);
|
||||
}
|
||||
|
||||
private void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, ProgressTaskUpdater progressTaskUpdater, boolean debug, long roundsFix) throws IOException, InvalidDBException {
|
||||
private void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, ProgressTaskUpdater progressTaskUpdater, boolean debug) throws IOException, InvalidDBException {
|
||||
BufferedInputStream bis = new BufferedInputStream(is);
|
||||
|
||||
if ( ! bis.markSupported() ) {
|
||||
@@ -173,7 +153,7 @@ public class Database {
|
||||
|
||||
bis.reset(); // Return to the start
|
||||
|
||||
pm = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater, roundsFix);
|
||||
pm = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater);
|
||||
if ( pm != null ) {
|
||||
try {
|
||||
switch (pm.getVersion()) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.kunzisoft.keepass.collections.VariantDictionary;
|
||||
import com.kunzisoft.keepass.crypto.CryptoUtil;
|
||||
import com.kunzisoft.keepass.crypto.engine.AesEngine;
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters;
|
||||
@@ -403,19 +402,9 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
}
|
||||
|
||||
public void makeFinalKey(byte[] masterSeed) throws IOException {
|
||||
makeFinalKey(masterSeed, 0);
|
||||
}
|
||||
|
||||
public void makeFinalKey(byte[] masterSeed, long roundsFix) throws IOException {
|
||||
|
||||
KdfEngine kdfEngine = KdfFactory.getEngineV4(kdfParameters);
|
||||
|
||||
// Set to 6000 rounds to open corrupted database
|
||||
if (roundsFix > 0 && kdfParameters.getUUID().equals(AesKdf.CIPHER_UUID)) {
|
||||
kdfParameters.setUInt32(AesKdf.ParamRounds, roundsFix);
|
||||
numKeyEncRounds = roundsFix;
|
||||
}
|
||||
|
||||
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfParameters);
|
||||
if (transformedMasterKey.length != 32) {
|
||||
transformedMasterKey = CryptoUtil.hashSha256(transformedMasterKey);
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class Importer {
|
||||
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream)
|
||||
throws IOException, InvalidDBException;
|
||||
|
||||
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater, long roundsFix)
|
||||
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater)
|
||||
throws IOException, InvalidDBException;
|
||||
|
||||
}
|
||||
@@ -126,11 +126,11 @@ public class ImporterV3 extends Importer {
|
||||
@Override
|
||||
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
|
||||
throws IOException, InvalidDBException {
|
||||
return openDatabase(inStream, password, kfIs, null, 0);
|
||||
return openDatabase(inStream, password, kfIs, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, long roundsFix)
|
||||
public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater)
|
||||
throws IOException, InvalidDBException {
|
||||
|
||||
PwDatabaseV3 databaseToOpen;
|
||||
|
||||
@@ -35,10 +35,9 @@ public class ImporterV3Debug extends ImporterV3 {
|
||||
|
||||
@Override
|
||||
public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputStream, ProgressTaskUpdater status, long roundsFix) throws IOException,
|
||||
InputStream keyInputStream, ProgressTaskUpdater status) throws IOException,
|
||||
InvalidDBException {
|
||||
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status,
|
||||
roundsFix);
|
||||
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -92,12 +92,12 @@ public class ImporterV4 extends Importer {
|
||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputStream) throws IOException, InvalidDBException {
|
||||
|
||||
return openDatabase(inStream, password, keyInputStream, null, 0);
|
||||
return openDatabase(inStream, password, keyInputStream, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater, long roundsFix) throws IOException,
|
||||
InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater) throws IOException,
|
||||
InvalidDBException {
|
||||
|
||||
if (progressTaskUpdater != null)
|
||||
@@ -114,7 +114,7 @@ public class ImporterV4 extends Importer {
|
||||
pbHeader = hh.header;
|
||||
|
||||
db.retrieveMasterKey(password, keyInputStream);
|
||||
db.makeFinalKey(header.masterSeed, roundsFix);
|
||||
db.makeFinalKey(header.masterSeed);
|
||||
|
||||
if (progressTaskUpdater != null)
|
||||
progressTaskUpdater.updateMessage(R.string.decrypting_db);
|
||||
|
||||
@@ -21,15 +21,12 @@ package com.kunzisoft.keepass.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsFixPreferenceDialogFragmentCompat;
|
||||
import com.kunzisoft.keepass.settings.preference.InputNumberPreference;
|
||||
|
||||
public class MainPreferenceFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@@ -68,21 +65,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayPreferenceDialog(Preference preference) {
|
||||
// Try if the preference is one of our custom Preferences
|
||||
if (preference instanceof InputNumberPreference) {
|
||||
assert getFragmentManager() != null;
|
||||
DialogFragment dialogFragment = RoundsFixPreferenceDialogFragmentCompat.newInstance(preference.getKey());
|
||||
dialogFragment.setTargetFragment(this, 0);
|
||||
dialogFragment.show(getFragmentManager(), null);
|
||||
}
|
||||
// Could not be handled here. Try with the super method.
|
||||
else {
|
||||
super.onDisplayPreferenceDialog(preference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
// here you should use the same keys as you used in the xml-file
|
||||
|
||||
-92
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.DialogPreference;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.settings.preference.InputNumberPreference;
|
||||
|
||||
public class RoundsFixPreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat {
|
||||
|
||||
private EditText inputTextView;
|
||||
|
||||
public static RoundsFixPreferenceDialogFragmentCompat newInstance(
|
||||
String key) {
|
||||
final RoundsFixPreferenceDialogFragmentCompat
|
||||
fragment = new RoundsFixPreferenceDialogFragmentCompat();
|
||||
final Bundle b = new Bundle(1);
|
||||
b.putString(ARG_KEY, key);
|
||||
fragment.setArguments(b);
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
|
||||
inputTextView = view.findViewById(R.id.input_text);
|
||||
|
||||
DialogPreference preference = getPreference();
|
||||
if (preference instanceof InputNumberPreference) {
|
||||
setExplanationText(((InputNumberPreference) preference).getExplanation());
|
||||
long numRounds = ((InputNumberPreference) preference).getNumber();
|
||||
setInputText(String.valueOf(numRounds));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
if ( positiveResult ) {
|
||||
long rounds;
|
||||
try {
|
||||
String strRounds = getInputText();
|
||||
rounds = Long.valueOf(strRounds);
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(getContext(), R.string.error_rounds_not_number, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
DialogPreference preference = getPreference();
|
||||
if (preference instanceof InputNumberPreference) {
|
||||
InputNumberPreference roundsPreference = (InputNumberPreference) preference;
|
||||
// This allows the client to ignore the user value.
|
||||
if (roundsPreference.callChangeListener(rounds)) {
|
||||
// Save the value
|
||||
roundsPreference.setNumber(rounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getInputText() {
|
||||
return this.inputTextView.getText().toString();
|
||||
}
|
||||
|
||||
public void setInputText(String inputText) {
|
||||
this.inputTextView.setText(inputText);
|
||||
this.inputTextView.setSelection(this.inputTextView.getText().length());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user