From 13ffd2038d56d90ffc583663a98c378ee9d9aa00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 14 Apr 2014 01:11:08 +0200 Subject: key edit: fix crash when create date was after expiry date, change from gregorian calendar to calendar with creation from instance, experimental result status for decrypt activity --- .../keychain/pgp/PgpDecryptVerify.java | 1 - .../keychain/pgp/PgpKeyOperation.java | 68 +++++++++--------- .../keychain/service/SaveKeyringParcel.java | 5 +- .../keychain/ui/DecryptFileFragment.java | 9 +-- .../keychain/ui/DecryptFragment.java | 84 ++++++++++++++-------- .../keychain/ui/DecryptMessageFragment.java | 7 +- .../keychain/ui/EditKeyActivity.java | 5 +- .../keychain/ui/EncryptFileFragment.java | 2 +- .../keychain/ui/EncryptMessageFragment.java | 2 +- .../keychain/ui/widget/KeyEditor.java | 36 +++++----- 10 files changed, 119 insertions(+), 100 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java index 22cd62379..7d5c1253c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -600,7 +600,6 @@ public class PgpDecryptVerify { throw new InvalidDataException(); } - // go through all signatures // and find out for which signature we have a key in our database Long masterKeyId = null; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 2df918ac8..9ccc2fd94 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -65,20 +65,21 @@ import java.security.NoSuchProviderException; import java.security.SecureRandom; import java.security.SignatureException; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; import java.util.TimeZone; -/** This class is the single place where ALL operations that actually modify a PGP public or secret +/** + * This class is the single place where ALL operations that actually modify a PGP public or secret * key take place. - * + *

* Note that no android specific stuff should be done here, ie no imports from com.android. - * + *

