Commit f9f57d26 authored by Toni Beier's avatar Toni Beier

Draft 1

parent 0bb913cf
......@@ -11,6 +11,12 @@ android {
versionName "1.3.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled true
......@@ -30,4 +36,5 @@ dependencies {
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
api 'com.google.guava:guava:28.0-android'
}
package de.tu_chemnitz.wlan;
public class EduroamWifiAnalyser {
}
......@@ -26,6 +26,9 @@ import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.StringRequest;
import com.google.common.base.Optional;
import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -43,6 +46,7 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -586,161 +590,176 @@ class Helper {
List<MainActivity.TickLine> list = new ArrayList<>();
WifiManager wifi = (WifiManager)context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifi.isWifiEnabled())
{
MainActivity.TickLine tick = new MainActivity.TickLine(true, context.getResources().getString(R.string.tickline_message_wifi_enabled), context.getResources().getString(R.string.msg_available ), false);
WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifi.isWifiEnabled()) {
MainActivity.TickLine tick = new MainActivity.TickLine(true, context.getResources().getString(R.string.tickline_message_wifi_enabled), context.getResources().getString(R.string.msg_available), false);
tick._tag = status_tags[0];
list.add(tick);
List<WifiConfiguration> currentConfigs = wifi.getConfiguredNetworks();
for (WifiConfiguration currentConfig : currentConfigs)
{
if (ssid.equals(currentConfig.SSID) && currentConfig.networkId != 0)
{
String message;
boolean ticked = true;
message=currentConfig.SSID;
if (currentConfig.allowedGroupCiphers.toString().contains(",")) message+=" with mixed mode";
else if (currentConfig.allowedGroupCiphers.toString().contains("2")) message+=" with CCMP";
else if (currentConfig.allowedGroupCiphers.toString().contains("2")) message+=" with TKIP";
list.add(new MainActivity.TickLine(ticked, message, "SSID", false));
ticked = false;
message = currentConfig.enterpriseConfig.getIdentity();
if( message != null && !message.isEmpty() ) {
if (message.contains("@")) {
message = message.substring(0, message.indexOf('@'));
if (message.contains("-")) {
message = message.substring(0, message.indexOf('-'));
ticked = true;
}
}
} else {
message = context.getString(R.string.tickline_subtext_user_identity_not_found);
ticked = false;
}
list.add(new MainActivity.TickLine(ticked, message, context.getString(R.string.tickline_category_user_identity), false));
Optional<WifiConfiguration> eduroamWifiConfiguration = FluentIterable.from(wifi.getConfiguredNetworks()).firstMatch(wifiConfiguration -> {
//some samsung devices return eduroam with leading and ending "-Symbols: "eduroam"
String wifiSSID = wifiConfiguration.SSID;
if (wifiSSID.startsWith("\"") && wifiSSID.endsWith("\"")) {
wifiSSID = wifiSSID.substring(1, wifiSSID.length() - 1);
}
if (currentConfig.enterpriseConfig.getAnonymousIdentity().length()>0) {
String anonymousIdentity = currentConfig.enterpriseConfig.getAnonymousIdentity();
if (!anonymousIdentity.equals(context.getString(R.string.edurom_anonymous_identity))) {
message = context.getString(R.string.edurom_error_old_configuration, anonymousIdentity);
ticked = false;
} else {
message = anonymousIdentity;
return context.getString(R.string.eduroam_ssid).equals(wifiSSID) && wifiConfiguration.networkId != 0;
});
if (eduroamWifiConfiguration.isPresent()) {
WifiConfiguration checkingEduroamWifiConfiguration = eduroamWifiConfiguration.get();
String message;
boolean ticked = true;
message = checkingEduroamWifiConfiguration.SSID;
if (checkingEduroamWifiConfiguration.allowedGroupCiphers.toString().contains(","))
message += " with mixed mode";
else if (checkingEduroamWifiConfiguration.allowedGroupCiphers.toString().contains("2"))
message += " with CCMP";
else if (checkingEduroamWifiConfiguration.allowedGroupCiphers.toString().contains("2"))
message += " with TKIP";
list.add(new MainActivity.TickLine(ticked, message, "SSID", false));
ticked = false;
message = checkingEduroamWifiConfiguration.enterpriseConfig.getIdentity();
if (message != null && !message.isEmpty()) {
if (message.contains("@")) {
message = message.substring(0, message.indexOf('@'));
if (message.contains("-")) {
message = message.substring(0, message.indexOf('-'));
ticked = true;
}
} else {
message= context.getResources().getString(R.string.msg_not_set);
ticked = false;
}
list.add(new MainActivity.TickLine(ticked, message, context.getResources().getString(R.string.tickline_category_anonymous_identity), true));
} else {
message = context.getString(R.string.tickline_subtext_user_identity_not_found);
ticked = false;
}
list.add(new MainActivity.TickLine(ticked, message, context.getString(R.string.tickline_category_user_identity), false));
ticked = true;
if (currentConfig.enterpriseConfig.getEapMethod()== WifiEnterpriseConfig.Eap.PEAP) message="PEAP with ";
else if (currentConfig.enterpriseConfig.getEapMethod()== WifiEnterpriseConfig.Eap.PWD) message="PWD with ";
else if (currentConfig.enterpriseConfig.getEapMethod()== WifiEnterpriseConfig.Eap.TLS) message="TLS";
else if (currentConfig.enterpriseConfig.getEapMethod()== WifiEnterpriseConfig.Eap.TTLS) message="TTLS with ";
else {
message="EAP Method error";
if (checkingEduroamWifiConfiguration.enterpriseConfig.getAnonymousIdentity().length() > 0) {
String anonymousIdentity = checkingEduroamWifiConfiguration.enterpriseConfig.getAnonymousIdentity();
if (!anonymousIdentity.equals(context.getString(R.string.edurom_anonymous_identity))) {
message = context.getString(R.string.edurom_error_old_configuration, anonymousIdentity);
ticked = false;
} else {
message = anonymousIdentity;
ticked = true;
}
if (currentConfig.enterpriseConfig.getEapMethod()!= WifiEnterpriseConfig.Eap.TLS)
{
if (currentConfig.enterpriseConfig.getPhase2Method()== WifiEnterpriseConfig.Phase2.MSCHAPV2) message+="Phase2: MSCHAPv2";
else if (currentConfig.enterpriseConfig.getPhase2Method()== WifiEnterpriseConfig.Phase2.GTC) message+="Phase2: GTC";
else if (currentConfig.enterpriseConfig.getPhase2Method()== WifiEnterpriseConfig.Phase2.PAP) message+="Phase2: PAP";
else message+="Phase2 Missing";
}
list.add(new MainActivity.TickLine(ticked, message, "EAP Methode", true));
// WifiManager::getConfiguredNetworks return WifiConfiguration instances with incomplete information
// There is no right way to verify the CA certificate in a configured WLAN.
// Transforms WifiEnterpriseConfig instance to string value and check the ca_cert value
Map<String, String> currentWifiConfigurationValues = new HashMap<>();
// Parse string representation of enterprise config
for (String wifiConfigurationLine : currentConfig.enterpriseConfig.toString().split(String.valueOf('\n'))) {
String wifiConfigurationValueIdentifier = null;
String wifiConfigurationValue = null;
// Check if identifier has value and add identifier and maybe value to a map
String[] wifiConfigurationLineSegments = wifiConfigurationLine.split(String.valueOf(' '));
if (wifiConfigurationLineSegments.length >= 1) {
wifiConfigurationValueIdentifier = wifiConfigurationLineSegments[0];
if (wifiConfigurationLineSegments.length >= 2) {
wifiConfigurationValue = wifiConfigurationLineSegments[1];
}
currentWifiConfigurationValues.put(wifiConfigurationValueIdentifier, wifiConfigurationValue);
} else {
message = context.getResources().getString(R.string.msg_not_set);
ticked = false;
}
list.add(new MainActivity.TickLine(ticked, message, context.getResources().getString(R.string.tickline_category_anonymous_identity), true));
ticked = true;
if (checkingEduroamWifiConfiguration.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.PEAP)
message = "PEAP with ";
else if (checkingEduroamWifiConfiguration.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.PWD)
message = "PWD with ";
else if (checkingEduroamWifiConfiguration.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.TLS)
message = "TLS";
else if (checkingEduroamWifiConfiguration.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.TTLS)
message = "TTLS with ";
else {
message = "EAP Method error";
ticked = false;
}
if (checkingEduroamWifiConfiguration.enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.TLS) {
if (checkingEduroamWifiConfiguration.enterpriseConfig.getPhase2Method() == WifiEnterpriseConfig.Phase2.MSCHAPV2)
message += "Phase2: MSCHAPv2";
else if (checkingEduroamWifiConfiguration.enterpriseConfig.getPhase2Method() == WifiEnterpriseConfig.Phase2.GTC)
message += "Phase2: GTC";
else if (checkingEduroamWifiConfiguration.enterpriseConfig.getPhase2Method() == WifiEnterpriseConfig.Phase2.PAP)
message += "Phase2: PAP";
else message += "Phase2 Missing";
}
list.add(new MainActivity.TickLine(ticked, message, "EAP Methode", true));
// WifiManager::getConfiguredNetworks return WifiConfiguration instances with incomplete information
// There is no right way to verify the CA certificate in a configured WLAN.
// Transforms WifiEnterpriseConfig instance to string value and check the ca_cert value
Map<String, String> currentWifiConfigurationValues = new HashMap<>();
// Parse string representation of enterprise config
for (String wifiConfigurationLine : checkingEduroamWifiConfiguration.enterpriseConfig.toString().split(String.valueOf('\n'))) {
String wifiConfigurationValueIdentifier = null;
String wifiConfigurationValue = null;
// Check if identifier has value and add identifier and maybe value to a map
String[] wifiConfigurationLineSegments = wifiConfigurationLine.split(String.valueOf(' '));
if (wifiConfigurationLineSegments.length >= 1) {
wifiConfigurationValueIdentifier = wifiConfigurationLineSegments[0];
if (wifiConfigurationLineSegments.length >= 2) {
wifiConfigurationValue = wifiConfigurationLineSegments[1];
}
currentWifiConfigurationValues.put(wifiConfigurationValueIdentifier, wifiConfigurationValue);
}
// If ca_cert is in map/string, then check value.
String currentWifiConfigurationCaCertValue = currentWifiConfigurationValues.get("ca_cert");
if (currentWifiConfigurationCaCertValue != null) {
if ( currentWifiConfigurationCaCertValue.contains("PEAP") && currentWifiConfigurationCaCertValue.contains("eduroam")
&& currentWifiConfigurationCaCertValue.contains("EAPIEEE8021X") && currentWifiConfigurationCaCertValue.contains("PEAP")) {
message = context.getString(R.string.tickline_subtext_ca_cert_certificate_ok);
ticked = true;
} else {
message = context.getString(R.string.tickline_subtext_ca_cert_certificate_wrong);
ticked = false;
}
}
// If ca_cert is in map/string, then check value.
String currentWifiConfigurationCaCertValue = currentWifiConfigurationValues.get("ca_cert");
if (currentWifiConfigurationCaCertValue != null) {
if (currentWifiConfigurationCaCertValue.contains("PEAP") && currentWifiConfigurationCaCertValue.contains("eduroam")
&& currentWifiConfigurationCaCertValue.contains("EAPIEEE8021X") && currentWifiConfigurationCaCertValue.contains("PEAP")) {
message = context.getString(R.string.tickline_subtext_ca_cert_certificate_ok);
ticked = true;
} else {
message = context.getString(R.string.tickline_subtext_ca_cert_certificate_not_found);
message = context.getString(R.string.tickline_subtext_ca_cert_certificate_wrong);
ticked = false;
}
list.add(new MainActivity.TickLine(ticked, message, context.getString(R.string.tickline_message_ca_cert), true));
} else {
message = context.getString(R.string.tickline_subtext_ca_cert_certificate_not_found);
ticked = false;
}
list.add(new MainActivity.TickLine(ticked, message, context.getString(R.string.tickline_message_ca_cert), true));
String subjectMatch;
if (Build.VERSION.SDK_INT >= 23)
subjectMatch = currentConfig.enterpriseConfig.getAltSubjectMatch();
else
subjectMatch = currentConfig.enterpriseConfig.getSubjectMatch();
String subjectMatch;
if (Build.VERSION.SDK_INT >= 23)
subjectMatch = checkingEduroamWifiConfiguration.enterpriseConfig.getAltSubjectMatch();
else
subjectMatch = checkingEduroamWifiConfiguration.enterpriseConfig.getSubjectMatch();
if (subjectMatch!=null && subjectMatch.length()>0)
{
message=context.getString(R.string.tickline_message_server_subject_match_ok);
ticked = true;
}
else {
message="Missing";
ticked = false;
}
list.add(new MainActivity.TickLine(ticked, message, "Server Subject Match", true));
if (subjectMatch != null && subjectMatch.length() > 0) {
message = context.getString(R.string.tickline_message_server_subject_match_ok);
ticked = true;
} else {
message = "Missing";
ticked = false;
}
list.add(new MainActivity.TickLine(ticked, message, "Server Subject Match", true));
message = context.getResources().getString(R.string.tickline_message_techincal_parameters);
if (list.get(3).ticked && list.get(4).ticked && list.get(5).ticked && list.get(6).ticked) {
message += " " + context.getResources().getString(R.string.tickline_message_are_correct);
ticked = true;
} else {
message += " " + context.getResources().getString(R.string.tickline_message_not_correct);
ticked = false;
}
list.add(3, new MainActivity.TickLine(ticked, message, "", false));
message = context.getResources().getString(R.string.tickline_message_techincal_parameters);
if (list.get(3).ticked && list.get(4).ticked && list.get(5).ticked && list.get(6).ticked) {
message += " " + context.getResources().getString(R.string.tickline_message_are_correct);
ticked = true;
} else {
message += " " + context.getResources().getString(R.string.tickline_message_not_correct);
ticked = false;
}
list.add(3, new MainActivity.TickLine(ticked, message, "", false));
// try to update network config without config change to check if config is managed by app
// if eduroam is not marked as writable, test it. Remember the result.
if (!IS_EDUROAM_WIFI_WRITABLE.get()) {
IS_EDUROAM_WIFI_WRITABLE.set(wifi.updateNetwork(currentConfig) != -1);
}
tick = new MainActivity.TickLine(IS_EDUROAM_WIFI_WRITABLE.get(), context.getString(R.string.tickline_message_wifi_writable), IS_EDUROAM_WIFI_WRITABLE.get() ? context.getString(R.string.tickline_subtext_wifi_writable) : context.getString(R.string.tickline_subtext_wifi_notwritable), false);
tick._tag = context.getString(R.string.tick_tag_wifi_writable);
list.add(tick);
// try to update network config without config change to check if config is managed by app
// if eduroam is not marked as writable, test it. Remember the result.
if (!IS_EDUROAM_WIFI_WRITABLE.get()) {
IS_EDUROAM_WIFI_WRITABLE.set(wifi.updateNetwork(checkingEduroamWifiConfiguration) != -1);
}
tick = new MainActivity.TickLine(IS_EDUROAM_WIFI_WRITABLE.get(), context.getString(R.string.tickline_message_wifi_writable), IS_EDUROAM_WIFI_WRITABLE.get() ? context.getString(R.string.tickline_subtext_wifi_writable) : context.getString(R.string.tickline_subtext_wifi_notwritable), false);
tick._tag = context.getString(R.string.tick_tag_wifi_writable);
list.add(tick);
}
} else {
MainActivity.TickLine tick = new MainActivity.TickLine(false, context.getResources().getString(R.string.tickline_message_wifi_disabled), context.getResources().getString(R.string.msg_available), false);
MainActivity.TickLine tick = new MainActivity.TickLine(false, context.getResources().getString(R.string.tickline_message_wifi_disabled), context.getResources().getString(R.string.msg_available), false);
tick._tag = status_tags[0];
list.add(tick);
}
MainActivity.TickLine tick = getByTag(list, status_tags[0]);
if (list.size() <= 1 && tick != null && tick.ticked) {
//Samsung gibt nicht eduroam als ssid zurück sondern "eduroam"
Collection<WifiConfiguration> avaliabelWifiConfiguration = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).getConfiguredNetworks();
Optional<WifiConfiguration> eduroamWifiConfiguration = FluentIterable.from(avaliabelWifiConfiguration).firstMatch(wifiConfiguration -> wifiConfiguration.SSID.replace("\"", "").equals(context.getString(R.string.eduroam_ssid)));
if (!eduroamWifiConfiguration.isPresent()) {
list.add(new MainActivity.TickLine(false, context.getResources().getString(R.string.message_no_ssid_configuration, ssid), context.getResources().getString(R.string.msg_available), false));
}
......
package de.tu_chemnitz.wlan;
public class StatusInfo {
}
package de.tu_chemnitz.wlan;
public class StatusTag extends Enum {
public static final WIFI_ENABLED = new StatusTag( "WIFI_ENABLED", 0, "wifiEnabled"" );
private String legacyStatusTagString;
private StatusTag( String name, int index, String legacyStatusTagString ) {
super( name, index );
this.legacyStatusTagString = legacyStatusTagString;
}
}
......@@ -98,7 +98,7 @@
<string name="message_wtc_login">WTC-Login</string>
<string name="message_logged_in_as" formatted="false">Angemeldet als %1$s</string>
<string name="message_no_ssid_configuration" formatted="false">Kein %1$s Konfiguration angewendet</string>
<string name="message_no_ssid_configuration" formatted="true">Keine %1$s-Konfiguration angewendet</string>
<string name="message_last_wifi_ssid_successfully_applied" formatted="false">%1$s erfolgreich angewendet!</string>
<string name="message_not_successfully_applied_last_wifi_ssid" formatted="false">Konnte Konfiguration nicht anwenden!\nLöschen Sie ggf. bestehende Konfiguration von %1$s.</string>
<string name="input_device_name" formatted="false">%1$s - %2$s (API - %3$d)</string>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="eduroam_ssid" translatable="false">eduroam</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment