diff --git a/app/src/androidTest/java/at/bitfire/davdroid/SSLSocketFactoryCompatTest.java b/app/src/androidTest/java/at/bitfire/davdroid/SSLSocketFactoryCompatTest.java new file mode 100644 index 00000000..f8ba5744 --- /dev/null +++ b/app/src/androidTest/java/at/bitfire/davdroid/SSLSocketFactoryCompatTest.java @@ -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")); + } + } + +} diff --git a/app/src/main/java/at/bitfire/davdroid/SSLSocketFactoryCompat.java b/app/src/main/java/at/bitfire/davdroid/SSLSocketFactoryCompat.java index edb45883..e996c31e 100644 --- a/app/src/main/java/at/bitfire/davdroid/SSLSocketFactoryCompat.java +++ b/app/src/main/java/at/bitfire/davdroid/SSLSocketFactoryCompat.java @@ -35,7 +35,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory { // 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 + // https://developer.android.com/reference/javax/net/ssl/SSLSocket.html static String protocols[] = null, cipherSuites[] = null; static { try { @@ -109,17 +109,13 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory { } 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) { Constants.log.debug("Setting allowed TLS protocols: " + TextUtils.join(", ", protocols)); ssl.setEnabledProtocols(protocols); } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && cipherSuites != null) { - Constants.log.debug("Setting allowed TLS ciphers for Android <5: " + TextUtils.join(", ", protocols)); + if (Build.VERSION.SDK_INT < 20 && cipherSuites != null) { + Constants.log.debug("Setting allowed TLS ciphers: " + TextUtils.join(", ", protocols)); ssl.setEnabledCipherSuites(cipherSuites); } } diff --git a/app/src/main/java/at/bitfire/davdroid/log/ExternalFileLogger.java b/app/src/main/java/at/bitfire/davdroid/log/ExternalFileLogger.java index 189bff87..07e61a3a 100644 --- a/app/src/main/java/at/bitfire/davdroid/log/ExternalFileLogger.java +++ b/app/src/main/java/at/bitfire/davdroid/log/ExternalFileLogger.java @@ -8,7 +8,6 @@ package at.bitfire.davdroid.log; -import android.app.Activity; import android.content.Context; import java.io.Closeable; diff --git a/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java b/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java index 3e541c79..0189b59a 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java @@ -45,7 +45,6 @@ import at.bitfire.dav4android.property.CurrentUserPrivilegeSet; import at.bitfire.dav4android.property.DisplayName; import at.bitfire.dav4android.property.ResourceType; import at.bitfire.dav4android.property.SupportedCalendarComponentSet; -import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.HttpClient; import lombok.NonNull; diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java index f0c5c941..3703d82c 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java @@ -16,12 +16,11 @@ import android.os.Bundle; import android.os.Parcel; import android.os.RemoteException; import android.provider.ContactsContract; +import android.provider.ContactsContract.CommonDataKinds.GroupMembership; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.Groups; import android.provider.ContactsContract.RawContacts; -import android.provider.ContactsContract.CommonDataKinds.GroupMembership; -import java.security.acl.Group; import java.util.LinkedList; import java.util.List; diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalCollection.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalCollection.java index b165c294..d2a51218 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalCollection.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalCollection.java @@ -8,8 +8,6 @@ package at.bitfire.davdroid.resource; -import android.provider.ContactsContract; - import java.io.FileNotFoundException; import at.bitfire.ical4android.CalendarStorageException; diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalEvent.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalEvent.java index 0dc13b4c..d6decc78 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalEvent.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalEvent.java @@ -18,8 +18,6 @@ import android.provider.CalendarContract.Events; import net.fortuna.ical4j.model.property.ProdId; -import org.apache.commons.lang3.math.NumberUtils; - import at.bitfire.davdroid.BuildConfig; import at.bitfire.ical4android.AndroidCalendar; import at.bitfire.ical4android.AndroidEvent; diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalGroup.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalGroup.java index 03cb62d6..f0dc7874 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalGroup.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalGroup.java @@ -8,10 +8,7 @@ package at.bitfire.davdroid.resource; -import android.content.ContentUris; import android.content.ContentValues; -import android.net.Uri; -import android.os.RemoteException; import android.provider.ContactsContract; import at.bitfire.vcard4android.AndroidAddressBook; diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalTask.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalTask.java index c2352a6a..8175c119 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalTask.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalTask.java @@ -15,7 +15,6 @@ import android.provider.CalendarContract.Events; import net.fortuna.ical4j.model.property.ProdId; -import org.apache.commons.lang3.math.NumberUtils; import org.dmfs.provider.tasks.TaskContract.Tasks; import java.io.FileNotFoundException; diff --git a/app/src/main/java/at/bitfire/davdroid/resource/ServerInfo.java b/app/src/main/java/at/bitfire/davdroid/resource/ServerInfo.java index 462303c1..39d4e808 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/ServerInfo.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/ServerInfo.java @@ -7,14 +7,9 @@ */ package at.bitfire.davdroid.resource; -import com.squareup.okhttp.HttpUrl; - import java.io.Serializable; import java.net.URI; -import java.util.LinkedList; -import java.util.List; -import at.bitfire.dav4android.UrlUtils; import lombok.Data; import lombok.RequiredArgsConstructor; diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java index 914ecfb7..f05e6cfd 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java @@ -20,7 +20,6 @@ import android.provider.CalendarContract; import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.resource.LocalCalendar; -import at.bitfire.davdroid.resource.LocalContact; import at.bitfire.ical4android.CalendarStorageException; public class CalendarsSyncAdapterService extends Service { diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java index 34b98e82..9b00db39 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -7,51 +7,51 @@ */ package at.bitfire.davdroid.syncadapter; -import android.accounts.Account; -import android.annotation.TargetApi; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.ContentResolver; -import android.content.Context; -import android.content.Intent; -import android.content.SyncResult; -import android.os.Build; -import android.os.Bundle; -import android.text.TextUtils; + import android.accounts.Account; + import android.annotation.TargetApi; + import android.app.Notification; + import android.app.NotificationManager; + import android.app.PendingIntent; + import android.content.ContentResolver; + import android.content.Context; + import android.content.Intent; + import android.content.SyncResult; + import android.os.Build; + import android.os.Bundle; + import android.text.TextUtils; -import com.squareup.okhttp.HttpUrl; -import com.squareup.okhttp.RequestBody; + import com.squareup.okhttp.HttpUrl; + import com.squareup.okhttp.RequestBody; -import org.slf4j.Logger; + import org.slf4j.Logger; -import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; + import java.io.IOException; + import java.util.Date; + import java.util.HashMap; + import java.util.HashSet; + import java.util.Map; + import java.util.Set; + import java.util.UUID; -import at.bitfire.dav4android.DavResource; -import at.bitfire.dav4android.exception.ConflictException; -import at.bitfire.dav4android.exception.DavException; -import at.bitfire.dav4android.exception.HttpException; -import at.bitfire.dav4android.exception.UnauthorizedException; -import at.bitfire.dav4android.exception.PreconditionFailedException; -import at.bitfire.dav4android.exception.ServiceUnavailableException; -import at.bitfire.dav4android.property.GetCTag; -import at.bitfire.dav4android.property.GetETag; -import at.bitfire.davdroid.Constants; -import at.bitfire.davdroid.HttpClient; -import at.bitfire.davdroid.R; -import at.bitfire.davdroid.log.ExternalFileLogger; -import at.bitfire.davdroid.resource.LocalCollection; -import at.bitfire.davdroid.resource.LocalResource; -import at.bitfire.davdroid.ui.DebugInfoActivity; -import at.bitfire.davdroid.ui.settings.AccountActivity; -import at.bitfire.ical4android.CalendarStorageException; -import at.bitfire.vcard4android.ContactsStorageException; + import at.bitfire.dav4android.DavResource; + import at.bitfire.dav4android.exception.ConflictException; + import at.bitfire.dav4android.exception.DavException; + import at.bitfire.dav4android.exception.HttpException; + import at.bitfire.dav4android.exception.PreconditionFailedException; + import at.bitfire.dav4android.exception.ServiceUnavailableException; + import at.bitfire.dav4android.exception.UnauthorizedException; + import at.bitfire.dav4android.property.GetCTag; + import at.bitfire.dav4android.property.GetETag; + import at.bitfire.davdroid.Constants; + import at.bitfire.davdroid.HttpClient; + import at.bitfire.davdroid.R; + import at.bitfire.davdroid.log.ExternalFileLogger; + import at.bitfire.davdroid.resource.LocalCollection; + import at.bitfire.davdroid.resource.LocalResource; + import at.bitfire.davdroid.ui.DebugInfoActivity; + import at.bitfire.davdroid.ui.settings.AccountActivity; + import at.bitfire.ical4android.CalendarStorageException; + import at.bitfire.vcard4android.ContactsStorageException; abstract public class SyncManager { diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java index 83b49635..88a07a0a 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java @@ -16,10 +16,8 @@ import android.content.Intent; import android.content.SyncResult; import android.os.Bundle; import android.os.IBinder; -import android.provider.CalendarContract; import at.bitfire.davdroid.Constants; -import at.bitfire.davdroid.resource.LocalCalendar; import at.bitfire.davdroid.resource.LocalTaskList; import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.ical4android.TaskProvider; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java index 2821e11f..cdd5fa33 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java @@ -9,12 +9,9 @@ package at.bitfire.davdroid.ui; import android.accounts.Account; -import android.accounts.AccountManager; import android.app.Activity; import android.app.LoaderManager; import android.content.AsyncTaskLoader; -import android.content.ClipData; -import android.content.ClipboardManager; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; @@ -24,9 +21,6 @@ import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Debug; -import android.os.Environment; -import android.provider.CalendarContract; import android.provider.ContactsContract; import android.text.TextUtils; import android.view.Menu; @@ -36,7 +30,6 @@ import android.widget.TextView; import org.apache.commons.lang3.exception.ExceptionUtils; import java.io.File; -import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; @@ -44,7 +37,6 @@ import at.bitfire.dav4android.exception.HttpException; import at.bitfire.davdroid.BuildConfig; import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.R; -import ezvcard.util.IOUtils; public class DebugInfoActivity extends Activity implements LoaderManager.LoaderCallbacks { public static final String diff --git a/app/src/main/java/at/bitfire/davdroid/ui/settings/AccountFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/settings/AccountFragment.java index 75f52445..9765ef26 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/settings/AccountFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/settings/AccountFragment.java @@ -12,8 +12,6 @@ import android.accounts.Account; import android.app.AlertDialog; import android.app.DialogFragment; import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.java index d49dc83a..3d7a678f 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.java @@ -29,8 +29,6 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; -import java.util.List; - import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.R; import at.bitfire.davdroid.resource.LocalAddressBook; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginURLFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginURLFragment.java index cfb64184..b3dda862 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginURLFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginURLFragment.java @@ -9,7 +9,6 @@ package at.bitfire.davdroid.ui.setup; import android.app.DialogFragment; import android.app.Fragment; -import android.app.FragmentTransaction; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/QueryServerDialogFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/QueryServerDialogFragment.java index c5770963..3d4e13d1 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/QueryServerDialogFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/QueryServerDialogFragment.java @@ -21,7 +21,6 @@ import android.content.Intent; import android.content.Loader; import android.os.Bundle; -import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader;