mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Disable some fields if Steam OTP type is selected
Also, move some magic default OTP parameters to constants
This commit is contained in:
parent
bc6cb35dc0
commit
2c8a64f943
15 changed files with 55 additions and 29 deletions
|
@ -239,7 +239,7 @@ public class AndOtpImporter extends DatabaseImporter {
|
|||
info = new TotpInfo(secret, algo, digits, obj.getInt("period"));
|
||||
break;
|
||||
case "steam":
|
||||
info = new SteamInfo(secret, algo, digits, obj.optInt("period", 30));
|
||||
info = new SteamInfo(secret, algo, digits, obj.optInt("period", TotpInfo.DEFAULT_PERIOD));
|
||||
break;
|
||||
default:
|
||||
throw new DatabaseImporterException("unsupported otp type: " + type);
|
||||
|
|
|
@ -256,7 +256,7 @@ public class AuthyImporter extends DatabaseImporter {
|
|||
}
|
||||
|
||||
int digits = entry.getInt("digits");
|
||||
OtpInfo info = new TotpInfo(secret, "SHA1", digits, isAuthy ? 10 : 30);
|
||||
OtpInfo info = new TotpInfo(secret, OtpInfo.DEFAULT_ALGORITHM, digits, isAuthy ? 10 : TotpInfo.DEFAULT_PERIOD);
|
||||
return new VaultEntry(info, authyEntryInfo.Name, authyEntryInfo.Issuer);
|
||||
} catch (OtpInfoException | JSONException | EncodingException e) {
|
||||
throw new DatabaseImporterEntryException(e, entry.toString());
|
||||
|
|
|
@ -91,7 +91,7 @@ public class MicrosoftAuthImporter extends DatabaseImporter {
|
|||
throw new DatabaseImporterEntryException(String.format("Unsupported OTP type: %d", entry.getType()), entry.toString());
|
||||
}
|
||||
|
||||
OtpInfo info = new TotpInfo(secret, "SHA1", digits, 30);
|
||||
OtpInfo info = new TotpInfo(secret, OtpInfo.DEFAULT_ALGORITHM, digits, TotpInfo.DEFAULT_PERIOD);
|
||||
return new VaultEntry(info, entry.getUserName(), entry.getIssuer());
|
||||
} catch (EncodingException | OtpInfoException e) {
|
||||
throw new DatabaseImporterEntryException(e, entry.toString());
|
||||
|
|
|
@ -221,7 +221,7 @@ public class TotpAuthenticatorImporter extends DatabaseImporter {
|
|||
throw new DatabaseImporterEntryException(String.format("Unsupported secret encoding: base %d", base), obj.toString());
|
||||
}
|
||||
|
||||
TotpInfo info = new TotpInfo(secret, "SHA1", 6, 30);
|
||||
TotpInfo info = new TotpInfo(secret);
|
||||
String name = obj.optString("name");
|
||||
String issuer = obj.optString("issuer");
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ public class GoogleAuthInfo implements Serializable {
|
|||
case DIGIT_COUNT_UNSPECIFIED:
|
||||
// intentional fallthrough
|
||||
case DIGIT_COUNT_SIX:
|
||||
digits = 6;
|
||||
digits = TotpInfo.DEFAULT_DIGITS;
|
||||
break;
|
||||
case DIGIT_COUNT_EIGHT:
|
||||
digits = 8;
|
||||
|
@ -252,7 +252,7 @@ public class GoogleAuthInfo implements Serializable {
|
|||
case OTP_TYPE_UNSPECIFIED:
|
||||
// intentional fallthrough
|
||||
case OTP_TYPE_TOTP:
|
||||
otp = new TotpInfo(secret, algo, digits, 30);
|
||||
otp = new TotpInfo(secret, algo, digits, TotpInfo.DEFAULT_PERIOD);
|
||||
break;
|
||||
case OTP_TYPE_HOTP:
|
||||
otp = new HotpInfo(secret, algo, digits, params.getCounter());
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.security.NoSuchAlgorithmException;
|
|||
|
||||
public class HotpInfo extends OtpInfo {
|
||||
public static final String ID = "hotp";
|
||||
public static final int DEFAULT_COUNTER = 0;
|
||||
|
||||
private long _counter;
|
||||
|
||||
|
@ -20,7 +21,7 @@ public class HotpInfo extends OtpInfo {
|
|||
}
|
||||
|
||||
public HotpInfo(byte[] secret) throws OtpInfoException {
|
||||
this(secret, 0);
|
||||
this(secret, DEFAULT_COUNTER);
|
||||
}
|
||||
|
||||
public HotpInfo(byte[] secret, String algorithm, int digits, long counter) throws OtpInfoException {
|
||||
|
|
|
@ -10,12 +10,15 @@ import java.io.Serializable;
|
|||
import java.util.Arrays;
|
||||
|
||||
public abstract class OtpInfo implements Serializable {
|
||||
public static final int DEFAULT_DIGITS = 6;
|
||||
public static final String DEFAULT_ALGORITHM = "SHA1";
|
||||
|
||||
private byte[] _secret;
|
||||
private String _algorithm;
|
||||
private int _digits;
|
||||
|
||||
public OtpInfo(byte[] secret) throws OtpInfoException {
|
||||
this(secret, "SHA1", 6);
|
||||
this(secret, DEFAULT_ALGORITHM, DEFAULT_DIGITS);
|
||||
}
|
||||
|
||||
public OtpInfo(byte[] secret, String algorithm, int digits) throws OtpInfoException {
|
||||
|
@ -29,7 +32,7 @@ public abstract class OtpInfo implements Serializable {
|
|||
public abstract String getTypeId();
|
||||
|
||||
public String getType() {
|
||||
return getType().toUpperCase();
|
||||
return getTypeId().toUpperCase();
|
||||
}
|
||||
|
||||
public JSONObject toJson() {
|
||||
|
|
|
@ -8,9 +8,10 @@ import java.security.NoSuchAlgorithmException;
|
|||
|
||||
public class SteamInfo extends TotpInfo {
|
||||
public static final String ID = "steam";
|
||||
public static final int DIGITS = 5;
|
||||
|
||||
public SteamInfo(byte[] secret) throws OtpInfoException {
|
||||
super(secret, "SHA1", 5, 30);
|
||||
super(secret, OtpInfo.DEFAULT_ALGORITHM, DIGITS, TotpInfo.DEFAULT_PERIOD);
|
||||
}
|
||||
|
||||
public SteamInfo(byte[] secret, String algorithm, int digits, int period) throws OtpInfoException {
|
||||
|
|
|
@ -11,12 +11,13 @@ import java.security.NoSuchAlgorithmException;
|
|||
|
||||
public class TotpInfo extends OtpInfo {
|
||||
public static final String ID = "totp";
|
||||
public static final int DEFAULT_PERIOD = 30;
|
||||
|
||||
private int _period;
|
||||
|
||||
public TotpInfo(byte[] secret) throws OtpInfoException {
|
||||
super(secret);
|
||||
setPeriod(30);
|
||||
setPeriod(DEFAULT_PERIOD);
|
||||
}
|
||||
|
||||
public TotpInfo(byte[] secret, String algorithm, int digits, int period) throws OtpInfoException {
|
||||
|
|
|
@ -81,10 +81,12 @@ public class EditEntryActivity extends AegisActivity {
|
|||
private TextInputEditText _textPeriodCounter;
|
||||
private TextInputLayout _textPeriodCounterLayout;
|
||||
private TextInputEditText _textDigits;
|
||||
private TextInputLayout _textDigitsLayout;
|
||||
private TextInputEditText _textSecret;
|
||||
|
||||
private AutoCompleteTextView _dropdownType;
|
||||
private AutoCompleteTextView _dropdownAlgo;
|
||||
private TextInputLayout _dropdownAlgoLayout;
|
||||
private AutoCompleteTextView _dropdownGroup;
|
||||
private List<String> _dropdownGroupList = new ArrayList<>();
|
||||
|
||||
|
@ -129,9 +131,11 @@ public class EditEntryActivity extends AegisActivity {
|
|||
_textPeriodCounter = findViewById(R.id.text_period_counter);
|
||||
_textPeriodCounterLayout = findViewById(R.id.text_period_counter_layout);
|
||||
_textDigits = findViewById(R.id.text_digits);
|
||||
_textDigitsLayout = findViewById(R.id.text_digits_layout);
|
||||
_textSecret = findViewById(R.id.text_secret);
|
||||
_dropdownType = findViewById(R.id.dropdown_type);
|
||||
DropdownHelper.fillDropdown(this, _dropdownType, R.array.otp_types_array);
|
||||
_dropdownAlgoLayout = findViewById(R.id.dropdown_algo_layout);
|
||||
_dropdownAlgo = findViewById(R.id.dropdown_algo);
|
||||
DropdownHelper.fillDropdown(this, _dropdownAlgo, R.array.otp_algo_array);
|
||||
_dropdownGroup = findViewById(R.id.dropdown_group);
|
||||
|
@ -194,8 +198,9 @@ public class EditEntryActivity extends AegisActivity {
|
|||
_textSecret.setText(secretString);
|
||||
}
|
||||
|
||||
_dropdownType.setText(_origEntry.getInfo().getTypeId().toUpperCase(), false);
|
||||
_dropdownType.setText(_origEntry.getInfo().getType(), false);
|
||||
_dropdownAlgo.setText(_origEntry.getInfo().getAlgorithm(false), false);
|
||||
updateAdvancedFieldStatus(_origEntry.getInfo().getTypeId());
|
||||
|
||||
String group = _origEntry.getGroup();
|
||||
setGroup(group);
|
||||
|
@ -208,18 +213,27 @@ public class EditEntryActivity extends AegisActivity {
|
|||
_dropdownType.setOnItemClickListener((parent, view, position, id) -> {
|
||||
String type = _dropdownType.getText().toString().toLowerCase();
|
||||
switch (type) {
|
||||
case TotpInfo.ID:
|
||||
case SteamInfo.ID:
|
||||
_dropdownAlgo.setText(OtpInfo.DEFAULT_ALGORITHM, false);
|
||||
_textPeriodCounterLayout.setHint(R.string.period_hint);
|
||||
_textPeriodCounter.setText(String.format("%d", 30));
|
||||
_textPeriodCounter.setText(String.valueOf(TotpInfo.DEFAULT_PERIOD));
|
||||
_textDigits.setText(String.valueOf(SteamInfo.DIGITS));
|
||||
break;
|
||||
case TotpInfo.ID:
|
||||
_textPeriodCounterLayout.setHint(R.string.period_hint);
|
||||
_textPeriodCounter.setText(String.valueOf(TotpInfo.DEFAULT_PERIOD));
|
||||
_textDigits.setText(String.valueOf(OtpInfo.DEFAULT_DIGITS));
|
||||
break;
|
||||
case HotpInfo.ID:
|
||||
_textPeriodCounterLayout.setHint(R.string.counter);
|
||||
_textPeriodCounter.setText(String.format("%d", 0));
|
||||
_textPeriodCounter.setText(String.valueOf(HotpInfo.DEFAULT_COUNTER));
|
||||
_textDigits.setText(String.valueOf(OtpInfo.DEFAULT_DIGITS));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(String.format("Unsupported OTP type: %s", type));
|
||||
}
|
||||
|
||||
updateAdvancedFieldStatus(type);
|
||||
});
|
||||
|
||||
_iconView.setOnClickListener(v -> {
|
||||
|
@ -248,6 +262,13 @@ public class EditEntryActivity extends AegisActivity {
|
|||
});
|
||||
}
|
||||
|
||||
private void updateAdvancedFieldStatus(String otpType) {
|
||||
boolean isSteam = otpType.equals(SteamInfo.ID);
|
||||
_textDigitsLayout.setEnabled(!isSteam);
|
||||
_textPeriodCounterLayout.setEnabled(!isSteam);
|
||||
_dropdownAlgoLayout.setEnabled(!isSteam);
|
||||
}
|
||||
|
||||
private void setGroup(String groupName) {
|
||||
int pos = 0;
|
||||
if (groupName != null) {
|
||||
|
|
|
@ -14,7 +14,7 @@ import androidx.annotation.RequiresApi;
|
|||
import com.beemdevelopment.aegis.otp.TotpInfo;
|
||||
|
||||
public class TotpProgressBar extends ProgressBar {
|
||||
private int _period = 30;
|
||||
private int _period = TotpInfo.DEFAULT_PERIOD;
|
||||
private Handler _handler;
|
||||
private float _animDurationScale;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue