1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Handle SIGNATURE_SUCCESS_UNCERTIFIED, code cleanup

This commit is contained in:
Dominik Schürmann 2014-03-04 15:10:20 +01:00
parent 4a69ef1509
commit f5b1ed920b
3 changed files with 43 additions and 24 deletions

View File

@ -23,7 +23,7 @@
android:maxLines="1" android:maxLines="1"
android:padding="2dp" android:padding="2dp"
android:singleLine="true" android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:textColorPrimaryInverse" android:textColor="?android:textColorPrimaryInverse"
android:textIsSelectable="false" /> android:textIsSelectable="false" />

View File

@ -1157,11 +1157,13 @@ Please submit bug reports, contribute new features and ask questions at
<!-- === OpenPGP specific ================================================================== --> <!-- === OpenPGP specific ================================================================== -->
<string name="openpgp_decrypting_verifying">Decrypting/Verifying…</string> <string name="openpgp_decrypting_verifying">Decrypting/Verifying…</string>
<string name="openpgp_successful_decryption">Successful decryption</string> <string name="openpgp_successful_decryption">Successful decryption</string>
<string name="openpgp_signature_valid">Valid signature</string> <string name="openpgp_signature_valid_certified">Valid signature (certified)</string>
<string name="openpgp_signature_valid_uncertified">Valid signature but uncertified</string>
<string name="openpgp_signature_unknown">Unknown signer</string> <string name="openpgp_signature_unknown">Unknown signer</string>
<string name="openpgp_signature_invalid">Invalid signature</string> <string name="openpgp_signature_invalid">Invalid signature</string>
<string name="openpgp_signature_unknown_text">Missing public key for this signature</string> <string name="openpgp_signature_unknown_text">Missing public key for this signature</string>
<string name="openpgp_successful_decryption_valid_signature">Successful decryption and valid signature</string> <string name="openpgp_successful_decryption_valid_signature_certified">Successful decryption and valid signature (certified)</string>
<string name="openpgp_successful_decryption_valid_signature_uncertified">Successful decryption and valid signature but uncertified</string>
<string name="openpgp_successful_decryption_unknown_signature">Successful decryption but missing public key</string> <string name="openpgp_successful_decryption_unknown_signature">Successful decryption but missing public key</string>
<string name="openpgp_get_key">Lookup missing key</string> <string name="openpgp_get_key">Lookup missing key</string>
<string name="openpgp_error">OpenPGP Error:</string> <string name="openpgp_error">OpenPGP Error:</string>

View File

