Skip to content

Commit

Permalink
Removed restrictions on ssl configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsbraden committed Feb 13, 2016
1 parent 3f2492b commit a8c7d3f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
classpath 'com.android.tools.build:gradle:2.0.0-beta2'
// NOTE: Do not place your application dependencies here; they belong in the individual module build.gradle files
}
}
Expand Down
108 changes: 62 additions & 46 deletions ttrssreader/src/main/java/org/ttrssreader/controllers/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@

package org.ttrssreader.controllers;

import org.stringtemplate.v4.ST;
import org.ttrssreader.R;
import org.ttrssreader.gui.CategoryActivity;
import org.ttrssreader.gui.FeedHeadlineActivity;
import org.ttrssreader.gui.MenuActivity;
import org.ttrssreader.imageCache.ImageCache;
import org.ttrssreader.net.JSONConnector;
import org.ttrssreader.preferences.Constants;
import org.ttrssreader.utils.AsyncTask;
import org.ttrssreader.utils.SSLUtils;
import org.ttrssreader.utils.Utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
Expand All @@ -49,6 +37,18 @@
import android.view.WindowManager;
import android.widget.Toast;

import org.stringtemplate.v4.ST;
import org.ttrssreader.R;
import org.ttrssreader.gui.CategoryActivity;
import org.ttrssreader.gui.FeedHeadlineActivity;
import org.ttrssreader.gui.MenuActivity;
import org.ttrssreader.imageCache.ImageCache;
import org.ttrssreader.net.JSONConnector;
import org.ttrssreader.preferences.Constants;
import org.ttrssreader.utils.AsyncTask;
import org.ttrssreader.utils.SSLUtils;
import org.ttrssreader.utils.Utils;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -211,16 +211,17 @@ public void initialize(final Context context) {
protected Void doInBackground(Void... params) {
wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

if (Controller.getInstance().useKeystore()) {
try {
// Trust certificates from keystore:
SSLUtils.initPrivateKeystore(Controller.getInstance().getKeystorePassword());
} catch (GeneralSecurityException e) {
String msg = context.getString(R.string.Error_SSL_Keystore);
Log.e(TAG, msg, e);
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
} else if (Controller.getInstance().trustAllSsl()) {
// if (Controller.getInstance().useKeystore()) {
// try {
// // Trust certificates from keystore:
// SSLUtils.initPrivateKeystore(Controller.getInstance().getKeystorePassword());
// } catch (GeneralSecurityException e) {
// String msg = context.getString(R.string.Error_SSL_Keystore);
// Log.e(TAG, msg, e);
// Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
// }
// } else
if (Controller.getInstance().trustAllSsl()) {
try {
// Trust all certificates:
SSLUtils.trustAllCert();
Expand All @@ -229,15 +230,15 @@ protected Void doInBackground(Void... params) {
Log.e(TAG, msg, e);
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
} else {
try {
// Normal certificate-checks:
SSLUtils.initSslSocketFactory(null, null);
} catch (GeneralSecurityException e) {
String msg = context.getString(R.string.Error_SSL_SocketFactory);
Log.e(TAG, msg, e);
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
// } else {
// try {
// // Normal certificate-checks:
// SSLUtils.initSslSocketFactory(null, null);
// } catch (GeneralSecurityException e) {
// String msg = context.getString(R.string.Error_SSL_SocketFactory);
// Log.e(TAG, msg, e);
// Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
// }
}

if (Controller.getInstance().trustAllHosts()) {
Expand Down Expand Up @@ -381,8 +382,10 @@ public boolean lazyServer() {
String key = getStringWithSSID(USE_OF_A_LAZY_SERVER, getCurrentSSID(wifiManager), wifibasedPrefsEnabled());

boolean useOfALazyServer;
if (prefs.contains(key)) useOfALazyServer = prefs.getBoolean(key, USE_OF_A_LAZY_SERVER_DEFAULT);
else useOfALazyServer = prefs.getBoolean(USE_OF_A_LAZY_SERVER, Constants.USE_OF_A_LAZY_SERVER_DEFAULT);
if (prefs.contains(key))
useOfALazyServer = prefs.getBoolean(key, USE_OF_A_LAZY_SERVER_DEFAULT);
else
useOfALazyServer = prefs.getBoolean(USE_OF_A_LAZY_SERVER, Constants.USE_OF_A_LAZY_SERVER_DEFAULT);

return useOfALazyServer;
}
Expand Down Expand Up @@ -549,7 +552,8 @@ public void setOpenUrlEmptyArticle(boolean openUrlEmptyArticle) {
}

public boolean useVolumeKeys() {
if (useVolumeKeys == null) useVolumeKeys = prefs.getBoolean(USE_VOLUME_KEYS, USE_VOLUME_KEYS_DEFAULT);
if (useVolumeKeys == null)
useVolumeKeys = prefs.getBoolean(USE_VOLUME_KEYS, USE_VOLUME_KEYS_DEFAULT);
return useVolumeKeys;
}

Expand All @@ -569,7 +573,8 @@ public void setLoadImages(boolean loadImages) {
}

public boolean invertBrowsing() {
if (invertBrowsing == null) invertBrowsing = prefs.getBoolean(INVERT_BROWSING, INVERT_BROWSING_DEFAULT);
if (invertBrowsing == null)
invertBrowsing = prefs.getBoolean(INVERT_BROWSING, INVERT_BROWSING_DEFAULT);
return invertBrowsing;
}

Expand All @@ -579,7 +584,8 @@ public void setInvertBrowsing(boolean invertBrowsing) {
}

public boolean workOffline() {
if (workOffline == null) workOffline = prefs.getBoolean(WORK_OFFLINE, Constants.WORK_OFFLINE_DEFAULT);
if (workOffline == null)
workOffline = prefs.getBoolean(WORK_OFFLINE, Constants.WORK_OFFLINE_DEFAULT);
return workOffline;
}

Expand All @@ -601,7 +607,8 @@ public void setGoBackAfterMarkAllRead(boolean goBackAfterMarkAllRead) {
}

public boolean hideActionbar() {
if (hideActionbar == null) hideActionbar = prefs.getBoolean(HIDE_ACTIONBAR, HIDE_ACTIONBAR_DEFAULT);
if (hideActionbar == null)
hideActionbar = prefs.getBoolean(HIDE_ACTIONBAR, HIDE_ACTIONBAR_DEFAULT);
return hideActionbar;
}

Expand Down Expand Up @@ -696,7 +703,8 @@ public void setHyphenationLanguage(String hyphenationLanguage) {
}

public boolean showVirtual() {
if (showVirtual == null) showVirtual = prefs.getBoolean(SHOW_VIRTUAL, Constants.SHOW_VIRTUAL_DEFAULT);
if (showVirtual == null)
showVirtual = prefs.getBoolean(SHOW_VIRTUAL, Constants.SHOW_VIRTUAL_DEFAULT);
return showVirtual;
}

Expand Down Expand Up @@ -760,7 +768,8 @@ public void setInvertSortFeedsCats(boolean invertSortFeedsCats) {
}

public boolean alignFlushLeft() {
if (alignFlushLeft == null) alignFlushLeft = prefs.getBoolean(ALIGN_FLUSH_LEFT, ALIGN_FLUSH_LEFT_DEFAULT);
if (alignFlushLeft == null)
alignFlushLeft = prefs.getBoolean(ALIGN_FLUSH_LEFT, ALIGN_FLUSH_LEFT_DEFAULT);
return alignFlushLeft;
}

Expand All @@ -770,7 +779,8 @@ public void setAlignFlushLeft(boolean alignFlushLeft) {
}

public boolean dateTimeSystem() {
if (dateTimeSystem == null) dateTimeSystem = prefs.getBoolean(DATE_TIME_SYSTEM, DATE_TIME_SYSTEM_DEFAULT);
if (dateTimeSystem == null)
dateTimeSystem = prefs.getBoolean(DATE_TIME_SYSTEM, DATE_TIME_SYSTEM_DEFAULT);
return dateTimeSystem;
}

Expand Down Expand Up @@ -800,7 +810,8 @@ public void setTimeString(String timeString) {
}

public String dateTimeString() {
if (dateTimeString == null) dateTimeString = prefs.getString(DATE_TIME_STRING, DATE_TIME_STRING_DEFAULT);
if (dateTimeString == null)
dateTimeString = prefs.getString(DATE_TIME_STRING, DATE_TIME_STRING_DEFAULT);
return dateTimeString;
}

Expand Down Expand Up @@ -858,7 +869,8 @@ public void setScheduledRestart(boolean scheduledRestart) {
// SYSTEM

public String saveAttachmentPath() {
if (saveAttachment == null) saveAttachment = prefs.getString(SAVE_ATTACHMENT, SAVE_ATTACHMENT_DEFAULT);
if (saveAttachment == null)
saveAttachment = prefs.getString(SAVE_ATTACHMENT, SAVE_ATTACHMENT_DEFAULT);
return saveAttachment;
}

Expand Down Expand Up @@ -945,7 +957,8 @@ public void setCacheImagesOnlyWifi(boolean cacheImagesOnlyWifi) {
}

public boolean onlyUseWifi() {
if (onlyUseWifi == null) onlyUseWifi = prefs.getBoolean(ONLY_USE_WIFI, ONLY_USE_WIFI_DEFAULT);
if (onlyUseWifi == null)
onlyUseWifi = prefs.getBoolean(ONLY_USE_WIFI, ONLY_USE_WIFI_DEFAULT);
return onlyUseWifi;
}

Expand All @@ -956,7 +969,8 @@ public void setOnlyUseWifi(boolean onlyUseWifi) {

// Returns true if noCrashreports OR noCrashreportsUntilUpdate is true.
public boolean isNoCrashreports() {
if (noCrashreports == null) noCrashreports = prefs.getBoolean(NO_CRASHREPORTS, NO_CRASHREPORTS_DEFAULT);
if (noCrashreports == null)
noCrashreports = prefs.getBoolean(NO_CRASHREPORTS, NO_CRASHREPORTS_DEFAULT);
if (noCrashreportsUntilUpdate == null) noCrashreportsUntilUpdate = prefs
.getBoolean(NO_CRASHREPORTS_UNTIL_UPDATE, NO_CRASHREPORTS_UNTIL_UPDATE_DEFAULT);
return noCrashreports || noCrashreportsUntilUpdate;
Expand Down Expand Up @@ -1013,7 +1027,8 @@ public void setAppLatestVersion(int appLatestVersion) {
}

public String getLastVersionRun() {
if (lastVersionRun == null) lastVersionRun = prefs.getString(LAST_VERSION_RUN, LAST_VERSION_RUN_DEFAULT);
if (lastVersionRun == null)
lastVersionRun = prefs.getString(LAST_VERSION_RUN, LAST_VERSION_RUN_DEFAULT);
return lastVersionRun;
}

Expand Down Expand Up @@ -1161,7 +1176,8 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
if (field.getName().endsWith(APPENDED_DEFAULT)) continue;

// Only use public static fields
if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPublic(field.getModifiers())) continue;
if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPublic(field.getModifiers()))
continue;

String fieldName = "";
try {
Expand Down
8 changes: 4 additions & 4 deletions ttrssreader/src/main/java/org/ttrssreader/utils/SSLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.ttrssreader.utils;

import org.ttrssreader.net.SSLSocketFactoryEx;

import android.annotation.SuppressLint;
import android.os.Environment;
import android.util.Log;

import org.ttrssreader.net.SSLSocketFactoryEx;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -109,13 +109,13 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws

@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
return new X509Certificate[]{};
}

};

// Create a trust manager that does not validate certificate chains
initSslSocketFactory(null, new TrustManager[] {easyTrustManager});
initSslSocketFactory(null, new TrustManager[]{easyTrustManager});
}

public static void trustAllHost() {
Expand Down

0 comments on commit a8c7d3f

Please sign in to comment.