Commit b0bc0eba authored by Ricki Hirner's avatar Ricki Hirner

Integrate cert4android

parent 9de0a550
[submodule "ical4android"]
path = ical4android
url = ../ical4android.git
[submodule "cert4android"]
path = cert4android
url = ../cert4android.git
......@@ -42,6 +42,7 @@ android {
}
dependencies {
compile project(':cert4android')
compile project(':ical4android')
compile 'com.android.support:appcompat-v7:26.0.1'
......
......@@ -9,23 +9,27 @@
package at.bitfire.icsdroid
import android.content.Context
import android.util.Log
import at.bitfire.cert4android.CustomCertManager
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.SSLContext
object CustomCertificates {
@JvmStatic
fun prepareHttpsURLConnection(context: Context, connection: HttpsURLConnection) {
/*try {
MemorizingTrustManager mtm = new MemorizingTrustManager(context);
fun prepareHttpsURLConnection(context: Context, connection: HttpsURLConnection, foreground: Boolean) {
try {
val manager = CustomCertManager(context, true)
manager.appInForeground = foreground
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new X509TrustManager[] { mtm }, null);
val sc = SSLContext.getInstance("TLS")
sc.init(null, arrayOf(manager), null)
connection.setSSLSocketFactory(sc.getSocketFactory());
connection.setHostnameVerifier(mtm.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()));
} catch (NoSuchAlgorithmException|KeyManagementException e) {
Log.e(TAG, "Couldn't initialize MemorizingTrustManager", e);
}*/
connection.sslSocketFactory = sc.socketFactory
connection.hostnameVerifier = manager.hostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())
} catch(e: Exception) {
Log.e(Constants.TAG, "Couldn't initialize cert4android", e)
}
}
}
......@@ -132,7 +132,7 @@ class SyncAdapter(
conn.ifModifiedSince = calendar.lastModified
if (conn is HttpsURLConnection)
CustomCertificates.prepareHttpsURLConnection(context, conn)
CustomCertificates.prepareHttpsURLConnection(context, conn, false)
if (conn is HttpURLConnection) {
conn.setRequestProperty("User-Agent", Constants.USER_AGENT)
......
......@@ -121,7 +121,7 @@ class AddCalendarValidationFragment: DialogFragment(), LoaderManager.LoaderCallb
conn.readTimeout = 20000
if (conn is HttpsURLConnection)
CustomCertificates.prepareHttpsURLConnection(context, conn)
CustomCertificates.prepareHttpsURLConnection(context, conn, true)
if (conn is HttpURLConnection) {
conn.setRequestProperty("User-Agent", Constants.USER_AGENT)
......
Subproject commit 47fe535bc66a1309046fa73c19a9e53183846236
/*
* Copyright (c) 2013 – 2015 Ricki Hirner (bitfire web engineering).
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*/
include ':app', ':ical4android'
include ':app', ':cert4android', ':ical4android'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment