use of de.slackspace.openkeepass.domain.KeePassFile 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.domain.KeePassFile in project TinyKeePass by sorz.
the class AuthActivity method onDatabaseOpened.
@Override
protected void onDatabaseOpened() {
StructureParser.Result result = parseStructure();
KeePassFile keePass = KeePassStorage.get(this);
SearchIndex index = new SearchIndex(keePass);
StringBuilder queryBuilder = new StringBuilder();
result.title.forEach(title -> queryBuilder.append(title).append(' '));
Stream<Entry> entryStream = index.search(queryBuilder.toString()).map(keePass::getEntryByUUID);
FillResponse.Builder responseBuilder = new FillResponse.Builder();
// add matched entities
entryStream.map(entry -> AutofillUtils.buildDataset(this, entry, result)).filter(Objects::nonNull).limit(MAX_NUM_CANDIDATE_ENTRIES).forEach(responseBuilder::addDataset);
// add "show all" item
RemoteViews presentation = AutofillUtils.getRemoteViews(this, getString(R.string.autofill_item_show_all), R.drawable.ic_more_horiz_gray_24dp);
presentation.setTextColor(R.id.textView, getColor(R.color.hint));
Dataset.Builder datasetBuilder = new Dataset.Builder(presentation).setAuthentication(EntrySelectActivity.getAuthIntentSenderForResponse(this));
result.allAutofillIds().forEach(id -> datasetBuilder.setValue(id, null));
responseBuilder.addDataset(datasetBuilder.build());
setFillResponse(responseBuilder.build());
finish();
}
use of de.slackspace.openkeepass.domain.KeePassFile 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;
}
use of de.slackspace.openkeepass.domain.KeePassFile in project TinyKeePass by sorz.
the class EntryRecyclerViewAdapter method reloadEntries.
public void reloadEntries(Context context) {
KeePassFile db = KeePassStorage.get(context);
if (db != null) {
allEntries = KeePassHelper.allEntriesNotInRecycleBin(db).collect(Collectors.toList());
allEntries.sort((a, b) -> {
if (a.getTitle() != null && b.getTitle() != null)
return a.getTitle().compareTo(b.getTitle());
else if (a.getUsername() != null && b.getUsername() != null)
return a.getUsername().compareTo(b.getUsername());
else if (a.getUrl() != null && b.getUrl() != null)
return a.getUrl().compareTo(b.getUrl());
else
return a.getTimes().getCreationTime().compareTo(b.getTimes().getCreationTime());
});
Log.d(TAG, allEntries.size() + " entries loaded");
} else {
Log.w(TAG, "database is locked");
allEntries = new ArrayList<>();
}
setFilter(filter);
}
Aggregations