mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
give key editing its own pass phrase mechanism, as the new cache won't work there
This commit is contained in:
parent
9855f4d144
commit
c7f0041751
@ -158,6 +158,7 @@ public class Apg {
|
||||
|
||||
private static HashMap<Long, CachedPassPhrase> mPassPhraseCache =
|
||||
new HashMap<Long, CachedPassPhrase>();
|
||||
private static String mEditPassPhrase = null;
|
||||
|
||||
public static class GeneralException extends Exception {
|
||||
static final long serialVersionUID = 0xf812773342L;
|
||||
@ -273,6 +274,14 @@ public class Apg {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setEditPassPhrase(String passPhrase) {
|
||||
mEditPassPhrase = passPhrase;
|
||||
}
|
||||
|
||||
public static String getEditPassPhrase() {
|
||||
return mEditPassPhrase;
|
||||
}
|
||||
|
||||
public static void setCachedPassPhrase(long keyId, String passPhrase) {
|
||||
mPassPhraseCache.put(keyId, new CachedPassPhrase(new Date().getTime(), passPhrase));
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
|
||||
private Button mSaveButton;
|
||||
private Button mDiscardButton;
|
||||
|
||||
private String mCurrentPassPhrase = null;
|
||||
private String mNewPassPhrase = null;
|
||||
|
||||
@Override
|
||||
@ -106,6 +107,11 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
|
||||
mKeys.setKeys(keys);
|
||||
container.addView(mKeys);
|
||||
|
||||
mCurrentPassPhrase = Apg.getEditPassPhrase();
|
||||
if (mCurrentPassPhrase == null) {
|
||||
mCurrentPassPhrase = "";
|
||||
}
|
||||
|
||||
Toast.makeText(this, "Warning: Key editing is still kind of beta.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@ -117,11 +123,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
|
||||
public boolean havePassPhrase() {
|
||||
long keyId = getMasterKeyId();
|
||||
if (keyId == 0) {
|
||||
return false;
|
||||
}
|
||||
return (Apg.getCachedPassPhrase(keyId) != null && !Apg.getCachedPassPhrase(keyId).equals("")) ||
|
||||
return (!mCurrentPassPhrase.equals("")) ||
|
||||
(mNewPassPhrase != null && !mNewPassPhrase.equals(""));
|
||||
}
|
||||
|
||||
@ -235,7 +237,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
|
||||
Message msg = new Message();
|
||||
|
||||
try {
|
||||
String oldPassPhrase = Apg.getCachedPassPhrase(getMasterKeyId());
|
||||
String oldPassPhrase = mCurrentPassPhrase;
|
||||
String newPassPhrase = mNewPassPhrase;
|
||||
if (newPassPhrase == null) {
|
||||
newPassPhrase = oldPassPhrase;
|
||||
|
@ -138,7 +138,7 @@ public class SecretKeyListActivity extends BaseActivity implements OnChildClickL
|
||||
switch (menuItem.getItemId()) {
|
||||
case Id.menu.edit: {
|
||||
mSelectedItem = groupPosition;
|
||||
showDialog(Id.dialog.pass_phrase);
|
||||
checkPassPhraseAndEdit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ public class SecretKeyListActivity extends BaseActivity implements OnChildClickL
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
|
||||
int childPosition, long id) {
|
||||
mSelectedItem = groupPosition;
|
||||
showDialog(Id.dialog.pass_phrase);
|
||||
checkPassPhraseAndEdit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -269,13 +269,27 @@ public class SecretKeyListActivity extends BaseActivity implements OnChildClickL
|
||||
}
|
||||
}
|
||||
|
||||
public void checkPassPhraseAndEdit() {
|
||||
PGPSecretKeyRing keyRing = Apg.getSecretKeyRings().get(mSelectedItem);
|
||||
long keyId = keyRing.getSecretKey().getKeyID();
|
||||
String passPhrase = Apg.getCachedPassPhrase(keyId);
|
||||
if (passPhrase == null) {
|
||||
showDialog(Id.dialog.pass_phrase);
|
||||
} else {
|
||||
Apg.setEditPassPhrase(passPhrase);
|
||||
editKey();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passPhraseCallback(long keyId, String passPhrase) {
|
||||
super.passPhraseCallback(keyId, passPhrase);
|
||||
Apg.setEditPassPhrase(passPhrase);
|
||||
editKey();
|
||||
}
|
||||
|
||||
private void createKey() {
|
||||
Apg.setEditPassPhrase("");
|
||||
Intent intent = new Intent(this, EditKeyActivity.class);
|
||||
startActivityForResult(intent, Id.message.create_key);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user