Fix database creation issue

This commit is contained in:
J-Jamet
2018-05-13 17:54:35 +02:00
parent e32b0d1c25
commit 7efaad1818
2 changed files with 10 additions and 3 deletions

View File

@@ -215,6 +215,8 @@ public class Database {
} }
private void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException { private void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
String errorMessage = "Failed to store database.";
if (uri.getScheme().equals("file")) { if (uri.getScheme().equals("file")) {
String filename = uri.getPath(); String filename = uri.getPath();
File tempFile = new File(filename + ".tmp"); File tempFile = new File(filename + ".tmp");
@@ -226,7 +228,8 @@ public class Database {
if (pmo != null) if (pmo != null)
pmo.output(); pmo.output();
} catch (Exception e) { } catch (Exception e) {
throw new IOException("Failed to store database."); Log.e(TAG, errorMessage, e);
throw new IOException(errorMessage, e);
} finally { } finally {
if (fos != null) if (fos != null)
fos.close(); fos.close();
@@ -242,7 +245,7 @@ public class Database {
File orig = new File(filename); File orig = new File(filename);
if (!tempFile.renameTo(orig)) { if (!tempFile.renameTo(orig)) {
throw new IOException("Failed to store database."); throw new IOException(errorMessage);
} }
} }
else { else {
@@ -253,7 +256,8 @@ public class Database {
if (pmo != null) if (pmo != null)
pmo.output(); pmo.output();
} catch (Exception e) { } catch (Exception e) {
throw new IOException("Failed to store database."); Log.e(TAG, errorMessage, e);
throw new IOException(errorMessage, e);
} finally { } finally {
if (os != null) if (os != null)
os.close(); os.close();

View File

@@ -293,6 +293,9 @@ public class PwDbV4Output extends PwDbOutput<PwDbHeaderV4> {
} }
random.nextBytes(header.encryptionIV); random.nextBytes(header.encryptionIV);
if (mPM.getKdfParameters() == null) {
mPM.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
}
KdfEngine kdf = KdfFactory.get(mPM.getKdfParameters()); KdfEngine kdf = KdfFactory.get(mPM.getKdfParameters());
kdf.randomize(mPM.getKdfParameters()); kdf.randomize(mPM.getKdfParameters());