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(
|
SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(
|
||||||
messenger, title);
|
messenger, null, title);
|
||||||
|
|
||||||
setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog");
|
setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog");
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,8 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
|
|
||||||
private SaveKeyringParcel mSaveKeyringParcel;
|
private SaveKeyringParcel mSaveKeyringParcel;
|
||||||
|
|
||||||
|
private String mCurrentPassphrase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
*/
|
*/
|
||||||
@ -125,6 +127,8 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
cachePassphraseForEdit();
|
||||||
|
|
||||||
// Inflate a "Done"/"Cancel" custom action bar view
|
// Inflate a "Done"/"Cancel" custom action bar view
|
||||||
ActionBarHelper.setTwoButtonView(((ActionBarActivity) getActivity()).getSupportActionBar(),
|
ActionBarHelper.setTwoButtonView(((ActionBarActivity) getActivity()).getSupportActionBar(),
|
||||||
R.string.btn_save, R.drawable.ic_action_save,
|
R.string.btn_save, R.drawable.ic_action_save,
|
||||||
@ -132,7 +136,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// Save
|
// Save
|
||||||
save();
|
save(mCurrentPassphrase);
|
||||||
}
|
}
|
||||||
}, R.string.menu_key_edit_cancel, R.drawable.ic_action_cancel,
|
}, R.string.menu_key_edit_cancel, R.drawable.ic_action_cancel,
|
||||||
new OnClickListener() {
|
new OnClickListener() {
|
||||||
@ -296,7 +300,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
Messenger messenger = new Messenger(returnHandler);
|
Messenger messenger = new Messenger(returnHandler);
|
||||||
|
|
||||||
SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(
|
SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(
|
||||||
messenger, R.string.title_change_passphrase);
|
messenger, mCurrentPassphrase, R.string.title_change_passphrase);
|
||||||
|
|
||||||
setPassphraseDialog.show(getActivity().getSupportFragmentManager(), "setPassphraseDialog");
|
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));
|
mSubkeysAddedAdapter.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.SIGN_DATA, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save() {
|
private void cachePassphraseForEdit() {
|
||||||
String passphrase = PassphraseCacheService.getCachedPassphrase(getActivity(),
|
mCurrentPassphrase = PassphraseCacheService.getCachedPassphrase(getActivity(),
|
||||||
mSaveKeyringParcel.mMasterKeyId);
|
mSaveKeyringParcel.mMasterKeyId);
|
||||||
if (passphrase == null) {
|
if (mCurrentPassphrase == null) {
|
||||||
PassphraseDialogFragment.show(getActivity(), mSaveKeyringParcel.mMasterKeyId,
|
PassphraseDialogFragment.show(getActivity(), mSaveKeyringParcel.mMasterKeyId,
|
||||||
new Handler() {
|
new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
||||||
String passphrase =
|
mCurrentPassphrase =
|
||||||
message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE);
|
message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE);
|
||||||
Log.d(Constants.TAG, "after caching 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());
|
Log.d(Constants.TAG, "add userids to parcel: " + mUserIdsAddedAdapter.getDataAsStringList());
|
||||||
mSaveKeyringParcel.addUserIds = mUserIdsAddedAdapter.getDataAsStringList();
|
mSaveKeyringParcel.addUserIds = mUserIdsAddedAdapter.getDataAsStringList();
|
||||||
|
|
||||||
|
@ -26,12 +26,15 @@ import android.os.Message;
|
|||||||
import android.os.Messenger;
|
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.text.TextUtils;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager.LayoutParams;
|
import android.view.WindowManager.LayoutParams;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.TextView.OnEditorActionListener;
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
@ -44,6 +47,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
public class SetPassphraseDialogFragment extends DialogFragment implements OnEditorActionListener {
|
public class SetPassphraseDialogFragment extends DialogFragment implements OnEditorActionListener {
|
||||||
private static final String ARG_MESSENGER = "messenger";
|
private static final String ARG_MESSENGER = "messenger";
|
||||||
private static final String ARG_TITLE = "title";
|
private static final String ARG_TITLE = "title";
|
||||||
|
private static final String ARG_OLD_PASSPHRASE = "title";
|
||||||
|
|
||||||
public static final int MESSAGE_OKAY = 1;
|
public static final int MESSAGE_OKAY = 1;
|
||||||
|
|
||||||
@ -52,6 +56,7 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
|||||||
private Messenger mMessenger;
|
private Messenger mMessenger;
|
||||||
private EditText mPassphraseEditText;
|
private EditText mPassphraseEditText;
|
||||||
private EditText mPassphraseAgainEditText;
|
private EditText mPassphraseAgainEditText;
|
||||||
|
private CheckBox mNoPassphraseCheckBox;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this dialog fragment
|
* 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
|
* @param messenger to communicate back after setting the passphrase
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static SetPassphraseDialogFragment newInstance(Messenger messenger, int title) {
|
public static SetPassphraseDialogFragment newInstance(Messenger messenger, String oldPassphrase, int title) {
|
||||||
SetPassphraseDialogFragment frag = new SetPassphraseDialogFragment();
|
SetPassphraseDialogFragment frag = new SetPassphraseDialogFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt(ARG_TITLE, title);
|
args.putInt(ARG_TITLE, title);
|
||||||
args.putParcelable(ARG_MESSENGER, messenger);
|
args.putParcelable(ARG_MESSENGER, messenger);
|
||||||
|
args.putString(ARG_OLD_PASSPHRASE, oldPassphrase);
|
||||||
|
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
|
|
||||||
@ -80,6 +86,7 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
|||||||
|
|
||||||
int title = getArguments().getInt(ARG_TITLE);
|
int title = getArguments().getInt(ARG_TITLE);
|
||||||
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
||||||
|
String oldPassphrase = getArguments().getString(ARG_OLD_PASSPHRASE);
|
||||||
|
|
||||||
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);
|
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);
|
||||||
|
|
||||||
@ -92,6 +99,19 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
|||||||
|
|
||||||
mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase);
|
mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase);
|
||||||
mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again);
|
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() {
|
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) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
dismiss();
|
dismiss();
|
||||||
|
|
||||||
String passphrase1 = mPassphraseEditText.getText().toString();
|
String passphrase1;
|
||||||
String passphrase2 = mPassphraseAgainEditText.getText().toString();
|
if (mNoPassphraseCheckBox.isChecked()) {
|
||||||
if (!passphrase1.equals(passphrase2)) {
|
passphrase1 = "";
|
||||||
Toast.makeText(
|
} else {
|
||||||
activity,
|
passphrase1 = mPassphraseEditText.getText().toString();
|
||||||
getString(R.string.error_message,
|
String passphrase2 = mPassphraseAgainEditText.getText().toString();
|
||||||
getString(R.string.passphrases_do_not_match)), Toast.LENGTH_SHORT)
|
if (!passphrase1.equals(passphrase2)) {
|
||||||
.show();
|
Toast.makeText(
|
||||||
return;
|
activity,
|
||||||
}
|
getString(R.string.error_message,
|
||||||
|
getString(R.string.passphrases_do_not_match)), Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (passphrase1.equals("")) {
|
if (passphrase1.equals("")) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity,
|
activity,
|
||||||
getString(R.string.error_message,
|
getString(R.string.error_message,
|
||||||
getString(R.string.passphrase_must_not_be_empty)),
|
getString(R.string.passphrase_must_not_be_empty)),
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT
|
||||||
return;
|
).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return resulting data back to activity
|
// return resulting data back to activity
|
||||||
|
@ -18,6 +18,89 @@
|
|||||||
android:paddingLeft="8dp"
|
android:paddingLeft="8dp"
|
||||||
android:stretchColumns="1">
|
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
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -4,11 +4,15 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="16dp"
|
android:paddingLeft="16dp"
|
||||||
android:paddingRight="16dp"
|
android:paddingRight="16dp"
|
||||||
android:stretchColumns="1" >
|
android:stretchColumns="1">
|
||||||
|
|
||||||
<TableRow
|
<CheckBox
|
||||||
android:layout_marginBottom="5dip"
|
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
|
<TextView
|
||||||
android:id="@+id/passphrase_label_passphrase"
|
android:id="@+id/passphrase_label_passphrase"
|
||||||
@ -26,9 +30,7 @@
|
|||||||
android:padding="4dp" />
|
android:padding="4dp" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
||||||
<TableRow
|
<TableRow android:layout_marginBottom="10dip">
|
||||||
android:layout_marginBottom="10dip"
|
|
||||||
>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/passphrase_label_passphrase_again"
|
android:id="@+id/passphrase_label_passphrase_again"
|
||||||
|
Loading…
Reference in New Issue
Block a user