1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2026-08-20 21:03:08 +00:00

Re-initiate the SSL trust manager and remove org.apache.commons.httpclient

+ fix a wrong string
This commit is contained in:
Loic Blot
2017-11-03 12:21:16 +01:00
parent 5cb6c63f16
commit a17bffb68c
5 changed files with 29 additions and 368 deletions
@@ -22,9 +22,6 @@ import android.util.Base64;
import android.util.Log;
import android.util.Pair;
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.json.JSONException;
import org.json.JSONObject;
@@ -38,6 +35,11 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType;
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
@@ -67,8 +69,29 @@ public class OCHttpClient {
private static final String OC_V2_GET_MESSAGES_SENDQUEUE = "/index.php/apps/ocsms/api/v2/messages/sendqueue?format=json";
public OCHttpClient(Context context, URL serverURL, String accountName, String accountPassword) {
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyhttps);
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception ignored) {
}
_url = serverURL;
_username = accountName;
_password = accountPassword;