diff --git a/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/Kdb3.java b/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/Kdb3.java
index 25c574ccb..fc897cf0a 100644
--- a/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/Kdb3.java
+++ b/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/Kdb3.java
@@ -19,22 +19,12 @@
*/
package com.kunzisoft.keepass.tests.database;
-import android.content.Context;
-import android.content.res.AssetManager;
-import android.net.Uri;
-import android.os.Environment;
import android.test.AndroidTestCase;
-import com.kunzisoft.keepass.database.load.ImporterV3;
-import com.kunzisoft.keepass.tests.TestUtil;
-import com.kunzisoft.keepass.utils.UriUtil;
-
-import java.io.InputStream;
-import java.io.File;
-
public class Kdb3 extends AndroidTestCase {
private void testKeyfile(String dbAsset, String keyAsset, String password) throws Exception {
+ /*
Context ctx = getContext();
File sdcard = Environment.getExternalStorageDirectory();
@@ -49,6 +39,7 @@ public class Kdb3 extends AndroidTestCase {
importer.openDatabase(is, password, TestUtil.getKeyFileInputStream(ctx, keyPath));
is.close();
+ */
}
public void testXMLKeyFile() throws Exception {
diff --git a/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/Kdb3Twofish.java b/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/Kdb3Twofish.java
index d39f37a29..3f41d341f 100644
--- a/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/Kdb3Twofish.java
+++ b/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/Kdb3Twofish.java
@@ -19,18 +19,11 @@
*/
package com.kunzisoft.keepass.tests.database;
-import java.io.InputStream;
-
-import android.content.Context;
-import android.content.res.AssetManager;
import android.test.AndroidTestCase;
-import com.kunzisoft.keepass.database.element.PwDatabaseV3;
-import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm;
-import com.kunzisoft.keepass.database.load.ImporterV3;
-
public class Kdb3Twofish extends AndroidTestCase {
public void testReadTwofish() throws Exception {
+ /*
Context ctx = getContext();
AssetManager am = ctx.getAssets();
@@ -43,6 +36,6 @@ public class Kdb3Twofish extends AndroidTestCase {
assertTrue(db.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish);
is.close();
-
+ */
}
}
diff --git a/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/TestData.java b/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/TestData.java
index 7f4d059e4..98cc21f2d 100644
--- a/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/TestData.java
+++ b/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/TestData.java
@@ -19,16 +19,7 @@
*/
package com.kunzisoft.keepass.tests.database;
-import android.content.Context;
-import android.content.res.AssetManager;
-import android.net.Uri;
-
import com.kunzisoft.keepass.database.element.Database;
-import com.kunzisoft.keepass.database.element.PwDatabaseV3Debug;
-import com.kunzisoft.keepass.database.load.Importer;
-import com.kunzisoft.keepass.tests.TestUtil;
-
-import java.io.InputStream;
public class TestData {
private static final String TEST1_KEYFILE = "";
@@ -37,6 +28,7 @@ public class TestData {
private static Database mDb1;
+ /*
public static Database GetDb1(Context ctx) throws Exception {
return GetDb1(ctx, false);
@@ -75,4 +67,5 @@ public class TestData {
//return (PwDatabaseV3Debug) mDb1.getPwDatabase();
return null;
}
+ */
}
diff --git a/app/src/androidTest/java/com/kunzisoft/keepass/tests/output/PwManagerOutputTest.java b/app/src/androidTest/java/com/kunzisoft/keepass/tests/output/PwManagerOutputTest.java
index 6841ccd1c..aa77c7843 100644
--- a/app/src/androidTest/java/com/kunzisoft/keepass/tests/output/PwManagerOutputTest.java
+++ b/app/src/androidTest/java/com/kunzisoft/keepass/tests/output/PwManagerOutputTest.java
@@ -19,33 +19,12 @@
*/
package com.kunzisoft.keepass.tests.output;
-import static org.junit.Assert.assertArrayEquals;
-
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.DigestOutputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import android.content.res.AssetManager;
import android.test.AndroidTestCase;
-
-import com.kunzisoft.keepass.database.element.PwDatabaseV3Debug;
-import com.kunzisoft.keepass.database.element.PwDbHeader;
-import com.kunzisoft.keepass.database.element.PwDbHeaderV3;
-import com.kunzisoft.keepass.database.exception.PwDbOutputException;
-import com.kunzisoft.keepass.database.save.PwDbHeaderOutputV3;
-import com.kunzisoft.keepass.database.save.PwDbV3Output;
-import com.kunzisoft.keepass.database.save.PwDbV3OutputDebug;
-import com.kunzisoft.keepass.stream.NullOutputStream;
-import com.kunzisoft.keepass.tests.TestUtil;
-import com.kunzisoft.keepass.tests.database.TestData;
public class PwManagerOutputTest extends AndroidTestCase {
- PwDatabaseV3Debug mPM;
-
+ // PwDatabaseV3Debug mPM;
+
+ /*
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -143,4 +122,5 @@ public class PwManagerOutputTest extends AndroidTestCase {
assertArrayEquals("Databases do not match.", bExpected.toByteArray(), bActual.toByteArray());
}
+ */
}
\ No newline at end of file
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/Database.java b/app/src/main/java/com/kunzisoft/keepass/database/element/Database.java
index 6cce4bcfe..085463a81 100644
--- a/app/src/main/java/com/kunzisoft/keepass/database/element/Database.java
+++ b/app/src/main/java/com/kunzisoft/keepass/database/element/Database.java
@@ -31,15 +31,13 @@ import com.kunzisoft.keepass.database.EntryHandler;
import com.kunzisoft.keepass.database.GroupHandler;
import com.kunzisoft.keepass.database.cursor.EntryCursorV3;
import com.kunzisoft.keepass.database.cursor.EntryCursorV4;
-import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
-import com.kunzisoft.keepass.database.exception.InvalidDBException;
-import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
-import com.kunzisoft.keepass.database.exception.PwDbOutputException;
-import com.kunzisoft.keepass.database.load.Importer;
-import com.kunzisoft.keepass.database.load.ImporterFactory;
+import com.kunzisoft.keepass.database.exception.*;
+import com.kunzisoft.keepass.database.load.ImporterV3;
+import com.kunzisoft.keepass.database.load.ImporterV4;
import com.kunzisoft.keepass.database.save.PwDbOutput;
import com.kunzisoft.keepass.database.search.SearchDbHelper;
import com.kunzisoft.keepass.icons.IconDrawableFactory;
+import com.kunzisoft.keepass.stream.LEDataInputStream;
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.UriUtil;
@@ -56,9 +54,9 @@ public class Database {
private static final String TAG = Database.class.getName();
private PwDatabase pwDatabase = null;
- private PwDatabaseV3 pwDatabaseV3 = null;
- private PwDatabaseV4 pwDatabaseV4 = null;
private PwVersion version = null;
+ // To keep a reference for specific methods provided by V4
+ private PwDatabaseV4 pwDatabaseV4 = null;
private Uri mUri = null;
private SearchDbHelper searchHelper = null;
@@ -74,32 +72,27 @@ public class Database {
public Database(String databasePath) {
// TODO Test with kdb extension
if (isKDBExtension(databasePath)) {
- this.pwDatabaseV3 = new PwDatabaseV3();
-
- this.pwDatabase = pwDatabaseV3;
+ setDatabaseV3(new PwDatabaseV3());
} else {
PwGroupV4 groupV4 = new PwGroupV4();
- this.pwDatabaseV4 = new PwDatabaseV4();
+ setDatabaseV4(new PwDatabaseV4());
groupV4.setTitle(dbNameFromPath(databasePath));
groupV4.setIconStandard(pwDatabaseV4.getIconFactory().getFolderIcon());
this.pwDatabaseV4.setRootGroup(groupV4);
-
- this.pwDatabase = pwDatabaseV4;
}
- this.version = pwDatabase.getVersion();
}
- private void retrieveDatabaseVersioned(PwDatabase pwDatabase) {
+ private void setDatabaseV3(PwDatabaseV3 pwDatabaseV3) {
+ this.pwDatabaseV4 = null;
+ this.pwDatabase = pwDatabaseV3;
+ this.version = pwDatabase.getVersion();
+ }
+
+ private void setDatabaseV4(PwDatabaseV4 pwDatabaseV4) {
+ this.pwDatabaseV4 = pwDatabaseV4;
+ this.pwDatabase = pwDatabaseV4;
this.version = pwDatabase.getVersion();
- switch (version) {
- case V3:
- pwDatabaseV3 = (PwDatabaseV3) pwDatabase;
- break;
- case V4:
- pwDatabaseV4 = (PwDatabaseV4) pwDatabase;
- break;
- }
}
private boolean isKDBExtension(String filename) {
@@ -145,11 +138,9 @@ public class Database {
return pwDatabase.getIconFactory();
}
- public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status) throws IOException, FileNotFoundException, InvalidDBException {
- loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
- }
+ public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater progressTaskUpdater)
+ throws IOException, InvalidDBException {
- private void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
mUri = uri;
readOnly = false;
if (uri.getScheme().equals("file")) {
@@ -157,48 +148,60 @@ public class Database {
readOnly = !file.canWrite();
}
- passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug);
- }
+ // Pass Uris as InputStreams
- private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
- InputStream is, kfIs;
+ InputStream inputStream, keyFileInputStream;
try {
- is = UriUtil.getUriInputStream(ctx, uri);
+ inputStream = UriUtil.getUriInputStream(ctx, uri);
} catch (Exception e) {
Log.e("KPD", "Database::loadData", e);
throw ContentFileNotFoundException.getInstance(uri);
}
try {
- kfIs = UriUtil.getUriInputStream(ctx, keyfile);
+ keyFileInputStream = UriUtil.getUriInputStream(ctx, keyfile);
} catch (Exception e) {
Log.e("KPD", "Database::loadData", e);
throw ContentFileNotFoundException.getInstance(keyfile);
}
- 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);
- }
+ // Load Data
- 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() ) {
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
+ if ( ! bufferedInputStream.markSupported() ) {
throw new IOException("Input stream does not support mark.");
}
// We'll end up reading 8 bytes to identify the header. Might as well use two extra.
- bis.mark(10);
+ bufferedInputStream.mark(10);
// Get the file directory to save the attachments
- Importer databaseImporter = ImporterFactory.createImporter(bis, ctx.getFilesDir(), debug);
+ int sig1 = LEDataInputStream.readInt(bufferedInputStream);
+ int sig2 = LEDataInputStream.readInt(bufferedInputStream);
- bis.reset(); // Return to the start
+ // Header of database V3
+ if ( PwDbHeaderV3.matchesHeader(sig1, sig2) ) {
+ bufferedInputStream.reset(); // Return to the start
+ setDatabaseV3(new ImporterV3().openDatabase(bufferedInputStream,
+ password,
+ keyFileInputStream,
+ progressTaskUpdater));
+ }
+
+ // Header of database V4
+ else if ( PwDbHeaderV4.matchesHeader(sig1, sig2) ) {
+ bufferedInputStream.reset(); // Return to the start
+ setDatabaseV4(new ImporterV4(ctx.getFilesDir()).openDatabase(bufferedInputStream,
+ password,
+ keyFileInputStream,
+ progressTaskUpdater));
+ }
+
+ // Header not recognized
+ else {
+ throw new InvalidDBSignatureException();
+ }
- pwDatabase = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater);
- retrieveDatabaseVersioned(pwDatabase);
if ( pwDatabase != null ) {
try {
passwordEncodingError = !pwDatabase.validatePasswordEncoding(password);
@@ -344,7 +347,6 @@ public class Database {
}
pwDatabase = null;
- pwDatabaseV3 = null;
pwDatabaseV4 = null;
mUri = null;
loaded = false;
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/PwDatabaseV3Debug.java b/app/src/main/java/com/kunzisoft/keepass/database/element/PwDatabaseV3Debug.java
deleted file mode 100644
index f9fb0bdf0..000000000
--- a/app/src/main/java/com/kunzisoft/keepass/database/element/PwDatabaseV3Debug.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2017 Brian Pellin, 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 .
- *
- */
-package com.kunzisoft.keepass.database.element;
-
-public class PwDatabaseV3Debug extends PwDatabaseV3 {
-
- private byte[] postHeader;
- private PwDbHeaderV3 dbHeader;
-
- @Override
- public void copyEncrypted(byte[] buf, int offset, int size) {
- postHeader = new byte[size];
- System.arraycopy(buf, offset, postHeader, 0, size);
- }
-
- @Override
- public void copyHeader(PwDbHeaderV3 header) {
- dbHeader = header;
- }
-
- public byte[] getPostHeader() {
- return postHeader;
- }
-
- public PwDbHeaderV3 getDbHeader() {
- return dbHeader;
- }
-}
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/Importer.java b/app/src/main/java/com/kunzisoft/keepass/database/load/Importer.java
index 1fc08ad3c..1b60c2e88 100644
--- a/app/src/main/java/com/kunzisoft/keepass/database/load/Importer.java
+++ b/app/src/main/java/com/kunzisoft/keepass/database/load/Importer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
+ * Copyright 2019 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
@@ -26,14 +26,19 @@ import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import java.io.IOException;
import java.io.InputStream;
-public abstract class Importer {
+public abstract class Importer {
- public static final boolean DEBUG = true;
-
- 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)
+ /**
+ * Load a versioned database file, return contents in a new PwDatabase.
+ *
+ * @param inStream Existing file to load.
+ * @param password Pass phrase for infile.
+ * @return new PwDatabase container.
+ *
+ * @throws IOException on any file error.
+ * @throws InvalidDBException on database error.
+ */
+ public abstract PwDb openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater)
throws IOException, InvalidDBException;
}
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterFactory.java b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterFactory.java
deleted file mode 100644
index 6fdd902c8..000000000
--- a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2017 Brian Pellin, 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 .
- *
- */
-package com.kunzisoft.keepass.database.load;
-
-import com.kunzisoft.keepass.database.element.PwDbHeaderV3;
-import com.kunzisoft.keepass.database.element.PwDbHeaderV4;
-import com.kunzisoft.keepass.database.exception.InvalidDBSignatureException;
-import com.kunzisoft.keepass.stream.LEDataInputStream;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-
-public class ImporterFactory {
-
- public static Importer createImporter(InputStream is, File streamDir, boolean debug) throws InvalidDBSignatureException, IOException {
- int sig1 = LEDataInputStream.readInt(is);
- int sig2 = LEDataInputStream.readInt(is);
-
- if ( PwDbHeaderV3.matchesHeader(sig1, sig2) ) {
- if (debug) {
- return new ImporterV3Debug();
- }
- return new ImporterV3();
- } else if ( PwDbHeaderV4.matchesHeader(sig1, sig2) ) {
- return new ImporterV4(streamDir);
- }
-
- throw new InvalidDBSignatureException();
- }
-}
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3.java b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3.java
index 5f4fd6bb9..e7e04bb59 100644
--- a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3.java
+++ b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3.java
@@ -46,94 +46,36 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package com.kunzisoft.keepass.database.load;
import android.util.Log;
-
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.CipherFactory;
-import com.kunzisoft.keepass.database.element.PwDatabaseV3;
-import com.kunzisoft.keepass.database.element.PwDate;
-import com.kunzisoft.keepass.database.element.PwDbHeader;
-import com.kunzisoft.keepass.database.element.PwDbHeaderV3;
-import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm;
-import com.kunzisoft.keepass.database.element.PwEntryInterface;
-import com.kunzisoft.keepass.database.element.PwEntryV3;
-import com.kunzisoft.keepass.database.element.PwGroupInterface;
-import com.kunzisoft.keepass.database.element.PwGroupV3;
-import com.kunzisoft.keepass.database.element.PwNodeIdUUID;
-import com.kunzisoft.keepass.database.exception.InvalidAlgorithmException;
-import com.kunzisoft.keepass.database.exception.InvalidDBException;
-import com.kunzisoft.keepass.database.exception.InvalidDBSignatureException;
-import com.kunzisoft.keepass.database.exception.InvalidDBVersionException;
-import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
-import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
+import com.kunzisoft.keepass.database.element.*;
+import com.kunzisoft.keepass.database.exception.*;
import com.kunzisoft.keepass.stream.LEDataInputStream;
import com.kunzisoft.keepass.stream.NullOutputStream;
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.utils.Types;
+import javax.crypto.*;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import java.security.DigestOutputStream;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
+import java.security.*;
import java.util.Arrays;
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.ShortBufferException;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-
/**
* Load a v3 database file.
*
* @author Naomaru Itoi
* @author Bill Zwicky
*/
-public class ImporterV3 extends Importer {
+public class ImporterV3 extends Importer {
private static final String TAG = ImporterV3.class.getName();
private PwDatabaseV3 databaseToOpen;
- public ImporterV3() {
- super();
- }
-
- protected PwDatabaseV3 createDB() {
- return new PwDatabaseV3();
- }
-
- /**
- * Load a v3 database file, return contents in a new PwDatabaseV3.
- *
- * @param inStream Existing file to load.
- * @param password Pass phrase for infile.
- * @return new PwDatabaseV3 container.
- *
- * @throws IOException on any file error.
- * @throws InvalidKeyFileException
- * @throws InvalidPasswordException
- * @throws InvalidPasswordException on a decryption error, or possible internal bug.
- * @throws InvalidDBSignatureException
- * @throws InvalidDBVersionException
- * @throws IllegalBlockSizeException on a decryption error, or possible internal bug.
- * @throws BadPaddingException on a decryption error, or possible internal bug.
- * @throws NoSuchAlgorithmException on a decryption error, or possible internal bug.
- * @throws NoSuchPaddingException on a decryption error, or possible internal bug.
- * @throws InvalidAlgorithmParameterException if error decrypting main file body.
- * @throws ShortBufferException if error decrypting main file body.
- */
- @Override
- public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
- throws IOException, InvalidDBException {
- return openDatabase(inStream, password, kfIs, null);
- }
-
@Override
public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater)
throws IOException, InvalidDBException {
@@ -160,7 +102,7 @@ public class ImporterV3 extends Importer {
if (progressTaskUpdater != null)
progressTaskUpdater.updateMessage(R.string.retrieving_db_key);
- databaseToOpen = createDB();
+ databaseToOpen = new PwDatabaseV3();
databaseToOpen.retrieveMasterKey(password, kfIs);
// Select algorithm
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3Debug.java b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3Debug.java
deleted file mode 100644
index 069c463f2..000000000
--- a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3Debug.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2017 Brian Pellin, 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 .
- *
- */
-package com.kunzisoft.keepass.database.load;
-
-import com.kunzisoft.keepass.database.element.PwDatabaseV3Debug;
-import com.kunzisoft.keepass.database.exception.InvalidDBException;
-import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class ImporterV3Debug extends ImporterV3 {
-
- @Override
- protected PwDatabaseV3Debug createDB() {
- return new PwDatabaseV3Debug();
- }
-
- @Override
- public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
- InputStream keyInputStream, ProgressTaskUpdater status) throws IOException,
- InvalidDBException {
- return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status);
- }
-
-}
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV4.java b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV4.java
index be0690d67..c80724dd3 100644
--- a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV4.java
+++ b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV4.java
@@ -19,22 +19,14 @@
*/
package com.kunzisoft.keepass.database.load;
+import biz.source_code.base64Coder.Base64Coder;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.CipherFactory;
import com.kunzisoft.keepass.crypto.PwStreamCipherFactory;
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
import com.kunzisoft.keepass.database.ITimeLogger;
import com.kunzisoft.keepass.database.PwCompressionAlgorithm;
-import com.kunzisoft.keepass.database.element.PwDatabase;
-import com.kunzisoft.keepass.database.element.PwDatabaseV4;
-import com.kunzisoft.keepass.database.element.PwDatabaseV4XML;
-import com.kunzisoft.keepass.database.element.PwDate;
-import com.kunzisoft.keepass.database.element.PwDbHeaderV4;
-import com.kunzisoft.keepass.database.element.PwDeletedObject;
-import com.kunzisoft.keepass.database.element.PwEntryV4;
-import com.kunzisoft.keepass.database.element.PwGroupV4;
-import com.kunzisoft.keepass.database.element.PwIconCustom;
-import com.kunzisoft.keepass.database.element.PwNodeIdUUID;
+import com.kunzisoft.keepass.database.element.*;
import com.kunzisoft.keepass.database.exception.ArcFourException;
import com.kunzisoft.keepass.database.exception.InvalidDBException;
import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
@@ -49,17 +41,14 @@ import com.kunzisoft.keepass.utils.DateUtil;
import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.MemUtil;
import com.kunzisoft.keepass.utils.Types;
-
import org.spongycastle.crypto.StreamCipher;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
+import javax.crypto.Cipher;
+import javax.crypto.NoSuchPaddingException;
+import java.io.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@@ -70,12 +59,7 @@ import java.util.Stack;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
-import javax.crypto.Cipher;
-import javax.crypto.NoSuchPaddingException;
-
-import biz.source_code.base64Coder.Base64Coder;
-
-public class ImporterV4 extends Importer {
+public class ImporterV4 extends Importer {
private StreamCipher randomStream;
private PwDatabaseV4 mDatabase;
@@ -87,18 +71,11 @@ public class ImporterV4 extends Importer {
public ImporterV4(File streamDir) {
this.streamDir = streamDir;
}
-
- @Override
- public PwDatabaseV4 openDatabase(InputStream inStream, String password,
- InputStream keyInputStream) throws IOException, InvalidDBException {
-
- return openDatabase(inStream, password, keyInputStream, null);
- }
@Override
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
- InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater) throws IOException,
- InvalidDBException {
+ InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater)
+ throws IOException, InvalidDBException {
if (progressTaskUpdater != null)
progressTaskUpdater.updateMessage(R.string.retrieving_db_key);
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/save/PwDbV3OutputDebug.java b/app/src/main/java/com/kunzisoft/keepass/database/save/PwDbV3OutputDebug.java
deleted file mode 100644
index a419f0dfb..000000000
--- a/app/src/main/java/com/kunzisoft/keepass/database/save/PwDbV3OutputDebug.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2017 Brian Pellin, 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 .
- *
- */
-package com.kunzisoft.keepass.database.save;
-
-import com.kunzisoft.keepass.database.element.PwDatabaseV3;
-import com.kunzisoft.keepass.database.element.PwDatabaseV3Debug;
-import com.kunzisoft.keepass.database.element.PwDbHeaderV3;
-import com.kunzisoft.keepass.database.exception.PwDbOutputException;
-
-import java.io.OutputStream;
-import java.security.SecureRandom;
-
-public class PwDbV3OutputDebug extends PwDbV3Output {
- PwDatabaseV3Debug debugDb;
- private boolean noHeaderHash;
-
- public PwDbV3OutputDebug(PwDatabaseV3 pm, OutputStream os, boolean noHeaderHash) {
- super(pm, os);
- debugDb = (PwDatabaseV3Debug) pm;
- this.noHeaderHash = noHeaderHash;
- }
-
- @Override
- protected SecureRandom setIVs(PwDbHeaderV3 header) throws PwDbOutputException {
- // Reuse random values to test equivalence in debug mode
- PwDbHeaderV3 origHeader = debugDb.getDbHeader();
- System.arraycopy(origHeader.encryptionIV, 0, header.encryptionIV, 0, origHeader.encryptionIV.length);
- System.arraycopy(origHeader.masterSeed, 0, header.masterSeed, 0, origHeader.masterSeed.length);
- System.arraycopy(origHeader.transformSeed, 0, header.transformSeed, 0, origHeader.transformSeed.length);
-
- return null;
- }
-
- @Override
- protected boolean useHeaderHash() {
- return !noHeaderHash;
- }
-
-}
diff --git a/app/src/main/java/com/kunzisoft/keepass/database/search/SearchDbHelper.java b/app/src/main/java/com/kunzisoft/keepass/database/search/SearchDbHelper.java
index aafdda43f..49bf7605d 100644
--- a/app/src/main/java/com/kunzisoft/keepass/database/search/SearchDbHelper.java
+++ b/app/src/main/java/com/kunzisoft/keepass/database/search/SearchDbHelper.java
@@ -86,9 +86,9 @@ public class SearchDbHelper {
private boolean entryContainsString(PwEntryInterface entry, String qStr, Locale loc) {
// Search all strings in the entry
- Iterator iter = EntrySearchStringIterator.getInstance(entry);
- while (iter.hasNext()) {
- String str = iter.next();
+ Iterator iterator = EntrySearchStringIterator.getInstance(entry);
+ while (iterator.hasNext()) {
+ String str = iterator.next();
if (str != null && str.length() != 0) {
String lower = str.toLowerCase(loc);
if (lower.contains(qStr)) {