Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Enable use of self-signed HTTP certificates.

  • Loading branch information...
commit c6ba9573122f330e42d663cb9fb749a211203249 1 parent bab5d74
Andrew Barr authored
View
4 .classpath
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="lib" path="/Users/kai/Projekte/eigene/SparkleShare-Android/libs/android-integration.jar"/>
+ <classpathentry kind="lib" path="libs/android-integration.jar"/>
+ <classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
View
51 res/values-fr_FR/strings.xml
@@ -1,51 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<resources>
- <string name="app_name">SparkleShare</string>
- <string name="version">1.0</string>
- <string name="welcome_sparkleshare">Bienvenue dans SparkleShare!</string>
- <string name="address">Addresse</string>
- <string name="host_hint">nom de domaine ou adresse IP</string>
- <string name="folder_name">Nom du dossier:</string>
- <string name="folder_name_hint">/home/user/repositoryname.git</string>
- <string name="email_address">Adresse Email</string>
- <string name="username">Nom d\'utilisateur</string>
- <string name="password">Mot de passe</string>
- <string name="link_code">Code d\'appairage</string>
- <string name="submit">soumettre</string>
- <string name="please_wait">Veuillez patienter...</string>
- <string name="login_error">Désolé mais nous n\'avons pas réussi à contacter le serveur...</string>
- <string name="close">Fermer</string>
- <string name="add_project">Ajouter le projet</string>
- <string name="adding_project">Ajout du projet en cours...</string>
- <string name="projects">SparkleShare</string>
- <string name="refresh">Actualiser</string>
- <string name="upload">Envoyer</string>
- <string name="activity_not_found">Désolé, il semble qu\'aucune des applications ne puisse ouvrir ce type de fichier.</string>
- <string name="scanner_app_not_found">Désolé, nous n\'avons pu trouver de scanner de code barre sur cet appareil.</string>
- <string name="not_implemented_yet">Pas encore implémenté</string>
- <string name="downloading">Téléchargement en cours...</string>
- <string name="downloading_failed">Désolé, une erreur s\'est produite pendant le téléchargement du fichier.</string>
- <string name="hint_sparkleshare_dashboard">Vous pouvez trouver cette information sur le tableau de bord de SparkleShare lorsque vous choisissez d\'appairer un nouvel appareil.</string>
- <string name="invalid_qr_code">QR code incorrect</string>
- <string name="home">Home</string>
- <string name="settings">Paramètres</string>
- <string name="info">A propos de SparkleShare</string>
- <string name="sparkleshare_account">Compte</string>
- <string name="settings_release_account">Oublier le compte</string>
- <string name="settings_hide_files_folders">Afficher les fichiers cachés</string>
- <string name="app_version">versioncode</string>
- <string name="setup_account">Saisissez le code d\'appairage</string>
- <string name="scan_qrcode">Scanner le QR code</string>
- <string name="are_you_sure">C\'est votre dernier mot?</string>
- <string name="release_account_hint">Etes-vous certain de vouloir oublier le compte courant?</string>
- <string name="release">Oublier</string>
- <string name="cancel">Annuler</string>
- <string name="get_started">Commencer par ajouter un projet:</string>
- <string name="never_mind">Tant pis</string>
- <string name="add">Ajouter</string>
- <string name="copyright">Copyright © 2011</string>
- <string name="authors">Kai Wolf, Hylke Bons et d\'autres.</string>
- <string name="disclaimer">SparkleShare est un logiciel gratuit et open source. Vous êtes libres de l\'utiliser, le modifier et le diffuser sous les termes de la license GNU General Public License (version 3 ou plus).</string>
- <string name="open_file">Ouvrir</string>
- <string name="download_file">Télécharger</string>
-</resources>
View
2  res/values/strings.xml
@@ -34,6 +34,8 @@
<string name="sparkleshare_account">Account</string>
<string name="settings_release_account">Forget account</string>
<string name="settings_hide_files_folders">Show hidden files</string>
+ <string name="sparkleshare_security">Security</string>
+ <string name="settings_accept_all_certificates">Accept all SSL certificates</string>
<string name="app_version">version</string>
<string name="setup_account">Enter link code</string>
<string name="scan_qrcode">Scan QR code</string>
View
5 res/xml/settings.xml
@@ -8,6 +8,11 @@
android:key="@string/settings_hide_files_folders"
android:title="@string/settings_hide_files_folders" />
</PreferenceCategory>
+ <PreferenceCategory android:title="@string/sparkleshare_security">
+ <CheckBoxPreference
+ android:key="@string/settings_accept_all_certificates"
+ android:title="@string/settings_accept_all_certificates" />
+ </PreferenceCategory>
<PreferenceCategory android:title="@string/info">
<Preference
android:key="@string/app_version"
View
23 src/org/sparkleshare/android/BrowsingActivity.java
@@ -11,12 +11,20 @@
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.sparkleshare.android.ui.BaseActivity;
import org.sparkleshare.android.ui.ListEntryItem;
+import org.transdroid.util.FakeSocketFactory;
import android.content.Context;
import android.content.ContextWrapper;
@@ -126,13 +134,26 @@ public void onConfigurationChanged(Configuration newConfig) {
protected void onPreExecute() {
}
+ private HttpClient getNewHttpClient() {
+ SharedPreferences sp = SettingsActivity.getSettings(BrowsingActivity.this);
+ boolean acceptAll = sp.getBoolean(getResources().getString(R.string.settings_accept_all_certificates), false);
+
+ SchemeRegistry s = new SchemeRegistry();
+ s.register(new Scheme("http", new PlainSocketFactory(), 80));
+ s.register(new Scheme("https", acceptAll ? new FakeSocketFactory() : SSLSocketFactory.getSocketFactory(), 443));
+
+ HttpParams httpParams = new BasicHttpParams();
+
+ return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, s), httpParams);
+ }
+
@Override
protected Boolean doInBackground(String... params) {
String server = params[0];
try {
// TODO: Refactor I/O here and in SetupActivity to central place
- HttpClient client = new DefaultHttpClient();
+ HttpClient client = getNewHttpClient();
HttpGet get = new HttpGet(server);
get.setHeader("X-SPARKLE-IDENT", ident);
get.setHeader("X-SPARKLE-AUTH", authCode);
View
24 src/org/sparkleshare/android/FileDetailsActivity.java
@@ -13,18 +13,27 @@
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
import org.sparkleshare.android.ui.BaseActivity;
import org.sparkleshare.android.ui.FormatHelper;
import org.sparkleshare.android.ui.ListEntryItem;
import org.sparkleshare.android.utils.ExternalDirectory;
import org.sparkleshare.android.utils.MimetypeChecker;
+import org.transdroid.util.FakeSocketFactory;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Color;
@@ -128,13 +137,26 @@ protected void onPreExecute() {
notification.contentIntent = intent;
}
+
+ private HttpClient getNewHttpClient() {
+ SharedPreferences sp = SettingsActivity.getSettings(FileDetailsActivity.this);
+ boolean acceptAll = sp.getBoolean(getResources().getString(R.string.settings_accept_all_certificates), false);
+
+ SchemeRegistry s = new SchemeRegistry();
+ s.register(new Scheme("http", new PlainSocketFactory(), 80));
+ s.register(new Scheme("https", acceptAll ? new FakeSocketFactory() : SSLSocketFactory.getSocketFactory(), 443));
+
+ HttpParams httpParams = new BasicHttpParams();
+
+ return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, s), httpParams);
+ }
@Override
protected Boolean doInBackground(ListEntryItem... params) {
// TODO: Check for connectivity
current = params[0];
try {
- HttpClient client = new DefaultHttpClient();
+ HttpClient client = getNewHttpClient();
HttpGet get = new HttpGet(current.getUrl());
get.setHeader("X-SPARKLE-IDENT", ident);
get.setHeader("X-SPARKLE-AUTH", authCode);
View
32 src/org/sparkleshare/android/SetupActivity.java
@@ -4,9 +4,15 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.security.SecureRandom;
+import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
@@ -14,11 +20,21 @@
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.SingleClientConnManager;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
import org.json.JSONException;
import org.json.JSONObject;
import org.sparkleshare.android.ui.BaseActivity;
+import org.transdroid.util.FakeSocketFactory;
import android.app.Activity;
import android.app.AlertDialog;
@@ -39,6 +55,7 @@
import android.widget.Button;
import android.widget.EditText;
+
/**
* This {@link Activity} handles a new setup for a SparkleShare instance.
* @author kai
@@ -145,9 +162,22 @@ protected void onPreExecute() {
loadingDialog = ProgressDialog.show(context, "", getString(R.string.adding_project));
}
+ private HttpClient getNewHttpClient() {
+ SharedPreferences sp = SettingsActivity.getSettings(SetupActivity.this);
+ boolean acceptAll = sp.getBoolean(getResources().getString(R.string.settings_accept_all_certificates), false);
+
+ SchemeRegistry s = new SchemeRegistry();
+ s.register(new Scheme("http", new PlainSocketFactory(), 80));
+ s.register(new Scheme("https", acceptAll ? new FakeSocketFactory() : SSLSocketFactory.getSocketFactory(), 443));
+
+ HttpParams httpParams = new BasicHttpParams();
+
+ return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, s), httpParams);
+ }
+
@Override
protected Boolean doInBackground(String... params) {
- HttpClient client = new DefaultHttpClient();
+ HttpClient client = getNewHttpClient();
serverUrl = params[0];
HttpPost post = new HttpPost(serverUrl + AUTH_SUFFIX);
try {
View
81 src/org/transdroid/util/FakeSocketFactory.java
@@ -0,0 +1,81 @@
+package org.transdroid.util;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.TrustManager;
+
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.conn.scheme.LayeredSocketFactory;
+import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+
+public class FakeSocketFactory implements SocketFactory, LayeredSocketFactory {
+
+ private SSLContext sslcontext = null;
+
+ private static SSLContext createEasySSLContext() throws IOException {
+ try {
+ SSLContext context = SSLContext.getInstance("TLS");
+ context.init(null, new TrustManager[] { new FakeTrustManager() }, null);
+ return context;
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ private SSLContext getSSLContext() throws IOException {
+ if (this.sslcontext == null) {
+ this.sslcontext = createEasySSLContext();
+ }
+ return this.sslcontext;
+ }
+
+ @Override
+ public Socket connectSocket(Socket sock, String host, int port,
+ InetAddress localAddress, int localPort, HttpParams params) throws IOException,
+ UnknownHostException, ConnectTimeoutException {
+ int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
+ int soTimeout = HttpConnectionParams.getSoTimeout(params);
+
+ InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
+ SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());
+
+ if ((localAddress != null) || (localPort > 0)) {
+ // we need to bind explicitly
+ if (localPort < 0) {
+ localPort = 0; // indicates "any"
+ }
+ InetSocketAddress isa = new InetSocketAddress(localAddress,
+ localPort);
+ sslsock.bind(isa);
+ }
+
+ sslsock.connect(remoteAddress, connTimeout);
+ sslsock.setSoTimeout(soTimeout);
+ return sslsock;
+ }
+
+ @Override
+ public Socket createSocket() throws IOException {
+ return getSSLContext().getSocketFactory().createSocket();
+ }
+
+ @Override
+ public boolean isSecure(Socket arg0) throws IllegalArgumentException {
+ return true;
+ }
+
+ @Override
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
+ throws IOException, UnknownHostException {
+ return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose);
+ }
+
+}
View
33 src/org/transdroid/util/FakeTrustManager.java
@@ -0,0 +1,33 @@
+package org.transdroid.util;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.X509TrustManager;
+
+public class FakeTrustManager implements X509TrustManager {
+
+ private static final X509Certificate[] _AcceptedIssuers = new X509Certificate[] {};
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ }
+
+ public boolean isClientTrusted(X509Certificate[] chain) {
+ return true;
+ }
+
+ public boolean isServerTrusted(X509Certificate[] chain) {
+ return true;
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return _AcceptedIssuers;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.