diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2019-07-23 16:25:50 +0300 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2019-07-23 16:25:50 +0300 |
commit | 1af52a7a30b40325fe69f5fba64f5d9564a903d6 (patch) | |
tree | ac8c3d0a9cdc07887c523c1a7c8faf26e46da356 | |
parent | 68a20ecf63d2590afde9bba04c73ff0be73be227 (diff) |
made some quicksy registration errors more explicit
3 files changed, 30 insertions, 6 deletions
diff --git a/src/quicksy/java/eu/siacs/conversations/services/QuickConversationsService.java b/src/quicksy/java/eu/siacs/conversations/services/QuickConversationsService.java index cfa2f7775..319f160f7 100644 --- a/src/quicksy/java/eu/siacs/conversations/services/QuickConversationsService.java +++ b/src/quicksy/java/eu/siacs/conversations/services/QuickConversationsService.java @@ -8,13 +8,17 @@ import android.preference.PreferenceManager; import android.util.Log; import java.io.BufferedWriter; +import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.ConnectException; import java.net.HttpURLConnection; +import java.net.SocketTimeoutException; import java.net.URL; import java.net.UnknownHostException; +import java.security.GeneralSecurityException; import java.security.SecureRandom; +import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -29,10 +33,11 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import javax.net.ssl.SSLException; import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLPeerUnverifiedException; import eu.siacs.conversations.Config; -import eu.siacs.conversations.android.JabberIdContact; import eu.siacs.conversations.android.PhoneNumberContact; import eu.siacs.conversations.crypto.sasl.Plain; import eu.siacs.conversations.entities.Account; @@ -44,8 +49,6 @@ import eu.siacs.conversations.utils.PhoneNumberUtilWrapper; import eu.siacs.conversations.utils.SerialSingleThreadExecutor; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Namespace; -import eu.siacs.conversations.xmpp.OnIqPacketReceived; -import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.stanzas.IqPacket; import io.michaelrocks.libphonenumber.android.Phonenumber; import rocks.xmpp.addr.Jid; @@ -58,6 +61,9 @@ public class QuickConversationsService extends AbstractQuickConversationsService public static final int API_ERROR_CONNECT = -3; public static final int API_ERROR_SSL_HANDSHAKE = -4; public static final int API_ERROR_AIRPLANE_MODE = -5; + public static final int API_ERROR_SSL_CERTIFICATE = -6; + public static final int API_ERROR_SSL_GENERAL = -7; + public static final int API_ERROR_TIMEOUT = -8; private static final String API_DOMAIN = "api." + Config.QUICKSY_DOMAIN; @@ -135,7 +141,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService } } } - } catch (Exception e) { + } catch (IOException e) { final int code = getApiErrorCode(e); synchronized (mOnVerificationRequested) { for (OnVerificationRequested onVerificationRequested : mOnVerificationRequested) { @@ -232,7 +238,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService } } } - } catch (Exception e) { + } catch (IOException e) { final int code = getApiErrorCode(e); synchronized (mOnVerification) { for (OnVerification onVerification : mOnVerification) { @@ -265,7 +271,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService } - private int getApiErrorCode(Exception e) { + private int getApiErrorCode(final Exception e) { if (!service.hasInternetConnection()) { return API_ERROR_AIRPLANE_MODE; } else if (e instanceof UnknownHostException) { @@ -274,6 +280,12 @@ public class QuickConversationsService extends AbstractQuickConversationsService return API_ERROR_CONNECT; } else if (e instanceof SSLHandshakeException) { return API_ERROR_SSL_HANDSHAKE; + } else if (e instanceof SSLPeerUnverifiedException || e instanceof CertificateException) { + return API_ERROR_SSL_CERTIFICATE; + } else if (e instanceof SSLException || e instanceof GeneralSecurityException) { + return API_ERROR_SSL_GENERAL; + } else if (e instanceof SocketTimeoutException) { + return API_ERROR_TIMEOUT; } else { Log.d(Config.LOGTAG, e.getClass().getName()); return API_ERROR_OTHER; diff --git a/src/quicksy/java/eu/siacs/conversations/ui/util/ApiDialogHelper.java b/src/quicksy/java/eu/siacs/conversations/ui/util/ApiDialogHelper.java index d1f987bff..995fe3fca 100644 --- a/src/quicksy/java/eu/siacs/conversations/ui/util/ApiDialogHelper.java +++ b/src/quicksy/java/eu/siacs/conversations/ui/util/ApiDialogHelper.java @@ -33,6 +33,15 @@ public class ApiDialogHelper { case QuickConversationsService.API_ERROR_UNKNOWN_HOST: res = R.string.unable_to_find_server; break; + case QuickConversationsService.API_ERROR_SSL_CERTIFICATE: + res = R.string.unable_to_verify_server_identity; + break; + case QuickConversationsService.API_ERROR_SSL_GENERAL: + res = R.string.unknown_security_error; + break; + case QuickConversationsService.API_ERROR_TIMEOUT: + res = R.string.timeout_while_connecting_to_server; + break; case 400: res = R.string.invalid_user_input; break; diff --git a/src/quicksy/res/values/strings.xml b/src/quicksy/res/values/strings.xml index e9cfa3cae..54f7b1481 100644 --- a/src/quicksy/res/values/strings.xml +++ b/src/quicksy/res/values/strings.xml @@ -20,4 +20,7 @@ <string name="foreground_service_channel_description">This notification category is used to display a permanent notification indicating that Quicksy is running.</string> <string name="set_profile_picture">Quicksy profile picture</string> <string name="not_available_in_your_country">Quicksy is not available in your country.</string> + <string name="unable_to_verify_server_identity">Unable to verify server identity.</string> + <string name="unknown_security_error">Unknown security error.</string> + <string name="timeout_while_connecting_to_server">Timeout while connecting to server.</string> </resources> |