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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<GregorianCalendar> getKeysExpiryDates(SectionView keysView) throws PgpGeneralException {
|
||||
ArrayList<GregorianCalendar> keysExpiryDates = new ArrayList<GregorianCalendar>();
|
||||
private ArrayList<Calendar> getKeysExpiryDates(SectionView keysView) throws PgpGeneralException {
|
||||
ArrayList<Calendar> keysExpiryDates = new ArrayList<Calendar>();
|
||||
|
||||
ViewGroup keyEditors = keysView.getEditors();
|
||||
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user