mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-11 03:25:05 -05:00
Cache passphrase for edit
This commit is contained in:
parent
85dde66804
commit
2988ac6e7b
@ -357,7 +357,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
}
|
||||
|
||||
SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(
|
||||
messenger, title);
|
||||
messenger, null, title);
|
||||
|
||||
setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog");
|
||||
}
|
||||
|
@ -91,6 +91,8 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
|
||||
private SaveKeyringParcel mSaveKeyringParcel;
|
||||
|
||||
private String mCurrentPassphrase;
|
||||
|
||||
/**
|
||||
* Creates new instance of this fragment
|
||||
*/
|
||||
@ -125,6 +127,8 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
cachePassphraseForEdit();
|
||||
|
||||
// Inflate a "Done"/"Cancel" custom action bar view
|
||||
ActionBarHelper.setTwoButtonView(((ActionBarActivity) getActivity()).getSupportActionBar(),
|
||||
R.string.btn_save, R.drawable.ic_action_save,
|
||||
@ -132,7 +136,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Save
|
||||
save();
|
||||
save(mCurrentPassphrase);
|
||||
}
|
||||
}, R.string.menu_key_edit_cancel, R.drawable.ic_action_cancel,
|
||||
new OnClickListener() {
|
||||
@ -296,7 +300,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
Messenger messenger = new Messenger(returnHandler);
|
||||
|
||||
SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(
|
||||
messenger, R.string.title_change_passphrase);
|
||||
messenger, mCurrentPassphrase, R.string.title_change_passphrase);
|
||||
|
||||
setPassphraseDialog.show(getActivity().getSupportFragmentManager(), "setPassphraseDialog");
|
||||
}
|
||||
@ -350,29 +354,28 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
mSubkeysAddedAdapter.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.SIGN_DATA, null));
|
||||
}
|
||||
|
||||
private void save() {
|
||||
String passphrase = PassphraseCacheService.getCachedPassphrase(getActivity(),
|
||||
private void cachePassphraseForEdit() {
|
||||
mCurrentPassphrase = PassphraseCacheService.getCachedPassphrase(getActivity(),
|
||||
mSaveKeyringParcel.mMasterKeyId);
|
||||
if (passphrase == null) {
|
||||
if (mCurrentPassphrase == null) {
|
||||
PassphraseDialogFragment.show(getActivity(), mSaveKeyringParcel.mMasterKeyId,
|
||||
new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
||||
String passphrase =
|
||||
mCurrentPassphrase =
|
||||
message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE);
|
||||
Log.d(Constants.TAG, "after caching passphrase");
|
||||
saveFinal(passphrase);
|
||||
} else {
|
||||
EditKeyFragment.this.getActivity().finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
saveFinal(passphrase);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFinal(String passphrase) {
|
||||
private void save(String passphrase) {
|
||||
Log.d(Constants.TAG, "add userids to parcel: " + mUserIdsAddedAdapter.getDataAsStringList());
|
||||
mSaveKeyringParcel.addUserIds = mUserIdsAddedAdapter.getDataAsStringList();
|
||||
|
||||
|
@ -26,12 +26,15 @@ import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
@ -44,6 +47,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
public class SetPassphraseDialogFragment extends DialogFragment implements OnEditorActionListener {
|
||||
private static final String ARG_MESSENGER = "messenger";
|
||||
private static final String ARG_TITLE = "title";
|
||||
private static final String ARG_OLD_PASSPHRASE = "title";
|
||||
|
||||
public static final int MESSAGE_OKAY = 1;
|
||||
|
||||
@ -52,6 +56,7 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
||||
private Messenger mMessenger;
|
||||
private EditText mPassphraseEditText;
|
||||
private EditText mPassphraseAgainEditText;
|
||||
private CheckBox mNoPassphraseCheckBox;
|
||||
|
||||
/**
|
||||
* Creates new instance of this dialog fragment
|
||||
@ -60,11 +65,12 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
||||
* @param messenger to communicate back after setting the passphrase
|
||||
* @return
|
||||
*/
|
||||
public static SetPassphraseDialogFragment newInstance(Messenger messenger, int title) {
|
||||
public static SetPassphraseDialogFragment newInstance(Messenger messenger, String oldPassphrase, int title) {
|
||||
SetPassphraseDialogFragment frag = new SetPassphraseDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_TITLE, title);
|
||||
args.putParcelable(ARG_MESSENGER, messenger);
|
||||
args.putString(ARG_OLD_PASSPHRASE, oldPassphrase);
|
||||
|
||||
frag.setArguments(args);
|
||||
|
||||
@ -80,6 +86,7 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
||||
|
||||
int title = getArguments().getInt(ARG_TITLE);
|
||||
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
||||
String oldPassphrase = getArguments().getString(ARG_OLD_PASSPHRASE);
|
||||
|
||||
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);
|
||||
|
||||
@ -92,6 +99,19 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
||||
|
||||
mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase);
|
||||
mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again);
|
||||
mNoPassphraseCheckBox = (CheckBox) view.findViewById(R.id.passphrase_no_passphrase);
|
||||
|
||||
if (TextUtils.isEmpty(oldPassphrase)) {
|
||||
mNoPassphraseCheckBox.setChecked(true);
|
||||
}
|
||||
|
||||
mNoPassphraseCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
mPassphraseEditText.setEnabled(!isChecked);
|
||||
mPassphraseAgainEditText.setEnabled(!isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
|
||||
@ -99,24 +119,31 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dismiss();
|
||||
|
||||
String passphrase1 = mPassphraseEditText.getText().toString();
|
||||
String passphrase2 = mPassphraseAgainEditText.getText().toString();
|
||||
if (!passphrase1.equals(passphrase2)) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
getString(R.string.error_message,
|
||||
getString(R.string.passphrases_do_not_match)), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
String passphrase1;
|
||||
if (mNoPassphraseCheckBox.isChecked()) {
|
||||
passphrase1 = "";
|
||||
} else {
|
||||
passphrase1 = mPassphraseEditText.getText().toString();
|
||||
String passphrase2 = mPassphraseAgainEditText.getText().toString();
|
||||
if (!passphrase1.equals(passphrase2)) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
getString(R.string.error_message,
|
||||
getString(R.string.passphrases_do_not_match)), Toast.LENGTH_SHORT
|
||||
)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (passphrase1.equals("")) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
getString(R.string.error_message,
|
||||
getString(R.string.passphrase_must_not_be_empty)),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
if (passphrase1.equals("")) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
getString(R.string.error_message,
|
||||
getString(R.string.passphrase_must_not_be_empty)),
|
||||
Toast.LENGTH_SHORT
|
||||
).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// return resulting data back to activity
|
||||
|
@ -18,6 +18,89 @@
|
||||
android:paddingLeft="8dp"
|
||||
android:stretchColumns="1">
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_expiry"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"
|
||||
android:text="@string/label_expiry" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/expiry"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:text="@string/none"
|
||||
android:background="@drawable/button_edgy" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/row_certify">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_usage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"
|
||||
android:text="@string/label_usage" />
|
||||
<CheckBox
|
||||
android:id="@+id/chkCertify"
|
||||
android:enabled = "false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/flag_certify" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/row_sign">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_usage2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"
|
||||
android:text="@string/label_usage" />
|
||||
<CheckBox
|
||||
android:id="@+id/chkSign"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/flag_sign" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/row_encrypt">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip" />
|
||||
<CheckBox
|
||||
android:id="@+id/chkEncrypt"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/flag_encrypt" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/row_authenticate">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip" />
|
||||
<CheckBox
|
||||
android:id="@+id/chkAuthenticate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/flag_authenticate" />
|
||||
</TableRow>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -4,11 +4,15 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:stretchColumns="1" >
|
||||
android:stretchColumns="1">
|
||||
|
||||
<TableRow
|
||||
android:layout_marginBottom="5dip"
|
||||
>
|
||||
<CheckBox
|
||||
android:id="@+id/passphrase_no_passphrase"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_no_passphrase" />
|
||||
|
||||
<TableRow android:layout_marginBottom="5dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/passphrase_label_passphrase"
|
||||
@ -26,9 +30,7 @@
|
||||
android:padding="4dp" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_marginBottom="10dip"
|
||||
>
|
||||
<TableRow android:layout_marginBottom="10dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/passphrase_label_passphrase_again"
|
||||
|
Loading…
Reference in New Issue
Block a user