Skip to content

Commit 97762fa

Browse files
Merge pull request #1641 from alexbakker/fix-1605
Fall back to default values in the FreeOTP importer
2 parents 60eea0b + c81e08b commit 97762fa

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

app/src/main/java/com/beemdevelopment/aegis/importers/FreeOtpImporter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ public Result convert() {
298298
private static VaultEntry convertEntry(JSONObject obj) throws DatabaseImporterEntryException {
299299
try {
300300
String type = obj.getString("type").toLowerCase(Locale.ROOT);
301-
String algo = obj.getString("algo");
302-
int digits = obj.getInt("digits");
301+
String algo = obj.optString("algo", OtpInfo.DEFAULT_ALGORITHM);
302+
int digits = obj.optInt("digits", OtpInfo.DEFAULT_DIGITS);
303303
byte[] secret = toBytes(obj.getJSONArray("secret"));
304304

305305
String issuer = obj.getString("issuerExt");
@@ -308,7 +308,7 @@ private static VaultEntry convertEntry(JSONObject obj) throws DatabaseImporterEn
308308
OtpInfo info;
309309
switch (type) {
310310
case "totp":
311-
int period = obj.getInt("period");
311+
int period = obj.optInt("period", TotpInfo.DEFAULT_PERIOD);
312312
if (issuer.equals("Steam")) {
313313
info = new SteamInfo(secret, algo, digits, period);
314314
} else {

app/src/test/java/com/beemdevelopment/aegis/importers/DatabaseImporterTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ public void testImportFreeOtpV2Api34() throws IOException, DatabaseImporterExcep
257257
checkImportedEntries(entries);
258258
}
259259

260+
@Test
261+
public void testImportFreeOtpV2NullAlgo() throws IOException, DatabaseImporterException, OtpInfoException {
262+
List<VaultEntry> entries = importEncrypted(FreeOtpImporter.class, "freeotp_v2_null_algo.xml", encryptedState -> {
263+
final char[] password = "test".toCharArray();
264+
return ((FreeOtpImporter.EncryptedState) encryptedState).decrypt(password);
265+
});
266+
checkImportedEntries(entries);
267+
}
268+
260269
@Test
261270
public void testImportFreeOtpPlus() throws IOException, DatabaseImporterException, OtpInfoException {
262271
List<VaultEntry> entries = importPlain(FreeOtpPlusImporter.class, "freeotp_plus.json");

0 commit comments

Comments
 (0)