From a3744ce4f8aa054aea1c50096b43166555028eed Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 25 Oct 2018 18:16:02 +0200 Subject: [PATCH] improve openkeychain error reporting --- .../siacs/conversations/crypto/PgpEngine.java | 19 +++++++++++++++---- .../ui/ConversationFragment.java | 2 +- src/main/res/values/strings.xml | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java index 861b904b8..35528ab2c 100644 --- a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java @@ -2,6 +2,8 @@ package eu.siacs.conversations.crypto; import android.app.PendingIntent; import android.content.Intent; +import android.os.Parcelable; +import android.support.annotation.StringRes; import android.util.Log; import org.openintents.openpgp.OpenPgpError; @@ -39,7 +41,8 @@ public class PgpEngine { private static void logError(Account account, OpenPgpError error) { if (error != null) { - Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId()); + error.describeContents(); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId()+" class="+error.getClass().getName()); } else { Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error with no message"); } @@ -94,8 +97,16 @@ public class PgpEngine { callback.userInputRequried(result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), message); break; case OpenPgpApi.RESULT_CODE_ERROR: - logError(conversation.getAccount(), result.getParcelableExtra(OpenPgpApi.RESULT_ERROR)); - callback.error(R.string.openpgp_error, message); + OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); + String errorMessage = error != null ? error.getMessage() : null; + @StringRes final int res; + if (errorMessage != null && errorMessage.startsWith("Bad key for encryption")) { + res = R.string.bad_key_for_encryption; + } else { + res = R.string.openpgp_error; + } + logError(conversation.getAccount(), error); + callback.error(res, message); break; } }); @@ -174,7 +185,7 @@ public class PgpEngine { case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: return 0; case OpenPgpApi.RESULT_CODE_ERROR: - logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + logError(account, result.getParcelableExtra(OpenPgpApi.RESULT_ERROR)); return 0; } return 0; diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index f4f0329af..b39f7ed45 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -2537,7 +2537,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public void error(final int error, Message message) { getActivity().runOnUiThread(() -> { doneSendingPgpMessage(); - Toast.makeText(getActivity(), R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT).show(); + Toast.makeText(getActivity(), error == 0 ? R.string.unable_to_connect_to_keychain : error, Toast.LENGTH_SHORT).show(); }); } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 20e3357a2..9403e5e28 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -121,7 +121,8 @@ Confirm Messages Let your contacts know when you have received and read their messages UI - OpenKeychain reported an error + OpenKeychain reported an error. + Bad key for encryption. Accept An error has occurred Error