Skip to content

Commit

Permalink
Update SSL trust manager #1095
Browse files Browse the repository at this point in the history
  • Loading branch information
klassm committed Feb 11, 2017
1 parent ef0997f commit 81a29d7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* Boston, MA 02110-1301 USA
*/

def appVersionCode = 440
def appVersionName = "4.4.0"
def appVersionCode = 441
def appVersionName = "4.4.1"

buildscript {
repositories {
Expand Down Expand Up @@ -200,12 +200,17 @@ dependencies {
//noinspection GradleDependency
compile 'com.google.android.gms:play-services:9.0.2'
compile 'commons-net:commons-net:3.3'
compile 'commons-codec:commons-codec:1.10'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.guava:guava:19.0'
compile 'org.apache.commons:commons-lang3:3.3.2'
apt 'com.google.dagger:dagger-compiler:2.7'
compile 'com.google.dagger:dagger:2.7'
compile 'javax.annotation:javax.annotation-api:1.2'
compile('com.google.http-client:google-http-client-android:1.22.0') {
exclude group: 'com.google.code.findbugs'
exclude group: 'org.apache.httpcomponents'
}

compile 'joda-time:joda-time:2.4'
//noinspection GradleDependency
Expand Down
Binary file modified external-dep/memorizing-trust-manager-release.aar
Binary file not shown.
7 changes: 6 additions & 1 deletion proguard-production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@
# MPAndroid Chart

-keep class com.github.mikephil.charting.** { *; }
-dontwarn io.realm.**
-dontwarn io.realm.**

-keepclassmembers class * {
@com.google.api.client.util.Key <fields>;
}
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault
42 changes: 19 additions & 23 deletions src/main/java/li/klass/fhem/fhem/FHEMWEBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;

import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpResponse;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.CharStreams;
Expand All @@ -42,8 +45,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyStore;
import java.util.Map;
Expand Down Expand Up @@ -135,38 +136,33 @@ public RequestResult<InputStream> executeRequest(String urlSuffix) {
}

private RequestResult<InputStream> executeRequest(String serverUrl, String urlSuffix, boolean isRetry) {

initSslContext();
String url = null;
HttpURLConnection connection;
try {
LOG.info("accessing URL {}", url);
url = serverUrl + urlSuffix;
URL requestUrl = new URL(url);
HttpResponse response = AndroidHttp.newCompatibleTransport()
.createRequestFactory().buildGetRequest(new GenericUrl(url))
.setConnectTimeout(SOCKET_TIMEOUT)
.setReadTimeout(SOCKET_TIMEOUT)
.setLoggingEnabled(false)
.setHeaders(new HttpHeaders().setBasicAuthentication(serverSpec.getUsername(), serverSpec.getPassword()))
.execute();

LOG.info("accessing URL {}", url);
connection = (HttpURLConnection) requestUrl.openConnection();
connection.setConnectTimeout(SOCKET_TIMEOUT);
connection.setReadTimeout(SOCKET_TIMEOUT);
connection.setDoOutput(false);

String authString = (serverSpec.getUsername() + ":" + serverSpec.getPassword());
connection.addRequestProperty("Authorization", "Basic " +
Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP));
int statusCode = connection.getResponseCode();
LOG.debug("response status code is " + statusCode);

RequestResult<InputStream> errorResult = handleHttpStatusCode(statusCode);
LOG.debug("response status code is " + response.getStatusCode());


RequestResult<InputStream> errorResult = handleHttpStatusCode(response.getStatusCode());
if (errorResult != null) {
String msg = "found error " + errorResult.error.getDeclaringClass().getSimpleName() + " for " +
"status code " + statusCode;
"status code " + response.getStatusCode();
LOG.debug(msg);
ErrorHolder.setError(null, msg);

close(connection);

return errorResult;
}

return new RequestResult<>((InputStream) new BufferedInputStream(connection.getInputStream()));
return new RequestResult<>((InputStream) new BufferedInputStream(response.getContent()));
} catch (Exception e) {
LOG.info("error while loading data", e);
return handleError(urlSuffix, isRetry, url, e);
Expand Down

0 comments on commit 81a29d7

Please sign in to comment.