@ -116,15 +116,17 @@ public class MessageOpenPgpView extends LinearLayout {
return; return;
} }
if (decryptedData != null && signatureResult == null) { if (decryptedData != null && signatureResult == null) {
// only decrypt // encrypted-only
Log.d(K9.LOG_TAG, "null!");
MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor( MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor(
R.color.openpgp_blue)); R.color.openpgp_blue));
mText.setText(R.string.openpgp_successful_decryption); mText.setText(R.string.openpgp_successful_decryption);
// don't process further // don't process further
return; return;
} else if (signatureResult != null && decryptedData != null) { } else if (decryptedData != null && signatureResult != null) {
// decryptAndVerify / only verify // signed-only and signed-and-encrypted
switch (signatureResult.getStatus()) { switch (signatureResult.getStatus()) {
case OpenPgpSignatureResult.SIGNATURE_ERROR: case OpenPgpSignatureResult.SIGNATURE_ERROR:
@ -133,16 +135,16 @@ public class MessageOpenPgpView extends LinearLayout {
MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor( MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor(
R.color.openpgp_red)); R.color.openpgp_red));
// mSignatureStatusImage.setImageResource(R.drawable.overlay_error); mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
mSignatureLayout.setVisibility(View.GONE); mSignatureLayout.setVisibility(View.GONE);
break; break;
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED:
if (signatureResult.isSignatureOnly()) { if (signatureResult.isSignatureOnly()) {
mText.setText(R.string.openpgp_signature_valid); mText.setText(R.string.openpgp_signature_valid_certified);
} }
else { else {
mText.setText(R.string.openpgp_successful_decryption_valid_signature); mText.setText(R.string.openpgp_successful_decryption_valid_signature_certified);
} }
MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor( MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor(
R.color.openpgp_green)); R.color.openpgp_green));
@ -170,6 +172,22 @@ public class MessageOpenPgpView extends LinearLayout {
break; break;
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED:
if (signatureResult.isSignatureOnly()) {
mText.setText(R.string.openpgp_signature_valid_uncertified);
}
else {
mText.setText(R.string.openpgp_successful_decryption_valid_signature_uncertified);
}
MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor(
R.color.openpgp_orange));
mSignatureUserId.setText(signatureResult.getUserId());
mSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
mSignatureLayout.setVisibility(View.VISIBLE);
break;
default: default:
break; break;
} }
@ -294,8 +312,11 @@ public class MessageOpenPgpView extends LinearLayout {
sigResult = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE); sigResult = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
} }
if (sigResult == null)
Log.d(K9.LOG_TAG, "sig null");
if (K9.DEBUG) if (K9.DEBUG)
Log.d(OpenPgpApi.TAG, "result: " + os.toByteArray().length Log.d(K9.LOG_TAG, "result: " + os.toByteArray().length
+ " str=" + output); + " str=" + output);
// missing key -> PendingIntent to get keys // missing key -> PendingIntent to get keys
@ -323,7 +344,7 @@ public class MessageOpenPgpView extends LinearLayout {
} }
case OpenPgpApi.RESULT_CODE_ERROR: { case OpenPgpApi.RESULT_CODE_ERROR: {
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERRORS); OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERRORS);
handleError(error, true); handleError(error);
break; break;
} }
} }
@ -337,12 +358,11 @@ public class MessageOpenPgpView extends LinearLayout {
// try again after user interaction // try again after user interaction
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_DECRYPT_VERIFY) { if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_DECRYPT_VERIFY) {
/* /*
* The data originally given to the pgp method are are again * The data originally given to the decryptVerify() method, is again
* returned here to be used when calling again after user * returned here to be used when calling decryptVerify() after user
* interaction. They also contain results from the user interaction * interaction. The Intent now also contains results from the user
* which happened, for example selected key ids. * interaction, for example selected key ids.
*/ */
decryptVerify(data); decryptVerify(data);
return true; return true;
@ -351,7 +371,7 @@ public class MessageOpenPgpView extends LinearLayout {
return false; return false;
} }
private void handleError(final OpenPgpError error, final boolean changeColor) { private void handleError(final OpenPgpError error) {
mFragment.getActivity().runOnUiThread(new Runnable() { mFragment.getActivity().runOnUiThread(new Runnable() {
@Override @Override
@ -359,15 +379,12 @@ public class MessageOpenPgpView extends LinearLayout {
mProgress.setVisibility(View.GONE); mProgress.setVisibility(View.GONE);
if (K9.DEBUG) { if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "handleError getErrorId:" + error.getErrorId()); Log.d(K9.LOG_TAG, "OpenPGP Error ID:" + error.getErrorId());
Log.d(K9.LOG_TAG, "handleError getMessage:" + error.getMessage()); Log.d(K9.LOG_TAG, "OpenPGP Error Message:" + error.getMessage());
} }
// TODO: better error handling with ids?
mText.setText(mFragment.getString(R.string.openpgp_error) + " " mText.setText(mFragment.getString(R.string.openpgp_error) + " "
+ error.getMessage()); + error.getMessage());
if (changeColor)
MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor( MessageOpenPgpView.this.setBackgroundColor(mFragment.getResources().getColor(
R.color.openpgp_red)); R.color.openpgp_red));
} }