This commit is contained in:
Wilco Baan Hofman 2018-08-25 14:37:48 +02:00
parent 761b704888
commit 40e8e39fb9
4 changed files with 79 additions and 120 deletions

View file

@ -15,55 +15,14 @@
package nl.eventinfra.wifisetup;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.provider.Settings.Secure;
import android.security.KeyChain;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.UnknownHostException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
/* import android.util.Base64; */
import org.json.JSONException;
import org.json.JSONObject;
import nl.eventinfra.wifisetup.R;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiEnterpriseConfig.Eap;
import android.net.wifi.WifiEnterpriseConfig.Phase2;
import android.net.wifi.WifiManager;
import android.os.Build;
@ -74,18 +33,24 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.CheckBox;
import android.widget.Toast;
import android.widget.ViewFlipper;
import java.io.InputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.List;
/* import android.util.Base64; */
// API level 18 and up
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiEnterpriseConfig.Eap;
public class WifiSetup extends Activity {
protected static final int SHOW_PREFERENCES = 0;
// FIXME This should be a configuration setting somehow
private static final String INT_EAP = "eap";
private static final String INT_PHASE2 = "phase2";
@ -101,15 +66,12 @@ public class WifiSetup extends Activity {
private static final String INT_IDENTITY = "identity";
private static final String INT_ANONYMOUS_IDENTITY = "anonymous_identity";
private static final String INT_ENTERPRISEFIELD_NAME = "android.net.wifi.WifiConfiguration$EnterpriseField";
// Because android.security.Credentials cannot be resolved...
private static final String INT_KEYSTORE_URI = "keystore://";
private static final String INT_CA_PREFIX = INT_KEYSTORE_URI + "CACERT_";
private static final String INT_PRIVATE_KEY_PREFIX = INT_KEYSTORE_URI + "USRPKEY_";
private static final String INT_PRIVATE_KEY_ID_PREFIX = "USRPKEY_";
private static final String INT_CLIENT_CERT_PREFIX = INT_KEYSTORE_URI + "USRCERT_";
protected static final int SHOW_PREFERENCES = 0;
private Handler mHandler = new Handler();
private EditText username;
private EditText password;
@ -127,11 +89,12 @@ public class WifiSetup extends Activity {
private String s_password;
private ViewFlipper flipper;
private void toastText(final String text) {
if (toast != null)
toast.cancel();
toast = Toast.makeText(getBaseContext(), text, Toast.LENGTH_SHORT);
toast.show();
static String removeQuotes(String str) {
int len = str.length();
if ((len > 1) && (str.charAt(0) == '"') && (str.charAt(len - 1) == '"')) {
return str.substring(1, len - 1);
}
return str;
}
/*
@ -144,6 +107,17 @@ public class WifiSetup extends Activity {
}
*/
static String surroundWithQuotes(String string) {
return "\"" + string + "\"";
}
private void toastText(final String text) {
if (toast != null)
toast.cancel();
toast = Toast.makeText(getBaseContext(), text, Toast.LENGTH_SHORT);
toast.show();
}
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
@ -240,7 +214,7 @@ public class WifiSetup extends Activity {
private void saveWifiConfig() {
WifiManager wifiManager = (WifiManager) this.getApplicationContext().getSystemService(WIFI_SERVICE);
if (!wifimanager) {
if (wifiManager == null) {
return;
}
wifiManager.setWifiEnabled(true);
@ -259,19 +233,19 @@ public class WifiSetup extends Activity {
}
if (check5g.isChecked()) {
ssid = "34C3";
ssid = "emfcamp";
} else {
ssid = "34C3-legacy";
ssid = "emfcamp-legacy18";
}
subject_match = "/CN=radius.c3noc.net";
altsubject_match = "DNS:radius.c3noc.net";
subject_match = "/CN=radius.emfcamp.org";
altsubject_match = "DNS:radius.emfcamp.org";
s_username = username.getText().toString();
s_password = password.getText().toString();
realm = "";
if (s_username.equals("") && s_password.equals("")) {
s_username = "34c3";
s_password = "34c3";
s_username = "emf";
s_password = "emf";
} else {
if (s_username.contains("@")) {
int idx = s_username.indexOf("@");
@ -280,7 +254,7 @@ public class WifiSetup extends Activity {
}
// Use the existing eduroam profile if it exists.
// Use the existing ssid profile if it exists.
boolean ssidExists = false;
if (configs != null) {
for (WifiConfiguration config : configs) {
@ -329,8 +303,8 @@ public class WifiSetup extends Activity {
configMap.put(INT_EAP, "TTLS");
configMap.put(INT_PHASE2, "auth=PAP");
configMap.put(INT_ENGINE, "0");
// configMap.put(INT_CA_CERT, INT_CA_PREFIX + ca_name);
// This sets the CA certificate.
applyAndroid43EnterpriseSettings(currentConfig, configMap);
if (!ssidExists) {
@ -344,7 +318,6 @@ public class WifiSetup extends Activity {
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void applyAndroid43EnterpriseSettings(WifiConfiguration currentConfig, HashMap<String,String> configMap) {
try {
@ -381,7 +354,7 @@ public class WifiSetup extends Activity {
Builder builder = new AlertDialog.Builder(this);
switch (item.getItemId()) {
case R.id.about:
PackageInfo pi = null;
PackageInfo pi;
try{
pi = getPackageManager().getPackageInfo(getClass().getPackage().getName(), 0);
} catch(Exception e){
@ -403,8 +376,6 @@ public class WifiSetup extends Activity {
return false;
}
/* Update the status in the main thread */
protected void resultStatus(final boolean success, final String text) {
mHandler.post(new Runnable() {
@ -428,16 +399,4 @@ public class WifiSetup extends Activity {
}
});
}
static String removeQuotes(String str) {
int len = str.length();
if ((len > 1) && (str.charAt(0) == '"') && (str.charAt(len - 1) == '"')) {
return str.substring(1, len - 1);
}
return str;
}
static String surroundWithQuotes(String string) {
return "\"" + string + "\"";
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View file

@ -2,38 +2,38 @@
<ViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".WifiSetup"
android:id="@+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/viewflipper"
tools:context=".WifiSetup"
>
<ScrollView
android:id="@+id/FirstView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/FirstView"
>
<LinearLayout
android:id="@+id/logonLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/logonLayout"
android:orientation="vertical"
android:gravity="center_horizontal|top">
android:gravity="center_horizontal|top"
android:orientation="vertical">
<ImageView
android:id="@+id/logo"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:scaleType="fitCenter"
android:contentDescription="@string/LOGO"
android:src="@drawable/ccc34c3logo"
android:padding="0dp" />
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/emflogo" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:autoLink="web"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:autoLink="web"
android:text="@string/twitter"/>
<CheckBox android:id="@+id/check5g"
@ -47,35 +47,35 @@
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:text="@string/l5ghz"/>
android:text="@string/l5ghz"
android:textAlignment="center" />
<TextView
android:layout_marginTop="5dp"
android:id="@+id/labelkeystore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:text="@string/lkeystore"/>
android:text="@string/lkeystore"
android:textAlignment="center" />
<LinearLayout
android:id="@+id/logindata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal|top"
android:orientation="vertical"
android:visibility="gone">
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="@string/Username"
android:inputType="textEmailAddress"
android:padding="5dp"
android:layout_marginTop="15dp"
android:hint="@string/Username"
>
<requestFocus />
</EditText>
@ -84,11 +84,11 @@
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:ems="10"
android:hint="@string/Password"
android:inputType="textPassword"
android:padding="5dp"
android:layout_marginTop="5dp"
android:hint="@string/Password"
/>
</LinearLayout>
@ -96,8 +96,8 @@
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Logon"
android:layout_margin="15dp"/>
android:layout_margin="15dp"
android:text="@string/Logon" />
<Space
android:layout_width="wrap_content"
@ -107,11 +107,11 @@
</ScrollView>
<LinearLayout
android:id="@+id/logonLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/logonLayout2"
android:orientation="vertical"
android:gravity="center"
android:orientation="vertical"
>
<TextView
android:id="@+id/resulttitle"

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">34C3 Wifi Setup</string>
<string name="app_name">EMF Camp Wifi Setup</string>
<string name="TITLE_LOGON">Please logon</string>
<string name="Username">username@realm</string>
@ -10,7 +10,7 @@
<string name="twitter">https://twitter.com/sha2017noc</string>
<string name="c5ghz">This device supports the 5GHz band</string>
<string name="l5ghz">(Unfortunately, autodetecting 5GHz support is broken...)</string>
<string name="l5ghz">(Unfortunately, autodetecting 5GHz support is broken&#8230;)</string>
<string name="lkeystore">Note: if you have no screen lock, Android refuses to store the security settings!</string>
@ -18,5 +18,5 @@
<string name="EXIT_TITLE">Exit</string>
<string name="ABOUT_CONTENT">This small helper app creates a Wifi connection entry for the CCC/EMF/SHA2017 networks. It configures the correct SSL CA and subject name match, making it a little more secure than a hand-created entry.</string>
<string name="LOGO">34C3 Logo</string>
<string name="LOGO">34C3 Logo (or EMF, whatever)</string>
</resources>