Always try to decrypt the password slot first, before the fallback

This makes sure the case where a user set up Aegis v0.4 with a password of over
64 bytes is also covered.
This commit is contained in:
Alexander Bakker 2019-05-28 10:41:53 +02:00 committed by Michael Schättgen
parent 8c658ac930
commit ff584a323d

View file

@ -61,19 +61,23 @@ public class SlotListTask<T extends Slot> extends ProgressDialogTask<SlotListTas
throws SlotIntegrityException, SlotException {
MasterKey masterKey;
SecretKey key = slot.deriveKey(password);
// a bug introduced in afb9e59 caused 64-byte passwords to produce a different key than before
// so, try the old password encode function if the encoded password is longer than 64 bytes
byte[] oldPasswordBytes = CryptoUtils.toBytesOld(password);
if (!slot.isRepaired() && oldPasswordBytes.length > 64) {
try {
masterKey = decryptPasswordSlot(slot, key);
} catch (SlotIntegrityException e) {
// a bug introduced in afb9e59 caused passwords longer than 64 bytes to produce a different key than before
// so, try again with the old password encode function if the password is longer than 64 bytes
if (slot.isRepaired() || oldPasswordBytes.length <= 64) {
throw e;
}
ProgressDialog dialog = getDialog();
dialog.setMessage(dialog.getContext().getString(R.string.unlocking_vault_repair));
// try to decrypt the password slot with the old key
SecretKey oldKey = slot.deriveKey(oldPasswordBytes);
masterKey = decryptPasswordSlot(slot, oldKey);
} else {
masterKey = decryptPasswordSlot(slot, key);
}
// if necessary, repair the slot by re-encrypting the master key with the correct key