* All operations support progress reporting to a ProgressDialogUpdater passed on initialization. * This indicator may be null. - * */ public class PgpKeyOperation { private ProgressDialogUpdater mProgress; @@ -129,7 +130,7 @@ public class PgpKeyOperation { public PGPSecretKey createKey(int algorithmChoice, int keySize, String passphrase, boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException, - PgpGeneralMsgIdException, InvalidAlgorithmParameterException { + PgpGeneralMsgIdException, InvalidAlgorithmParameterException { if (keySize < 512) { throw new PgpGeneralMsgIdException(R.string.error_key_size_minimum512bit); @@ -190,13 +191,13 @@ public class PgpKeyOperation { PGPEncryptedData.CAST5, sha1Calc) .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.toCharArray()); - return new PGPSecretKey(keyPair.getPrivateKey(), keyPair.getPublicKey(), - sha1Calc, isMasterKey, keyEncryptor); + return new PGPSecretKey(keyPair.getPrivateKey(), keyPair.getPublicKey(), + sha1Calc, isMasterKey, keyEncryptor); } public PGPSecretKeyRing changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassphrase, - String newPassphrase) - throws IOException, PGPException, NoSuchProviderException { + String newPassphrase) + throws IOException, PGPException, NoSuchProviderException { updateProgress(R.string.progress_building_key, 0, 100); if (oldPassphrase == null) { @@ -261,13 +262,13 @@ public class PgpKeyOperation { hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS); if (saveParcel.keysExpiryDates.get(0) != null) { - GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + Calendar creationDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); creationDate.setTime(masterPublicKey.getCreationTime()); - GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(0); + Calendar 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); + (creationDate.getTimeInMillis() / 86400000); if (numDays <= 0) { throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation); } @@ -336,13 +337,13 @@ public class PgpKeyOperation { hashedPacketsGen.setKeyFlags(false, usageId); if (saveParcel.keysExpiryDates.get(i) != null) { - GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + Calendar creationDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); creationDate.setTime(subPublicKey.getCreationTime()); - GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(i); + Calendar 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); + (creationDate.getTimeInMillis() / 86400000); if (numDays <= 0) { throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation); } @@ -437,13 +438,13 @@ public class PgpKeyOperation { hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS); if (saveParcel.keysExpiryDates.get(0) != null) { - GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + Calendar creationDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); creationDate.setTime(masterPublicKey.getCreationTime()); - GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(0); + Calendar 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); + (creationDate.getTimeInMillis() / 86400000); if (numDays <= 0) { throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation); } @@ -455,13 +456,13 @@ public class PgpKeyOperation { } if (saveParcel.primaryIDChanged || - !saveParcel.originalIDs.get(0).equals(saveParcel.userIds.get(0))) { + !saveParcel.originalIDs.get(0).equals(saveParcel.userIds.get(0))) { anyIDChanged = true; ArrayList> sigList = new ArrayList>(); for (String userId : saveParcel.userIds) { String origID = saveParcel.originalIDs.get(userIDIndex); if (origID.equals(userId) && !saveParcel.newIDs[userIDIndex] && - !userId.equals(saveParcel.originalPrimaryID) && userIDIndex != 0) { + !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()) { @@ -489,7 +490,7 @@ public class PgpKeyOperation { } for (Pair toAdd : sigList) { masterPublicKey = - PGPPublicKey.addCertification(masterPublicKey, toAdd.first, toAdd.second); + PGPPublicKey.addCertification(masterPublicKey, toAdd.first, toAdd.second); } } else { for (String userId : saveParcel.userIds) { @@ -511,7 +512,7 @@ public class PgpKeyOperation { masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, origID); } masterPublicKey = - PGPPublicKey.addCertification(masterPublicKey, userId, certification); + PGPPublicKey.addCertification(masterPublicKey, userId, certification); } userIDIndex++; } @@ -606,14 +607,14 @@ public class PgpKeyOperation { hashedPacketsGen.setKeyFlags(false, usageId); if (saveParcel.keysExpiryDates.get(i) != null) { - GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + Calendar creationDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); creationDate.setTime(subPublicKey.getCreationTime()); - GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(i); + Calendar 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); + (creationDate.getTimeInMillis() / 86400000); if (numDays <= 0) { throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation); } @@ -696,18 +697,19 @@ public class PgpKeyOperation { * Certify the given pubkeyid with the given masterkeyid. * * @param certificationKey Certifying key - * @param publicKey public key to certify - * @param userIds User IDs to certify, must not be null or empty - * @param passphrase Passphrase of the secret key + * @param publicKey public key to certify + * @param userIds User IDs to certify, must not be null or empty + * @param passphrase Passphrase of the secret key * @return A keyring with added certifications */ public PGPPublicKey certifyKey(PGPSecretKey certificationKey, PGPPublicKey publicKey, List userIds, String passphrase) throws PgpGeneralMsgIdException, NoSuchAlgorithmException, NoSuchProviderException, - PGPException, SignatureException { + PGPException, SignatureException { // create a signatureGenerator from the supplied masterKeyId and passphrase - PGPSignatureGenerator signatureGenerator; { + PGPSignatureGenerator signatureGenerator; + { if (certificationKey == null) { throw new PgpGeneralMsgIdException(R.string.error_signature_failed); @@ -744,14 +746,16 @@ public class PgpKeyOperation { return publicKey; } - /** Simple static subclass that stores two values. - * + /** + * Simple static subclass that stores two values. + *

* This is only used to return a pair of values in one function above. We specifically don't use * com.android.Pair to keep this class free from android dependencies. */ public static class Pair { public final K first; public final V second; + public Pair(K first, V second) { this.first = first; this.second = second; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java index 626feeb75..71bdb0231 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -24,6 +24,7 @@ import org.spongycastle.openpgp.PGPSecretKey; import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; import java.util.ArrayList; +import java.util.Calendar; import java.util.GregorianCalendar; public class SaveKeyringParcel implements Parcelable { @@ -35,7 +36,7 @@ public class SaveKeyringParcel implements Parcelable { public boolean primaryIDChanged; public boolean[] moddedKeys; public ArrayList deletedKeys; - public ArrayList keysExpiryDates; + public ArrayList keysExpiryDates; public ArrayList keysUsages; public String newPassphrase; public String oldPassphrase; @@ -58,7 +59,7 @@ public class SaveKeyringParcel implements Parcelable { } else { deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(tmp); } - keysExpiryDates = (ArrayList) source.readSerializable(); + keysExpiryDates = (ArrayList) source.readSerializable(); keysUsages = source.readArrayList(Integer.class.getClassLoader()); newPassphrase = source.readString(); oldPassphrase = source.readString(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java index 492c0cf29..788d95e99 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java @@ -204,8 +204,8 @@ public class DecryptFileFragment extends DecryptFragment { decryptVerifyResult.getStatus()) { showPassphraseDialog(Id.key.symmetric); } else { - AppMsg.makeText(getActivity(), R.string.decryption_successful, - AppMsg.STYLE_INFO).show(); + // display signature result in activity + onResult(decryptVerifyResult); if (mDeleteAfter.isChecked()) { // Create and show dialog to delete original file @@ -213,11 +213,6 @@ public class DecryptFileFragment extends DecryptFragment { .newInstance(mInputFilename); deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog"); } - - OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult(); - - // display signature result in activity - onSignatureResult(signatureResult); } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 1c465f55c..2254029df 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -26,6 +26,7 @@ import android.support.v4.app.Fragment; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; @@ -34,10 +35,8 @@ import com.devspark.appmsg.AppMsg; import org.openintents.openpgp.OpenPgpSignatureResult; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; public class DecryptFragment extends Fragment { @@ -45,19 +44,24 @@ public class DecryptFragment extends Fragment { protected long mSignatureKeyId = 0; - protected RelativeLayout mSignatureLayout = null; - protected ImageView mSignatureStatusImage = null; - protected TextView mUserId = null; - protected TextView mUserIdRest = null; + protected LinearLayout mResultLayout; + protected RelativeLayout mSignatureLayout; + protected TextView mResultText; - protected BootstrapButton mLookupKey = null; + protected ImageView mSignatureStatusImage; + protected TextView mUserId; + protected TextView mUserIdRest; + + protected BootstrapButton mLookupKey; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - mSignatureLayout = (RelativeLayout) getView().findViewById(R.id.signature); + mResultLayout = (LinearLayout) getView().findViewById(R.id.result); + mResultText = (TextView) getView().findViewById(R.id.result_text); + mSignatureLayout = (RelativeLayout) getView().findViewById(R.id.result_signature); mSignatureStatusImage = (ImageView) getView().findViewById(R.id.ic_signature_status); mUserId = (TextView) getView().findViewById(R.id.mainUserId); mUserIdRest = (TextView) getView().findViewById(R.id.mainUserIdRest); @@ -68,8 +72,8 @@ public class DecryptFragment extends Fragment { lookupUnknownKey(mSignatureKeyId); } }); - mSignatureLayout.setVisibility(View.GONE); - mSignatureLayout.setOnClickListener(new OnClickListener() { + mResultLayout.setVisibility(View.GONE); + mResultLayout.setOnClickListener(new OnClickListener() { public void onClick(View v) { lookupUnknownKey(mSignatureKeyId); } @@ -102,10 +106,13 @@ public class DecryptFragment extends Fragment { } } - protected void onSignatureResult(OpenPgpSignatureResult signatureResult) { + protected void onResult(PgpDecryptVerifyResult decryptVerifyResult) { + OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult(); + mSignatureKeyId = 0; - mSignatureLayout.setVisibility(View.GONE); + mResultLayout.setVisibility(View.VISIBLE); if (signatureResult != null) { + mSignatureStatusImage.setVisibility(View.VISIBLE); mSignatureKeyId = signatureResult.getKeyId(); @@ -124,48 +131,63 @@ public class DecryptFragment extends Fragment { } switch (signatureResult.getStatus()) { - case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED: { + case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: { + mResultText.setText(R.string.decrypt_verified_successful); + + mResultLayout.setBackgroundColor(getResources().getColor(R.color.result_green)); mSignatureStatusImage.setImageResource(R.drawable.overlay_ok); mLookupKey.setVisibility(View.GONE); break; } - // TODO! -// case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: { -// break; -// } + case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED: { + mResultText.setText(R.string.decrypt_verified_successful); + + mResultLayout.setBackgroundColor(getResources().getColor(R.color.result_orange)); + mSignatureStatusImage.setImageResource(R.drawable.overlay_ok); + mLookupKey.setVisibility(View.GONE); + break; + } case OpenPgpSignatureResult.SIGNATURE_UNKNOWN_PUB_KEY: { + mResultText.setText(R.string.unknown_signature); + + mResultLayout.setBackgroundColor(getResources().getColor(R.color.result_orange)); mSignatureStatusImage.setImageResource(R.drawable.overlay_error); mLookupKey.setVisibility(View.VISIBLE); - AppMsg.makeText(getActivity(), - R.string.unknown_signature, - AppMsg.STYLE_ALERT).show(); break; } default: { + mResultText.setText(R.string.error); + + mResultLayout.setBackgroundColor(getResources().getColor(R.color.result_red)); mSignatureStatusImage.setImageResource(R.drawable.overlay_error); mLookupKey.setVisibility(View.GONE); break; } } - mSignatureLayout.setVisibility(View.VISIBLE); + } else { + mSignatureLayout.setVisibility(View.GONE); + + // only successful decryption + mResultLayout.setBackgroundColor(getResources().getColor(R.color.result_blue)); + mResultText.setText(R.string.decrypt_successful); } } protected void showPassphraseDialog(long keyId) { PassphraseDialogFragment.show(getActivity(), keyId, - new Handler() { - @Override - public void handleMessage(Message message) { - if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { - String passphrase = - message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE); - decryptStart(passphrase); + new Handler() { + @Override + public void handleMessage(Message message) { + if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { + String passphrase = + message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE); + decryptStart(passphrase); + } } - } - }); + }); } /** diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java index ca75cbd4f..9487b4007 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java @@ -158,18 +158,13 @@ public class DecryptMessageFragment extends DecryptFragment { decryptVerifyResult.getStatus()) { showPassphraseDialog(Id.key.symmetric); } else { - AppMsg.makeText(getActivity(), R.string.decryption_successful, - AppMsg.STYLE_INFO).show(); - byte[] decryptedMessage = returnData .getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES); mMessage.setText(new String(decryptedMessage)); mMessage.setHorizontallyScrolling(false); - OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult(); - // display signature result in activity - onSignatureResult(signatureResult); + onResult(decryptVerifyResult); } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 5e8ca17a1..a568672be 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -72,6 +72,7 @@ import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; +import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; import java.util.Vector; @@ -731,8 +732,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener return keysUsages; } - private ArrayList getKeysExpiryDates(SectionView keysView) throws PgpGeneralException { - ArrayList keysExpiryDates = new ArrayList(); + private ArrayList getKeysExpiryDates(SectionView keysView) throws PgpGeneralException { + ArrayList keysExpiryDates = new ArrayList(); ViewGroup keyEditors = keysView.getEditors(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java index ea54f493e..0d9d590b4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java @@ -320,7 +320,7 @@ public class EncryptFileFragment extends Fragment { super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - AppMsg.makeText(getActivity(), R.string.encryption_successful, + AppMsg.makeText(getActivity(), R.string.encrypt_sign_successful, AppMsg.STYLE_INFO).show(); if (mDeleteAfter.isChecked()) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java index ba11074fc..b68df81df 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java @@ -229,7 +229,7 @@ public class EncryptMessageFragment extends Fragment { if (toClipboard) { ClipboardReflection.copyToClipboard(getActivity(), output); AppMsg.makeText(getActivity(), - R.string.encryption_to_clipboard_successful, AppMsg.STYLE_INFO) + R.string.encrypt_sign_clipboard_successful, AppMsg.STYLE_INFO) .show(); } else { Intent sendIntent = new Intent(Intent.ACTION_SEND); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 78731ca86..490be7674 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -64,9 +64,9 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { TextView mKeyId; TextView mCreationDate; BootstrapButton mExpiryDateButton; - GregorianCalendar mCreatedDate; - GregorianCalendar mExpiryDate; - GregorianCalendar mOriginalExpiryDate = null; + Calendar mCreatedDate; + Calendar mExpiryDate; + Calendar mOriginalExpiryDate = null; CheckBox mChkCertify; CheckBox mChkSign; CheckBox mChkEncrypt; @@ -145,9 +145,9 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mExpiryDateButton.setOnClickListener(new OnClickListener() { @TargetApi(11) public void onClick(View v) { - GregorianCalendar date = mExpiryDate; - if (date == null) { - date = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + Calendar expiryDate = mExpiryDate; + if (expiryDate == null) { + expiryDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); } /* * Using custom DatePickerDialog which overrides the setTitle because @@ -155,8 +155,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { * See: https://code.google.com/p/android/issues/detail?id=49066 */ DatePickerDialog dialog = new ExpiryDatePickerDialog(getContext(), - mExpiryDateSetListener, date.get(Calendar.YEAR), date.get(Calendar.MONTH), - date.get(Calendar.DAY_OF_MONTH)); + mExpiryDateSetListener, expiryDate.get(Calendar.YEAR), expiryDate.get(Calendar.MONTH), + expiryDate.get(Calendar.DAY_OF_MONTH)); mDatePickerResultCount = 0; dialog.setCancelable(true); dialog.setButton(Dialog.BUTTON_NEGATIVE, @@ -179,13 +179,16 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { dialog.getDatePicker().setCalendarViewShown(false); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { - if (dialog != null && mCreatedDate != null) { + + // will crash with IllegalArgumentException if we set a min date + // that is not before expiry + if (mCreatedDate != null && mCreatedDate.before(expiryDate)) { dialog.getDatePicker() .setMinDate( mCreatedDate.getTime().getTime() + DateUtils.DAY_IN_MILLIS); } else { - //When created date isn't available - dialog.getDatePicker().setMinDate(date.getTime().getTime() + DateUtils.DAY_IN_MILLIS); + // When created date isn't available + dialog.getDatePicker().setMinDate(expiryDate.getTime().getTime() + DateUtils.DAY_IN_MILLIS); } } @@ -243,7 +246,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mLabelUsage2.setVisibility(View.INVISIBLE); } - int selectId = 0; mIsNewKey = isNewKey; if (isNewKey) { mUsage = usage; @@ -263,10 +265,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); } - GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTime(PgpKeyHelper.getCreationDate(key)); setCreatedDate(cal); - cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); Date expiryDate = PgpKeyHelper.getExpiryDate(key); if (expiryDate == null) { setExpiryDate(null); @@ -296,7 +298,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mEditorListener = listener; } - private void setCreatedDate(GregorianCalendar date) { + private void setCreatedDate(Calendar date) { mCreatedDate = date; if (date == null) { mCreationDate.setText(getContext().getString(R.string.none)); @@ -305,7 +307,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } } - private void setExpiryDate(GregorianCalendar date) { + private void setExpiryDate(Calendar date) { mExpiryDate = date; if (date == null) { mExpiryDateButton.setText(getContext().getString(R.string.none)); @@ -314,7 +316,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } } - public GregorianCalendar getExpiryDate() { + public Calendar getExpiryDate() { return mExpiryDate; } -- cgit v1.2.3