|
@@ -1,7 +1,24 @@
|
|
package de.tudarmstadt.informatik.hostage.commons;
|
|
package de.tudarmstadt.informatik.hostage.commons;
|
|
|
|
|
|
|
|
+import org.apache.http.HttpVersion;
|
|
|
|
+import org.apache.http.client.HttpClient;
|
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
|
+import org.apache.http.conn.ClientConnectionManager;
|
|
|
|
+import org.apache.http.conn.scheme.PlainSocketFactory;
|
|
|
|
+import org.apache.http.conn.scheme.Scheme;
|
|
|
|
+import org.apache.http.conn.scheme.SchemeRegistry;
|
|
|
|
+import org.apache.http.conn.ssl.SSLSocketFactory;
|
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
|
+import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
|
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
|
|
|
+import org.apache.http.params.BasicHttpParams;
|
|
|
|
+import org.apache.http.params.HttpParams;
|
|
|
|
+import org.apache.http.params.HttpProtocolParams;
|
|
|
|
+import org.apache.http.protocol.HTTP;
|
|
|
|
+
|
|
import java.net.InetAddress;
|
|
import java.net.InetAddress;
|
|
import java.net.UnknownHostException;
|
|
import java.net.UnknownHostException;
|
|
|
|
+import java.security.KeyStore;
|
|
import java.security.SecureRandom;
|
|
import java.security.SecureRandom;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
@@ -10,8 +27,13 @@ import android.net.NetworkInfo;
|
|
import android.net.wifi.WifiInfo;
|
|
import android.net.wifi.WifiInfo;
|
|
import android.net.wifi.WifiManager;
|
|
import android.net.wifi.WifiManager;
|
|
import android.os.Environment;
|
|
import android.os.Environment;
|
|
|
|
+import android.preference.PreferenceManager;
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.formatter.TraCINgFormatter;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.net.MySSLSocketFactory;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Helper class with some static methods for general usage.
|
|
* Helper class with some static methods for general usage.
|
|
*
|
|
*
|
|
@@ -126,6 +148,8 @@ public final class HelperUtils {
|
|
return newBytes;
|
|
return newBytes;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Gets BSSID of the wireless network.
|
|
* Gets BSSID of the wireless network.
|
|
*
|
|
*
|
|
@@ -151,6 +175,62 @@ public final class HelperUtils {
|
|
return bssid;
|
|
return bssid;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static HttpClient createHttpClient() {
|
|
|
|
+ try {
|
|
|
|
+ KeyStore trustStore = KeyStore.getInstance(KeyStore
|
|
|
|
+ .getDefaultType());
|
|
|
|
+ trustStore.load(null, null);
|
|
|
|
+
|
|
|
|
+ SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
|
|
|
|
+ sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
|
|
|
+
|
|
|
|
+ HttpParams params = new BasicHttpParams();
|
|
|
|
+ HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
|
|
|
+ HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
|
|
|
|
+
|
|
|
|
+ SchemeRegistry registry = new SchemeRegistry();
|
|
|
|
+ registry.register(new Scheme("http", PlainSocketFactory
|
|
|
|
+ .getSocketFactory(), 80));
|
|
|
|
+ registry.register(new Scheme("https", sf, 443));
|
|
|
|
+
|
|
|
|
+ ClientConnectionManager ccm = new ThreadSafeClientConnManager(
|
|
|
|
+ params, registry);
|
|
|
|
+
|
|
|
|
+ return new DefaultHttpClient(ccm, params);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return new DefaultHttpClient();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean uploadSingleRecord(Context context, Record record) {
|
|
|
|
+ // Create a https client. Uses MySSLSocketFactory to accept all
|
|
|
|
+ // certificates
|
|
|
|
+ HttpClient httpclient = HelperUtils.createHttpClient();
|
|
|
|
+ HttpPost httppost;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ // Create HttpPost
|
|
|
|
+ httppost = new HttpPost(PreferenceManager
|
|
|
|
+ .getDefaultSharedPreferences(context).getString(
|
|
|
|
+ "pref_upload", "https://ssi.cased.de"));
|
|
|
|
+
|
|
|
|
+ // Create JSON String of Record
|
|
|
|
+ StringEntity se = new StringEntity(record.toString(TraCINgFormatter.getInstance()));
|
|
|
|
+
|
|
|
|
+ httppost.setEntity(se);
|
|
|
|
+
|
|
|
|
+ // Execute HttpPost
|
|
|
|
+ httpclient.execute(httppost);
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Gets internal IP address of the device in a wireless network.
|
|
* Gets internal IP address of the device in a wireless network.
|
|
*
|
|
*
|