diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain')
4 files changed, 81 insertions, 89 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 4cbb4724e..9ed8e369d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -35,6 +35,7 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; +import org.bouncycastle.bcpg.PublicKeyAlgorithmTags; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; @@ -440,50 +441,45 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment<SaveKeyring } break; } - case EditSubkeyDialogFragment.MESSAGE_MOVE_KEY_TO_CARD: { - // TODO: enable later when Admin PIN handling is resolved - Notify.create(getActivity(), - "This feature will be available in an upcoming OpenKeychain version.", - Notify.Style.WARN).show(); - break; + case EditSubkeyDialogFragment.MESSAGE_MOVE_KEY_TO_SECURITY_TOKEN: { + SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position); + if (secretKeyType == SecretKeyType.DIVERT_TO_CARD || + secretKeyType == SecretKeyType.GNU_DUMMY) { + Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_stripped, Notify.Style.ERROR) + .show(); + break; + } + + int algorithm = mSubkeysAdapter.getAlgorithm(position); + if (algorithm != PublicKeyAlgorithmTags.RSA_GENERAL + && algorithm != PublicKeyAlgorithmTags.RSA_ENCRYPT + && algorithm != PublicKeyAlgorithmTags.RSA_SIGN) { + Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_algo, Notify.Style.ERROR) + .show(); + break; + } + + if (mSubkeysAdapter.getKeySize(position) != 2048) { + Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_size, Notify.Style.ERROR) + .show(); + break; + } -// Activity activity = EditKeyFragment.this.getActivity(); -// SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position); -// if (secretKeyType == SecretKeyType.DIVERT_TO_CARD || -// secretKeyType == SecretKeyType.GNU_DUMMY) { -// Notify.create(activity, R.string.edit_key_error_bad_nfc_stripped, Notify.Style.ERROR) -// .show((ViewGroup) activity.findViewById(R.id.import_snackbar)); -// break; -// } -// int algorithm = mSubkeysAdapter.getAlgorithm(position); -// // these are the PGP constants for RSA_GENERAL, RSA_ENCRYPT and RSA_SIGN -// if (algorithm != 1 && algorithm != 2 && algorithm != 3) { -// Notify.create(activity, R.string.edit_key_error_bad_nfc_algo, Notify.Style.ERROR) -// .show((ViewGroup) activity.findViewById(R.id.import_snackbar)); -// break; -// } -// if (mSubkeysAdapter.getKeySize(position) != 2048) { -// Notify.create(activity, R.string.edit_key_error_bad_nfc_size, Notify.Style.ERROR) -// .show((ViewGroup) activity.findViewById(R.id.import_snackbar)); -// break; -// } -// -// -// SubkeyChange change; -// change = mSaveKeyringParcel.getSubkeyChange(keyId); -// if (change == null) { -// mSaveKeyringParcel.mChangeSubKeys.add( -// new SubkeyChange(keyId, false, true) -// ); -// break; -// } -// // toggle -// change.mMoveKeyToSecurityToken = !change.mMoveKeyToSecurityToken; -// if (change.mMoveKeyToSecurityToken && change.mDummyStrip) { -// // User had chosen to strip key, but now wants to divert it. -// change.mDummyStrip = false; -// } -// break; + SubkeyChange change; + change = mSaveKeyringParcel.getSubkeyChange(keyId); + if (change == null) { + mSaveKeyringParcel.mChangeSubKeys.add( + new SubkeyChange(keyId, false, true) + ); + break; + } + // toggle + change.mMoveKeyToSecurityToken = !change.mMoveKeyToSecurityToken; + if (change.mMoveKeyToSecurityToken && change.mDummyStrip) { + // User had chosen to strip key, but now wants to divert it. + change.mDummyStrip = false; + } + break; } } getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvSubkeysFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvSubkeysFragment.java index fc6db1b92..93b38af9b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvSubkeysFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvSubkeysFragment.java @@ -39,6 +39,7 @@ import android.widget.AdapterView; import android.widget.ListView; import android.widget.ViewAnimator; +import org.bouncycastle.bcpg.PublicKeyAlgorithmTags; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; @@ -346,50 +347,45 @@ public class ViewKeyAdvSubkeysFragment extends LoaderFragment implements } break; } - case EditSubkeyDialogFragment.MESSAGE_MOVE_KEY_TO_CARD: { - // TODO: enable later when Admin PIN handling is resolved - Notify.create(getActivity(), - "This feature will be available in an upcoming OpenKeychain version.", - Notify.Style.WARN).show(); - break; + case EditSubkeyDialogFragment.MESSAGE_MOVE_KEY_TO_SECURITY_TOKEN: { + SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position); + if (secretKeyType == SecretKeyType.DIVERT_TO_CARD || + secretKeyType == SecretKeyType.GNU_DUMMY) { + Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_stripped, Notify.Style.ERROR) + .show(); + break; + } + + int algorithm = mSubkeysAdapter.getAlgorithm(position); + if (algorithm != PublicKeyAlgorithmTags.RSA_GENERAL + && algorithm != PublicKeyAlgorithmTags.RSA_ENCRYPT + && algorithm != PublicKeyAlgorithmTags.RSA_SIGN) { + Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_algo, Notify.Style.ERROR) + .show(); + break; + } + + if (mSubkeysAdapter.getKeySize(position) != 2048) { + Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_size, Notify.Style.ERROR) + .show(); + break; + } -// Activity activity = EditKeyFragment.this.getActivity(); -// SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position); -// if (secretKeyType == SecretKeyType.DIVERT_TO_CARD || -// secretKeyType == SecretKeyType.GNU_DUMMY) { -// Notify.create(activity, R.string.edit_key_error_bad_nfc_stripped, Notify.Style.ERROR) -// .show((ViewGroup) activity.findViewById(R.id.import_snackbar)); -// break; -// } -// int algorithm = mSubkeysAdapter.getAlgorithm(position); -// // these are the PGP constants for RSA_GENERAL, RSA_ENCRYPT and RSA_SIGN -// if (algorithm != 1 && algorithm != 2 && algorithm != 3) { -// Notify.create(activity, R.string.edit_key_error_bad_nfc_algo, Notify.Style.ERROR) -// .show((ViewGroup) activity.findViewById(R.id.import_snackbar)); -// break; -// } -// if (mSubkeysAdapter.getKeySize(position) != 2048) { -// Notify.create(activity, R.string.edit_key_error_bad_nfc_size, Notify.Style.ERROR) -// .show((ViewGroup) activity.findViewById(R.id.import_snackbar)); -// break; -// } -// -// -// SubkeyChange change; -// change = mSaveKeyringParcel.getSubkeyChange(keyId); -// if (change == null) { -// mSaveKeyringParcel.mChangeSubKeys.add( -// new SubkeyChange(keyId, false, true) -// ); -// break; -// } -// // toggle -// change.mMoveKeyToSecurityToken = !change.mMoveKeyToSecurityToken; -// if (change.mMoveKeyToSecurityToken && change.mDummyStrip) { -// // User had chosen to strip key, but now wants to divert it. -// change.mDummyStrip = false; -// } -// break; + SubkeyChange change; + change = mEditModeSaveKeyringParcel.getSubkeyChange(keyId); + if (change == null) { + mEditModeSaveKeyringParcel.mChangeSubKeys.add( + new SubkeyChange(keyId, false, true) + ); + break; + } + // toggle + change.mMoveKeyToSecurityToken = !change.mMoveKeyToSecurityToken; + if (change.mMoveKeyToSecurityToken && change.mDummyStrip) { + // User had chosen to strip key, but now wants to divert it. + change.mDummyStrip = false; + } + break; } } getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/EditSubkeyDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/EditSubkeyDialogFragment.java index 9f5ffc358..0c0877bae 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/EditSubkeyDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/EditSubkeyDialogFragment.java @@ -35,7 +35,7 @@ public class EditSubkeyDialogFragment extends DialogFragment { public static final int MESSAGE_CHANGE_EXPIRY = 1; public static final int MESSAGE_REVOKE = 2; public static final int MESSAGE_STRIP = 3; - public static final int MESSAGE_MOVE_KEY_TO_CARD = 4; + public static final int MESSAGE_MOVE_KEY_TO_SECURITY_TOKEN = 4; public static final int SUBKEY_MENU_CHANGE_EXPIRY = 0; public static final int SUBKEY_MENU_REVOKE_SUBKEY = 1; public static final int SUBKEY_MENU_STRIP_SUBKEY = 2; @@ -82,7 +82,7 @@ public class EditSubkeyDialogFragment extends DialogFragment { showAlertDialog(); break; case SUBKEY_MENU_MOVE_TO_SECURITY_TOKEN: - sendMessageToHandler(MESSAGE_MOVE_KEY_TO_CARD, null); + sendMessageToHandler(MESSAGE_MOVE_KEY_TO_SECURITY_TOKEN, null); break; default: break; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java index 5fcc3d58b..4dc0ebaa0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java @@ -64,8 +64,8 @@ public class KeyFormattingUtils { String algorithmStr; switch (algorithm) { - case PublicKeyAlgorithmTags.RSA_ENCRYPT: case PublicKeyAlgorithmTags.RSA_GENERAL: + case PublicKeyAlgorithmTags.RSA_ENCRYPT: case PublicKeyAlgorithmTags.RSA_SIGN: { algorithmStr = "RSA"; break; |