1
0
mirror of https://github.com/etesync/android synced 2024-11-26 09:58:11 +00:00

SSLSocketFactoryCompatTest

This commit is contained in:
Ricki Hirner 2015-10-19 16:55:01 +02:00
parent c93a89348e
commit 661276450c
No known key found for this signature in database
GPG Key ID: C4A212CF0B2B4566
18 changed files with 97 additions and 82 deletions

View File

@ -0,0 +1,52 @@
/*
* Copyright © 2013 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid;
import android.os.Build;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import junit.framework.TestCase;
import java.io.IOException;
import java.net.Socket;
import javax.net.ssl.SSLSocket;
public class SSLSocketFactoryCompatTest extends TestCase {
SSLSocketFactoryCompat factory = new SSLSocketFactoryCompat(null);
MockWebServer server = new MockWebServer();
@Override
protected void setUp() throws Exception {
server.start();
}
@Override
protected void tearDown() throws Exception {
server.shutdown();
}
public void testUpgradeTLS() throws IOException {
Socket s = factory.createSocket(server.getHostName(), server.getPort());
assertTrue(s instanceof SSLSocket);
SSLSocket ssl = (SSLSocket)s;
assertFalse(org.apache.commons.lang3.ArrayUtils.contains(ssl.getEnabledProtocols(), "SSLv3"));
assertTrue(org.apache.commons.lang3.ArrayUtils.contains(ssl.getEnabledProtocols(), "TLSv1"));
if (Build.VERSION.SDK_INT >= 16) {
assertTrue(org.apache.commons.lang3.ArrayUtils.contains(ssl.getEnabledProtocols(), "TLSv1.1"));
assertTrue(org.apache.commons.lang3.ArrayUtils.contains(ssl.getEnabledProtocols(), "TLSv1.2"));
}
}
}

View File

@ -35,7 +35,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
// Android 5.0+ (API level21) provides reasonable default settings // Android 5.0+ (API level21) provides reasonable default settings
// but it still allows SSLv3 // but it still allows SSLv3
// https://developer.android.com/about/versions/android-5.0-changes.html#ssl // https://developer.android.com/reference/javax/net/ssl/SSLSocket.html
static String protocols[] = null, cipherSuites[] = null; static String protocols[] = null, cipherSuites[] = null;
static { static {
try { try {
@ -109,17 +109,13 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
} }
private void upgradeTLS(SSLSocket ssl) { private void upgradeTLS(SSLSocket ssl) {
// Android 5.0+ (API level21) provides reasonable default settings
// but it still allows SSLv3
// https://developer.android.com/about/versions/android-5.0-changes.html#ssl
if (protocols != null) { if (protocols != null) {
Constants.log.debug("Setting allowed TLS protocols: " + TextUtils.join(", ", protocols)); Constants.log.debug("Setting allowed TLS protocols: " + TextUtils.join(", ", protocols));
ssl.setEnabledProtocols(protocols); ssl.setEnabledProtocols(protocols);
} }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && cipherSuites != null) { if (Build.VERSION.SDK_INT < 20 && cipherSuites != null) {
Constants.log.debug("Setting allowed TLS ciphers for Android <5: " + TextUtils.join(", ", protocols)); Constants.log.debug("Setting allowed TLS ciphers: " + TextUtils.join(", ", protocols));
ssl.setEnabledCipherSuites(cipherSuites); ssl.setEnabledCipherSuites(cipherSuites);
} }
} }

View File

@ -8,7 +8,6 @@
package at.bitfire.davdroid.log; package at.bitfire.davdroid.log;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import java.io.Closeable; import java.io.Closeable;

View File

@ -45,7 +45,6 @@ import at.bitfire.dav4android.property.CurrentUserPrivilegeSet;
import at.bitfire.dav4android.property.DisplayName; import at.bitfire.dav4android.property.DisplayName;
import at.bitfire.dav4android.property.ResourceType; import at.bitfire.dav4android.property.ResourceType;
import at.bitfire.dav4android.property.SupportedCalendarComponentSet; import at.bitfire.dav4android.property.SupportedCalendarComponentSet;
import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.HttpClient; import at.bitfire.davdroid.HttpClient;
import lombok.NonNull; import lombok.NonNull;

View File

@ -16,12 +16,11 @@ import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
import android.provider.ContactsContract.Data; import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Groups; import android.provider.ContactsContract.Groups;
import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
import java.security.acl.Group;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;

View File

@ -8,8 +8,6 @@
package at.bitfire.davdroid.resource; package at.bitfire.davdroid.resource;
import android.provider.ContactsContract;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.ical4android.CalendarStorageException;

View File

@ -18,8 +18,6 @@ import android.provider.CalendarContract.Events;
import net.fortuna.ical4j.model.property.ProdId; import net.fortuna.ical4j.model.property.ProdId;
import org.apache.commons.lang3.math.NumberUtils;
import at.bitfire.davdroid.BuildConfig; import at.bitfire.davdroid.BuildConfig;
import at.bitfire.ical4android.AndroidCalendar; import at.bitfire.ical4android.AndroidCalendar;
import at.bitfire.ical4android.AndroidEvent; import at.bitfire.ical4android.AndroidEvent;

View File

@ -8,10 +8,7 @@
package at.bitfire.davdroid.resource; package at.bitfire.davdroid.resource;
import android.content.ContentUris;
import android.content.ContentValues; import android.content.ContentValues;
import android.net.Uri;
import android.os.RemoteException;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import at.bitfire.vcard4android.AndroidAddressBook; import at.bitfire.vcard4android.AndroidAddressBook;

View File

@ -15,7 +15,6 @@ import android.provider.CalendarContract.Events;
import net.fortuna.ical4j.model.property.ProdId; import net.fortuna.ical4j.model.property.ProdId;
import org.apache.commons.lang3.math.NumberUtils;
import org.dmfs.provider.tasks.TaskContract.Tasks; import org.dmfs.provider.tasks.TaskContract.Tasks;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

View File

@ -7,14 +7,9 @@
*/ */
package at.bitfire.davdroid.resource; package at.bitfire.davdroid.resource;
import com.squareup.okhttp.HttpUrl;
import java.io.Serializable; import java.io.Serializable;
import java.net.URI; import java.net.URI;
import java.util.LinkedList;
import java.util.List;
import at.bitfire.dav4android.UrlUtils;
import lombok.Data; import lombok.Data;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;

