mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
Merge pull request #963 from jkolo/feature/numpad4yubikey
Added option for num keypad for YubiKey
This commit is contained in:
commit
78e313ec42
@ -83,6 +83,7 @@ public final class Constants {
|
|||||||
public static final String SEARCH_KEYSERVER = "search_keyserver_pref";
|
public static final String SEARCH_KEYSERVER = "search_keyserver_pref";
|
||||||
public static final String SEARCH_KEYBASE = "search_keybase_pref";
|
public static final String SEARCH_KEYBASE = "search_keybase_pref";
|
||||||
public static final String USE_DEFAULT_YUBIKEY_PIN = "useDefaultYubikeyPin";
|
public static final String USE_DEFAULT_YUBIKEY_PIN = "useDefaultYubikeyPin";
|
||||||
|
public static final String USE_NUMKEYPAD_FOR_YUBIKEY_PIN="useNumKeypadForYubikeyPin";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Defaults {
|
public static final class Defaults {
|
||||||
|
@ -27,6 +27,8 @@ import android.os.AsyncTask;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.text.method.PasswordTransformationMethod;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -52,6 +54,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We can not directly create a dialog on the application context.
|
* We can not directly create a dialog on the application context.
|
||||||
@ -138,6 +141,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
alert.setTitle(R.string.title_authentication);
|
alert.setTitle(R.string.title_authentication);
|
||||||
|
|
||||||
String userId;
|
String userId;
|
||||||
|
CanonicalizedSecretKey.SecretKeyType keyType = CanonicalizedSecretKey.SecretKeyType.PASSPHRASE;
|
||||||
|
|
||||||
if (mSubKeyId == Constants.key.symmetric || mSubKeyId == Constants.key.none) {
|
if (mSubKeyId == Constants.key.symmetric || mSubKeyId == Constants.key.none) {
|
||||||
alert.setMessage(R.string.passphrase_for_symmetric_encryption);
|
alert.setMessage(R.string.passphrase_for_symmetric_encryption);
|
||||||
@ -161,7 +165,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
long masterKeyId = new ProviderHelper(activity).getMasterKeyId(mSubKeyId);
|
long masterKeyId = new ProviderHelper(activity).getMasterKeyId(mSubKeyId);
|
||||||
CachedPublicKeyRing keyRing = new ProviderHelper(activity).getCachedPublicKeyRing(masterKeyId);
|
CachedPublicKeyRing keyRing = new ProviderHelper(activity).getCachedPublicKeyRing(masterKeyId);
|
||||||
// get the type of key (from the database)
|
// get the type of key (from the database)
|
||||||
CanonicalizedSecretKey.SecretKeyType keyType = keyRing.getSecretKeyType(mSubKeyId);
|
keyType = keyRing.getSecretKeyType(mSubKeyId);
|
||||||
switch (keyType) {
|
switch (keyType) {
|
||||||
case PASSPHRASE:
|
case PASSPHRASE:
|
||||||
message = getString(R.string.passphrase_for, userId);
|
message = getString(R.string.passphrase_for, userId);
|
||||||
@ -231,6 +235,14 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
mPassphraseEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
|
mPassphraseEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
|
||||||
mPassphraseEditText.setOnEditorActionListener(this);
|
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());
|
||||||
|
|
||||||
AlertDialog dialog = alert.create();
|
AlertDialog dialog = alert.create();
|
||||||
dialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
dialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
||||||
activity.getString(android.R.string.ok), (DialogInterface.OnClickListener) null);
|
activity.getString(android.R.string.ok), (DialogInterface.OnClickListener) null);
|
||||||
|
@ -127,6 +127,9 @@ public class PreferencesActivity extends PreferenceActivity {
|
|||||||
initializeUseDefaultYubikeyPin(
|
initializeUseDefaultYubikeyPin(
|
||||||
(CheckBoxPreference) findPreference(Constants.Pref.USE_DEFAULT_YUBIKEY_PIN));
|
(CheckBoxPreference) findPreference(Constants.Pref.USE_DEFAULT_YUBIKEY_PIN));
|
||||||
|
|
||||||
|
initializeUseNumKeypadForYubikeyPin(
|
||||||
|
(CheckBoxPreference) findPreference(Constants.Pref.USE_NUMKEYPAD_FOR_YUBIKEY_PIN));
|
||||||
|
|
||||||
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||||
// Load the legacy preferences headers
|
// Load the legacy preferences headers
|
||||||
addPreferencesFromResource(R.xml.preference_headers_legacy);
|
addPreferencesFromResource(R.xml.preference_headers_legacy);
|
||||||
@ -278,6 +281,9 @@ public class PreferencesActivity extends PreferenceActivity {
|
|||||||
|
|
||||||
initializeUseDefaultYubikeyPin(
|
initializeUseDefaultYubikeyPin(
|
||||||
(CheckBoxPreference) findPreference(Constants.Pref.USE_DEFAULT_YUBIKEY_PIN));
|
(CheckBoxPreference) findPreference(Constants.Pref.USE_DEFAULT_YUBIKEY_PIN));
|
||||||
|
|
||||||
|
initializeUseNumKeypadForYubikeyPin(
|
||||||
|
(CheckBoxPreference) findPreference(Constants.Pref.USE_NUMKEYPAD_FOR_YUBIKEY_PIN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,4 +469,14 @@ public class PreferencesActivity extends PreferenceActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void initializeUseNumKeypadForYubikeyPin(final CheckBoxPreference mUseNumKeypadForYubikeyPin) {
|
||||||
|
mUseNumKeypadForYubikeyPin.setChecked(sPreferences.useNumKeypadForYubikeyPin());
|
||||||
|
mUseNumKeypadForYubikeyPin.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
mUseNumKeypadForYubikeyPin.setChecked((Boolean) newValue);
|
||||||
|
sPreferences.setUseNumKeypadForYubikeyPin((Boolean) newValue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ import android.os.Messenger;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.text.method.PasswordTransformationMethod;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -54,6 +56,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
|||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
public class PassphraseDialogFragment extends DialogFragment implements OnEditorActionListener {
|
public class PassphraseDialogFragment extends DialogFragment implements OnEditorActionListener {
|
||||||
private static final String ARG_MESSENGER = "messenger";
|
private static final String ARG_MESSENGER = "messenger";
|
||||||
@ -132,6 +135,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
alert.setTitle(R.string.title_authentication);
|
alert.setTitle(R.string.title_authentication);
|
||||||
|
|
||||||
String userId;
|
String userId;
|
||||||
|
CanonicalizedSecretKey.SecretKeyType keyType = CanonicalizedSecretKey.SecretKeyType.PASSPHRASE;
|
||||||
|
|
||||||
if (mSubKeyId == Constants.key.symmetric || mSubKeyId == Constants.key.none) {
|
if (mSubKeyId == Constants.key.symmetric || mSubKeyId == Constants.key.none) {
|
||||||
alert.setMessage(R.string.passphrase_for_symmetric_encryption);
|
alert.setMessage(R.string.passphrase_for_symmetric_encryption);
|
||||||
@ -155,7 +159,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
long masterKeyId = new ProviderHelper(getActivity()).getMasterKeyId(mSubKeyId);
|
long masterKeyId = new ProviderHelper(getActivity()).getMasterKeyId(mSubKeyId);
|
||||||
CachedPublicKeyRing keyRing = new ProviderHelper(getActivity()).getCachedPublicKeyRing(masterKeyId);
|
CachedPublicKeyRing keyRing = new ProviderHelper(getActivity()).getCachedPublicKeyRing(masterKeyId);
|
||||||
// get the type of key (from the database)
|
// get the type of key (from the database)
|
||||||
CanonicalizedSecretKey.SecretKeyType keyType = keyRing.getSecretKeyType(mSubKeyId);
|
keyType = keyRing.getSecretKeyType(mSubKeyId);
|
||||||
switch (keyType) {
|
switch (keyType) {
|
||||||
case PASSPHRASE:
|
case PASSPHRASE:
|
||||||
message = getString(R.string.passphrase_for, userId);
|
message = getString(R.string.passphrase_for, userId);
|
||||||
@ -226,6 +230,13 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
mPassphraseEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
|
mPassphraseEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
|
||||||
mPassphraseEditText.setOnEditorActionListener(this);
|
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());
|
||||||
|
|
||||||
AlertDialog dialog = alert.create();
|
AlertDialog dialog = alert.create();
|
||||||
dialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
dialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
||||||
activity.getString(android.R.string.ok), (DialogInterface.OnClickListener) null);
|
activity.getString(android.R.string.ok), (DialogInterface.OnClickListener) null);
|
||||||
|
@ -191,6 +191,16 @@ public class Preferences {
|
|||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean useNumKeypadForYubikeyPin() {
|
||||||
|
return mSharedPreferences.getBoolean(Pref.USE_NUMKEYPAD_FOR_YUBIKEY_PIN, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseNumKeypadForYubikeyPin(boolean useNumKeypadForYubikeyPin) {
|
||||||
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||||
|
editor.putBoolean(Pref.USE_NUMKEYPAD_FOR_YUBIKEY_PIN, useNumKeypadForYubikeyPin);
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
|
||||||
public void setFirstTime(boolean value) {
|
public void setFirstTime(boolean value) {
|
||||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||||
editor.putBoolean(Constants.Pref.FIRST_TIME, value);
|
editor.putBoolean(Constants.Pref.FIRST_TIME, value);
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:imeOptions="actionDone"
|
android:imeOptions="actionDone"
|
||||||
android:inputType="textPassword"
|
|
||||||
android:hint="@string/label_passphrase"
|
android:hint="@string/label_passphrase"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:layout_gravity="center_horizontal" />
|
android:layout_gravity="center_horizontal" />
|
||||||
|
@ -112,6 +112,7 @@
|
|||||||
<string name="label_write_version_header">"Let others know that you're using OpenKeychain"</string>
|
<string name="label_write_version_header">"Let others know that you're using OpenKeychain"</string>
|
||||||
<string name="label_write_version_header_summary">"Writes 'OpenKeychain v2.7' to OpenPGP signatures, ciphertext, and exported keys"</string>
|
<string name="label_write_version_header_summary">"Writes 'OpenKeychain v2.7' to OpenPGP signatures, ciphertext, and exported keys"</string>
|
||||||
<string name="label_use_default_yubikey_pin">"Use default Yubikey PIN"</string>
|
<string name="label_use_default_yubikey_pin">"Use default Yubikey PIN"</string>
|
||||||
|
<string name="label_use_num_keypad_for_yubikey_pin">Use number keypad for Yubikey PIN</string>
|
||||||
<string name="label_label_use_default_yubikey_pin_summary">"Uses default PIN (123456) to access Yubikeys over NFC"</string>
|
<string name="label_label_use_default_yubikey_pin_summary">"Uses default PIN (123456) to access Yubikeys over NFC"</string>
|
||||||
<string name="label_asymmetric_from">"Signed by:"</string>
|
<string name="label_asymmetric_from">"Signed by:"</string>
|
||||||
<string name="label_to">"Encrypt to:"</string>
|
<string name="label_to">"Encrypt to:"</string>
|
||||||
|
@ -44,5 +44,9 @@
|
|||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:title="@string/label_use_default_yubikey_pin"
|
android:title="@string/label_use_default_yubikey_pin"
|
||||||
android:summary="@string/label_label_use_default_yubikey_pin_summary" />
|
android:summary="@string/label_label_use_default_yubikey_pin_summary" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="useNumKeypadForYubikeyPin"
|
||||||
|
android:persistent="false"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:title="@string/label_use_num_keypad_for_yubikey_pin" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
Loading…
Reference in New Issue
Block a user