1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-13 19:06:13 +00:00

Merge pull request #253 from owncloud/master

1.0.1 stable
This commit is contained in:
David González Verdugo 2019-06-18 09:35:41 +02:00 committed by GitHub
commit 4870756ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 135 additions and 19 deletions

View File

@ -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'
}
}

View File

@ -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_1.0.1'
}
android {
@ -12,6 +12,9 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode = 10000100
versionName = "1.0.1"
}
lintOptions {

View File

@ -24,9 +24,7 @@
-->
<manifest package="com.owncloud.android.lib"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0">
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- USE_CREDENTIALS, MANAGE_ACCOUNTS and AUTHENTICATE_ACCOUNTS are needed for API < 23.
In API >= 23 the do not exist anymore -->

View File

@ -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

View File

@ -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 in API 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.

View File

@ -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;
}
}

View File

@ -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;
@ -13,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";
@ -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;
@ -32,37 +37,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 +76,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]);