Use the old encode method for passwords over 64 bytes and repair the slot (#98)

Commit afb9e59711 fixed a bug where the password
encode function would add null bytes to the end of the output. Luckily (I
thought), PBKDF2 produces collisions for inputs with trailing null bytes and
thus scrypt does this as well, so we could safely change that function to remove
the null bytes without any impact. Unfortunately, that doesn't hold up if the
password is over 64 bytes in size. So after that change, the KDF started
producing different keys than before for such passwords and thus some users
could no longer unlock their vault.

This patch addresses the issue by using the old password encode function for
passwords over 64 bytes and repairing the affected password slot.
This commit is contained in:
Alexander Bakker 2019-05-26 23:52:20 +02:00 committed by Michael Schättgen
parent 588c1c07df
commit 8c658ac930
9 changed files with 184 additions and 67 deletions

View file

@ -346,7 +346,13 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
private void onDecryptResult(int resultCode, Intent intent) {
DatabaseFileCredentials creds = (DatabaseFileCredentials) intent.getSerializableExtra("creds");
unlockDatabase(creds);
boolean unlocked = unlockDatabase(creds);
// save the database in case a slot was repaired
if (unlocked && intent.getBooleanExtra("repairedSlot", false)) {
_db.setCredentials(creds);
saveDatabase();
}
doShortcutActions();
}
@ -526,11 +532,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
}
}
private void unlockDatabase(DatabaseFileCredentials creds) {
if (_loaded) {
return;
}
private boolean unlockDatabase(DatabaseFileCredentials creds) {
try {
if (!_db.isLoaded()) {
_db.load();
@ -538,7 +540,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
if (_db.isLocked()) {
if (creds == null) {
startAuthActivity();
return;
return false;
} else {
_db.unlock(creds);
}
@ -546,10 +548,11 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
} catch (DatabaseManagerException e) {
Toast.makeText(this, getString(R.string.decryption_error), Toast.LENGTH_LONG).show();
startAuthActivity();
return;
return false;
}
loadEntries();
return true;
}
private void loadEntries() {