From 4b0510d79192c0111171076ed7c2bc192f930cf9 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Thu, 7 Mar 2019 10:06:25 +0100 Subject: [PATCH 01/11] Android Studio 3.3.2 see what's changed https://androidstudio.googleblog.com/2019/03/android-studio-332-available.html --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index da14d602..0f79bf7f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + classpath 'com.android.tools.build:gradle:3.3.2' } } From 6b61e66318fa3e0d5ca3d08061d94a6d95cfbac6 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sat, 9 Feb 2019 10:39:25 +0100 Subject: [PATCH 02/11] add log level to output this is a pre-task to colorize log output and add ability to filter on loglevel --- .../android/lib/common/utils/Log_OC.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index bdfc2645..26c5255d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -32,37 +32,37 @@ public class Log_OC { public static void i(String TAG, String message) { Log.i(TAG, message); - appendLog(TAG + " : " + message); + appendLog("I: " + TAG + " : " + message); } public static void d(String TAG, String message) { Log.d(TAG, message); - appendLog(TAG + " : " + message); + appendLog("D: " + TAG + " : " + message); } public static void d(String TAG, String message, Exception e) { Log.d(TAG, message, e); - appendLog(TAG + " : " + message + " Exception : " + e.getStackTrace()); + appendLog("D: " + TAG + " : " + message + " Exception : " + e.getStackTrace()); } public static void e(String TAG, String message) { Log.e(TAG, message); - appendLog(TAG + " : " + message); + appendLog("E: " + TAG + " : " + message); } public static void e(String TAG, String message, Throwable e) { Log.e(TAG, message, e); - appendLog(TAG + " : " + message + " Exception : " + e.getStackTrace()); + appendLog("E: " + TAG + " : " + message + " Exception : " + e.getStackTrace()); } public static void v(String TAG, String message) { Log.v(TAG, message); - appendLog(TAG + " : " + message); + appendLog("V: " + TAG + " : " + message); } public static void w(String TAG, String message) { Log.w(TAG, message); - appendLog(TAG + " : " + message); + appendLog("W: " + TAG + " : " + message); } /** @@ -71,8 +71,7 @@ public class Log_OC { * @param storagePath : directory for keeping logs */ synchronized public static void startLogging(String storagePath) { - String logPath = storagePath + File.separator + - mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; + String logPath = storagePath + File.separator + mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; mFolder = new File(logPath); mLogFile = new File(mFolder + File.separator + mLogFileNames[0]); From 446ac7c489047a54c1eb39ef0518ba6a1a39934b Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sun, 10 Feb 2019 07:20:29 +0100 Subject: [PATCH 03/11] split log into debug and release --- .../java/com/owncloud/android/lib/common/utils/Log_OC.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index 26c5255d..f2e66b47 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -2,6 +2,8 @@ package com.owncloud.android.lib.common.utils; import android.util.Log; +import com.owncloud.android.lib.BuildConfig; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -21,7 +23,10 @@ public class Log_OC { private static File mFolder; private static BufferedWriter mBuf; - private static String[] mLogFileNames = {"currentLog.txt", "olderLog.txt"}; + private static String[] mLogFileNames = { + "currentLog" + BuildConfig.BUILD_TYPE + ".txt", + "olderLog" + BuildConfig.BUILD_TYPE + ".txt" + }; private static boolean isMaxFileSizeReached = false; private static boolean isEnabled = false; From 79283cd6ed6ebd97747e7ca48ad2b75009cb7da3 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sun, 10 Feb 2019 12:02:37 +0100 Subject: [PATCH 04/11] increase cache size --- .../main/java/com/owncloud/android/lib/common/utils/Log_OC.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index f2e66b47..47d49c07 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -15,7 +15,7 @@ import java.util.Locale; public class Log_OC { private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; private static final String LOG_FOLDER_NAME = "log"; - private static final long MAX_FILE_SIZE = 1000000; // 1MB + private static final long MAX_FILE_SIZE = 2000000; // 2MB private static String mOwncloudDataFolderLog = "owncloud_log"; From ec01a211376acea6c1e20a0c2f3436f22b2dc833 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 20 Feb 2019 18:16:37 +0100 Subject: [PATCH 05/11] Include TLSv1.2 support and make it work on 16 to 19 devices --- .../android/lib/common/http/HttpClient.java | 32 +++++++- .../lib/common/http/TLSSocketFactory.java | 82 +++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/TLSSocketFactory.java diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java index 566d98e9..e9f77fe4 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java @@ -26,6 +26,7 @@ package com.owncloud.android.lib.common.http; import android.content.Context; +import android.os.Build; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor; import com.owncloud.android.lib.common.http.interceptors.RequestHeaderInterceptor; @@ -39,8 +40,10 @@ import okhttp3.OkHttpClient; import okhttp3.Protocol; import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; +import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -67,9 +70,34 @@ public class HttpClient { try { final X509TrustManager trustManager = new AdvancedX509TrustManager( NetworkUtils.getKnownServersStore(sContext)); - final SSLContext sslContext = SSLContext.getInstance("TLS"); + + SSLContext sslContext; + + try { + sslContext = SSLContext.getInstance("TLSv1.2"); + } catch (NoSuchAlgorithmException tlsv12Exception) { + try { + Log_OC.w(TAG, "TLSv1.2 is not supported in this device; falling through TLSv1.1"); + sslContext = SSLContext.getInstance("TLSv1.1"); + } catch (NoSuchAlgorithmException tlsv11Exception) { + Log_OC.w(TAG, "TLSv1.1 is not supported in this device; falling through TLSv1.0"); + sslContext = SSLContext.getInstance("TLSv1"); + // should be available in any device; see reference of supported protocols in + // http://developer.android.com/reference/javax/net/ssl/SSLSocket.html + } + } + sslContext.init(null, new TrustManager[]{trustManager}, null); + SSLSocketFactory sslSocketFactory; + + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { + // TLS v1.2 is disabled by default from API 16 to 19, use custom SSLSocketFactory to enable it + sslSocketFactory = new TLSSocketFactory(sslContext.getSocketFactory()); + } else { + sslSocketFactory = sslContext.getSocketFactory(); + } + // Automatic cookie handling, NOT PERSISTENT CookieJar cookieJar = new CookieJar() { @Override @@ -97,7 +125,7 @@ public class HttpClient { .writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS) .connectTimeout(HttpConstants.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS) .followRedirects(false) - .sslSocketFactory(sslContext.getSocketFactory(), trustManager) + .sslSocketFactory(sslSocketFactory, trustManager) .hostnameVerifier((asdf, usdf) -> true) .cookieJar(cookieJar); // TODO: Not verifying the hostname against certificate. ask owncloud security human if this is ok. diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/TLSSocketFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/TLSSocketFactory.java new file mode 100644 index 00000000..9ec8815e --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/TLSSocketFactory.java @@ -0,0 +1,82 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2019 ownCloud GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib.common.http; + +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; + +public class TLSSocketFactory extends SSLSocketFactory { + private SSLSocketFactory mInternalSSLSocketFactory; + + public TLSSocketFactory(SSLSocketFactory delegate) { + mInternalSSLSocketFactory = delegate; + } + + @Override + public String[] getDefaultCipherSuites() { + return mInternalSSLSocketFactory.getDefaultCipherSuites(); + } + + @Override + public String[] getSupportedCipherSuites() { + return mInternalSSLSocketFactory.getSupportedCipherSuites(); + } + + @Override + public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { + return enableTLSOnSocket(mInternalSSLSocketFactory.createSocket(s, host, port, autoClose)); + } + + @Override + public Socket createSocket(String host, int port) throws IOException { + return enableTLSOnSocket(mInternalSSLSocketFactory.createSocket(host, port)); + } + + @Override + public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException { + return enableTLSOnSocket(mInternalSSLSocketFactory.createSocket(host, port, localHost, localPort)); + } + + @Override + public Socket createSocket(InetAddress host, int port) throws IOException { + return enableTLSOnSocket(mInternalSSLSocketFactory.createSocket(host, port)); + } + + @Override + public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws + IOException { + return enableTLSOnSocket(mInternalSSLSocketFactory.createSocket(address, port, localAddress, localPort)); + } + + private Socket enableTLSOnSocket(Socket socket) { + if(socket != null && (socket instanceof SSLSocket)) { + ((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"}); + } + return socket; + } +} From 510ec1798ed51e94ca73287017b26ab1eaa6c33c Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 8 Mar 2019 10:11:11 +0100 Subject: [PATCH 06/11] Get rid of TLS support for 16 to 18 API versions --- .../java/com/owncloud/android/lib/common/http/HttpClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java index e9f77fe4..b0b3e7a2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java @@ -91,8 +91,8 @@ public class HttpClient { SSLSocketFactory sslSocketFactory; - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { - // TLS v1.2 is disabled by default from API 16 to 19, use custom SSLSocketFactory to enable it + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { + // TLS v1.2 is disabled by default in API 19, use custom SSLSocketFactory to enable it sslSocketFactory = new TLSSocketFactory(sslContext.getSocketFactory()); } else { sslSocketFactory = sslContext.getSocketFactory(); From e233fe058711b1f8a02acea884aa867eb88a0c27 Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 2 May 2019 10:58:06 +0200 Subject: [PATCH 07/11] Use api instead of implementation to export dav4android dependency so the app can use it as well --- owncloudComLibrary/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 146f276f..eb0480cf 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.library' dependencies { api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11" - implementation 'com.gitlab.ownclouders:dav4android:oc_support' + api 'com.gitlab.ownclouders:dav4android:oc_support' } android { From 87841a55d04a72974efd4399e88ee0a045ba8856 Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 2 May 2019 12:29:45 +0200 Subject: [PATCH 08/11] Update dav4android tag --- owncloudComLibrary/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index eb0480cf..7e8ef744 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.library' dependencies { api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11" - api 'com.gitlab.ownclouders:dav4android:oc_support' + api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' } android { From b5efb1d6647212503de9a43abd3976bdc6de83f4 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 8 May 2019 16:16:18 +0200 Subject: [PATCH 09/11] Use UTF-8 when encoding authorization headers --- .../lib/common/authentication/OwnCloudBasicCredentials.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java index 5a83cf63..ab1ba3ef 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java @@ -27,6 +27,7 @@ import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.http.HttpClient; import com.owncloud.android.lib.common.http.HttpConstants; import okhttp3.Credentials; +import okhttp3.internal.Util; public class OwnCloudBasicCredentials implements OwnCloudCredentials { @@ -52,7 +53,7 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials { HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER); HttpClient.addHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER, - Credentials.basic(mUsername, mPassword)); + Credentials.basic(mUsername, mPassword, Util.UTF_8)); } @Override From f16ac0de97cb01279f8cd43740548c27ef8a760a Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 23 May 2019 10:15:59 +0200 Subject: [PATCH 10/11] Update version code and name in build.gradle --- owncloudComLibrary/build.gradle | 3 +++ owncloudComLibrary/src/main/AndroidManifest.xml | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 7e8ef744..a72a4edc 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -12,6 +12,9 @@ android { defaultConfig { minSdkVersion 19 targetSdkVersion 28 + + versionCode = 10000001 + versionName = "1.0.1-beta.1" } lintOptions { diff --git a/owncloudComLibrary/src/main/AndroidManifest.xml b/owncloudComLibrary/src/main/AndroidManifest.xml index fce28b17..4561b3f5 100644 --- a/owncloudComLibrary/src/main/AndroidManifest.xml +++ b/owncloudComLibrary/src/main/AndroidManifest.xml @@ -24,9 +24,7 @@ --> + xmlns:android="http://schemas.android.com/apk/res/android"> From 1b727ae71d3703bbe0a07a86551465583e5f9b54 Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 11 Jun 2019 10:11:18 +0200 Subject: [PATCH 11/11] Update versionCode and versionName --- owncloudComLibrary/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index a72a4edc..3dce97b1 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -13,8 +13,8 @@ android { minSdkVersion 19 targetSdkVersion 28 - versionCode = 10000001 - versionName = "1.0.1-beta.1" + versionCode = 10000100 + versionName = "1.0.1" } lintOptions {