Permalink
Browse files

Fix for android 4.x

  • Loading branch information...
Michael van Leeuwen
Michael van Leeuwen committed Apr 23, 2012
1 parent c01ed05 commit 05a8e9ec8ca5f29ef911286a5a1817a099ec5e04
View
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xebia.xcoss.axcv"
- android:versionCode="5"
+ android:versionCode="6"
android:versionName="@string/app_version" >
<uses-sdk android:minSdkVersion="7" />
View
Binary file not shown.
@@ -151,7 +151,7 @@
<string name="auth_failed_title">Niet toegestaan</string>
<string name="auth_failed">Actie \'%s\' is niet toegestaan. Geef de juiste toegangsgegevens op.</string>
<string name="action_failed">Actie mislukt</string>
- <string name="communication_failure">Communicatiefout bij \'%1$s\' veroorzaakt door %2$s.</string>
+ <string name="communication_failure">Fout bij \'%1$s\': %2$s.</string>
<string name="server_unreachable">Server onbereikbaar</string>
<string name="server_missing_url">Geen resultaat bij \'%s\'</string>
<string name="server_timeout">Geen tijdige reactie op \'%s\'</string>
@@ -3,7 +3,7 @@
<string name="app_name">Conference Viewer</string>
<string name="app_full_name">Xebia Conference Viewer</string>
- <string name="app_version">0.7.4</string>
+ <string name="app_version">0.7.5</string>
<string name="app_help_url">http://xke.xebia.com/help</string>
<string name="splash_conference">Xebia Knowledge Exchange</string>
@@ -159,7 +159,7 @@
<string name="auth_failed_title">Not authorized</string>
<string name="auth_failed">Authentication failed for task \'%s\'. Please set credentials.</string>
<string name="action_failed">Action failed</string>
- <string name="communication_failure">Communication failure on \'%1$s\' due to %2$s.</string>
+ <string name="communication_failure">Failure on \'%1$s\': %2$s.</string>
<string name="server_unreachable">Server unreachable</string>
<string name="server_missing_url">No result for \'%s\'</string>
<string name="server_timeout">Time out on \'%s\'</string>
@@ -1,6 +1,9 @@
package com.xebia.xcoss.axcv.logic;
+import java.io.BufferedInputStream;
+import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
@@ -17,63 +20,113 @@
import org.apache.http.conn.ssl.SSLSocketFactory;
-import android.util.Log;
+import android.os.Build;
public class EC2TrustedSocketFactory extends SSLSocketFactory {
-
- private SSLContext sslContext = SSLContext.getInstance("TLS");
- public EC2TrustedSocketFactory() throws GeneralSecurityException, IOException {
- super(createKeyStore());
+ private SSLContext sslContext = SSLContext.getInstance("TLS");
+
+ public EC2TrustedSocketFactory() throws GeneralSecurityException, IOException {
+ super(createKeyStore());
X509TrustManager easyTrustManager = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
- for (X509Certificate x509Certificate : xcs) {
- Log.e("debug", "check Client: " + string + " * " + x509Certificate.getIssuerDN());
- }
+ // for (X509Certificate x509Certificate : xcs) {
+ // Log.e("debug", "check Client: " + string + " * " +
+ // x509Certificate.getIssuerDN());
+ // }
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
- for (X509Certificate x509Certificate : xcs) {
- x509Certificate.checkValidity();
- Log.e("debug", "check issuer : " + x509Certificate.getIssuerDN());
- Log.e("debug", "check subject: " + x509Certificate.getSubjectDN());
- }
+ // for (X509Certificate x509Certificate : xcs) {
+ // x509Certificate.checkValidity();
+ // Log.e("debug", "check issuer : " +
+ // x509Certificate.getIssuerDN());
+ // Log.e("debug", "check subject: " +
+ // x509Certificate.getSubjectDN());
+ // }
}
public X509Certificate[] getAcceptedIssuers() {
// TODO : Add the Comodo certificate
return null;
}
};
- sslContext.init(null, new TrustManager[] { easyTrustManager }, null);
- setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
- }
-
- private static KeyStore createKeyStore() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
- KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- FileInputStream is = new FileInputStream("/system/etc/security/cacerts.bks");
- trustStore.load(is, null);
-// Enumeration<String> e = trustStore.aliases();
-// while ( e.hasMoreElements() ) {
-// String key = e.nextElement();
-// Certificate certificate = trustStore.getCertificate(key);
-// String message = "?";
-// if ( certificate instanceof X509Certificate ) {
-// message = ((X509Certificate)certificate).getSubjectDN().toString();
-// }
-// Log.v("Security", message);
-// }
- return trustStore;
+ sslContext.init(null, new TrustManager[] { easyTrustManager }, null);
+ setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
+ }
+
+ private static KeyStore createKeyStore() throws KeyStoreException, NoSuchAlgorithmException, CertificateException,
+ IOException {
+ try {
+ KeyStore trustStore;
+
+ if (Build.VERSION.SDK_INT >= 14) {
+ trustStore = KeyStore.getInstance("AndroidCAStore");
+ trustStore.load(null, null);
+ } else {
+ trustStore = KeyStore.getInstance("BKS");
+ trustStore.load(new BufferedInputStream(new FileInputStream(getTrustStorePath())),
+ getTrustStorePassword().toCharArray());
+ }
+
+ return trustStore;
+ } catch (NoSuchAlgorithmException nsae) {
+ throw new AssertionError(nsae);
+ } catch (KeyStoreException e) {
+ throw new AssertionError(e);
+ } catch (CertificateException e) {
+ throw new AssertionError(e);
+ } catch (FileNotFoundException e) {
+ throw new AssertionError(e);
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+//
+// KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+// FileInputStream is = new FileInputStream("/system/etc/security/cacerts.bks");
+// trustStore.load(is, null);
+// // Enumeration<String> e = trustStore.aliases();
+// // while ( e.hasMoreElements() ) {
+// // String key = e.nextElement();
+// // Certificate certificate = trustStore.getCertificate(key);
+// // String message = "?";
+// // if ( certificate instanceof X509Certificate ) {
+// // message = ((X509Certificate)certificate).getSubjectDN().toString();
+// // }
+// // Log.v("Security", message);
+// // }
+// return trustStore;
+ }
+
+ private static String getTrustStorePath() {
+ String path = System.getProperty("javax.net.ssl.trustStore");
+
+ if (path == null) {
+ path = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security"
+ + File.separator + "cacerts.bks";
+ }
+
+ return path;
+ }
+
+ private static String getTrustStorePassword() {
+ String password = System.getProperty("javax.net.ssl.trustStorePassword");
+
+ if (password == null)
+ password = "changeit";
+
+ return password;
}
@Override
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
- return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
- }
-
- @Override
- public Socket createSocket() throws IOException {
- return sslContext.getSocketFactory().createSocket();
- }
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
+ UnknownHostException {
+ return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
+ }
+
+ @Override
+ public Socket createSocket() throws IOException {
+ return sslContext.getSocketFactory().createSocket();
+ }
}
@@ -339,6 +339,7 @@ private static DefaultHttpClient getHttpClient() {
} catch (Exception e) {
Log.e(XCS.LOG.COMMUNICATE, "Could not use secure connection: "
+ StringUtil.getExceptionMessage(e));
+ throw new RuntimeException(e);
}
ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(
params, registry);
@@ -4,7 +4,7 @@
public class StringUtil {
- public static final int LEN = 50;
+ public static final int LEN = 80;
public static boolean isEmpty(String value) {
return value == null || value.trim().length() == 0;

0 comments on commit 05a8e9e

Please sign in to comment.