aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-12-29 23:16:54 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-12-29 23:16:54 +0100
commit610c4780f13cbfb0f85eb74ee8c6bed4f18eb70a (patch)
tree0072696eefb6dcc5097002a228d70764ee8b2bef /OpenKeychain/src/main/java
parent320f82587868bf081ac858c1e8b2e7ee7e36c49c (diff)
downloadopen-keychain-610c4780f13cbfb0f85eb74ee8c6bed4f18eb70a.tar.gz
open-keychain-610c4780f13cbfb0f85eb74ee8c6bed4f18eb70a.tar.bz2
open-keychain-610c4780f13cbfb0f85eb74ee8c6bed4f18eb70a.zip
New work on PIN and lock pattern UI
Diffstat (limited to 'OpenKeychain/src/main/java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java7
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java117
2 files changed, 91 insertions, 33 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
index f9fa41528..a965d4819 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
@@ -83,7 +83,8 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
}
public enum SecretKeyType {
- UNAVAILABLE(0), GNU_DUMMY(1), PASSPHRASE(2), PASSPHRASE_EMPTY(3), DIVERT_TO_CARD(4);
+ UNAVAILABLE(0), GNU_DUMMY(1), PASSPHRASE(2), PASSPHRASE_EMPTY(3), DIVERT_TO_CARD(4), PIN(5),
+ PATTERN(6);
final int mNum;
@@ -101,6 +102,10 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
return PASSPHRASE_EMPTY;
case 4:
return DIVERT_TO_CARD;
+ case 5:
+ return PIN;
+ case 6:
+ return PATTERN;
// if this case happens, it's probably a check from a database value
default:
return UNAVAILABLE;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java
index deff648ba..4c65aa314 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java
@@ -41,6 +41,8 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
+import com.haibison.android.lockpattern.LockPatternActivity;
+
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
@@ -68,6 +70,8 @@ public class PassphraseDialogActivity extends FragmentActivity {
// special extra for OpenPgpService
public static final String EXTRA_DATA = "data";
+ private static final int REQUEST_CODE_ENTER_PATTERN = 2;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -90,6 +94,40 @@ public class PassphraseDialogActivity extends FragmentActivity {
show(this, keyId, serviceIntent);
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case REQUEST_CODE_ENTER_PATTERN: {
+ /*
+ * NOTE that there are 4 possible result codes!!!
+ */
+ switch (resultCode) {
+ case RESULT_OK:
+ // The user passed
+ break;
+ case RESULT_CANCELED:
+ // The user cancelled the task
+ break;
+ case LockPatternActivity.RESULT_FAILED:
+ // The user failed to enter the pattern
+ break;
+ case LockPatternActivity.RESULT_FORGOT_PATTERN:
+ // The user forgot the pattern and invoked your recovery Activity.
+ break;
+ }
+
+ /*
+ * In any case, there's always a key EXTRA_RETRY_COUNT, which holds
+ * the number of tries that the user did.
+ */
+ int retryCount = data.getIntExtra(
+ LockPatternActivity.EXTRA_RETRY_COUNT, 0);
+
+ break;
+ }
+ }
+ }
+
/**
* Shows passphrase dialog to cache a new passphrase the user enters for using it later for
* encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks
@@ -138,7 +176,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme);
- alert.setTitle(R.string.title_authentication);
+ alert.setTitle(R.string.title_unlock);
String userId;
CanonicalizedSecretKey.SecretKeyType keyType = CanonicalizedSecretKey.SecretKeyType.PASSPHRASE;
@@ -171,7 +209,10 @@ public class PassphraseDialogActivity extends FragmentActivity {
message = getString(R.string.passphrase_for, userId);
break;
case DIVERT_TO_CARD:
- message = getString(R.string.yubikey_pin, userId);
+ message = getString(R.string.yubikey_pin_for, userId);
+ break;
+ case PIN:
+ message = getString(R.string.pin_for, userId);
break;
default:
message = "This should not happen!";
@@ -209,40 +250,52 @@ public class PassphraseDialogActivity extends FragmentActivity {
}
});
- // Hack to open keyboard.
- // This is the only method that I found to work across all Android versions
- // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/
- // Notes: * onCreateView can't be used because we want to add buttons to the dialog
- // * opening in onActivityCreated does not work on Android 4.4
- mPassphraseEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- mPassphraseEditText.post(new Runnable() {
- @Override
- public void run() {
- if (getActivity() == null || mPassphraseEditText == null) {
- return;
+
+ if (keyType == CanonicalizedSecretKey.SecretKeyType.PATTERN) {
+ // start pattern dialog and show progress circle here...
+ Intent patternActivity = new Intent(getActivity(), LockPatternActivity.class);
+ patternActivity.putExtra(LockPatternActivity.EXTRA_PATTERN, "123");
+ startActivityForResult(patternActivity, REQUEST_CODE_ENTER_PATTERN);
+ mInput.setVisibility(View.GONE);
+ mProgress.setVisibility(View.VISIBLE);
+ } else {
+ // Hack to open keyboard.
+ // This is the only method that I found to work across all Android versions
+ // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/
+ // Notes: * onCreateView can't be used because we want to add buttons to the dialog
+ // * opening in onActivityCreated does not work on Android 4.4
+ mPassphraseEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ mPassphraseEditText.post(new Runnable() {
+ @Override
+ public void run() {
+ if (getActivity() == null || mPassphraseEditText == null) {
+ return;
+ }
+ InputMethodManager imm = (InputMethodManager) getActivity()
+ .getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.showSoftInput(mPassphraseEditText, InputMethodManager.SHOW_IMPLICIT);
}
- InputMethodManager imm = (InputMethodManager) getActivity()
- .getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(mPassphraseEditText, InputMethodManager.SHOW_IMPLICIT);
- }
- });
+ });
+ }
+ });
+ mPassphraseEditText.requestFocus();
+
+ mPassphraseEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
+ mPassphraseEditText.setOnEditorActionListener(this);
+
+ if (keyType == CanonicalizedSecretKey.SecretKeyType.DIVERT_TO_CARD && Preferences.getPreferences(activity).useNumKeypadForYubikeyPin()) {
+ mPassphraseEditText.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ } else if (keyType == CanonicalizedSecretKey.SecretKeyType.PIN) {
+ mPassphraseEditText.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ } else {
+ mPassphraseEditText.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
- });
- mPassphraseEditText.requestFocus();
- mPassphraseEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
- mPassphraseEditText.setOnEditorActionListener(this);
-
- if (keyType == CanonicalizedSecretKey.SecretKeyType.DIVERT_TO_CARD && Preferences.getPreferences(activity).useNumKeypadForYubikeyPin()) {
- mPassphraseEditText.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD);
- } else {
- mPassphraseEditText.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ mPassphraseEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
- mPassphraseEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
-
AlertDialog dialog = alert.create();
dialog.setButton(DialogInterface.BUTTON_POSITIVE,
activity.getString(android.R.string.ok), (DialogInterface.OnClickListener) null);
@@ -264,7 +317,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
// Early breakout if we are dealing with a symmetric key
if (mSecretRing == null) {
PassphraseCacheService.addCachedPassphrase(getActivity(),
- Constants.key.symmetric, Constants.key.symmetric, passphrase,
+ Constants.key.symmetric, Constants.key.symmetric, passphrase,
getString(R.string.passp_cache_notif_pwd));
finishCaching(passphrase);