<CheckBoxPreference android:title="Device administration" android:summaryOn="Device administration is enabled." android:key="admin" android:summaryOff="Device administration is disabled. Some commands require device administration."/><CheckBoxPreference android:key="foreground" android:title="Run service in foreground" android:summaryOn="The FonBot service is kept in foreground. " android:summaryOff="The FonBot service is not kept in foreground."/><CheckBoxPreference android:key="poll_on_screen_on" android:summaryOff="The server is not polled when the screen is turned on" android:summaryOn="The server is polled when the screen is turned on" android:title="Poll server on screen on"/>
<CheckBoxPreference android:key="system" android:summaryOff="FonBot is not a system app. Changing this requires root and busybox" android:title="System App" android:summaryOn="FonBot is a system app. Changing this requires root and busybox"/>
- <EditTextPreference android:dialogTitle="Server hostname" android:title="Server hostname" android:dialogMessage="Server hostname. Do not change unless you know what you are doing!" android:key="hostname" android:defaultValue="ieval.ro" android:summary="ieval.ro"/>
+ <EditTextPreference android:dialogTitle="Server hostname" android:title="Server hostname" android:dialogMessage="Server hostname. Do not change unless you know what you are doing!" android:key="hostname" android:defaultValue="fonbot.ieval.ro" android:summary="fonbot.ieval.ro"/>
<EditTextPreference android:dialogMessage="Server port. Do not change unless you know what you are doing!" android:dialogTitle="Server port" android:title="Server port" android:summary="7777" android:defaultValue="7777" android:key="port"/>
</PreferenceScreen>
\ No newline at end of file
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.HttpURLConnection;
import java.net.URL;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
import java.util.Collection;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.X509TrustManager;
+
import org.eclipse.jdt.annotation.Nullable;
import android.content.Context;
*/
/**
- * ExecutableRunnable that makes a HTTP call to the server and hands the response to a callback
+ * ExecutableRunnable that makes a HTTPS call to the server and hands the response to a callback
*
* @author Marius Gavrilescu <marius@ieval.ro>
*/
public final class HttpCallExecutableRunnable extends ExecutableRunnable{
+ /**
+ * X509TrustManager that trusts any certificate
+ *
+ * @author Marius Gavrilescu
+ */
+ private static final class TotallyInsecureTrustManager implements X509TrustManager {
+ @Override
+ public @Nullable X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[0];
+ }
+
+ @Override
+ public void checkServerTrusted(final @Nullable X509Certificate[] chain, final @Nullable String authType)
+ throws CertificateException {
+ //do nothing
+ }
+
+ @Override
+ public void checkClientTrusted(final @Nullable X509Certificate[] chain, final @Nullable String authType)
+ throws CertificateException {
+ //do nothing
+ }
+ }
+
/**
* Callback which is run after a HTTP call.
*
public void onError(final String error);
}
+ /** SSLSocketFactory that uses {@link TotallyInsecureTrustManager} */
+ private static final SSLSocketFactory DEFAULT_SOCKET_FACTORY;
+ static{
+ try{
+ final SSLContext sslcontext=SSLContext.getInstance("TLS");
+ sslcontext.init(null, new X509TrustManager[]{new TotallyInsecureTrustManager()}, null);
+ DEFAULT_SOCKET_FACTORY=sslcontext.getSocketFactory();
+ } catch(final Exception e){
+ Log.wtf("HttpCallExecutableRunnable", "Cannot create SSLSocketFactory", e);
+ throw new AssertionError("Log.wtf did not terminate the process");
+ }
+ }
+
/**
* List of extra request headers.
*/
public void run() {
try {
final URL url=Utils.getServerURL(toNonNull(context),toNonNull(path));
- final HttpURLConnection conn=(HttpURLConnection) url.openConnection();
+ final HttpsURLConnection conn=(HttpsURLConnection) url.openConnection();
+ conn.setSSLSocketFactory(DEFAULT_SOCKET_FACTORY);
if(data!=null){
conn.setDoOutput(true);
conn.setFixedLengthStreamingMode(data.length);
* @throws MalformedURLException if the user preferences create an invalid URL
*/
public static URL getServerURL(final Context context, final String path) throws MalformedURLException{
- final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "ieval.ro");
+ final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "fonbot.ieval.ro");
final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "7777"));
- final URL url=new URL("http", hostname, port, path);
+ final URL url=new URL("https", hostname, port, path);
return url;
}