Pass the seed from the AuthenticatActivity to the caller
This commit is contained in:
parent
1f4b46e89a
commit
6612095e8f
2 changed files with 22 additions and 10 deletions
|
@ -52,6 +52,8 @@ import static org.shadowice.flocke.andotp.Utilities.Settings.AuthMethod;
|
||||||
|
|
||||||
public class AuthenticateActivity extends ThemedActivity
|
public class AuthenticateActivity extends ThemedActivity
|
||||||
implements EditText.OnEditorActionListener {
|
implements EditText.OnEditorActionListener {
|
||||||
|
public static final String EXTRA_NAME_SEED = "credential_seed";
|
||||||
|
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
AuthMethod authMethod;
|
AuthMethod authMethod;
|
||||||
|
@ -88,7 +90,7 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
|
|
||||||
if (password.isEmpty()) {
|
if (password.isEmpty()) {
|
||||||
Toast.makeText(this, R.string.auth_toast_password_missing, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.auth_toast_password_missing, Toast.LENGTH_LONG).show();
|
||||||
finishWithResult(true);
|
finishWithResult(true, null);
|
||||||
} else {
|
} else {
|
||||||
passwordLabel.setText(R.string.auth_msg_password);
|
passwordLabel.setText(R.string.auth_msg_password);
|
||||||
passwordLayout.setHint(getString(R.string.auth_hint_password));
|
passwordLayout.setHint(getString(R.string.auth_hint_password));
|
||||||
|
@ -104,14 +106,14 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
|
|
||||||
if (password.isEmpty()) {
|
if (password.isEmpty()) {
|
||||||
Toast.makeText(this, R.string.auth_toast_pin_missing, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.auth_toast_pin_missing, Toast.LENGTH_LONG).show();
|
||||||
finishWithResult(true);
|
finishWithResult(true, null);
|
||||||
} else {
|
} else {
|
||||||
passwordLabel.setText(R.string.auth_msg_pin);
|
passwordLabel.setText(R.string.auth_msg_pin);
|
||||||
passwordLayout.setHint(getString(R.string.auth_hint_pin));
|
passwordLayout.setHint(getString(R.string.auth_hint_pin));
|
||||||
passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
finishWithResult(true);
|
finishWithResult(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
|
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
|
||||||
|
@ -129,19 +131,21 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
byte[] passwordArray = Base64.decode(password, Base64.URL_SAFE);
|
byte[] passwordArray = Base64.decode(password, Base64.URL_SAFE);
|
||||||
|
|
||||||
if (Arrays.equals(passwordArray, credentials.password)) {
|
if (Arrays.equals(passwordArray, credentials.password)) {
|
||||||
finishWithResult(true);
|
finishWithResult(true, credentials.seed);
|
||||||
} else {
|
} else {
|
||||||
finishWithResult(false);
|
finishWithResult(false, null);
|
||||||
}
|
}
|
||||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
finishWithResult(false);
|
finishWithResult(false, null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String plainPassword = v.getText().toString();
|
String plainPassword = v.getText().toString();
|
||||||
String hashedPassword = new String(Hex.encodeHex(DigestUtils.sha256(plainPassword)));
|
String hashedPassword = new String(Hex.encodeHex(DigestUtils.sha256(plainPassword)));
|
||||||
|
|
||||||
if (hashedPassword.equals(password)) {
|
if (hashedPassword.equals(password)) {
|
||||||
|
byte[] seed = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int iter = EncryptionHelper.generateRandomIterations();
|
int iter = EncryptionHelper.generateRandomIterations();
|
||||||
EncryptionHelper.PBKDF2Credentials credentials = EncryptionHelper.generatePBKDF2Credentials(plainPassword, settings.getSalt(), iter);
|
EncryptionHelper.PBKDF2Credentials credentials = EncryptionHelper.generatePBKDF2Credentials(plainPassword, settings.getSalt(), iter);
|
||||||
|
@ -153,6 +157,8 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
settings.setAuthPINPBKDF2(base64);
|
settings.setAuthPINPBKDF2(base64);
|
||||||
|
|
||||||
settings.setIterations(authMethod, iter);
|
settings.setIterations(authMethod, iter);
|
||||||
|
|
||||||
|
seed = credentials.seed;
|
||||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||||
Toast.makeText(this, R.string.settings_toast_auth_upgrade_failed, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.settings_toast_auth_upgrade_failed, Toast.LENGTH_LONG).show();
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -163,9 +169,9 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
else if (authMethod == AuthMethod.PIN)
|
else if (authMethod == AuthMethod.PIN)
|
||||||
settings.removeAuthPINHash();
|
settings.removeAuthPINHash();
|
||||||
|
|
||||||
finishWithResult(true);
|
finishWithResult(true, seed);
|
||||||
} else {
|
} else {
|
||||||
finishWithResult(false);
|
finishWithResult(false, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,9 +182,12 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
// End with a result
|
// End with a result
|
||||||
public void finishWithResult(boolean success) {
|
public void finishWithResult(boolean success, byte[] seed) {
|
||||||
Intent data = new Intent();
|
Intent data = new Intent();
|
||||||
|
|
||||||
|
if (seed != null)
|
||||||
|
data.putExtra(EXTRA_NAME_SEED, seed);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
setResult(RESULT_OK, data);
|
setResult(RESULT_OK, data);
|
||||||
|
|
||||||
|
@ -188,7 +197,7 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
// Go back to the main activity
|
// Go back to the main activity
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
finishWithResult(false);
|
finishWithResult(false, null);
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ import org.shadowice.flocke.andotp.View.TagsAdapter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import static org.shadowice.flocke.andotp.Activities.AuthenticateActivity.EXTRA_NAME_SEED;
|
||||||
import static org.shadowice.flocke.andotp.Utilities.Settings.SortMode;
|
import static org.shadowice.flocke.andotp.Utilities.Settings.SortMode;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity
|
public class MainActivity extends BaseActivity
|
||||||
|
@ -376,6 +377,8 @@ public class MainActivity extends BaseActivity
|
||||||
} else {
|
} else {
|
||||||
requireAuthentication = false;
|
requireAuthentication = false;
|
||||||
|
|
||||||
|
byte[] credentialSeed = intent.getByteArrayExtra(EXTRA_NAME_SEED);
|
||||||
|
|
||||||
adapter.setEncryptionKey(KeyStoreHelper.loadEncryptionKeyFromKeyStore(this));
|
adapter.setEncryptionKey(KeyStoreHelper.loadEncryptionKeyFromKeyStore(this));
|
||||||
populateAdapter();
|
populateAdapter();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue