Skip to content

Commit

Permalink
reenable ssl cert check if checbox unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
mc51 committed Dec 2, 2020
1 parent 7fd9007 commit bbd76c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
applicationId "com.data_dive.com.clipster"
minSdkVersion 19
targetSdkVersion 29
versionCode 2
versionName "0.2.0"
versionCode 3
versionName "0.2.1"
}

buildTypes {
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/com/data_dive/com/clipster/NetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

public class NetClient {

private static NetClient instance;
private static Context mContext;

private static final int TIMEOUT_CONN = 5000;
Expand All @@ -51,6 +50,8 @@ protected NetClient(Context context) {
Log.d(logtag, "Default constructor, SERVER: " + SERVER_URI);
if(credentials.ignore_cert) {
disableSSLCertChecks();
} else {
enableSSLCertChecks();
}
mContext = context;
}
Expand All @@ -61,6 +62,8 @@ protected NetClient(Context context, Credentials creds) {
SERVER_URI = credentials.server;
if(credentials.ignore_cert) {
disableSSLCertChecks();
} else {
enableSSLCertChecks();
}
mContext = context;
}
Expand Down Expand Up @@ -143,6 +146,20 @@ public boolean verify(String arg0, SSLSession arg1) {
}
}

public static void enableSSLCertChecks() {
// Reenable SSL Certification Checks
Log.d(logtag, "Enabling SSL Cert Checks");
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, null, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier());
} catch (GeneralSecurityException e) {
Log.e(logtag, "Error enabling SSL Cert: " + e.toString());
}
}

// Send request to API on server
public static class ClientRequest extends AsyncTask<String, Void, ArrayList> {

Expand Down

0 comments on commit bbd76c7

Please sign in to comment.