1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-19 12:23:00 +00:00

Add Log_OC class and update the log references

This commit is contained in:
jabarros
2014-09-12 09:30:54 +02:00
parent e43e43f51a
commit b0fe841c3e
33 changed files with 340 additions and 191 deletions
@@ -30,15 +30,12 @@ import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;
//import java.security.Provider;
import java.security.cert.X509Certificate;
//import java.util.Enumeration;
import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
//import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
@@ -48,8 +45,7 @@ import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
//import android.os.Build;
import android.util.Log;
import com.owncloud.android.lib.common.utils.Log_OC;
@@ -97,39 +93,39 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
/*
private void logSslInfo() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
Log.v(TAG, "SUPPORTED SSL PARAMETERS");
Log_OCv(TAG, "SUPPORTED SSL PARAMETERS");
logSslParameters(mSslContext.getSupportedSSLParameters());
Log.v(TAG, "DEFAULT SSL PARAMETERS");
Log_OCv(TAG, "DEFAULT SSL PARAMETERS");
logSslParameters(mSslContext.getDefaultSSLParameters());
Log.i(TAG, "CURRENT PARAMETERS");
Log.i(TAG, "Protocol: " + mSslContext.getProtocol());
Log_OCi(TAG, "CURRENT PARAMETERS");
Log_OCi(TAG, "Protocol: " + mSslContext.getProtocol());
}
Log.i(TAG, "PROVIDER");
Log_OCi(TAG, "PROVIDER");
logSecurityProvider(mSslContext.getProvider());
}
private void logSecurityProvider(Provider provider) {
Log.i(TAG, "name: " + provider.getName());
Log.i(TAG, "version: " + provider.getVersion());
Log.i(TAG, "info: " + provider.getInfo());
Log_OCi(TAG, "name: " + provider.getName());
Log_OCi(TAG, "version: " + provider.getVersion());
Log_OCi(TAG, "info: " + provider.getInfo());
Enumeration<?> keys = provider.propertyNames();
String key;
while (keys.hasMoreElements()) {
key = (String) keys.nextElement();
Log.i(TAG, " property " + key + " : " + provider.getProperty(key));
Log_OCi(TAG, " property " + key + " : " + provider.getProperty(key));
}
}
private void logSslParameters(SSLParameters params) {
Log.v(TAG, "Cipher suites: ");
Log_OCv(TAG, "Cipher suites: ");
String [] elements = params.getCipherSuites();
for (int i=0; i<elements.length ; i++) {
Log.v(TAG, " " + elements[i]);
Log_OCv(TAG, " " + elements[i]);
}
Log.v(TAG, "Protocols: ");
Log_OCv(TAG, "Protocols: ");
elements = params.getProtocols();
for (int i=0; i<elements.length ; i++) {
Log.v(TAG, " " + elements[i]);
Log_OCv(TAG, " " + elements[i]);
}
}
*/
@@ -154,7 +150,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
final InetAddress localAddress, final int localPort,
final HttpConnectionParams params) throws IOException,
UnknownHostException, ConnectTimeoutException {
Log.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + localPort + ", params: " + params);
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + localPort + ", params: " + params);
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
@@ -163,7 +159,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
//logSslInfo();
SocketFactory socketfactory = mSslContext.getSocketFactory();
Log.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
Log_OC.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
Socket socket = socketfactory.createSocket();
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
SocketAddress remoteaddr = new InetSocketAddress(host, port);
@@ -180,7 +176,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
*/
public Socket createSocket(String host, int port) throws IOException,
UnknownHostException {
Log.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
Socket socket = mSslContext.getSocketFactory().createSocket(host, port);
verifyPeerIdentity(host, port, socket);
return socket;
@@ -38,7 +38,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import android.util.Log;
import com.owncloud.android.lib.common.utils.Log_OC;
@@ -147,7 +147,7 @@ public class AdvancedX509TrustManager implements X509TrustManager {
try {
return (mKnownServersKeyStore.getCertificateAlias(cert) != null);
} catch (KeyStoreException e) {
Log.d(TAG, "Fail while checking certificate in the known-servers store");
Log_OC.d(TAG, "Fail while checking certificate in the known-servers store");
return false;
}
}
@@ -34,7 +34,7 @@ import org.apache.commons.httpclient.auth.AuthenticationException;
import org.apache.commons.httpclient.auth.InvalidCredentialsException;
import org.apache.commons.httpclient.auth.MalformedChallengeException;
import android.util.Log;
import com.owncloud.android.lib.common.utils.Log_OC;
@@ -129,7 +129,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
* @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
*/
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
Log.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");
Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");
BearerCredentials bearer = null;
try {
@@ -164,7 +164,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
* @return a basic authorization string
*/
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
Log.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");
Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");
if (method == null) {
throw new IllegalArgumentException("Method may not be null");
@@ -208,7 +208,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
* @since 3.0
*/
public static String authenticate(BearerCredentials credentials, String charset) {
Log.d(TAG, "enter BearerAuthScheme.authenticate(BearerCredentials, String)");
Log_OC.d(TAG, "enter BearerAuthScheme.authenticate(BearerCredentials, String)");
if (credentials == null) {
throw new IllegalArgumentException("Credentials may not be null");
@@ -36,8 +36,7 @@ import java.util.Set;
import org.apache.commons.httpclient.methods.RequestEntity;
import android.util.Log;
import com.owncloud.android.lib.common.utils.Log_OC;
/**
@@ -142,7 +141,7 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres
}
} catch (IOException io) {
Log.e(TAG, io.getMessage());
Log_OC.e(TAG, io.getMessage());
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
}
@@ -38,7 +38,7 @@ import java.util.Set;
import org.apache.commons.httpclient.methods.RequestEntity;
import android.util.Log;
import com.owncloud.android.lib.common.utils.Log_OC;
@@ -126,7 +126,7 @@ public class FileRequestEntity implements RequestEntity, ProgressiveDataTransfer
}
} catch (IOException io) {
Log.e("FileRequestException", io.getMessage());
Log_OC.e("FileRequestException", io.getMessage());
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
} finally {
@@ -45,7 +45,8 @@ import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import android.content.Context;
import android.util.Log;
import com.owncloud.android.lib.common.utils.Log_OC;
public class NetworkUtils {
@@ -133,7 +134,7 @@ public class NetworkUtils {
//mKnownServersStore = KeyStore.getInstance("BKS");
mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType());
File localTrustStoreFile = new File(context.getFilesDir(), LOCAL_TRUSTSTORE_FILENAME);
Log.d(TAG, "Searching known-servers store at " + localTrustStoreFile.getAbsolutePath());
Log_OC.d(TAG, "Searching known-servers store at " + localTrustStoreFile.getAbsolutePath());
if (localTrustStoreFile.exists()) {
InputStream in = new FileInputStream(localTrustStoreFile);
try {
@@ -175,7 +176,7 @@ public class NetworkUtils {
public static boolean isCertInKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
KeyStore knownServers = getKnownServersStore(context);
Log.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
+ Boolean.toString(knownServers.isCertificateEntry(Integer.toString(cert.hashCode()))));
return knownServers.isCertificateEntry(Integer.toString(cert.hashCode()));
}
@@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.net.ssl.SSLSocket;
import android.util.Log;
import com.owncloud.android.lib.common.utils.Log_OC;
/**
@@ -80,19 +80,19 @@ public class ServerNameIndicator {
if (setHostnameMethod != null) {
try {
setHostnameMethod.invoke(sslSocket, hostname);
Log.i(TAG, "SNI done, hostname: " + hostname);
Log_OC.i(TAG, "SNI done, hostname: " + hostname);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
} catch (IllegalAccessException e) {
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
Log_OC.e(TAG, "Call to SSLSocket#setHost(String) failed ", e);
}
} else {
Log.i(TAG, "SNI not supported");
Log_OC.i(TAG, "SNI not supported");
}
}
@@ -134,15 +134,15 @@ public class ServerNameIndicator {
* @return Method to call to indicate the server name of interest to the server.
*/
private static Method initFrom(Class<?> sslSocketClass) {
Log.i(TAG, "SSLSocket implementation: " + sslSocketClass.getCanonicalName());
Log_OC.i(TAG, "SSLSocket implementation: " + sslSocketClass.getCanonicalName());
Method setHostnameMethod = null;
try {
setHostnameMethod = sslSocketClass.getMethod(METHOD_NAME, String.class);
} catch (SecurityException e) {
Log.e(TAG, "Could not access to SSLSocket#setHostname(String) method ", e);
Log_OC.e(TAG, "Could not access to SSLSocket#setHostname(String) method ", e);
} catch (NoSuchMethodException e) {
Log.i(TAG, "Could not find SSLSocket#setHostname(String) method - SNI not supported");
Log_OC.i(TAG, "Could not find SSLSocket#setHostname(String) method - SNI not supported");
}
mSingleInstance.set(new ServerNameIndicator(sslSocketClass, setHostnameMethod));
return setHostnameMethod;
@@ -33,7 +33,8 @@ import org.apache.jackrabbit.webdav.property.DavPropertySet;
import org.apache.jackrabbit.webdav.xml.Namespace;
import android.net.Uri;
import android.util.Log;
import com.owncloud.android.lib.common.utils.Log_OC;
public class WebdavEntry {
private static final String NAMESPACE_OC = "http://owncloud.org/ns";
@@ -125,7 +126,7 @@ public class WebdavEntry {
}
} else {
Log.e("WebdavEntry",
Log_OC.e("WebdavEntry",
"General fuckup, no status for webdav response");
}
}