Fall back to default values in the FreeOTP importer

This commit is contained in:
Alexander Bakker 2025-04-23 15:51:49 +02:00
parent a5dc861336
commit c81e08bf1f
3 changed files with 12 additions and 3 deletions

View file

@ -298,8 +298,8 @@ public class FreeOtpImporter extends DatabaseImporter {
private static VaultEntry convertEntry(JSONObject obj) throws DatabaseImporterEntryException {
try {
String type = obj.getString("type").toLowerCase(Locale.ROOT);
String algo = obj.getString("algo");
int digits = obj.getInt("digits");
String algo = obj.optString("algo", OtpInfo.DEFAULT_ALGORITHM);
int digits = obj.optInt("digits", OtpInfo.DEFAULT_DIGITS);
byte[] secret = toBytes(obj.getJSONArray("secret"));
String issuer = obj.getString("issuerExt");
@ -308,7 +308,7 @@ public class FreeOtpImporter extends DatabaseImporter {
OtpInfo info;
switch (type) {
case "totp":
int period = obj.getInt("period");
int period = obj.optInt("period", TotpInfo.DEFAULT_PERIOD);
if (issuer.equals("Steam")) {
info = new SteamInfo(secret, algo, digits, period);
} else {

View file

@ -257,6 +257,15 @@ public class DatabaseImporterTest {
checkImportedEntries(entries);
}
@Test
public void testImportFreeOtpV2NullAlgo() throws IOException, DatabaseImporterException, OtpInfoException {
List<VaultEntry> entries = importEncrypted(FreeOtpImporter.class, "freeotp_v2_null_algo.xml", encryptedState -> {
final char[] password = "test".toCharArray();
return ((FreeOtpImporter.EncryptedState) encryptedState).decrypt(password);
});
checkImportedEntries(entries);
}
@Test
public void testImportFreeOtpPlus() throws IOException, DatabaseImporterException, OtpInfoException {
List<VaultEntry> entries = importPlain(FreeOtpPlusImporter.class, "freeotp_plus.json");