1
0
mirror of https://github.com/etesync/android synced 2024-12-27 17:08:11 +00:00

Bug fixes, SDK level 19

* use SDK level 19
* add action to all preference intents (fixes #92)
* use StrictHostnameVerifier instead of HttpsURLConnection.getDefaultHostnameVerifier() (fixes #88)
* use per-WebDavResource instead of static DavHttpClient to enable different settings for different accounts
This commit is contained in:
rfc2822 2013-11-22 14:27:44 +01:00
parent 1fc2679bd4
commit af698c584b
8 changed files with 44 additions and 51 deletions

View File

@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target. # Project target.
target=android-17 target=android-19

View File

@ -42,8 +42,8 @@
installieren, um Datenverlust beim Neustart zu vermeiden (dies ist ein Android/Play Store-Bug).</p> installieren, um Datenverlust beim Neustart zu vermeiden (dies ist ein Android/Play Store-Bug).</p>
<p>Weitere Informationen erhalten Sie auf der <a href="http://davdroid.bitfire.at?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">DAVdroid-Homepage</a>. <p>Weitere Informationen erhalten Sie auf der <a href="http://davdroid.bitfire.at?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">DAVdroid-Homepage</a>.
Dort finden Sie auch eine <a href="http://davdroid.bitfire.at/configuration?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">Anleitung zum Einrichten</a> Dort finden Sie auch eine <a href="http://davdroid.bitfire.at/configuration?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">Anleitung zum Einrichten</a>.
DAVdroid ist auf den Schutz der Privatsphäre ausgelegt (siehe <a href="http://davdroid.bitfire.at/privacy?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">Datenschutzrichtlinie</a>).</p> DAVdroid respektiert Ihre Privatsphäre (siehe <a href="http://davdroid.bitfire.at/privacy?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">Datenschutzrichtlinie</a>).</p>
<p><b>Bei Problemen lesen Sie bitte die <a href="http://davdroid.bitfire.at/configuration?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">häufig gestellten Fragen</a>. <p><b>Bei Problemen lesen Sie bitte die <a href="http://davdroid.bitfire.at/configuration?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">häufig gestellten Fragen</a>.
Im Falle eines Fehlers, der eindeutig durch DAVdroid verursacht wird, berichten Sie diesen wenn möglich auf Im Falle eines Fehlers, der eindeutig durch DAVdroid verursacht wird, berichten Sie diesen wenn möglich auf
@ -57,8 +57,7 @@
<a href="https://f-droid.org/app/at.bitfire.davdroid">über F-Droid bezogen werden</a>.</p> <a href="https://f-droid.org/app/at.bitfire.davdroid">über F-Droid bezogen werden</a>.</p>
<p>Es ist jedoch viel Arbeit, die App zu entwickeln und besser zu machen. Daher haben wir uns entschlossen, sie <p>Es ist jedoch viel Arbeit, die App zu entwickeln und besser zu machen. Daher haben wir uns entschlossen, sie
auch gegen eine kleine Gebühr in die Stores (Google Play, auch gegen eine kleine Gebühr in die Stores (Google Play, <a href="samsungapps://ProductDetail/at.bitfire.davdroid">Samsung Store</a>)
<a href="http://apps.samsung.com/earth/topApps/topAppsDetail.as?productId=000000665458">Samsung Store</a>)
zu stellen. Wenn Sie das Projekt unterstützen wollen, können Sie zu stellen. Wenn Sie das Projekt unterstützen wollen, können Sie
<a href="http://davdroid.bitfire.at/donate?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">für DAVdroid spenden</a> oder die App kaufen.</p> <a href="http://davdroid.bitfire.at/donate?pk_campaign=davdroid-app&amp;pk_kwd=main-activity">für DAVdroid spenden</a> oder die App kaufen.</p>

View File

@ -4,7 +4,8 @@
<Preference android:title="@string/davdroid_help" > <Preference android:title="@string/davdroid_help" >
<intent <intent
android:targetPackage="at.bitfire.davdroid" android:targetPackage="at.bitfire.davdroid"
android:targetClass="at.bitfire.davdroid.MainActivity" /> android:targetClass="at.bitfire.davdroid.MainActivity"
android:action="ACTION_VIEW" />
</Preference> </Preference>
</PreferenceScreen> </PreferenceScreen>

View File

@ -1,8 +1,5 @@
package at.bitfire.davdroid; package at.bitfire.davdroid;
import java.net.URI;
import java.net.URISyntaxException;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.util.Log; import android.util.Log;

View File

@ -1,34 +1,26 @@
package at.bitfire.davdroid.webdav; package at.bitfire.davdroid.webdav;
import org.apache.http.client.params.HttpClientParams; import org.apache.http.client.params.HttpClientParams;
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.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient; 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.BasicHttpParams;
import org.apache.http.params.CoreProtocolPNames; import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.webdav.GzipDecompressingEntity;
import at.bitfire.davdroid.webdav.TlsSniSocketFactory;
// see AndroidHttpClient // see AndroidHttpClient
public class DavHttpClient extends DefaultHttpClient { public class DavHttpClient extends DefaultHttpClient {
private static DavHttpClient httpClient = null; private DavHttpClient(HttpParams params) {
super(params);
private DavHttpClient(ClientConnectionManager connectionManager, HttpParams params) {
super(connectionManager, params);
} }
public static synchronized DefaultHttpClient getInstance() { public static DefaultHttpClient getDefault() {
if (httpClient == null) {
HttpParams params = new BasicHttpParams(); HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.USER_AGENT, "DAVdroid/" + Constants.APP_VERSION); params.setParameter(CoreProtocolPNames.USER_AGENT, "DAVdroid/" + Constants.APP_VERSION);
@ -41,17 +33,14 @@ public class DavHttpClient extends DefaultHttpClient {
// don't allow redirections // don't allow redirections
HttpClientParams.setRedirecting(params, false); HttpClientParams.setRedirecting(params, false);
// use our own, SNI-capable LayeredSocketFactory for https:// DavHttpClient httpClient = new DavHttpClient(params);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", new TlsSniSocketFactory(), 443));
httpClient = new DavHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params); // use our own, SNI-capable LayeredSocketFactory for https://
SchemeRegistry schemeRegistry = httpClient.getConnectionManager().getSchemeRegistry();
schemeRegistry.register(new Scheme("https", new TlsSniSocketFactory(), 443));
// allow gzip compression // allow gzip compression
GzipDecompressingEntity.enable(httpClient); GzipDecompressingEntity.enable(httpClient);
}
return httpClient; return httpClient;
} }

View File

@ -5,13 +5,14 @@ import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import org.apache.http.conn.scheme.LayeredSocketFactory; import org.apache.http.conn.scheme.LayeredSocketFactory;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import android.annotation.TargetApi; import android.annotation.TargetApi;
@ -28,6 +29,8 @@ public class TlsSniSocketFactory implements LayeredSocketFactory {
SSLCertificateSocketFactory sslSocketFactory = SSLCertificateSocketFactory sslSocketFactory =
(SSLCertificateSocketFactory) SSLCertificateSocketFactory.getInsecure(0, null); (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getInsecure(0, null);
final static HostnameVerifier hostnameVerifier = new StrictHostnameVerifier();
// Plain TCP/IP (layer below TLS) // Plain TCP/IP (layer below TLS)
@ -71,7 +74,7 @@ public class TlsSniSocketFactory implements LayeredSocketFactory {
throw new SSLException("Cannot verify SSL socket without session"); throw new SSLException("Cannot verify SSL socket without session");
// verify host name (important!) // verify host name (important!)
if (!HttpsURLConnection.getDefaultHostnameVerifier().verify(host, session)) if (!hostnameVerifier.verify(host, session))
throw new SSLPeerUnverifiedException("Cannot verify hostname: " + host); throw new SSLPeerUnverifiedException("Cannot verify hostname: " + host);
return ssl; return ssl;
} }

View File

@ -86,7 +86,7 @@ public class WebDavResource {
// content (available after GET) // content (available after GET)
@Getter protected InputStream content; @Getter protected InputStream content;
protected DefaultHttpClient client = DavHttpClient.getInstance(); protected DefaultHttpClient client;
public WebDavResource(URI baseURL, boolean trailingSlash) throws URISyntaxException { public WebDavResource(URI baseURL, boolean trailingSlash) throws URISyntaxException {
@ -99,22 +99,26 @@ public class WebDavResource {
public WebDavResource(URI baseURL, String username, String password, boolean preemptive, boolean trailingSlash) throws URISyntaxException { public WebDavResource(URI baseURL, String username, String password, boolean preemptive, boolean trailingSlash) throws URISyntaxException {
this(baseURL, trailingSlash); this(baseURL, trailingSlash);
client = DavHttpClient.getDefault();
// authenticate // authenticate
client.getCredentialsProvider().setCredentials(new AuthScope(location.getHost(), location.getPort()), client.getCredentialsProvider().setCredentials(
new UsernamePasswordCredentials(username, password)); new AuthScope(location.getHost(), location.getPort()),
// preemptive auth is available for Basic auth only new UsernamePasswordCredentials(username, password)
);
if (preemptive) { if (preemptive) {
Log.i(TAG, "Using preemptive Basic Authentication"); Log.i(TAG, "Using preemptive authentication (not compatible with Digest auth)");
client.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); client.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0);
} }
} }
protected WebDavResource(WebDavResource parent, URI uri) { protected WebDavResource(WebDavResource parent, URI uri) {
location = uri; location = uri;
client = parent.client;
} }
public WebDavResource(WebDavResource parent, String member) { public WebDavResource(WebDavResource parent, String member) {
location = parent.location.resolve(URIUtils.sanitize(member)); this(parent, parent.location.resolve(URIUtils.sanitize(member)));
} }
public WebDavResource(WebDavResource parent, String member, boolean trailingSlash) { public WebDavResource(WebDavResource parent, String member, boolean trailingSlash) {

View File

@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target. # Project target.
target=android-17 target=android-19