|
@@ -5,6 +5,8 @@ import android.accounts.AccountManager;
|
|
|
import android.content.ContentResolver;
|
|
|
import android.content.Context;
|
|
|
import android.content.SharedPreferences;
|
|
|
+import android.location.Address;
|
|
|
+import android.location.Geocoder;
|
|
|
import android.location.Location;
|
|
|
import android.os.Bundle;
|
|
|
import android.preference.PreferenceManager;
|
|
@@ -47,6 +49,7 @@ import java.util.Date;
|
|
|
import java.util.GregorianCalendar;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
|
|
@@ -146,30 +149,30 @@ public class SyncUtils {
|
|
|
public static void appendRecordToStringWriter(Record record, Writer stream){
|
|
|
try {
|
|
|
stream.append(
|
|
|
- "{" +
|
|
|
- "\"sensor\":{" +
|
|
|
- "\"name\":\"HosTaGe\"," +
|
|
|
- "\"type\":\"Honeypot\"" +
|
|
|
- "}," +
|
|
|
- "\"src\":{" +
|
|
|
- "\"ip\":\"" + record.getRemoteIP() + "\"," +
|
|
|
- "\"port\":" + record.getRemotePort() +
|
|
|
- "}," +
|
|
|
- "\"dst\":{" +
|
|
|
- "\"ip\":\"" + record.getLocalIP() + "\"," +
|
|
|
- "\"port\":" + record.getLocalPort() +
|
|
|
- "}," +
|
|
|
- "\"type\":" + (protocolsTypeMap.containsKey(record.getProtocol()) ? protocolsTypeMap.get(record.getProtocol()) : 0) + "," +
|
|
|
- "\"log\":\"" + record.getProtocol() + "\"," +
|
|
|
- "\"md5sum\":\"\"," +
|
|
|
- "\"date\":" + (int)(record.getTimestamp() / 1000) + "," +
|
|
|
- "\"bssid\":\"" + record.getBssid() + "\"," +
|
|
|
- "\"ssid\":\"" + record.getSsid() + "\"," +
|
|
|
- "\"device\":\"" + record.getDevice() + "\"," +
|
|
|
- "\"sync_id\":\"" + record.getSync_id() + "\"," +
|
|
|
- "\"internal_attack\":\"" + record.getWasInternalAttack() + "\"," +
|
|
|
- "\"external_ip\":\"" + record.getExternalIP() + "\"" +
|
|
|
- "}\n"
|
|
|
+ "{" +
|
|
|
+ "\"sensor\":{" +
|
|
|
+ "\"name\":\"HosTaGe\"," +
|
|
|
+ "\"type\":\"Honeypot\"" +
|
|
|
+ "}," +
|
|
|
+ "\"src\":{" +
|
|
|
+ "\"ip\":\"" + record.getRemoteIP() + "\"," +
|
|
|
+ "\"port\":" + record.getRemotePort() +
|
|
|
+ "}," +
|
|
|
+ "\"dst\":{" +
|
|
|
+ "\"ip\":\"" + record.getLocalIP() + "\"," +
|
|
|
+ "\"port\":" + record.getLocalPort() +
|
|
|
+ "}," +
|
|
|
+ "\"type\":" + (protocolsTypeMap.containsKey(record.getProtocol()) ? protocolsTypeMap.get(record.getProtocol()) : 0) + "," +
|
|
|
+ "\"log\":\"" + record.getProtocol() + "\"," +
|
|
|
+ "\"md5sum\":\"\"," +
|
|
|
+ "\"date\":" + (int)(record.getTimestamp() / 1000) + "," +
|
|
|
+ "\"bssid\":\"" + record.getBssid() + "\"," +
|
|
|
+ "\"ssid\":\"" + record.getSsid() + "\"," +
|
|
|
+ "\"device\":\"" + record.getDevice() + "\"," +
|
|
|
+ "\"sync_id\":\"" + record.getSync_id() + "\"," +
|
|
|
+ "\"internal_attack\":\"" + record.getWasInternalAttack() + "\"," +
|
|
|
+ "\"external_ip\":\"" + record.getExternalIP() + "\"" +
|
|
|
+ "}\n"
|
|
|
);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -263,40 +266,42 @@ public class SyncUtils {
|
|
|
|
|
|
JSONObject condition = new JSONObject();
|
|
|
|
|
|
- /**if(fromTime > 0){
|
|
|
- Calendar calendar = GregorianCalendar.getInstance();
|
|
|
- calendar.setTimeInMillis(fromTime);
|
|
|
+ if(fromTime > 0){
|
|
|
+ Calendar calendar = GregorianCalendar.getInstance();
|
|
|
+ calendar.setTimeInMillis(fromTime);
|
|
|
|
|
|
- condition.put("date", fromCalendar(calendar));
|
|
|
- }**/
|
|
|
+ condition.put("date", fromCalendar(calendar));
|
|
|
+ }
|
|
|
+
|
|
|
+ String country = null;
|
|
|
+
|
|
|
+ Location location = MyLocationManager.getNewestLocation();
|
|
|
|
|
|
- Location location = null;
|
|
|
- /**
|
|
|
- TODO(alex): UNCOMMENT THIS AGAIN, WHEN WE ARE SURE ABOUT USING LOCATIONS THIS WAY.
|
|
|
- =======================================================================
|
|
|
- location = MyLocationManager.getNewestLocation();
|
|
|
- */
|
|
|
if(location != null){
|
|
|
- JSONArray ll = new JSONArray();
|
|
|
- ll.put(location.getLongitude());
|
|
|
- ll.put(location.getLatitude());
|
|
|
+ Geocoder geocoder = new Geocoder(context, Locale.getDefault());
|
|
|
+ List<Address> fromLocation = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
|
|
|
+
|
|
|
+ if(fromLocation.size() > 0){
|
|
|
+ Address address = fromLocation.get(0);
|
|
|
+ country = address.getCountryCode();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- condition.put("location", ll);
|
|
|
- condition.put("distance", 500);
|
|
|
- } else {
|
|
|
+ if(country == null){
|
|
|
// We could not get the gps coordinates, try to retrieve the country code from the SIM card
|
|
|
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
- String countryCodeValue = tm.getNetworkCountryIso();
|
|
|
- /**
|
|
|
- TODO(julien): COMMENT THIS OUT, TO GET ALL SYNC DATA FROM TRACING.
|
|
|
- */
|
|
|
- condition.put("country", countryCodeValue);
|
|
|
+ country = tm.getNetworkCountryIso();
|
|
|
}
|
|
|
|
|
|
+ if(country == null || country.trim().isEmpty()) country = Locale.getDefault().getCountry();
|
|
|
+
|
|
|
+ condition.put("country", country);
|
|
|
+
|
|
|
JSONObject req = new JSONObject();
|
|
|
req.put("condition", condition);
|
|
|
req.put("info", deviceMap);
|
|
|
|
|
|
+
|
|
|
StringEntity se = new StringEntity(req.toString());
|
|
|
httppost.addHeader("content-type", "application/json");
|
|
|
httppost.setEntity(se);
|
|
@@ -520,4 +525,4 @@ public class SyncUtils {
|
|
|
return new DefaultHttpClient();
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|