diff options
author | Parménides GV <parmegv@sdf.org> | 2014-11-17 18:44:36 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2014-11-26 12:59:53 +0100 |
commit | 301adeab4b1630645e53baa982b35cba394e52b2 (patch) | |
tree | a37866c8aebb53b8040e8b24b7fc148ccb83ed4e | |
parent | ba3362c6779e3b89533b1a132d67b4916a9976d8 (diff) |
Update vpn certificate and store it correctly.
One more onReceiveResult for Dashboard, that method needs a rethink: a
statemachine class, and a simple "next()" method? The reality is that
the onReceiveResult specifies a linked process, and that should have a
better model than a series of if/else cases with strings comparisons hehehe
4 files changed, 24 insertions, 40 deletions
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java index 03cbda0c..a89ef357 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java @@ -861,23 +861,13 @@ public class ProviderAPI extends IntentService { } return true; } - - private boolean updateVpnCertificate() { - getNewCert(); - - Intent updateEIP = new Intent(getApplicationContext(), EIP.class); - updateEIP.setAction(Constants.ACTION_UPDATE_EIP_SERVICE); - startService(updateEIP); - - return true; - } /** * Downloads a new OpenVPN certificate, attaching authenticated cookie for authenticated certificate. * * @return true if certificate was downloaded correctly, false if provider.json or danger_on flag are not present in SharedPreferences, or if the certificate url could not be parsed as a URI, or if there was an SSL error. */ - private boolean getNewCert() { + private boolean updateVpnCertificate() { try { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 395e9987..b139f73f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -433,22 +433,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf hideProgressBar(); setResult(RESULT_OK); - Intent updateEIP = new Intent(getApplicationContext(), EIP.class); - ResultReceiver eip_receiver = new ResultReceiver(new Handler()){ - protected void onReceiveResult(int resultCode, Bundle resultData){ - super.onReceiveResult(resultCode, resultData); - String request = resultData.getString(Constants.REQUEST_TAG); - if (resultCode == Activity.RESULT_OK){ - if(authed_eip) - eipStart(); - else - eipStatus.setText("Certificate updated"); - } - } - }; - updateEIP.putExtra(Constants.RECEIVER_TAG, eip_receiver); - updateEIP.setAction(Constants.ACTION_UPDATE_EIP_SERVICE); - startService(updateEIP); + + updateEipService(); } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { changeStatusMessage(resultCode); hideProgressBar(); @@ -456,6 +442,24 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf } } + private void updateEipService() { + Intent updateEIP = new Intent(getApplicationContext(), EIP.class); + updateEIP.setAction(Constants.ACTION_UPDATE_EIP_SERVICE); + ResultReceiver receiver = new ResultReceiver(new Handler()) { + protected void onReceiveResult(int resultCode, Bundle resultData) { + String request = resultData.getString(Constants.REQUEST_TAG); + if(request.equalsIgnoreCase(Constants.ACTION_UPDATE_EIP_SERVICE)) { + if(resultCode == Activity.RESULT_OK) { + if(authed_eip) + eipStart(); + } + } + } + }; + updateEIP.putExtra(Constants.RECEIVER_TAG, receiver); + startService(updateEIP); + } + private void changeStatusMessage(final int previous_result_code) { // TODO Auto-generated method stub ResultReceiver eip_status_receiver = new ResultReceiver(new Handler()){ diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 2b9f120d..9f81f263 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -194,7 +194,7 @@ public final class EIP extends IntentService { refreshEipDefinition(); deleteAllVpnProfiles(); updateGateways(); - if(mReceiver != null) mReceiver.send(Activity.RESULT_OK, Bundle.EMPTY); + tellToReceiver(ACTION_UPDATE_EIP_SERVICE, Activity.RESULT_OK); } private void refreshEipDefinition() { diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java index e2da588c..0fa60550 100644 --- a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java @@ -845,23 +845,13 @@ public class ProviderAPI extends IntentService { } return true; } - - private boolean updateVpnCertificate() { - getNewCert(); - - Intent updateEIP = new Intent(getApplicationContext(), EIP.class); - updateEIP.setAction(Constants.ACTION_UPDATE_EIP_SERVICE); - startService(updateEIP); - - return true; - } /** * Downloads a new OpenVPN certificate, attaching authenticated cookie for authenticated certificate. * * @return true if certificate was downloaded correctly, false if provider.json is not present in SharedPreferences, or if the certificate url could not be parsed as a URI, or if there was an SSL error. */ - private boolean getNewCert() { + private boolean updateVpnCertificate() { try { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); @@ -898,6 +888,7 @@ public class ProviderAPI extends IntentService { certificateString = certAndKey[i++] + certAndKey[i]; } } + RSAPrivateKey key = ConfigHelper.parseRsaKeyFromString(keyString); keyString = Base64.encodeToString(key.getEncoded(), Base64.DEFAULT); preferences.edit().putString(Constants.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n"+keyString+"-----END RSA PRIVATE KEY-----").commit(); @@ -905,7 +896,6 @@ public class ProviderAPI extends IntentService { X509Certificate certificate = ConfigHelper.parseX509CertificateFromString(certificateString); certificateString = Base64.encodeToString(certificate.getEncoded(), Base64.DEFAULT); preferences.edit().putString(Constants.CERTIFICATE, "-----BEGIN CERTIFICATE-----\n"+certificateString+"-----END CERTIFICATE-----").commit(); - preferences.edit().putString(Constants.DATE_FROM_CERTIFICATE, EIP.certificate_date_format.format(Calendar.getInstance().getTime())).commit(); return true; } catch (CertificateException e) { // TODO Auto-generated catch block |