From: David A. Velasco Date: Thu, 2 Aug 2012 11:28:33 +0000 (+0200) Subject: Fixed crash by URL with whitespaces in login page; reviewed error handling and user... X-Git-Tag: oc-android-1.4.3~215 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/38ece35da5372d828e79a9ba31bdcd828cb5cd52?ds=sidebyside Fixed crash by URL with whitespaces in login page; reviewed error handling and user info in connection checking --- diff --git a/res/values/strings.xml b/res/values/strings.xml index c0f0de0f..c482937e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -131,14 +131,19 @@ Testing connection… Malformed ownCloud configuration It seems that your ownCloud instance is not correctly configured. Contact your administrator for more details. - Unknown error occurred + Unknown error occurred! Unknown error occurred. Please contact authors and include logs from your device. - Can\'t establish connection - Couldn\'t establish connection to host. Please check hostname and server availability and try again. + Couldn\'t find host + Couldn\'t find the entered host. Please check hostname and server availability and try again. ownCloud instance not found Application couldn\'t find ownClound instance at given path. Please check your path and try again. - Secure connection established - Unknown error occurred! + The server took too long to respond + Malformed URL + SSL initialization failed + Unverified SSL server\'s identity + Unrecognized ownCloud server version + Couldn\'t establish connection + Secure connection established Login details Application terminated unexpectedly. Would you like to submit crash report? diff --git a/src/com/owncloud/android/authenticator/ConnectionCheckerRunnable.java b/src/com/owncloud/android/authenticator/ConnectionCheckerRunnable.java index d1d10706..52e4eb09 100644 --- a/src/com/owncloud/android/authenticator/ConnectionCheckerRunnable.java +++ b/src/com/owncloud/android/authenticator/ConnectionCheckerRunnable.java @@ -18,12 +18,20 @@ package com.owncloud.android.authenticator; +import java.io.IOException; import java.net.ConnectException; +import java.net.MalformedURLException; +import java.net.SocketException; import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URL; import java.net.UnknownHostException; +import javax.net.ssl.SSLException; import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLPeerUnverifiedException; +import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.json.JSONException; @@ -75,19 +83,17 @@ public class ConnectionCheckerRunnable implements Runnable { } if (mUrl.startsWith("http://") || mUrl.startsWith("https://")) { mLatestResult = (mUrl.startsWith("https://"))? ResultType.OK_SSL : ResultType.OK_NO_SSL; - tryConnection(Uri.parse(mUrl + AccountUtils.STATUS_PATH)); + tryConnection(mUrl + AccountUtils.STATUS_PATH); postResult(mLatestResult); } else { - Uri uri = Uri.parse("https://" + mUrl + AccountUtils.STATUS_PATH); - if (tryConnection(uri)) { + if (tryConnection("https://" + mUrl + AccountUtils.STATUS_PATH)) { postResult(ResultType.OK_SSL); return; } Log.d(TAG, "establishing secure connection failed, trying non secure connection"); - uri = Uri.parse("http://" + mUrl + AccountUtils.STATUS_PATH); - if (tryConnection(uri)) { + if (tryConnection("http://" + mUrl + AccountUtils.STATUS_PATH)) { postResult(ResultType.OK_NO_SSL); return; } @@ -99,12 +105,13 @@ public class ConnectionCheckerRunnable implements Runnable { return mOCVersion; } - private boolean tryConnection(Uri uri) { - WebdavClient wc = new WebdavClient(); - wc.allowSelfsignedCertificates(); - GetMethod get = new GetMethod(uri.toString()); + private boolean tryConnection(String urlSt) { boolean retval = false; try { + WebdavClient wc = new WebdavClient(); + wc.allowSelfsignedCertificates(); + URL url = new URL(urlSt); // better than android.net.Uri in this case; provides URL validation + GetMethod get = new GetMethod(url.toString()); int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT); switch (status) { case HttpStatus.SC_OK: { @@ -115,8 +122,10 @@ public class ConnectionCheckerRunnable implements Runnable { break; } mOCVersion = new OwnCloudVersion(json.getString("version")); - if (!mOCVersion.isVersionValid()) + if (!mOCVersion.isVersionValid()) { + mLatestResult = ResultType.BAD_OC_VERSION; break; + } retval = true; break; } @@ -131,19 +140,45 @@ public class ConnectionCheckerRunnable implements Runnable { Log.e(TAG, "Not handled status received from server: " + status); } + } catch (JSONException e) { + mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED; + Log.e(TAG, "JSON exception while trying connection (instance not configured) ", e); + + } catch (SocketException e) { + mLatestResult = ResultType.WRONG_CONNECTION; + Log.e(TAG, "Socket exception while trying connection", e); + + } catch (SocketTimeoutException e) { + mLatestResult = ResultType.TIMEOUT; + Log.e(TAG, "Socket timeout exception while trying connection", e); + + } catch (MalformedURLException e) { + mLatestResult = ResultType.INCORRECT_ADDRESS; + Log.e(TAG, "Connect exception while trying connection", e); + + } catch (UnknownHostException e) { + mLatestResult = ResultType.HOST_NOT_AVAILABLE; + Log.e(TAG, "Unknown host exception while trying connection", e); + + } catch (SSLPeerUnverifiedException e) { // specially meaningful SSLException + mLatestResult = ResultType.SSL_UNVERIFIED_SERVER; + Log.e(TAG, "SSL Peer Unverified exception while trying connection", e); + + } catch (SSLException e) { + mLatestResult = ResultType.SSL_INIT_ERROR; + Log.e(TAG, "SSL exception while trying connection", e); + + } catch (HttpException e) { // specific exceptions from org.apache.commons.httpclient + mLatestResult = ResultType.UNKNOWN_ERROR; + Log.e(TAG, "HTTP exception while trying connection", e); + + } catch (IOException e) { // UnkownsServiceException, and any other weird I/O Exception that could occur + mLatestResult = ResultType.UNKNOWN_ERROR; + Log.e(TAG, "I/O exception while trying connection", e); + } catch (Exception e) { - if (e instanceof UnknownHostException - || e instanceof ConnectException - || e instanceof SocketTimeoutException) { - mLatestResult = ResultType.HOST_NOT_AVAILABLE; - } else if (e instanceof JSONException) { - mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED; - } else if (e instanceof SSLHandshakeException) { - mLatestResult = ResultType.SSL_INIT_ERROR; - } else { - mLatestResult = ResultType.UNKNOWN_ERROR; - } - e.printStackTrace(); + mLatestResult = ResultType.UNKNOWN_ERROR; + Log.e(TAG, "Unexpected exception while trying connection", e); } return retval; diff --git a/src/com/owncloud/android/authenticator/OnConnectCheckListener.java b/src/com/owncloud/android/authenticator/OnConnectCheckListener.java index bca71ae7..3d66c3c0 100644 --- a/src/com/owncloud/android/authenticator/OnConnectCheckListener.java +++ b/src/com/owncloud/android/authenticator/OnConnectCheckListener.java @@ -3,7 +3,7 @@ package com.owncloud.android.authenticator; public interface OnConnectCheckListener { enum ResultType { - OK_SSL, OK_NO_SSL, SSL_INIT_ERROR, HOST_NOT_AVAILABLE, TIMEOUT, NO_NETWORK_CONNECTION, INORRECT_ADDRESS, INSTANCE_NOT_CONFIGURED, FILE_NOT_FOUND, UNKNOWN_ERROR + OK_SSL, OK_NO_SSL, SSL_INIT_ERROR, HOST_NOT_AVAILABLE, TIMEOUT, NO_NETWORK_CONNECTION, INCORRECT_ADDRESS, INSTANCE_NOT_CONFIGURED, FILE_NOT_FOUND, UNKNOWN_ERROR, WRONG_CONNECTION, SSL_UNVERIFIED_SERVER, BAD_OC_VERSION } public void onConnectionCheckResult(ResultType type); diff --git a/src/com/owncloud/android/ui/activity/AuthenticatorActivity.java b/src/com/owncloud/android/ui/activity/AuthenticatorActivity.java index 4aa7cddd..dbf9576e 100644 --- a/src/com/owncloud/android/ui/activity/AuthenticatorActivity.java +++ b/src/com/owncloud/android/ui/activity/AuthenticatorActivity.java @@ -249,7 +249,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void continueConnection(String prefix) { String url = ((TextView) findViewById(R.id.host_URL)).getText() - .toString(); + .toString().trim(); String username = ((TextView) findViewById(R.id.account_username)) .getText().toString(); String password = ((TextView) findViewById(R.id.account_password)) @@ -302,12 +302,33 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mStatusIcon = android.R.drawable.ic_partial_secure; } break; + case BAD_OC_VERSION: + mStatusIcon = R.drawable.common_error; + mStatusText = R.string.auth_bad_oc_version_title; + break; + case WRONG_CONNECTION: + mStatusIcon = R.drawable.common_error; + mStatusText = R.string.auth_wrong_connection_title; + break; case TIMEOUT: - case INORRECT_ADDRESS: + mStatusIcon = R.drawable.common_error; + mStatusText = R.string.auth_timeout_title; + break; + case INCORRECT_ADDRESS: + mStatusIcon = R.drawable.common_error; + mStatusText = R.string.auth_incorrect_address_title; + break; + case SSL_UNVERIFIED_SERVER: + mStatusIcon = R.drawable.common_error; + mStatusText = R.string.auth_ssl_unverified_server_title; + break; case SSL_INIT_ERROR: + mStatusIcon = R.drawable.common_error; + mStatusText = R.string.auth_ssl_general_error_title; + break; case HOST_NOT_AVAILABLE: mStatusIcon = R.drawable.common_error; - mStatusText = R.string.auth_unknow_host_title; + mStatusText = R.string.auth_unknown_host_title; break; case NO_NETWORK_CONNECTION: mStatusIcon = R.drawable.no_network; @@ -319,7 +340,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity break; case UNKNOWN_ERROR: mStatusIcon = R.drawable.common_error; - mStatusText = R.string.auth_unknow_error; + mStatusText = R.string.auth_unknown_error_title; break; case FILE_NOT_FOUND: mStatusIcon = R.drawable.common_error; @@ -341,7 +362,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (view.getId() == R.id.host_URL) { if (!hasFocus) { TextView tv = ((TextView) findViewById(R.id.host_URL)); - String uri = tv.getText().toString(); + String uri = tv.getText().toString().trim(); if (uri.length() != 0) { setResultIconAndText(R.drawable.progress_small, R.string.auth_testing_connection); diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 1e64bdfe..1fabe3ad 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -255,10 +255,10 @@ public class WebdavClient extends HttpClient { */ public static int tryToLogin(Uri uri, String username, String password) { int returnCode = 0; - WebdavClient client = new WebdavClient(); - client.setCredentials(username, password); - HeadMethod head = new HeadMethod(uri.toString()); try { + WebdavClient client = new WebdavClient(); + client.setCredentials(username, password); + HeadMethod head = new HeadMethod(uri.toString()); returnCode = client.executeMethod(head); } catch (HttpException e) { Log.e(TAG, "HTTP exception trying to login at " + uri.getEncodedPath(), e);