aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-12-31 16:29:55 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2015-12-31 16:29:55 +0100
commit6fb96ce7903623f2e3b1c38c765e8a501dbcc0a1 (patch)
tree324c0452d753164ec3e1b27a003c222f529533e9 /OpenKeychain/src/main/java/org/sufficientlysecure
parentbfa28fcb5e023ac82df2665f7616bd9305daa589 (diff)
downloadopen-keychain-6fb96ce7903623f2e3b1c38c765e8a501dbcc0a1.tar.gz
open-keychain-6fb96ce7903623f2e3b1c38c765e8a501dbcc0a1.tar.bz2
open-keychain-6fb96ce7903623f2e3b1c38c765e8a501dbcc0a1.zip
Add change password menu item to view key
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java105
1 files changed, 94 insertions, 11 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
index 2c0f4afcc..1db273e48 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
@@ -36,6 +36,8 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Message;
+import android.os.Messenger;
import android.provider.ContactsContract;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
@@ -64,6 +66,7 @@ import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
+import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
@@ -75,10 +78,11 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
+import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.ui.ViewKeyFragment.PostponeType;
import org.sufficientlysecure.keychain.ui.base.BaseNfcActivity;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
-import org.sufficientlysecure.keychain.ui.linked.LinkedIdWizard;
+import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
@@ -90,6 +94,7 @@ import org.sufficientlysecure.keychain.ui.util.QrCodeUtils;
import org.sufficientlysecure.keychain.util.ContactHelper;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.NfcHelper;
+import org.sufficientlysecure.keychain.util.Passphrase;
import org.sufficientlysecure.keychain.util.Preferences;
@@ -116,7 +121,9 @@ public class ViewKeyActivity extends BaseNfcActivity implements
// For CryptoOperationHelper.Callback
private String mKeyserver;
private ArrayList<ParcelableKeyRing> mKeyList;
- private CryptoOperationHelper<ImportKeyringParcel, ImportKeyResult> mOperationHelper;
+ private CryptoOperationHelper<ImportKeyringParcel, ImportKeyResult> mImportOpHelper;
+ private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mEditOpHelper;
+ private SaveKeyringParcel mSaveKeyringParcel;
private TextView mStatusText;
private ImageView mStatusImage;
@@ -151,8 +158,10 @@ public class ViewKeyActivity extends BaseNfcActivity implements
private boolean mIsRefreshing;
private Animation mRotate, mRotateSpin;
private View mRefresh;
- private String mFingerprint;
+
private long mMasterKeyId;
+ private byte[] mFingerprint;
+ private String mFingerprintString;
private byte[] mNfcFingerprints;
private String mNfcUserId;
@@ -164,7 +173,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
super.onCreate(savedInstanceState);
mProviderHelper = new ProviderHelper(this);
- mOperationHelper = new CryptoOperationHelper<>(1, this, this, null);
+ mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null);
setTitle(null);
@@ -357,6 +366,10 @@ public class ViewKeyActivity extends BaseNfcActivity implements
startActivity(homeIntent);
return true;
}
+ case R.id.menu_key_change_password: {
+ changePassword();
+ return true;
+ }
case R.id.menu_key_view_backup: {
startPassphraseActivity(REQUEST_BACKUP);
return true;
@@ -395,6 +408,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem backupKey = menu.findItem(R.id.menu_key_view_backup);
backupKey.setVisible(mIsSecret);
+ MenuItem changePassword = menu.findItem(R.id.menu_key_change_password);
+ changePassword.setVisible(mIsSecret);
MenuItem certifyFingerprint = menu.findItem(R.id.menu_key_view_certify_fingerprint);
certifyFingerprint.setVisible(!mIsSecret && !mIsVerified && !mIsExpired && !mIsRevoked);
@@ -405,6 +420,70 @@ public class ViewKeyActivity extends BaseNfcActivity implements
return true;
}
+ private void changePassword() {
+ mSaveKeyringParcel = new SaveKeyringParcel(mMasterKeyId, mFingerprint);
+
+ CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult> editKeyCallback
+ = new CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult>() {
+ @Override
+ public SaveKeyringParcel createOperationInput() {
+ return mSaveKeyringParcel;
+ }
+
+ @Override
+ public void onCryptoOperationSuccess(EditKeyResult result) {
+ displayResult(result);
+ }
+
+ @Override
+ public void onCryptoOperationCancelled() {
+
+ }
+
+ @Override
+ public void onCryptoOperationError(EditKeyResult result) {
+ displayResult(result);
+ }
+
+ @Override
+ public boolean onCryptoSetProgress(String msg, int progress, int max) {
+ return false;
+ }
+ };
+
+ mEditOpHelper = new CryptoOperationHelper<>(2, this, editKeyCallback, R.string.progress_building_key);
+
+ // Message is received after passphrase is cached
+ Handler returnHandler = new Handler() {
+ @Override
+ public void handleMessage(Message message) {
+ if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) {
+ Bundle data = message.getData();
+
+ // use new passphrase!
+ mSaveKeyringParcel.mNewUnlock = new SaveKeyringParcel.ChangeUnlockParcel(
+ (Passphrase) data.getParcelable(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE),
+ null
+ );
+
+ mEditOpHelper.cryptoOperation();
+ }
+ }
+ };
+
+ // Create a new Messenger for the communication back
+ Messenger messenger = new Messenger(returnHandler);
+
+ SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(
+ messenger, R.string.title_change_passphrase);
+
+ setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog");
+ }
+
+ private void displayResult(OperationResult result) {
+ result.createNotify(this).show();
+ }
+
private void scanQrCode() {
Intent scanQrCode = new Intent(this, ImportKeysProxyActivity.class);
scanQrCode.setAction(ImportKeysProxyActivity.ACTION_SCAN_WITH_RESULT);
@@ -496,9 +575,12 @@ public class ViewKeyActivity extends BaseNfcActivity implements
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (mOperationHelper.handleActivityResult(requestCode, resultCode, data)) {
+ if (mImportOpHelper.handleActivityResult(requestCode, resultCode, data)) {
return;
}
+ if (mEditOpHelper != null) {
+ mEditOpHelper.handleActivityResult(requestCode, resultCode, data);
+ }
switch (requestCode) {
case REQUEST_QR_FINGERPRINT: {
@@ -519,7 +601,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
Notify.create(this, R.string.error_scan_fp, Notify.LENGTH_LONG, Style.ERROR).show();
return;
}
- if (mFingerprint.equalsIgnoreCase(fp)) {
+ if (mFingerprintString.equalsIgnoreCase(fp)) {
certifyImmediate();
} else {
Notify.create(this, R.string.error_scan_match, Notify.LENGTH_LONG, Style.ERROR).show();
@@ -584,7 +666,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
byte[] candidateFp = ring.getFingerprint();
// if the master key of that key matches this one, just show the yubikey dialog
- if (KeyFormattingUtils.convertFingerprintToHex(candidateFp).equals(mFingerprint)) {
+ if (KeyFormattingUtils.convertFingerprintToHex(candidateFp).equals(mFingerprintString)) {
showYubiKeyFragment(mNfcFingerprints, mNfcUserId, mNfcAid);
return;
}
@@ -803,7 +885,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
}
mMasterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
- mFingerprint = KeyFormattingUtils.convertFingerprintToHex(data.getBlob(INDEX_FINGERPRINT));
+ mFingerprint = data.getBlob(INDEX_FINGERPRINT);
+ mFingerprintString = KeyFormattingUtils.convertFingerprintToHex(mFingerprint);
// if it wasn't shown yet, display yubikey fragment
if (mShowYubikeyAfterCreation && getIntent().hasExtra(EXTRA_NFC_AID)) {
@@ -880,8 +963,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
mStatusImage.setVisibility(View.GONE);
color = getResources().getColor(R.color.key_flag_green);
// reload qr code only if the fingerprint changed
- if (!mFingerprint.equals(mQrCodeLoaded)) {
- loadQrCode(mFingerprint);
+ if (!mFingerprintString.equals(mQrCodeLoaded)) {
+ loadQrCode(mFingerprintString);
}
photoTask.execute(mMasterKeyId);
mQrCodeLayout.setVisibility(View.VISIBLE);
@@ -1021,7 +1104,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
mKeyserver = Preferences.getPreferences(this).getPreferredKeyserver();
- mOperationHelper.cryptoOperation();
+ mImportOpHelper.cryptoOperation();
}
@Override