From 9bb172e96cfd741e528e692118ee32fc609c6da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 18:59:27 +0100 Subject: Cleaned imports, use wildcards when appropriate --- .../se/leap/bitmaskclient/test/ConnectionManager.java | 11 ++++------- .../java/se/leap/bitmaskclient/test/FromAssets.java | 9 +++------ .../bitmaskclient/test/testDashboardIntegration.java | 4 ++-- .../java/se/leap/bitmaskclient/test/testEIP.java | 14 ++++++-------- .../leap/bitmaskclient/test/testGatewaysManager.java | 19 +++++++------------ .../leap/bitmaskclient/test/testLeapSRPSession.java | 19 +++++++------------ 6 files changed, 29 insertions(+), 47 deletions(-) (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test') diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java index e67dd820..96abc7eb 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java @@ -1,12 +1,9 @@ package se.leap.bitmaskclient.test; -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.wifi.WifiManager; -import android.util.Log; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import android.content.*; +import android.net.*; +import android.net.wifi.*; +import java.lang.reflect.*; public class ConnectionManager { static void setMobileDataEnabled(boolean enabled, Context context) { diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java index 4f771922..fd8b9a7e 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java @@ -1,11 +1,8 @@ package se.leap.bitmaskclient.test; -import android.content.Context; - -import org.json.JSONException; - -import java.io.IOException; -import java.io.InputStream; +import android.content.*; +import org.json.*; +import java.io.*; public class FromAssets { diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java index 91b93d42..57213bc1 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java @@ -1,10 +1,10 @@ package se.leap.bitmaskclient.test; -import android.content.Context; +import android.content.*; import android.test.*; import com.robotium.solo.*; -import java.io.IOException; +import java.io.*; import de.blinkt.openvpn.activities.*; import se.leap.bitmaskclient.*; diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testEIP.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testEIP.java index d9235085..b504af99 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testEIP.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testEIP.java @@ -16,15 +16,13 @@ */ package se.leap.bitmaskclient.test; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.test.ServiceTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import se.leap.bitmaskclient.Dashboard; -import se.leap.bitmaskclient.eip.Constants; -import se.leap.bitmaskclient.eip.EIP; +import android.content.*; +import android.test.*; +import android.test.suitebuilder.annotation.*; + +import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.eip.*; /** * @author parmegv diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testGatewaysManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testGatewaysManager.java index c4303251..addbc53c 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testGatewaysManager.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testGatewaysManager.java @@ -16,20 +16,15 @@ */ package se.leap.bitmaskclient.test; -import android.app.Activity; -import android.content.Context; -import android.content.SharedPreferences; -import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; +import android.app.*; +import android.content.*; +import android.test.*; +import android.test.suitebuilder.annotation.*; -import junit.framework.Test; +import org.json.*; -import org.json.JSONObject; - -import se.leap.bitmaskclient.Dashboard; -import se.leap.bitmaskclient.eip.Gateway; -import se.leap.bitmaskclient.eip.GatewaysManager; +import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.eip.*; /** * @author parmegv diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testLeapSRPSession.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testLeapSRPSession.java index d7f4bfb3..e25d4e56 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testLeapSRPSession.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testLeapSRPSession.java @@ -1,20 +1,15 @@ package se.leap.bitmaskclient.test; -import java.io.UnsupportedEncodingException; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.Arrays; +import java.io.*; +import java.math.*; +import java.security.*; +import java.util.*; -import org.jboss.security.srp.SRPParameters; +import android.test.suitebuilder.annotation.*; -import android.test.suitebuilder.annotation.SmallTest; +import se.leap.bitmaskclient.*; -import se.leap.bitmaskclient.ConfigHelper; -import se.leap.bitmaskclient.LeapSRPSession; - -import junit.framework.TestCase; +import junit.framework.*; public class testLeapSRPSession extends TestCase { -- cgit v1.2.3 From b87f082fe0e9c05cf45c56b510a2c4000133b572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 19:07:43 +0100 Subject: Indent everything with IntelliJ --- .../leap/bitmaskclient/test/ConnectionManager.java | 27 +- .../se/leap/bitmaskclient/test/FromAssets.java | 5 +- .../test/testConfigurationWizard.java | 63 +- .../test/testDashboardIntegration.java | 113 +- .../bitmaskclient/test/testGatewaysManager.java | 4 +- .../bitmaskclient/test/testLeapSRPSession.java | 1094 ++++++++++---------- .../test/testVpnCertificateValidator.java | 10 +- 7 files changed, 663 insertions(+), 653 deletions(-) (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test') diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java index 96abc7eb..a664c885 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java @@ -3,26 +3,27 @@ package se.leap.bitmaskclient.test; import android.content.*; import android.net.*; import android.net.wifi.*; + import java.lang.reflect.*; public class ConnectionManager { static void setMobileDataEnabled(boolean enabled, Context context) { - final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - Method[] methods = conman.getClass().getMethods(); - for (Method method : methods) { - if (method.getName().equals("setMobileDataEnabled")) { - method.setAccessible(true); - try { - method.invoke(conman, enabled); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } + final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + Method[] methods = conman.getClass().getMethods(); + for (Method method : methods) { + if (method.getName().equals("setMobileDataEnabled")) { + method.setAccessible(true); + try { + method.invoke(conman, enabled); + } catch (InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + } } - } } static void setWifiEnabled(boolean enabled, Context context) { - WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - wifiManager.setWifiEnabled(enabled); + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + wifiManager.setWifiEnabled(enabled); } } diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java index fd8b9a7e..6a4c1ee2 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java @@ -1,7 +1,9 @@ package se.leap.bitmaskclient.test; import android.content.*; + import org.json.*; + import java.io.*; public class FromAssets { @@ -11,11 +13,12 @@ public class FromAssets { public FromAssets(Context context) { this.context = context; } + public String toString(String filename) throws IOException, JSONException { String result = ""; InputStream is = context.getAssets().open(filename); byte[] bytes = new byte[is.available()]; - if(is.read(bytes) > 0) { + if (is.read(bytes) > 0) { result = new String(bytes); } return result; diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java index 755f83a7..7a19409b 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java @@ -2,41 +2,44 @@ package se.leap.bitmaskclient.test; import android.test.*; import android.widget.*; + import com.robotium.solo.*; + import java.io.*; + import se.leap.bitmaskclient.*; public class testConfigurationWizard extends ActivityInstrumentationTestCase2 { - private Solo solo; - private static int added_providers; - - public testConfigurationWizard() { - super(ConfigurationWizard.class); - } + private Solo solo; + private static int added_providers; + + public testConfigurationWizard() { + super(ConfigurationWizard.class); + } public testConfigurationWizard(Solo solo) { super(ConfigurationWizard.class); this.solo = solo; } - @Override - protected void setUp() throws Exception { - super.setUp(); + @Override + protected void setUp() throws Exception { + super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); - ConnectionManager.setMobileDataEnabled(true, solo.getCurrentActivity().getApplicationContext()); - } + ConnectionManager.setMobileDataEnabled(true, solo.getCurrentActivity().getApplicationContext()); + } - @Override - protected void tearDown() throws Exception { - solo.finishOpenedActivities(); - } - - public void testListProviders() { - assertEquals(solo.getCurrentViews(ListView.class).size(), 1); + @Override + protected void tearDown() throws Exception { + solo.finishOpenedActivities(); + } - assertEquals("Number of available providers differ", predefinedProviders() + added_providers, shownProviders()); - } + public void testListProviders() { + assertEquals(solo.getCurrentViews(ListView.class).size(), 1); + + assertEquals("Number of available providers differ", predefinedProviders() + added_providers, shownProviders()); + } private int shownProviders() { return solo.getCurrentViews(ListView.class).get(0).getCount(); @@ -53,10 +56,10 @@ public class testConfigurationWizard extends ActivityInstrumentationTestCase2 { - private Solo solo; + private Solo solo; private Context context; - public testDashboardIntegration() { - super(Dashboard.class); - } + public testDashboardIntegration() { + super(Dashboard.class); + } - @Override - protected void setUp() throws Exception { - super.setUp(); + @Override + protected void setUp() throws Exception { + super.setUp(); context = getInstrumentation().getContext(); - solo = new Solo(getInstrumentation(), getActivity()); - ConnectionManager.setMobileDataEnabled(true, context); + solo = new Solo(getInstrumentation(), getActivity()); + ConnectionManager.setMobileDataEnabled(true, context); solo.unlockScreen(); - if(solo.searchText(solo.getString(R.string.configuration_wizard_title))) + if (solo.searchText(solo.getString(R.string.configuration_wizard_title))) new testConfigurationWizard(solo).toDashboard("demo.bitmask.net"); - } - - @Override - protected void tearDown() throws Exception { - solo.finishOpenedActivities(); - } - - /** - * This test will fail if Android does not trust VPN connection. - * I cannot automate that dialog. - */ - public void testOnOffOpenVpn() { - solo.clickOnView(solo.getView(R.id.eipSwitch)); - turningEipOn(); - - solo.clickOnView(solo.getView(R.id.eipSwitch)); - turningEipOff(); - - solo.clickOnView(solo.getView(R.id.eipSwitch)); - turningEipOn(); - - solo.clickOnView(solo.getView(R.id.eipSwitch)); - turningEipOff(); + } + + @Override + protected void tearDown() throws Exception { + solo.finishOpenedActivities(); + } + + /** + * This test will fail if Android does not trust VPN connection. + * I cannot automate that dialog. + */ + public void testOnOffOpenVpn() { + solo.clickOnView(solo.getView(R.id.eipSwitch)); + turningEipOn(); + + solo.clickOnView(solo.getView(R.id.eipSwitch)); + turningEipOff(); + + solo.clickOnView(solo.getView(R.id.eipSwitch)); + turningEipOn(); + + solo.clickOnView(solo.getView(R.id.eipSwitch)); + turningEipOff(); /*solo.clickOnView(solo.getView(R.id.eipSwitch)); turningEipOn(); @@ -57,14 +58,14 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2Yd*s T`-n."; - salt = "40c3f47b99ce8dc9"; - expected_A = trim(new BigInteger("490b5de7a287c59cefe267441a186ec24f63210fbf28877305f5896eaec5a7245d304ecb2b09d91066e627d7b2c8bf9e5271d882361a435355d1c2d1ac9d3069877189a01d64b2dd73a569e9e96b9a99767dbc02e04c839b09444f48430b113c1827c20b684ae33f5018051169f5acf4913ebd76a205c6f1aa2cc75747687d56", 16).toByteArray()); - String x_string = "9665839759b4fb9684e7438daecbd6e7129b4ebd3e4a107916e9a64bbbf399c9"; - expected_x = trim(new BigInteger(x_string, 16).toByteArray()); - assertEquals(new BigInteger(1, expected_x).toString(16), x_string); - a = "a72111a2"; - B = "6574ddce3e33c44a77198fa8b3656627e4a24c8786948e79f0c2588febaa485c94b1deb5e420bd3b46f9a34c7862525452ca7a0542c52f939d9f277a013aeceef7353a7741440f6dd2f6c2f1dc07fa5ca003e305c89c876a3035bd04f546b711d44da06a3ba827bc8affbf9ed46de1bfbc670ef9ed7c0bb8cdc588285d13849e"; - expected_M1 = trim(new BigInteger("03bbcf57aeaec89a3a254bb9650a924ea86aa0fdd83fd7274a75b7083f221cf0", 16).toByteArray()); - expected_M2 = trim(new BigInteger("082cf49ad5a34cc5ca571e3d063aec4bd96e7b96a6d951295180631650a84587", 16).toByteArray()); - - a_byte = new BigInteger(a, 16).toByteArray(); - client = new LeapSRPSession(username, password, a_byte); - - x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); - assertTrue(Arrays.equals(x, expected_x)); - assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); - - A = client.exponential(); - assertTrue(Arrays.equals(A, expected_A)); - - M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); - - assertTrue(Arrays.equals(M1, expected_M1)); - - verified = client.verify(expected_M2); - assertTrue(verified); + username = "parmegv"; + password = "wR\"P}x@_,:k$`YYd*s T`-n."; + salt = "40c3f47b99ce8dc9"; + expected_A = trim(new BigInteger("490b5de7a287c59cefe267441a186ec24f63210fbf28877305f5896eaec5a7245d304ecb2b09d91066e627d7b2c8bf9e5271d882361a435355d1c2d1ac9d3069877189a01d64b2dd73a569e9e96b9a99767dbc02e04c839b09444f48430b113c1827c20b684ae33f5018051169f5acf4913ebd76a205c6f1aa2cc75747687d56", 16).toByteArray()); + String x_string = "9665839759b4fb9684e7438daecbd6e7129b4ebd3e4a107916e9a64bbbf399c9"; + expected_x = trim(new BigInteger(x_string, 16).toByteArray()); + assertEquals(new BigInteger(1, expected_x).toString(16), x_string); + a = "a72111a2"; + B = "6574ddce3e33c44a77198fa8b3656627e4a24c8786948e79f0c2588febaa485c94b1deb5e420bd3b46f9a34c7862525452ca7a0542c52f939d9f277a013aeceef7353a7741440f6dd2f6c2f1dc07fa5ca003e305c89c876a3035bd04f546b711d44da06a3ba827bc8affbf9ed46de1bfbc670ef9ed7c0bb8cdc588285d13849e"; + expected_M1 = trim(new BigInteger("03bbcf57aeaec89a3a254bb9650a924ea86aa0fdd83fd7274a75b7083f221cf0", 16).toByteArray()); + expected_M2 = trim(new BigInteger("082cf49ad5a34cc5ca571e3d063aec4bd96e7b96a6d951295180631650a84587", 16).toByteArray()); + + a_byte = new BigInteger(a, 16).toByteArray(); + client = new LeapSRPSession(username, password, a_byte); + + x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); + assertTrue(Arrays.equals(x, expected_x)); + assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); + + A = client.exponential(); + assertTrue(Arrays.equals(A, expected_A)); + + M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); + + assertTrue(Arrays.equals(M1, expected_M1)); + + verified = client.verify(expected_M2); + assertTrue(verified); /* Test 7: password with ! */ - username = "parmegvtest3"; - password = "holahola!"; - salt = "1bf48d42b9a7ed32"; - expected_A = trim(new BigInteger("4e2fbe8db5d07f33ff1f4303959b5396dcffc1460b6ce8866fd388415f27fe10f9042986ab8682cdcf9a033e651bca89173688989adad854c91bc1918f98d5c82525fb6f328a8cf74ce1436b23821cba5337aaa20a3e5631e4b957053d542f2b5fc456e888371c9d6b94360b37adb2793eca8db100c24887c459e36d729a98e1", 16).toByteArray()); - x_string = "363d1d62dda07b2d987a9739ddb5ec32fcad9c7322fb64e87937f2da86c45d9f"; - expected_x = trim(new BigInteger(x_string, 16).toByteArray()); - assertEquals(new BigInteger(1, expected_x).toString(16), x_string); - a = "16dd0cf5"; - B = "dd5c9c5e13eb5daa6e7303928b3c826cec520ccef429c0dcb785be34c330d5bb89c99d7d94842b6b5c19cac600f884c50b26989b105f397115df7f3d13c5c7c2f6327cc547fc854ae40f09f1f6a104968bd510243feb104eb559e085fe1d720770be2887a1f424c534a3ab962d82e92458f652328bcf9878f95fdcf463d06193"; - expected_M1 = trim(new BigInteger("a7ffbff753a547b877f8944339b707b3ce1998da27badf253d56bf39f35308a6", 16).toByteArray()); - expected_M2 = trim(new BigInteger("5cc3d7f0077e978c83acdef14a725af01488c1728f0cf32cd7013d24faf5d901", 16).toByteArray()); - - a_byte = new BigInteger(a, 16).toByteArray(); - client = new LeapSRPSession(username, password, a_byte); - - x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); - assertTrue(Arrays.equals(x, expected_x)); - assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); - - A = client.exponential(); - assertTrue(Arrays.equals(A, expected_A)); - - M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); - - assertTrue(Arrays.equals(M1, expected_M1)); - - verified = client.verify(expected_M2); - assertTrue(verified); + username = "parmegvtest3"; + password = "holahola!"; + salt = "1bf48d42b9a7ed32"; + expected_A = trim(new BigInteger("4e2fbe8db5d07f33ff1f4303959b5396dcffc1460b6ce8866fd388415f27fe10f9042986ab8682cdcf9a033e651bca89173688989adad854c91bc1918f98d5c82525fb6f328a8cf74ce1436b23821cba5337aaa20a3e5631e4b957053d542f2b5fc456e888371c9d6b94360b37adb2793eca8db100c24887c459e36d729a98e1", 16).toByteArray()); + x_string = "363d1d62dda07b2d987a9739ddb5ec32fcad9c7322fb64e87937f2da86c45d9f"; + expected_x = trim(new BigInteger(x_string, 16).toByteArray()); + assertEquals(new BigInteger(1, expected_x).toString(16), x_string); + a = "16dd0cf5"; + B = "dd5c9c5e13eb5daa6e7303928b3c826cec520ccef429c0dcb785be34c330d5bb89c99d7d94842b6b5c19cac600f884c50b26989b105f397115df7f3d13c5c7c2f6327cc547fc854ae40f09f1f6a104968bd510243feb104eb559e085fe1d720770be2887a1f424c534a3ab962d82e92458f652328bcf9878f95fdcf463d06193"; + expected_M1 = trim(new BigInteger("a7ffbff753a547b877f8944339b707b3ce1998da27badf253d56bf39f35308a6", 16).toByteArray()); + expected_M2 = trim(new BigInteger("5cc3d7f0077e978c83acdef14a725af01488c1728f0cf32cd7013d24faf5d901", 16).toByteArray()); + + a_byte = new BigInteger(a, 16).toByteArray(); + client = new LeapSRPSession(username, password, a_byte); + + x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); + assertTrue(Arrays.equals(x, expected_x)); + assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); + + A = client.exponential(); + assertTrue(Arrays.equals(A, expected_A)); + + M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); + + assertTrue(Arrays.equals(M1, expected_M1)); + + verified = client.verify(expected_M2); + assertTrue(verified); /* Test 8: username and password *was* failing in localhost testProviderAPI*/ - username = "gg"; - password = "password"; - a = "bc925bfb"; - salt = "ff9ebb44e947cf59"; - expected_A = trim(new BigInteger("8f434633414faeaf035a0dea8c1cb7876bb1f8ee80d6fee8ea43ae60c4f9658550d825c25f1ed5c6a5543358bbcb559b76958c8047a2e7e5fe0072bc1f16401bcfa77b57651ff50dd665c6f28c302b37c98495eff397a56befead2e5ceffaace45f2ec200520258adb66df751e815e464656d869454e360d98cbc70f9c64fd4c", 16).toByteArray()); - x_string = "9cad2eca264380dd0b48e3b405e109c1be0615ee6ec92e7105eff5bc3a309fd9"; - expected_x = trim(new BigInteger(x_string, 16).toByteArray()); - assertEquals(new BigInteger(1, expected_x).toString(16), x_string); - B = "9ca2cd50b4c41047e4aa9e4fac9078ae21175e51e04a23877d6c2044765e39959e9a6a3ede99d08a556c196f51a2be12117681b1ef9d0b0498fb2fa4e88649ab9403e743504e3aaefbce8c5cb474eef8f4724ccd076fd33857de510d8509b67f166d986443bc262d776ec20985f617a7aa86e490290ce5d66332c8b45742a527"; - expected_M1 = trim(new BigInteger("7a2f768791abaeb954eb7f001bb60d91e6f61e959c8fcdefb58de857af9edaac", 16).toByteArray()); - expected_M2 = trim(new BigInteger("d78da7e0a23c9b87a2f09cdee05c510c105b4a8d471b47402c38f4cdfa49fe6d", 16).toByteArray()); - - a_byte = new BigInteger(a, 16).toByteArray(); - client = new LeapSRPSession(username, password, a_byte); - - x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); - assertTrue(Arrays.equals(x, expected_x)); - assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); - - A = client.exponential(); - assertTrue(Arrays.equals(A, expected_A)); - - M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); - - assertTrue(Arrays.equals(M1, expected_M1)); - - verified = client.verify(expected_M2); - assertTrue(verified); + username = "gg"; + password = "password"; + a = "bc925bfb"; + salt = "ff9ebb44e947cf59"; + expected_A = trim(new BigInteger("8f434633414faeaf035a0dea8c1cb7876bb1f8ee80d6fee8ea43ae60c4f9658550d825c25f1ed5c6a5543358bbcb559b76958c8047a2e7e5fe0072bc1f16401bcfa77b57651ff50dd665c6f28c302b37c98495eff397a56befead2e5ceffaace45f2ec200520258adb66df751e815e464656d869454e360d98cbc70f9c64fd4c", 16).toByteArray()); + x_string = "9cad2eca264380dd0b48e3b405e109c1be0615ee6ec92e7105eff5bc3a309fd9"; + expected_x = trim(new BigInteger(x_string, 16).toByteArray()); + assertEquals(new BigInteger(1, expected_x).toString(16), x_string); + B = "9ca2cd50b4c41047e4aa9e4fac9078ae21175e51e04a23877d6c2044765e39959e9a6a3ede99d08a556c196f51a2be12117681b1ef9d0b0498fb2fa4e88649ab9403e743504e3aaefbce8c5cb474eef8f4724ccd076fd33857de510d8509b67f166d986443bc262d776ec20985f617a7aa86e490290ce5d66332c8b45742a527"; + expected_M1 = trim(new BigInteger("7a2f768791abaeb954eb7f001bb60d91e6f61e959c8fcdefb58de857af9edaac", 16).toByteArray()); + expected_M2 = trim(new BigInteger("d78da7e0a23c9b87a2f09cdee05c510c105b4a8d471b47402c38f4cdfa49fe6d", 16).toByteArray()); + + a_byte = new BigInteger(a, 16).toByteArray(); + client = new LeapSRPSession(username, password, a_byte); + + x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); + assertTrue(Arrays.equals(x, expected_x)); + assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); + + A = client.exponential(); + assertTrue(Arrays.equals(A, expected_A)); + + M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); + + assertTrue(Arrays.equals(M1, expected_M1)); + + verified = client.verify(expected_M2); + assertTrue(verified); /* Test 9: username and password *was* failing in localhost testProviderAPI*/ - username = "oo"; - password = "password"; - a = "1322ec50"; - salt = "a93c74934dcadd90"; - expected_A = trim(new BigInteger("c8e9f30a2f67977ee7e61e9ca5af8bd854b6cc98fe01dbe1b1a4cf002c1e2523b7e49f373a600ff85a84867817ec60fec532857812a07f5c6189f6172f133023af75ca4cb98b758bb84620d0aa3cfc74dc69e0507114c0aeab5a75c3ae3f07a919c5729420f03266c26ed41d1846e07de023ec68dd6830e9ebf129cf51abb571", 16).toByteArray()); - x_string = "20470538560c4beb4908e6bfe5b0e00da94223e361302a25c898cbdd3724020"; - expected_x = trim(new BigInteger(x_string, 16).toByteArray()); - assertEquals(new BigInteger(1, expected_x).toString(16), x_string); - B = "24f98ede155212bea8b1d8bacf8153735ee8114faa824c57c84df55f8d6072ab87f5ae885ce1062939dbaa68ca6e63147c1d2dc1f751e8be20d8a6f87287a2a83fcb1dc9b85dd406d438aeee5ccbc873603cb399627e26e6444e94b3d5d26764e866776c8960fe206bd33febeca9f55f6291dd2cb832eab69e5373f548adeefb"; - expected_M1 = trim(new BigInteger("1b35c705e563bd5239cdccc6627aa877c3023286f49b4b7c21341d2949ca2d15", 16).toByteArray()); - expected_M2 = trim(new BigInteger("a382025452bad8a6ccd0f703253fda90e7ea7bd0c2d466a389455080a4bd015d", 16).toByteArray()); - - a_byte = new BigInteger(a, 16).toByteArray(); - client = new LeapSRPSession(username, password, a_byte); - - x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); - assertTrue(Arrays.equals(x, expected_x)); - assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); - - A = client.exponential(); - assertTrue(Arrays.equals(A, expected_A)); - - M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); - - assertTrue(Arrays.equals(M1, expected_M1)); - - verified = client.verify(expected_M2); - assertTrue(verified); + username = "oo"; + password = "password"; + a = "1322ec50"; + salt = "a93c74934dcadd90"; + expected_A = trim(new BigInteger("c8e9f30a2f67977ee7e61e9ca5af8bd854b6cc98fe01dbe1b1a4cf002c1e2523b7e49f373a600ff85a84867817ec60fec532857812a07f5c6189f6172f133023af75ca4cb98b758bb84620d0aa3cfc74dc69e0507114c0aeab5a75c3ae3f07a919c5729420f03266c26ed41d1846e07de023ec68dd6830e9ebf129cf51abb571", 16).toByteArray()); + x_string = "20470538560c4beb4908e6bfe5b0e00da94223e361302a25c898cbdd3724020"; + expected_x = trim(new BigInteger(x_string, 16).toByteArray()); + assertEquals(new BigInteger(1, expected_x).toString(16), x_string); + B = "24f98ede155212bea8b1d8bacf8153735ee8114faa824c57c84df55f8d6072ab87f5ae885ce1062939dbaa68ca6e63147c1d2dc1f751e8be20d8a6f87287a2a83fcb1dc9b85dd406d438aeee5ccbc873603cb399627e26e6444e94b3d5d26764e866776c8960fe206bd33febeca9f55f6291dd2cb832eab69e5373f548adeefb"; + expected_M1 = trim(new BigInteger("1b35c705e563bd5239cdccc6627aa877c3023286f49b4b7c21341d2949ca2d15", 16).toByteArray()); + expected_M2 = trim(new BigInteger("a382025452bad8a6ccd0f703253fda90e7ea7bd0c2d466a389455080a4bd015d", 16).toByteArray()); + + a_byte = new BigInteger(a, 16).toByteArray(); + client = new LeapSRPSession(username, password, a_byte); + + x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); + assertTrue(Arrays.equals(x, expected_x)); + assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); + + A = client.exponential(); + assertTrue(Arrays.equals(A, expected_A)); + + M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); + + assertTrue(Arrays.equals(M1, expected_M1)); + + verified = client.verify(expected_M2); + assertTrue(verified); /* Test 10: derived from test 11, discovered that password bytes should be in ISO-8859-1*/ - username = "nostradamus"; - password = "$[[//jjiilajfewahug43a89y¿"; - a = "800f0819"; - salt = "cfb9ae3ec5433076"; - expected_A = trim(new BigInteger("2ab09ee2fa01058f2f72fd2142b129f2ec26313801052889bcc4af57ee2e4d5b92c90cdfd6ecd660e82c635b2a091ba1b164e5b371c911ce0c4e69686baa120c58e2e0af84b2adc10da6cdfb0b579a1685032c57fd6ed1306d9713a562eddf5c833725042e825fa1abc7017f74760cb53d8c755ffe628c510022c296d1cd3584", 16).toByteArray()); - x_string = "9736a5e386a18f35bb08cac0f7c70bdbe120f2efe019874d0eb23b85b1955858"; - expected_x = trim(new BigInteger(x_string, 16).toByteArray()); - assertEquals(new BigInteger(1, expected_x).toString(16), x_string); - B = "2d19fe17dca1bda01044a0f406547895c32a10df2b0e69676de911273a8685d294763c4d16b3663f722b8980126e2c659efd33ffc6435a9594a2539e726c48e365893b3374670bd1958c13f55c2defa8ea9c0f9ba1345a5dca0e78debba434c8b755353d066d42bc5dfe0403fdcacfe5efd25c685f883ee6766c710b775c50f2"; - expected_M1 = trim(new BigInteger("a33feada1771c6f53e9343f5b9e69d51d4f15043c95fb663b6dd5b1c7af6f66b", 16).toByteArray()); - expected_M2 = trim(new BigInteger("9e99f9adfbfaa7add3626ed6e6aea94c9fa60dab6b8d56ad0cc950548f577d32", 16).toByteArray()); - - a_byte = new BigInteger(a, 16).toByteArray(); - client = new LeapSRPSession(username, password, a_byte); - - x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); - assertTrue(Arrays.equals(x, expected_x)); - assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); - - A = client.exponential(); - assertTrue(Arrays.equals(A, expected_A)); - - M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); - - assertTrue(Arrays.equals(M1, expected_M1)); - - verified = client.verify(expected_M2); - assertTrue(verified); + username = "nostradamus"; + password = "$[[//jjiilajfewahug43a89y¿"; + a = "800f0819"; + salt = "cfb9ae3ec5433076"; + expected_A = trim(new BigInteger("2ab09ee2fa01058f2f72fd2142b129f2ec26313801052889bcc4af57ee2e4d5b92c90cdfd6ecd660e82c635b2a091ba1b164e5b371c911ce0c4e69686baa120c58e2e0af84b2adc10da6cdfb0b579a1685032c57fd6ed1306d9713a562eddf5c833725042e825fa1abc7017f74760cb53d8c755ffe628c510022c296d1cd3584", 16).toByteArray()); + x_string = "9736a5e386a18f35bb08cac0f7c70bdbe120f2efe019874d0eb23b85b1955858"; + expected_x = trim(new BigInteger(x_string, 16).toByteArray()); + assertEquals(new BigInteger(1, expected_x).toString(16), x_string); + B = "2d19fe17dca1bda01044a0f406547895c32a10df2b0e69676de911273a8685d294763c4d16b3663f722b8980126e2c659efd33ffc6435a9594a2539e726c48e365893b3374670bd1958c13f55c2defa8ea9c0f9ba1345a5dca0e78debba434c8b755353d066d42bc5dfe0403fdcacfe5efd25c685f883ee6766c710b775c50f2"; + expected_M1 = trim(new BigInteger("a33feada1771c6f53e9343f5b9e69d51d4f15043c95fb663b6dd5b1c7af6f66b", 16).toByteArray()); + expected_M2 = trim(new BigInteger("9e99f9adfbfaa7add3626ed6e6aea94c9fa60dab6b8d56ad0cc950548f577d32", 16).toByteArray()); + + a_byte = new BigInteger(a, 16).toByteArray(); + client = new LeapSRPSession(username, password, a_byte); + + x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); + assertTrue(Arrays.equals(x, expected_x)); + assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); + + A = client.exponential(); + assertTrue(Arrays.equals(A, expected_A)); + + M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); + + assertTrue(Arrays.equals(M1, expected_M1)); + + verified = client.verify(expected_M2); + assertTrue(verified); /* Test 11: username and password failing in localhost testProviderAPI*/ - username = "nostradamus"; - password = "$[['//\"jjiilajfewahug43a89y¿"; - a = "5bfbc968"; - salt = "1bcae1065951bbf5"; - expected_A = trim(new BigInteger("7a74c254d46dd6010a7090e574817a03f32ba13f98ed3c695d96f09c9d334e591771541400e68b6d27a19e734baccf3965ca79c0294ffbf553716b41fbca627c7cd3ea4a0d1c640c22411881696f59ad7ed8ce6ef7010e43f57fb3858aa4c3479dd41e4073afadb6a516c41f649b8cf30dea6366efa711c5106c83ea71b00da4", 16).toByteArray()); - x_string = "9834210874c883db35785ee6648079e13d22450c472d6469192ea775ff50c646"; - expected_x = trim(new BigInteger(x_string, 16).toByteArray()); - assertEquals(new BigInteger(1, expected_x).toString(16), x_string); - B = "285b00c034da5676dd8938ce6a7b717968fef2e5f479ecca6d95828a6ce809dd37893752c956245b5d13315987c50e57cc68aa4f770ff9ce977ddfd65052f278b90545286cf32b3d18307140514e0fe2269fc0437fb16104358f6fa127dc97281a017582759644862d736f48025f2b35cb1662067c11f2fcf0753e2f72c9e028"; - expected_M1 = trim(new BigInteger("fedbaff9d9a19efc4eea949b045297a6a3121cf371e2acdda85a2a1ca61c929d", 16).toByteArray()); - expected_M2 = trim(new BigInteger("ffccafa0febc1771a428082b30b7ce409856de4581c7d7d986f5b80015aba0d3", 16).toByteArray()); - - a_byte = new BigInteger(a, 16).toByteArray(); - client = new LeapSRPSession(username, password, a_byte); - - x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); - assertTrue(Arrays.equals(x, expected_x)); - assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); - - A = client.exponential(); - assertTrue(Arrays.equals(A, expected_A)); - - M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); - - assertTrue(Arrays.equals(M1, expected_M1)); - - verified = client.verify(expected_M2); - assertTrue(verified); - } - - public void testSignUpMath() throws NoSuchAlgorithmException{ - String username = "parmegvtest29"; - String password = "holahola2"; - byte[] salt = new BigInteger("67e8348d1500d26c", 16).toByteArray(); - - LeapSRPSession client = new LeapSRPSession(username, password); - - String expected_v = "12bea84e588ffa2f8fc5ae47cb5e751a8f2d9e8125268ad9ab483eff83f98cb08484350eb478bee582b8b72363ff8e7b12e9f332e86f7a0bd77689927c609d275471c6ad2cff8b1e7bbfc3664169c3b7bccb0b974154c1f1656b64274568015ca1b849c9d9890ae4437ed686341b432340809b81c30727ed2aadea8bdec6d101"; - - assertEquals(expected_v, client.calculateV(username, password, salt).toString(16)); + username = "nostradamus"; + password = "$[['//\"jjiilajfewahug43a89y¿"; + a = "5bfbc968"; + salt = "1bcae1065951bbf5"; + expected_A = trim(new BigInteger("7a74c254d46dd6010a7090e574817a03f32ba13f98ed3c695d96f09c9d334e591771541400e68b6d27a19e734baccf3965ca79c0294ffbf553716b41fbca627c7cd3ea4a0d1c640c22411881696f59ad7ed8ce6ef7010e43f57fb3858aa4c3479dd41e4073afadb6a516c41f649b8cf30dea6366efa711c5106c83ea71b00da4", 16).toByteArray()); + x_string = "9834210874c883db35785ee6648079e13d22450c472d6469192ea775ff50c646"; + expected_x = trim(new BigInteger(x_string, 16).toByteArray()); + assertEquals(new BigInteger(1, expected_x).toString(16), x_string); + B = "285b00c034da5676dd8938ce6a7b717968fef2e5f479ecca6d95828a6ce809dd37893752c956245b5d13315987c50e57cc68aa4f770ff9ce977ddfd65052f278b90545286cf32b3d18307140514e0fe2269fc0437fb16104358f6fa127dc97281a017582759644862d736f48025f2b35cb1662067c11f2fcf0753e2f72c9e028"; + expected_M1 = trim(new BigInteger("fedbaff9d9a19efc4eea949b045297a6a3121cf371e2acdda85a2a1ca61c929d", 16).toByteArray()); + expected_M2 = trim(new BigInteger("ffccafa0febc1771a428082b30b7ce409856de4581c7d7d986f5b80015aba0d3", 16).toByteArray()); + + a_byte = new BigInteger(a, 16).toByteArray(); + client = new LeapSRPSession(username, password, a_byte); + + x = client.calculatePasswordHash(username, password, trim(new BigInteger(salt, 16).toByteArray())); + assertTrue(Arrays.equals(x, expected_x)); + assertEquals(new BigInteger(1, expected_x).toString(16), new BigInteger(1, x).toString(16)); + + A = client.exponential(); + assertTrue(Arrays.equals(A, expected_A)); + + M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray()); + + assertTrue(Arrays.equals(M1, expected_M1)); + + verified = client.verify(expected_M2); + assertTrue(verified); + } + + public void testSignUpMath() throws NoSuchAlgorithmException { + String username = "parmegvtest29"; + String password = "holahola2"; + byte[] salt = new BigInteger("67e8348d1500d26c", 16).toByteArray(); + + LeapSRPSession client = new LeapSRPSession(username, password); + + String expected_v = "12bea84e588ffa2f8fc5ae47cb5e751a8f2d9e8125268ad9ab483eff83f98cb08484350eb478bee582b8b72363ff8e7b12e9f332e86f7a0bd77689927c609d275471c6ad2cff8b1e7bbfc3664169c3b7bccb0b974154c1f1656b64274568015ca1b849c9d9890ae4437ed686341b432340809b81c30727ed2aadea8bdec6d101"; + + assertEquals(expected_v, client.calculateV(username, password, salt).toString(16)); + } + + public byte[] trim(byte[] in) { + if (in.length == 0 || in[0] != 0) + return in; + + int len = in.length; + int i = 1; + while (in[i] == 0 && i < len) + ++i; + byte[] ret = new byte[len - i]; + System.arraycopy(in, i, ret, 0, len - i); + return ret; } - - public byte[] trim(byte[] in) { - if(in.length == 0 || in[0] != 0) - return in; - - int len = in.length; - int i = 1; - while(in[i] == 0 && i < len) - ++i; - byte[] ret = new byte[len - i]; - System.arraycopy(in, i, ret, 0, len - i); - return ret; - } } diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java index cd1d6c3b..672607be 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java @@ -56,11 +56,11 @@ public class testVpnCertificateValidator extends InstrumentationTestCase { } private void setTime(int year, int month, int day) { - shellCommand("adb shell chmod 666 /dev/alarm"); - Calendar c = Calendar.getInstance(); - c.set(year, month, day, 12, 00, 00); - SystemClock.setCurrentTimeMillis(c.getTimeInMillis()); - shellCommand("adb shell chmod 664 /dev/alarm"); + shellCommand("adb shell chmod 666 /dev/alarm"); + Calendar c = Calendar.getInstance(); + c.set(year, month, day, 12, 00, 00); + SystemClock.setCurrentTimeMillis(c.getTimeInMillis()); + shellCommand("adb shell chmod 664 /dev/alarm"); } private int shellCommand(String command) { -- cgit v1.2.3