change edit key for empty private master keys
This commit is contained in:
@@ -75,6 +75,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
|
||||
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
|
||||
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
|
||||
public static final String EXTRA_MASTER_CAN_SIGN = "masterCanSign";
|
||||
|
||||
// results when saving key
|
||||
public static final String RESULT_EXTRA_MASTER_KEY_ID = "masterKeyId";
|
||||
@@ -97,6 +98,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
Vector<String> mUserIds;
|
||||
Vector<PGPSecretKey> mKeys;
|
||||
Vector<Integer> mKeysUsages;
|
||||
boolean masterCanSign = true;
|
||||
|
||||
// will be set to false to build layout later in handler
|
||||
private boolean mBuildLayout = true;
|
||||
@@ -192,6 +194,13 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
});
|
||||
|
||||
//disable key passhphrase changing with empty private keys for no
|
||||
//library fails, fix later
|
||||
if (!masterCanSign) {
|
||||
mChangePassPhrase.setEnabled(false);
|
||||
mNoPassphrase.setEnabled(false);
|
||||
}
|
||||
|
||||
if (mBuildLayout) {
|
||||
buildLayout();
|
||||
}
|
||||
@@ -317,6 +326,9 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
|
||||
if (extras != null) {
|
||||
if (extras.containsKey(EXTRA_MASTER_CAN_SIGN)) {
|
||||
masterCanSign = extras.getBoolean(EXTRA_MASTER_CAN_SIGN);
|
||||
}
|
||||
if (extras.containsKey(EXTRA_MASTER_KEY_ID)) {
|
||||
long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
|
||||
|
||||
@@ -394,10 +406,12 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
LinearLayout container = (LinearLayout) findViewById(R.id.edit_key_container);
|
||||
mUserIdsView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
|
||||
mUserIdsView.setType(Id.type.user_id);
|
||||
mUserIdsView.setCanEdit(masterCanSign);
|
||||
mUserIdsView.setUserIds(mUserIds);
|
||||
container.addView(mUserIdsView);
|
||||
mKeysView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
|
||||
mKeysView.setType(Id.type.key);
|
||||
mKeysView.setCanEdit(masterCanSign);
|
||||
mKeysView.setKeys(mKeys, mKeysUsages);
|
||||
container.addView(mKeysView);
|
||||
|
||||
@@ -447,6 +461,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
data.putIntegerArrayList(KeychainIntentService.SAVE_KEYRING_KEYS_USAGES,
|
||||
getKeysUsages(mKeysView));
|
||||
data.putLong(KeychainIntentService.SAVE_KEYRING_MASTER_KEY_ID, getMasterKeyId());
|
||||
data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign);
|
||||
|
||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||
|
||||
|
||||
@@ -70,18 +70,19 @@ public class KeyListSecretActivity extends KeyListActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkPassPhraseAndEdit(long masterKeyId) {
|
||||
public void checkPassPhraseAndEdit(long masterKeyId, boolean masterCanSign) {
|
||||
String passPhrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId);
|
||||
if (passPhrase == null) {
|
||||
showPassphraseDialog(masterKeyId);
|
||||
showPassphraseDialog(masterKeyId, masterCanSign);
|
||||
} else {
|
||||
PgpMain.setEditPassPhrase(passPhrase);
|
||||
editKey(masterKeyId);
|
||||
editKey(masterKeyId, masterCanSign);
|
||||
}
|
||||
}
|
||||
|
||||
private void showPassphraseDialog(final long masterKeyId) {
|
||||
private void showPassphraseDialog(final long masterKeyId, boolean masterCanSign) {
|
||||
// Message is received after passphrase is cached
|
||||
final boolean mCanSign = masterCanSign;
|
||||
Handler returnHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
@@ -89,7 +90,7 @@ public class KeyListSecretActivity extends KeyListActivity {
|
||||
String passPhrase = PassphraseCacheService.getCachedPassphrase(
|
||||
KeyListSecretActivity.this, masterKeyId);
|
||||
PgpMain.setEditPassPhrase(passPhrase);
|
||||
editKey(masterKeyId);
|
||||
editKey(masterKeyId, mCanSign);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -115,9 +116,10 @@ public class KeyListSecretActivity extends KeyListActivity {
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
|
||||
private void editKey(long masterKeyId) {
|
||||
private void editKey(long masterKeyId, boolean masterCanSign) {
|
||||
Intent intent = new Intent(EditKeyActivity.ACTION_EDIT_KEY);
|
||||
intent.putExtra(EditKeyActivity.EXTRA_MASTER_KEY_ID, masterKeyId);
|
||||
intent.putExtra(EditKeyActivity.EXTRA_MASTER_CAN_SIGN, masterCanSign);
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,9 +91,11 @@ public class KeyListSecretFragment extends KeyListFragment implements
|
||||
long masterKeyId = ProviderHelper
|
||||
.getSecretMasterKeyId(mKeyListSecretActivity, keyRingRowId);
|
||||
|
||||
boolean masterCanSign = ProviderHelper.getSecretMasterKeyCanSign(mKeyListSecretActivity, keyRingRowId);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case Id.menu.edit:
|
||||
mKeyListSecretActivity.checkPassPhraseAndEdit(masterKeyId);
|
||||
mKeyListSecretActivity.checkPassPhraseAndEdit(masterKeyId, masterCanSign);
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
@@ -125,6 +125,14 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
super.onFinishInflate();
|
||||
}
|
||||
|
||||
public void setCanEdit(boolean bCanEdit) {
|
||||
if (!bCanEdit) {
|
||||
mDeleteButton.setVisibility(View.INVISIBLE);
|
||||
mUsage.setEnabled(false);
|
||||
mExpiryDateButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setValue(PGPSecretKey key, boolean isMasterKey, int usage) {
|
||||
mKey = key;
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
@@ -55,12 +56,14 @@ import java.util.Vector;
|
||||
public class SectionView extends LinearLayout implements OnClickListener, EditorListener {
|
||||
private LayoutInflater mInflater;
|
||||
private View mAdd;
|
||||
private ImageView mPlusButton;
|
||||
private ViewGroup mEditors;
|
||||
private TextView mTitle;
|
||||
private int mType = 0;
|
||||
|
||||
private Choice mNewKeyAlgorithmChoice;
|
||||
private int mNewKeySize;
|
||||
private boolean canEdit = true;
|
||||
|
||||
private SherlockFragmentActivity mActivity;
|
||||
|
||||
@@ -99,6 +102,14 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
}
|
||||
}
|
||||
|
||||
public void setCanEdit(boolean bCanEdit) {
|
||||
canEdit = bCanEdit;
|
||||
mPlusButton = (ImageView)findViewById(R.id.plusbutton);
|
||||
if (!canEdit) {
|
||||
mPlusButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
@@ -129,6 +140,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void onClick(View v) {
|
||||
if (canEdit) {
|
||||
switch (mType) {
|
||||
case Id.type.user_id: {
|
||||
UserIdEditor view = (UserIdEditor) mInflater.inflate(R.layout.edit_key_user_id_item,
|
||||
@@ -205,6 +217,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
}
|
||||
}
|
||||
this.updateEditorsVisible();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUserIds(Vector<String> list) {
|
||||
@@ -221,6 +234,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
if (mEditors.getChildCount() == 0) {
|
||||
view.setIsMainUserId(true);
|
||||
}
|
||||
view.setCanEdit(canEdit);
|
||||
mEditors.addView(view);
|
||||
}
|
||||
|
||||
@@ -241,6 +255,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
view.setEditorListener(this);
|
||||
boolean isMasterKey = (mEditors.getChildCount() == 0);
|
||||
view.setValue(list.get(i), isMasterKey, usages.get(i));
|
||||
view.setCanEdit(canEdit);
|
||||
mEditors.addView(view);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,16 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
public void setCanEdit(boolean bCanEdit) {
|
||||
if (!bCanEdit) {
|
||||
mDeleteButton.setVisibility(View.INVISIBLE);
|
||||
mName.setEnabled(false);
|
||||
mIsMainUserId.setEnabled(false);
|
||||
mEmail.setEnabled(false);
|
||||
mComment.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static class NoEmailException extends Exception {
|
||||
static final long serialVersionUID = 0xf812773344L;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user