Browse Source

fixed merge conflicts

Alexander Brakowski 10 years ago
parent
commit
0bf5507578
35 changed files with 2232 additions and 1439 deletions
  1. 1 1
      .classpath
  2. 16 4
      AndroidManifest.xml
  3. 1 1
      res/layout/activity_nfc.xml
  4. 17 0
      res/layout/activity_sync_central.xml
  5. 1 0
      res/values/strings_gui.xml
  6. 10 4
      src/de/tudarmstadt/informatik/hostage/ConnectionGuard.java
  7. 42 17
      src/de/tudarmstadt/informatik/hostage/Handler.java
  8. 0 38
      src/de/tudarmstadt/informatik/hostage/Hostage.java
  9. 12 11
      src/de/tudarmstadt/informatik/hostage/Listener.java
  10. 339 409
      src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java
  11. 0 305
      src/de/tudarmstadt/informatik/hostage/deprecated/OldLogger.java
  12. 1 1
      src/de/tudarmstadt/informatik/hostage/deprecated/UglyDbHelper.java
  13. 171 0
      src/de/tudarmstadt/informatik/hostage/logging/AttackRecord.java
  14. 58 8
      src/de/tudarmstadt/informatik/hostage/logging/Logger.java
  15. 125 0
      src/de/tudarmstadt/informatik/hostage/logging/MessageRecord.java
  16. 136 0
      src/de/tudarmstadt/informatik/hostage/logging/NetworkRecord.java
  17. 47 133
      src/de/tudarmstadt/informatik/hostage/logging/Record.java
  18. 63 0
      src/de/tudarmstadt/informatik/hostage/logging/SyncInfoRecord.java
  19. 18 1
      src/de/tudarmstadt/informatik/hostage/persistence/HostageDBContract.java
  20. 432 260
      src/de/tudarmstadt/informatik/hostage/persistence/HostageDBOpenHelper.java
  21. 53 1
      src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java
  22. 39 0
      src/de/tudarmstadt/informatik/hostage/sync/SyncMessage.java
  23. 40 190
      src/de/tudarmstadt/informatik/hostage/sync/bluetooth/BluetoothSync.java
  24. 29 0
      src/de/tudarmstadt/informatik/hostage/sync/bluetooth/BluetoothSyncService.java
  25. 48 0
      src/de/tudarmstadt/informatik/hostage/sync/bluetooth/ClientThread.java
  26. 146 0
      src/de/tudarmstadt/informatik/hostage/sync/bluetooth/CommunicationThread.java
  27. 57 0
      src/de/tudarmstadt/informatik/hostage/sync/bluetooth/ServerThread.java
  28. 23 27
      src/de/tudarmstadt/informatik/hostage/sync/nfc/NFCSync.java
  29. 43 0
      src/de/tudarmstadt/informatik/hostage/sync/tracing/TracingSyncActivity.java
  30. 28 0
      src/de/tudarmstadt/informatik/hostage/sync/tracing/TracingSyncResultReciever.java
  31. 196 0
      src/de/tudarmstadt/informatik/hostage/sync/tracing/TracingSyncService.java
  32. 1 1
      src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java
  33. 33 22
      src/de/tudarmstadt/informatik/hostage/ui/PlayGroundActivity.java
  34. 2 1
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordDetailFragment.java
  35. 4 4
      src/de/tudarmstadt/informatik/hostage/wrapper/Packet.java

+ 1 - 1
.classpath

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src"/>
+	<classpathentry excluding="de/tudarmstadt/informatik/hostage/ui/ViewLog.java|de/tudarmstadt/informatik/hostage/ui/ViewLogTable.java" kind="src" path="src"/>
 	<classpathentry kind="src" path="gen"/>
 	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>

+ 16 - 4
AndroidManifest.xml

@@ -15,6 +15,9 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    <uses-permission android:name="android.permission.NFC" />
     <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
 	<uses-permission android:name="android.permission.BLUETOOTH" />
     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
@@ -44,9 +47,8 @@
             android:configChanges="keyboardHidden|orientation|screenSize"
             android:label="@string/app_name"
             android:screenOrientation="portrait" >
-            <intent-filter>
+           	<intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
@@ -54,6 +56,7 @@
             android:name="de.tudarmstadt.informatik.hostage.ui.MainActivity"
             android:configChanges="keyboardHidden|orientation|screenSize"
             android:label="@string/app_name" >
+
         </activity>
         <activity
             android:name="de.tudarmstadt.informatik.hostage.ui.ViewLog"
@@ -80,12 +83,17 @@
             android:label="@string/gui_playground" >
         </activity>
         <activity
-            android:name="de.tudarmstadt.informatik.hostage.sync.BluetoothSync"
+            android:name="de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncActivity"
+            android:label="@string/gui_tracing"
+            android:theme="@android:style/Theme.Dialog" >
+        </activity>
+        <activity
+            android:name="de.tudarmstadt.informatik.hostage.sync.bluetooth.BluetoothSync"
             android:label="@string/gui_bluetooth"
             android:theme="@android:style/Theme.Dialog" >
         </activity>
         <activity
-            android:name="de.tudarmstadt.informatik.hostage.sync.NFCSync"
+            android:name="de.tudarmstadt.informatik.hostage.sync.nfc.NFCSync"
             android:label="@string/gui_nfc"
             android:theme="@android:style/Theme.Dialog" >
             <intent-filter>
@@ -105,6 +113,10 @@
             android:name="de.tudarmstadt.informatik.hostage.logging.Logger"
             android:exported="false" >
         </service>
+        <service
+            android:name="de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncService"
+            android:exported="false" >
+        </service>
 
         <provider
             android:name="de.tudarmstadt.informatik.hostage.provider.HostageContentProvider"

+ 1 - 1
res/layout/activity_nfc.xml

@@ -9,7 +9,7 @@
     android:paddingTop="@dimen/activity_vertical_margin" >
 
     <TextView
-        android:id="@+id/record_details_text_ssid"
+        android:id="@+id/nfc_text_view"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="NFC - SYNC" />

+ 17 - 0
res/layout/activity_sync_central.xml

@@ -0,0 +1,17 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin" >
+
+    <TextView
+        android:id="@+id/sync_central_text_view"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="Uploading Records to" />
+
+</LinearLayout>

+ 1 - 0
res/values/strings_gui.xml

@@ -30,5 +30,6 @@
     <string name="gui_choose_device">Choose Device</string>
     <string name="gui_nfc">NFC</string>
     <string name="gui_bluetooth">Bluetooth</string>
+    <string name="gui_tracing">Tracing</string>
     
 </resources>

+ 10 - 4
src/de/tudarmstadt/informatik/hostage/ConnectionGuard.java

@@ -1,6 +1,6 @@
 package de.tudarmstadt.informatik.hostage;
 
