Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/src/main/java/app/notesr/activity/security/AuthActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public final class AuthActivity extends ActivityBase {

public static final String HEX_KEY = "hex_key";
public static final String CACHE_KEY_HEX_KEY = "hexKey";
public static final String EXTRA_MODE = "mode";

@AllArgsConstructor
Expand All @@ -39,7 +39,7 @@ public enum Mode {
private final String mode;
}

private AuthActivityExtension extension;
private AuthHandler authHandler;
private Mode currentMode;

private final SecureStringBuilder passwordBuilder = new SecureStringBuilder();
Expand All @@ -57,7 +57,7 @@ protected void onCreate(Bundle savedInstanceState) {

String mode = getIntent().getStringExtra(EXTRA_MODE);
var appSecurityService = new AppSecurityService(getApplicationContext());
extension = new AuthActivityExtension(this, appSecurityService, passwordBuilder);
authHandler = new AuthHandler(this, appSecurityService, passwordBuilder);

try {
currentMode = Mode.valueOf(mode);
Expand Down Expand Up @@ -122,10 +122,10 @@ private void configure() {

authButton.setOnClickListener(view -> {
switch (currentMode) {
case AUTHENTICATION -> extension.authenticate();
case CREATE_PASSWORD -> extension.createPassword();
case KEY_RECOVERY -> extension.recoverKey();
case CHANGE_PASSWORD -> extension.changePassword();
case AUTHENTICATION -> authHandler.authenticate();
case CREATE_PASSWORD -> authHandler.createPassword();
case KEY_RECOVERY -> authHandler.recoverKey();
case CHANGE_PASSWORD -> authHandler.changePassword();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package app.notesr.activity.security;

import static app.notesr.activity.security.AuthActivity.HEX_KEY;
import static app.notesr.activity.security.AuthActivity.CACHE_KEY_HEX_KEY;
import static app.notesr.core.util.CharUtils.bytesToChars;
import static app.notesr.core.util.CharUtils.charsToBytes;

Expand Down Expand Up @@ -37,9 +37,8 @@
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public final class AuthActivityExtension {
public final class AuthHandler {
private static final int MAX_ATTEMPTS = 3;
private static final int MIN_PASSWORD_LENGTH = 4;
private static final int ON_WRONG_PASSWORD_DELAY_MS = 1500;

private final AuthActivity activity;
Expand Down Expand Up @@ -95,7 +94,7 @@ public void recoverKey() {
if (password != null) {
try {

byte[] hexKeyBytes = SecretCache.take(HEX_KEY);
byte[] hexKeyBytes = SecretCache.take(CACHE_KEY_HEX_KEY);

if (hexKeyBytes == null) {
throw new RuntimeException("Missing hex key");
Expand Down Expand Up @@ -143,13 +142,13 @@ private char[] proceedPasswordSetting() {
TextView topLabel = activity.findViewById(R.id.authTopLabel);

if (createdPassword == null) {
if (passwordBuilder.length() >= MIN_PASSWORD_LENGTH) {
if (passwordBuilder.length() >= CryptoSecrets.PASSWORD_MIN_LENGTH) {
createdPassword = password;
topLabel.setText(activity.getString(R.string.repeat_access_code));
} else {
showToastMessage(String.format(
activity.getString(R.string.minimum_password_length_is_n),
MIN_PASSWORD_LENGTH));
CryptoSecrets.PASSWORD_MIN_LENGTH));
}
} else {
if (Arrays.equals(password, createdPassword)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void apply(EditText hexKeyField, char[] hexKey)
try {
if (appSecurityService.isKeyMatchingWithStored(keyBytes)) {
byte[] hexKeyBytes = charsToBytes(hexKey, StandardCharsets.UTF_8);
SecretCache.put(AuthActivity.HEX_KEY, hexKeyBytes);
SecretCache.put(AuthActivity.CACHE_KEY_HEX_KEY, hexKeyBytes);

// The hex key has already been wiped by charsToBytes
wipeSecretData(keyBytes, hexKeyField);
Expand Down
Loading