Commit 05069643 authored by Toni Beier's avatar Toni Beier

Use new certificate to configure edurom wifi

parent ba2adcec
-----BEGIN CERTIFICATE-----
MIIGLjCCBBagAwIBAgIJAONOGbgO3/24MA0GCSqGSIb3DQEBCwUAMIGjMQswCQYDVQQGEwJERTEQMA4GA1UECAwHU2FjaHNlbjERMA8GA1UEBwwIQ2hlbW5pdHoxKTAnBgNVBAoMIFRlY2huaXNjaGUgVW5pdmVyc2l0YWV0IENoZW1uaXR6MSMwIQYDVQQLDBpVbml2ZXJzaXRhZXRzcmVjaGVuemVudHJ1bTEfMB0GA1UEAwwWVFUgQ2hlbW5pdHogV0xBTiBDQSBHMTAeFw0xODAyMjgxNzMwMjVaFw00MzAyMjcxNzMwMjVaMIGjMQswCQYDVQQGEwJERTEQMA4GA1UECAwHU2FjaHNlbjERMA8GA1UEBwwIQ2hlbW5pdHoxKTAnBgNVBAoMIFRlY2huaXNjaGUgVW5pdmVyc2l0YWV0IENoZW1uaXR6MSMwIQYDVQQLDBpVbml2ZXJzaXRhZXRzcmVjaGVuemVudHJ1bTEfMB0GA1UEAwwWVFUgQ2hlbW5pdHogV0xBTiBDQSBHMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAONA+4woOCrp8AHHnV7FAdx948GI268HnzCqQ35IBXyecTaMHmszSvUiKn287ppBMictYRZbyrd5xZG0vZbKOywuA9824EXMMV8K5Un94lBjAwGKlTwWMSPLvrUBz98jMdUBpU3c+Cg6JWRbSjU7ZlbjvCtwfdzBLRlAt+Ikkdo82CQRMCQkxhs+qhh/wkNR3Pt45V9oxBZxz61QQ4EzlGkw6n4kovFiMkMFebgwVFkg8L8A+BxR9K1Q0IUJjEaBTXq22vfBAUxjAertOD2320oJUi95GKZFCOyyE6JMNNuBMIiq7Q9mbfcXq8TRsQYqmr+vOK28iSlwTAdnsrlovskazyllZdqZcNjDHiMWX/mJpJbi3HeMHiidYB+9ISJuwnLuhtwUuIdx7z3+ZP8BpV+gGlhySisWjA3Bm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sLtOWvHdOFZxbRxVjPpvn5Svo15j4WVWSIjaGzic7HBf8=
-----END CERTIFICATE-----
......@@ -9,6 +9,8 @@ package de.tu_chemnitz.wlan;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
......@@ -32,6 +34,8 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.CookieHandler;
import java.net.CookieManager;
......@@ -39,11 +43,13 @@ import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
class Helper {
......@@ -275,10 +281,10 @@ class Helper {
Log.e("ca_migration","error while old local idm values converted in form", jsonException);
}
return sharedPrefs.contains("wifi_json") &&
buildWifiConfig(savedJsonEduromConfig);
buildWifiConfig(savedJsonEduromConfig, context);
}
static boolean buildWifiConfig(String json) {
static boolean buildWifiConfig(String json, Context context) {
try {
Log.d("buildWifiConfig", json);
JSONObject jObj = new JSONObject(json);
......@@ -297,13 +303,25 @@ class Helper {
return false;
}
CertificateFactory cf = CertificateFactory.getInstance("X.509");
JSONArray certs = jObj.getJSONArray("certs");
X509Certificate[] x509s = new X509Certificate[certs.length()];
for (int i = 0; i < certs.length(); i++) {
x509s[i] = (X509Certificate)cf.generateCertificate(
new ByteArrayInputStream(
Base64.decode(certs.getString(i), Base64.DEFAULT)));
X509Certificate[] x509s = new X509Certificate[1];
AssetManager assetManager = context.getAssets();
InputStream eduromCertificateStream = null;
try {
eduromCertificateStream = assetManager.open("ca.pem");
X509Certificate eduromCertificate = (X509Certificate) cf.generateCertificate(eduromCertificateStream);
x509s[0] = eduromCertificate;
} catch (IOException exception) {
Log.e("buildWifiConfig", "Can't open certificate", exception);
} catch (CertificateException exception) {
Log.e("buildWifiConfig", "Can't read or process certificate", exception);
} catch (Throwable throwable) {
Log.e("buildWifiConfig", "Unexpected error", throwable);
} finally {
if (eduromCertificateStream != null) {
eduromCertificateStream.close();
}
}
WifiConfiguration conf = createEapConfig(
......@@ -437,7 +455,7 @@ class Helper {
}
static void quickApply(Context context, String json) {
if (Helper.buildWifiConfig(json)) {
if (Helper.buildWifiConfig(json, context)) {
if (Helper.applyWifiConfig(context)) {
Toast.makeText(context, Helper.lastWifi.SSID + " erfolgreich angewendet!", Toast.LENGTH_LONG).show();
} else {
......
......@@ -166,7 +166,7 @@ public class LoginActivity extends AppCompatActivity {
Helper.buildRequest(LoginActivity.this.getApplicationContext(), API_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (Helper.buildWifiConfig(response)) {
if (Helper.buildWifiConfig(response, getApplicationContext())) {
//showText("Konfiguration erfolgreich geladen.<br>Warte auf Freigabe von Server.");
SharedPreferences sharedPrefs = getApplicationContext().getSharedPreferences("de.tu_chemnitz.de.wlan.config", Context.MODE_PRIVATE);
......
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