-import android.util.Log;
+import de.tudarmstadt.informatik.hostage.logging.Logger;
 
 public class ConnectionGuard {
 
@@ -12,14 +12,20 @@ public class ConnectionGuard {
 	private final static long ONE_SECOND_IN_NANOSECONDS = 1000000000;
 
 	private static long lastTimestamp = 0;
+	private static String lastIP = "";
+	private static String lastProtocol = "";
 
-	public static void registerConnection() {
+	public static void registerConnection(String protocol, String ip) {
 		long timestamp = System.nanoTime();
 		boolean firstConnection = (lastTimestamp == 0);
 		boolean belowThreshold = ((timestamp - lastTimestamp) < ONE_SECOND_IN_NANOSECONDS);
-		if (!firstConnection && belowThreshold) {
-			Log.d("ConnectionGuard", "PORTSCAN DETECTED");
+		boolean sameIP = (lastIP == ip);
+		boolean sameProtocol = (lastProtocol == protocol);
+		if (!firstConnection && sameIP && belowThreshold && !sameProtocol) {
+//TODO LOG PORTSCAN			Logger.logPortscan(Hostage.getContext(), System.currentTimeMillis(), ip);
 		}
 		lastTimestamp = timestamp;
+		lastIP = ip;
+		lastProtocol = protocol;
 	}
 }

+ 42 - 17
src/de/tudarmstadt/informatik/hostage/Handler.java

@@ -12,9 +12,11 @@ import android.content.SharedPreferences.Editor;
 import android.preference.PreferenceManager;
 import android.util.Log;
 import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
+import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
 import de.tudarmstadt.informatik.hostage.logging.Logger;
-import de.tudarmstadt.informatik.hostage.logging.Record;
-import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
+import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
+import de.tudarmstadt.informatik.hostage.logging.MessageRecord.TYPE;
+import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
 import de.tudarmstadt.informatik.hostage.nio.Reader;
 import de.tudarmstadt.informatik.hostage.nio.Writer;
 import de.tudarmstadt.informatik.hostage.protocol.GHOST;
@@ -71,14 +73,16 @@ public class Handler implements Runnable {
 		this.thread = new Thread(this);
 		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(service);
 		TIMEOUT = pref.getInt("timeout", 30) * 1000;
-		// TODO ThreadSicher?
 		getAndIncrementAttackID(pref);
 		SharedPreferences connInfo = service.getSharedPreferences(service.getString(R.string.connection_info), Context.MODE_PRIVATE);
 		BSSID = connInfo.getString(service.getString(R.string.connection_info_bssid), null);
 		SSID = connInfo.getString(service.getString(R.string.connection_info_ssid), null);
 		externalIP = connInfo.getString(service.getString(R.string.connection_info_external_ip), null);
 		setSoTimeout(client);
+		Logger.log(Hostage.getContext(), createNetworkRecord());
+		Logger.log(Hostage.getContext(), createAttackRecord());
 		thread.start();
+		
 	}
 
 	/**
@@ -101,10 +105,9 @@ public class Handler implements Runnable {
 			client.close();
 			Log.i("HoneyHandler", "Socket closed: " + client.isClosed());
 		} catch (Exception e) {
-			e.printStackTrace();
-		} finally {
-
-		}
+			
+		} 
+		//TODO kann ConcurrentModificationException auslösen, da über collection iteriert wird während elemente entfernt werden
 		listener.refreshHandlers();
 	}
 
@@ -160,7 +163,7 @@ public class Handler implements Runnable {
 	}
 
 	/**
-	 * Creates a Record for a message exchanged with a client.
+	 * Creates a MessageRecord for a message exchanged with a client.
 	 * 
 	 * @param type
 	 *            The type of the message.
@@ -168,21 +171,43 @@ public class Handler implements Runnable {
 	 *            The content of the message.
 	 * @return The Record representing the communication message.
 	 */
-	protected Record createRecord(TYPE type, String packet) {
-		Record record = new Record();
+	protected MessageRecord createMessageRecord(TYPE type, String packet) {
+		MessageRecord record = new MessageRecord();
 		record.setId(message_id++);
-		record.setAttack_id(attack_id);
-		record.setProtocol(protocol.toString());
+		record.setAttack_id(attack_id);		
 		record.setType(type);
 		record.setTimestamp(System.currentTimeMillis());
+		record.setPacket(packet);
+		return record;
+	}
+	
+	/**
+	 * Creates a AttackRecord for a specific attack from a client.
+	 * 
+	 * @return The AttackRecord representing the attack.
+	 */
+	protected AttackRecord createAttackRecord() {
+		AttackRecord record = new AttackRecord();
+		record.setAttack_id(attack_id);			
+		record.setProtocol(protocol.toString());
 		record.setExternalIP(externalIP);
 		record.setLocalIP(client.getLocalAddress().getHostAddress());
 		record.setLocalPort(protocol.getPort());
 		record.setRemoteIP(client.getInetAddress().getHostAddress());
 		record.setRemotePort(client.getPort());
 		record.setBssid(BSSID);
-		record.setSsid(SSID);
-		record.setPacket(packet);
+		return record;
+	}
+	
+	/**
+	 * Creates a NetworkRecord containing information about the current network.
+	 * 
+	 * @return The NetworkRecord representing the current network.
+	 */
+	protected NetworkRecord createNetworkRecord() {
+		NetworkRecord record = new NetworkRecord();
+		record.setBssid(BSSID);		
+		record.setSsid(SSID);		
 		if (MyLocationManager.getNewestLocation() != null) {
 			record.setLatitude(MyLocationManager.getNewestLocation().getLatitude());
 			record.setLongitude(MyLocationManager.getNewestLocation().getLongitude());
@@ -216,16 +241,16 @@ public class Handler implements Runnable {
 			outputLine = protocol.processMessage(null);
 			writer.write(outputLine);
 			for (Packet o : outputLine) {
-				Logger.log(Hostage.getContext(), createRecord(TYPE.SEND, o.toString()));
+				Logger.log(Hostage.getContext(), createMessageRecord(TYPE.SEND, o.toString()));
 			}
 		}
 		while (!thread.isInterrupted() && (inputLine = reader.read()) != null) {
 			outputLine = protocol.processMessage(inputLine);
-			Logger.log(Hostage.getContext(), createRecord(TYPE.RECEIVE, inputLine.toString()));
+			Logger.log(Hostage.getContext(), createMessageRecord(TYPE.RECEIVE, inputLine.toString()));
 			if (outputLine != null) {
 				writer.write(outputLine);
 				for (Packet o : outputLine) {
-					Logger.log(Hostage.getContext(), createRecord(TYPE.SEND, o.toString()));
+					Logger.log(Hostage.getContext(), createMessageRecord(TYPE.SEND, o.toString()));
 				}
 			}
 			if (protocol.isClosed()) {

+ 0 - 38
src/de/tudarmstadt/informatik/hostage/Hostage.java

@@ -64,40 +64,6 @@ public class Hostage extends Service {
 		}
 	}
 
-	/**
-	 * Task for accuiring a qotd from one of four possible servers.
-	 * 
-	 * @author Wulf Pfeiffer
-	 */
-	private class QotdTask extends AsyncTask<String, Void, String> {
-		@Override
-		protected String doInBackground(String... unused) {
-			String[] sources = new String[] { "djxmmx.net", "ota.iambic.com", "alpha.mike-r.com", "electricbiscuit.org" };
-			SecureRandom rndm = new SecureRandom();
-			StringBuffer sb = new StringBuffer();
-			try {
-				Socket client = new Socket(sources[rndm.nextInt(4)], 17);
-				BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
-				while (!in.ready())
-					;
-				while (in.ready()) {
-					sb.append(in.readLine());
-				}
-				in.close();
-				client.close();
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-			return sb.toString();
-		}
-
-		@Override
-		protected void onPostExecute(String result) {
-			if (result != null)
-				HTTP.setHtmlDocumentContent(result);
-		}
-	}
-
 	/**
 	 * Task to find out the external IP.
 	 * 
@@ -307,10 +273,6 @@ public class Hostage extends Service {
 		registerNetReceiver();
 		updateConnectionInfo();
 		getLocationData();
-		boolean useQotd = context.getSharedPreferences(getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE).getBoolean("useQotd", true);
-		if (useQotd) {
-			new QotdTask().execute(new String[] {});
-		}
 	}
 
 	@Override

+ 12 - 11
src/de/tudarmstadt/informatik/hostage/Listener.java

@@ -1,7 +1,11 @@
 package de.tudarmstadt.informatik.hostage;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.Iterator;
 
@@ -9,7 +13,10 @@ import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLSocket;
 import javax.net.ssl.SSLSocketFactory;
 
+import android.os.AsyncTask;
+
 import de.tudarmstadt.informatik.hostage.net.MyServerSocketFactory;
+import de.tudarmstadt.informatik.hostage.protocol.HTTP;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.SMB;
 import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
@@ -21,7 +28,7 @@ import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
  * For each connection creates a Socket and instantiate an {@link Handler}.
  * 
  * @author Mihai Plasoianu
- * 
+ * @author Wulf Pfeiffer
  */
 public class Listener implements Runnable {
 
@@ -114,6 +121,7 @@ public class Listener implements Runnable {
 			addHandler();
 		}
 		for (Handler handler : handlers) {
+			//TODO kann ConcurrentModificationException auslösen, da über collection iteriert wird während elemente entfernt werden
 			handler.kill();
 		}
 	}
@@ -137,8 +145,7 @@ public class Listener implements Runnable {
 			service.notifyUI(this.getClass().getName(),
 					new String[] { service.getString(R.string.broadcast_started), protocol.toString(), Integer.toString(port) });
 			return true;
-		} catch (Exception e) {
-			e.printStackTrace();
+		} catch (IOException e) {
 			return false;
 		}
 	}
@@ -154,8 +161,7 @@ public class Listener implements Runnable {
 			running = false;
 			service.notifyUI(this.getClass().getName(),
 					new String[] { service.getString(R.string.broadcast_stopped), protocol.toString(), Integer.toString(port) });
-		} catch (Exception e) {
-			e.printStackTrace();
+		} catch (IOException e) {
 		}
 	}
 
@@ -166,7 +172,7 @@ public class Listener implements Runnable {
 		if (conReg.isConnectionFree()) {
 			try {
 				Socket client = server.accept();
-				ConnectionGuard.registerConnection();
+				ConnectionGuard.registerConnection(this.getProtocolName(), client.getInetAddress().getHostAddress());
 				conReg.newOpenConnection();
 				if (protocol.isSecure()) {
 					startSecureHandler(client);
@@ -222,9 +228,4 @@ public class Listener implements Runnable {
 		sslClient.setUseClientMode(false);
 		handlers.add(newInstance(service, this, protocol.getClass().newInstance(), sslClient));
 	}
-
-	@Override
-	public String toString() {
-		return protocol.toString() + ":" + port;
-	}
 }

+ 339 - 409
src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java

@@ -1,409 +1,339 @@
-package de.tudarmstadt.informatik.hostage.commons;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.security.KeyStore;
-import java.security.SecureRandom;
-
-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 android.content.Context;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
-import android.os.Environment;
-import android.preference.PreferenceManager;
-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.
- * 
- * @author Lars Pandikow
- * @author Wulf Pfeiffer
- * 
- */
-public final class HelperUtils {
-
-	/**
-	 * Converts a byte array into a hexadecimal String, e.g. {0x00, 0x01} to
-	 * "00, 01".
-	 * 
-	 * @param bytes
-	 *            that will be converted.
-	 * @return converted String.
-	 */
-	public static String bytesToHexString(byte[] bytes) {
-		char[] hexArray = "0123456789ABCDEF".toCharArray();
-		int v;
-		StringBuffer buffer = new StringBuffer();
-		for (int j = 0; j < bytes.length; j++) {
-			v = bytes[j] & 0xFF;
-			buffer.append(hexArray[v >>> 4]);
-			buffer.append(hexArray[v & 0x0F]);
-			if (j < bytes.length - 1)
-				buffer.append(", ");
-		}
-		return buffer.toString();
-	}
-
-	/**
-	 * Converts a byte[] to a String, but only characters in ASCII between 32
-	 * and 127
-	 * 
-	 * @param bytes
-	 *            that are converted
-	 * @return converted String
-	 */
-	public static String byteToStr(byte[] bytes) {
-		int size = 0;
-		for(byte b : bytes) {
-			 if(isLetter((char) b)) {
-				 size++;
-			 }
-		}
-		char[] chars = new char[size];
-		for (int i = 0, j = 0; i < bytes.length && j < size; i++) {
-			if (isLetter((char) bytes[i])) {
-				chars[j] = (char) bytes[i];
-				j++;
-			}
-		}
-		return new String(chars);
-	}
-
-	/**
-	 * Concatenates several byte arrays.
-	 * 
-	 * @param bytes
-	 *            The byte arrays.
-	 * @return A single byte arrays containing all the bytes from the given
-	 *         arrays in the order they are given.
-	 */
-	public static byte[] concat(byte[]... bytes) {
-		int newSize = 0;
-		for (byte[] b : bytes)
-			if (b != null)
-				newSize += b.length;
-		byte[] dst = new byte[newSize];
-
-		int currentPos = 0;
-		int newPos;
-		for (byte[] b : bytes) {
-			if (b != null) {
-				newPos = b.length;
-				System.arraycopy(b, 0, dst, currentPos, newPos);
-				currentPos += newPos;
-			}
-		}
-		return dst;
-	}
-
-	/**
-	 * Creates a HttpClient with an own SSL Socket.
-	 * 
-	 * @return HttpsClient who accepts accepts all certificates.
-	 * @see MySSLSocketFactory
-	 */
-	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();
-		}
-	}
-
-	/**
-	 * Puts a 0x00 byte between each byte in a byte array.
-	 * 
-	 * @param bytes
-	 *            that need to be filled with 0x00.
-	 * @return filled byte array.
-	 */
-	public static byte[] fillWithZero(byte[] bytes) {
-		byte[] newBytes = new byte[(bytes.length * 2)];
-		for (int i = 0, j = 0; i < bytes.length && j < newBytes.length; i++, j = j + 2) {
-			newBytes[j] = bytes[i];
-			newBytes[j + 1] = 0x00;
-		}
-		return newBytes;
-	}
-
-	/**
-	 * Puts a 0x00 byte between each byte and another 2 0x00 bytes at the end of
-	 * a byte array.
-	 * 
-	 * @param bytes
-	 *            that need to be filled with 0x00.
-	 * @return filled byte array.
-	 */
-	public static byte[] fillWithZeroExtended(byte[] bytes) {
-		byte[] zeroBytes = fillWithZero(bytes);
-		byte[] newBytes = new byte[zeroBytes.length + 2];
-		newBytes = HelperUtils.concat(zeroBytes, new byte[] { 0x00, 0x00 });
-		return newBytes;
-	}
-
-	/**
-	 * Gets BSSID of the wireless network.
-	 * 
-	 * @param context
-	 *            Needs a context to get system recourses.
-	 * @return BSSID of wireless network if connected, else null.
-	 */
-	public static String getBSSID(Context context) {
-		String bssid = null;
-		ConnectivityManager connManager = (ConnectivityManager) context
-				.getSystemService(Context.CONNECTIVITY_SERVICE);
-		NetworkInfo networkInfo = connManager
-				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
-		if (networkInfo != null && networkInfo.isConnected()) {
-			final WifiManager wifiManager = (WifiManager) context
-					.getSystemService(Context.WIFI_SERVICE);
-			final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
-			if (connectionInfo != null
-					&& !TextUtils.isEmpty(connectionInfo.getSSID())) {
-				bssid = connectionInfo.getBSSID();
-			}
-		}
-		return bssid;
-	}
-
-	/**
-	 * Gets internal IP address of the device in a wireless network.
-	 * 
-	 * @param context
-	 *            Needs a context to get system recourses.
-	 * @return internal IP of the device in a wireless network if connected,
-	 *         else null.
-	 */
-	public static String getInternalIP(Context context) {
-		String ipAddress = null;
-		ConnectivityManager connManager = (ConnectivityManager) context
-				.getSystemService(Context.CONNECTIVITY_SERVICE);
-		NetworkInfo networkInfo = connManager
-				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
-		if (networkInfo != null && networkInfo.isConnected()) {
-			final WifiManager wifiManager = (WifiManager) context
-					.getSystemService(Context.WIFI_SERVICE);
-			final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
-			if (connectionInfo != null) {
-				try {
-					ipAddress = InetAddress.getByAddress(
-							unpackInetAddress(connectionInfo.getIpAddress()))
-							.getHostAddress();
-				} catch (UnknownHostException e) {
-					e.printStackTrace();
-				}
-			}
-		}
-		return ipAddress;
-	}
-
-	/**
-	 * Produces a random String. The String can be of random length (minimum 1)
-	 * with a maximum length, or it can be forced to have the length that was
-	 * given.
-	 * 
-	 * @param length
-	 *            maximal / forced length of String.
-	 * @param forceLength
-	 *            forces the String to be exact the given length instead of
-	 *            maximum
-	 * @return random String.
-	 */
-	public static String getRandomString(int length, boolean forceLength) {
-		SecureRandom rndm = new SecureRandom();
-		char[] c = new char[forceLength ? length : rndm.nextInt(length - 1) + 1];
-		for (int i = 0; i < c.length; i++) {
-			c[i] = (char) (rndm.nextInt(95) + 32);
-		}
-		return new String(c);
-	}
-
-	/**
-	 * Gets SSID of the wireless network.
-	 * 
-	 * @param context
-	 *            Needs a context to get system recourses
-	 * @return SSID of wireless network if connected, else null.
-	 */
-	public static String getSSID(Context context) {
-		String ssid = null;
-		ConnectivityManager connManager = (ConnectivityManager) context
-				.getSystemService(Context.CONNECTIVITY_SERVICE);
-		NetworkInfo networkInfo = connManager
-				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
-		if (networkInfo != null && networkInfo.isConnected()) {
-			final WifiManager wifiManager = (WifiManager) context
-					.getSystemService(Context.WIFI_SERVICE);
-			final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
-			if (connectionInfo != null
-					&& !TextUtils.isEmpty(connectionInfo.getSSID())) {
-				ssid = connectionInfo.getSSID();
-			}
-		}
-		return ssid;
-	}
-
-	/**
-	 * Converts a String into a byte array, e.g. "00, 01" to {0x00, 0x01}.
-	 * 
-	 * @param string
-	 *            that will be converted.
-	 * @return converted byte array.
-	 */
-	public static byte[] hexStringToBytes(String string) {
-		String[] hexStrings = string.split(", ");
-		byte[] bytes = new byte[hexStrings.length];
-		for (int j = 0; j < hexStrings.length; j++) {
-			bytes[j] = (byte) ((Character.digit(hexStrings[j].charAt(0), 16) << 4) + Character
-					.digit(hexStrings[j].charAt(1), 16));
-		}
-		return bytes;
-	}
-
-	/**
-	 * Checks if external storage is available for read and write.
-	 * 
-	 * @return True if external storage is available for read and write, else
-	 *         false.
-	 */
-	public static boolean isExternalStorageWritable() {
-		String state = Environment.getExternalStorageState();
-		if (Environment.MEDIA_MOUNTED.equals(state)) {
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Generates a random byte[] of a specified size
-	 * 
-	 * @param size
-	 *            of the byte[]
-	 * @return random byte[]
-	 */
-	public static byte[] randomBytes(int size) {
-		byte[] bytes = new byte[size];
-		SecureRandom rdm = new SecureRandom();
-		rdm.nextBytes(bytes);
-		return bytes;
-	}
-
-	/**
-	 * Turns around the values of an byte[], e.g. {0x00, 0x01, 0x02} turns into
-	 * {0x02, 0x01, 0x00}.
-	 * 
-	 * @param bytes
-	 *            array that is turned.
-	 * @return turned array.
-	 */
-	public static byte[] turnByteArray(byte[] bytes) {
-		byte[] tmp = new byte[bytes.length];
-		for (int i = 0; i < bytes.length; i++) {
-			tmp[i] = bytes[bytes.length - 1 - i];
-		}
-		return tmp;
-	}
-
-	/**
-	 * Uploads a single Record to a server, specified in the settings.
-	 * 
-	 * @param record
-	 *            The Record to upload.
-	 * @return True if the upload was successful, else false.
-	 */
-	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;
-	}
-
-	/**
-	 * Determines if a character is in ASCII between 32 and 126
-	 * 
-	 * @param character
-	 *            that is checked
-	 * @return true if the character is between 32 and 126, else false
-	 */
-	private static boolean isLetter(char character) {
-		return (character > 31 && character < 127);
-	}
-
-	private static byte[] unpackInetAddress(int bytes) {
-		return new byte[] { (byte) ((bytes) & 0xff),
-				(byte) ((bytes >>> 8) & 0xff), (byte) ((bytes >>> 16) & 0xff),
-				(byte) ((bytes >>> 24) & 0xff) };
-	}
-
-	public static boolean isWifiConnected(Context context){
-		if(context == null) return false;
-		ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
-		NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
-
-		return mWifi.isConnected();
-	}
-
-	public static boolean isNetworkAvailable(Context context) {
-		if(context == null) return false;
-
-		ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
-		NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
-		return activeNetworkInfo != null && activeNetworkInfo.isConnected();
-	}
-}
+package de.tudarmstadt.informatik.hostage.commons;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.SecureRandom;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Environment;
+import android.text.TextUtils;
+
+/**
+ * Helper class with some static methods for general usage.
+ * 
+ * @author Lars Pandikow
+ * @author Wulf Pfeiffer
+ * 
+ */
+public final class HelperUtils {
+
+	/**
+	 * Converts a byte array into a hexadecimal String, e.g. {0x00, 0x01} to
+	 * "00, 01".
+	 * 
+	 * @param bytes
+	 *            that will be converted.
+	 * @return converted String.
+	 */
+	public static String bytesToHexString(byte[] bytes) {
+		char[] hexArray = "0123456789ABCDEF".toCharArray();
+		int v;
+		StringBuffer buffer = new StringBuffer();
+		for (int j = 0; j < bytes.length; j++) {
+			v = bytes[j] & 0xFF;
+			buffer.append(hexArray[v >>> 4]);
+			buffer.append(hexArray[v & 0x0F]);
+			if (j < bytes.length - 1)
+				buffer.append(", ");
+		}
+		return buffer.toString();
+	}
+
+	/**
+	 * Converts a byte[] to a String, but only characters in ASCII between 32
+	 * and 127
+	 * 
+	 * @param bytes
+	 *            that are converted
+	 * @return converted String
+	 */
+	public static String byteToStr(byte[] bytes) {
+		int size = 0;
+		for(byte b : bytes) {
+			 if(isLetter((char) b)) {
+				 size++;
+			 }
+		}
+		char[] chars = new char[size];
+		for (int i = 0, j = 0; i < bytes.length && j < size; i++) {
+			if (isLetter((char) bytes[i])) {
+				chars[j] = (char) bytes[i];
+				j++;
+			}
+		}
+		return new String(chars);
+	}
+
+	/**
+	 * Concatenates several byte arrays.
+	 * 
+	 * @param bytes
+	 *            The byte arrays.
+	 * @return A single byte arrays containing all the bytes from the given
+	 *         arrays in the order they are given.
+	 */
+	public static byte[] concat(byte[]... bytes) {
+		int newSize = 0;
+		for (byte[] b : bytes)
+			if (b != null)
+				newSize += b.length;
+		byte[] dst = new byte[newSize];
+
+		int currentPos = 0;
+		int newPos;
+		for (byte[] b : bytes) {
+			if (b != null) {
+				newPos = b.length;
+				System.arraycopy(b, 0, dst, currentPos, newPos);
+				currentPos += newPos;
+			}
+		}
+		return dst;
+	}
+
+	/**
+	 * Puts a 0x00 byte between each byte in a byte array.
+	 * 
+	 * @param bytes
+	 *            that need to be filled with 0x00.
+	 * @return filled byte array.
+	 */
+	public static byte[] fillWithZero(byte[] bytes) {
+		byte[] newBytes = new byte[(bytes.length * 2)];
+		for (int i = 0, j = 0; i < bytes.length && j < newBytes.length; i++, j = j + 2) {
+			newBytes[j] = bytes[i];
+			newBytes[j + 1] = 0x00;
+		}
+		return newBytes;
+	}
+
+	/**
+	 * Puts a 0x00 byte between each byte and another 2 0x00 bytes at the end of
+	 * a byte array.
+	 * 
+	 * @param bytes
+	 *            that need to be filled with 0x00.
+	 * @return filled byte array.
+	 */
+	public static byte[] fillWithZeroExtended(byte[] bytes) {
+		byte[] zeroBytes = fillWithZero(bytes);
+		byte[] newBytes = new byte[zeroBytes.length + 2];
+		newBytes = HelperUtils.concat(zeroBytes, new byte[] { 0x00, 0x00 });
+		return newBytes;
+	}
+
+	/**
+	 * Gets BSSID of the wireless network.
+	 * 
+	 * @param context
+	 *            Needs a context to get system recourses.
+	 * @return BSSID of wireless network if connected, else null.
+	 */
+	public static String getBSSID(Context context) {
+		String bssid = null;
+		ConnectivityManager connManager = (ConnectivityManager) context
+				.getSystemService(Context.CONNECTIVITY_SERVICE);
+		NetworkInfo networkInfo = connManager
+				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+		if (networkInfo != null && networkInfo.isConnected()) {
+			final WifiManager wifiManager = (WifiManager) context
+					.getSystemService(Context.WIFI_SERVICE);
+			final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
+			if (connectionInfo != null
+					&& !TextUtils.isEmpty(connectionInfo.getSSID())) {
+				bssid = connectionInfo.getBSSID();
+			}
+		}
+		return bssid;
+	}
+
+	/**
+	 * Gets internal IP address of the device in a wireless network.
+	 * 
+	 * @param context
+	 *            Needs a context to get system recourses.
+	 * @return internal IP of the device in a wireless network if connected,
+	 *         else null.
+	 */
+	public static String getInternalIP(Context context) {
+		String ipAddress = null;
+		ConnectivityManager connManager = (ConnectivityManager) context
+				.getSystemService(Context.CONNECTIVITY_SERVICE);
+		NetworkInfo networkInfo = connManager
+				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+		if (networkInfo != null && networkInfo.isConnected()) {
+			final WifiManager wifiManager = (WifiManager) context
+					.getSystemService(Context.WIFI_SERVICE);
+			final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
+			if (connectionInfo != null) {
+				try {
+					ipAddress = InetAddress.getByAddress(
+							unpackInetAddress(connectionInfo.getIpAddress()))
+							.getHostAddress();
+				} catch (UnknownHostException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		return ipAddress;
+	}
+
+	/**
+	 * Gets SSID of the wireless network.
+	 * 
+	 * @param context
+	 *            Needs a context to get system recourses
+	 * @return SSID of wireless network if connected, else null.
+	 */
+	public static String getSSID(Context context) {
+		String ssid = null;
+		ConnectivityManager connManager = (ConnectivityManager) context
+				.getSystemService(Context.CONNECTIVITY_SERVICE);
+		NetworkInfo networkInfo = connManager
+				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+		if (networkInfo != null && networkInfo.isConnected()) {
+			final WifiManager wifiManager = (WifiManager) context
+					.getSystemService(Context.WIFI_SERVICE);
+			final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
+			if (connectionInfo != null
+					&& !TextUtils.isEmpty(connectionInfo.getSSID())) {
+				ssid = connectionInfo.getSSID();
+			}
+		}
+		return ssid;
+	}
+	
+	/**
+	 * Gets the mac address of the devicek.
+	 * 
+	 * @param context
+	 *            Needs a context to get system recourses
+	 * @return MAC address of the device.
+	 */
+	public static String getMacAdress(Context context) {
+		String mac = null;
+		WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+		WifiInfo connectionInfo = wifiManager.getConnectionInfo();		
+		mac = connectionInfo.getMacAddress();
+		return mac;
+	}
+	
+	/**
+	 * Produces a random String. The String can be of random length (minimum 1)
+	 * with a maximum length, or it can be forced to have the length that was
+	 * given.
+	 * 
+	 * @param length
+	 *            maximal / forced length of String.
+	 * @param forceLength
+	 *            forces the String to be exact the given length instead of
+	 *            maximum
+	 * @return random String.
+	 */
+	public static String getRandomString(int length, boolean forceLength) {
+		SecureRandom rndm = new SecureRandom();
+		char[] c = new char[forceLength ? length : rndm.nextInt(length - 1) + 1];
+		for (int i = 0; i < c.length; i++) {
+			c[i] = (char) (rndm.nextInt(95) + 32);
+		}
+		return new String(c);
+	}
+
+	/**
+	 * Converts a String into a byte array, e.g. "00, 01" to {0x00, 0x01}.
+	 * 
+	 * @param string
+	 *            that will be converted.
+	 * @return converted byte array.
+	 */
+	public static byte[] hexStringToBytes(String string) {
+		String[] hexStrings = string.split(", ");
+		byte[] bytes = new byte[hexStrings.length];
+		for (int j = 0; j < hexStrings.length; j++) {
+			bytes[j] = (byte) ((Character.digit(hexStrings[j].charAt(0), 16) << 4) + Character
+					.digit(hexStrings[j].charAt(1), 16));
+		}
+		return bytes;
+	}
+
+	/**
+	 * Checks if external storage is available for read and write.
+	 * 
+	 * @return True if external storage is available for read and write, else
+	 *         false.
+	 */
+	public static boolean isExternalStorageWritable() {
+		String state = Environment.getExternalStorageState();
+		if (Environment.MEDIA_MOUNTED.equals(state)) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Generates a random byte[] of a specified size
+	 * 
+	 * @param size
+	 *            of the byte[]
+	 * @return random byte[]
+	 */
+	public static byte[] randomBytes(int size) {
+		byte[] bytes = new byte[size];
+		SecureRandom rdm = new SecureRandom();
+		rdm.nextBytes(bytes);
+		return bytes;
+	}
+
+	/**
+	 * Turns around the values of an byte[], e.g. {0x00, 0x01, 0x02} turns into
+	 * {0x02, 0x01, 0x00}.
+	 * 
+	 * @param bytes
+	 *            array that is turned.
+	 * @return turned array.
+	 */
+	public static byte[] turnByteArray(byte[] bytes) {
+		byte[] tmp = new byte[bytes.length];
+		for (int i = 0; i < bytes.length; i++) {
+			tmp[i] = bytes[bytes.length - 1 - i];
+		}
+		return tmp;
+	}
+
+	/**
+	 * Determines if a character is in ASCII between 32 and 126
+	 * 
+	 * @param character
+	 *            that is checked
+	 * @return true if the character is between 32 and 126, else false
+	 */
+	private static boolean isLetter(char character) {
+		return (character > 31 && character < 127);
+	}
+
+	private static byte[] unpackInetAddress(int bytes) {
+		return new byte[] { (byte) ((bytes) & 0xff),
+				(byte) ((bytes >>> 8) & 0xff), (byte) ((bytes >>> 16) & 0xff),
+				(byte) ((bytes >>> 24) & 0xff) };
+	}
+	
+	public static boolean isWifiConnected(Context context){
+		if(context == null) return false;
+		ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+		NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+
+		return mWifi.isConnected();
+	}
+	
+	public static boolean isNetworkAvailable(Context context) {
+		if(context == null) return false;
+
+		ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+		NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
+		return activeNetworkInfo != null && activeNetworkInfo.isConnected();
+	}
+}

+ 0 - 305
src/de/tudarmstadt/informatik/hostage/deprecated/OldLogger.java

@@ -1,305 +0,0 @@
-package de.tudarmstadt.informatik.hostage.deprecated;
-
-import java.util.ArrayList;
-
-import android.app.IntentService;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.ResultReceiver;
-import de.tudarmstadt.informatik.hostage.logging.Record;
-
-/**
- * An {@link IntentService} subclass for handling asynchronous task requests in
- * a service on a separate handler thread.
- * 
- * @author Mihai Plasoianu
- */
-public class OldLogger extends IntentService {
-
-	private static final String ACTION_LOG = "de.tudarmstadt.informatik.hostage.action.LOG";
-	private static final String ACTION_GET_RECORD_ALL = "de.tudarmstadt.informatik.hostage.action.GET_RECORD_ALL";
-	private static final String ACTION_GET_RECORD_EACH = "de.tudarmstadt.informatik.hostage.action.GET_RECORD_EACH";
-	private static final String ACTION_GET_RECORD_ID = "de.tudarmstadt.informatik.hostage.action.GET_RECORD_ID";
-	private static final String ACTION_GET_COUNT_ALL = "de.tudarmstadt.informatik.hostage.action.GET_COUNT_ALL";
-	private static final String ACTION_GET_COUNT_PROTOCOL = "de.tudarmstadt.informatik.hostage.action.GET_COUNT_PROTOCOL";
-	private static final String ACTION_GET_ATTACK_MIN = "de.tudarmstadt.informatik.hostage.action.GET_ATTACK_MIN";
-	private static final String ACTION_GET_ATTACK_MAX = "de.tudarmstadt.informatik.hostage.action.GET_ATTACK_MAX";
-	private static final String ACTION_IS_BSSID_SEEN = "de.tudarmstadt.informatik.hostage.action.IS_BSSID_SEEN";
-	private static final String ACTION_GET_BSSID_ALL = "de.tudarmstadt.informatik.hostage.action.GET_BSSID_ALL";
-	private static final String ACTION_GET_SSID_BSSID = "de.tudarmstadt.informatik.hostage.action.GET_SSID_BSSID";
-	private static final String ACTION_CLEAR_DATE = "de.tudarmstadt.informatik.hostage.action.CLEAR_DATE";
-	private static final String ACTION_CLEAR_BSSID = "de.tudarmstadt.informatik.hostage.action.CLEAR_BSSID";
-	private static final String ACTION_CLEAR_ALL = "de.tudarmstadt.informatik.hostage.action.CLEAR_ALL";
-
-	private static final String EXTRA_RECORD = "de.tudarmstadt.informatik.hostage.extra.RECORD";
-	private static final String EXTRA_PROTOCOL = "de.tudarmstadt.informatik.hostage.extra.PROTOCOL";
-	private static final String EXTRA_BSSID = "de.tudarmstadt.informatik.hostage.extra.BSSID";
-	private static final String EXTRA_PRIMITIVE = "de.tudarmstadt.informatik.hostage.extra.PRIMITIVE";
-
-	private static final String RESULT_RECEIVER = "de.tudarmstadt.informatik.hostage.RESULT_RECEIVER";
-
-	public static void deleteAll(Context context) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_CLEAR_ALL);
-		context.startService(intent);
-	}
-
-	public static void deleteByBssid(Context context, String bssid) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_CLEAR_BSSID);
-		intent.putExtra(EXTRA_BSSID, bssid);
-		context.startService(intent);
-	}
-
-	public static void deleteByDate(Context context, long time) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_CLEAR_DATE);
-		intent.putExtra(EXTRA_PRIMITIVE, time);
-		context.startService(intent);
-	}
-
-	public static void getAllBssids(Context context, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_BSSID_ALL);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void getAllRecords(Context context, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_RECORD_ALL);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void getAttackCount(Context context, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_COUNT_ALL);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void getAttackPerProtocolCount(Context context, String protocol, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_COUNT_PROTOCOL);
-		intent.putExtra(EXTRA_PROTOCOL, protocol);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void getMaxAttackId(Context context, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_ATTACK_MAX);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void getMinAttackId(Context context, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_ATTACK_MIN);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void getRecordOfAttackId(Context context, long attack_id, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_RECORD_ID);
-		intent.putExtra(EXTRA_PRIMITIVE, attack_id);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void getRecordOfEachAttack(Context context, int lastUploadedAttackId, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_RECORD_EACH);
-		intent.putExtra(EXTRA_PRIMITIVE, lastUploadedAttackId);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void getSsid(Context context, String bssid, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_GET_SSID_BSSID);
-		intent.putExtra(EXTRA_BSSID, bssid);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void isBssidSeen(Context context, String protocol, String bssid, ResultReceiver receiver) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_IS_BSSID_SEEN);
-		intent.putExtra(EXTRA_PROTOCOL, protocol);
-		intent.putExtra(EXTRA_BSSID, bssid);
-		intent.putExtra(RESULT_RECEIVER, receiver);
-		context.startService(intent);
-	}
-
-	public static void log(Context context, Record record) {
-		Intent intent = new Intent(context, OldLogger.class);
-		intent.setAction(ACTION_LOG);
-		intent.putExtra(EXTRA_RECORD, record);
-		context.startService(intent);
-	}
-
-	private UglyDbHelper mDbHelper;
-
-	public OldLogger() {
-		super("Logger");
-	}
-
-	@Override
-	public void onCreate() {
-		super.onCreate();
-		mDbHelper = new UglyDbHelper(getApplicationContext());
-	}
-
-	private boolean handleActionBssidSeen(String protocol, String bssid) {
-		return mDbHelper.bssidSeen(protocol, bssid);
-	}
-
-	/**
-	 * Delete all records.
-	 */
-	private void handleActionDeleteAll() {
-		mDbHelper.clearData();
-	}
-
-	private void handleActionDeleteByBssid(String bssid) {
-		mDbHelper.deleteByBSSID(bssid);
-	}
-
-	private void handleActionDeleteByDate(long time) {
-		mDbHelper.deleteByDate(time);
-	}
-
-	private String[] handleActionGetAllBssids() {
-		return mDbHelper.getAllBSSIDS();
-	}
-
-	private ArrayList<Record> handleActionGetAllRecords() {
-		return mDbHelper.getAllRecords();
-	}
-
-	private int handleActionGetAttackCount() {
-		return mDbHelper.getAttackCount();
-	}
-
-	private int handleActionGetAttackPerProtocolCount(String protocol) {
-		return mDbHelper.getAttackPerProtocolCount(protocol);
-	}
-
-	private long handleActionGetMaxAttackId() {
-		return mDbHelper.getHighestAttackId();
-	}
-
-	private long handleActionGetMinAttackId() {
-		return mDbHelper.getSmallestAttackId();
-	}
-
-	private Record handleActionGetRecordOfAttackId(long attack_id) {
-		return mDbHelper.getRecordOfAttackId(attack_id);
-	}
-
-	private ArrayList<Record> handleActionGetRecordOfEachAttack(int lastUploadedAttackId) {
-		return mDbHelper.getRecordOfEachAttack(lastUploadedAttackId);
-	}
-
-	private String handleActionGetSsid(String bssid) {
-		return mDbHelper.getSSID(bssid);
-	}
-
-	/**
-	 * Log a record.
-	 */
-	private void handleActionLog(Record record) {
-		mDbHelper.addRecord(record);
-	}
-
-	@Override
-	protected void onHandleIntent(Intent intent) {
-		if (intent != null) {
-			final String action = intent.getAction();
-			if (ACTION_LOG.equals(action)) {
-				final Record record = intent.getParcelableExtra(EXTRA_RECORD);
-				handleActionLog(record);
-			} else if (ACTION_GET_RECORD_ALL.equals(action)) {
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				ArrayList<Record> r = handleActionGetAllRecords();
-				Bundle result = new Bundle();
-				result.putParcelableArrayList("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_GET_RECORD_EACH.equals(action)) {
-				final int lastUploadedAttackId = intent.getIntExtra(EXTRA_PRIMITIVE, -1);
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				ArrayList<Record> r = handleActionGetRecordOfEachAttack(lastUploadedAttackId);
-				Bundle result = new Bundle();
-				result.putParcelableArrayList("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_GET_RECORD_ID.equals(action)) {
-				final int attack_id = intent.getIntExtra(EXTRA_PRIMITIVE, -1);
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				Record r = handleActionGetRecordOfAttackId(attack_id);
-				Bundle result = new Bundle();
-				result.putParcelable("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_GET_COUNT_ALL.equals(action)) {
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				int r = handleActionGetAttackCount();
-				Bundle result = new Bundle();
-				result.putInt("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_GET_COUNT_PROTOCOL.equals(action)) {
-				final String protocol = intent.getStringExtra(EXTRA_PROTOCOL);
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				int r = handleActionGetAttackPerProtocolCount(protocol);
-				Bundle result = new Bundle();
-				result.putInt("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_GET_ATTACK_MIN.equals(action)) {
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				long r = handleActionGetMinAttackId();
-				Bundle result = new Bundle();
-				result.putLong("result", r);
-				receiver.send(0, result);
-				handleActionGetMinAttackId();
-			} else if (ACTION_GET_ATTACK_MAX.equals(action)) {
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				long r = handleActionGetMaxAttackId();
-				Bundle result = new Bundle();
-				result.putLong("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_IS_BSSID_SEEN.equals(action)) {
-				final String protocol = intent.getStringExtra(EXTRA_PROTOCOL);
-				final String bssid = intent.getStringExtra(EXTRA_BSSID);
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				boolean r = handleActionBssidSeen(protocol, bssid);
-				Bundle result = new Bundle();
-				result.putBoolean("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_GET_BSSID_ALL.equals(action)) {
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				String[] r = handleActionGetAllBssids();
-				Bundle result = new Bundle();
-				result.putStringArray("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_GET_SSID_BSSID.equals(action)) {
-				final String bssid = intent.getStringExtra(EXTRA_BSSID);
-				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
-				String r = handleActionGetSsid(bssid);
-				Bundle result = new Bundle();
-				result.putString("result", r);
-				receiver.send(0, result);
-			} else if (ACTION_CLEAR_DATE.equals(action)) {
-				final long time = intent.getLongExtra(EXTRA_PRIMITIVE, -1L);
-				handleActionDeleteByDate(time);
-			} else if (ACTION_CLEAR_BSSID.equals(action)) {
-				final String bssid = intent.getStringExtra(EXTRA_BSSID);
-				handleActionDeleteByBssid(bssid);
-			} else if (ACTION_CLEAR_ALL.equals(action)) {
-				handleActionDeleteAll();
-			}
-		}
-	}
-
-}

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/deprecated/UglyDbHelper.java

@@ -13,7 +13,7 @@ import java.util.LinkedList;
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.logging.Record;
-import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
+import de.tudarmstadt.informatik.hostage.logging.MessageRecord.TYPE;
 import de.tudarmstadt.informatik.hostage.model.Profile;
 import de.tudarmstadt.informatik.hostage.ui.LogFilter;
 

+ 171 - 0
src/de/tudarmstadt/informatik/hostage/logging/AttackRecord.java

@@ -0,0 +1,171 @@
+package de.tudarmstadt.informatik.hostage.logging;
+
+import java.io.Serializable;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class AttackRecord implements Parcelable, Serializable{
+	
+	private static final long serialVersionUID = 6111024905373724227L;
+	
+	private long attack_id;
+	private String bssid;
+	private String protocol;
+	private String localIP;
+	private int localPort;
+	private String remoteIP;
+	private int remotePort;
+	private String externalIP;
+	
+	
+    public static final Parcelable.Creator<AttackRecord> CREATOR = new Parcelable.Creator<AttackRecord>() {
+    	@Override
+        public AttackRecord createFromParcel(Parcel source) {
+                    return new AttackRecord(source);
+            }
+
+            @Override
+            public AttackRecord[] newArray(int size) {
+            	return new AttackRecord[size];
+            }
+    };
+
+    public AttackRecord() {
+
+    }
+
+    public AttackRecord(Parcel source) {
+            this.attack_id = source.readLong();
+            this.protocol = source.readString();
+            this.localIP = source.readString();
+            this.localPort = source.readInt();
+            this.remoteIP = source.readString();
+            this.remotePort = source.readInt();
+            this.externalIP = source.readString();
+            this.bssid = source.readString();
+    }
+	
+	@Override
+	public int describeContents() {
+		return 0;
+	}
+	
+	@Override
+	public void writeToParcel(Parcel dest, int flags) {
+        dest.writeLong(attack_id);
+        dest.writeString(protocol);
+        dest.writeString(localIP);
+        dest.writeInt(localPort);
+        dest.writeString(remoteIP);
+        dest.writeInt(remotePort);
+        dest.writeString(externalIP);
+        dest.writeString(bssid);
+	}
+	
+	/**
+	 * @return the attack_id
+	 */
+	public long getAttack_id() {
+		return attack_id;
+	}
+	/**
+	 * @param attack_id the attack_id to set
+	 */
+	public void setAttack_id(long attack_id) {
+		this.attack_id = attack_id;
+	}
+	/**
+	 * @return the bssid
+	 */
+	public String getBssid() {
+		return bssid;
+	}
+	/**
+	 * @param bssid the bssid to set
+	 */
+	public void setBssid(String bssid) {
+		this.bssid = bssid;
+	}
+	/**
+	 * @return the protocol
+	 */
+	public String getProtocol() {
+		return protocol;
+	}
+	/**
+	 * @param protocol the protocol to set
+	 */
+	public void setProtocol(String protocol) {
+		this.protocol = protocol;
+	}
+	/**
+	 * @return the localIP
+	 */
+	public String getLocalIP() {
+		return localIP;
+	}
+	/**
+	 * @param localIP the localIP to set
+	 */
+	public void setLocalIP(String localIP) {
+		this.localIP = localIP;
+	}
+	/**
+	 * @return the localPort
+	 */
+	public int getLocalPort() {
+		return localPort;
+	}
+	/**
+	 * @param localPort the localPort to set
+	 */
+	public void setLocalPort(int localPort) {
+		this.localPort = localPort;
+	}
+	/**
+	 * @return the remoteIP
+	 */
+	public String getRemoteIP() {
+		return remoteIP;
+	}
+	/**
+	 * @param remoteIP the remoteIP to set
+	 */
+	public void setRemoteIP(String remoteIP) {
+		this.remoteIP = remoteIP;
+	}
+	/**
+	 * @return the remotePort
+	 */
+	public int getRemotePort() {
+		return remotePort;
+	}
+	/**
+	 * @param remotePort the remotePort to set
+	 */
+	public void setRemotePort(int remotePort) {
+		this.remotePort = remotePort;
+	}
+	/**
+	 * @return the externalIP
+	 */
+	public String getExternalIP() {
+		return externalIP;
+	}
+	/**
+	 * @param externalIP the externalIP to set
+	 */
+	public void setExternalIP(String externalIP) {
+		this.externalIP = externalIP;
+	}
+	
+	//TEMP ZU TEST
+	@Override
+	public String toString(){
+		return String
+				.format("{ \"sensor\":{\"type\": \"Honeypot\", \"name\": \"HosTaGe\"}, \"type\": \"%s server access\", \"src\":{\"ip\": \"%s\", \"port\": %d}, \"dst\":{\"ip\": \"%s\", \"port\": %d} }",
+						getProtocol(), getRemoteIP(), getRemotePort(), getExternalIP(), getLocalPort());
+	}
+
+}

+ 58 - 8
src/de/tudarmstadt/informatik/hostage/logging/Logger.java

@@ -3,18 +3,46 @@ package de.tudarmstadt.informatik.hostage.logging;
 import android.app.IntentService;
 import android.content.Context;
 import android.content.Intent;
+import android.os.Parcelable;
+import de.tudarmstadt.informatik.hostage.logging.MessageRecord.TYPE;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
 
 public class Logger extends IntentService {
 
-	private static final String ACTION_LOG = "de.tudarmstadt.informatik.hostage.action.LOG";
+	private static final String ACTION_LOG_MESSAGE = "de.tudarmstadt.informatik.hostage.action.LOG_MESSAGE";
+	private static final String ACTION_LOG_ATTACK = "de.tudarmstadt.informatik.hostage.action.LOG_ATTACK";
+	private static final String ACTION_LOG_NETWORK = "de.tudarmstadt.informatik.hostage.action.LOG_NETWORK";
+	private static final String ACTION_LOG_PORTSCAN = "de.tudarmstadt.informatik.hostage.action.LOG_PORTSCAN";
 
 	private static final String EXTRA_RECORD = "de.tudarmstadt.informatik.hostage.extra.RECORD";
+	private static final String EXTRA_TIMESTAMP = "de.tudarmstadt.informatik.hostage.extra.TIMESTAMP";
 
-	public static void log(Context context, Record record) {
+	public static void log(Context context, MessageRecord record) {
 		Intent intent = new Intent(context, Logger.class);
-		intent.setAction(ACTION_LOG);
-		intent.putExtra(EXTRA_RECORD, record);
+		intent.setAction(ACTION_LOG_MESSAGE);
+		intent.putExtra(EXTRA_RECORD, (Parcelable)record);
+		context.startService(intent);
+	}
+	
+	public static void log(Context context, AttackRecord record) {
+		Intent intent = new Intent(context, Logger.class);
+		intent.setAction(ACTION_LOG_ATTACK);
+		intent.putExtra(EXTRA_RECORD, (Parcelable)record);
+		context.startService(intent);
+	}
+	
+	public static void log(Context context, NetworkRecord record) {
+		Intent intent = new Intent(context, Logger.class);
+		intent.setAction(ACTION_LOG_NETWORK);
+		intent.putExtra(EXTRA_RECORD, (Parcelable)record);
+		context.startService(intent);
+	}
+	
+	public static void logPortscan(Context context, AttackRecord record, long timestamp){
+		Intent intent = new Intent(context, Logger.class);
+		intent.setAction(ACTION_LOG_PORTSCAN);
+		intent.putExtra(EXTRA_RECORD, (Parcelable)record);
+		intent.putExtra(EXTRA_TIMESTAMP, timestamp);
 		context.startService(intent);
 	}
 
@@ -30,17 +58,39 @@ public class Logger extends IntentService {
 		mDbHelper = new HostageDBOpenHelper(getApplicationContext());
 	}
 
-	private void handleActionLog(Record record) {
-		mDbHelper.addRecord(record);
+	private void handleActionLog(MessageRecord record) {
+		mDbHelper.addMessageRecord(record);
+	}
+	private void handleActionLog(AttackRecord record) {
+		mDbHelper.addAttackRecord(record);
+		mDbHelper.updateSyncAttackCounter(record);
+	}
+	private void handleActionLog(NetworkRecord record) {
+		mDbHelper.updateNetworkInformation(record);
 	}
 
 	@Override
 	protected void onHandleIntent(Intent intent) {
 		if (intent != null) {
 			final String action = intent.getAction();
-			if (ACTION_LOG.equals(action)) {
-				final Record record = intent.getParcelableExtra(EXTRA_RECORD);
+			if (ACTION_LOG_MESSAGE.equals(action)) {
+				final MessageRecord record = intent.getParcelableExtra(EXTRA_RECORD);
+				handleActionLog(record);
+			}else if(ACTION_LOG_ATTACK.equals(action)){
+				final AttackRecord record = intent.getParcelableExtra(EXTRA_RECORD);
+				handleActionLog(record);
+			}else if(ACTION_LOG_NETWORK.equals(action)){
+				final NetworkRecord record = intent.getParcelableExtra(EXTRA_RECORD);
+				handleActionLog(record);
+			}else if(ACTION_LOG_PORTSCAN.equals(action)){
+				final AttackRecord record = intent.getParcelableExtra(EXTRA_RECORD);
 				handleActionLog(record);
+				MessageRecord mRecord = new MessageRecord();
+				mRecord.setAttack_id(record.getAttack_id());
+				mRecord.setId(0);
+				mRecord.setPacket("");
+				mRecord.setTimestamp(intent.getLongExtra(EXTRA_TIMESTAMP, 0));
+				mRecord.setType(TYPE.RECEIVE);
 			}
 		}
 	}

+ 125 - 0
src/de/tudarmstadt/informatik/hostage/logging/MessageRecord.java

@@ -0,0 +1,125 @@
+package de.tudarmstadt.informatik.hostage.logging;
+
+import java.io.Serializable;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+
+public class MessageRecord implements Parcelable, Serializable{
+	
+	private static final long serialVersionUID = -5936572995202342935L;
+	
+	public static enum TYPE {
+		SEND, RECEIVE
+	};
+	
+	// attack
+	private int id;
+	private long attack_id;
+	private long timestamp;
+	private TYPE type;
+	private String packet;
+	
+    public static final Parcelable.Creator<MessageRecord> CREATOR = new Parcelable.Creator<MessageRecord>() {
+    	@Override
+        public MessageRecord createFromParcel(Parcel source) {
+                    return new MessageRecord(source);
+            }
+
+            @Override
+            public MessageRecord[] newArray(int size) {
+            	return new MessageRecord[size];
+            }
+    };
+
+
+    public MessageRecord() {
+
+    }
+
+
+    public MessageRecord(Parcel source) {
+            this.id = source.readInt();
+            this.attack_id = source.readLong();
+            this.timestamp = source.readLong();
+            this.type = TYPE.valueOf(source.readString());
+            this.packet = source.readString(); 
+    }
+
+	
+	@Override
+	public int describeContents() {
+		return 0;
+	}
+	
+	@Override
+	public void writeToParcel(Parcel dest, int flags) {
+        dest.writeInt(id);
+        dest.writeLong(attack_id);
+        dest.writeLong(timestamp);
+        dest.writeString(type.name());
+        dest.writeString(packet);
+	}
+	
+	/**
+	 * @return the id
+	 */
+	public int getId() {
+		return id;
+	}
+	/**
+	 * @param id the id to set
+	 */
+	public void setId(int id) {
+		this.id = id;
+	}
+	/**
+	 * @return the attack_id
+	 */
+	public long getAttack_id() {
+		return attack_id;
+	}
+	/**
+	 * @param attack_id the attack_id to set
+	 */
+	public void setAttack_id(long attack_id) {
+		this.attack_id = attack_id;
+	}
+	/**
+	 * @return the timestamp
+	 */
+	public long getTimestamp() {
+		return timestamp;
+	}
+	/**
+	 * @param timestamp the timestamp to set
+	 */
+	public void setTimestamp(long timestamp) {
+		this.timestamp = timestamp;
+	}
+	/**
+	 * @return the type
+	 */
+	public TYPE getType() {
+		return type;
+	}
+	/**
+	 * @param type the type to set
+	 */
+	public void setType(TYPE type) {
+		this.type = type;
+	}
+	/**
+	 * @return the packet
+	 */
+	public String getPacket() {
+		return packet;
+	}
+	/**
+	 * @param packet the packet to set
+	 */
+	public void setPacket(String packet) {
+		this.packet = packet;
+	}
+}

+ 136 - 0
src/de/tudarmstadt/informatik/hostage/logging/NetworkRecord.java

@@ -0,0 +1,136 @@
+package de.tudarmstadt.informatik.hostage.logging;
+
+import java.io.Serializable;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class NetworkRecord implements Parcelable, Serializable{	
+	
+	private static final long serialVersionUID = -1586629159904177836L;
+
+	private String bssid;
+	private String ssid;
+	private long timestampLocation;
+	private double latitude;
+	private double longitude;
+	private float accuracy;
+	
+    public static final Parcelable.Creator<NetworkRecord> CREATOR = new Parcelable.Creator<NetworkRecord>() {
+    	@Override
+        public NetworkRecord createFromParcel(Parcel source) {
+                    return new NetworkRecord(source);
+            }
+
+            @Override
+            public NetworkRecord[] newArray(int size) {
+            	return new NetworkRecord[size];
+            }
+    };
+
+
+    public NetworkRecord() {
+
+    }
+
+
+    public NetworkRecord(Parcel source) {
+            this.bssid = source.readString();
+            this.ssid = source.readString();  
+            this.timestampLocation = source.readLong();
+            this.latitude = source.readDouble();
+            this.longitude = source.readDouble();
+            this.accuracy = source.readFloat();
+    }
+
+	
+	@Override
+	public int describeContents() {
+		return 0;
+	}
+	
+	@Override
+	public void writeToParcel(Parcel dest, int flags) {
+        dest.writeString(bssid);
+        dest.writeString(ssid);
+        dest.writeLong(timestampLocation);
+        dest.writeDouble(latitude);
+        dest.writeDouble(longitude);
+        dest.writeFloat(accuracy);
+
+	}
+	
+	/**
+	 * @return the bssid
+	 */
+	public String getBssid() {
+		return bssid;
+	}
+	/**
+	 * @param bssid the bssid to set
+	 */
+	public void setBssid(String bssid) {
+		this.bssid = bssid;
+	}
+	/**
+	 * @return the ssid
+	 */
+	public String getSsid() {
+		return ssid;
+	}
+	/**
+	 * @param ssid the ssid to set
+	 */
+	public void setSsid(String ssid) {
+		this.ssid = ssid;
+	}
+	/**
+	 * @return the timestampLocation
+	 */
+	public long getTimestampLocation() {
+		return timestampLocation;
+	}
+	/**
+	 * @param timestampLocation the timestampLocation to set
+	 */
+	public void setTimestampLocation(long timestampLocation) {
+		this.timestampLocation = timestampLocation;
+	}
+	/**
+	 * @return the latitude
+	 */
+	public double getLatitude() {
+		return latitude;
+	}
+	/**
+	 * @param latitude the latitude to set
+	 */
+	public void setLatitude(double latitude) {
+		this.latitude = latitude;
+	}
+	/**
+	 * @return the longitude
+	 */
+	public double getLongitude() {
+		return longitude;
+	}
+	/**
+	 * @param longitude the longitude to set
+	 */
+	public void setLongitude(double longitude) {
+		this.longitude = longitude;
+	}
+	/**
+	 * @return the accuracy
+	 */
+	public float getAccuracy() {
+		return accuracy;
+	}
+	/**
+	 * @param accuracy the accuracy to set
+	 */
+	public void setAccuracy(float accuracy) {
+		this.accuracy = accuracy;
+	}
+
+}

+ 47 - 133
src/de/tudarmstadt/informatik/hostage/logging/Record.java

@@ -1,218 +1,159 @@
 package de.tudarmstadt.informatik.hostage.logging;
 
-import android.os.Parcel;
-import android.os.Parcelable;
+import de.tudarmstadt.informatik.hostage.logging.MessageRecord.TYPE;
 import de.tudarmstadt.informatik.hostage.logging.formatter.Formatter;
 
-public class Record implements Parcelable {
-
-	public static enum TYPE {
-		SEND, RECEIVE
-	};
+public class Record {
 
+	//
+	private MessageRecord message;
 	// attack
-	private int id;
-	private long attack_id;
-	private long timestamp;
-	private String protocol;
-	private TYPE type;
-	private String packet;
-
+	private AttackRecord attack;
 	// network
-	private String localIP;
-	private int localPort;
-	private String remoteIP;
-	private int remotePort;
-	private String externalIP;
-	private String bssid;
-	private String ssid;
-
-	// location
-	private long timestampLocation;
-	private double latitude;
-	private double longitude;
-	private float accuracy;
-
-	public static final Parcelable.Creator<Record> CREATOR = new Parcelable.Creator<Record>() {
-
-		@Override
-		public Record createFromParcel(Parcel source) {
-			return new Record(source);
-		}
-
-		@Override
-		public Record[] newArray(int size) {
-			return new Record[size];
-		}
-	};
-
-	public Record() {
-	}
-
-	public Record(Parcel source) {
-		// attack
-		this.id = source.readInt();
-		this.attack_id = source.readLong();
-		this.timestamp = source.readLong();
-		this.protocol = source.readString();
-		this.type = TYPE.valueOf(source.readString());
-		this.packet = source.readString();
-
-		// network
-		this.localIP = source.readString();
-		this.localPort = source.readInt();
-		this.remoteIP = source.readString();
-		this.remotePort = source.readInt();
-		this.externalIP = source.readString();
-		this.bssid = source.readString();
-		this.ssid = source.readString();
-
-		// location
-		this.timestampLocation = source.readLong();
-		this.latitude = source.readDouble();
-		this.longitude = source.readDouble();
-		this.accuracy = source.readFloat();
-	}
-
-	@Override
-	public int describeContents() {
-		return 0;
+	private NetworkRecord network;
+	
+	public Record(){
+		message = new MessageRecord();
+		attack = new AttackRecord();
+		network = new NetworkRecord();
 	}
 
 	public float getAccuracy() {
-		return accuracy;
+		return network.getAccuracy();
 	}
 
 	public long getAttack_id() {
-		return attack_id;
+		return attack.getAttack_id();
 	}
 
 	public String getBssid() {
-		return bssid;
+		return network.getBssid();
 	}
 
 	public String getExternalIP() {
-		return externalIP;
+		return attack.getExternalIP();
 	}
 
 	public int getId() {
-		return id;
+		return message.getId();
 	}
 
 	public double getLatitude() {
-		return latitude;
+		return network.getLatitude();
 	}
 
 	public String getLocalIP() {
-		return localIP;
+		return attack.getLocalIP();
 	}
 
 	public int getLocalPort() {
-		return localPort;
+		return attack.getLocalPort();
 	}
 
 	public double getLongitude() {
-		return longitude;
+		return network.getLongitude();
 	}
 
 	public String getPacket() {
-		return packet;
+		return message.getPacket();
 	}
 
 	public String getProtocol() {
-		return protocol;
+		return attack.getProtocol();
 	}
 
 	public String getRemoteIP() {
-		return remoteIP;
+		return attack.getRemoteIP();
 	}
 
 	public int getRemotePort() {
-		return remotePort;
+		return attack.getRemotePort();
 	}
 
 	public String getSsid() {
-		return ssid;
+		return network.getSsid();
 	}
 
 	public long getTimestamp() {
-		return timestamp;
+		return message.getTimestamp();
 	}
 
 	public long getTimestampLocation() {
-		return timestampLocation;
+		return network.getTimestampLocation();
 	}
 
 	public TYPE getType() {
-		return type;
+		return message.getType();
 	}
 
 	public void setAccuracy(float accuracy) {
-		this.accuracy = accuracy;
+		network.setAccuracy(accuracy);
 	}
 
 	public void setAttack_id(long attack_id) {
-		this.attack_id = attack_id;
+		message.setAttack_id(attack_id);
+		attack.setAttack_id(attack_id);
 	}
 
 	public void setBssid(String bssid) {
-		this.bssid = bssid;
+		attack.setBssid(bssid);
+		network.setBssid(bssid);
 	}
 
 	public void setExternalIP(String externalIP) {
-		this.externalIP = externalIP;
+		attack.setExternalIP(externalIP);
 	}
 
 	public void setId(int id) {
-		this.id = id;
+		message.setId(id);
 	}
 
 	public void setLatitude(double latitude) {
-		this.latitude = latitude;
+		network.setLatitude(latitude);
 	}
 
 	public void setLocalIP(String localIP) {
-		this.localIP = localIP;
+		attack.setLocalIP(localIP);
 	}
 
 	public void setLocalPort(int localPort) {
-		this.localPort = localPort;
+		attack.setLocalPort(localPort);
 	}
 
 	public void setLongitude(double longitude) {
-		this.longitude = longitude;
+		network.setLongitude(longitude);
 	}
 
 	public void setPacket(String packet) {
-		this.packet = packet;
+		message.setPacket(packet);
 	}
 
 	public void setProtocol(String protocol) {
-		this.protocol = protocol;
+		attack.setProtocol(protocol);
 	}
 
 	public void setRemoteIP(String remoteIP) {
-		this.remoteIP = remoteIP;
+		attack.setRemoteIP(remoteIP);
 	}
 
 	public void setRemotePort(int remotePort) {
-		this.remotePort = remotePort;
+		attack.setRemotePort(remotePort);
 	}
 
 	public void setSsid(String ssid) {
-		this.ssid = ssid;
+		network.setSsid(ssid);
 	}
 
 	public void setTimestamp(long timestamp) {
-		this.timestamp = timestamp;
+		message.setTimestamp(timestamp);
 	}
 
 	public void setTimestampLocation(long timestampLocation) {
-		this.timestampLocation = timestampLocation;
+		network.setTimestampLocation(timestampLocation);
 	}
 
 	public void setType(TYPE type) {
-		this.type = type;
+		message.setType(type);
 	}
 
 	@Override
@@ -226,31 +167,4 @@ public class Record implements Parcelable {
 		}
 		return formatter.format(this);
 	}
-
-	@Override
-	public void writeToParcel(Parcel dest, int flags) {
-		// attack
-		dest.writeInt(id);
-		dest.writeLong(attack_id);
-		dest.writeLong(timestamp);
-		dest.writeString(protocol);
-		dest.writeString(type.name());
-		dest.writeString(packet);
-
-		// network
-		dest.writeString(localIP);
-		dest.writeInt(localPort);
-		dest.writeString(remoteIP);
-		dest.writeInt(remotePort);
-		dest.writeString(externalIP);
-		dest.writeString(bssid);
-		dest.writeString(ssid);
-
-		// location
-		dest.writeLong(timestampLocation);
-		dest.writeDouble(latitude);
-		dest.writeDouble(longitude);
-		dest.writeFloat(accuracy);
-	}
-
 }

+ 63 - 0
src/de/tudarmstadt/informatik/hostage/logging/SyncInfoRecord.java

@@ -0,0 +1,63 @@
+package de.tudarmstadt.informatik.hostage.logging;
+
+import java.io.Serializable;
+
+public class SyncInfoRecord implements Serializable{	
+
+	private static final long serialVersionUID = 7156818788190434192L;
+	
+	private String deviceID;
+	private String BSSID;
+	private long number_of_attacks;
+	private long number_of_portscans;
+	
+	/**
+	 * @return the deviceID
+	 */
+	public String getDeviceID() {
+		return deviceID;
+	}
+	/**
+	 * @param deviceID the deviceID to set
+	 */
+	public void setDeviceID(String deviceID) {
+		this.deviceID = deviceID;
+	}
+	/**
+	 * @return the bSSID
+	 */
+	public String getBSSID() {
+		return BSSID;
+	}
+	/**
+	 * @param bSSID the bSSID to set
+	 */
+	public void setBSSID(String bSSID) {
+		BSSID = bSSID;
+	}
+	/**
+	 * @return the number_of_attacks
+	 */
+	public long getNumber_of_attacks() {
+		return number_of_attacks;
+	}
+	/**
+	 * @param number_of_attacks the number_of_attacks to set
+	 */
+	public void setNumber_of_attacks(long number_of_attacks) {
+		this.number_of_attacks = number_of_attacks;
+	}
+	/**
+	 * @return the number_of_portscans
+	 */
+	public long getNumber_of_portscans() {
+		return number_of_portscans;
+	}
+	/**
+	 * @param number_of_portscans the number_of_portscans to set
+	 */
+	public void setNumber_of_portscans(long number_of_portscans) {
+		this.number_of_portscans = number_of_portscans;
+	}
+
+}

+ 18 - 1
src/de/tudarmstadt/informatik/hostage/persistence/HostageDBContract.java

@@ -40,5 +40,22 @@ public final class HostageDBContract {
 
 		public static final String KEY_ID = COLUMN_NAME_ID;
 	}
-
+	
+	public static abstract class SyncDeviceEntry implements BaseColumns {
+		public static final String TABLE_NAME = "sync_devices";
+		public static final String COLUMN_NAME_DEVICE_ID = "_device_id";	
+		public static final String COLUMN_NAME_DEVICE_TIMESTAMP = "last_sync_timestamp";
+		
+		public static final String KEY_ID = COLUMN_NAME_DEVICE_ID;
+	}
+	
+	public static abstract class SyncInfoEntry implements BaseColumns {
+		public static final String TABLE_NAME = "sync_info";
+		public static final String COLUMN_NAME_DEVICE_ID = "_device_id";	
+		public static final String COLUMN_NAME_BSSID = "_bssid";
+		public static final String COLUMN_NAME_NUMBER_ATTACKS = "number_of_attacks";
+		public static final String COLUMN_NAME_NUMBER_PORTSCANS = "number_of_portscans";		
+		
+		public static final String KEY_ID = COLUMN_NAME_DEVICE_ID;
+	}
 }

+ 432 - 260
src/de/tudarmstadt/informatik/hostage/persistence/HostageDBOpenHelper.java

@@ -9,16 +9,22 @@ import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.util.Log;
-import de.tudarmstadt.informatik.hostage.logging.Record;
-import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
+import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
+import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
+import de.tudarmstadt.informatik.hostage.logging.SyncInfoRecord;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.AttackEntry;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.NetworkEntry;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.PacketEntry;
+import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.SyncDeviceEntry;
+import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.SyncInfoEntry;
 
 public class HostageDBOpenHelper extends SQLiteOpenHelper {
 
 	private static final String DATABASE_NAME = "hostage.db";
 	private static final int DATABASE_VERSION = 1;
+	private Context context;
 
 	static {
 		StringBuilder networkSQLBuilder = new StringBuilder("CREATE TABLE ").append(NetworkEntry.TABLE_NAME).append("(");
@@ -56,95 +62,151 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 				AttackEntry.COLUMN_NAME_ATTACK_ID));
 		packetSQLBuilder.append(")");
 		SQL_CREATE_PACKET_ENTRIES = packetSQLBuilder.toString();
+		
+		StringBuilder syncDevicesSQLBuilder = new StringBuilder("CREATE TABLE ").append(SyncDeviceEntry.TABLE_NAME).append("(");
+		syncDevicesSQLBuilder.append(SyncDeviceEntry.COLUMN_NAME_DEVICE_ID).append(" TEXT PRIMARY KEY,");
+		syncDevicesSQLBuilder.append(SyncDeviceEntry.COLUMN_NAME_DEVICE_TIMESTAMP).append(" INTEGER");
+		syncDevicesSQLBuilder.append(")");
+		SQL_CREATE_SYNC_DEVICES_ENTRIES = syncDevicesSQLBuilder.toString();
+		
+		StringBuilder syncInfoSQLBuilder = new StringBuilder("CREATE TABLE ").append(SyncInfoEntry.TABLE_NAME).append("(");
+		syncInfoSQLBuilder.append(SyncInfoEntry.COLUMN_NAME_DEVICE_ID).append(" TEXT,");
+		syncInfoSQLBuilder.append(SyncInfoEntry.COLUMN_NAME_BSSID).append(" TEXT,");
+		syncInfoSQLBuilder.append(SyncInfoEntry.COLUMN_NAME_NUMBER_ATTACKS).append(" INTEGER,");
+		syncInfoSQLBuilder.append(SyncInfoEntry.COLUMN_NAME_NUMBER_PORTSCANS).append(" INTEGER,");
+		syncInfoSQLBuilder.append(String.format("PRIMARY KEY(%s,%s)", SyncInfoEntry.COLUMN_NAME_DEVICE_ID, SyncInfoEntry.COLUMN_NAME_BSSID));
+		syncInfoSQLBuilder.append(String.format("FOREIGN KEY(%s) REFERENCES %s(%s)", SyncInfoEntry.COLUMN_NAME_BSSID, NetworkEntry.TABLE_NAME,
+				NetworkEntry.COLUMN_NAME_BSSID));
+		syncInfoSQLBuilder.append(")");
+		SQL_CREATE_SYNC_INFO_ENTRIES = syncInfoSQLBuilder.toString();
+		
+
 	}
 
 	private static final String SQL_CREATE_NETWORK_ENTRIES;
 	private static final String SQL_CREATE_ATTACK_ENTRIES;
 	private static final String SQL_CREATE_PACKET_ENTRIES;
+	private static final String SQL_CREATE_SYNC_DEVICES_ENTRIES;
+	private static final String SQL_CREATE_SYNC_INFO_ENTRIES;
 
 	private static final String SQL_DELETE_PACKET_ENTRIES = "DROP TABLE IF EXISTS " + PacketEntry.TABLE_NAME;
 	private static final String SQL_DELETE_ATTACK_ENTRIES = "DROP TABLE IF EXISTS " + AttackEntry.TABLE_NAME;
 	private static final String SQL_DELETE_NETWORK_ENTRIES = "DROP TABLE IF EXISTS " + NetworkEntry.TABLE_NAME;
+	private static final String SQL_DELETE_SYNC_DEVICES_ENTRIES = "DROP TABLE IF EXISTS " + SyncDeviceEntry.TABLE_NAME;
+	private static final String SQL_DELETE_SYNC_INFO_ENTRIES = "DROP TABLE IF EXISTS " + SyncInfoEntry.TABLE_NAME;
 
 	public HostageDBOpenHelper(Context context) {
 		super(context, DATABASE_NAME, null, DATABASE_VERSION);
+		this.context = context;
 	}
 
 	@Override
 	public void onCreate(SQLiteDatabase db) {
-		db.execSQL(SQL_CREATE_PACKET_ENTRIES);
-		db.execSQL(SQL_CREATE_ATTACK_ENTRIES);
 		db.execSQL(SQL_CREATE_NETWORK_ENTRIES);
+		db.execSQL(SQL_CREATE_ATTACK_ENTRIES);
+		db.execSQL(SQL_CREATE_PACKET_ENTRIES);
+		db.execSQL(SQL_CREATE_SYNC_DEVICES_ENTRIES);
+		db.execSQL(SQL_CREATE_SYNC_INFO_ENTRIES);
 	}
 
 	@Override
 	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+		db.execSQL(SQL_DELETE_SYNC_INFO_ENTRIES);
 		db.execSQL(SQL_DELETE_PACKET_ENTRIES);
 		db.execSQL(SQL_DELETE_ATTACK_ENTRIES);
 		db.execSQL(SQL_DELETE_NETWORK_ENTRIES);
+		db.execSQL(SQL_DELETE_SYNC_DEVICES_ENTRIES);
 		onCreate(db);
 	}
 
 	/**
-	 * Adds a given {@link Record} to the database.
+	 * Adds a given {@link MessageRecord} to the database.
 	 * 
 	 * @param record
-	 *            The added {@link Record} .
+	 *            The added {@link MessageRecord} .
 	 */
-	public void addRecord(Record record) {
+	public void addMessageRecord(MessageRecord record) {
 		SQLiteDatabase db = this.getWritableDatabase();
 
-		HashMap<String, Object> bssidValues = new HashMap<String, Object>();
-		bssidValues.put(NetworkEntry.COLUMN_NAME_BSSID, record.getBssid());
-		bssidValues.put(NetworkEntry.COLUMN_NAME_SSID, record.getSsid());
-		bssidValues.put(NetworkEntry.COLUMN_NAME_LATITUDE, record.getLatitude());
-		bssidValues.put(NetworkEntry.COLUMN_NAME_LONGITUDE, record.getLongitude());
-		bssidValues.put(NetworkEntry.COLUMN_NAME_ACCURACY, record.getAccuracy());
-		bssidValues.put(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, record.getTimestampLocation());
+		ContentValues recordValues = new ContentValues();
+		recordValues.put(PacketEntry.COLUMN_NAME_ID, record.getId()); // Log Message Number
+		recordValues.put(PacketEntry.COLUMN_NAME_ATTACK_ID, record.getAttack_id()); // Log Attack ID
+		recordValues.put(PacketEntry.COLUMN_NAME_TYPE, record.getType().name()); // Log Type
+		recordValues.put(PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP, record.getTimestamp()); // Log Timestamp
+		recordValues.put(PacketEntry.COLUMN_NAME_PACKET, record.getPacket()); // Log Packet
+
+		// Inserting Rows
+		db.insert(PacketEntry.TABLE_NAME, null, recordValues);
+		db.close(); // Closing database connection
+	}
+	
+	/**
+	 * Adds a given {@link AttackRecord} to the database.
+	 * 
+	 * @param record
+	 *            The added {@link AttackRecord} .
+	 */
+	public void addAttackRecord(AttackRecord record) {
+		Log.i("DBHelper", "Add Attack Record with id: " + record.getAttack_id());
+		SQLiteDatabase db = this.getWritableDatabase();
 
 		ContentValues attackValues = new ContentValues();
-		attackValues.put(AttackEntry.COLUMN_NAME_ATTACK_ID, record.getAttack_id()); // Log
-																					// Attack
-																					// ID
+		attackValues.put(AttackEntry.COLUMN_NAME_ATTACK_ID, record.getAttack_id()); // Log Attack ID
 		attackValues.put(AttackEntry.COLUMN_NAME_PROTOCOL, record.getProtocol().toString());
 		attackValues.put(AttackEntry.COLUMN_NAME_EXTERNAL_IP, record.getExternalIP());
-		attackValues.put(AttackEntry.COLUMN_NAME_LOCAL_IP, record.getLocalIP()); // Log
-																					// Local
-																					// IP
+		attackValues.put(AttackEntry.COLUMN_NAME_LOCAL_IP, record.getLocalIP()); // Log Local IP
 		attackValues.put(AttackEntry.COLUMN_NAME_LOCAL_PORT, record.getLocalPort());
-		attackValues.put(AttackEntry.COLUMN_NAME_REMOTE_IP, record.getRemoteIP()); // Log
-																					// Remote
-																					// IP
-		attackValues.put(AttackEntry.COLUMN_NAME_REMOTE_PORT, record.getRemotePort()); // Log
-																						// Remote
-																						// Port
+		attackValues.put(AttackEntry.COLUMN_NAME_REMOTE_IP, record.getRemoteIP()); // Log Remote IP
+		attackValues.put(AttackEntry.COLUMN_NAME_REMOTE_PORT, record.getRemotePort()); // Log Remote Port
 		attackValues.put(AttackEntry.COLUMN_NAME_BSSID, record.getBssid());
-
-		ContentValues recordValues = new ContentValues();
-		recordValues.put(PacketEntry.COLUMN_NAME_ID, record.getId()); // Log
-																		// Message
-																		// Number
-		recordValues.put(PacketEntry.COLUMN_NAME_ATTACK_ID, record.getAttack_id()); // Log
-																					// Attack
-																					// ID
-		recordValues.put(PacketEntry.COLUMN_NAME_TYPE, record.getType().name()); // Log
-																					// Type
-		recordValues.put(PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP, record.getTimestamp()); // Log
-																							// Timestamp
-		recordValues.put(PacketEntry.COLUMN_NAME_PACKET, record.getPacket()); // Log
-																				// Packet
+		
 
 		// Inserting Rows
 		db.insertWithOnConflict(AttackEntry.TABLE_NAME, null, attackValues, SQLiteDatabase.CONFLICT_REPLACE);
-		db.insert(PacketEntry.TABLE_NAME, null, recordValues);
 		db.close(); // Closing database connection
-		// Update Network Information
-		updateNetworkInformation(bssidValues);
 	}
+	
+	public void updateSyncAttackCounter(AttackRecord record){
+		
+		SQLiteDatabase db = this.getWritableDatabase();
+
+		String mac = HelperUtils.getMacAdress(context);
+		ContentValues syncDeviceValues = new ContentValues();
+		syncDeviceValues.put(SyncDeviceEntry.COLUMN_NAME_DEVICE_ID, mac);
+		syncDeviceValues.put(SyncDeviceEntry.COLUMN_NAME_DEVICE_TIMESTAMP, System.currentTimeMillis());
+		
+		String query = "SELECT  * FROM " + SyncInfoEntry.TABLE_NAME + 
+					  " WHERE " + SyncInfoEntry.COLUMN_NAME_DEVICE_ID + " = ? " +
+					   "AND " + SyncInfoEntry.COLUMN_NAME_BSSID + " = ?";
+		Cursor cursor = db.rawQuery(query, new String[] {mac, record.getBssid()});
+		long attackCount = 0;
+		long portscanCount = 0;
+		if (cursor.moveToFirst()){
+			attackCount = cursor.getLong(2);
+			portscanCount = cursor.getLong(3);
+		}			
+		
+		if("PORTSCAN".equals(record.getProtocol())){
+			portscanCount++;
+		}else { attackCount++; }
+			
+		Log.i("DBHelper", "Update number of attack: " + attackCount);
+		
+		ContentValues synInfoValues = new ContentValues();
+		synInfoValues.put(SyncInfoEntry.COLUMN_NAME_BSSID, record.getBssid());
+		synInfoValues.put(SyncInfoEntry.COLUMN_NAME_DEVICE_ID, mac);
+		synInfoValues.put(SyncInfoEntry.COLUMN_NAME_NUMBER_ATTACKS, attackCount);
+		synInfoValues.put(SyncInfoEntry.COLUMN_NAME_NUMBER_PORTSCANS, portscanCount);
+
+		// Inserting Rows
+		db.insertWithOnConflict(SyncInfoEntry.TABLE_NAME, null, synInfoValues, SQLiteDatabase.CONFLICT_REPLACE);
+		db.insertWithOnConflict(SyncDeviceEntry.TABLE_NAME, null, syncDeviceValues, SQLiteDatabase.CONFLICT_REPLACE);
+		db.close(); // Closing database connection
+	}
+	
 
 	/**
-	 * Determines if a network with given BSSID has already been recorded as
-	 * malicious.
+	 * Determines if a network with given BSSID has already been recorded as malicious.
 	 * 
 	 * @param BSSID
 	 *            The BSSID of the network.
@@ -152,9 +214,9 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	 *         BSSID, else false.
 	 */
 	public boolean bssidSeen(String BSSID) {
-		String countQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME + " WHERE " + NetworkEntry.COLUMN_NAME_BSSID + " = " + "'" + BSSID + "'";
+		String countQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME + " WHERE " + NetworkEntry.COLUMN_NAME_BSSID + " = ?";
 		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
+		Cursor cursor = db.rawQuery(countQuery, new String[] {BSSID});
 		int result = cursor.getCount();
 		cursor.close();
 		db.close();
@@ -175,52 +237,19 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	 *         network with the given BSSID, else false.
 	 */
 	public boolean bssidSeen(String protocol, String BSSID) {
+		if(BSSID == null || protocol == null){
+			return false;
+		}
 		String countQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME + " NATURAL JOIN " + NetworkEntry.TABLE_NAME + " WHERE "
-				+ AttackEntry.COLUMN_NAME_PROTOCOL + " = " + "'" + protocol + "'" + " AND " + NetworkEntry.COLUMN_NAME_BSSID + " = " + "'" + BSSID + "'";
+				+ AttackEntry.COLUMN_NAME_PROTOCOL + " = ? AND " + NetworkEntry.COLUMN_NAME_BSSID + " = ?";
 		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
+		Cursor cursor = db.rawQuery(countQuery, new String[]{protocol, BSSID});
 		int result = cursor.getCount();
 		cursor.close();
 		db.close();
 		return result > 0;
 	}
 
-	/**
-	 * Deletes all records from {@link #PacketEntry.TABLE_NAME}.
-	 */
-	public void clearData() {
-		SQLiteDatabase db = this.getReadableDatabase();
-		db.delete(PacketEntry.TABLE_NAME, null, null);
-		db.delete(AttackEntry.TABLE_NAME, null, null);
-		db.close();
-	}
-
-	/**
-	 * Deletes all records from {@link #PacketEntry.TABLE_NAME} with a specific BSSID.
-	 * 
-	 * @param bssid
-	 *            The BSSID to match against.
-	 */
-	public void deleteByBSSID(String bssid) {
-		SQLiteDatabase db = this.getReadableDatabase();
-		db.delete(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_BSSID + " = ?", new String[] { bssid });
-		db.delete(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_BSSID + " = ?", new String[] { bssid });
-		db.close();
-	}
-
-	/**
-	 * Deletes all records from {@link #PacketEntry.TABLE_NAME} with a time stamp smaller
-	 * then the given
-	 * 
-	 * @param date
-	 *            A Date represented in milliseconds.
-	 */
-	public void deleteByDate(long date) {
-		SQLiteDatabase db = this.getReadableDatabase();
-		String deleteQuery = "DELETE  FROM " + PacketEntry.TABLE_NAME + " WHERE " + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP + " < " + date;
-		db.execSQL(deleteQuery);
-		db.close();
-	}
 
 	/**
 	 * Returns a String array with all BSSIDs stored in the database.
@@ -246,73 +275,38 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	}
 
 	/**
-	 * Gets all received {@link Record Records} for every attack identified by
-	 * its attack id and ordered by date.
+	 * Determines the number of different attacks in the database.
 	 * 
-	 * @return A ArrayList with all received {@link Record Records} for each
-	 *         attack id in the Database.
+	 * @return The number of different attacks in the database.
 	 */
-	public ArrayList<Record> getAllReceivedRecordsOfEachAttack() {
-		ArrayList<Record> recordList = new ArrayList<Record>();
-		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
-				+ NetworkEntry.TABLE_NAME + " WHERE " + PacketEntry.COLUMN_NAME_TYPE + "='RECEIVE'" + " ORDER BY " + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
+	public int getAttackCount() {
 		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				Record record = createRecord(cursor);
-				// Adding record to list
-				recordList.add(record);
-			} while (cursor.moveToNext());
-		}
+		String countQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME + 
+				           " WHERE " + AttackEntry.COLUMN_NAME_PROTOCOL + " <> ?";		
+		Cursor cursor = db.rawQuery(countQuery, new String[]{"PORTSCAN"});
+		int result = cursor.getCount();
 		cursor.close();
 
-		// return record list
-		db.close();
-		return recordList;
-	}
-
-	/**
-	 * Gets all {@link Record Records} saved in the database.
-	 * 
-	 * @return A ArrayList of all the {@link Record Records} in the Database.
-	 */
-	public ArrayList<Record> getAllRecords() {
-		ArrayList<Record> recordList = new ArrayList<Record>();
-		// Select All Query
-		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME
-				+ " USING (_bssid)";
-
-		SQLiteDatabase db = this.getWritableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-
-		Log.i("Database", "Start loop");
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				Log.i("Database", "Add Record");
-				Record record = createRecord(cursor);
-				// Adding record to list
-				recordList.add(record);
-			} while (cursor.moveToNext());
-		}
-		cursor.close();
+		// return count
 		db.close();
-		// return record list
-		return recordList;
+		return result;
 	}
-
+	
 	/**
-	 * Determines the number of different attack_ids in the database.
-	 * 
-	 * @return The number of different attack_ids in the database.
+	 * Determines the number of different recorded attacks in a specific access point since the given attack_id.
+	 * The given attack_id is not included.
+	 * @param attack_id  The attack id to match the query against.
+	 * @param bssid  The BSSID of the access point. 
+	 * @return The number of different attacks in the database since the given attack_id.
 	 */
-	public int getAttackCount() {
-		String countQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME;
+	public int getAttackCount(int attack_id, String bssid) {
 		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
+		String countQuery = "SELECT * FROM " + AttackEntry.TABLE_NAME + 
+				           " WHERE "+ AttackEntry.COLUMN_NAME_PROTOCOL + " <> ? " +
+				           	"AND " + AttackEntry.COLUMN_NAME_ATTACK_ID + " > ? " +
+				           	"AND " + AttackEntry.COLUMN_NAME_BSSID + " = ?";			
+		String[] selectArgs = new String[]{"PORTSCAN", attack_id + "", bssid};
+		Cursor cursor = db.rawQuery(countQuery, selectArgs);
 		int result = cursor.getCount();
 		cursor.close();
 
@@ -320,21 +314,23 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 		db.close();
 		return result;
 	}
+	
 
 	/**
-	 * Determines the number of different attack_ids for a specific protocol in
+	 * Determines the number of different attacks for a specific protocol in
 	 * the database.
 	 * 
 	 * @param protocol
 	 *            The String representation of the
 	 *            {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
 	 *            Protocol}
-	 * @return The number of different attack_ids in the database.
+	 * @return The number of different attacks in the database.
 	 */
 	public int getAttackPerProtocolCount(String protocol) {
-		String countQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_PROTOCOL + " = " + "'" + protocol + "'";
 		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
+		String countQuery = "SELECT * FROM " + AttackEntry.TABLE_NAME + 
+		                   " WHERE "+ AttackEntry.COLUMN_NAME_PROTOCOL + " = ? ";	
+		Cursor cursor = db.rawQuery(countQuery, new String[]{protocol});
 		int result = cursor.getCount();
 		cursor.close();
 
@@ -342,77 +338,86 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 		db.close();
 		return result;
 	}
-
+	
 	/**
-	 * Determines the highest attack id stored in the database.
+	 * Determines the number of  attacks for a specific protocol in
+	 * the database since the given attack_id.
 	 * 
-	 * @return The highest attack id stored in the database.
+	 * @param protocol
+	 *            The String representation of the
+	 *            {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
+	 *            Protocol}
+	 * @param attack_id  The attack id to match the query against.
+	 * @return The number of different attacks in the database since the given attack_id.
 	 */
-	public long getHighestAttackId() {
-		String selectQuery = "SELECT MAX(" + AttackEntry.COLUMN_NAME_ATTACK_ID + ") FROM " + AttackEntry.TABLE_NAME;
+	public int getAttackPerProtocolCount(String protocol, int attack_id) {
 		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-		int result;
-
-		if (cursor.moveToFirst()) {
-			result = cursor.getInt(0);
-		} else {
-			result = -1;
-		}
+		String countQuery = "SELECT * FROM " + AttackEntry.TABLE_NAME + 
+                		   " WHERE "+ AttackEntry.COLUMN_NAME_PROTOCOL + " = ? " +
+                		    "AND " + AttackEntry.COLUMN_NAME_ATTACK_ID + " > ? ";	
+		Cursor cursor = db.rawQuery(countQuery, new String[]{protocol, attack_id + ""});
+		int result = cursor.getCount();
 		cursor.close();
+
+		// return count
 		db.close();
 		return result;
 	}
-
-	public ArrayList<HashMap<String, Object>> getNetworkInformation() {
-		String selectQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME;
+	
+	/**
+	 * Determines the number of recorded attacks for a specific protocol and accesss point since the given attack_id.
+	 * 
+	 * @param protocol
+	 *            The String representation of the
+	 *            {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
+	 *            Protocol}
+	 * @param attack_id  The attack id to match the query against.
+	 * @param bssid The BSSID of the access point. 
+	 * @return The number of different attacks in the database since the given attack_id.
+	 */
+	public int getAttackPerProtocolCount(String protocol, int attack_id, String bssid) {
 		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-
-		ArrayList<HashMap<String, Object>> networkInformation = new ArrayList<HashMap<String, Object>>();
-
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				HashMap<String, Object> values = new HashMap<String, Object>();
-				values.put(NetworkEntry.COLUMN_NAME_BSSID, cursor.getString(0));
-				values.put(NetworkEntry.COLUMN_NAME_SSID, cursor.getString(1));
-				values.put(NetworkEntry.COLUMN_NAME_LATITUDE, Double.parseDouble(cursor.getString(2)));
-				values.put(NetworkEntry.COLUMN_NAME_LONGITUDE, Double.parseDouble(cursor.getString(3)));
-				values.put(NetworkEntry.COLUMN_NAME_ACCURACY, Float.parseFloat(cursor.getString(4)));
-				values.put(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, cursor.getLong(5));
-				networkInformation.add(values);
-			} while (cursor.moveToNext());
-		}
-
+		String countQuery = "SELECT * FROM " + AttackEntry.TABLE_NAME + 
+     		   			   " WHERE "+ AttackEntry.COLUMN_NAME_PROTOCOL + " = ? " +
+     		   			    "AND " + AttackEntry.COLUMN_NAME_ATTACK_ID + " > ? " +	
+						 	"AND " + AttackEntry.COLUMN_NAME_BSSID + " = ?";
+		Cursor cursor = db.rawQuery(countQuery, new String[]{protocol, attack_id + "", bssid});
+		int result = cursor.getCount();
 		cursor.close();
+
+		// return count
 		db.close();
-		return networkInformation;
+		return result;
 	}
-
+	
 	/**
-	 * Gets a single {@link Record} with the given ID from the database.
+	 * Determines the number of portscans stored in the database.
 	 * 
-	 * @param id
-	 *            The ID of the {@link Record};
-	 * @return The {@link Record}.
+	 * @return The number of portscans stored in the database.
 	 */
-	public Record getRecord(int id) {
-		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
-				+ NetworkEntry.TABLE_NAME + " WHERE " + PacketEntry.COLUMN_NAME_ID + " = " + id;
-		SQLiteDatabase db = this.getReadableDatabase();
-
-		Cursor cursor = db.rawQuery(selectQuery, null);
-		Record record = null;
-		if (cursor.moveToFirst()) {
-			record = createRecord(cursor);
-		}
+	public int getPortscanCount() {
+		return getAttackPerProtocolCount("PORTSCAN");
+	}	
+	
+	/**
+	 * Determines the number of recorded portscans since the given attack_id.
+	 * @param attack_id  The attack id to match the query against.
+	 * @return The number of portscans stored in the database since the given attack_id.
+	 */
+	public int getPortscanCount(int attack_id) {
+		return getAttackPerProtocolCount("PORTSCAN", attack_id);
+	}	
+	
+	/**
+	 * Determines the number of recorded portscans in a specific access point since the given attack_id.
+	 * @param attack_id  The attack id to match the query against.
+	 * @param bssid The BSSID of the access point. 
+	 * @return The number of portscans stored in the database since the given attack_id.
+	 */
+	public int getPortscanCount(int attack_id, String bssid) {
+		return getAttackPerProtocolCount("PORTSCAN", attack_id, bssid);
+	}	
 
-		cursor.close();
-		db.close();
-		// return contact
-		return record;
-	}
 
 	/**
 	 * Determines the number of {@link Record Records} in the database.
@@ -432,22 +437,20 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	}
 
 	/**
-	 * Gets a single {@link Record} with the given attack id from the database.
+	 * Returns the {@link AttackRecord} with the given attack id from the database.
 	 * 
 	 * @param attack_id
 	 *            The attack id of the {@link Record};
 	 * @return The {@link Record}.
 	 */
-	public Record getRecordOfAttackId(long attack_id) {
-		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
-				+ NetworkEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_ATTACK_ID + " = " + attack_id + " GROUP BY "
-				+ AttackEntry.COLUMN_NAME_ATTACK_ID;
+	public AttackRecord getRecordOfAttackId(long attack_id) {
+		String selectQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_ATTACK_ID + " = " + attack_id;
 		SQLiteDatabase db = this.getReadableDatabase();
 		Cursor cursor = db.rawQuery(selectQuery, null);
-		Record record = null;
+		AttackRecord record = null;
 
 		if (cursor.moveToFirst()) {
-			record = createRecord(cursor);
+			record = createAttackRecord(cursor);
 		}
 		cursor.close();
 
@@ -457,23 +460,20 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	}
 
 	/**
-	 * Gets a representative {@link Record} for every attack identified by its
-	 * attack id.
+	 * Gets a {@link AttackRecord} for every attack identified by its attack id.
 	 * 
-	 * @return A ArrayList with one {@link Record Records} for each attack id in
-	 *         the Database.
+	 * @return A ArrayList with a {@link AttackRecord} for each attack id in the Database.
 	 */
-	public ArrayList<Record> getRecordOfEachAttack() {
-		ArrayList<Record> recordList = new ArrayList<Record>();
-		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
-				+ NetworkEntry.TABLE_NAME + " GROUP BY " + AttackEntry.COLUMN_NAME_ATTACK_ID;
+	public ArrayList<AttackRecord> getRecordOfEachAttack() {
+		ArrayList<AttackRecord> recordList = new ArrayList<AttackRecord>();
+		String selectQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME;
 		SQLiteDatabase db = this.getReadableDatabase();
 		Cursor cursor = db.rawQuery(selectQuery, null);
 
 		// looping through all rows and adding to list
 		if (cursor.moveToFirst()) {
 			do {
-				Record record = createRecord(cursor);
+				AttackRecord record = createAttackRecord(cursor);
 				// Adding record to list
 				recordList.add(record);
 			} while (cursor.moveToNext());
@@ -486,26 +486,23 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	}
 
 	/**
-	 * Gets a representative {@link Record} for every attack with a higher
-	 * attack id than the specified.
+	 * Gets a AttackRecord for every attack with a higher attack id than the specified.
 	 * 
 	 * @param attack_id
 	 *            The attack id to match the query against.
-	 * @return A ArrayList with one {@link Record Records} for each attack id
+	 * @return A ArrayList with one {@link AttackRecord} for each attack id
 	 *         higher than the given.
 	 */
-	public ArrayList<Record> getRecordOfEachAttack(long attack_id) {
-		ArrayList<Record> recordList = new ArrayList<Record>();
-		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
-				+ NetworkEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_ATTACK_ID + " > " + attack_id + " GROUP BY "
-				+ AttackEntry.COLUMN_NAME_ATTACK_ID;
+	public ArrayList<AttackRecord> getRecordOfEachAttack(long attack_id) {
+		ArrayList<AttackRecord> recordList = new ArrayList<AttackRecord>();
+		String selectQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_ATTACK_ID + " > " + attack_id;
 		SQLiteDatabase db = this.getReadableDatabase();
 		Cursor cursor = db.rawQuery(selectQuery, null);
 
 		// looping through all rows and adding to list
 		if (cursor.moveToFirst()) {
 			do {
-				Record record = createRecord(cursor);
+				AttackRecord record = createAttackRecord(cursor);
 				// Adding record to list
 				recordList.add(record);
 			} while (cursor.moveToNext());
@@ -516,6 +513,27 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 		db.close();
 		return recordList;
 	}
+	
+	/**
+	 * Determines the highest attack id stored in the database.
+	 * 
+	 * @return The highest attack id stored in the database.
+	 */
+	public long getHighestAttackId() {
+		String selectQuery = "SELECT MAX(" + AttackEntry.COLUMN_NAME_ATTACK_ID + ") FROM " + AttackEntry.TABLE_NAME;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+		int result;
+
+		if (cursor.moveToFirst()) {
+			result = cursor.getInt(0);
+		} else {
+			result = -1;
+		}
+		cursor.close();
+		db.close();
+		return result;
+	}
 
 	/**
 	 * Determines the smallest attack id stored in the database.
@@ -559,36 +577,184 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 		db.close();
 		return ssid;
 	}
+	
+	public ArrayList<NetworkRecord> getNetworkInformation() {
+		String selectQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+
+		ArrayList<NetworkRecord> networkInformation = new ArrayList<NetworkRecord>();
+
+		// looping through all rows and adding to list
+		if (cursor.moveToFirst()) {
+			do {
+				NetworkRecord record = new NetworkRecord();
+				record.setBssid(cursor.getString(0));
+				record.setSsid(cursor.getString(1));
+				record.setLatitude(Double.parseDouble(cursor.getString(2)));
+				record.setLongitude(Double.parseDouble(cursor.getString(3)));
+				record.setAccuracy(Float.parseFloat(cursor.getString(4)));
+				record.setTimestampLocation(cursor.getLong(5));
+				networkInformation.add(record);
+			} while (cursor.moveToNext());
+		}
+
+		cursor.close();
+		db.close();
+		return networkInformation;
+	}
 
-	public void updateNetworkInformation(ArrayList<HashMap<String, Object>> networkInformation) {
+	public void updateNetworkInformation(ArrayList<NetworkRecord> networkInformation) {
 		Log.i("DatabaseHandler", "Starte updating");
-		for (HashMap<String, Object> values : networkInformation) {
-			updateNetworkInformation(values);
+		for (NetworkRecord record : networkInformation) {
+			updateNetworkInformation(record);
 		}
 	}
 
-	public void updateNetworkInformation(HashMap<String, Object> networkInformation) {
+	public void updateNetworkInformation(NetworkRecord record) {
 		SQLiteDatabase db = this.getReadableDatabase();
-		String bssid = (String) networkInformation.get(NetworkEntry.COLUMN_NAME_BSSID);
-		String bssidQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME + " WHERE " + NetworkEntry.COLUMN_NAME_BSSID + " = " + "'" + bssid + "'";
-		Cursor cursor = db.rawQuery(bssidQuery, null);
-		int result = cursor.getCount();
-		if (cursor != null && cursor.moveToFirst()
-				&& (result <= 0 || cursor.getLong(5) < (Long) networkInformation.get(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP)))
-			;
-		{
+		String bssid = record.getBssid();
+		String bssidQuery = "SELECT  * FROM " +  NetworkEntry.TABLE_NAME + " WHERE " +  NetworkEntry.COLUMN_NAME_BSSID + " = ?";
+		Cursor cursor = db.rawQuery(bssidQuery, new String[] {bssid});
+		if (!cursor.moveToFirst() || cursor.getLong(5) < record.getTimestampLocation()){
 			ContentValues bssidValues = new ContentValues();
 			bssidValues.put(NetworkEntry.COLUMN_NAME_BSSID, bssid);
-			bssidValues.put(NetworkEntry.COLUMN_NAME_SSID, (String) networkInformation.get(NetworkEntry.COLUMN_NAME_SSID));
-			bssidValues.put(NetworkEntry.COLUMN_NAME_LATITUDE, (double) (Double) networkInformation.get(NetworkEntry.COLUMN_NAME_LATITUDE));
-			bssidValues.put(NetworkEntry.COLUMN_NAME_LONGITUDE, (double) (Double) networkInformation.get(NetworkEntry.COLUMN_NAME_LONGITUDE));
-			bssidValues.put(NetworkEntry.COLUMN_NAME_ACCURACY, (float) (Float) networkInformation.get(NetworkEntry.COLUMN_NAME_ACCURACY));
-			bssidValues.put(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, (Long) networkInformation.get(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP));
+			bssidValues.put(NetworkEntry.COLUMN_NAME_SSID, record.getSsid());
+			bssidValues.put(NetworkEntry.COLUMN_NAME_LATITUDE, record.getLatitude());
+			bssidValues.put(NetworkEntry.COLUMN_NAME_LONGITUDE, record.getLongitude());
+			bssidValues.put(NetworkEntry.COLUMN_NAME_ACCURACY, record.getAccuracy());
+			bssidValues.put(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, record.getTimestampLocation());
 			db.insertWithOnConflict(NetworkEntry.TABLE_NAME, null, bssidValues, SQLiteDatabase.CONFLICT_REPLACE);
 		}
 		cursor.close();
 		db.close();
 	}
+	
+	
+	public void updateSyncDevices(HashMap<String, Long> devices){
+		SQLiteDatabase db = this.getReadableDatabase();		
+		for(String key : devices.keySet()){
+			ContentValues deviceValues = new ContentValues();
+			deviceValues.put(SyncDeviceEntry.COLUMN_NAME_DEVICE_ID, key);
+			deviceValues.put(SyncDeviceEntry.COLUMN_NAME_DEVICE_TIMESTAMP, devices.get(key));
+			db.insertWithOnConflict(SyncDeviceEntry.TABLE_NAME, null, deviceValues, SQLiteDatabase.CONFLICT_REPLACE);
+		}
+		db.close();
+	}
+	
+	/**
+	 * Returns a HashMap of all devices that were previously synchronized with.
+	 * @return HashMap containing device id's and the last synchronization timestamp.
+	 */
+	public HashMap<String, Long> getSyncDevices(){
+		SQLiteDatabase db = this.getReadableDatabase();
+		HashMap<String, Long> devices = new HashMap<String, Long>();
+		
+		String query = "SELECT  * FROM " + SyncDeviceEntry.TABLE_NAME;
+		Cursor cursor = db.rawQuery(query, null);
+		
+		if (cursor.moveToFirst()) {
+			do {
+				devices.put(cursor.getString(0), cursor.getLong(1));
+			} while (cursor.moveToNext());
+		}
+		cursor.close();
+		db.close();
+		return devices;
+	}
+	
+	/**
+	 * Returns a ArrayList containing all information stored in the SyncInfo table.
+	 * @return ArrayList<SyncInfo>
+	 */
+	public ArrayList<SyncInfoRecord> getSyncInfo(){
+		SQLiteDatabase db = this.getReadableDatabase();
+		ArrayList<SyncInfoRecord> syncInfo = new ArrayList<SyncInfoRecord>();
+		
+		String query = "SELECT  * FROM " + SyncInfoEntry.TABLE_NAME;
+		Cursor cursor = db.rawQuery(query, null);
+		
+		if (cursor.moveToFirst()) {
+			do {
+				SyncInfoRecord info = new SyncInfoRecord();
+				info.setDeviceID(cursor.getString(0));
+				info.setBSSID(cursor.getString(1));
+				info.setNumber_of_attacks(cursor.getLong(2));
+				info.setNumber_of_portscans(cursor.getLong(3));
+				syncInfo.add(info);
+			} while (cursor.moveToNext());
+		}
+		cursor.close();
+		db.close();
+		return syncInfo;
+	}	
+	
+	
+	public void updateSyncInfo(ArrayList<SyncInfoRecord> syncInfo){
+		for(SyncInfoRecord info : syncInfo){
+			updateSyncInfo(info);
+		}
+	}
+	
+	public void updateSyncInfo(SyncInfoRecord syncInfo){
+		SQLiteDatabase db = this.getReadableDatabase();
+		ContentValues syncValues = new ContentValues();
+		syncValues.put(SyncInfoEntry.COLUMN_NAME_BSSID, syncInfo.getBSSID());
+		syncValues.put(SyncInfoEntry.COLUMN_NAME_DEVICE_ID, syncInfo.getDeviceID());
+		syncValues.put(SyncInfoEntry.COLUMN_NAME_NUMBER_ATTACKS, syncInfo.getNumber_of_attacks());
+		syncValues.put(SyncInfoEntry.COLUMN_NAME_NUMBER_PORTSCANS, syncInfo.getNumber_of_portscans());
+		db.insertWithOnConflict(SyncInfoEntry.TABLE_NAME, null, syncValues, SQLiteDatabase.CONFLICT_REPLACE);
+		db.close();
+	}
+	
+	/**
+	 * Deletes a device with given id from the device {@link SyncDeviceEntry.TABLE_NAME} and also all data captured by this device in  {@link SyncInfoEntry.TABLE_NAME}
+	 * @param device_id The id of the device that is to be deleted.
+	 */
+	public void clearSyncInfos(){
+		SQLiteDatabase db = this.getReadableDatabase();
+		db.delete(SyncDeviceEntry.TABLE_NAME, null, null);
+		db.delete(SyncInfoEntry.TABLE_NAME, null, null);
+		db.close();
+	}
+	
+	
+	/**
+	 * Deletes all records from {@link #PacketEntry.TABLE_NAME}.
+	 */
+	public void clearData() {
+		SQLiteDatabase db = this.getReadableDatabase();
+		db.delete(PacketEntry.TABLE_NAME, null, null);
+		db.delete(AttackEntry.TABLE_NAME, null, null);
+		db.close();
+	}
+
+	/**
+	 * Deletes all records from {@link #PacketEntry.TABLE_NAME} with a specific BSSID.
+	 * 
+	 * @param bssid
+	 *            The BSSID to match against.
+	 */
+	public void deleteByBSSID(String bssid) {
+		SQLiteDatabase db = this.getReadableDatabase();
+		db.delete(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_BSSID + " = ?", new String[] { bssid });
+		db.delete(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_BSSID + " = ?", new String[] { bssid });
+		db.close();
+	}
+	
+	/**
+	 * Deletes all records from {@link #PacketEntry.TABLE_NAME} with a time stamp smaller
+	 * then the given
+	 * 
+	 * @param date
+	 *            A Date represented in milliseconds.
+	 */
+	public void deleteByDate(long date) {
+		SQLiteDatabase db = this.getReadableDatabase();
+		String deleteQuery = "DELETE  FROM " + PacketEntry.TABLE_NAME + " WHERE " + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP + " < " + date;
+		db.execSQL(deleteQuery);
+		db.close();
+	}
 
 	/**
 	 * Creates a {@link Record} from a Cursor. If the cursor does not show to a
@@ -597,28 +763,34 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 	 * @param cursor
 	 * @return Returns the created {@link Record} .
 	 */
-	private Record createRecord(Cursor cursor) {
-		Record record = new Record();
+	private MessageRecord createMessageRecord(Cursor cursor) {
+		MessageRecord record = new MessageRecord();
 		record.setId(Integer.parseInt(cursor.getString(0)));
 		record.setAttack_id(cursor.getLong(1));
-		record.setType(TYPE.valueOf(cursor.getString(2)));
+		record.setType(MessageRecord.TYPE.valueOf(cursor.getString(2)));
 		record.setTimestamp(cursor.getLong(3));
 		record.setPacket(cursor.getString(4));
-		record.setProtocol(cursor.getString(5));
-		record.setExternalIP(cursor.getString(6));
-
-		record.setLocalIP(cursor.getString(7));
-		record.setLocalPort(Integer.parseInt(cursor.getString(8)));
-
-		record.setRemoteIP(cursor.getString(9));
-		record.setRemotePort(Integer.parseInt(cursor.getString(10)));
 
-		record.setBssid(cursor.getString(11));
-		record.setSsid(cursor.getString(12));
-		record.setLatitude(Double.parseDouble(cursor.getString(13)));
-		record.setLongitude(Double.parseDouble(cursor.getString(14)));
-		record.setAccuracy(Float.parseFloat(cursor.getString(15)));
-		record.setTimestampLocation(cursor.getLong(16));
+		return record;
+	}
+	
+	/**
+	 * Creates a {@link AttackRecord} from a Cursor. If the cursor does not show to a
+	 * valid data structure a runtime exception is thrown.
+	 * 
+	 * @param cursor
+	 * @return Returns the created {@link Record} .
+	 */
+	private AttackRecord createAttackRecord(Cursor cursor) {
+		AttackRecord record = new AttackRecord();
+		record.setAttack_id(cursor.getLong(0));
+		record.setProtocol(cursor.getString(1));
+		record.setExternalIP(cursor.getString(2));
+		record.setLocalIP(cursor.getString(3));
+		record.setLocalPort(Integer.parseInt(cursor.getString(4)));
+		record.setRemoteIP(cursor.getString(5));
+		record.setRemotePort(Integer.parseInt(cursor.getString(6)));
+		record.setBssid(cursor.getString(7));
 
 		return record;
 	}

+ 53 - 1
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -1,5 +1,8 @@
 package de.tudarmstadt.informatik.hostage.protocol;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.Socket;
 import java.security.SecureRandom;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -9,6 +12,7 @@ import java.util.Locale;
 import java.util.TimeZone;
 
 import android.content.Context;
+import android.os.AsyncTask;
 import de.tudarmstadt.informatik.hostage.Hostage;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
@@ -22,7 +26,14 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
  * @author Wulf Pfeiffer
  */
 public class HTTP implements Protocol {
-
+	
+	public HTTP() {
+		boolean useQotd = Hostage.getContext().getSharedPreferences(Hostage.getContext().getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE).getBoolean("useQotd", true);
+		if (useQotd) {
+			new QotdTask().execute(new String[] {});
+		}
+	}
+	
 	/**
 	 * Get the current time in html header format.
 	 * 
@@ -181,6 +192,11 @@ public class HTTP implements Protocol {
 		} else {
 			responsePackets.add(buildPacket(STATUS_CODE_400, ""));
 		}
+		
+		boolean useQotd = Hostage.getContext().getSharedPreferences(Hostage.getContext().getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE).getBoolean("useQotd", true);
+		if (useQotd) {
+			new QotdTask().execute(new String[] {});
+		}
 		return responsePackets;
 	}
 
@@ -218,4 +234,40 @@ public class HTTP implements Protocol {
 		return new Packet(httpVersion + " " + code + headerPrefix
 				+ document.length() + headerSuffix + document, toString());
 	}
+	
+	/**
+	 * Task for accuiring a qotd from one of four possible servers.
+	 * 
+	 * @author Wulf Pfeiffer
+	 */
+	private class QotdTask extends AsyncTask<String, Void, String> {
+		@Override
+		protected String doInBackground(String... unused) {
+			String[] sources = new String[] { "djxmmx.net", "ota.iambic.com", "alpha.mike-r.com", "electricbiscuit.org" };
+			SecureRandom rndm = new SecureRandom();
+			StringBuffer sb = new StringBuffer();
+			try {
+				Socket client = new Socket(sources[rndm.nextInt(4)], 17);
+				BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
+				while (!in.ready())
+					;
+				while (in.ready()) {
+					sb.append(in.readLine());
+				}
+				in.close();
+				client.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			return sb.toString();
+		}
+
+		@Override
+		protected void onPostExecute(String result) {
+			if (result != null)
+				HTTP.setHtmlDocumentContent(result);
+			else
+				HTTP.setHtmlDocumentContent(HelperUtils.getRandomString(32, false));
+		}
+	}
 }

+ 39 - 0
src/de/tudarmstadt/informatik/hostage/sync/SyncMessage.java

@@ -0,0 +1,39 @@
+package de.tudarmstadt.informatik.hostage.sync;
+
+import java.io.Serializable;
+
+public class SyncMessage implements Serializable{
+	
+
+	private static final long serialVersionUID = -7597101233186914926L;
+	
+	//REQUEST CODES
+	public static final int SYNC_REQUEST = 0x00;
+	public static final int SYNC_RESPONSE_NET_INFO = 0x01;
+	public static final int SYNC_RESPONSE_SYNC_INFO = 0x02;
+	
+	private int message_code;
+	private Object payload;
+	
+	public SyncMessage(int message_code, Object payload){
+		this.message_code = message_code;
+		this.payload = payload;
+	}
+
+	public int getMessage_code() {
+		return message_code;
+	}
+
+	public void setMessage_code(int message_code) {
+		this.message_code = message_code;
+	}
+
+	public Object getPayload() {
+		return payload;
+	}
+
+	public void setPayload(Object payload) {
+		this.payload = payload;
+	}
+
+}

+ 40 - 190
src/de/tudarmstadt/informatik/hostage/sync/BluetoothSync.java → src/de/tudarmstadt/informatik/hostage/sync/bluetooth/BluetoothSync.java

@@ -1,9 +1,5 @@
-package de.tudarmstadt.informatik.hostage.sync;
+package de.tudarmstadt.informatik.hostage.sync.bluetooth;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.UUID;
 
@@ -11,7 +7,6 @@ import android.util.Log;
 import android.app.Activity;
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothServerSocket;
 import android.bluetooth.BluetoothSocket;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -28,27 +23,31 @@ import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.AdapterView.OnItemClickListener;
 import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
+import de.tudarmstadt.informatik.hostage.sync.SyncMessage;
 
 public class BluetoothSync extends Activity{	
 	
-    private static final int CONNECTION_ESTABLISHED = 0x0;
-    private static final int CONNECTION_FAILED = 0x1;
-    private static final int MESSAGE_SENT = 0x2;
-    private static final int MESSAGE_RECIEVED = 0x3;
+	public static final int CONNECTING = 0x0;
+    public static final int CONNECTION_ESTABLISHED = 0x1;
+    public static final int CONNECTION_FAILED = 0x2;
+    public static final int SYNC_SUCCESSFUL = 0x3;
+    public static final int SYNC_FAILED = 0x4;
     
-	private UUID serviceUUID;
+    public static UUID serviceUUID;
 	
 	private BluetoothAdapter mBluetoothAdapter;
 	private ArrayAdapter<String> arrayAdapter;
 
 	private ServerThread serverThread;	
 	private ClientThread clientThread;
-	CommunicationThread commThread;
+	private CommunicationThread commThread;
 	
-	TextView mInfoText;
-	ListView listView;
-	LinearLayout layout;
+	
+	private TextView mInfoText;
+	private ListView listView;
+	private LinearLayout layout;
 	
 	
 	@Override
@@ -108,171 +107,24 @@ public class BluetoothSync extends Activity{
 		discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
 		startActivity(discoverableIntent);
 
-		serverThread = new ServerThread();
+		serverThread = new ServerThread(mHandler, getResources().getString(R.string.app_name));
 		serverThread.start();
 	}
 		
 
-	private void manageConnectedSocket(BluetoothSocket socket) {
+	protected void manageConnectedSocket(BluetoothSocket socket) {
 		mBluetoothAdapter.cancelDiscovery();
 		unregisterBroadcastReceiver();
-		commThread = new CommunicationThread(socket);
-		commThread.start();
+		
 		HostageDBOpenHelper dbh = new HostageDBOpenHelper(this);
-		ArrayList<HashMap<String, Object>> localNetworkInformation = dbh.getNetworkInformation();
-		commThread.write(localNetworkInformation);
-	}
-
-	private class ClientThread extends Thread {
-		private final BluetoothSocket socket;
-
-		public ClientThread(BluetoothDevice device) {
-			BluetoothSocket tmp = null;
-			try {
-				tmp = device.createRfcommSocketToServiceRecord(serviceUUID);
-			} catch (IOException e) {
-			}
-			socket = tmp;
-		}
-
-		/** Will cancel an in-progress connection, and close the socket */
-		public void cancel() {
-			try {
-				socket.close();
-			} catch (IOException e) {
-			}
-		}
-
-		@Override
-		public void run() {
-
-			try {
-				socket.connect();
-			} catch (IOException connectException) {
-				mHandler.obtainMessage(CONNECTION_FAILED).sendToTarget();
-				// Unable to connect; close the socket and get out
-				try {
-					socket.close();
-				} catch (IOException closeException) {
-				}
-				return;
-			}
-			mHandler.obtainMessage(CONNECTION_ESTABLISHED, socket).sendToTarget();
-			manageConnectedSocket(socket);
-		}
-	}
-
-	private class ServerThread extends Thread {
-		private final BluetoothServerSocket serverSocket;
-
-		public ServerThread() {
-			BluetoothServerSocket tmp = null;
-			try {
-				tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(getResources().getString(R.string.app_name), serviceUUID);
-			} catch (IOException e) {
-			}
-			serverSocket = tmp;
-		}
-
-		/** Will cancel the listening socket, and cause the thread to finish */
-		public void cancel() {
-			try {
-				serverSocket.close();
-			} catch (IOException e) {
-			}
-		}
-
-		@Override
-		public void run() {
-			BluetoothSocket socket = null;
-			while (true) {
-				try {
-					socket = serverSocket.accept();
-				} catch (IOException e) {
-					e.printStackTrace();
-					mHandler.obtainMessage(CONNECTION_FAILED).sendToTarget();
-					break;
-				}
-
-				if (socket != null) {
-					// Do work to manage the connection (in a separate thread)
-					manageConnectedSocket(socket);
-					mHandler.obtainMessage(CONNECTION_ESTABLISHED, socket).sendToTarget();
-					try {
-						serverSocket.close();
-					} catch (IOException e) {
-						e.printStackTrace();
-					}
-					break;
-				}
-			}
-		}
-	}
-	
-	private class CommunicationThread extends Thread {
-		private final BluetoothSocket mmSocket;
-		private final ObjectInputStream objectInput;
-		private final ObjectOutputStream objectOuput;
-
-		public CommunicationThread(BluetoothSocket socket) {
-			mmSocket = socket;
-			ObjectInputStream tmpIn = null;
-			ObjectOutputStream tmpOut = null;
-
-			// Get the input and output streams, using temp objects because
-			// member streams are final
-			try {
-				tmpOut = new ObjectOutputStream(socket.getOutputStream());
-				tmpIn = new ObjectInputStream(socket.getInputStream());
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-
-			objectInput = tmpIn;
-			objectOuput = tmpOut;
-		}
-
-		/* Call this from the main activity to shutdown the connection */
-		public void cancel() {
-			try {
-				mmSocket.close();
-			} catch (IOException e) {
-			}
-		}
-
-		@Override
-		public void run() {
-			// Keep listening to the InputStream until an exception occurs
-			while (true) {
-			try {
-				// TODO Ersetze dbh mit Logger
-				HostageDBOpenHelper dbh = new HostageDBOpenHelper(getContext());
-				// Read from the InputStream
-				ArrayList<HashMap<String, Object>> remoteNetworkInformation = (ArrayList<HashMap<String, Object>>) objectInput.readObject();
-				// update database
-				dbh.updateNetworkInformation(remoteNetworkInformation);	
-				mHandler.obtainMessage(MESSAGE_RECIEVED).sendToTarget();
-			} catch (ClassNotFoundException e) {
-				e.printStackTrace();
-			} catch (IOException e) {
-				e.printStackTrace();
-				break;
-			}
-			}
-		}
-
-		/* Call this from the main activity to send data to the remote device */
-		public void write(ArrayList<HashMap<String, Object>> networkInformation) {
-			try {
-				objectOuput.writeObject(networkInformation);
-				mHandler.obtainMessage(MESSAGE_SENT).sendToTarget();
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-		}
+		commThread = new CommunicationThread(this, socket, mHandler);
+		commThread.start();
+		
+		//TODO auslagern
+		HashMap<String, Long> devices = dbh.getSyncDevices();
+		commThread.write(new SyncMessage(SyncMessage.SYNC_REQUEST, devices));
 	}
 
-
 	// Create a BroadcastReceiver for ACTION_FOUND
 	private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
 		@Override
@@ -315,10 +167,6 @@ public class BluetoothSync extends Activity{
 		mRecieverRegistered = false;
 	}
 	
-	private Context getContext(){
-		return this;
-	}
-	
 	private void setLayoutElement(){
 		mInfoText = (TextView) findViewById(R.id.bluetoothInfoText);
 		layout = (LinearLayout) findViewById(R.id.bluetoothLayout);
@@ -329,40 +177,42 @@ public class BluetoothSync extends Activity{
 			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 				String deviceInfo = arrayAdapter.getItem(position);
 				String mac = deviceInfo.substring(deviceInfo.indexOf("\n") + 1);
-				clientThread = new ClientThread(mBluetoothAdapter.getRemoteDevice(mac));
+				String name = deviceInfo.substring(0, deviceInfo.indexOf("\n"));
+				mHandler.obtainMessage(CONNECTING, name).sendToTarget();
+				clientThread = new ClientThread(mBluetoothAdapter.getRemoteDevice(mac), mHandler);
 				clientThread.start();
 			}
 		});		
 	}	
 	
-	private boolean message_sent = false;
-	private boolean message_recieved = false;
-	
 	private Handler mHandler = new Handler() {
 
         @Override
         public void handleMessage(Message msg) {
         	switch(msg.what){
-        		case CONNECTION_ESTABLISHED: 
+        		case CONNECTING:       
         			layout.removeView(listView);
+        			mInfoText.setText("Connecting to " + (String)msg.obj + "!");
+        			break;
+        		case CONNECTION_ESTABLISHED: 
         			BluetoothSocket socket = (BluetoothSocket) msg.obj;
+        			layout.removeView(listView);
         			String deviceName = socket.getRemoteDevice().getName();
         			mInfoText.setText("Synchronizing with " + deviceName + "...");	
+        			manageConnectedSocket(socket);
         			break;
         		case CONNECTION_FAILED: 
-        			mInfoText.setText("Synchronization failed!");
+        			mInfoText.setText("Failed to connect to device!");
         			break;
-        		case MESSAGE_SENT: 
-        			message_sent = true;
-        			if(message_recieved)
-        				mInfoText.setText("Synchronization successfull!");
+        		case SYNC_SUCCESSFUL: 
+        			mInfoText.setText("Synchronization successfull!");
         			break;	
-        		case MESSAGE_RECIEVED: 
-        			message_recieved = true;
-        			if(message_sent)
-        				mInfoText.setText("Synchronization successfull!");
+        		case SYNC_FAILED: 
+        			mInfoText.setText("Synchronization failed!");
         			break;	
         	}        		
         }
-};
+	};
+	
+	
 }

+ 29 - 0
src/de/tudarmstadt/informatik/hostage/sync/bluetooth/BluetoothSyncService.java

@@ -0,0 +1,29 @@
+package de.tudarmstadt.informatik.hostage.sync.bluetooth;
+
+import android.app.IntentService;
+import android.bluetooth.BluetoothAdapter;
+import android.content.Intent;
+
+public class BluetoothSyncService extends IntentService {
+	
+	private ServerThread serverThread;	
+	private ClientThread clientThread;
+	private CommunicationThread commThread;
+	
+	private BluetoothAdapter mBluetoothAdapter;
+	
+	
+	public BluetoothSyncService() {
+		super("BluetoothSyncService");
+		
+	}
+
+	@Override
+	protected void onHandleIntent(Intent intent) {
+		// TODO Auto-generated method stub
+		
+	}
+
+
+	
+}

+ 48 - 0
src/de/tudarmstadt/informatik/hostage/sync/bluetooth/ClientThread.java

@@ -0,0 +1,48 @@
+package de.tudarmstadt.informatik.hostage.sync.bluetooth;
+
+import java.io.IOException;
+
+
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothSocket;
+import android.os.Handler;
+
+public class ClientThread extends Thread {
+	private final BluetoothSocket socket;
+	private final Handler mHandler;
+
+	public ClientThread(BluetoothDevice device, Handler handler) {
+		mHandler = handler;
+		BluetoothSocket tmp = null;
+		try {
+			tmp = device.createRfcommSocketToServiceRecord(BluetoothSync.serviceUUID);
+		} catch (IOException e) {
+		}
+		socket = tmp;
+	}
+
+	/** Will cancel an in-progress connection, and close the socket */
+	public void cancel() {
+		try {
+			socket.close();
+		} catch (IOException e) {
+		}
+	}
+
+	@Override
+	public void run() {
+
+		try {
+			socket.connect();
+		} catch (IOException connectException) {
+			mHandler.obtainMessage(BluetoothSync.CONNECTION_FAILED).sendToTarget();
+			// Unable to connect; close the socket and get out
+			try {
+				socket.close();
+			} catch (IOException closeException) {
+			}
+			return;
+		}
+		mHandler.obtainMessage(BluetoothSync.CONNECTION_ESTABLISHED, socket).sendToTarget();
+	}
+}

+ 146 - 0
src/de/tudarmstadt/informatik/hostage/sync/bluetooth/CommunicationThread.java

@@ -0,0 +1,146 @@
+package de.tudarmstadt.informatik.hostage.sync.bluetooth;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
+import de.tudarmstadt.informatik.hostage.logging.SyncInfoRecord;
+import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
+import de.tudarmstadt.informatik.hostage.sync.SyncMessage;
+
+
+import android.bluetooth.BluetoothSocket;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Handler;
+import android.preference.PreferenceManager;
+import android.util.Log;
+
+public class CommunicationThread extends Thread {
+	private final Context context;
+	private final BluetoothSocket mmSocket;
+	private final ObjectInputStream objectInput;
+	private final ObjectOutputStream objectOuput;
+	private final Handler mHandler;
+	private final HostageDBOpenHelper mdbh;
+	private final SharedPreferences pref;
+
+
+	public CommunicationThread(Context con, BluetoothSocket socket, Handler handler) {
+		mmSocket = socket;
+		mHandler = handler;
+		context = con;
+		mdbh = new HostageDBOpenHelper(context);		
+		pref = PreferenceManager.getDefaultSharedPreferences(context);
+		ObjectInputStream tmpIn = null;
+		ObjectOutputStream tmpOut = null;
+		
+
+		// Get the input and output streams, using temp objects because
+		// member streams are final
+		try {
+			tmpOut = new ObjectOutputStream(socket.getOutputStream());
+			tmpIn = new ObjectInputStream(socket.getInputStream());
+		} catch (IOException e) {
+			mHandler.obtainMessage(BluetoothSync.CONNECTION_FAILED).sendToTarget();
+			e.printStackTrace();
+		}
+
+		objectInput = tmpIn;
+		objectOuput = tmpOut;
+	}
+
+	/* Call this from the main activity to shutdown the connection */
+	public void cancel() {
+		try {
+			mmSocket.close();
+		} catch (IOException e) {
+		}
+	}
+
+	@Override
+	public void run() {	
+		// Keep listening to the InputStream until an exception occurs
+		while (true) {
+		try {
+			Object inputObject = objectInput.readObject();
+			if(inputObject instanceof SyncMessage){
+				handleMessage((SyncMessage) inputObject);				
+			}		
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+			break;
+		}
+		}
+	}
+	
+	/**
+	 * Handles a received synchronization message.
+	 * @param message The received message.
+	 */
+	private void handleMessage(SyncMessage message){
+		Log.i("CommunicationThread", "Recieved: " + message.getMessage_code());
+		switch(message.getMessage_code()){
+			case SyncMessage.SYNC_REQUEST:
+				HashMap<String, Long> devices_remote = (HashMap<String, Long>) message.getPayload();
+				HashMap<String, Long> devices_local = mdbh.getSyncDevices();
+				ArrayList<SyncInfoRecord> syncInfo = mdbh.getSyncInfo();
+
+				long tracing_timestamp = 0;
+				//TODO "TRACING" zentral definieren
+				if(devices_local.containsKey("TRACING"))
+					tracing_timestamp = devices_local.get("TRACING");				
+					
+				for(Iterator<String> i = devices_remote.keySet().iterator(); i.hasNext(); ){
+					String key = i.next();
+					if((devices_local.containsKey(key) && devices_local.get(key) >= devices_remote.get(key)) 
+					    || (tracing_timestamp > devices_remote.get(key))){
+						Log.i("CommunicationThread", "Removed: " + key);
+						i.remove();
+					}
+				}
+				mdbh.updateSyncDevices(devices_remote);
+				
+				for ( Iterator<SyncInfoRecord> i = syncInfo.iterator(); i.hasNext(); ){
+					SyncInfoRecord info = i.next();
+					if(devices_remote.containsKey(info.getDeviceID())){
+						Log.i("CommunicationThread", "Removed from SyncInfo: " + info.getDeviceID());
+						i.remove();
+					}				    
+				}				
+								
+				write(new SyncMessage(SyncMessage.SYNC_RESPONSE_SYNC_INFO, syncInfo));
+				write(new SyncMessage(SyncMessage.SYNC_RESPONSE_NET_INFO, mdbh.getNetworkInformation()));
+				break;			
+			case SyncMessage.SYNC_RESPONSE_NET_INFO:
+				ArrayList<NetworkRecord> netInfo = (ArrayList<NetworkRecord>) message.getPayload();
+				mdbh.updateNetworkInformation(netInfo);	
+				mHandler.obtainMessage(BluetoothSync.SYNC_SUCCESSFUL).sendToTarget();	
+				break;			
+			case SyncMessage.SYNC_RESPONSE_SYNC_INFO:
+				ArrayList<SyncInfoRecord> syncInfo_new = (ArrayList<SyncInfoRecord>) message.getPayload();
+				mdbh.updateSyncInfo(syncInfo_new);
+				break;
+			default: 
+				//TODO DEFAULT WITH UNKNOWN MESSAGE CODE;
+		}		
+	}
+	
+	/* Call this from the main activity to send data to the remote device */
+	public void write(SyncMessage message) {
+		try {
+			objectOuput.writeObject(message);
+//TODO NACHRICHT SCHICKEN?			mHandler.obtainMessage(BluetoothSync.MESSAGE_SENT).sendToTarget();
+		} catch (IOException e) {
+			mHandler.obtainMessage(BluetoothSync.CONNECTION_FAILED).sendToTarget();
+			e.printStackTrace();
+		}
+	}
+}	

+ 57 - 0
src/de/tudarmstadt/informatik/hostage/sync/bluetooth/ServerThread.java

@@ -0,0 +1,57 @@
+package de.tudarmstadt.informatik.hostage.sync.bluetooth;
+
+import java.io.IOException;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothServerSocket;
+import android.bluetooth.BluetoothSocket;
+import android.os.Handler;
+
+public class ServerThread extends Thread {
+	private final BluetoothServerSocket serverSocket;
+	private final Handler mHandler;
+
+	public ServerThread(Handler handler, String app_name) {
+		BluetoothServerSocket tmp = null;
+		mHandler = handler;
+		try {
+			tmp = BluetoothAdapter.getDefaultAdapter().listenUsingRfcommWithServiceRecord(app_name, BluetoothSync.serviceUUID);
+		} catch (IOException e) {
+			mHandler.obtainMessage(BluetoothSync.CONNECTION_FAILED).sendToTarget();
+		}
+		serverSocket = tmp;
+	}
+
+	/** Will cancel the listening socket, and cause the thread to finish */
+	public void cancel() {
+		try {
+			serverSocket.close();
+		} catch (IOException e) {
+		}
+	}
+
+	@Override
+	public void run() {
+		BluetoothSocket socket = null;
+		while (true) {
+			try {
+				socket = serverSocket.accept();
+			} catch (IOException e) {
+				e.printStackTrace();
+				mHandler.obtainMessage(BluetoothSync.CONNECTION_FAILED).sendToTarget();
+				break;
+			}
+
+			if (socket != null) {
+				// Do work to manage the connection (in a separate thread)
+				mHandler.obtainMessage(BluetoothSync.CONNECTION_ESTABLISHED, socket).sendToTarget();
+				try {
+					serverSocket.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+				break;
+			}
+		}
+	}
+}

+ 23 - 27
src/de/tudarmstadt/informatik/hostage/sync/NFCSync.java → src/de/tudarmstadt/informatik/hostage/sync/nfc/NFCSync.java

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package de.tudarmstadt.informatik.hostage.sync;
+package de.tudarmstadt.informatik.hostage.sync.nfc;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -22,8 +22,6 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.util.ArrayList;
-import java.util.HashMap;
-
 import android.annotation.TargetApi;
 import android.app.Activity;
 import android.content.Intent;
@@ -42,6 +40,7 @@ import android.util.Log;
 import android.widget.TextView;
 import android.widget.Toast;
 import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
 
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@@ -50,9 +49,6 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback, OnNd
 	TextView mInfoText;
 	private static final int MESSAGE_SENT = 1;
 
-
-
-	/** This handler receives a message from onNdefPushComplete */
 	private final Handler mHandler = new Handler() {
 		@Override
 		public void handleMessage(Message msg) {
@@ -64,6 +60,25 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback, OnNd
 			}
 		}
 	};
+	
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_nfc);
+
+		mInfoText = (TextView) findViewById(R.id.nfc_text_view);
+		// Check for available NFC Adapter
+		mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
+		if (mNfcAdapter == null) {
+			mInfoText.setText("NFC is not available on this device.");
+		} else {
+			mInfoText.setText("Hold phones together to synchronize.");
+			// Register callback to set NDEF message
+			mNfcAdapter.setNdefPushMessageCallback(this, this);
+			// Register callback to listen for message-sent success
+			mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
+		}
+	}
 
 	/**
 	 * Implementation for the CreateNdefMessageCallback interface
@@ -72,7 +87,7 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback, OnNd
 	public NdefMessage createNdefMessage(NfcEvent event) {
 		// Get Networkdata
 		HostageDBOpenHelper dbh = new HostageDBOpenHelper(this);
-		ArrayList<HashMap<String, Object>> localNetworkInformation = dbh.getNetworkInformation();
+		ArrayList<NetworkRecord> localNetworkInformation = dbh.getNetworkInformation();
 		Log.i("NFC", "Creating Message");
 		NdefMessage msg = null;
 		try {
@@ -85,25 +100,6 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback, OnNd
 		return msg;
 	}
 
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.activity_nfc);
-
-		mInfoText = (TextView) findViewById(R.id.record_details_text_ssid);
-		// Check for available NFC Adapter
-		mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
-		if (mNfcAdapter == null) {
-			mInfoText.setText("NFC is not available on this device.");
-		} else {
-			mInfoText.setText("Hold phones together to synchronize.");
-			// Register callback to set NDEF message
-			mNfcAdapter.setNdefPushMessageCallback(this, this);
-			// Register callback to listen for message-sent success
-			mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
-		}
-	}
-
 	/**
 	 * Implementation for the OnNdefPushCompleteCallback interface
 	 */
@@ -143,7 +139,7 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback, OnNd
 		Log.i("NFC", "Getting Message!");
 		try {
 			object = deserialize(msg.getRecords()[0].getPayload());
-			ArrayList<HashMap<String, Object>> remoteNetworkInformation = (ArrayList<HashMap<String, Object>>) object;
+			ArrayList<NetworkRecord> remoteNetworkInformation = (ArrayList<NetworkRecord>) object;
 			HostageDBOpenHelper dbh = new HostageDBOpenHelper(this);
 			dbh.updateNetworkInformation(remoteNetworkInformation);
 		} catch (ClassNotFoundException e) {

+ 43 - 0
src/de/tudarmstadt/informatik/hostage/sync/tracing/TracingSyncActivity.java

@@ -0,0 +1,43 @@
+package de.tudarmstadt.informatik.hostage.sync.tracing;
+
+import de.tudarmstadt.informatik.hostage.R;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.widget.TextView;
+
+public class TracingSyncActivity extends Activity implements TracingSyncResultReciever.Receiver{
+	
+	TextView mInfoText;
+
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_nfc);
+		mInfoText = (TextView) findViewById(R.id.nfc_text_view);
+		mInfoText.setText("Uploading Records...");
+		
+		TracingSyncResultReciever mReceiver = new TracingSyncResultReciever(new Handler());
+        mReceiver.setReceiver(this);
+        
+		Intent intent = new Intent(this, TracingSyncService.class);
+		intent.setAction(TracingSyncService.ACTION_START_SYNC);
+		intent.putExtra(TracingSyncService.EXTRA_RECEIVER, mReceiver);
+		startService(intent);
+	}
+
+	@Override
+	public void onReceiveResult(int resultCode, Bundle resultData) {
+        switch (resultCode) {
+        case TracingSyncService.SYNC_COMPLETE:
+        	mInfoText.setText("Information is up to date!");
+            break;        
+        case TracingSyncService.RECORD_UPLOADED:      
+        	mInfoText.setText("Uploading Records...(" + resultData.getInt(TracingSyncService.UPLOAD_PROGRESS) + "/"+ resultData.getInt(TracingSyncService.UPLOAD_SIZE) + ")");
+        break;
+    }
+		
+	}	
+	
+}

+ 28 - 0
src/de/tudarmstadt/informatik/hostage/sync/tracing/TracingSyncResultReciever.java

@@ -0,0 +1,28 @@
+package de.tudarmstadt.informatik.hostage.sync.tracing;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.ResultReceiver;
+ 
+public class TracingSyncResultReciever extends ResultReceiver {
+    private Receiver mReceiver;
+ 
+    public TracingSyncResultReciever(Handler handler) {
+        super(handler);
+    }
+ 
+    public void setReceiver(Receiver receiver) {
+        mReceiver = receiver;
+    }
+ 
+    public interface Receiver {
+        public void onReceiveResult(int resultCode, Bundle resultData);
+    }
+ 
+    @Override
+    protected void onReceiveResult(int resultCode, Bundle resultData) {
+        if (mReceiver != null) {
+            mReceiver.onReceiveResult(resultCode, resultData);
+        }
+    }
+}

+ 196 - 0
src/de/tudarmstadt/informatik/hostage/sync/tracing/TracingSyncService.java

@@ -0,0 +1,196 @@
+package de.tudarmstadt.informatik.hostage.sync.tracing;
+
+import java.security.KeyStore;
+import java.util.ArrayList;
+
+import org.apache.http.HttpResponse;
+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 android.app.IntentService;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.os.Bundle;
+import android.os.ResultReceiver;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
+import de.tudarmstadt.informatik.hostage.net.MySSLSocketFactory;
+import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
+
+public class TracingSyncService extends IntentService{
+	
+	public static final String REMOTE_DEVICE = "de.tudarmstadt.informatik.hostage.REMOTE_DEVICE";
+	
+	public static final String ACTION_START_SYNC = "de.tudarmstadt.informatik.hostage.ACTION_START_SYNC";
+	public static final String EXTRA_RECEIVER = "de.tudarmstadt.informatik.hostage.EXTRA_HANDLER";
+	
+	public static final String UPLOAD_SIZE = "de.tudarmstadt.informatik.hostage.UPLOAD_SIZE";
+	public static final String UPLOAD_PROGRESS = "de.tudarmstadt.informatik.hostage.UPLOAD_PROGRESS";
+	
+	public static final int RECORD_UPLOADED = 0x00;
+	public static final int SYNC_COMPLETE = 0x01;
+	
+	
+	private HttpClient httpClient;
+	private ResultReceiver receiver;
+	
+	HostageDBOpenHelper dbh;
+	
+	SharedPreferences pref;
+	Editor editor;
+
+	public TracingSyncService() {
+		super(TracingSyncService.class.getName());
+
+	}
+	
+
+	@Override
+	public void onCreate() {
+		super.onCreate();
+		pref = PreferenceManager.getDefaultSharedPreferences(this);
+		editor = pref.edit();
+		dbh = new HostageDBOpenHelper(this);
+	}
+
+	/**
+	 * The IntentService calls this method from the default worker thread with
+	 * the intent that started the service. When this method returns, IntentService
+	 * stops the service, as appropriate.
+	 */
+	@Override
+	protected void onHandleIntent(Intent intent) {
+		if (intent != null) {
+			final String action = intent.getAction();
+			if (ACTION_START_SYNC.equals(action)) {
+				receiver = intent.getParcelableExtra(EXTRA_RECEIVER);
+				uploadNewRecords();
+				getRemoteData();
+				//TODO add: dbh.clearSyncInfos();
+				if(receiver != null){
+					receiver.send(SYNC_COMPLETE, null);
+				}
+			}
+
+		}	
+	}	
+	
+	
+	/**
+	 * Uploads all new Records to a server, specified in the settings.
+	 */
+	private void uploadNewRecords() {
+		int lastUploadedAttackId = pref.getInt("LAST_UPLOADED_ATTACK_ID", -1);
+		String serverAddress = pref.getString("pref_upload", "https://ssi.cased.de");	
+		ArrayList<AttackRecord> recordList = dbh.getRecordOfEachAttack(lastUploadedAttackId);
+		int size = recordList.size();
+		int offset = 1;
+		for(AttackRecord record: recordList){
+			editor.putInt("LAST_UPLOADED_ATTACK_ID", lastUploadedAttackId + offset);
+			editor.commit();
+			
+			boolean success = uploadSingleRecord(record, serverAddress);
+			Log.i("Tracing upload", "Upload of record: " + offset +"/" + size + ((success) ? " successful.": " failed."));
+			if(receiver != null){
+				Bundle data = new Bundle();
+				data.putInt(UPLOAD_SIZE, size); 
+				data.putInt(UPLOAD_PROGRESS, offset);
+				receiver.send(RECORD_UPLOADED, data);
+			}
+			offset++;			
+		}
+	}	
+	
+	/**
+	 * Uploads a single Record to a server, specified in the settings.
+	 * 
+	 * @param record The Record to upload.
+	 * @serverAddress Address of the target server
+	 * @return True if the upload was successful, else false.
+	 */
+	private boolean uploadSingleRecord(AttackRecord record, String serverAddress) {
+		// Create a https client. Uses MySSLSocketFactory to accept all certificates
+		HttpPost httppost;
+		try {
+			httpClient = createHttpClient();
+			// Create HttpPost
+			httppost = new HttpPost(serverAddress);
+			// Create JSON String of Record
+			//TODO FIX ME
+			//StringEntity se = new StringEntity( record.toString(TraCINgFormatter.getInstance()) );
+			StringEntity se = new StringEntity(record.toString());
+			httppost.setEntity(se);
+			// Execute HttpPost
+			HttpResponse response = httpClient.execute(httppost);
+			Log.i("TracingSyncService", "Status Code: " + response.getStatusLine().getStatusCode()); 
+		} catch (Exception e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+	
+	/**
+	 * Uploads a single Record to a server, specified in the settings.
+	 * 
+	 * @param record
+	 *            The Record to upload.
+	 * @return True if the upload was successful, else false.
+	 */
+	private void getRemoteData() {
+		//TODO GET DATA FROM SERVER
+		//TODO SAVE DATA IN DATABASE
+	}
+	
+	/**
+	 * Creates a HttpClient with an own SSL Socket.
+	 * 
+	 * @return HttpsClient who accepts accepts all certificates.
+	 * @see MySSLSocketFactory
+	 */
+	private 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();
+		}
+	}
+
+
+
+}

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java

@@ -205,7 +205,7 @@ public class MainActivity extends FragmentActivity {
 	 *            View elements which triggers the method call.
 	 */
 	public void showLog(View view) {
-		startActivity(new Intent(this, ViewLog.class));
+		//startActivity(new Intent(this, ViewLog.class));
 	}
 
 	public void startPlayGround(View view) {

+ 33 - 22
src/de/tudarmstadt/informatik/hostage/ui/PlayGroundActivity.java

@@ -8,30 +8,36 @@ import java.util.Random;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.util.Log;
 import android.view.Menu;
 import android.view.View;
 import android.widget.TextView;
 import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
+import de.tudarmstadt.informatik.hostage.logging.SyncInfoRecord;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
-import de.tudarmstadt.informatik.hostage.sync.BluetoothSync;
-import de.tudarmstadt.informatik.hostage.sync.NFCSync;
+import de.tudarmstadt.informatik.hostage.sync.bluetooth.BluetoothSync;
+import de.tudarmstadt.informatik.hostage.sync.nfc.NFCSync;
+import de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncActivity;
 
 public class PlayGroundActivity extends Activity {
 
 
 	public void createNetworkData(View view) {
 		Random rnd = new Random();
-		ArrayList<HashMap<String, Object>> fakeNetInfo = new ArrayList<HashMap<String, Object>>();
+		ArrayList<NetworkRecord> fakeNetInfo = new ArrayList<NetworkRecord>();
 		for (int i = 0; i < 25; i++) {
-			HashMap<String, Object> network = new HashMap<String, Object>();
-			network.put(HostageDBContract.NetworkEntry.COLUMN_NAME_BSSID, createRandomBSSID());
-			network.put(HostageDBContract.NetworkEntry.COLUMN_NAME_SSID, new BigInteger(130, rnd).toString(32));
-			network.put(HostageDBContract.NetworkEntry.COLUMN_NAME_LATITUDE, rnd.nextDouble() * 360);
-			network.put(HostageDBContract.NetworkEntry.COLUMN_NAME_LONGITUDE, rnd.nextDouble() * 360);
-			network.put(HostageDBContract.NetworkEntry.COLUMN_NAME_ACCURACY, rnd.nextFloat());
-			network.put(HostageDBContract.NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, System.currentTimeMillis());
-			fakeNetInfo.add(network);
+			NetworkRecord record = new NetworkRecord();
+			record.setBssid(createRandomBSSID());
+			record.setSsid(new BigInteger(130, rnd).toString(32));
+			record.setLatitude(rnd.nextDouble() * 360);
+			record.setLongitude(rnd.nextDouble() * 360);
+			record.setAccuracy(rnd.nextFloat());
+			record.setTimestampLocation(System.currentTimeMillis());
+			fakeNetInfo.add(record);
 		}
 
 		setNetworkInfoText();
@@ -45,7 +51,7 @@ public class PlayGroundActivity extends Activity {
 	}
 
 	public void startNFC(View view) {
-		startActivity(new Intent(this, NFCSync.class));
+		startActivity(new Intent(this, TracingSyncActivity.class));
 	}
 
 	public void syncData(View view) {
@@ -73,18 +79,23 @@ public class PlayGroundActivity extends Activity {
 
 	private void setNetworkInfoText() {
 		HostageDBOpenHelper dbh = new HostageDBOpenHelper(this);
-		TextView bssids = (TextView) findViewById(R.id.textView1);
+		TextView text_view = (TextView) findViewById(R.id.textView1);
 		String text = "";
-		ArrayList<HashMap<String, Object>> netInfo = dbh.getNetworkInformation();
-		for (HashMap<String, Object> network : netInfo) {
-			text = text + (String) network.get(HostageDBContract.NetworkEntry.COLUMN_NAME_BSSID) + "\n"
-					+ (String) network.get(HostageDBContract.NetworkEntry.COLUMN_NAME_SSID) + "\n"
-					+ network.get(HostageDBContract.NetworkEntry.COLUMN_NAME_LATITUDE) + "\n"
-					+ network.get(HostageDBContract.NetworkEntry.COLUMN_NAME_LONGITUDE) + "\n"
-					+ network.get(HostageDBContract.NetworkEntry.COLUMN_NAME_ACCURACY) + "\n"
-					+ network.get(HostageDBContract.NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP) + "\n\n";
+		ArrayList<SyncInfoRecord> syncInfo = dbh.getSyncInfo();
+		HashMap<String, Long> syncDevices = dbh.getSyncDevices();
+
+		for (SyncInfoRecord info: syncInfo) {
+			text = text + info.getBSSID() + "\n"
+					+ info.getDeviceID() + "\n" +
+					+ info.getNumber_of_attacks() + "\n"
+					+ info.getNumber_of_portscans() + "\n\n";
+		}
+		
+		for(String device: syncDevices.keySet()){
+			text = text + device + "\n"
+					+ syncDevices.get(device) + "\n\n";
 		}
-		bssids.setText(text);
+		text_view.setText(text);
 	}
 
 	@Override

+ 2 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordDetailFragment.java

@@ -23,6 +23,7 @@ import de.tudarmstadt.informatik.hostage.deprecated.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.ui.LogFilter;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
+import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
 
 /**
  * Created by Julien on 02.03.14.
@@ -146,7 +147,7 @@ public class RecordDetailFragment extends UpNavigatibleFragment {
 			String from = r.getLocalIP() == null ? "-" : r.getLocalIP() + ":" + r.getLocalPort();
 			String to = r.getRemoteIP() == null ? "-" : r.getRemoteIP() + ":" + r.getRemotePort();
 
-			if (r.getType() == Record.TYPE.SEND) {
+			if (r.getType() == MessageRecord.TYPE.SEND) {
 				row = mInflater.inflate(R.layout.fragment_record_conversation_sent, null);
 			} else {
 				row = mInflater.inflate(R.layout.fragment_record_conversation_received, null);

+ 4 - 4
src/de/tudarmstadt/informatik/hostage/wrapper/Packet.java

@@ -46,11 +46,11 @@ public class Packet {
 
 	/**
 	 * Returns a String representation of the payload.
-	 * If the payload contains a ASCII character the whole
-	 * String will be represented as a String of a byte values.
+	 * Depending on the protocol, the String will be represented 
+	 * as a String of it's byte values.
 	 * E.g.: the byte[] {0x01, 0x4A, 0x03} would look like
-	 * the String "01, 4A, 03".
-	 * Otherwise a normal String will be created with the payload.
+	 * the String "01, 4A, 03", or
+	 * otherwise a normal String will be created with the payload.
 	 * 
 	 * @return String representation.
 	 */