use of de.slackspace.openkeepass.exception.KeePassDatabaseUnreadableException in project TinyKeePass by sorz.
the class FetchDatabaseTask method doInBackground.
@Override
protected String doInBackground(Void... voids) {
File tmpDbFile = new File(cacheDir, DB_FILENAME);
File dbFile = new File(filesDir, DB_FILENAME);
try {
OutputStream output = new BufferedOutputStream(new FileOutputStream(tmpDbFile));
InputStream input = getInputStream(uri);
IOUtils.copy(input, output);
input.close();
output.close();
} catch (InterruptedIOException e) {
// task cancelled
return null;
} catch (IOException e) {
Log.w(TAG, "fail to open database file.", e);
return e.getClass().getSimpleName() + ": " + e.getLocalizedMessage();
}
KeePassFile db;
try {
db = KeePassDatabase.getInstance(tmpDbFile).openDatabase(masterPassword);
} catch (KeePassDatabaseUnreadableException | UnsupportedOperationException e) {
Log.w(TAG, "cannot open database.", e);
return e.getLocalizedMessage();
} catch (NullPointerException e) {
// happen on try to open a KDBX 4 database with Argon2 (openkeepass 8.0)
Log.e(TAG, "Underlying library throw null pointer exception", e);
return "Database broken or not support";
}
Meta meta = db.getMeta();
Log.d(TAG, "Database opened, name: " + meta.getDatabaseName());
if (!tmpDbFile.renameTo(dbFile)) {
try {
InputStream input = new FileInputStream(tmpDbFile);
OutputStream output = new FileOutputStream(dbFile);
IOUtils.copy(input, output);
if (!tmpDbFile.delete())
Log.w(TAG, "fail to delete temp database on cache");
input.close();
output.close();
} catch (IOException e) {
Log.e(TAG, "cannot copy new database.", e);
return "Fail to save database";
}
}
Context context = this.context.get();
if (context != null)
KeePassStorage.set(context, db);
return null;
}
use of de.slackspace.openkeepass.exception.KeePassDatabaseUnreadableException in project TinyKeePass by sorz.
the class OpenKeePassTask method doInBackground.
@Override
protected KeePassFile doInBackground(Void... voids) {
try {
long t = System.currentTimeMillis();
KeePassDatabase instance = KeePassDatabase.getInstance(path);
Log.d(TAG, "get instance in " + (System.currentTimeMillis() - t) + "ms");
t = System.currentTimeMillis();
KeePassFile keePassFile = instance.openDatabase(key);
Log.d(TAG, "open db in " + (System.currentTimeMillis() - t) + "ms");
return keePassFile;
} catch (KeePassDatabaseUnreadableException | UnsupportedOperationException e) {
Log.w(TAG, "cannot open database.", e);
errorMessage = e.getLocalizedMessage();
}
return null;
}
Aggregations