From 212ee222c3cf66adda0842176a17f9302549f51b Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sun, 2 Feb 2014 22:14:07 +0000 Subject: replace spinner with non-functioning checkboxes --- .../keychain/ui/widget/KeyEditor.java | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 6c265057e..16e868a2c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -89,18 +89,18 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mKeyId = (TextView) findViewById(R.id.keyId); mCreationDate = (TextView) findViewById(R.id.creation); mExpiryDateButton = (BootstrapButton) findViewById(R.id.expiry); - mUsage = (Spinner) findViewById(R.id.usage); - Choice choices[] = { - new Choice(Id.choice.usage.sign_only, getResources().getString( - R.string.choice_sign_only)), - new Choice(Id.choice.usage.encrypt_only, getResources().getString( - R.string.choice_encrypt_only)), - new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( - R.string.choice_sign_and_encrypt)), }; - ArrayAdapter adapter = new ArrayAdapter(getContext(), - android.R.layout.simple_spinner_item, choices); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mUsage.setAdapter(adapter); + //mUsage = (Spinner) findViewById(R.id.usage); + //Choice choices[] = { + // new Choice(Id.choice.usage.sign_only, getResources().getString( + // R.string.choice_sign_only)), + // new Choice(Id.choice.usage.encrypt_only, getResources().getString( + // R.string.choice_encrypt_only)), + // new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( + // R.string.choice_sign_and_encrypt)), }; + //ArrayAdapter adapter = new ArrayAdapter(getContext(), + // android.R.layout.simple_spinner_item, choices); + //adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + //mUsage.setAdapter(adapter); mDeleteButton = (BootstrapButton) findViewById(R.id.delete); mDeleteButton.setOnClickListener(this); @@ -139,7 +139,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { public void setCanEdit(boolean bCanEdit) { if (!bCanEdit) { mDeleteButton.setVisibility(View.INVISIBLE); - mUsage.setEnabled(false); + //mUsage.setEnabled(false); mExpiryDateButton.setEnabled(false); } } @@ -161,22 +161,22 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT); boolean isDSAKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.DSA); if (!isElGamalKey) { - choices.add(new Choice(Id.choice.usage.sign_only, getResources().getString( - R.string.choice_sign_only))); + //choices.add(new Choice(Id.choice.usage.sign_only, getResources().getString( + // R.string.choice_sign_only))); } if (!mIsMasterKey && !isDSAKey) { - choices.add(new Choice(Id.choice.usage.encrypt_only, getResources().getString( - R.string.choice_encrypt_only))); + //choices.add(new Choice(Id.choice.usage.encrypt_only, getResources().getString( + // R.string.choice_encrypt_only))); } if (!isElGamalKey && !isDSAKey) { - choices.add(new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( - R.string.choice_sign_and_encrypt))); + //choices.add(new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( + // R.string.choice_sign_and_encrypt))); } ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, choices); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mUsage.setAdapter(adapter); + //mUsage.setAdapter(adapter); // Set value in choice dropdown to key int selectId = 0; @@ -198,7 +198,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { for (int i = 0; i < choices.size(); ++i) { if (choices.get(i).getId() == selectId) { - mUsage.setSelection(i); + //mUsage.setSelection(i); break; } } @@ -249,7 +249,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } public int getUsage() { - return ((Choice) mUsage.getSelectedItem()).getId(); + return 1; //((Choice) mUsage.getSelectedItem()).getId(); } } -- cgit v1.2.3 From a90b748611126cd122e39ef944f4c268798419f0 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sun, 2 Feb 2014 23:56:53 +0000 Subject: set checkboxes from key properties --- .../keychain/ui/widget/KeyEditor.java | 74 +++++++++++----------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 16e868a2c..f845b53a7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -39,9 +39,12 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.CheckBox; import android.widget.DatePicker; import android.widget.LinearLayout; import android.widget.Spinner; +import android.widget.TableLayout; +import android.widget.TableRow; import android.widget.TextView; import com.beardedhen.androidbootstrap.BootstrapButton; @@ -59,6 +62,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { TextView mCreationDate; BootstrapButton mExpiryDateButton; GregorianCalendar mExpiryDate; + CheckBox mChkCertify; + CheckBox mChkSign; + CheckBox mChkEncrypt; + CheckBox mChkAuthenticate; private int mDatePickerResultCount = 0; private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() { @@ -89,21 +96,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mKeyId = (TextView) findViewById(R.id.keyId); mCreationDate = (TextView) findViewById(R.id.creation); mExpiryDateButton = (BootstrapButton) findViewById(R.id.expiry); - //mUsage = (Spinner) findViewById(R.id.usage); - //Choice choices[] = { - // new Choice(Id.choice.usage.sign_only, getResources().getString( - // R.string.choice_sign_only)), - // new Choice(Id.choice.usage.encrypt_only, getResources().getString( - // R.string.choice_encrypt_only)), - // new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( - // R.string.choice_sign_and_encrypt)), }; - //ArrayAdapter adapter = new ArrayAdapter(getContext(), - // android.R.layout.simple_spinner_item, choices); - //adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - //mUsage.setAdapter(adapter); mDeleteButton = (BootstrapButton) findViewById(R.id.delete); mDeleteButton.setOnClickListener(this); + mChkCertify = (CheckBox) findViewById(R.id.chkCertify); + mChkSign = (CheckBox) findViewById(R.id.chkSign); + mChkEncrypt = (CheckBox) findViewById(R.id.chkEncrypt); + mChkAuthenticate = (CheckBox) findViewById(R.id.chkAuthenticate); setExpiryDate(null); @@ -139,8 +138,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { public void setCanEdit(boolean bCanEdit) { if (!bCanEdit) { mDeleteButton.setVisibility(View.INVISIBLE); - //mUsage.setEnabled(false); mExpiryDateButton.setEnabled(false); + mChkSign.setEnabled(false); //certify is always disabled + mChkEncrypt.setEnabled(false); + mChkAuthenticate.setEnabled(false); } } @@ -160,17 +161,26 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { Vector choices = new Vector(); boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT); boolean isDSAKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.DSA); - if (!isElGamalKey) { - //choices.add(new Choice(Id.choice.usage.sign_only, getResources().getString( - // R.string.choice_sign_only))); + if (isElGamalKey) { + mChkSign.setVisibility(View.INVISIBLE); + TableLayout table = (TableLayout)findViewById(R.id.table_keylayout); + TableRow row = (TableRow)findViewById(R.id.row_sign); + table.removeView(row); } - if (!mIsMasterKey && !isDSAKey) { - //choices.add(new Choice(Id.choice.usage.encrypt_only, getResources().getString( - // R.string.choice_encrypt_only))); + if (isDSAKey) { + mChkEncrypt.setVisibility(View.INVISIBLE); + TableLayout table = (TableLayout)findViewById(R.id.table_keylayout); + TableRow row = (TableRow)findViewById(R.id.row_encrypt); + table.removeView(row); } - if (!isElGamalKey && !isDSAKey) { - //choices.add(new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( - // R.string.choice_sign_and_encrypt))); + if (!mIsMasterKey) { + mChkCertify.setVisibility(View.INVISIBLE); + TableLayout table = (TableLayout)findViewById(R.id.table_keylayout); + TableRow row = (TableRow)findViewById(R.id.row_certify); + table.removeView(row); + } else { + TextView mLabelUsage2= (TextView) findViewById(R.id.label_usage2); + mLabelUsage2.setVisibility(View.INVISIBLE); } ArrayAdapter adapter = new ArrayAdapter(getContext(), @@ -180,21 +190,11 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { // Set value in choice dropdown to key int selectId = 0; - if (PgpKeyHelper.isEncryptionKey(key)) { - if (PgpKeyHelper.isSigningKey(key)) { - selectId = Id.choice.usage.sign_and_encrypt; - } else { - selectId = Id.choice.usage.encrypt_only; - } - } else { - // set usage if it is predefined - if (usage != -1) { - selectId = usage; - } else { - selectId = Id.choice.usage.sign_only; - } - - } + if (key.isMasterKey()) + mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key)); + mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); + mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); + // TODO: use usage argument? for (int i = 0; i < choices.size(); ++i) { if (choices.get(i).getId() == selectId) { -- cgit v1.2.3 From fd308a671d571b3d8c58d294cda8f6add5832054 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Mon, 3 Feb 2014 00:05:45 +0000 Subject: include authentication keys --- .../keychain/pgp/PgpKeyHelper.java | 30 ++++++++++++++++++++++ .../keychain/ui/widget/KeyEditor.java | 1 + 2 files changed, 31 insertions(+) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java index 3fc63cda1..bef41ce64 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java @@ -397,6 +397,36 @@ public class PgpKeyHelper { return false; } + public static boolean isAuthenticationKey(PGPSecretKey key) { + return isAuthenticationKey(key.getPublicKey()); + } + + @SuppressWarnings("unchecked") + public static boolean isAuthenticationKey(PGPPublicKey key) { + if (key.getVersion() <= 3) { + return true; + } + + for (PGPSignature sig : new IterableIterator(key.getSignatures())) { + if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) { + continue; + } + PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets(); + + if (hashed != null && (hashed.getKeyFlags() & KeyFlags.AUTHENTICATION) != 0) { + return true; + } + + PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets(); + + if (unhashed != null && (unhashed.getKeyFlags() & KeyFlags.AUTHENTICATION) != 0) { + return true; + } + } + + return false; + } + public static boolean isCertificationKey(PGPSecretKey key) { return isCertificationKey(key.getPublicKey()); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index f845b53a7..b05963385 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -194,6 +194,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key)); mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); + mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); // TODO: use usage argument? for (int i = 0; i < choices.size(); ++i) { -- cgit v1.2.3 From 089a70fe323ee0628b05709f2f831d6aa32e0281 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Mon, 3 Feb 2014 01:15:29 +0000 Subject: save flags from checkboxes --- .../keychain/pgp/PgpKeyOperation.java | 22 +++++------------- .../keychain/ui/widget/KeyEditor.java | 26 ++++++++++------------ 2 files changed, 18 insertions(+), 30 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 9782d1ac2..d2793a859 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -237,8 +237,8 @@ public class PgpKeyOperation { updateProgress(R.string.progress_preparing_master_key, 10, 100); int usageId = keysUsages.get(0); - boolean canSign = (usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt); - boolean canEncrypt = (usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt); + boolean canSign = (usageId & KeyFlags.SIGN_DATA) > 0; + boolean canEncrypt = (usageId & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) > 0; String mainUserId = userIds.get(0); @@ -287,11 +287,7 @@ public class PgpKeyOperation { PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator(); PGPSignatureSubpacketGenerator unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); - int keyFlags = KeyFlags.CERTIFY_OTHER | KeyFlags.SIGN_DATA; - if (canEncrypt) { - keyFlags |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE; - } - hashedPacketsGen.setKeyFlags(true, keyFlags); + hashedPacketsGen.setKeyFlags(true, usageId); hashedPacketsGen.setPreferredSymmetricAlgorithms(true, PREFERRED_SYMMETRIC_ALGORITHMS); hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS); @@ -349,14 +345,11 @@ public class PgpKeyOperation { hashedPacketsGen = new PGPSignatureSubpacketGenerator(); unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); - keyFlags = 0; - usageId = keysUsages.get(i); - canSign = (usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt); - canEncrypt = (usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt); + canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this + canEncrypt = (usageId & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) > 0; if (canSign) { Date todayDate = new Date(); //both sig times the same - keyFlags |= KeyFlags.SIGN_DATA; // cross-certify signing keys hashedPacketsGen.setSignatureCreationTime(false, todayDate); //set outer creation time PGPSignatureSubpacketGenerator subHashedPacketsGen = new PGPSignatureSubpacketGenerator(); @@ -371,10 +364,7 @@ public class PgpKeyOperation { subPublicKey); unhashedPacketsGen.setEmbeddedSignature(false, certification); } - if (canEncrypt) { - keyFlags |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE; - } - hashedPacketsGen.setKeyFlags(false, keyFlags); + hashedPacketsGen.setKeyFlags(false, usageId); if (keysExpiryDates.get(i) != null) { GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index b05963385..2bedafc9f 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -23,6 +23,7 @@ import java.util.GregorianCalendar; import java.util.TimeZone; import java.util.Vector; +import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPSecretKey; import org.sufficientlysecure.keychain.Id; @@ -183,12 +184,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mLabelUsage2.setVisibility(View.INVISIBLE); } - ArrayAdapter adapter = new ArrayAdapter(getContext(), - android.R.layout.simple_spinner_item, choices); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - //mUsage.setAdapter(adapter); - - // Set value in choice dropdown to key int selectId = 0; if (key.isMasterKey()) mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key)); @@ -197,13 +192,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); // TODO: use usage argument? - for (int i = 0; i < choices.size(); ++i) { - if (choices.get(i).getId() == selectId) { - //mUsage.setSelection(i); - break; - } - } - GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.setTime(PgpKeyHelper.getCreationDate(key)); mCreationDate.setText(DateFormat.getDateInstance().format(cal.getTime())); @@ -250,7 +238,17 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } public int getUsage() { - return 1; //((Choice) mUsage.getSelectedItem()).getId(); + int result = 0; // TODO: preserve other flags + if (mChkCertify.isChecked()) + result |= KeyFlags.CERTIFY_OTHER; + if (mChkSign.isChecked()) //TODO: fix what happens when we remove sign flag from master - should still be able to certify + result |= KeyFlags.SIGN_DATA; + if (mChkEncrypt.isChecked()) + result |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE; + if (mChkAuthenticate.isChecked()) + result |= KeyFlags.AUTHENTICATION; + + return result; } } -- cgit v1.2.3 From 82b94838c3132064c8011a041466fea04a602b19 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 4 Feb 2014 00:38:19 +0000 Subject: fix certify keys without sign flag --- .../sufficientlysecure/keychain/provider/ProviderHelper.java | 12 +++++------- .../org/sufficientlysecure/keychain/ui/EditKeyActivity.java | 2 +- .../org/sufficientlysecure/keychain/ui/widget/KeyEditor.java | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index a4992163a..12bc33995 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -23,8 +23,6 @@ import java.util.ArrayList; import java.util.Date; import org.spongycastle.bcpg.ArmoredOutputStream; -import org.spongycastle.bcpg.UserAttributePacket; -import org.spongycastle.bcpg.UserAttributeSubpacket; import org.spongycastle.openpgp.PGPKeyRing; import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPPublicKeyRing; @@ -348,7 +346,7 @@ public class ProviderHelper { values.put(Keys.KEY_SIZE, key.getPublicKey().getBitStrength()); values.put(Keys.CAN_CERTIFY, (PgpKeyHelper.isCertificationKey(key) && has_private)); values.put(Keys.CAN_SIGN, (PgpKeyHelper.isSigningKey(key) && has_private)); - values.put(Keys.CAN_ENCRYPT, PgpKeyHelper.isEncryptionKey(key)); + values.put(Keys.CAN_ENCRYPT, PgpKeyHelper.isEncryptionKey(key) && has_private); values.put(Keys.IS_REVOKED, key.getPublicKey().isRevoked()); values.put(Keys.CREATION, PgpKeyHelper.getCreationDate(key).getTime() / 1000); Date expiryDate = PgpKeyHelper.getExpiryDate(key); @@ -441,21 +439,21 @@ public class ProviderHelper { /** * Get empty status of master key of keyring by its row id */ - public static boolean getSecretMasterKeyCanSign(Context context, long keyRingRowId) { + public static boolean getSecretMasterKeyCanCertify(Context context, long keyRingRowId) { Uri queryUri = KeyRings.buildSecretKeyRingsUri(String.valueOf(keyRingRowId)); - return getMasterKeyCanSign(context, queryUri, keyRingRowId); + return getMasterKeyCanCertify(context, queryUri, keyRingRowId); } /** * Private helper method to get master key private empty status of keyring by its row id */ - private static boolean getMasterKeyCanSign(Context context, Uri queryUri, long keyRingRowId) { + private static boolean getMasterKeyCanCertify(Context context, Uri queryUri, long keyRingRowId) { String[] projection = new String[]{ KeyRings.MASTER_KEY_ID, "(SELECT COUNT(sign_keys." + Keys._ID + ") FROM " + Tables.KEYS + " AS sign_keys WHERE sign_keys." + Keys.KEY_RING_ROW_ID + " = " + KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings._ID - + " AND sign_keys." + Keys.CAN_SIGN + " = '1' AND " + Keys.IS_MASTER_KEY + + " AND sign_keys." + Keys.CAN_CERTIFY + " = '1' AND " + Keys.IS_MASTER_KEY + " = 1) AS sign",}; ContentResolver cr = context.getContentResolver(); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 73426e32d..2c49d4921 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -256,7 +256,7 @@ public class EditKeyActivity extends ActionBarActivity { // get master key id using row id long masterKeyId = ProviderHelper.getSecretMasterKeyId(this, keyRingRowId); - masterCanSign = ProviderHelper.getSecretMasterKeyCanSign(this, keyRingRowId); + masterCanSign = ProviderHelper.getSecretMasterKeyCanCertify(this, keyRingRowId); finallyEdit(masterKeyId, masterCanSign); } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 2bedafc9f..2ea044e66 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -59,7 +59,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { BootstrapButton mDeleteButton; TextView mAlgorithm; TextView mKeyId; - Spinner mUsage; TextView mCreationDate; BootstrapButton mExpiryDateButton; GregorianCalendar mExpiryDate; -- cgit v1.2.3 From fe3db8f0e68b7490bf98e356474a631dec32530c Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 4 Feb 2014 01:18:54 +0000 Subject: preserve keys that we don\'t use in the app --- .../keychain/pgp/PgpKeyHelper.java | 27 +++++++++++++++++++--- .../keychain/ui/widget/KeyEditor.java | 20 ++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java index bef41ce64..78d42cbf9 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java @@ -209,9 +209,8 @@ public class PgpKeyHelper { Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(creationDate); calendar.add(Calendar.DATE, key.getValidDays()); - Date expiryDate = calendar.getTime(); - return expiryDate; + return calendar.getTime(); } public static Date getExpiryDate(PGPSecretKey key) { @@ -291,6 +290,28 @@ public class PgpKeyHelper { return userId; } + public static int getKeyUsage(PGPSecretKey key) + { + return getKeyUsage(key.getPublicKey()); + } + + @SuppressWarnings("unchecked") + private static int getKeyUsage(PGPPublicKey key) { + int usage = 0; + if (key.getVersion() >= 4) { + for (PGPSignature sig : new IterableIterator(key.getSignatures())) { + if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) continue; + + PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets(); + if (hashed != null) usage |= hashed.getKeyFlags(); + + PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets(); + if (unhashed != null) usage |= unhashed.getKeyFlags(); + } + } + return usage; + } + @SuppressWarnings("unchecked") public static boolean isEncryptionKey(PGPPublicKey key) { if (!key.isEncryptionKey()) { @@ -440,7 +461,7 @@ public class PgpKeyHelper { } public static String getAlgorithmInfo(int algorithm, int keySize) { - String algorithmStr = null; + String algorithmStr; switch (algorithm) { case PGPPublicKey.RSA_ENCRYPT: diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 2ea044e66..8443895e8 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -66,6 +66,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { CheckBox mChkSign; CheckBox mChkEncrypt; CheckBox mChkAuthenticate; + int mUsage; private int mDatePickerResultCount = 0; private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() { @@ -189,6 +190,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); + mUsage = PgpKeyHelper.getKeyUsage(key); // TODO: use usage argument? GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); @@ -237,17 +239,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } public int getUsage() { - int result = 0; // TODO: preserve other flags - if (mChkCertify.isChecked()) - result |= KeyFlags.CERTIFY_OTHER; - if (mChkSign.isChecked()) //TODO: fix what happens when we remove sign flag from master - should still be able to certify - result |= KeyFlags.SIGN_DATA; - if (mChkEncrypt.isChecked()) - result |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE; - if (mChkAuthenticate.isChecked()) - result |= KeyFlags.AUTHENTICATION; - - return result; + mUsage = (mUsage & ~KeyFlags.CERTIFY_OTHER) | (mChkCertify.isChecked() ? KeyFlags.CERTIFY_OTHER : 0); + mUsage = (mUsage & ~KeyFlags.SIGN_DATA) | (mChkSign.isChecked() ? KeyFlags.SIGN_DATA : 0); + mUsage = (mUsage & ~KeyFlags.ENCRYPT_COMMS) | (mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_COMMS : 0); + mUsage = (mUsage & ~KeyFlags.ENCRYPT_STORAGE) | (mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_STORAGE : 0); + mUsage = (mUsage & ~KeyFlags.AUTHENTICATION) | (mChkAuthenticate.isChecked() ? KeyFlags.AUTHENTICATION : 0); + + return mUsage; } } -- cgit v1.2.3 From 6d40bc3c0c5e14b77f7de734e57e351eacd6e98c Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 4 Feb 2014 22:02:53 +0000 Subject: use usage argument if needed --- .../java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java | 8 +++++--- .../org/sufficientlysecure/keychain/ui/widget/SectionView.java | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 8443895e8..2e56c65bc 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -146,7 +146,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } } - public void setValue(PGPSecretKey key, boolean isMasterKey, int usage) { + public void setValue(PGPSecretKey key, boolean isMasterKey, int usage, boolean isNewKey) { mKey = key; mIsMasterKey = isMasterKey; @@ -190,8 +190,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); - mUsage = PgpKeyHelper.getKeyUsage(key); - // TODO: use usage argument? + if (isNewKey) + mUsage = usage; + else + mUsage = PgpKeyHelper.getKeyUsage(key); GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.setTime(PgpKeyHelper.getCreationDate(key)); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 9d3643914..df69ff60b 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -272,7 +272,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor false); view.setEditorListener(this); boolean isMasterKey = (mEditors.getChildCount() == 0); - view.setValue(list.get(i), isMasterKey, usages.get(i)); + view.setValue(list.get(i), isMasterKey, usages.get(i), false); view.setCanEdit(canEdit); mEditors.addView(view); } @@ -344,7 +344,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item, mEditors, false); view.setEditorListener(SectionView.this); - view.setValue(newKey, newKey.isMasterKey(), -1); + view.setValue(newKey, newKey.isMasterKey(), -1, true); mEditors.addView(view); SectionView.this.updateEditorsVisible(); } -- cgit v1.2.3 From 8d7cc6755349d06dcd9a2c28dc556c7adb71b8a4 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Wed, 5 Feb 2014 21:04:20 +0000 Subject: save --- .../keychain/ui/EditKeyActivity.java | 13 +++++++- .../keychain/ui/PreferencesKeyServerActivity.java | 7 +++- .../keychain/ui/widget/Editor.java | 4 ++- .../keychain/ui/widget/KeyEditor.java | 37 +++++++++++++++++++--- .../keychain/ui/widget/KeyServerEditor.java | 2 +- .../keychain/ui/widget/SectionView.java | 29 +++++++++++++++-- .../keychain/ui/widget/UserIdEditor.java | 7 +++- 7 files changed, 87 insertions(+), 12 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 2c49d4921..b28ed8922 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -38,9 +38,11 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment; +import org.sufficientlysecure.keychain.ui.widget.Editor; import org.sufficientlysecure.keychain.ui.widget.KeyEditor; import org.sufficientlysecure.keychain.ui.widget.SectionView; import org.sufficientlysecure.keychain.ui.widget.UserIdEditor; +import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; @@ -67,7 +69,7 @@ import android.widget.Toast; import com.beardedhen.androidbootstrap.BootstrapButton; -public class EditKeyActivity extends ActionBarActivity { +public class EditKeyActivity extends ActionBarActivity implements EditorListener { // Actions for internal use only: public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY"; @@ -106,6 +108,15 @@ public class EditKeyActivity extends ActionBarActivity { ExportHelper mExportHelper; + public void onDeleted(Editor e, boolean wasNewItem) + { + } + + public void onEdited() + { + + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java index b5ac739ae..b39b93f52 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java @@ -91,10 +91,15 @@ public class PreferencesKeyServerActivity extends ActionBarActivity implements O } } - public void onDeleted(Editor editor) { + public void onDeleted(Editor editor, boolean wasNewItem) { // nothing to do } + @Override + public void onEdited() { + + } + public void onClick(View v) { KeyServerEditor view = (KeyServerEditor) mInflater.inflate(R.layout.key_server_editor, mEditors, false); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/Editor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/Editor.java index 1cf510d3a..7b21c189d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/Editor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/Editor.java @@ -18,8 +18,10 @@ package org.sufficientlysecure.keychain.ui.widget; public interface Editor { public interface EditorListener { - public void onDeleted(Editor editor); + public void onDeleted(Editor editor, boolean wasNewItem); + public void onEdited(); } public void setEditorListener(EditorListener listener); + public boolean needsSaving(); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 2e56c65bc..c941ea908 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -26,7 +26,6 @@ import java.util.Vector; import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPSecretKey; -import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.util.Choice; @@ -39,11 +38,9 @@ import android.util.AttributeSet; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.DatePicker; import android.widget.LinearLayout; -import android.widget.Spinner; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; @@ -62,11 +59,14 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { TextView mCreationDate; BootstrapButton mExpiryDateButton; GregorianCalendar mExpiryDate; + GregorianCalendar mOriginalExpiryDate = null; CheckBox mChkCertify; CheckBox mChkSign; CheckBox mChkEncrypt; CheckBox mChkAuthenticate; int mUsage; + int mOriginalUsage; + boolean mIsNewKey; private int mDatePickerResultCount = 0; private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() { @@ -190,10 +190,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); + mIsNewKey = isNewKey; if (isNewKey) mUsage = usage; - else + else { mUsage = PgpKeyHelper.getKeyUsage(key); + mOriginalUsage = mUsage; + } GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.setTime(PgpKeyHelper.getCreationDate(key)); @@ -205,6 +208,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } else { cal.setTime(PgpKeyHelper.getExpiryDate(key)); setExpiryDate(cal); + mOriginalExpiryDate = cal; // TODO: ensure time doesn't matter when selecting the same date as before } } @@ -218,7 +222,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { if (v == mDeleteButton) { parent.removeView(this); if (mEditorListener != null) { - mEditorListener.onDeleted(this); + mEditorListener.onDeleted(this, mIsNewKey); } } } @@ -250,4 +254,27 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { return mUsage; } + public boolean needsSaving() + { + if (mIsNewKey) + return true; + + boolean retval = (getUsage() != mOriginalUsage); + + boolean dateChanged; + boolean mOEDNull = (mOriginalExpiryDate == null); + boolean mEDNull = (mExpiryDate == null); + if (mOEDNull != mEDNull) { + dateChanged = true; + } else { + if(mOEDNull) //both null, no change + dateChanged = false; + else + dateChanged = ((mExpiryDate.compareTo(mOriginalExpiryDate)) != 0); + } + retval |= dateChanged; + + return retval; + } + } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyServerEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyServerEditor.java index 01259ccd1..a75aafc11 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyServerEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyServerEditor.java @@ -68,7 +68,7 @@ public class KeyServerEditor extends LinearLayout implements Editor, OnClickList if (v == mDeleteButton) { parent.removeView(this); if (mEditorListener != null) { - mEditorListener.onDeleted(this); + mEditorListener.onDeleted(this, false); } } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index df69ff60b..19926abd3 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -50,21 +50,27 @@ import android.widget.TextView; import com.beardedhen.androidbootstrap.BootstrapButton; -public class SectionView extends LinearLayout implements OnClickListener, EditorListener { +public class SectionView extends LinearLayout implements OnClickListener, EditorListener, Editor { private LayoutInflater mInflater; private BootstrapButton mPlusButton; private ViewGroup mEditors; private TextView mTitle; private int mType = 0; + private EditorListener mEditorListener = null; private Choice mNewKeyAlgorithmChoice; private int mNewKeySize; private boolean canEdit = true; + private boolean oldItemDeleted = false; private ActionBarActivity mActivity; private ProgressDialogFragment mGeneratingDialog; + public void setEditorListener(EditorListener listener) { + mEditorListener = listener; + } + public SectionView(Context context) { super(context); mActivity = (ActionBarActivity) context; @@ -124,15 +130,34 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor } /** {@inheritDoc} */ - public void onDeleted(Editor editor) { + public void onDeleted(Editor editor, boolean wasNewItem) { + oldItemDeleted |= !wasNewItem; this.updateEditorsVisible(); } + @Override + public void onEdited() { + if (mEditorListener != null) { + mEditorListener.onEdited(); + } + } + protected void updateEditorsVisible() { final boolean hasChildren = mEditors.getChildCount() > 0; mEditors.setVisibility(hasChildren ? View.VISIBLE : View.GONE); } + public boolean needsSaving() + { + //check each view for needs saving, take account of deleted items + boolean ret = oldItemDeleted; + for (int i = 0; i < mEditors.getChildCount(); ++i) { + Editor editor = (Editor) mEditors.getChildAt(i); + ret |= editor.needsSaving(); + } + return ret; + } + /** {@inheritDoc} */ public void onClick(View v) { if (canEdit) { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index 5428b626e..a56340582 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -175,7 +175,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene boolean wasMainUserId = mIsMainUserId.isChecked(); parent.removeView(this); if (mEditorListener != null) { - mEditorListener.onDeleted(this); + mEditorListener.onDeleted(this, false); } if (wasMainUserId && parent.getChildCount() > 0) { UserIdEditor editor = (UserIdEditor) parent.getChildAt(0); @@ -204,4 +204,9 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene public void setEditorListener(EditorListener listener) { mEditorListener = listener; } + + @Override + public boolean needsSaving() { + return false; + } } -- cgit v1.2.3 From 262425c6ad7cfa6509dc53150e592b3f6fd366c1 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Wed, 5 Feb 2014 21:36:11 +0000 Subject: edit ui knows it it has been changed --- .../keychain/ui/widget/SectionView.java | 5 +---- .../keychain/ui/widget/UserIdEditor.java | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 19926abd3..bf8a3f96b 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -273,10 +273,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor UserIdEditor view = (UserIdEditor) mInflater.inflate(R.layout.edit_key_user_id_item, mEditors, false); view.setEditorListener(this); - view.setValue(userId); - if (mEditors.getChildCount() == 0) { - view.setIsMainUserId(true); - } + view.setValue(userId, mEditors.getChildCount() == 0); view.setCanEdit(canEdit); mEditors.addView(view); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index a56340582..4cd1392c2 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -38,8 +38,12 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene private BootstrapButton mDeleteButton; private RadioButton mIsMainUserId; private EditText mName; + private String mOriginalName; private EditText mEmail; + private String mOriginalEmail; private EditText mComment; + private String mOriginalComment; + private boolean mOriginallyMainUserID; // see http://www.regular-expressions.info/email.html // RFC 2822 if we omit the syntax using double quotes and square brackets @@ -108,17 +112,22 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene super.onFinishInflate(); } - public void setValue(String userId) { + public void setValue(String userId, boolean isMainID) { mName.setText(""); mComment.setText(""); mEmail.setText(""); + //TODO: update this file for blank email/name? + Pattern withComment = Pattern.compile("^(.*) [(](.*)[)] <(.*)>$"); Matcher matcher = withComment.matcher(userId); if (matcher.matches()) { mName.setText(matcher.group(1)); + mOriginalName = matcher.group(1); mComment.setText(matcher.group(2)); + mOriginalComment = matcher.group(2); mEmail.setText(matcher.group(3)); + mOriginalEmail = matcher.group(3); return; } @@ -126,9 +135,14 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene matcher = withoutComment.matcher(userId); if (matcher.matches()) { mName.setText(matcher.group(1)); + mOriginalName = matcher.group(1); mEmail.setText(matcher.group(2)); + mOriginalEmail = matcher.group(2); + mOriginalComment = ""; return; } + mOriginallyMainUserID = isMainID; + setIsMainUserId(isMainID); } public String getValue() throws NoNameException, NoEmailException, InvalidEmailException { @@ -207,6 +221,10 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene @Override public boolean needsSaving() { - return false; + boolean retval = (mOriginallyMainUserID != isMainUserId()); + retval |= (mOriginalName.equals( ("" + mName.getText()).trim() ) ); + retval |= (mOriginalEmail.equals( ("" + mEmail.getText()).trim() ) ); + retval |= (mOriginalComment.equals( ("" + mComment.getText()).trim() ) ); + return retval; } } -- cgit v1.2.3 From 83514b82c0861b90f33a2b32f9dfc1dd54f2cde4 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Wed, 5 Feb 2014 22:19:07 +0000 Subject: notify of changes --- .../keychain/ui/widget/KeyEditor.java | 24 ++++++++++++++++++++++ .../keychain/ui/widget/UserIdEditor.java | 24 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index c941ea908..0ec1bad92 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -39,6 +39,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.DatePicker; import android.widget.LinearLayout; import android.widget.TableLayout; @@ -68,6 +69,19 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { int mOriginalUsage; boolean mIsNewKey; + private CheckBox.OnCheckedChangeListener mCheckChanged = new CheckBox.OnCheckedChangeListener() + { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) + { + if (mEditorListener != null) { + mEditorListener.onEdited(); + } + } + + } + + private int mDatePickerResultCount = 0; private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { @@ -76,6 +90,9 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC")); date.set(year, monthOfYear, dayOfMonth); setExpiryDate(date); + if (mEditorListener != null) { + mEditorListener.onEdited(); + } } } }; @@ -101,9 +118,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mDeleteButton = (BootstrapButton) findViewById(R.id.delete); mDeleteButton.setOnClickListener(this); mChkCertify = (CheckBox) findViewById(R.id.chkCertify); + mChkCertify.setOnCheckedChangeListener(mCheckChanged); mChkSign = (CheckBox) findViewById(R.id.chkSign); + mChkSign.setOnCheckedChangeListener(mCheckChanged); mChkEncrypt = (CheckBox) findViewById(R.id.chkEncrypt); + mChkEncrypt.setOnCheckedChangeListener(mCheckChanged); mChkAuthenticate = (CheckBox) findViewById(R.id.chkAuthenticate); + mChkAuthenticate.setOnCheckedChangeListener(mCheckChanged); setExpiryDate(null); @@ -126,6 +147,9 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { // Note: Ignore results after the first one - android sends multiples. if (mDatePickerResultCount++ == 0) { setExpiryDate(null); + if (mEditorListener != null) { + mEditorListener.onEdited(); + } } } }); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index 4cd1392c2..4b550c580 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -22,6 +22,8 @@ import java.util.regex.Pattern; import org.sufficientlysecure.keychain.R; import android.content.Context; +import android.text.Editable; +import android.text.TextWatcher; import android.util.AttributeSet; import android.view.View; import android.view.View.OnClickListener; @@ -106,6 +108,23 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene mIsMainUserId.setOnClickListener(this); mName = (EditText) findViewById(R.id.name); + mName.addTextChangedListener(new TextWatcher() { + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void afterTextChanged(Editable s) + { + if (mEditorListener != null) { + mEditorListener.onEdited(); + } + } + }); mEmail = (EditText) findViewById(R.id.email); mComment = (EditText) findViewById(R.id.comment); @@ -189,7 +208,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene boolean wasMainUserId = mIsMainUserId.isChecked(); parent.removeView(this); if (mEditorListener != null) { - mEditorListener.onDeleted(this, false); + mEditorListener.onDeleted(this, false); //TODO: WAS THIS A NEW ITEM } if (wasMainUserId && parent.getChildCount() > 0) { UserIdEditor editor = (UserIdEditor) parent.getChildAt(0); @@ -204,6 +223,9 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene editor.setIsMainUserId(false); } } + if (mEditorListener != null) { + mEditorListener.onEdited(); + } } } -- cgit v1.2.3 From 603665976a3a75918fb9838361b7194c5def6968 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 09:00:36 +0000 Subject: new Ids need to be saved --- .../java/org/sufficientlysecure/keychain/ui/widget/SectionView.java | 6 ++---- .../org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index bf8a3f96b..e0d31fa3f 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -166,9 +166,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor UserIdEditor view = (UserIdEditor) mInflater.inflate( R.layout.edit_key_user_id_item, mEditors, false); view.setEditorListener(this); - if (mEditors.getChildCount() == 0) { - view.setIsMainUserId(true); - } + view.setValue("", mEditors.getChildCount() == 0, true); mEditors.addView(view); break; } @@ -273,7 +271,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor UserIdEditor view = (UserIdEditor) mInflater.inflate(R.layout.edit_key_user_id_item, mEditors, false); view.setEditorListener(this); - view.setValue(userId, mEditors.getChildCount() == 0); + view.setValue(userId, mEditors.getChildCount() == 0, false); view.setCanEdit(canEdit); mEditors.addView(view); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index 4b550c580..0509e69f2 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -46,6 +46,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene private EditText mComment; private String mOriginalComment; private boolean mOriginallyMainUserID; + private boolean mIsNewId; // see http://www.regular-expressions.info/email.html // RFC 2822 if we omit the syntax using double quotes and square brackets @@ -131,10 +132,11 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene super.onFinishInflate(); } - public void setValue(String userId, boolean isMainID) { + public void setValue(String userId, boolean isMainID, boolean isNewId) { mName.setText(""); mComment.setText(""); mEmail.setText(""); + mIsNewId = isNewId; //TODO: update this file for blank email/name? @@ -247,6 +249,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene retval |= (mOriginalName.equals( ("" + mName.getText()).trim() ) ); retval |= (mOriginalEmail.equals( ("" + mEmail.getText()).trim() ) ); retval |= (mOriginalComment.equals( ("" + mComment.getText()).trim() ) ); + retval |= mIsNewId; return retval; } } -- cgit v1.2.3 From a5aae930e5e857005563c21fb2c7ca86d6e235da Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 13:28:59 +0000 Subject: allow blank names and emails --- .../keychain/ui/widget/UserIdEditor.java | 67 ++++++---------------- 1 file changed, 17 insertions(+), 50 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index 0509e69f2..641b710a9 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -20,6 +20,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import android.content.Context; import android.text.Editable; @@ -56,14 +57,6 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", Pattern.CASE_INSENSITIVE); - public static class NoNameException extends Exception { - static final long serialVersionUID = 0xf812773343L; - - public NoNameException(String message) { - super(message); - } - } - public void setCanEdit(boolean bCanEdit) { if (!bCanEdit) { mDeleteButton.setVisibility(View.INVISIBLE); @@ -74,14 +67,6 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene } } - public static class NoEmailException extends Exception { - static final long serialVersionUID = 0xf812773344L; - - public NoEmailException(String message) { - super(message); - } - } - public static class InvalidEmailException extends Exception { static final long serialVersionUID = 0xf812773345L; @@ -133,40 +118,31 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene } public void setValue(String userId, boolean isMainID, boolean isNewId) { + mName.setText(""); mComment.setText(""); mEmail.setText(""); mIsNewId = isNewId; - //TODO: update this file for blank email/name? - - Pattern withComment = Pattern.compile("^(.*) [(](.*)[)] <(.*)>$"); - Matcher matcher = withComment.matcher(userId); - if (matcher.matches()) { - mName.setText(matcher.group(1)); - mOriginalName = matcher.group(1); - mComment.setText(matcher.group(2)); - mOriginalComment = matcher.group(2); - mEmail.setText(matcher.group(3)); - mOriginalEmail = matcher.group(3); - return; + String[] result = PgpKeyHelper.splitUserId(userId); + if (result[0] != null) { + mName.setText(result[0]); + mOriginalName = result[0]; } - - Pattern withoutComment = Pattern.compile("^(.*) <(.*)>$"); - matcher = withoutComment.matcher(userId); - if (matcher.matches()) { - mName.setText(matcher.group(1)); - mOriginalName = matcher.group(1); - mEmail.setText(matcher.group(2)); - mOriginalEmail = matcher.group(2); - mOriginalComment = ""; - return; + if (result[1] != null) { + mComment.setText(result[1]); + mOriginalComment = result[1]; + } + if (result[2] != null) { + mEmail.setText(result[2]); + mOriginalEmail = result[2]; } + mOriginallyMainUserID = isMainID; setIsMainUserId(isMainID); } - public String getValue() throws NoNameException, NoEmailException, InvalidEmailException { + public String getValue() throws InvalidEmailException { String name = ("" + mName.getText()).trim(); String email = ("" + mEmail.getText()).trim(); String comment = ("" + mComment.getText()).trim(); @@ -191,16 +167,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene // ok, empty one... return userId; } - - // otherwise make sure that name and email exist - if (name.equals("")) { - throw new NoNameException("need a name"); - } - - if (email.equals("")) { - throw new NoEmailException("need an email"); - } - + //TODO: check gpg accepts an entirely empty ID packet. specs say this is allowed return userId; } @@ -210,7 +177,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene boolean wasMainUserId = mIsMainUserId.isChecked(); parent.removeView(this); if (mEditorListener != null) { - mEditorListener.onDeleted(this, false); //TODO: WAS THIS A NEW ITEM + mEditorListener.onDeleted(this, mIsNewId); } if (wasMainUserId && parent.getChildCount() > 0) { UserIdEditor editor = (UserIdEditor) parent.getChildAt(0); -- cgit v1.2.3 From e7ebbc5ef662ecfe4f43ae203731c6d25cc26e0d Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 13:56:34 +0000 Subject: final link in chain, fix compile --- .../org/sufficientlysecure/keychain/ui/EditKeyActivity.java | 12 ++++++------ .../org/sufficientlysecure/keychain/ui/widget/KeyEditor.java | 3 +-- .../keychain/ui/widget/KeyServerEditor.java | 5 +++++ 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index b28ed8922..d8489ce65 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -96,6 +96,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener private String mNewPassPhrase = null; private String mSavedNewPassPhrase = null; private boolean mIsPassPhraseSet; + private boolean mNeedsSaving; private BootstrapButton mChangePassPhrase; @@ -114,7 +115,9 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener public void onEdited() { - + mNeedsSaving = mUserIdsView.needsSaving(); + mNeedsSaving |= mKeysView.needsSaving(); + Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving), Toast.LENGTH_LONG).show(); } @Override @@ -437,11 +440,13 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mUserIdsView.setType(Id.type.user_id); mUserIdsView.setCanEdit(masterCanSign); mUserIdsView.setUserIds(mUserIds); + mUserIdsView.setEditorListener(this); 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); + mKeysView.setEditorListener(this); container.addView(mKeysView); updatePassPhraseButtonText(); @@ -597,11 +602,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener String userId = null; try { userId = editor.getValue(); - } catch (UserIdEditor.NoNameException e) { - throw new PgpGeneralException(this.getString(R.string.error_user_id_needs_a_name)); - } catch (UserIdEditor.NoEmailException e) { - throw new PgpGeneralException( - this.getString(R.string.error_user_id_needs_an_email_address)); } catch (UserIdEditor.InvalidEmailException e) { throw new PgpGeneralException(e.getMessage()); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 0ec1bad92..009b0cb10 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -78,8 +78,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mEditorListener.onEdited(); } } - - } + }; private int mDatePickerResultCount = 0; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyServerEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyServerEditor.java index a75aafc11..47238cd56 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyServerEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyServerEditor.java @@ -73,6 +73,11 @@ public class KeyServerEditor extends LinearLayout implements Editor, OnClickList } } + @Override + public boolean needsSaving() { + return false; + } + public void setEditorListener(EditorListener listener) { mEditorListener = listener; } -- cgit v1.2.3 From d6726fe9d6a2efccca394567424342df9a941f2e Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 14:25:09 +0000 Subject: some fixes --- .../keychain/ui/widget/UserIdEditor.java | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index 641b710a9..e3747aeb9 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -83,6 +83,24 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene super(context, attrs); } + TextWatcher mTextWatcher = new TextWatcher() { + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void afterTextChanged(Editable s) + { + if (mEditorListener != null) { + mEditorListener.onEdited(); + } + } + }; + @Override protected void onFinishInflate() { setDrawingCacheEnabled(true); @@ -94,25 +112,11 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene mIsMainUserId.setOnClickListener(this); mName = (EditText) findViewById(R.id.name); - mName.addTextChangedListener(new TextWatcher() { - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void afterTextChanged(Editable s) - { - if (mEditorListener != null) { - mEditorListener.onEdited(); - } - } - }); + mName.addTextChangedListener(mTextWatcher); mEmail = (EditText) findViewById(R.id.email); + mEmail.addTextChangedListener(mTextWatcher); mComment = (EditText) findViewById(R.id.comment); + mComment.addTextChangedListener(mTextWatcher); super.onFinishInflate(); } @@ -120,8 +124,11 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene public void setValue(String userId, boolean isMainID, boolean isNewId) { mName.setText(""); + mOriginalName = ""; mComment.setText(""); + mOriginalComment = ""; mEmail.setText(""); + mOriginalEmail = ""; mIsNewId = isNewId; String[] result = PgpKeyHelper.splitUserId(userId); @@ -213,9 +220,9 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene @Override public boolean needsSaving() { boolean retval = (mOriginallyMainUserID != isMainUserId()); - retval |= (mOriginalName.equals( ("" + mName.getText()).trim() ) ); - retval |= (mOriginalEmail.equals( ("" + mEmail.getText()).trim() ) ); - retval |= (mOriginalComment.equals( ("" + mComment.getText()).trim() ) ); + retval |= !(mOriginalName.equals( ("" + mName.getText()).trim() ) ); + retval |= !(mOriginalEmail.equals( ("" + mEmail.getText()).trim() ) ); + retval |= !(mOriginalComment.equals( ("" + mComment.getText()).trim() ) ); retval |= mIsNewId; return retval; } -- cgit v1.2.3 From 53dc044ab4da1e177f4259863cb7fb0266521f6e Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 14:33:29 +0000 Subject: pass message when key added --- .../java/org/sufficientlysecure/keychain/ui/widget/SectionView.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index e0d31fa3f..072c04f03 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -168,6 +168,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor view.setEditorListener(this); view.setValue("", mEditors.getChildCount() == 0, true); mEditors.addView(view); + if (mEditorListener != null) { + mEditorListener.onEdited(); + } break; } @@ -367,5 +370,8 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor view.setValue(newKey, newKey.isMasterKey(), -1, true); mEditors.addView(view); SectionView.this.updateEditorsVisible(); + if (mEditorListener != null) { + mEditorListener.onEdited(); + } } } -- cgit v1.2.3 From 6dbf48275518b6089d4f4a92d20e460d0a2f96ba Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 15:21:29 +0000 Subject: passphrase changes update need to save --- .../keychain/ui/EditKeyActivity.java | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index d8489ce65..b3df52726 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -109,15 +109,22 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener ExportHelper mExportHelper; + public void somethingChanged() + { + mNeedsSaving = mUserIdsView.needsSaving(); + mNeedsSaving |= mKeysView.needsSaving(); + mNeedsSaving |= hasPassphraseChanged(); + Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show(); + } + public void onDeleted(Editor e, boolean wasNewItem) { + somethingChanged(); } public void onEdited() { - mNeedsSaving = mUserIdsView.needsSaving(); - mNeedsSaving |= mKeysView.needsSaving(); - Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving), Toast.LENGTH_LONG).show(); + somethingChanged(); } @Override @@ -400,6 +407,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener .getString(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE); updatePassPhraseButtonText(); + somethingChanged(); } } }; @@ -471,6 +479,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mNewPassPhrase = mSavedNewPassPhrase; mChangePassPhrase.setVisibility(View.VISIBLE); } + somethingChanged(); } }); } @@ -493,6 +502,15 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } } + public boolean hasPassphraseChanged() + { + if (mNoPassphrase.isChecked()) { + return mIsPassPhraseSet; + } else { + return (mNewPassPhrase != null && !mNewPassPhrase.equals("")); + } + } + private void saveClicked() { long masterKeyId = getMasterKeyId(); try { -- cgit v1.2.3 From d4d6de1bc5c538c17613f5918e70ee0932637915 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 20:07:04 +0000 Subject: select old date doesn't need save --- .../java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 009b0cb10..ba10c7603 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -88,7 +88,11 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { if (mDatePickerResultCount++ == 0) { GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC")); date.set(year, monthOfYear, dayOfMonth); - setExpiryDate(date); + long numDays = (date.getTimeInMillis() / 86400000) - (mOriginalExpiryDate.getTimeInMillis() / 86400000); + if (numDays == 0) + setExpiryDate(mOriginalExpiryDate); + else + setExpiryDate(date); if (mEditorListener != null) { mEditorListener.onEdited(); } @@ -231,7 +235,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } else { cal.setTime(PgpKeyHelper.getExpiryDate(key)); setExpiryDate(cal); - mOriginalExpiryDate = cal; // TODO: ensure time doesn't matter when selecting the same date as before + mOriginalExpiryDate = cal; } } -- cgit v1.2.3 From aee4ec6d1f5b41d882dea747915af93cd7d84652 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 22:16:41 +0000 Subject: action bar and a small fix --- .../keychain/ui/EditKeyActivity.java | 57 ++++++++++++---------- .../keychain/ui/widget/SectionView.java | 3 ++ .../keychain/ui/widget/UserIdEditor.java | 8 +-- 3 files changed, 38 insertions(+), 30 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index b3df52726..89af2d683 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -55,6 +55,7 @@ import android.os.Handler; import android.os.Message; import android.os.Messenger; import android.support.v7.app.ActionBarActivity; +import android.support.v4.app.ActivityCompat; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -97,6 +98,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener private String mSavedNewPassPhrase = null; private boolean mIsPassPhraseSet; private boolean mNeedsSaving; + private MenuItem mSaveButton; private BootstrapButton mChangePassPhrase; @@ -109,12 +111,19 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener ExportHelper mExportHelper; - public void somethingChanged() + public boolean needsSaving() { mNeedsSaving = mUserIdsView.needsSaving(); mNeedsSaving |= mKeysView.needsSaving(); mNeedsSaving |= hasPassphraseChanged(); - Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show(); + return mNeedsSaving; + } + + + public void somethingChanged() + { + ActivityCompat.invalidateOptionsMenu(this); + //Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show(); } public void onDeleted(Editor e, boolean wasNewItem) @@ -133,6 +142,10 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mExportHelper = new ExportHelper(this); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setIcon(android.R.color.transparent); + getSupportActionBar().setHomeButtonEnabled(true); + mUserIds = new Vector(); mKeys = new Vector(); mKeysUsages = new Vector(); @@ -153,20 +166,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener * @param intent */ private void handleActionCreateKey(Intent intent) { - // Inflate a "Done"/"Cancel" custom action bar - ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save, - new View.OnClickListener() { - @Override - public void onClick(View v) { - saveClicked(); - } - }, R.string.btn_do_not_save, new View.OnClickListener() { - @Override - public void onClick(View v) { - cancelClicked(); - } - }); - Bundle extras = intent.getExtras(); mCurrentPassPhrase = ""; @@ -255,15 +254,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener * @param intent */ private void handleActionEditKey(Intent intent) { - // Inflate a "Done"/"Cancel" custom action bar - ActionBarHelper.setDoneView(getSupportActionBar(), R.string.btn_save, - new View.OnClickListener() { - @Override - public void onClick(View v) { - saveClicked(); - } - }); - mDataUri = intent.getData(); if (mDataUri == null) { Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); @@ -325,12 +315,17 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.key_edit, menu); + mSaveButton = (MenuItem) menu.findItem(R.id.menu_key_edit_save); + mSaveButton.setEnabled(needsSaving()); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case android.R.id.home: + cancelClicked(); + return true; case R.id.menu_key_edit_cancel: cancelClicked(); return true; @@ -353,6 +348,9 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mExportHelper.deleteKey(mDataUri, Id.type.secret_key, returnHandler); return true; } + case R.id.menu_key_edit_save: + saveClicked(); + return true; } return super.onOptionsItemSelected(item); } @@ -373,8 +371,15 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_LONG).show(); } if (masterKey != null) { + boolean isSet = false; for (String userId : new IterableIterator(masterKey.getUserIDs())) { Log.d(Constants.TAG, "Added userId " + userId); + if (!isSet) { + isSet = true; + String[] parts = PgpKeyHelper.splitUserId(userId); + if (parts[0] != null) + setTitle(parts[0]); + } mUserIds.add(userId); } } @@ -465,7 +470,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } }); - // disable passphrase when no passphrase checkobox is checked! + // disable passphrase when no passphrase checkbox is checked! mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 072c04f03..21ebff102 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -133,6 +133,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor public void onDeleted(Editor editor, boolean wasNewItem) { oldItemDeleted |= !wasNewItem; this.updateEditorsVisible(); + if (mEditorListener != null) { + mEditorListener.onEdited(); + } } @Override diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index e3747aeb9..b499a429a 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -137,12 +137,12 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene mOriginalName = result[0]; } if (result[1] != null) { - mComment.setText(result[1]); - mOriginalComment = result[1]; + mEmail.setText(result[1]); + mOriginalEmail = result[1]; } if (result[2] != null) { - mEmail.setText(result[2]); - mOriginalEmail = result[2]; + mComment.setText(result[2]); + mOriginalComment = result[2]; } mOriginallyMainUserID = isMainID; -- cgit v1.2.3 From fd33a6764567bfd02c1af228161501078ca8030a Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 22:35:27 +0000 Subject: ask for save --- .../keychain/ui/EditKeyActivity.java | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 89af2d683..49713db71 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -46,8 +46,10 @@ import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; +import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -604,8 +606,35 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } private void cancelClicked() { - setResult(RESULT_CANCELED); - finish(); + if (mNeedsSaving && masterCanSign) { //ask if we want to save + AlertDialog.Builder alert = new AlertDialog.Builder( + EditKeyActivity.this); + + alert.setIcon(android.R.drawable.ic_dialog_alert); + alert.setTitle(R.string.warning); + alert.setMessage(EditKeyActivity.this.getString(R.string.ask_save_changed_key)); + + alert.setPositiveButton(EditKeyActivity.this.getString(android.R.string.yes), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + saveClicked(); + } + }); + alert.setNegativeButton(this.getString(android.R.string.no), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + setResult(RESULT_CANCELED); + finish(); + } + }); + alert.setCancelable(false); + alert.create().show(); + } else { + setResult(RESULT_CANCELED); + finish(); + } } /** -- cgit v1.2.3 From 899fadb9169e93105f633c0925835cce9c413b24 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 22:43:59 +0000 Subject: can change passwords --- .../main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 49713db71..694e52f71 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -606,7 +606,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } private void cancelClicked() { - if (mNeedsSaving && masterCanSign) { //ask if we want to save + if (mNeedsSaving) { //ask if we want to save AlertDialog.Builder alert = new AlertDialog.Builder( EditKeyActivity.this); -- cgit v1.2.3 From 8d1047d05c3a0e1e1310fb1a47dc6d4f80b2c0f4 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Feb 2014 22:52:22 +0000 Subject: fix a crash --- .../org/sufficientlysecure/keychain/ui/widget/KeyEditor.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index ba10c7603..fa220313c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -88,11 +88,15 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { if (mDatePickerResultCount++ == 0) { GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC")); date.set(year, monthOfYear, dayOfMonth); - long numDays = (date.getTimeInMillis() / 86400000) - (mOriginalExpiryDate.getTimeInMillis() / 86400000); - if (numDays == 0) - setExpiryDate(mOriginalExpiryDate); - else + if (mOriginalExpiryDate != null) { + long numDays = (date.getTimeInMillis() / 86400000) - (mOriginalExpiryDate.getTimeInMillis() / 86400000); + if (numDays == 0) + setExpiryDate(mOriginalExpiryDate); + else + setExpiryDate(date); + } else { setExpiryDate(date); + } if (mEditorListener != null) { mEditorListener.onEdited(); } -- cgit v1.2.3 From cd2b493ea8d25796bf666b46597e6b6bd416f64b Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 12:12:17 +0000 Subject: small extra check --- .../keychain/ui/EditKeyActivity.java | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 694e52f71..d53a1f836 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -326,7 +326,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - cancelClicked(); + cancelClicked(); //TODO: why isn't this triggered on my tablet - one of many ui problems I've had with this device. A code compatibility issue or a Samsung fail? return true; case R.id.menu_key_edit_cancel: cancelClicked(); @@ -520,25 +520,27 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener private void saveClicked() { long masterKeyId = getMasterKeyId(); - try { - if (!isPassphraseSet()) { - throw new PgpGeneralException(this.getString(R.string.set_a_passphrase)); - } + if (needsSaving()) { //make sure, as some versions don't support invalidateOptionsMenu + try { + if (!isPassphraseSet()) { + throw new PgpGeneralException(this.getString(R.string.set_a_passphrase)); + } - String passphrase = null; - if (mIsPassPhraseSet) - passphrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId); - else - passphrase = ""; - if (passphrase == null) { - showPassphraseDialog(masterKeyId, masterCanSign); - } else { - mCurrentPassPhrase = passphrase; - finallySaveClicked(); + String passphrase = null; + if (mIsPassPhraseSet) + passphrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId); + else + passphrase = ""; + if (passphrase == null) { + showPassphraseDialog(masterKeyId, masterCanSign); + } else { + mCurrentPassPhrase = passphrase; + finallySaveClicked(); + } + } catch (PgpGeneralException e) { + Toast.makeText(this, getString(R.string.error_message, e.getMessage()), + Toast.LENGTH_SHORT).show(); } - } catch (PgpGeneralException e) { - //Toast.makeText(this, getString(R.string.error_message, e.getMessage()), - // Toast.LENGTH_SHORT).show(); } } -- cgit v1.2.3 From b74ed4643453cd089ec885bb3f56169629f8cacf Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 15:35:44 +0000 Subject: disable export if unsaved --- .../java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index d53a1f836..66f23e22e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -332,8 +332,12 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener cancelClicked(); return true; case R.id.menu_key_edit_export_file: - mExportHelper.showExportKeysDialog(mDataUri, Id.type.secret_key, Constants.path.APP_DIR - + "/secexport.asc"); + if (needsSaving()) { + Toast.makeText(this, R.string.error_save_first, Toast.LENGTH_LONG).show(); + } else { + mExportHelper.showExportKeysDialog(mDataUri, Id.type.secret_key, Constants.path.APP_DIR + + "/secexport.asc"); + } return true; case R.id.menu_key_edit_delete: { // Message is received after key is deleted -- cgit v1.2.3 From 44ee7137632c2fd8e6d97a8f05a213467ecf1dc6 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 15:51:11 +0000 Subject: fix create keyring crash --- .../sufficientlysecure/keychain/ui/EditKeyActivity.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 66f23e22e..802d29a44 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -115,8 +115,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener public boolean needsSaving() { - mNeedsSaving = mUserIdsView.needsSaving(); - mNeedsSaving |= mKeysView.needsSaving(); + mNeedsSaving = (mUserIdsView == null) ? false : mUserIdsView.needsSaving(); + mNeedsSaving |= (mKeysView == null) ? false : mKeysView.needsSaving(); mNeedsSaving |= hasPassphraseChanged(); return mNeedsSaving; } @@ -515,10 +515,14 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener public boolean hasPassphraseChanged() { - if (mNoPassphrase.isChecked()) { - return mIsPassPhraseSet; - } else { - return (mNewPassPhrase != null && !mNewPassPhrase.equals("")); + if (mNoPassphrase != null) { + if (mNoPassphrase.isChecked()) { + return mIsPassPhraseSet; + } else { + return (mNewPassPhrase != null && !mNewPassPhrase.equals("")); + } + }else { + return false; } } -- cgit v1.2.3 From 5def251e62d383f023c62fea1734977e11b0fa27 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 15:59:44 +0000 Subject: keep track of brand new keys, they need saving --- .../java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 802d29a44..9ddfadef1 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -100,6 +100,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener private String mSavedNewPassPhrase = null; private boolean mIsPassPhraseSet; private boolean mNeedsSaving; + private boolean mIsBrandNewKeyring = false; private MenuItem mSaveButton; private BootstrapButton mChangePassPhrase; @@ -118,6 +119,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mNeedsSaving = (mUserIdsView == null) ? false : mUserIdsView.needsSaving(); mNeedsSaving |= (mKeysView == null) ? false : mKeysView.needsSaving(); mNeedsSaving |= hasPassphraseChanged(); + mNeedsSaving |= mIsBrandNewKeyring; return mNeedsSaving; } @@ -171,6 +173,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener Bundle extras = intent.getExtras(); mCurrentPassPhrase = ""; + mIsBrandNewKeyring = true; if (extras != null) { // if userId is given, prefill the fields @@ -616,7 +619,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } private void cancelClicked() { - if (mNeedsSaving) { //ask if we want to save + if (needsSaving()) { //ask if we want to save AlertDialog.Builder alert = new AlertDialog.Builder( EditKeyActivity.this); -- cgit v1.2.3 From 33f41e66a0a39ab7b8eb48c1055ba16ce8d784f5 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 16:18:30 +0000 Subject: consistent ui --- .../sufficientlysecure/keychain/ui/EditKeyActivity.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 9ddfadef1..a0c2871ae 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -306,22 +306,19 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } } - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - // show menu only on edit - if (mDataUri != null) { - return super.onPrepareOptionsMenu(menu); - } else { - return false; - } - } - @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.key_edit, menu); mSaveButton = (MenuItem) menu.findItem(R.id.menu_key_edit_save); mSaveButton.setEnabled(needsSaving()); + //totally get rid of some actions for new keys + if (mDataUri == null) { + MenuItem mButton = (MenuItem) menu.findItem(R.id.menu_key_edit_export_file); + mButton.setVisible(false); + mButton = (MenuItem) menu.findItem(R.id.menu_key_edit_delete); + mButton.setVisible(false); + } return true; } -- cgit v1.2.3 From adc6a3ea64c00f35e881e856d2877c2ea88c7e51 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 16:33:37 +0000 Subject: some AS Inspect Code fixes --- .../keychain/ui/EditKeyActivity.java | 33 ++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index a0c2871ae..d12a5479d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -26,7 +26,6 @@ import org.spongycastle.openpgp.PGPSecretKeyRing; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.helper.ActionBarHelper; import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; @@ -218,10 +217,10 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { // get new key from data bundle returned from service Bundle data = message.getData(); - PGPSecretKey masterKey = (PGPSecretKey) PgpConversionHelper + PGPSecretKey masterKey = PgpConversionHelper .BytesToPGPSecretKey(data .getByteArray(KeychainIntentService.RESULT_NEW_KEY)); - PGPSecretKey subKey = (PGPSecretKey) PgpConversionHelper + PGPSecretKey subKey = PgpConversionHelper .BytesToPGPSecretKey(data .getByteArray(KeychainIntentService.RESULT_NEW_KEY2)); @@ -235,7 +234,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener buildLayout(); } - }; + } }; // Create a new Messenger for the communication back @@ -263,7 +262,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener if (mDataUri == null) { Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); finish(); - return; } else { Log.d(Constants.TAG, "uri: " + mDataUri); @@ -273,19 +271,18 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener long masterKeyId = ProviderHelper.getSecretMasterKeyId(this, keyRingRowId); masterCanSign = ProviderHelper.getSecretMasterKeyCanCertify(this, keyRingRowId); - finallyEdit(masterKeyId, masterCanSign); + finallyEdit(masterKeyId); } } - private void showPassphraseDialog(final long masterKeyId, final boolean masterCanSign) { + private void showPassphraseDialog(final long masterKeyId) { // Message is received after passphrase is cached Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { - String passPhrase = PassphraseCacheService.getCachedPassphrase( + mCurrentPassPhrase = PassphraseCacheService.getCachedPassphrase( EditKeyActivity.this, masterKeyId); - mCurrentPassPhrase = passPhrase; finallySaveClicked(); } } @@ -310,13 +307,13 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.key_edit, menu); - mSaveButton = (MenuItem) menu.findItem(R.id.menu_key_edit_save); + mSaveButton = menu.findItem(R.id.menu_key_edit_save); mSaveButton.setEnabled(needsSaving()); //totally get rid of some actions for new keys if (mDataUri == null) { - MenuItem mButton = (MenuItem) menu.findItem(R.id.menu_key_edit_export_file); + MenuItem mButton = menu.findItem(R.id.menu_key_edit_export_file); mButton.setVisible(false); - mButton = (MenuItem) menu.findItem(R.id.menu_key_edit_delete); + mButton = menu.findItem(R.id.menu_key_edit_delete); mButton.setVisible(false); } return true; @@ -362,7 +359,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } @SuppressWarnings("unchecked") - private void finallyEdit(final long masterKeyId, final boolean masterCanSign) { + private void finallyEdit(final long masterKeyId) { if (masterKeyId != 0) { PGPSecretKey masterKey = null; mKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(this, masterKeyId); @@ -427,7 +424,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener Messenger messenger = new Messenger(returnHandler); // set title based on isPassphraseSet() - int title = -1; + int title; if (isPassphraseSet()) { title = R.string.title_change_pass_phrase; } else { @@ -534,13 +531,13 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener throw new PgpGeneralException(this.getString(R.string.set_a_passphrase)); } - String passphrase = null; + String passphrase; if (mIsPassPhraseSet) passphrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId); else passphrase = ""; if (passphrase == null) { - showPassphraseDialog(masterKeyId, masterCanSign); + showPassphraseDialog(masterKeyId); } else { mCurrentPassPhrase = passphrase; finallySaveClicked(); @@ -598,7 +595,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener setResult(RESULT_OK, data); finish(); } - }; + } }; // Create a new Messenger for the communication back @@ -661,7 +658,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener boolean gotMainUserId = false; for (int i = 0; i < userIdEditors.getChildCount(); ++i) { UserIdEditor editor = (UserIdEditor) userIdEditors.getChildAt(i); - String userId = null; + String userId; try { userId = editor.getValue(); } catch (UserIdEditor.InvalidEmailException e) { -- cgit v1.2.3 From 75640934a080d21113f501ed604b85de3eab6b51 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 21:04:38 +0000 Subject: saving fixes --- .../keychain/ui/EditKeyActivity.java | 26 +++++++++++----------- .../keychain/ui/widget/KeyEditor.java | 20 +++++++++++------ .../keychain/ui/widget/SectionView.java | 10 ++++++--- 3 files changed, 33 insertions(+), 23 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index d12a5479d..132141bc5 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.GregorianCalendar; import java.util.Vector; +import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKeyRing; import org.sufficientlysecure.keychain.Constants; @@ -224,15 +225,17 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener .BytesToPGPSecretKey(data .getByteArray(KeychainIntentService.RESULT_NEW_KEY2)); + //We must set the key flags here as they are not set when we make the + //key pair. Because we are not generating hashed packets there... // add master key mKeys.add(masterKey); - mKeysUsages.add(Id.choice.usage.sign_only); //TODO: get from key flags + mKeysUsages.add(KeyFlags.CERTIFY_OTHER); // add sub key mKeys.add(subKey); - mKeysUsages.add(Id.choice.usage.encrypt_only); //TODO: get from key flags + mKeysUsages.add(KeyFlags.ENCRYPT_COMMS + KeyFlags.ENCRYPT_STORAGE); - buildLayout(); + buildLayout(true); } } }; @@ -248,7 +251,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } } } else { - buildLayout(); + buildLayout(false); } } @@ -390,7 +393,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mCurrentPassPhrase = ""; - buildLayout(); + buildLayout(false); mIsPassPhraseSet = PassphraseCacheService.hasPassphrase(this, masterKeyId); if (!mIsPassPhraseSet) { // check "no passphrase" checkbox and remove button @@ -440,8 +443,9 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener /** * Build layout based on mUserId, mKeys and mKeysUsages Vectors. It creates Views for every user * id and key. + * @param newKeys */ - private void buildLayout() { + private void buildLayout(boolean newKeys) { setContentView(R.layout.edit_key_activity); // find views @@ -461,7 +465,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mKeysView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false); mKeysView.setType(Id.type.key); mKeysView.setCanEdit(masterCanSign); - mKeysView.setKeys(mKeys, mKeysUsages); + mKeysView.setKeys(mKeys, mKeysUsages, newKeys); mKeysView.setEditorListener(this); container.addView(mKeysView); @@ -607,8 +611,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener // start service with intent startService(intent); } catch (PgpGeneralException e) { - //Toast.makeText(this, getString(R.string.error_message, e.getMessage()), - // Toast.LENGTH_SHORT).show(); + Toast.makeText(this, getString(R.string.error_message, e.getMessage()), + Toast.LENGTH_SHORT).show(); } } @@ -665,10 +669,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener throw new PgpGeneralException(e.getMessage()); } - if (userId.equals("")) { - continue; - } - if (editor.isMainUserId()) { userIds.add(0, userId); gotMainUserId = true; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index fa220313c..5ce5d89d7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -24,6 +24,7 @@ import java.util.TimeZone; import java.util.Vector; import org.spongycastle.bcpg.sig.KeyFlags; +import org.spongycastle.openpgp.PGPKeyFlags; import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPSecretKey; import org.sufficientlysecure.keychain.R; @@ -216,17 +217,22 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } int selectId = 0; - if (key.isMasterKey()) - mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key)); - mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); - mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); - mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); mIsNewKey = isNewKey; - if (isNewKey) + if (isNewKey) { mUsage = usage; - else { + mChkCertify.setChecked((usage &= KeyFlags.CERTIFY_OTHER) == KeyFlags.CERTIFY_OTHER); + mChkSign.setChecked((usage &= KeyFlags.SIGN_DATA) == KeyFlags.SIGN_DATA); + mChkEncrypt.setChecked(((usage &= KeyFlags.ENCRYPT_COMMS) == KeyFlags.ENCRYPT_COMMS) || + ((usage &= KeyFlags.ENCRYPT_STORAGE) == KeyFlags.ENCRYPT_STORAGE)); + mChkAuthenticate.setChecked((usage &= KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION); + } else { mUsage = PgpKeyHelper.getKeyUsage(key); mOriginalUsage = mUsage; + if (key.isMasterKey()) + mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key)); + mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); + mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); + mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); } GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 21ebff102..315a8faba 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -18,6 +18,7 @@ package org.sufficientlysecure.keychain.ui.widget; import java.util.Vector; +import org.spongycastle.openpgp.PGPKeyFlags; import org.spongycastle.openpgp.PGPSecretKey; import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; @@ -285,7 +286,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor this.updateEditorsVisible(); } - public void setKeys(Vector list, Vector usages) { + public void setKeys(Vector list, Vector usages, boolean newKeys) { if (mType != Id.type.key) { return; } @@ -298,7 +299,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor false); view.setEditorListener(this); boolean isMasterKey = (mEditors.getChildCount() == 0); - view.setValue(list.get(i), isMasterKey, usages.get(i), false); + view.setValue(list.get(i), isMasterKey, usages.get(i), newKeys); view.setCanEdit(canEdit); mEditors.addView(view); } @@ -370,7 +371,10 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item, mEditors, false); view.setEditorListener(SectionView.this); - view.setValue(newKey, newKey.isMasterKey(), -1, true); + int usage = 0; + if (mEditors.getChildCount() == 0) + usage = PGPKeyFlags.CAN_CERTIFY; + view.setValue(newKey, newKey.isMasterKey(), usage, true); mEditors.addView(view); SectionView.this.updateEditorsVisible(); if (mEditorListener != null) { -- cgit v1.2.3 From 5bd0a2ebc8d4738d53d5ba3e112069ca6a0d049a Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 21:38:56 +0000 Subject: fix Android Studio analysis issues --- .../keychain/pgp/PgpKeyOperation.java | 54 +++++++--------------- 1 file changed, 17 insertions(+), 37 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index d2793a859..7ab5df613 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -23,6 +23,7 @@ import java.security.InvalidAlgorithmParameterException; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; +import java.security.PublicKey; import java.security.SecureRandom; import java.security.SignatureException; import java.util.ArrayList; @@ -56,6 +57,7 @@ import org.spongycastle.openpgp.operator.PGPContentSignerBuilder; import org.spongycastle.openpgp.operator.PGPDigestCalculator; import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; +import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyPair; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; @@ -71,8 +73,8 @@ import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import android.content.Context; public class PgpKeyOperation { - private Context mContext; - private ProgressDialogUpdater mProgress; + private final Context mContext; + private final ProgressDialogUpdater mProgress; private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[] { SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192, @@ -90,34 +92,18 @@ public class PgpKeyOperation { this.mProgress = progress; } - public void updateProgress(int message, int current, int total) { + void updateProgress(int message, int current, int total) { if (mProgress != null) { mProgress.setProgress(message, current, total); } } - public void updateProgress(int current, int total) { + void updateProgress(int current, int total) { if (mProgress != null) { mProgress.setProgress(current, total); } } - /** - * Creates new secret key. - * - * @param algorithmChoice - * @param keySize - * @param passPhrase - * @param isMasterKey - * @return - * @throws NoSuchAlgorithmException - * @throws PGPException - * @throws NoSuchProviderException - * @throws PgpGeneralException - * @throws InvalidAlgorithmParameterException - */ - - // TODO: key flags? public PGPSecretKey createKey(int algorithmChoice, int keySize, String passPhrase, boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException, PgpGeneralException, InvalidAlgorithmParameterException { @@ -130,8 +116,8 @@ public class PgpKeyOperation { passPhrase = ""; } - int algorithm = 0; - KeyPairGenerator keyGen = null; + int algorithm; + KeyPairGenerator keyGen; switch (algorithmChoice) { case Id.choice.algorithm.dsa: { @@ -183,15 +169,13 @@ public class PgpKeyOperation { PGPEncryptedData.CAST5, sha1Calc) .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray()); - PGPSecretKey secKey = new PGPSecretKey(keyPair.getPrivateKey(), keyPair.getPublicKey(), + return new PGPSecretKey(keyPair.getPrivateKey(), keyPair.getPublicKey(), sha1Calc, isMasterKey, keyEncryptor); - return secKey; } public void changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase, - String newPassPhrase) throws IOException, PGPException, PGPException, - NoSuchProviderException { + String newPassPhrase) throws IOException, PGPException { updateProgress(R.string.progress_building_key, 0, 100); if (oldPassPhrase == null) { @@ -219,9 +203,8 @@ public class PgpKeyOperation { public void buildSecretKey(ArrayList userIds, ArrayList keys, ArrayList keysUsages, ArrayList keysExpiryDates, - long masterKeyId, String oldPassPhrase, - String newPassPhrase) throws PgpGeneralException, NoSuchProviderException, - PGPException, NoSuchAlgorithmException, SignatureException, IOException { + String oldPassPhrase, String newPassPhrase) throws PgpGeneralException, + PGPException, SignatureException, IOException { Log.d(Constants.TAG, "userIds: " + userIds.toString()); @@ -237,17 +220,16 @@ public class PgpKeyOperation { updateProgress(R.string.progress_preparing_master_key, 10, 100); int usageId = keysUsages.get(0); - boolean canSign = (usageId & KeyFlags.SIGN_DATA) > 0; - boolean canEncrypt = (usageId & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) > 0; - + boolean canSign; String mainUserId = userIds.get(0); PGPSecretKey masterKey = keys.get(0); // this removes all userIds and certifications previously attached to the masterPublicKey PGPPublicKey tmpKey = masterKey.getPublicKey(); - PGPPublicKey masterPublicKey = new PGPPublicKey(tmpKey.getAlgorithm(), - tmpKey.getKey(new BouncyCastleProvider()), tmpKey.getCreationTime()); + PublicKey tmpPuK = new JcaPGPKeyConverter().setProvider(new BouncyCastleProvider()).getPublicKey(tmpKey); + PGPPublicKey masterPublicKey = new JcaPGPKeyConverter().getPGPPublicKey(tmpKey.getAlgorithm(), + tmpPuK, tmpKey.getCreationTime()); // already done by code above: // PGPPublicKey masterPublicKey = masterKey.getPublicKey(); @@ -347,7 +329,6 @@ public class PgpKeyOperation { usageId = keysUsages.get(i); canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this - canEncrypt = (usageId & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) > 0; if (canSign) { Date todayDate = new Date(); //both sig times the same // cross-certify signing keys @@ -396,8 +377,7 @@ public class PgpKeyOperation { } public PGPPublicKeyRing signKey(long masterKeyId, long pubKeyId, String passphrase) - throws PgpGeneralException, NoSuchAlgorithmException, NoSuchProviderException, - PGPException, SignatureException { + throws PgpGeneralException, PGPException, SignatureException { if (passphrase == null) { throw new PgpGeneralException("Unable to obtain passphrase"); } else { -- cgit v1.2.3 From e150004e32d4f4278950dc2b24a9cf70885c468f Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 8 Feb 2014 21:42:04 +0000 Subject: should have used refactor... --- .../org/sufficientlysecure/keychain/service/KeychainIntentService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 657d40a5a..a31ddc53e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -542,7 +542,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId), oldPassPhrase, newPassPhrase); } else { - keyOperations.buildSecretKey(userIds, keys, keysUsages, keysExpiryDates, masterKeyId, + keyOperations.buildSecretKey(userIds, keys, keysUsages, keysExpiryDates, oldPassPhrase, newPassPhrase); } PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase); -- cgit v1.2.3 From 076a7ec4a16a6db5df0bbe5490d44cbd514f10c1 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 13 Feb 2014 22:05:36 +0000 Subject: save work, this code doesn't work... --- .../keychain/pgp/PgpKeyOperation.java | 34 ++++++++++------------ .../keychain/service/KeychainIntentService.java | 11 +++++-- .../keychain/ui/EditKeyActivity.java | 15 ++++++++++ .../keychain/ui/widget/SectionView.java | 19 ++++++++++++ 4 files changed, 58 insertions(+), 21 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 7ab5df613..505d3ba55 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -23,7 +23,6 @@ import java.security.InvalidAlgorithmParameterException; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -import java.security.PublicKey; import java.security.SecureRandom; import java.security.SignatureException; import java.util.ArrayList; @@ -35,7 +34,6 @@ import org.spongycastle.bcpg.CompressionAlgorithmTags; import org.spongycastle.bcpg.HashAlgorithmTags; import org.spongycastle.bcpg.SymmetricKeyAlgorithmTags; import org.spongycastle.bcpg.sig.KeyFlags; -import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.spec.ElGamalParameterSpec; import org.spongycastle.openpgp.PGPEncryptedData; import org.spongycastle.openpgp.PGPException; @@ -57,7 +55,6 @@ import org.spongycastle.openpgp.operator.PGPContentSignerBuilder; import org.spongycastle.openpgp.operator.PGPDigestCalculator; import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; -import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyPair; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; @@ -201,9 +198,7 @@ public class PgpKeyOperation { } - public void buildSecretKey(ArrayList userIds, ArrayList keys, - ArrayList keysUsages, ArrayList keysExpiryDates, - String oldPassPhrase, String newPassPhrase) throws PgpGeneralException, + public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, ArrayList keys, boolean[] modded_keys, String newPassPhrase, ArrayList keysExpiryDates, String oldPassPhrase, ArrayList keysUsages) throws PgpGeneralException, PGPException, SignatureException, IOException { Log.d(Constants.TAG, "userIds: " + userIds.toString()); @@ -226,10 +221,7 @@ public class PgpKeyOperation { PGPSecretKey masterKey = keys.get(0); // this removes all userIds and certifications previously attached to the masterPublicKey - PGPPublicKey tmpKey = masterKey.getPublicKey(); - PublicKey tmpPuK = new JcaPGPKeyConverter().setProvider(new BouncyCastleProvider()).getPublicKey(tmpKey); - PGPPublicKey masterPublicKey = new JcaPGPKeyConverter().getPGPPublicKey(tmpKey.getAlgorithm(), - tmpPuK, tmpKey.getCreationTime()); + PGPPublicKey masterPublicKey = masterKey.getPublicKey(); // already done by code above: // PGPPublicKey masterPublicKey = masterKey.getPublicKey(); @@ -243,6 +235,8 @@ public class PgpKeyOperation { // masterPublicKey = masterPublicKeyRmCert; // } + + PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray()); PGPPrivateKey masterPrivateKey = masterKey.extractPrivateKey(keyDecryptor); @@ -250,18 +244,22 @@ public class PgpKeyOperation { updateProgress(R.string.progress_certifying_master_key, 20, 100); // TODO: if we are editing a key, keep old certs, don't remake certs we don't have to. - + int user_id_index = 0; for (String userId : userIds) { - PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( - masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) - .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); - PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); + if (OriginalIDs[user_id_index]) { + PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( + masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); + PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); - sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); + sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); - PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); + PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); - masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); + masterPublicKey = PGPPublicKey.removeCertification(); + masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); + } + user_id_index++; } PGPKeyPair masterKeyPair = new PGPKeyPair(masterPublicKey, masterPrivateKey); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index a31ddc53e..4cace2658 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -54,7 +54,6 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry; import org.sufficientlysecure.keychain.util.HkpKeyServer; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.PositionAwareInputStream; import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import android.app.IntentService; @@ -135,6 +134,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial public static final String SAVE_KEYRING_KEYS_EXPIRY_DATES = "keys_expiry_dates"; public static final String SAVE_KEYRING_MASTER_KEY_ID = "master_key_id"; public static final String SAVE_KEYRING_CAN_SIGN = "can_sign"; + public static final String SAVE_KEYRING_ORIGINAL_IDS = "original_ids"; + public static final String SAVE_KEYRING_DELETED_IDS = "deleted_ids"; + public static final String SAVE_KEYRING_MODDED_KEYS = "modified_keys"; // generate key public static final String GENERATE_KEY_ALGORITHM = "algorithm"; @@ -532,6 +534,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial .getByteArray(SAVE_KEYRING_KEYS)); ArrayList keysUsages = data.getIntegerArrayList(SAVE_KEYRING_KEYS_USAGES); ArrayList keysExpiryDates = (ArrayList) data.getSerializable(SAVE_KEYRING_KEYS_EXPIRY_DATES); + ArrayList original_ids = data.getStringArrayList(SAVE_KEYRING_ORIGINAL_IDS); + ArrayList deleted_ids = data.getStringArrayList(SAVE_KEYRING_DELETED_IDS); + boolean[] modded_keys = data.getBooleanArray(SAVE_KEYRING_MODDED_KEYS); long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID); @@ -542,8 +547,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId), oldPassPhrase, newPassPhrase); } else { - keyOperations.buildSecretKey(userIds, keys, keysUsages, keysExpiryDates, - oldPassPhrase, newPassPhrase); + keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, keys, modded_keys, + newPassPhrase, keysExpiryDates, oldPassPhrase, keysUsages); } PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 132141bc5..5adb65342 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui; import java.util.ArrayList; import java.util.GregorianCalendar; +import java.util.List; import java.util.Vector; import org.spongycastle.bcpg.sig.KeyFlags; @@ -553,6 +554,15 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } } + private boolean[] toPrimitiveArray(final List booleanList) { + final boolean[] primitives = new boolean[booleanList.size()]; + int index = 0; + for (Boolean object : booleanList) { + primitives[index++] = object; + } + return primitives; + } + private void finallySaveClicked() { try { // Send all information needed to service to edit key in other thread @@ -576,6 +586,11 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener getKeysExpiryDates(mKeysView)); data.putLong(KeychainIntentService.SAVE_KEYRING_MASTER_KEY_ID, getMasterKeyId()); data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign); + data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS, ); + data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS, + toPrimitiveArray(mUserIdsView.getNeedsSavingArray())); + data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_MODDED_KEYS, + toPrimitiveArray(mKeysView.getNeedsSavingArray())); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 315a8faba..5eaf54841 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -16,6 +16,8 @@ package org.sufficientlysecure.keychain.ui.widget; +import java.util.ArrayList; +import java.util.List; import java.util.Vector; import org.spongycastle.openpgp.PGPKeyFlags; @@ -162,6 +164,23 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor return ret; } + public List getNeedsSavingArray() + { + ArrayList mList = new ArrayList(); + for (int i = 0; i < mEditors.getChildCount(); ++i) { + Editor editor = (Editor) mEditors.getChildAt(i); + if (mType == Id.type.user_id) { + try { + if (((UserIdEditor)editor).getValue().equals("")) //other code ignores empty user id + continue; + } catch (UserIdEditor.InvalidEmailException e) { + } + } + mList.add(editor.needsSaving()); + } + return mList; + } + /** {@inheritDoc} */ public void onClick(View v) { if (canEdit) { -- cgit v1.2.3 From ba62d30563ee5dd316528decd272f1bbdcbee5bd Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Fri, 14 Feb 2014 17:40:11 +0000 Subject: propgate through --- .../keychain/ui/EditKeyActivity.java | 7 +++--- .../keychain/ui/widget/SectionView.java | 29 ++++++++++++++++------ .../keychain/ui/widget/UserIdEditor.java | 7 ++++++ 3 files changed, 33 insertions(+), 10 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 5adb65342..9ebe73197 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -586,9 +586,10 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener getKeysExpiryDates(mKeysView)); data.putLong(KeychainIntentService.SAVE_KEYRING_MASTER_KEY_ID, getMasterKeyId()); data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign); - data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS, ); - data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS, - toPrimitiveArray(mUserIdsView.getNeedsSavingArray())); + data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_DELETED_IDS, + mUserIdsView.getDeletedIDs()); + data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS, + mUserIdsView.getOriginalIDs()); data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_MODDED_KEYS, toPrimitiveArray(mKeysView.getNeedsSavingArray())); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 5eaf54841..788a80a60 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -65,6 +65,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor private int mNewKeySize; private boolean canEdit = true; private boolean oldItemDeleted = false; + private ArrayList mDeletedIDs = new ArrayList(); private ActionBarActivity mActivity; @@ -135,6 +136,8 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor /** {@inheritDoc} */ public void onDeleted(Editor editor, boolean wasNewItem) { oldItemDeleted |= !wasNewItem; + if (oldItemDeleted && mType == Id.type.user_id) + mDeletedIDs.add(((UserIdEditor)editor).getOriginalID()); this.updateEditorsVisible(); if (mEditorListener != null) { mEditorListener.onEdited(); @@ -164,18 +167,30 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor return ret; } + public ArrayList getOriginalIDs() + { + ArrayList orig = new ArrayList(); + if (mType == Id.type.user_id) { + for (int i = 0; i < mEditors.getChildCount(); ++i) { + UserIdEditor editor = (UserIdEditor) mEditors.getChildAt(i); + orig.add(editor.getOriginalID()); + } + return orig; + } else { + return null; + } + } + + public ArrayList getDeletedIDs() + { + return mDeletedIDs; + } + public List getNeedsSavingArray() { ArrayList mList = new ArrayList(); for (int i = 0; i < mEditors.getChildCount(); ++i) { Editor editor = (Editor) mEditors.getChildAt(i); - if (mType == Id.type.user_id) { - try { - if (((UserIdEditor)editor).getValue().equals("")) //other code ignores empty user id - continue; - } catch (UserIdEditor.InvalidEmailException e) { - } - } mList.add(editor.needsSaving()); } return mList; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index b499a429a..37ab0e051 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -40,6 +40,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene private BootstrapButton mDeleteButton; private RadioButton mIsMainUserId; + private String mOriginalID; private EditText mName; private String mOriginalName; private EditText mEmail; @@ -130,6 +131,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene mEmail.setText(""); mOriginalEmail = ""; mIsNewId = isNewId; + mOriginalID = userId; String[] result = PgpKeyHelper.splitUserId(userId); if (result[0] != null) { @@ -226,4 +228,9 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene retval |= mIsNewId; return retval; } + + public String getOriginalID() + { + return mOriginalID; + } } -- cgit v1.2.3 From c9d9c800b609d4bc9ed4b9f20a4085d4ad3f13bc Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 15 Feb 2014 14:45:57 +0000 Subject: pass through deleted keys --- .../sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 2 +- .../keychain/service/KeychainIntentService.java | 5 ++++- .../sufficientlysecure/keychain/ui/EditKeyActivity.java | 3 +++ .../keychain/ui/widget/SectionView.java | 15 +++++++++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 505d3ba55..c57718540 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -198,7 +198,7 @@ public class PgpKeyOperation { } - public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, ArrayList keys, boolean[] modded_keys, String newPassPhrase, ArrayList keysExpiryDates, String oldPassPhrase, ArrayList keysUsages) throws PgpGeneralException, + public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, ArrayList keys, boolean[] modded_keys, ArrayList deleted_keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase) throws PgpGeneralException, PGPException, SignatureException, IOException { Log.d(Constants.TAG, "userIds: " + userIds.toString()); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 4cace2658..5e5735c88 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -137,6 +137,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial public static final String SAVE_KEYRING_ORIGINAL_IDS = "original_ids"; public static final String SAVE_KEYRING_DELETED_IDS = "deleted_ids"; public static final String SAVE_KEYRING_MODDED_KEYS = "modified_keys"; + public static final String SAVE_KEYRING_DELETED_KEYS = "deleted_keys"; // generate key public static final String GENERATE_KEY_ALGORITHM = "algorithm"; @@ -537,6 +538,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial ArrayList original_ids = data.getStringArrayList(SAVE_KEYRING_ORIGINAL_IDS); ArrayList deleted_ids = data.getStringArrayList(SAVE_KEYRING_DELETED_IDS); boolean[] modded_keys = data.getBooleanArray(SAVE_KEYRING_MODDED_KEYS); + ArrayList deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(data + .getByteArray(SAVE_KEYRING_DELETED_KEYS)); long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID); @@ -548,7 +551,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial oldPassPhrase, newPassPhrase); } else { keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, keys, modded_keys, - newPassPhrase, keysExpiryDates, oldPassPhrase, keysUsages); + deletedKeys, keysExpiryDates, keysUsages, newPassPhrase, oldPassPhrase); } PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 9ebe73197..ec7dd1330 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -580,6 +580,9 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener ArrayList keys = getKeys(mKeysView); data.putByteArray(KeychainIntentService.SAVE_KEYRING_KEYS, PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys)); + ArrayList dKeys = mKeysView.getDeletedKeys(); + data.putByteArray(KeychainIntentService.SAVE_KEYRING_DELETED_KEYS, + PgpConversionHelper.PGPSecretKeyArrayListToBytes(dKeys)); data.putIntegerArrayList(KeychainIntentService.SAVE_KEYRING_KEYS_USAGES, getKeysUsages(mKeysView)); data.putSerializable(KeychainIntentService.SAVE_KEYRING_KEYS_EXPIRY_DATES, diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 788a80a60..369288d2c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -66,6 +66,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor private boolean canEdit = true; private boolean oldItemDeleted = false; private ArrayList mDeletedIDs = new ArrayList(); + private ArrayList mDeletedKeys = new ArrayList(); private ActionBarActivity mActivity; @@ -136,8 +137,13 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor /** {@inheritDoc} */ public void onDeleted(Editor editor, boolean wasNewItem) { oldItemDeleted |= !wasNewItem; - if (oldItemDeleted && mType == Id.type.user_id) - mDeletedIDs.add(((UserIdEditor)editor).getOriginalID()); + if (oldItemDeleted) { + if (mType == Id.type.user_id) + mDeletedIDs.add(((UserIdEditor)editor).getOriginalID()); + else if (mType == Id.type.key) + mDeletedKeys.add(((KeyEditor)editor).getValue()); + + } this.updateEditorsVisible(); if (mEditorListener != null) { mEditorListener.onEdited(); @@ -186,6 +192,11 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor return mDeletedIDs; } + public ArrayList getDeletedKeys() + { + return mDeletedKeys; + } + public List getNeedsSavingArray() { ArrayList mList = new ArrayList(); -- cgit v1.2.3 From 034deaacba5cdccf422fbba26d6244c0a4cf2554 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Fri, 21 Feb 2014 15:01:59 +0000 Subject: initial split into two functions --- .../keychain/pgp/PgpKeyOperation.java | 178 ++++++++++++++++++--- 1 file changed, 154 insertions(+), 24 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index c57718540..6055aebfc 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -198,12 +198,158 @@ public class PgpKeyOperation { } - public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, ArrayList keys, boolean[] modded_keys, ArrayList deleted_keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase) throws PgpGeneralException, + private void buildNewSecretKey(ArrayList userIds, ArrayList keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase) throws PgpGeneralException, PGPException, SignatureException, IOException { - Log.d(Constants.TAG, "userIds: " + userIds.toString()); + int usageId = keysUsages.get(0); + boolean canSign; + String mainUserId = userIds.get(0); + + PGPSecretKey masterKey = keys.get(0); + + // this removes all userIds and certifications previously attached to the masterPublicKey + PGPPublicKey masterPublicKey = masterKey.getPublicKey(); + + PGPSecretKeyRing mKR = ProviderHelper.getPGPSecretKeyRingByKeyId(mContext, masterKey.getKeyID()); + + PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( + Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray()); + PGPPrivateKey masterPrivateKey = masterKey.extractPrivateKey(keyDecryptor); + + updateProgress(R.string.progress_certifying_master_key, 20, 100); + int user_id_index = 0; + for (String userId : userIds) { + PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( + masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); + PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); + + sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); + + PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); + masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); + user_id_index++; + } + + PGPKeyPair masterKeyPair = new PGPKeyPair(masterPublicKey, masterPrivateKey); + + PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator(); + PGPSignatureSubpacketGenerator unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); + + hashedPacketsGen.setKeyFlags(true, usageId); + + hashedPacketsGen.setPreferredSymmetricAlgorithms(true, PREFERRED_SYMMETRIC_ALGORITHMS); + hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS); + hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS); + + if (keysExpiryDates.get(0) != null) { + GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + creationDate.setTime(masterPublicKey.getCreationTime()); + GregorianCalendar expiryDate = keysExpiryDates.get(0); + //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c + //here we purposefully ignore partial days in each date - long type has no fractional part! + long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); + if (numDays <= 0) + throw new PgpGeneralException(mContext.getString(R.string.error_expiry_must_come_after_creation)); + hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); + } else { + hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, + //this happens anyway + } + + updateProgress(R.string.progress_building_master_key, 30, 100); + + // define hashing and signing algos + PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get( + HashAlgorithmTags.SHA1); + PGPContentSignerBuilder certificationSignerBuilder = new JcaPGPContentSignerBuilder( + masterKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1); + + // Build key encrypter based on passphrase + PBESecretKeyEncryptor keyEncryptor = new JcePBESecretKeyEncryptorBuilder( + PGPEncryptedData.CAST5, sha1Calc) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( + newPassPhrase.toCharArray()); + + PGPKeyRingGenerator keyGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, + masterKeyPair, mainUserId, sha1Calc, hashedPacketsGen.generate(), + unhashedPacketsGen.generate(), certificationSignerBuilder, keyEncryptor); + + updateProgress(R.string.progress_adding_sub_keys, 40, 100); + + for (int i = 1; i < keys.size(); ++i) { + updateProgress(40 + 50 * (i - 1) / (keys.size() - 1), 100); + + PGPSecretKey subKey = keys.get(i); + PGPPublicKey subPublicKey = subKey.getPublicKey(); + + PBESecretKeyDecryptor keyDecryptor2 = new JcePBESecretKeyDecryptorBuilder() + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( + oldPassPhrase.toCharArray()); + PGPPrivateKey subPrivateKey = subKey.extractPrivateKey(keyDecryptor2); + + // TODO: now used without algorithm and creation time?! (APG 1) + PGPKeyPair subKeyPair = new PGPKeyPair(subPublicKey, subPrivateKey); + + hashedPacketsGen = new PGPSignatureSubpacketGenerator(); + unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); + + usageId = keysUsages.get(i); + canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this + if (canSign) { + Date todayDate = new Date(); //both sig times the same + // cross-certify signing keys + hashedPacketsGen.setSignatureCreationTime(false, todayDate); //set outer creation time + PGPSignatureSubpacketGenerator subHashedPacketsGen = new PGPSignatureSubpacketGenerator(); + subHashedPacketsGen.setSignatureCreationTime(false, todayDate); //set inner creation time + PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( + subPublicKey.getAlgorithm(), PGPUtil.SHA1) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); + PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); + sGen.init(PGPSignature.PRIMARYKEY_BINDING, subPrivateKey); + sGen.setHashedSubpackets(subHashedPacketsGen.generate()); + PGPSignature certification = sGen.generateCertification(masterPublicKey, + subPublicKey); + unhashedPacketsGen.setEmbeddedSignature(false, certification); + } + hashedPacketsGen.setKeyFlags(false, usageId); + + if (keysExpiryDates.get(i) != null) { + GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + creationDate.setTime(subPublicKey.getCreationTime()); + GregorianCalendar expiryDate = keysExpiryDates.get(i); + //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c + //here we purposefully ignore partial days in each date - long type has no fractional part! + long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); + if (numDays <= 0) + throw new PgpGeneralException(mContext.getString(R.string.error_expiry_must_come_after_creation)); + hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); + } else { + hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, + //this happens anyway + } + + keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate()); + } + + PGPSecretKeyRing secretKeyRing = keyGen.generateSecretKeyRing(); + PGPPublicKeyRing publicKeyRing = keyGen.generatePublicKeyRing(); + + updateProgress(R.string.progress_saving_key_ring, 90, 100); + + ProviderHelper.saveKeyRing(mContext, secretKeyRing); + ProviderHelper.saveKeyRing(mContext, publicKeyRing); + + updateProgress(R.string.progress_done, 100, 100); + } + + public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, ArrayList keys, boolean[] modded_keys, ArrayList deleted_keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase) throws PgpGeneralException, + PGPException, SignatureException, IOException { updateProgress(R.string.progress_building_key, 0, 100); + PGPSecretKey masterKey = keys.get(0); + + PGPSecretKeyRing mKR = ProviderHelper.getPGPSecretKeyRingByKeyId(mContext, masterKey.getKeyID()); if (oldPassPhrase == null) { oldPassPhrase = ""; @@ -212,41 +358,25 @@ public class PgpKeyOperation { newPassPhrase = ""; } - updateProgress(R.string.progress_preparing_master_key, 10, 100); + if (mKR == null) + buildNewSecretKey(userIds, keys, keysExpiryDates, keysUsages, newPassPhrase, oldPassPhrase); //new Keyring + + masterKey = mKR.getSecretKey(); + PGPPublicKey masterPublicKey = masterKey.getPublicKey(); int usageId = keysUsages.get(0); boolean canSign; String mainUserId = userIds.get(0); - PGPSecretKey masterKey = keys.get(0); - - // this removes all userIds and certifications previously attached to the masterPublicKey - PGPPublicKey masterPublicKey = masterKey.getPublicKey(); - - // already done by code above: - // PGPPublicKey masterPublicKey = masterKey.getPublicKey(); - // // Somehow, the PGPPublicKey already has an empty certification attached to it when the - // // keyRing is generated the first time, we remove that when it exists, before adding the - // new - // // ones - // PGPPublicKey masterPublicKeyRmCert = PGPPublicKey.removeCertification(masterPublicKey, - // ""); - // if (masterPublicKeyRmCert != null) { - // masterPublicKey = masterPublicKeyRmCert; - // } - - - PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray()); PGPPrivateKey masterPrivateKey = masterKey.extractPrivateKey(keyDecryptor); updateProgress(R.string.progress_certifying_master_key, 20, 100); - // TODO: if we are editing a key, keep old certs, don't remake certs we don't have to. int user_id_index = 0; for (String userId : userIds) { - if (OriginalIDs[user_id_index]) { + if (!OriginalIDs.get(user_id_index).equals(userIds.get(user_id_index))) { PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); -- cgit v1.2.3 From c3c311152ef33a6887909dbbeae40e8d01f96a9d Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Fri, 21 Feb 2014 15:09:49 +0000 Subject: put main original id at the top --- .../java/org/sufficientlysecure/keychain/ui/widget/SectionView.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 369288d2c..2e06f3f34 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -179,7 +179,10 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor if (mType == Id.type.user_id) { for (int i = 0; i < mEditors.getChildCount(); ++i) { UserIdEditor editor = (UserIdEditor) mEditors.getChildAt(i); - orig.add(editor.getOriginalID()); + if (editor.isMainUserId()) + orig.add(0, editor.getOriginalID()); + else + orig.add(editor.getOriginalID()); } return orig; } else { -- cgit v1.2.3 From 1a28a4e9214add62b2b1e23b4579e0a4d585f52e Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 22 Feb 2014 13:54:59 +0000 Subject: change how primary id changing is passed through --- .../sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 4 ++-- .../keychain/service/KeychainIntentService.java | 7 +++++-- .../org/sufficientlysecure/keychain/ui/EditKeyActivity.java | 2 ++ .../sufficientlysecure/keychain/ui/widget/SectionView.java | 13 +++++++++++++ .../sufficientlysecure/keychain/ui/widget/UserIdEditor.java | 7 ++++++- 5 files changed, 28 insertions(+), 5 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 80831d35f..cc9384821 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -343,7 +343,7 @@ public class PgpKeyOperation { updateProgress(R.string.progress_done, 100, 100); } - public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, ArrayList keys, boolean[] modded_keys, ArrayList deleted_keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase) throws PgpGeneralException, + public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, boolean primaryIDChanged, boolean[] modded_keys, ArrayList deleted_keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase, ArrayList keys) throws PgpGeneralException, PGPException, SignatureException, IOException { updateProgress(R.string.progress_building_key, 0, 100); @@ -386,7 +386,7 @@ public class PgpKeyOperation { PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); - masterPublicKey = PGPPublicKey.removeCertification(); + //masterPublicKey = PGPPublicKey.removeCertification(); masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); } user_id_index++; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 9e517b93e..73de7ca6e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -128,6 +128,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial public static final String SAVE_KEYRING_NEW_PASSPHRASE = "new_passphrase"; public static final String SAVE_KEYRING_CURRENT_PASSPHRASE = "current_passphrase"; public static final String SAVE_KEYRING_USER_IDS = "user_ids"; + public static final String SAVE_KEYRING_PRIMARY_ID_CHANGED = "primary_id_changed"; public static final String SAVE_KEYRING_KEYS = "keys"; public static final String SAVE_KEYRING_KEYS_USAGES = "keys_usages"; public static final String SAVE_KEYRING_KEYS_EXPIRY_DATES = "keys_expiry_dates"; @@ -549,6 +550,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial boolean[] modded_keys = data.getBooleanArray(SAVE_KEYRING_MODDED_KEYS); ArrayList deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(data .getByteArray(SAVE_KEYRING_DELETED_KEYS)); + boolean primaryChanged = data.getBoolean(SAVE_KEYRING_PRIMARY_ID_CHANGED); long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID); @@ -559,8 +561,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId), oldPassPhrase, newPassPhrase); } else { - keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, keys, modded_keys, - deletedKeys, keysExpiryDates, keysUsages, newPassPhrase, oldPassPhrase); + keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, primaryChanged, + modded_keys, deletedKeys, keysExpiryDates, keysUsages, newPassPhrase, + oldPassPhrase, keys); } PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index ec7dd1330..09be0dc79 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -595,6 +595,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mUserIdsView.getOriginalIDs()); data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_MODDED_KEYS, toPrimitiveArray(mKeysView.getNeedsSavingArray())); + data.putBoolean(KeychainIntentService.SAVE_KEYRING_PRIMARY_ID_CHANGED, + mUserIdsView.primaryChanged()); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 2e06f3f34..014a891a5 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -169,6 +169,19 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor for (int i = 0; i < mEditors.getChildCount(); ++i) { Editor editor = (Editor) mEditors.getChildAt(i); ret |= editor.needsSaving(); + if (mType == Id.type.user_id) + ret |= ((UserIdEditor)editor).primarySwapped(); + } + return ret; + } + + public boolean primaryChanged() + { + boolean ret = false; + for (int i = 0; i < mEditors.getChildCount(); ++i) { + Editor editor = (Editor) mEditors.getChildAt(i); + if (mType == Id.type.user_id) + ret |= ((UserIdEditor)editor).primarySwapped(); } return ret; } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index 37ab0e051..5098c8713 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -221,7 +221,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene @Override public boolean needsSaving() { - boolean retval = (mOriginallyMainUserID != isMainUserId()); + boolean retval = false; //(mOriginallyMainUserID != isMainUserId()); retval |= !(mOriginalName.equals( ("" + mName.getText()).trim() ) ); retval |= !(mOriginalEmail.equals( ("" + mEmail.getText()).trim() ) ); retval |= !(mOriginalComment.equals( ("" + mComment.getText()).trim() ) ); @@ -229,6 +229,11 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene return retval; } + public boolean primarySwapped() + { + return (mOriginallyMainUserID != isMainUserId()); + } + public String getOriginalID() { return mOriginalID; -- cgit v1.2.3 From a39c73ca12dabba01412083afbf0b58dfb42a79e Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 22 Feb 2014 15:29:19 +0000 Subject: first go at saving IDs correctly --- .../keychain/pgp/PgpKeyOperation.java | 78 ++++++++++++++++++---- 1 file changed, 64 insertions(+), 14 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index cc9384821..f3b289f66 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -28,6 +28,7 @@ import java.security.SignatureException; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Iterator; import java.util.TimeZone; import org.spongycastle.bcpg.CompressionAlgorithmTags; @@ -68,6 +69,7 @@ import org.sufficientlysecure.keychain.util.Primes; import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import android.content.Context; +import android.util.Pair; public class PgpKeyOperation { private final Context mContext; @@ -361,6 +363,21 @@ public class PgpKeyOperation { if (mKR == null) buildNewSecretKey(userIds, keys, keysExpiryDates, keysUsages, newPassPhrase, oldPassPhrase); //new Keyring + /* + IDs - + remove deleted ids + if the primary ID changed we need to: + remove all of the IDs from the keyring, saving their certifications + add them all in again, updating certs of IDs which have changed + else + remove changed IDs and add in with new certs + + Keys + remove deleted keys + if a key is modified, re-sign it + do we need to remove and add in? + */ + masterKey = mKR.getSecretKey(); PGPPublicKey masterPublicKey = masterKey.getPublicKey(); @@ -374,22 +391,55 @@ public class PgpKeyOperation { updateProgress(R.string.progress_certifying_master_key, 20, 100); - int user_id_index = 0; - for (String userId : userIds) { - if (!OriginalIDs.get(user_id_index).equals(userIds.get(user_id_index))) { - PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( - masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) - .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); - PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); - - sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); - - PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); + for (String delID : deletedIDs) { + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, delID); + } - //masterPublicKey = PGPPublicKey.removeCertification(); - masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); + int user_id_index = 0; + if (primaryIDChanged) { + ArrayList> sigList = new ArrayList>(); + for (String userId : userIds) { + String orig_id = OriginalIDs.get(user_id_index); + if (orig_id.equals(userId)) { + Iterator orig_sigs = masterPublicKey.getSignaturesForID(orig_id); //TODO: make sure this iterator only has signatures we are interested in + while (orig_sigs.hasNext()) { + PGPSignature orig_sig = orig_sigs.next(); + sigList.add(new Pair(orig_id, orig_sig)); + } + } else { + PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( + masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); + PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); + + sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); + + PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); + sigList.add(new Pair(userId, certification)); + } + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, orig_id); + user_id_index++; + } + for (Pair to_add : sigList) { + masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, to_add.first, to_add.second); + } + } else { + for (String userId : userIds) { + String orig_id = OriginalIDs.get(user_id_index); + if (!orig_id.equals(userId)) { + PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( + masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); + PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); + + sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); + + PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, orig_id); + masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); + } + user_id_index++; } - user_id_index++; } PGPKeyPair masterKeyPair = new PGPKeyPair(masterPublicKey, masterPrivateKey); -- cgit v1.2.3 From fab74590eb0984e055f98ccf3af4390d3e3c0c15 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 22 Feb 2014 15:41:15 +0000 Subject: remove deleted keys --- .../java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index f3b289f66..ab4408056 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -378,6 +378,10 @@ public class PgpKeyOperation { do we need to remove and add in? */ + for (PGPSecretKey dKey : deleted_keys) { + mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey); + } + masterKey = mKR.getSecretKey(); PGPPublicKey masterPublicKey = masterKey.getPublicKey(); -- cgit v1.2.3 From fa533dda325b5d56db16dee2f84152ec4807a2b2 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 22 Feb 2014 16:08:38 +0000 Subject: pass through which keys are new --- .../org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 9 +++++++-- .../keychain/service/KeychainIntentService.java | 4 +++- .../org/sufficientlysecure/keychain/ui/EditKeyActivity.java | 2 ++ .../org/sufficientlysecure/keychain/ui/widget/KeyEditor.java | 5 +++++ .../sufficientlysecure/keychain/ui/widget/SectionView.java | 12 ++++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index ab4408056..a6ff60442 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -345,7 +345,7 @@ public class PgpKeyOperation { updateProgress(R.string.progress_done, 100, 100); } - public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, boolean primaryIDChanged, boolean[] modded_keys, ArrayList deleted_keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase, ArrayList keys) throws PgpGeneralException, + public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, boolean primaryIDChanged, boolean[] modded_keys, ArrayList deleted_keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase, boolean[] new_keys, ArrayList keys) throws PgpGeneralException, PGPException, SignatureException, IOException { updateProgress(R.string.progress_building_key, 0, 100); @@ -490,6 +490,11 @@ public class PgpKeyOperation { masterKeyPair, mainUserId, sha1Calc, hashedPacketsGen.generate(), unhashedPacketsGen.generate(), certificationSignerBuilder, keyEncryptor); + //updating master is slightly different to updating the others + if (modded_keys[0]) { + + } + updateProgress(R.string.progress_adding_sub_keys, 40, 100); for (int i = 1; i < keys.size(); ++i) { @@ -549,7 +554,7 @@ public class PgpKeyOperation { PGPSecretKeyRing secretKeyRing = keyGen.generateSecretKeyRing(); PGPPublicKeyRing publicKeyRing = keyGen.generatePublicKeyRing(); - +//must copy with new passphrase... new keys will have an empty passphrase... pass in boolean array to mark new key? updateProgress(R.string.progress_saving_key_ring, 90, 100); ProviderHelper.saveKeyRing(mContext, secretKeyRing); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 73de7ca6e..3610ddc9e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -138,6 +138,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial public static final String SAVE_KEYRING_DELETED_IDS = "deleted_ids"; public static final String SAVE_KEYRING_MODDED_KEYS = "modified_keys"; public static final String SAVE_KEYRING_DELETED_KEYS = "deleted_keys"; + public static final String SAVE_KEYRING_NEW_KEYS = "new_keys"; // generate key public static final String GENERATE_KEY_ALGORITHM = "algorithm"; @@ -548,6 +549,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial ArrayList original_ids = data.getStringArrayList(SAVE_KEYRING_ORIGINAL_IDS); ArrayList deleted_ids = data.getStringArrayList(SAVE_KEYRING_DELETED_IDS); boolean[] modded_keys = data.getBooleanArray(SAVE_KEYRING_MODDED_KEYS); + boolean[] new_keys = data.getBooleanArray(SAVE_KEYRING_NEW_KEYS); ArrayList deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(data .getByteArray(SAVE_KEYRING_DELETED_KEYS)); boolean primaryChanged = data.getBoolean(SAVE_KEYRING_PRIMARY_ID_CHANGED); @@ -563,7 +565,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial } else { keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, primaryChanged, modded_keys, deletedKeys, keysExpiryDates, keysUsages, newPassPhrase, - oldPassPhrase, keys); + oldPassPhrase, new_keys, keys); } PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 09be0dc79..bb38ac979 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -597,6 +597,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener toPrimitiveArray(mKeysView.getNeedsSavingArray())); data.putBoolean(KeychainIntentService.SAVE_KEYRING_PRIMARY_ID_CHANGED, mUserIdsView.primaryChanged()); + data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_NEW_KEYS, + toPrimitiveArray(mKeysView.getNewKeysArray())); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 5ce5d89d7..68bfc573e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -314,4 +314,9 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { return retval; } + public boolean getIsNewKey() + { + return mIsNewKey; + } + } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 014a891a5..93c10a2b0 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -223,6 +223,18 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor return mList; } + public List getNewKeysArray() + { + ArrayList mList = new ArrayList(); + if (mType == Id.type.key) { + for (int i = 0; i < mEditors.getChildCount(); ++i) { + KeyEditor editor = (KeyEditor) mEditors.getChildAt(i); + mList.add(editor.getIsNewKey()); + } + } + return mList; + } + /** {@inheritDoc} */ public void onClick(View v) { if (canEdit) { -- cgit v1.2.3 From d6b0975f9b666dc30edab36e6f2c68c0022790d1 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sun, 2 Mar 2014 20:34:28 +0000 Subject: begin adding parcel for save intent --- .../keychain/pgp/PgpKeyOperation.java | 10 ++- .../keychain/service/SaveKeyringParcel.java | 90 ++++++++++++++++++++++ 2 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index a6ff60442..a52f247c6 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; import java.util.Iterator; +import java.util.List; import java.util.TimeZone; import org.spongycastle.bcpg.CompressionAlgorithmTags; @@ -490,11 +491,14 @@ public class PgpKeyOperation { masterKeyPair, mainUserId, sha1Calc, hashedPacketsGen.generate(), unhashedPacketsGen.generate(), certificationSignerBuilder, keyEncryptor); - //updating master is slightly different to updating the others - if (modded_keys[0]) { + for (int i = 0; i < keys.size(); ++i) { + updateProgress(40 + 50 * (i - 1) / (keys.size() - 1), 100); + if (new_keys[i]) { - } + } else { + } + } updateProgress(R.string.progress_adding_sub_keys, 40, 100); for (int i = 1; i < keys.size(); ++i) { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java new file mode 100644 index 000000000..bdabc70a2 --- /dev/null +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2014 Ash Hughes + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +package org.sufficientlysecure.keychain.service; + +import android.os.Parcel; +import android.os.Parcelable; + +import org.spongycastle.openpgp.PGPSecretKey; +import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; + +import java.util.ArrayList; +import java.util.GregorianCalendar; + +public class SaveKeyringParcel implements Parcelable { + + public ArrayList userIDs; + public ArrayList originalIDs; + public ArrayList deletedIDs; + public boolean primaryIDChanged; + public boolean[] moddedKeys; + public ArrayList deletedKeys; + public ArrayList keysExpiryDates; + public ArrayList keysUsages; + public String newPassPhrase; + public String oldPassPhrase; + public boolean[] newKeys; + public ArrayList keys; + + private SaveKeyringParcel(Parcel source) + { + byte[] tmpB; + userIDs = (ArrayList)source.readSerializable(); + originalIDs = (ArrayList)source.readSerializable(); + deletedIDs = (ArrayList)source.readSerializable(); + primaryIDChanged = source.readByte() != 0; + source.readBooleanArray(moddedKeys); + deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray()); + keysExpiryDates = (ArrayList)source.readSerializable(); + keysUsages = source.readArrayList(Integer.class.getClassLoader()); + } + + @Override + public void writeToParcel(Parcel destination, int flags) + { + destination.writeSerializable(userIDs); + destination.writeSerializable(originalIDs); + destination.writeSerializable(deletedIDs); + destination.writeByte((byte) (primaryIDChanged ? 1 : 0)); + destination.writeBooleanArray(moddedKeys); + destination.writeByteArray(PgpConversionHelper.PGPSecretKeyArrayListToBytes(deletedKeys)); + destination.writeSerializable(keysExpiryDates); + destination.writeList(keysUsages); + destination.writeString(newPassPhrase); + destination.writeString(oldPassPhrase); + destination.writeBooleanArray(newKeys); + destination.writeByteArray(); + } + + public static final Creator CREATOR = new Creator() { + public SaveKeyringParcel createFromParcel(final Parcel source) { + return new SaveKeyringParcel(source); + } + + public SaveKeyringParcel[] newArray(final int size) { + return new SaveKeyringParcel[size]; + } + }; + + @Override + public int describeContents() + { + return 0; + } +} -- cgit v1.2.3 From 8662ca2928ac0b007d4ee5d00f6de3211f5d3d2c Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Mar 2014 12:25:35 +0000 Subject: a method, if not the best one, for each property --- .../sufficientlysecure/keychain/service/SaveKeyringParcel.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java index bdabc70a2..9e290c1b6 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -53,12 +53,16 @@ public class SaveKeyringParcel implements Parcelable { deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray()); keysExpiryDates = (ArrayList)source.readSerializable(); keysUsages = source.readArrayList(Integer.class.getClassLoader()); + newPassPhrase = source.readString(); + oldPassPhrase = source.readString(); + source.readBooleanArray(newKeys); + keys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray()); } @Override public void writeToParcel(Parcel destination, int flags) { - destination.writeSerializable(userIDs); + destination.writeSerializable(userIDs); //might not be the best method to store. destination.writeSerializable(originalIDs); destination.writeSerializable(deletedIDs); destination.writeByte((byte) (primaryIDChanged ? 1 : 0)); @@ -69,7 +73,7 @@ public class SaveKeyringParcel implements Parcelable { destination.writeString(newPassPhrase); destination.writeString(oldPassPhrase); destination.writeBooleanArray(newKeys); - destination.writeByteArray(); + destination.writeByteArray(PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys)); } public static final Creator CREATOR = new Creator() { -- cgit v1.2.3 From 01951810ae1b3a0e4fefab7d55c090fc8f776ce5 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Mar 2014 13:00:17 +0000 Subject: fix saving new key (tmp) --- .../java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 4 +++- .../sufficientlysecure/keychain/service/KeychainIntentService.java | 7 ++++++- .../java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index a52f247c6..66665df3c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -361,8 +361,10 @@ public class PgpKeyOperation { newPassPhrase = ""; } - if (mKR == null) + if (mKR == null) { buildNewSecretKey(userIds, keys, keysExpiryDates, keysUsages, newPassPhrase, oldPassPhrase); //new Keyring + return; + } /* IDs - diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 3610ddc9e..9d6e24d30 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -550,8 +550,13 @@ public class KeychainIntentService extends IntentService implements ProgressDial ArrayList deleted_ids = data.getStringArrayList(SAVE_KEYRING_DELETED_IDS); boolean[] modded_keys = data.getBooleanArray(SAVE_KEYRING_MODDED_KEYS); boolean[] new_keys = data.getBooleanArray(SAVE_KEYRING_NEW_KEYS); - ArrayList deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(data + byte[] tmp = data.getByteArray(SAVE_KEYRING_DELETED_KEYS); + ArrayList deletedKeys; + if (tmp != null) + deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(data .getByteArray(SAVE_KEYRING_DELETED_KEYS)); + else + deletedKeys = new ArrayList(); boolean primaryChanged = data.getBoolean(SAVE_KEYRING_PRIMARY_ID_CHANGED); long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index bb38ac979..044d15ec7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -581,8 +581,11 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener data.putByteArray(KeychainIntentService.SAVE_KEYRING_KEYS, PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys)); ArrayList dKeys = mKeysView.getDeletedKeys(); + byte[] tmp = null; + if (dKeys.size() != 0) + tmp = PgpConversionHelper.PGPSecretKeyArrayListToBytes(dKeys); data.putByteArray(KeychainIntentService.SAVE_KEYRING_DELETED_KEYS, - PgpConversionHelper.PGPSecretKeyArrayListToBytes(dKeys)); + tmp); data.putIntegerArrayList(KeychainIntentService.SAVE_KEYRING_KEYS_USAGES, getKeysUsages(mKeysView)); data.putSerializable(KeychainIntentService.SAVE_KEYRING_KEYS_EXPIRY_DATES, -- cgit v1.2.3 From 04fa0e9cc7fbfc117948d60a3ad8bfab0b0060ba Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 6 Mar 2014 23:47:11 +0000 Subject: use parcel to save keys, but saving existing keys is disabled, pending a rewrite... --- .../keychain/pgp/PgpKeyOperation.java | 18 +++++---- .../keychain/service/KeychainIntentService.java | 45 ++++----------------- .../keychain/service/SaveKeyringParcel.java | 18 ++++++--- .../keychain/ui/EditKeyActivity.java | 46 ++++++++-------------- 4 files changed, 49 insertions(+), 78 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 66665df3c..0073107a0 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -65,6 +65,7 @@ import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Primes; import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; @@ -346,23 +347,24 @@ public class PgpKeyOperation { updateProgress(R.string.progress_done, 100, 100); } - public void buildSecretKey(ArrayList userIds, ArrayList OriginalIDs, ArrayList deletedIDs, boolean primaryIDChanged, boolean[] modded_keys, ArrayList deleted_keys, ArrayList keysExpiryDates, ArrayList keysUsages, String newPassPhrase, String oldPassPhrase, boolean[] new_keys, ArrayList keys) throws PgpGeneralException, + public void buildSecretKey(SaveKeyringParcel saveParcel) throws PgpGeneralException, PGPException, SignatureException, IOException { updateProgress(R.string.progress_building_key, 0, 100); - PGPSecretKey masterKey = keys.get(0); + PGPSecretKey masterKey = saveParcel.keys.get(0); PGPSecretKeyRing mKR = ProviderHelper.getPGPSecretKeyRingByKeyId(mContext, masterKey.getKeyID()); - if (oldPassPhrase == null) { - oldPassPhrase = ""; + if (saveParcel.oldPassPhrase == null) { + saveParcel.oldPassPhrase = ""; } - if (newPassPhrase == null) { - newPassPhrase = ""; + if (saveParcel.newPassPhrase == null) { + saveParcel.newPassPhrase = ""; } if (mKR == null) { - buildNewSecretKey(userIds, keys, keysExpiryDates, keysUsages, newPassPhrase, oldPassPhrase); //new Keyring + buildNewSecretKey(saveParcel.userIDs, saveParcel.keys, saveParcel.keysExpiryDates, + saveParcel.keysUsages, saveParcel.newPassPhrase, saveParcel.oldPassPhrase); //new Keyring return; } @@ -381,6 +383,7 @@ public class PgpKeyOperation { do we need to remove and add in? */ + /* for (PGPSecretKey dKey : deleted_keys) { mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey); } @@ -567,6 +570,7 @@ public class PgpKeyOperation { ProviderHelper.saveKeyRing(mContext, publicKeyRing); updateProgress(R.string.progress_done, 100, 100); + */ } public PGPPublicKeyRing certifyKey(long masterKeyId, long pubKeyId, String passphrase) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 9d6e24d30..24bce8eeb 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -125,20 +125,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial public static final String DECRYPT_ASSUME_SYMMETRIC = "assume_symmetric"; // save keyring - public static final String SAVE_KEYRING_NEW_PASSPHRASE = "new_passphrase"; - public static final String SAVE_KEYRING_CURRENT_PASSPHRASE = "current_passphrase"; - public static final String SAVE_KEYRING_USER_IDS = "user_ids"; - public static final String SAVE_KEYRING_PRIMARY_ID_CHANGED = "primary_id_changed"; - public static final String SAVE_KEYRING_KEYS = "keys"; - public static final String SAVE_KEYRING_KEYS_USAGES = "keys_usages"; - public static final String SAVE_KEYRING_KEYS_EXPIRY_DATES = "keys_expiry_dates"; - public static final String SAVE_KEYRING_MASTER_KEY_ID = "master_key_id"; + public static final String SAVE_KEYRING_PARCEL = "save_parcel"; public static final String SAVE_KEYRING_CAN_SIGN = "can_sign"; - public static final String SAVE_KEYRING_ORIGINAL_IDS = "original_ids"; - public static final String SAVE_KEYRING_DELETED_IDS = "deleted_ids"; - public static final String SAVE_KEYRING_MODDED_KEYS = "modified_keys"; - public static final String SAVE_KEYRING_DELETED_KEYS = "deleted_keys"; - public static final String SAVE_KEYRING_NEW_KEYS = "new_keys"; + // generate key public static final String GENERATE_KEY_ALGORITHM = "algorithm"; @@ -530,8 +519,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial } else if (ACTION_SAVE_KEYRING.equals(action)) { try { /* Input */ - String oldPassPhrase = data.getString(SAVE_KEYRING_CURRENT_PASSPHRASE); - String newPassPhrase = data.getString(SAVE_KEYRING_NEW_PASSPHRASE); + SaveKeyringParcel saveParams = data.getParcelable(SAVE_KEYRING_PARCEL); + String oldPassPhrase = saveParams.oldPassPhrase; + String newPassPhrase = saveParams.newPassPhrase; boolean canSign = true; if (data.containsKey(SAVE_KEYRING_CAN_SIGN)) { @@ -541,25 +531,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial if (newPassPhrase == null) { newPassPhrase = oldPassPhrase; } - ArrayList userIds = data.getStringArrayList(SAVE_KEYRING_USER_IDS); - ArrayList keys = PgpConversionHelper.BytesToPGPSecretKeyList(data - .getByteArray(SAVE_KEYRING_KEYS)); - ArrayList keysUsages = data.getIntegerArrayList(SAVE_KEYRING_KEYS_USAGES); - ArrayList keysExpiryDates = (ArrayList) data.getSerializable(SAVE_KEYRING_KEYS_EXPIRY_DATES); - ArrayList original_ids = data.getStringArrayList(SAVE_KEYRING_ORIGINAL_IDS); - ArrayList deleted_ids = data.getStringArrayList(SAVE_KEYRING_DELETED_IDS); - boolean[] modded_keys = data.getBooleanArray(SAVE_KEYRING_MODDED_KEYS); - boolean[] new_keys = data.getBooleanArray(SAVE_KEYRING_NEW_KEYS); - byte[] tmp = data.getByteArray(SAVE_KEYRING_DELETED_KEYS); - ArrayList deletedKeys; - if (tmp != null) - deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(data - .getByteArray(SAVE_KEYRING_DELETED_KEYS)); - else - deletedKeys = new ArrayList(); - boolean primaryChanged = data.getBoolean(SAVE_KEYRING_PRIMARY_ID_CHANGED); - - long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID); + + long masterKeyId = saveParams.keys.get(0).getKeyID(); PgpKeyOperation keyOperations = new PgpKeyOperation(this, this); /* Operation */ @@ -568,9 +541,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId), oldPassPhrase, newPassPhrase); } else { - keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, primaryChanged, - modded_keys, deletedKeys, keysExpiryDates, keysUsages, newPassPhrase, - oldPassPhrase, new_keys, keys); + keyOperations.buildSecretKey(saveParams); } PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java index 9e290c1b6..ae481aa80 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -42,20 +42,25 @@ public class SaveKeyringParcel implements Parcelable { public boolean[] newKeys; public ArrayList keys; + public SaveKeyringParcel() {} + private SaveKeyringParcel(Parcel source) { - byte[] tmpB; userIDs = (ArrayList)source.readSerializable(); originalIDs = (ArrayList)source.readSerializable(); deletedIDs = (ArrayList)source.readSerializable(); primaryIDChanged = source.readByte() != 0; - source.readBooleanArray(moddedKeys); - deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray()); + moddedKeys = source.createBooleanArray(); + byte[] tmp = source.createByteArray(); + if (tmp == null) + deletedKeys = null; + else + deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(tmp); keysExpiryDates = (ArrayList)source.readSerializable(); keysUsages = source.readArrayList(Integer.class.getClassLoader()); newPassPhrase = source.readString(); oldPassPhrase = source.readString(); - source.readBooleanArray(newKeys); + newKeys = source.createBooleanArray(); keys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray()); } @@ -67,7 +72,10 @@ public class SaveKeyringParcel implements Parcelable { destination.writeSerializable(deletedIDs); destination.writeByte((byte) (primaryIDChanged ? 1 : 0)); destination.writeBooleanArray(moddedKeys); - destination.writeByteArray(PgpConversionHelper.PGPSecretKeyArrayListToBytes(deletedKeys)); + byte[] tmp = null; + if (deletedKeys.size() != 0) + tmp = PgpConversionHelper.PGPSecretKeyArrayListToBytes(deletedKeys); + destination.writeByteArray(tmp); destination.writeSerializable(keysExpiryDates); destination.writeList(keysUsages); destination.writeString(newPassPhrase); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 044d15ec7..6ce2a8f6b 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -36,6 +36,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.PassphraseCacheService; +import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment; @@ -570,38 +571,25 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING); + SaveKeyringParcel saveParams = new SaveKeyringParcel(); + saveParams.userIDs = getUserIds(mUserIdsView); + saveParams.originalIDs = mUserIdsView.getOriginalIDs(); + saveParams.deletedIDs = mUserIdsView.getDeletedIDs(); + saveParams.primaryIDChanged = mUserIdsView.primaryChanged(); + saveParams.moddedKeys = toPrimitiveArray(mKeysView.getNeedsSavingArray()); + saveParams.deletedKeys = mKeysView.getDeletedKeys(); + saveParams.keysExpiryDates = getKeysExpiryDates(mKeysView); + saveParams.keysUsages = getKeysUsages(mKeysView); + saveParams.newPassPhrase = mNewPassPhrase; + saveParams.oldPassPhrase = mCurrentPassPhrase; + saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray()); + saveParams.keys = getKeys(mKeysView); + + // fill values for this action Bundle data = new Bundle(); - data.putString(KeychainIntentService.SAVE_KEYRING_CURRENT_PASSPHRASE, - mCurrentPassPhrase); - data.putString(KeychainIntentService.SAVE_KEYRING_NEW_PASSPHRASE, mNewPassPhrase); - data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_USER_IDS, - getUserIds(mUserIdsView)); - ArrayList keys = getKeys(mKeysView); - data.putByteArray(KeychainIntentService.SAVE_KEYRING_KEYS, - PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys)); - ArrayList dKeys = mKeysView.getDeletedKeys(); - byte[] tmp = null; - if (dKeys.size() != 0) - tmp = PgpConversionHelper.PGPSecretKeyArrayListToBytes(dKeys); - data.putByteArray(KeychainIntentService.SAVE_KEYRING_DELETED_KEYS, - tmp); - data.putIntegerArrayList(KeychainIntentService.SAVE_KEYRING_KEYS_USAGES, - getKeysUsages(mKeysView)); - data.putSerializable(KeychainIntentService.SAVE_KEYRING_KEYS_EXPIRY_DATES, - getKeysExpiryDates(mKeysView)); - data.putLong(KeychainIntentService.SAVE_KEYRING_MASTER_KEY_ID, getMasterKeyId()); data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign); - data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_DELETED_IDS, - mUserIdsView.getDeletedIDs()); - data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS, - mUserIdsView.getOriginalIDs()); - data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_MODDED_KEYS, - toPrimitiveArray(mKeysView.getNeedsSavingArray())); - data.putBoolean(KeychainIntentService.SAVE_KEYRING_PRIMARY_ID_CHANGED, - mUserIdsView.primaryChanged()); - data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_NEW_KEYS, - toPrimitiveArray(mKeysView.getNewKeysArray())); + data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, saveParams); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); -- cgit v1.2.3 From b06e4d827a65838cc7085040ea465c1163f1cdd9 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Fri, 7 Mar 2014 15:36:01 +0000 Subject: uncomment, use Parcel. Builds, not functional --- .../keychain/pgp/PgpKeyOperation.java | 48 +++++++++++----------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index f744fbcec..87f8fdebb 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -383,33 +383,32 @@ public class PgpKeyOperation { do we need to remove and add in? */ - /* - for (PGPSecretKey dKey : deleted_keys) { + for (PGPSecretKey dKey : saveParcel.deletedKeys) { mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey); } masterKey = mKR.getSecretKey(); PGPPublicKey masterPublicKey = masterKey.getPublicKey(); - int usageId = keysUsages.get(0); + int usageId = saveParcel.keysUsages.get(0); boolean canSign; - String mainUserId = userIds.get(0); + String mainUserId = saveParcel.userIDs.get(0); PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( - Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray()); + Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(saveParcel.oldPassPhrase.toCharArray()); PGPPrivateKey masterPrivateKey = masterKey.extractPrivateKey(keyDecryptor); updateProgress(R.string.progress_certifying_master_key, 20, 100); - for (String delID : deletedIDs) { + for (String delID : saveParcel.deletedIDs) { masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, delID); } int user_id_index = 0; - if (primaryIDChanged) { + if (saveParcel.primaryIDChanged) { ArrayList> sigList = new ArrayList>(); - for (String userId : userIds) { - String orig_id = OriginalIDs.get(user_id_index); + for (String userId : saveParcel.userIDs) { + String orig_id = saveParcel.originalIDs.get(user_id_index); if (orig_id.equals(userId)) { Iterator orig_sigs = masterPublicKey.getSignaturesForID(orig_id); //TODO: make sure this iterator only has signatures we are interested in while (orig_sigs.hasNext()) { @@ -434,8 +433,8 @@ public class PgpKeyOperation { masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, to_add.first, to_add.second); } } else { - for (String userId : userIds) { - String orig_id = OriginalIDs.get(user_id_index); + for (String userId : saveParcel.userIDs) { + String orig_id = saveParcel.originalIDs.get(user_id_index); if (!orig_id.equals(userId)) { PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) @@ -463,10 +462,10 @@ public class PgpKeyOperation { hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS); hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS); - if (keysExpiryDates.get(0) != null) { + if (saveParcel.keysExpiryDates.get(0) != null) { GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); creationDate.setTime(masterPublicKey.getCreationTime()); - GregorianCalendar expiryDate = keysExpiryDates.get(0); + GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(0); //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c //here we purposefully ignore partial days in each date - long type has no fractional part! long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); @@ -490,15 +489,15 @@ public class PgpKeyOperation { PBESecretKeyEncryptor keyEncryptor = new JcePBESecretKeyEncryptorBuilder( PGPEncryptedData.CAST5, sha1Calc) .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( - newPassPhrase.toCharArray()); + saveParcel.newPassPhrase.toCharArray()); PGPKeyRingGenerator keyGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, masterKeyPair, mainUserId, sha1Calc, hashedPacketsGen.generate(), unhashedPacketsGen.generate(), certificationSignerBuilder, keyEncryptor); - for (int i = 0; i < keys.size(); ++i) { - updateProgress(40 + 50 * (i - 1) / (keys.size() - 1), 100); - if (new_keys[i]) { + for (int i = 0; i < saveParcel.keys.size(); ++i) { + updateProgress(40 + 50 * (i - 1) / (saveParcel.keys.size() - 1), 100); + if (saveParcel.newKeys[i]) { } else { @@ -506,15 +505,15 @@ public class PgpKeyOperation { } updateProgress(R.string.progress_adding_sub_keys, 40, 100); - for (int i = 1; i < keys.size(); ++i) { - updateProgress(40 + 50 * (i - 1) / (keys.size() - 1), 100); + for (int i = 1; i < saveParcel.keys.size(); ++i) { + updateProgress(40 + 50 * (i - 1) / (saveParcel.keys.size() - 1), 100); - PGPSecretKey subKey = keys.get(i); + PGPSecretKey subKey = saveParcel.keys.get(i); PGPPublicKey subPublicKey = subKey.getPublicKey(); PBESecretKeyDecryptor keyDecryptor2 = new JcePBESecretKeyDecryptorBuilder() .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( - oldPassPhrase.toCharArray()); + saveParcel.oldPassPhrase.toCharArray()); PGPPrivateKey subPrivateKey = subKey.extractPrivateKey(keyDecryptor2); // TODO: now used without algorithm and creation time?! (APG 1) @@ -523,7 +522,7 @@ public class PgpKeyOperation { hashedPacketsGen = new PGPSignatureSubpacketGenerator(); unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); - usageId = keysUsages.get(i); + usageId = saveParcel.keysUsages.get(i); canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this if (canSign) { Date todayDate = new Date(); //both sig times the same @@ -543,10 +542,10 @@ public class PgpKeyOperation { } hashedPacketsGen.setKeyFlags(false, usageId); - if (keysExpiryDates.get(i) != null) { + if (saveParcel.keysExpiryDates.get(i) != null) { GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); creationDate.setTime(subPublicKey.getCreationTime()); - GregorianCalendar expiryDate = keysExpiryDates.get(i); + GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(i); //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c //here we purposefully ignore partial days in each date - long type has no fractional part! long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); @@ -570,7 +569,6 @@ public class PgpKeyOperation { ProviderHelper.saveKeyRing(mContext, publicKeyRing); updateProgress(R.string.progress_done, 100, 100); - */ } public PGPPublicKeyRing certifyKey(long masterKeyId, long pubKeyId, String passphrase) -- cgit v1.2.3 From 6f0a5d39b2931981fb521f533acb5c2c33514734 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Mon, 10 Mar 2014 23:53:28 +0000 Subject: start modifying save code --- .../keychain/pgp/PgpKeyOperation.java | 34 +++++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 87f8fdebb..89be90ab8 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -73,6 +73,8 @@ import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import android.content.Context; import android.util.Pair; +import javax.crypto.SecretKey; + public class PgpKeyOperation { private final Context mContext; private final ProgressDialogUpdater mProgress; @@ -354,6 +356,7 @@ public class PgpKeyOperation { PGPSecretKey masterKey = saveParcel.keys.get(0); PGPSecretKeyRing mKR = ProviderHelper.getPGPSecretKeyRingByKeyId(mContext, masterKey.getKeyID()); + PGPPublicKeyRing pKR = ProviderHelper.getPGPPublicKeyRingByKeyId(mContext, masterKey.getKeyID()); if (saveParcel.oldPassPhrase == null) { saveParcel.oldPassPhrase = ""; @@ -497,11 +500,27 @@ public class PgpKeyOperation { for (int i = 0; i < saveParcel.keys.size(); ++i) { updateProgress(40 + 50 * (i - 1) / (saveParcel.keys.size() - 1), 100); - if (saveParcel.newKeys[i]) { - + if (saveParcel.moddedKeys[i]) { +//secretkey.replacepublickey with updated public key +//secretkeyring.insertsecretkey with newly signed secret key } else { - +//else nothing, right? + } + if (saveParcel.newKeys[i]) { + //set the passphrase to the old one, so we can update the whole keyring passphrase later + PBESecretKeyEncryptor keyEncryptorOld = new JcePBESecretKeyEncryptorBuilder( + PGPEncryptedData.CAST5, sha1Calc) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( + saveParcel.oldPassPhrase.toCharArray()); + PBESecretKeyDecryptor keyDecryptorBlank = new JcePBESecretKeyDecryptorBuilder() + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( + saveParcel.oldPassPhrase.toCharArray()); + saveParcel.keys.set(i, PGPSecretKey.copyWithNewPassword(saveParcel.keys.get(i), + keyDecryptorBlank, keyEncryptorOld)); } + //finally, update the keyrings + mKR = PGPSecretKeyRing.insertSecretKey(mKR, saveParcel.keys.get(i)); + pKR = PGPPublicKeyRing.insertPublicKey(pKR, saveParcel.keys.get(i).getPublicKey()); } updateProgress(R.string.progress_adding_sub_keys, 40, 100); @@ -560,13 +579,12 @@ public class PgpKeyOperation { keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate()); } - PGPSecretKeyRing secretKeyRing = keyGen.generateSecretKeyRing(); - PGPPublicKeyRing publicKeyRing = keyGen.generatePublicKeyRing(); -//must copy with new passphrase... new keys will have an empty passphrase... pass in boolean array to mark new key? + //update the passphrase + mKR = PGPSecretKeyRing.copyWithNewPassword(mKR, keyDecryptor, keyEncryptor); updateProgress(R.string.progress_saving_key_ring, 90, 100); - ProviderHelper.saveKeyRing(mContext, secretKeyRing); - ProviderHelper.saveKeyRing(mContext, publicKeyRing); + ProviderHelper.saveKeyRing(mContext, mKR); + ProviderHelper.saveKeyRing(mContext, pKR); updateProgress(R.string.progress_done, 100, 100); } -- cgit v1.2.3 From fdb013a0529e4fcf3b602f856c0290f5626789aa Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 11 Mar 2014 00:00:19 +0000 Subject: unused imports --- .../java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 89be90ab8..8ef2a7452 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; import java.util.Iterator; -import java.util.List; import java.util.TimeZone; import org.spongycastle.bcpg.CompressionAlgorithmTags; @@ -66,15 +65,12 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; -import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Primes; import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import android.content.Context; import android.util.Pair; -import javax.crypto.SecretKey; - public class PgpKeyOperation { private final Context mContext; private final ProgressDialogUpdater mProgress; -- cgit v1.2.3 From fcc7117770be50b1fdaf204bf725a69a111c26d2 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sun, 23 Mar 2014 23:41:08 +0000 Subject: move stuff around, save work --- .../keychain/pgp/PgpKeyOperation.java | 120 +++++++++++---------- 1 file changed, 61 insertions(+), 59 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 8ef2a7452..e64c11852 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -497,12 +497,69 @@ public class PgpKeyOperation { for (int i = 0; i < saveParcel.keys.size(); ++i) { updateProgress(40 + 50 * (i - 1) / (saveParcel.keys.size() - 1), 100); if (saveParcel.moddedKeys[i]) { + //to make public key, use a keygen and temp.publickeyring? + + PGPSecretKey subKey = saveParcel.keys.get(i); + PGPPublicKey subPublicKey = subKey.getPublicKey(); + + PBESecretKeyDecryptor keyDecryptor2; + if (saveParcel.newKeys[i]) { + keyDecryptor2 = new JcePBESecretKeyDecryptorBuilder() + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( + "".toCharArray()); + } else { + keyDecryptor2 = new JcePBESecretKeyDecryptorBuilder() + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( + saveParcel.oldPassPhrase.toCharArray()); + } + PGPPrivateKey subPrivateKey = subKey.extractPrivateKey(keyDecryptor2); + + // TODO: now used without algorithm and creation time?! (APG 1) + PGPKeyPair subKeyPair = new PGPKeyPair(subPublicKey, subPrivateKey); + + hashedPacketsGen = new PGPSignatureSubpacketGenerator(); + unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); + + usageId = saveParcel.keysUsages.get(i); + canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this + if (canSign) { + Date todayDate = new Date(); //both sig times the same + // cross-certify signing keys + hashedPacketsGen.setSignatureCreationTime(false, todayDate); //set outer creation time + PGPSignatureSubpacketGenerator subHashedPacketsGen = new PGPSignatureSubpacketGenerator(); + subHashedPacketsGen.setSignatureCreationTime(false, todayDate); //set inner creation time + PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( + subPublicKey.getAlgorithm(), PGPUtil.SHA1) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); + PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); + sGen.init(PGPSignature.PRIMARYKEY_BINDING, subPrivateKey); + sGen.setHashedSubpackets(subHashedPacketsGen.generate()); + PGPSignature certification = sGen.generateCertification(masterPublicKey, + subPublicKey); + unhashedPacketsGen.setEmbeddedSignature(false, certification); + } + hashedPacketsGen.setKeyFlags(false, usageId); + + if (saveParcel.keysExpiryDates.get(i) != null) { + GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + creationDate.setTime(subPublicKey.getCreationTime()); + GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(i); + //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c + //here we purposefully ignore partial days in each date - long type has no fractional part! + long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); + if (numDays <= 0) + throw new PgpGeneralException(mContext.getString(R.string.error_expiry_must_come_after_creation)); + hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); + } else { + hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, + //this happens anyway + } + + keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate()); + //discard only certain certs //secretkey.replacepublickey with updated public key -//secretkeyring.insertsecretkey with newly signed secret key - } else { -//else nothing, right? } - if (saveParcel.newKeys[i]) { + if (saveParcel.newKeys[i]) { //might not be necessary //set the passphrase to the old one, so we can update the whole keyring passphrase later PBESecretKeyEncryptor keyEncryptorOld = new JcePBESecretKeyEncryptorBuilder( PGPEncryptedData.CAST5, sha1Calc) @@ -520,61 +577,6 @@ public class PgpKeyOperation { } updateProgress(R.string.progress_adding_sub_keys, 40, 100); - for (int i = 1; i < saveParcel.keys.size(); ++i) { - updateProgress(40 + 50 * (i - 1) / (saveParcel.keys.size() - 1), 100); - - PGPSecretKey subKey = saveParcel.keys.get(i); - PGPPublicKey subPublicKey = subKey.getPublicKey(); - - PBESecretKeyDecryptor keyDecryptor2 = new JcePBESecretKeyDecryptorBuilder() - .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( - saveParcel.oldPassPhrase.toCharArray()); - PGPPrivateKey subPrivateKey = subKey.extractPrivateKey(keyDecryptor2); - - // TODO: now used without algorithm and creation time?! (APG 1) - PGPKeyPair subKeyPair = new PGPKeyPair(subPublicKey, subPrivateKey); - - hashedPacketsGen = new PGPSignatureSubpacketGenerator(); - unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); - - usageId = saveParcel.keysUsages.get(i); - canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this - if (canSign) { - Date todayDate = new Date(); //both sig times the same - // cross-certify signing keys - hashedPacketsGen.setSignatureCreationTime(false, todayDate); //set outer creation time - PGPSignatureSubpacketGenerator subHashedPacketsGen = new PGPSignatureSubpacketGenerator(); - subHashedPacketsGen.setSignatureCreationTime(false, todayDate); //set inner creation time - PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( - subPublicKey.getAlgorithm(), PGPUtil.SHA1) - .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); - PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); - sGen.init(PGPSignature.PRIMARYKEY_BINDING, subPrivateKey); - sGen.setHashedSubpackets(subHashedPacketsGen.generate()); - PGPSignature certification = sGen.generateCertification(masterPublicKey, - subPublicKey); - unhashedPacketsGen.setEmbeddedSignature(false, certification); - } - hashedPacketsGen.setKeyFlags(false, usageId); - - if (saveParcel.keysExpiryDates.get(i) != null) { - GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - creationDate.setTime(subPublicKey.getCreationTime()); - GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(i); - //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c - //here we purposefully ignore partial days in each date - long type has no fractional part! - long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); - if (numDays <= 0) - throw new PgpGeneralException(mContext.getString(R.string.error_expiry_must_come_after_creation)); - hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); - } else { - hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, - //this happens anyway - } - - keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate()); - } - //update the passphrase mKR = PGPSecretKeyRing.copyWithNewPassword(mKR, keyDecryptor, keyEncryptor); updateProgress(R.string.progress_saving_key_ring, 90, 100); -- cgit v1.2.3 From 974514e470d6835ee7a2f6cc34863dae23f16a3e Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Mon, 24 Mar 2014 16:15:28 +0000 Subject: work on saving --- .../keychain/pgp/PgpKeyOperation.java | 45 +++++++++++----------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index e64c11852..3d7826553 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -382,6 +382,8 @@ public class PgpKeyOperation { do we need to remove and add in? */ + //todo: flag changes of master key if IDs changed maybe? + for (PGPSecretKey dKey : saveParcel.deletedKeys) { mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey); } @@ -484,11 +486,11 @@ public class PgpKeyOperation { PGPContentSignerBuilder certificationSignerBuilder = new JcaPGPContentSignerBuilder( masterKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1); - // Build key encrypter based on passphrase + // Build key encryptor based on old passphrase, as some keys may be unchanged PBESecretKeyEncryptor keyEncryptor = new JcePBESecretKeyEncryptorBuilder( PGPEncryptedData.CAST5, sha1Calc) .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( - saveParcel.newPassPhrase.toCharArray()); + saveParcel.oldPassPhrase.toCharArray()); PGPKeyRingGenerator keyGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, masterKeyPair, mainUserId, sha1Calc, hashedPacketsGen.generate(), @@ -497,8 +499,6 @@ public class PgpKeyOperation { for (int i = 0; i < saveParcel.keys.size(); ++i) { updateProgress(40 + 50 * (i - 1) / (saveParcel.keys.size() - 1), 100); if (saveParcel.moddedKeys[i]) { - //to make public key, use a keygen and temp.publickeyring? - PGPSecretKey subKey = saveParcel.keys.get(i); PGPPublicKey subPublicKey = subKey.getPublicKey(); @@ -513,8 +513,6 @@ public class PgpKeyOperation { saveParcel.oldPassPhrase.toCharArray()); } PGPPrivateKey subPrivateKey = subKey.extractPrivateKey(keyDecryptor2); - - // TODO: now used without algorithm and creation time?! (APG 1) PGPKeyPair subKeyPair = new PGPKeyPair(subPublicKey, subPrivateKey); hashedPacketsGen = new PGPSignatureSubpacketGenerator(); @@ -557,28 +555,31 @@ public class PgpKeyOperation { keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate()); //discard only certain certs -//secretkey.replacepublickey with updated public key } - if (saveParcel.newKeys[i]) { //might not be necessary - //set the passphrase to the old one, so we can update the whole keyring passphrase later - PBESecretKeyEncryptor keyEncryptorOld = new JcePBESecretKeyEncryptorBuilder( - PGPEncryptedData.CAST5, sha1Calc) - .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( - saveParcel.oldPassPhrase.toCharArray()); - PBESecretKeyDecryptor keyDecryptorBlank = new JcePBESecretKeyDecryptorBuilder() - .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( - saveParcel.oldPassPhrase.toCharArray()); - saveParcel.keys.set(i, PGPSecretKey.copyWithNewPassword(saveParcel.keys.get(i), - keyDecryptorBlank, keyEncryptorOld)); + } + + PGPSecretKeyRing updatedSecretKeyRing = keyGen.generateSecretKeyRing(); + //finally, update the keyrings + Iterator itr = updatedSecretKeyRing.getSecretKeys(); + while (itr.hasNext()) { + PGPSecretKey theNextKey = itr.next(); + if ((theNextKey.isMasterKey() && saveParcel.moddedKeys[0]) || !theNextKey.isMasterKey()) { + mKR = PGPSecretKeyRing.insertSecretKey(mKR, theNextKey); + pKR = PGPPublicKeyRing.insertPublicKey(pKR, theNextKey.getPublicKey()); } - //finally, update the keyrings - mKR = PGPSecretKeyRing.insertSecretKey(mKR, saveParcel.keys.get(i)); - pKR = PGPPublicKeyRing.insertPublicKey(pKR, saveParcel.keys.get(i).getPublicKey()); } + + updateProgress(R.string.progress_adding_sub_keys, 40, 100); + // Build key encryptor based on new passphrase + PBESecretKeyEncryptor keyEncryptorNew = new JcePBESecretKeyEncryptorBuilder( + PGPEncryptedData.CAST5, sha1Calc) + .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( + saveParcel.newPassPhrase.toCharArray()); + //update the passphrase - mKR = PGPSecretKeyRing.copyWithNewPassword(mKR, keyDecryptor, keyEncryptor); + mKR = PGPSecretKeyRing.copyWithNewPassword(mKR, keyDecryptor, keyEncryptorNew); updateProgress(R.string.progress_saving_key_ring, 90, 100); ProviderHelper.saveKeyRing(mContext, mKR); -- cgit v1.2.3 From 300b90bcac6fbf5b5e416943e538a2c2bc49342c Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Mon, 24 Mar 2014 16:47:02 +0000 Subject: make sure ID info is saved --- .../sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 3d7826553..5f97aa2e5 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -368,7 +368,7 @@ public class PgpKeyOperation { } /* - IDs - + IDs - NB This might not need to happen later, if we change the way the primary ID is chosen remove deleted ids if the primary ID changed we need to: remove all of the IDs from the keyring, saving their certifications @@ -382,8 +382,6 @@ public class PgpKeyOperation { do we need to remove and add in? */ - //todo: flag changes of master key if IDs changed maybe? - for (PGPSecretKey dKey : saveParcel.deletedKeys) { mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey); } @@ -406,7 +404,9 @@ public class PgpKeyOperation { } int user_id_index = 0; + boolean anyIDChanged = false; if (saveParcel.primaryIDChanged) { + anyIDChanged = true; ArrayList> sigList = new ArrayList>(); for (String userId : saveParcel.userIDs) { String orig_id = saveParcel.originalIDs.get(user_id_index); @@ -437,6 +437,7 @@ public class PgpKeyOperation { for (String userId : saveParcel.userIDs) { String orig_id = saveParcel.originalIDs.get(user_id_index); if (!orig_id.equals(userId)) { + anyIDChanged = true; PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME); @@ -452,6 +453,12 @@ public class PgpKeyOperation { } } + //update the keyring with the new ID information + if (anyIDChanged) { + pKR = PGPPublicKeyRing.insertPublicKey(pKR, masterPublicKey); + mKR = PGPSecretKeyRing.replacePublicKeys(mKR, pKR); + } + PGPKeyPair masterKeyPair = new PGPKeyPair(masterPublicKey, masterPrivateKey); PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator(); -- cgit v1.2.3 From 02688f6ebfb07b70656cbe9fe6d723d36f3ffc35 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Mon, 24 Mar 2014 17:41:45 +0000 Subject: comments, slight change to progress bar --- .../sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 5f97aa2e5..adccc5ba3 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -380,6 +380,10 @@ public class PgpKeyOperation { remove deleted keys if a key is modified, re-sign it do we need to remove and add in? + + Todo + identify more things which need to be preserved - e.g. trust levels? + user attributes */ for (PGPSecretKey dKey : saveParcel.deletedKeys) { @@ -504,7 +508,7 @@ public class PgpKeyOperation { unhashedPacketsGen.generate(), certificationSignerBuilder, keyEncryptor); for (int i = 0; i < saveParcel.keys.size(); ++i) { - updateProgress(40 + 50 * (i - 1) / (saveParcel.keys.size() - 1), 100); + updateProgress(40 + 50 * i/ saveParcel.keys.size(), 100); if (saveParcel.moddedKeys[i]) { PGPSecretKey subKey = saveParcel.keys.get(i); PGPPublicKey subPublicKey = subKey.getPublicKey(); @@ -561,7 +565,11 @@ public class PgpKeyOperation { } keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate()); - //discard only certain certs + //certifications will be discarded if the key is changed, because I think, for a start, + //they will be invalid. Binding certs are regenerated anyway, and other certs which + //need to be kept are on IDs and attributes + //TODO: don't let revoked keys be edited, other than removed - changing one would result in the + //revocation being wrong? } } @@ -575,10 +583,6 @@ public class PgpKeyOperation { pKR = PGPPublicKeyRing.insertPublicKey(pKR, theNextKey.getPublicKey()); } } - - - updateProgress(R.string.progress_adding_sub_keys, 40, 100); - // Build key encryptor based on new passphrase PBESecretKeyEncryptor keyEncryptorNew = new JcePBESecretKeyEncryptorBuilder( PGPEncryptedData.CAST5, sha1Calc) -- cgit v1.2.3 From e7b3dd64f4f0dbf5841ade521fe654ed8e3e0b26 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 25 Mar 2014 00:20:35 +0000 Subject: results of debugging, fix several bugs - more needed though... --- .../keychain/pgp/PgpKeyOperation.java | 76 +++++++++++++--------- 1 file changed, 45 insertions(+), 31 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index adccc5ba3..fab456bf8 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -386,8 +386,10 @@ public class PgpKeyOperation { user attributes */ - for (PGPSecretKey dKey : saveParcel.deletedKeys) { - mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey); + if (saveParcel.deletedKeys != null) { + for (PGPSecretKey dKey : saveParcel.deletedKeys) { + mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey); + } } masterKey = mKR.getSecretKey(); @@ -409,6 +411,31 @@ public class PgpKeyOperation { int user_id_index = 0; boolean anyIDChanged = false; + + PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator(); + PGPSignatureSubpacketGenerator unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); + + hashedPacketsGen.setKeyFlags(true, usageId); + + hashedPacketsGen.setPreferredSymmetricAlgorithms(true, PREFERRED_SYMMETRIC_ALGORITHMS); + hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS); + hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS); + + if (saveParcel.keysExpiryDates.get(0) != null) { + GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + creationDate.setTime(masterPublicKey.getCreationTime()); + GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(0); + //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c + //here we purposefully ignore partial days in each date - long type has no fractional part! + long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); + if (numDays <= 0) + throw new PgpGeneralException(mContext.getString(R.string.error_expiry_must_come_after_creation)); + hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); + } else { + hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, + //this happens anyway + } + if (saveParcel.primaryIDChanged) { anyIDChanged = true; ArrayList> sigList = new ArrayList>(); @@ -427,11 +454,16 @@ public class PgpKeyOperation { PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); - + if (user_id_index == 0) { + sGen.setHashedSubpackets(hashedPacketsGen.generate()); + sGen.setUnhashedSubpackets(unhashedPacketsGen.generate()); + } PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); sigList.add(new Pair(userId, certification)); } - masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, orig_id); + if (!orig_id.equals("")) { + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, orig_id); + } user_id_index++; } for (Pair to_add : sigList) { @@ -448,9 +480,14 @@ public class PgpKeyOperation { PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); - + if (user_id_index == 0) { + sGen.setHashedSubpackets(hashedPacketsGen.generate()); + sGen.setUnhashedSubpackets(unhashedPacketsGen.generate()); + } PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); - masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, orig_id); + if (!orig_id.equals("")) { + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, orig_id); + } masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); } user_id_index++; @@ -465,30 +502,6 @@ public class PgpKeyOperation { PGPKeyPair masterKeyPair = new PGPKeyPair(masterPublicKey, masterPrivateKey); - PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator(); - PGPSignatureSubpacketGenerator unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); - - hashedPacketsGen.setKeyFlags(true, usageId); - - hashedPacketsGen.setPreferredSymmetricAlgorithms(true, PREFERRED_SYMMETRIC_ALGORITHMS); - hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS); - hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS); - - if (saveParcel.keysExpiryDates.get(0) != null) { - GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - creationDate.setTime(masterPublicKey.getCreationTime()); - GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(0); - //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c - //here we purposefully ignore partial days in each date - long type has no fractional part! - long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); - if (numDays <= 0) - throw new PgpGeneralException(mContext.getString(R.string.error_expiry_must_come_after_creation)); - hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); - } else { - hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, - //this happens anyway - } - updateProgress(R.string.progress_building_master_key, 30, 100); // define hashing and signing algos @@ -503,11 +516,12 @@ public class PgpKeyOperation { .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( saveParcel.oldPassPhrase.toCharArray()); + //this generates one more signature than necessary... PGPKeyRingGenerator keyGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, masterKeyPair, mainUserId, sha1Calc, hashedPacketsGen.generate(), unhashedPacketsGen.generate(), certificationSignerBuilder, keyEncryptor); - for (int i = 0; i < saveParcel.keys.size(); ++i) { + for (int i = 1; i < saveParcel.keys.size(); ++i) { updateProgress(40 + 50 * i/ saveParcel.keys.size(), 100); if (saveParcel.moddedKeys[i]) { PGPSecretKey subKey = saveParcel.keys.get(i); -- cgit v1.2.3 From 68f035ff88131928cdd0681ba3b1fb4980d9a574 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 25 Mar 2014 22:28:32 +0000 Subject: allow lists to be subkeys or keyrings --- .../keychain/pgp/PgpConversionHelper.java | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java index 20d446824..c7dd7d647 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java @@ -59,13 +59,30 @@ public class PgpConversionHelper { * @return */ public static ArrayList BytesToPGPSecretKeyList(byte[] keysBytes) { - PGPSecretKeyRing keyRing = (PGPSecretKeyRing) BytesToPGPKeyRing(keysBytes); + PGPObjectFactory factory = new PGPObjectFactory(keysBytes); + Object obj = null; ArrayList keys = new ArrayList(); - - @SuppressWarnings("unchecked") - Iterator itr = keyRing.getSecretKeys(); - while (itr.hasNext()) { - keys.add(itr.next()); + try { + while ((obj = factory.nextObject()) != null) { + PGPSecretKey secKey = null; + if(obj instanceof PGPSecretKey) { + if ((secKey = (PGPSecretKey)obj ) == null) { + Log.e(Constants.TAG, "No keys given!"); + } + keys.add(secKey); + } else if(obj instanceof PGPSecretKeyRing) { //master keys are sent as keyrings + PGPSecretKeyRing keyRing = null; + if ((keyRing = (PGPSecretKeyRing)obj) == null) { + Log.e(Constants.TAG, "No keys given!"); + } + @SuppressWarnings("unchecked") + Iterator itr = keyRing.getSecretKeys(); + while (itr.hasNext()) { + keys.add(itr.next()); + } + } + } + } catch (IOException e) { } return keys; -- cgit v1.2.3 From 259a8a63a2efa587c6cbe23ae929d7f8c9478664 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 25 Mar 2014 22:40:05 +0000 Subject: delete IDs needs to update keyring, flag it --- .../main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index fab456bf8..370f66388 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -405,12 +405,13 @@ public class PgpKeyOperation { updateProgress(R.string.progress_certifying_master_key, 20, 100); + boolean anyIDChanged = false; for (String delID : saveParcel.deletedIDs) { + anyIDChanged = true; masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, delID); } int user_id_index = 0; - boolean anyIDChanged = false; PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator(); PGPSignatureSubpacketGenerator unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); -- cgit v1.2.3 From b77e0504aa1308da36df63038d4c05ca9aaebd71 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Tue, 25 Mar 2014 23:01:17 +0000 Subject: allow master key updates by removing old primary ID cert --- .../java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 370f66388..9bf9ecc73 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -376,6 +376,9 @@ public class PgpKeyOperation { else remove changed IDs and add in with new certs + if the master key changed, we need to remove the primary ID certification, so we can add + the new one when it is generated, and they don't conflict + Keys remove deleted keys if a key is modified, re-sign it @@ -495,6 +498,11 @@ public class PgpKeyOperation { } } + if (saveParcel.moddedKeys[0]) { + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, saveParcel.originalIDs.get(0)); + anyIDChanged = true; + } + //update the keyring with the new ID information if (anyIDChanged) { pKR = PGPPublicKeyRing.insertPublicKey(pKR, masterPublicKey); -- cgit v1.2.3 From 4923c9b8e3e78c888cde438a5f9aac7155ed30f5 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Wed, 26 Mar 2014 00:29:39 +0000 Subject: add original primary ID field to parcel --- .../org/sufficientlysecure/keychain/service/SaveKeyringParcel.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java index ae481aa80..c99284847 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -41,6 +41,7 @@ public class SaveKeyringParcel implements Parcelable { public String oldPassPhrase; public boolean[] newKeys; public ArrayList keys; + public String originalPrimaryID; public SaveKeyringParcel() {} @@ -62,6 +63,7 @@ public class SaveKeyringParcel implements Parcelable { oldPassPhrase = source.readString(); newKeys = source.createBooleanArray(); keys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray()); + originalPrimaryID = source.readString(); } @Override @@ -82,6 +84,7 @@ public class SaveKeyringParcel implements Parcelable { destination.writeString(oldPassPhrase); destination.writeBooleanArray(newKeys); destination.writeByteArray(PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys)); + destination.writeString(originalPrimaryID); } public static final Creator CREATOR = new Creator() { -- cgit v1.2.3 From 140646fa121958ba3b19decd8a92f470fe13ac43 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 27 Mar 2014 13:35:03 +0000 Subject: pass through original primary ID --- .../sufficientlysecure/keychain/ui/EditKeyActivity.java | 1 + .../keychain/ui/widget/SectionView.java | 15 +++++++++++++++ .../keychain/ui/widget/UserIdEditor.java | 5 +++++ 3 files changed, 21 insertions(+) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 716140655..0726897c3 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -597,6 +597,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener saveParams.oldPassPhrase = mCurrentPassphrase; saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray()); saveParams.keys = getKeys(mKeysView); + saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID(); // fill values for this action diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 6ab422d69..9758835d2 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -198,6 +198,21 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor return ret; } + public String getOriginalPrimaryID() + { //NB: this will have to change when we change how Primary IDs are chosen, and so we need to be + // careful about where Master key capabilities are stored... multiple primaries and + // revoked ones make this harder than the simple case we are continuing to assume here + for (int i = 0; i < mEditors.getChildCount(); ++i) { + Editor editor = (Editor) mEditors.getChildAt(i); + if (mType == Id.type.user_id) { + if(((UserIdEditor)editor).getIsOriginallyMainUserID()) { + return ((UserIdEditor)editor).getOriginalID(); + } + } + } + return null; + } + public ArrayList getOriginalIDs() { ArrayList orig = new ArrayList(); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index 5098c8713..8760b72f7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -229,6 +229,11 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene return retval; } + public boolean getIsOriginallyMainUserID() + { + return mOriginallyMainUserID; + } + public boolean primarySwapped() { return (mOriginallyMainUserID != isMainUserId()); -- cgit v1.2.3 From 56447ad0b55d2ff41e5acb6b8f8ee85393eee05c Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 27 Mar 2014 14:48:27 +0000 Subject: fix for editing master keys and IDs, case of change primary ID and modify master key props fails --- .../keychain/pgp/PgpKeyOperation.java | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 9bf9ecc73..603b8dcd1 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -440,12 +440,12 @@ public class PgpKeyOperation { //this happens anyway } - if (saveParcel.primaryIDChanged) { + if (saveParcel.primaryIDChanged || !saveParcel.originalIDs.get(0).equals(saveParcel.userIDs.get(0))) { anyIDChanged = true; ArrayList> sigList = new ArrayList>(); for (String userId : saveParcel.userIDs) { String orig_id = saveParcel.originalIDs.get(user_id_index); - if (orig_id.equals(userId)) { + if (orig_id.equals(userId) && !userId.equals(saveParcel.originalPrimaryID) && user_id_index != 0) { Iterator orig_sigs = masterPublicKey.getSignaturesForID(orig_id); //TODO: make sure this iterator only has signatures we are interested in while (orig_sigs.hasNext()) { PGPSignature orig_sig = orig_sigs.next(); @@ -498,8 +498,23 @@ public class PgpKeyOperation { } } + ArrayList> sigList = new ArrayList>(); if (saveParcel.moddedKeys[0]) { - masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, saveParcel.originalIDs.get(0)); + user_id_index = 0; + for (String userId : saveParcel.userIDs) { + String orig_id = saveParcel.originalIDs.get(user_id_index); + if (!orig_id.equals(saveParcel.originalPrimaryID) && !saveParcel.primaryIDChanged) { + Iterator sigs = masterPublicKey.getSignaturesForID(userId); //TODO: make sure this iterator only has signatures we are interested in + while (sigs.hasNext()) { + PGPSignature sig = sigs.next(); + sigList.add(new Pair(userId, sig)); + } + } + if (!userId.equals("")) { + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, userId); + } + user_id_index++; + } anyIDChanged = true; } @@ -606,6 +621,17 @@ public class PgpKeyOperation { pKR = PGPPublicKeyRing.insertPublicKey(pKR, theNextKey.getPublicKey()); } } + + //replace lost IDs + if (saveParcel.moddedKeys[0]) { + masterPublicKey = mKR.getPublicKey(); + for (Pair to_add : sigList) { + masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, to_add.first, to_add.second); + } + pKR = PGPPublicKeyRing.insertPublicKey(pKR, masterPublicKey); + mKR = PGPSecretKeyRing.replacePublicKeys(mKR, pKR); + } + // Build key encryptor based on new passphrase PBESecretKeyEncryptor keyEncryptorNew = new JcePBESecretKeyEncryptorBuilder( PGPEncryptedData.CAST5, sha1Calc) -- cgit v1.2.3 From 7a2d880c4db21ab62cb152f10d1938a36319acb3 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Thu, 27 Mar 2014 15:00:35 +0000 Subject: all editing cases I can think of now work --- .../main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 603b8dcd1..b7f84ccdc 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -503,7 +503,7 @@ public class PgpKeyOperation { user_id_index = 0; for (String userId : saveParcel.userIDs) { String orig_id = saveParcel.originalIDs.get(user_id_index); - if (!orig_id.equals(saveParcel.originalPrimaryID) && !saveParcel.primaryIDChanged) { + if (!(orig_id.equals(saveParcel.originalPrimaryID) && !saveParcel.primaryIDChanged)) { Iterator sigs = masterPublicKey.getSignaturesForID(userId); //TODO: make sure this iterator only has signatures we are interested in while (sigs.hasNext()) { PGPSignature sig = sigs.next(); -- cgit v1.2.3 From 556d6ff2268c8769d2d9d16eb0a50c8b0ee97365 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sat, 29 Mar 2014 15:19:38 +0000 Subject: revert mistake --- .../java/org/sufficientlysecure/keychain/provider/ProviderHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index b47c4946f..b971143ae 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -354,7 +354,7 @@ public class ProviderHelper { values.put(Keys.KEY_SIZE, key.getPublicKey().getBitStrength()); values.put(Keys.CAN_CERTIFY, (PgpKeyHelper.isCertificationKey(key) && hasPrivate)); values.put(Keys.CAN_SIGN, (PgpKeyHelper.isSigningKey(key) && hasPrivate)); - values.put(Keys.CAN_ENCRYPT, PgpKeyHelper.isEncryptionKey(key) && hasPrivate); + values.put(Keys.CAN_ENCRYPT, PgpKeyHelper.isEncryptionKey(key)); values.put(Keys.IS_REVOKED, key.getPublicKey().isRevoked()); values.put(Keys.CREATION, PgpKeyHelper.getCreationDate(key).getTime() / 1000); Date expiryDate = PgpKeyHelper.getExpiryDate(key); -- cgit v1.2.3 From be007ecc56809cc0b6d489ab09be656e2ced9c32 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sun, 30 Mar 2014 16:22:13 +0100 Subject: style changes --- .../keychain/pgp/PgpKeyOperation.java | 53 +++++++++++----------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 05ca99578..592bdec73 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -217,7 +217,7 @@ public class PgpKeyOperation { PGPPrivateKey masterPrivateKey = masterKey.extractPrivateKey(keyDecryptor); updateProgress(R.string.progress_certifying_master_key, 20, 100); - int user_id_index = 0; + for (String userId : userIds) { PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) @@ -228,7 +228,6 @@ public class PgpKeyOperation { PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); - user_id_index++; } PGPKeyPair masterKeyPair = new PGPKeyPair(masterPublicKey, masterPrivateKey); @@ -412,7 +411,7 @@ public class PgpKeyOperation { masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, delID); } - int user_id_index = 0; + int userIDIndex = 0; PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator(); PGPSignatureSubpacketGenerator unhashedPacketsGen = new PGPSignatureSubpacketGenerator(); @@ -442,12 +441,12 @@ public class PgpKeyOperation { anyIDChanged = true; ArrayList> sigList = new ArrayList>(); for (String userId : saveParcel.userIDs) { - String orig_id = saveParcel.originalIDs.get(user_id_index); - if (orig_id.equals(userId) && !userId.equals(saveParcel.originalPrimaryID) && user_id_index != 0) { - Iterator orig_sigs = masterPublicKey.getSignaturesForID(orig_id); //TODO: make sure this iterator only has signatures we are interested in - while (orig_sigs.hasNext()) { - PGPSignature orig_sig = orig_sigs.next(); - sigList.add(new Pair(orig_id, orig_sig)); + String origID = saveParcel.originalIDs.get(userIDIndex); + if (origID.equals(userId) && !userId.equals(saveParcel.originalPrimaryID) && userIDIndex != 0) { + Iterator origSigs = masterPublicKey.getSignaturesForID(origID); //TODO: make sure this iterator only has signatures we are interested in + while (origSigs.hasNext()) { + PGPSignature origSig = origSigs.next(); + sigList.add(new Pair(origID, origSig)); } } else { PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( @@ -456,25 +455,25 @@ public class PgpKeyOperation { PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); - if (user_id_index == 0) { + if (userIDIndex == 0) { sGen.setHashedSubpackets(hashedPacketsGen.generate()); sGen.setUnhashedSubpackets(unhashedPacketsGen.generate()); } PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); sigList.add(new Pair(userId, certification)); } - if (!orig_id.equals("")) { - masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, orig_id); + if (!origID.equals("")) { + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, origID); } - user_id_index++; + userIDIndex++; } - for (Pair to_add : sigList) { - masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, to_add.first, to_add.second); + for (Pair toAdd : sigList) { + masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, toAdd.first, toAdd.second); } } else { for (String userId : saveParcel.userIDs) { - String orig_id = saveParcel.originalIDs.get(user_id_index); - if (!orig_id.equals(userId)) { + String origID = saveParcel.originalIDs.get(userIDIndex); + if (!origID.equals(userId)) { anyIDChanged = true; PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder( masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1) @@ -482,26 +481,26 @@ public class PgpKeyOperation { PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder); sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey); - if (user_id_index == 0) { + if (userIDIndex == 0) { sGen.setHashedSubpackets(hashedPacketsGen.generate()); sGen.setUnhashedSubpackets(unhashedPacketsGen.generate()); } PGPSignature certification = sGen.generateCertification(userId, masterPublicKey); - if (!orig_id.equals("")) { - masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, orig_id); + if (!origID.equals("")) { + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, origID); } masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); } - user_id_index++; + userIDIndex++; } } ArrayList> sigList = new ArrayList>(); if (saveParcel.moddedKeys[0]) { - user_id_index = 0; + userIDIndex = 0; for (String userId : saveParcel.userIDs) { - String orig_id = saveParcel.originalIDs.get(user_id_index); - if (!(orig_id.equals(saveParcel.originalPrimaryID) && !saveParcel.primaryIDChanged)) { + String origID = saveParcel.originalIDs.get(userIDIndex); + if (!(origID.equals(saveParcel.originalPrimaryID) && !saveParcel.primaryIDChanged)) { Iterator sigs = masterPublicKey.getSignaturesForID(userId); //TODO: make sure this iterator only has signatures we are interested in while (sigs.hasNext()) { PGPSignature sig = sigs.next(); @@ -511,7 +510,7 @@ public class PgpKeyOperation { if (!userId.equals("")) { masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, userId); } - user_id_index++; + userIDIndex++; } anyIDChanged = true; } @@ -623,8 +622,8 @@ public class PgpKeyOperation { //replace lost IDs if (saveParcel.moddedKeys[0]) { masterPublicKey = mKR.getPublicKey(); - for (Pair to_add : sigList) { - masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, to_add.first, to_add.second); + for (Pair toAdd : sigList) { + masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, toAdd.first, toAdd.second); } pKR = PGPPublicKeyRing.insertPublicKey(pKR, masterPublicKey); mKR = PGPSecretKeyRing.replacePublicKeys(mKR, pKR); -- cgit v1.2.3