View File

@ -20,7 +20,6 @@ import android.provider.CalendarContract;
import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.resource.LocalCalendar; import at.bitfire.davdroid.resource.LocalCalendar;
import at.bitfire.davdroid.resource.LocalContact;
import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.ical4android.CalendarStorageException;
public class CalendarsSyncAdapterService extends Service { public class CalendarsSyncAdapterService extends Service {

View File

@ -37,9 +37,9 @@ import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.exception.ConflictException; import at.bitfire.dav4android.exception.ConflictException;
import at.bitfire.dav4android.exception.DavException; import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException; import at.bitfire.dav4android.exception.HttpException;
import at.bitfire.dav4android.exception.UnauthorizedException;
import at.bitfire.dav4android.exception.PreconditionFailedException; import at.bitfire.dav4android.exception.PreconditionFailedException;
import at.bitfire.dav4android.exception.ServiceUnavailableException; import at.bitfire.dav4android.exception.ServiceUnavailableException;
import at.bitfire.dav4android.exception.UnauthorizedException;
import at.bitfire.dav4android.property.GetCTag; import at.bitfire.dav4android.property.GetCTag;
import at.bitfire.dav4android.property.GetETag; import at.bitfire.dav4android.property.GetETag;
import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.Constants;

View File

@ -16,10 +16,8 @@ import android.content.Intent;
import android.content.SyncResult; import android.content.SyncResult;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.provider.CalendarContract;
import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.resource.LocalCalendar;
import at.bitfire.davdroid.resource.LocalTaskList; import at.bitfire.davdroid.resource.LocalTaskList;
import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.ical4android.CalendarStorageException;
import at.bitfire.ical4android.TaskProvider; import at.bitfire.ical4android.TaskProvider;

View File

@ -9,12 +9,9 @@
package at.bitfire.davdroid.ui; package at.bitfire.davdroid.ui;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity; import android.app.Activity;
import android.app.LoaderManager; import android.app.LoaderManager;
import android.content.AsyncTaskLoader; import android.content.AsyncTaskLoader;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -24,9 +21,6 @@ import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Debug;
import android.os.Environment;
import android.provider.CalendarContract;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.Menu; import android.view.Menu;
@ -36,7 +30,6 @@ import android.widget.TextView;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
@ -44,7 +37,6 @@ import at.bitfire.dav4android.exception.HttpException;
import at.bitfire.davdroid.BuildConfig; import at.bitfire.davdroid.BuildConfig;
import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.R; import at.bitfire.davdroid.R;
import ezvcard.util.IOUtils;
public class DebugInfoActivity extends Activity implements LoaderManager.LoaderCallbacks<String> { public class DebugInfoActivity extends Activity implements LoaderManager.LoaderCallbacks<String> {
public static final String public static final String

View File

@ -12,8 +12,6 @@ import android.accounts.Account;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.DialogFragment; import android.app.DialogFragment;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.preference.ListPreference; import android.preference.ListPreference;

View File

@ -29,8 +29,6 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.List;
import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.R; import at.bitfire.davdroid.R;
import at.bitfire.davdroid.resource.LocalAddressBook; import at.bitfire.davdroid.resource.LocalAddressBook;

View File

@ -9,7 +9,6 @@ package at.bitfire.davdroid.ui.setup;
import android.app.DialogFragment; import android.app.DialogFragment;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;

View File

@ -21,7 +21,6 @@ import android.content.Intent;
import android.content.Loader; import android.content.Loader;
import android.os.Bundle; import android.os.Bundle;
import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;