summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/androidTest/java')
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java94
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java31
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java26
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/Screenshot.java54
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java127
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestCalendarProvider.java26
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestConstants.java26
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestDashboardIntegration.java60
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java81
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestEipFragment.java73
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java161
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestLeapSRPSession.java629
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestProviderListActivity.java114
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestUserStatusFragment.java34
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java86
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java83
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java137
17 files changed, 127 insertions, 1715 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java
deleted file mode 100644
index e187d424..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import android.content.Context;
-import android.graphics.Rect;
-import android.test.ActivityInstrumentationTestCase2;
-import android.view.View;
-
-import com.robotium.solo.Solo;
-
-import se.leap.bitmaskclient.ProviderListActivity;
-import se.leap.bitmaskclient.Dashboard;
-import se.leap.bitmaskclient.R;
-
-public abstract class BaseTestDashboardFragment extends ActivityInstrumentationTestCase2<Dashboard> {
-
- Solo solo;
- Context context;
- UserStatusTestController user_status_controller;
- VpnTestController vpn_controller;
-
- public BaseTestDashboardFragment() { super(Dashboard.class); }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- context = getInstrumentation().getContext();
- solo = new Solo(getInstrumentation(), getActivity());
- Screenshot.initialize(solo);
- user_status_controller = new UserStatusTestController(solo);
- vpn_controller = new VpnTestController(solo);
- ConnectionManager.setMobileDataEnabled(true, context);
- solo.unlockScreen();
- if (solo.searchText(solo.getString(R.string.configuration_wizard_title))) {
- toDashboardAnonymously("demo.bitmask.net");
- }
- }
-
- void changeProviderAndLogIn(String provider) {
- tapSwitchProvider();
- solo.clickOnText(provider);
- useRegistered();
- }
-
- void tapSwitchProvider() {
- solo.clickOnMenuItem(solo.getString(R.string.switch_provider_menu_option));
- solo.waitForActivity(ProviderListActivity.class);
- }
-
- private void useRegistered() {
- solo.waitForFragmentById(R.id.provider_detail_fragment);
- String text = solo.getString(R.string.signup_or_login_button);
- clickAndWaitForDashboard(text);
- user_status_controller.logIn("parmegvtest10", "holahola2");
- }
-
- private void clickAndWaitForDashboard(String click_text) {
- solo.clickOnButton(click_text);
- assertTrue(solo.waitForActivity(Dashboard.class, 80 * 1000));
- }
-
- static boolean isShownWithinConfinesOfVisibleScreen(View view) {
- Rect scrollBounds = new Rect();
- view.getHitRect(scrollBounds);
- return view.getLocalVisibleRect(scrollBounds);
- }
-
-
- private void toDashboardAnonymously(String provider) {
- selectProvider(provider);
- useAnonymously();
- }
-
- private void useAnonymously() {
- String text = solo.getString(R.string.use_anonymously_button);
- clickAndWaitForDashboard(text);
- }
-
-
- private void selectProvider(String provider) {
- solo.clickOnText(provider);
- Screenshot.setTimeToSleep(1);
- Screenshot.take("Configuring provider");
- waitForProviderDetails();
- }
-
- private void waitForProviderDetails() {
- String text = solo.getString(R.string.provider_details_title);
- assertTrue("Provider details dialog did not appear", solo.waitForText(text, 1, 60*1000));
- Screenshot.take("Provider details");
- }
-
-
-
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java
deleted file mode 100644
index 6fb7d8a9..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java
+++ /dev/null
@@ -1,31 +0,0 @@
-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 e) {
- //e.printStackTrace();
- } catch (IllegalAccessException e) {
- //e.printStackTrace();
- }
- }
- }
- }
-
- static void setWifiEnabled(boolean enabled, Context context) {
- 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
deleted file mode 100644
index 6a4c1ee2..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/FromAssets.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import android.content.*;
-
-import org.json.*;
-
-import java.io.*;
-
-public class FromAssets {
-
- Context context;
-
- 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) {
- result = new String(bytes);
- }
- return result;
- }
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/Screenshot.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/Screenshot.java
deleted file mode 100644
index ade28b73..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/Screenshot.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import com.robotium.solo.*;
-
-import java.text.*;
-import java.util.*;
-
-public class Screenshot {
- private static String default_name = Screenshot.class.getPackage().getName();
- private static DateFormat date_format = DateFormat.getDateTimeInstance();
- private static int DEFAULT_MILLISECONDS_TO_SLEEP = 500;
- private static int milliseconds_to_sleep = 0;
- private static Solo solo;
-
- public static void initialize(Solo solo) {
- Screenshot.solo = solo;
- }
-
- public static void take(String name) {
- solo.takeScreenshot(name.replace(" ", "_") + " " + getTimeStamp());
- }
-
- public static void takeWithSleep(String name) {
- sleepBefore();
- take(name);
- }
-
- public static void take() {
- take(default_name + "_" + getTimeStamp());
- }
-
- public static void takeWithSleep() {
- sleepBefore();
- take();
- }
-
- private static String getTimeStamp() {
- return date_format.format(Calendar.getInstance().getTime()).replace(" ", "_").replace("/", "_").replace(":", "_");
- }
-
- public static void setTimeToSleep(double seconds) {
- long milliseconds_to_sleep = Math.round(seconds * 1000);
- Screenshot.milliseconds_to_sleep = Math.round(milliseconds_to_sleep);
- }
-
- private static void sleepBefore() {
- if(milliseconds_to_sleep == 0)
- solo.sleep(DEFAULT_MILLISECONDS_TO_SLEEP);
- else
- solo.sleep(milliseconds_to_sleep);
- milliseconds_to_sleep = 0;
- }
-}
-
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java
new file mode 100644
index 00000000..c7c6a86f
--- /dev/null
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java
@@ -0,0 +1,127 @@
+package se.leap.bitmaskclient.test;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.espresso.contrib.DrawerActions;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.IOException;
+
+import se.leap.bitmaskclient.MainActivity;
+import se.leap.bitmaskclient.Provider;
+import se.leap.bitmaskclient.testutils.TestSetupHelper;
+
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
+import static android.support.test.espresso.Espresso.onData;
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.action.ViewActions.click;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.contrib.DrawerMatchers.isClosed;
+import static android.support.test.espresso.contrib.DrawerMatchers.isOpen;
+import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static android.support.test.espresso.matcher.ViewMatchers.withId;
+import static org.hamcrest.Matchers.anything;
+import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
+import static se.leap.bitmaskclient.MainActivity.ACTION_SHOW_VPN_FRAGMENT;
+import static se.leap.bitmaskclient.R.id.aboutLayout;
+import static se.leap.bitmaskclient.R.id.accountList;
+import static se.leap.bitmaskclient.R.id.configuration_wizard_layout;
+import static se.leap.bitmaskclient.R.id.drawer_layout;
+import static se.leap.bitmaskclient.R.id.eipServiceFragment;
+import static se.leap.bitmaskclient.R.id.log_layout;
+import static se.leap.bitmaskclient.R.id.settingsList;
+
+/**
+ * Created by cyberta on 19.01.18.
+ */
+
+@RunWith(AndroidJUnit4.class)
+public class StartActivityDrawerTest {
+
+ Intent intent;
+ SharedPreferences preferences;
+ SharedPreferences.Editor preferencesEditor;
+
+ @Rule
+ public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
+ MainActivity.class,
+ true,
+ false); // Activity is not launched immediately
+
+ @Before
+ public void setUp() throws IOException {
+ intent = new Intent(ACTION_SHOW_VPN_FRAGMENT);
+ Context context = getInstrumentation().getTargetContext();
+
+ preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
+ preferencesEditor = preferences.edit();
+ preferencesEditor.putString(Provider.KEY, TestSetupHelper.getInputAsString(InstrumentationRegistry.getContext().getAssets().open("riseup.net.json")))
+ .putString(Provider.CA_CERT, TestSetupHelper.getInputAsString(InstrumentationRegistry.getContext().getAssets().open("riseup.net.pem")))
+ .commit();
+
+ }
+
+
+ @Test
+ public void testDisplayDrawer_isOpenUntilUserManuallyOpendDrawerOnce() {
+ preferencesEditor.putBoolean("navigation_drawer_learned", false).commit();
+ mActivityRule.launchActivity(intent);
+ onView(withId(drawer_layout)).check(matches(isOpen()));
+ onView(withId(drawer_layout)).perform(DrawerActions.close());
+ mActivityRule.finishActivity();
+
+ mActivityRule.launchActivity(intent);
+ onView(withId(drawer_layout)).check(matches(isOpen()));
+ onView(withId(drawer_layout)).perform(DrawerActions.close());
+ onView(withId(drawer_layout)).perform(DrawerActions.open());
+ mActivityRule.finishActivity();
+
+ mActivityRule.launchActivity(intent);
+ onView(withId(drawer_layout)).check(matches(isClosed()));
+ }
+
+ @Test
+ public void testClickProviderName_closeDrawerAndShowEipFragment() {
+ preferencesEditor.putBoolean("navigation_drawer_learned", false).commit();
+ mActivityRule.launchActivity(intent);
+
+ onData(anything()).inAdapterView(withId(accountList)).atPosition(0).perform(click());
+ onView(withId(drawer_layout)).check(matches(isClosed()));
+ onView(withId(eipServiceFragment)).check(matches(isDisplayed()));
+ }
+
+ @Test
+ public void testClickSwitchProvider_closeDrawerAndShowProviderListView() {
+ preferencesEditor.putBoolean("navigation_drawer_learned", false).commit();
+ mActivityRule.launchActivity(intent);
+
+ onData(anything()).inAdapterView(withId(settingsList)).atPosition(0).perform(click());
+ onView(withId(configuration_wizard_layout)).check(matches(isDisplayed()));
+ }
+
+ @Test
+ public void testClickLog_closeDrawerAndShowLogFragment() {
+ preferencesEditor.putBoolean("navigation_drawer_learned", false).commit();
+ mActivityRule.launchActivity(intent);
+
+ onData(anything()).inAdapterView(withId(settingsList)).atPosition(1).perform(click());
+ onView(withId(log_layout)).check(matches(isDisplayed()));
+ }
+
+ @Test
+ public void testClickAbout_closeDrawerAndShowAboutFragment() {
+ preferencesEditor.putBoolean("navigation_drawer_learned", false).commit();
+ mActivityRule.launchActivity(intent);
+
+ onData(anything()).inAdapterView(withId(settingsList)).atPosition(2).perform(click());
+ onView(withId(aboutLayout)).check(matches(isDisplayed()));
+ }
+}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestCalendarProvider.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestCalendarProvider.java
deleted file mode 100644
index 82ea8b59..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestCalendarProvider.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import java.util.Calendar;
-
-import se.leap.bitmaskclient.eip.CalendarProviderInterface;
-
-/**
- * Created by cyberta on 13.09.17.
- */
-
-class TestCalendarProvider implements CalendarProviderInterface {
-
- private long currentTimeInMillis = 0;
-
- public TestCalendarProvider(long currentTimeInMillis) {
- this.currentTimeInMillis = currentTimeInMillis;
- }
-
- @Override
- public Calendar getCalendar() {
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(currentTimeInMillis);
- return calendar;
- }
-
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConstants.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConstants.java
deleted file mode 100644
index 6b4cdfb1..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConstants.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright (c) 2013, 2014, 2015 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package se.leap.bitmaskclient.test;
-
-/**
- * @author parmegv
- */
-public class TestConstants {
- public final static String EIP_DEFINITION_FILE = "eip-service-test.json";
- public final static String SECRETS_FILE = "secrets.json";
- public final static String GATEWAY_FILE = "gateway.json";
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestDashboardIntegration.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestDashboardIntegration.java
deleted file mode 100644
index ad2b4a00..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestDashboardIntegration.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import java.io.*;
-
-import se.leap.bitmaskclient.R;
-
-public class TestDashboardIntegration extends BaseTestDashboardFragment {
-
- @Override
- protected void tearDown() throws Exception {
- solo.finishOpenedActivities();
- }
-
- public void testSwitchProvider() {
- tapSwitchProvider();
- solo.goBack();
- }
-
- public void testShowAbout() {
- showAbout();
- solo.goBack();
- showAbout();
- solo.goBack();
- }
-
- private void showAbout() {
- clickAbout();
- String text_unique_to_about = solo.getString(R.string.repository_url_text);
- solo.waitForText(text_unique_to_about);
- }
-
- private void clickAbout() {
- String menu_item = solo.getString(R.string.about);
- solo.clickOnMenuItem(menu_item);
- }
-
- private void turnNetworkOff() {
- ConnectionManager.setMobileDataEnabled(false, context);
- if (!solo.waitForText(getActivity().getString(R.string.eip_state_not_connected), 1, 15 * 1000))
- fail();
- }
-
- private void restartAdbServer() {
- runAdbCommand("kill-server");
- runAdbCommand("start-server");
- }
-
- /*public void testReboot() {
- runAdbCommand("shell am broadcast -a android.intent.action.BOOT_COMPLETED");
- }*/
-
- private void runAdbCommand(String adb_command) {
- try {
- String command = "adb " + adb_command;
- Runtime.getRuntime().exec(command).waitFor();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java
deleted file mode 100644
index 4c215360..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Copyright (c) 2013, 2014, 2015 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-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.eip.EIP;
-
-import static se.leap.bitmaskclient.Constants.EIP_ACTION_CHECK_CERT_VALIDITY;
-import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE;
-import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
-
-/**
- * @author parmegv
- */
-public class TestEIP extends ServiceTestCase<EIP> {
-
- private Context context;
- private Intent intent;
- private SharedPreferences preferences;
-
- public TestEIP(Class<EIP> activityClass) {
- super(activityClass);
- context = getSystemContext();
- intent = new Intent(context, EIP.class);
- preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @MediumTest
- private void testCheckCertValidity() {
- testEmptyCertificate();
- testExpiredCertificate();
- // Wait for the service to start
- // Check result is OK.
- }
-
- private void testEmptyCertificate() {
- preferences.edit().putString(PROVIDER_VPN_CERTIFICATE, "").apply();
- startService(EIP_ACTION_CHECK_CERT_VALIDITY);
- }
-
- private void testExpiredCertificate() {
- String expired_certificate = "expired certificate";
- preferences.edit().putString(PROVIDER_VPN_CERTIFICATE, expired_certificate).apply();
- startService(EIP_ACTION_CHECK_CERT_VALIDITY);
- }
-
- private void startService(String action) {
- intent.setAction(action);
- startService(intent);
- }
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEipFragment.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEipFragment.java
deleted file mode 100644
index 4227f19a..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEipFragment.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-public class TestEipFragment extends BaseTestDashboardFragment {
-
- /**
- * This test will fail if Android does not trust VPN connection.
- * I cannot automate that dialog.
- */
- public void testOnOffOpenVpn() {
- vpn_controller.clickVpnButton();
- Screenshot.setTimeToSleep(2);
- Screenshot.takeWithSleep("Turning VPN on");
- vpn_controller.turningEipOn();
- Screenshot.setTimeToSleep(0.5);
- Screenshot.takeWithSleep("VPN turned on");
-
- vpn_controller.clickVpnButton();
- vpn_controller.turningEipOff();
- Screenshot.take("VPN turned off");
-
- vpn_controller.clickVpnButton();
- vpn_controller.turningEipOn();
-
- vpn_controller.clickVpnButton();
- vpn_controller.turningEipOff();
-
- }
-
- /**
- * Run only if the trust this app dialog has not been checked.
- * You must pay attention to the screen, because you need to cancel de dialog twice (block vpn and normal vpn)
- */
- public void testOnFailed() {
- /* TODO Do not rely on the Android's vpn trust dialog
- vpn_controller.clickVpnButton();
- assertTrue("Have you checked the trust vpn dialog?", solo.waitForActivity(LogWindow.class));
- solo.goBack();
- assertTrue(vpn_controller.iconShowsDisconnected());
- */
- }
-
- public void testVpnEveryProvider() {
- checkDemoBitmaskNet();
- checkRiseupNet();
- checkCalyxNet();
- }
-
- private void checkDemoBitmaskNet() {
- checkProvider("demo.bitmask.net");
- }
-
- private void checkRiseupNet() {
- checkProvider("riseup.net");
- }
-
- private void checkCalyxNet() {
- checkProvider("calyx.net");
- }
-
- private void checkProvider(String provider) {
- changeProviderAndLogIn(provider);
- vpn_controller.sleepSeconds(1);
- vpn_controller.turnVpnOnAndOff();
- vpn_controller.sleepSeconds(1);
- }
-
- public void testVpnIconIsDisplayed() {
- assertTrue(isShownWithinConfinesOfVisibleScreen(vpn_controller.getVpnWholeIcon()));
- }
- public void testVpnButtonIsDisplayed() {
- assertTrue(isShownWithinConfinesOfVisibleScreen(vpn_controller.getVpnButton()));
- }
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java
deleted file mode 100644
index 02c521be..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Copyright (c) 2013, 2014, 2015 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package se.leap.bitmaskclient.test;
-
-import android.app.*;
-import android.content.*;
-import android.test.*;
-
-import org.json.*;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-import se.leap.bitmaskclient.eip.*;
-
-import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
-
-/**
- * @author parmegv
- */
-public class TestGatewaysManager extends InstrumentationTestCase {
-
- GatewaysManager gateways_manager;
- Gateway gateway;
- JSONObject eip_definition;
-
- FromAssets assets;
-
- Context context;
- SharedPreferences preferences;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- context = getInstrumentation().getContext();
- assets = new FromAssets(context);
- mockGatewaysManager();
- mockRealGateway();
- }
-
- public void testFromEipServiceJson() {
- gateways_manager.fromEipServiceJson(eip_definition);
- assertEquals(2, gateways_manager.size());
- gateways_manager.addFromString(gateway.toString());
- assertEquals(2, gateways_manager.size());
- }
-
- public void testOrderOfGateways_UDP_TCP() {
- String[] protocolsInOrder = {"udp", "tcp"};
- manipulateSupportedProtocols(protocolsInOrder);
- gateways_manager.fromEipServiceJson(eip_definition);
- gateways_manager.addFromString(gateway.toString());
- assertTrue(gateways_manager.select().toString().contains("[\"udp\",\"tcp\"]"));
- assertFalse(gateways_manager.select().toString().contains("[\"tcp\",\"udp\"]"));
- }
-
- public void testOrderOfGateways_TCP_UDP() {
- String[] protocolsInOrder = {"tcp", "udp"};
- manipulateSupportedProtocols(protocolsInOrder);
- gateways_manager.fromEipServiceJson(eip_definition);
- gateways_manager.addFromString(gateway.toString());
- assertFalse(gateways_manager.select().toString().contains("[\"udp\",\"tcp\"]"));
- assertTrue(gateways_manager.select().toString().contains("[\"tcp\",\"udp\"]"));
- }
-
- public void testAddFromString() {
- gateways_manager.addFromString("");
- assertEquals(0, gateways_manager.size());
- gateways_manager.addFromString(gateway.toString());
- assertEquals(1, gateways_manager.size());
- }
-
- public void testRemoveDuplicate() {
- gateways_manager.addFromString(gateway.toString());
- assertEquals(1, gateways_manager.size());
-
- mockArtificialGateway();
- gateways_manager.addFromString(gateway.toString());
- assertEquals(1, gateways_manager.size());
- }
-
- public void testToString() {
- assertEquals("[]", gateways_manager.toString());
-
- gateways_manager.addFromString(gateway.toString());
- assertEquals("[" + gateway.toString() + "]", gateways_manager.toString());
- }
-
- public void testIsEmpty() {
- assertTrue(gateways_manager.isEmpty());
- gateways_manager.addFromString("");
- assertTrue(gateways_manager.isEmpty());
- gateways_manager.addFromString(gateway.toString());
- assertFalse(gateways_manager.isEmpty());
- }
-
- private void mockGatewaysManager() {
- context = getInstrumentation().getContext();
- preferences = context.getSharedPreferences(SHARED_PREFERENCES, Activity.MODE_PRIVATE);
- gateways_manager = new GatewaysManager(context, preferences);
- }
-
- private void mockRealGateway() {
- try {
- eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE));
- JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE));
- JSONObject gateway = new JSONObject(assets.toString(TestConstants.GATEWAY_FILE));
- this.gateway = new Gateway(eip_definition, secrets, gateway);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void manipulateSupportedProtocols(String[] protocols) {
- try {
- eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE));
- JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE));
- JSONArray protocolJsonArray = new JSONArray(Arrays.asList(protocols));
- JSONArray gateways = eip_definition.getJSONArray("gateways");
- for (int i = 0; i < gateways.length(); i++) {
- JSONObject gatewayJson = gateways.getJSONObject(i);
- JSONObject capabilitiesJson = gatewayJson.getJSONObject("capabilities");
- capabilitiesJson.put("protocols", protocolJsonArray);
- gatewayJson.put("protocols", protocolJsonArray);
- }
- this.gateway = new Gateway(eip_definition, secrets, gateways.getJSONObject(0));
- } catch (JSONException e) {
- e.printStackTrace();
- assertFalse(true);
- } catch (IOException e) {
- e.printStackTrace();
- assertFalse(true);
- }
-
- }
-
- private void mockArtificialGateway() {
- try {
- eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE));
- JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE).replace("6u6", "7u7"));
- JSONObject gateway = new JSONObject(assets.toString(TestConstants.GATEWAY_FILE));
- this.gateway = new Gateway(eip_definition, secrets, gateway);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestLeapSRPSession.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestLeapSRPSession.java
deleted file mode 100644
index 8d0df59b..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestLeapSRPSession.java
+++ /dev/null
@@ -1,629 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import java.io.*;
-import java.math.*;
-import java.security.*;
-import java.util.*;
-
-import android.test.suitebuilder.annotation.*;
-
-import se.leap.bitmaskclient.*;
-
-import junit.framework.*;
-
-public class TestLeapSRPSession extends TestCase {
-
- public TestLeapSRPSession(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testExponential() {
- byte[] expected_A;
- byte[] a_byte;
- LeapSRPSession client;
-
- /* Test 1: abytes = 4 */
- expected_A = new BigInteger("44eba0239ddfcc5a488d208df32a89eb00e93e6576b22ba2e4410085a413cf64e9c2f08ebc36a788a0761391150ad4a0507ca43f9ca659e2734f0457a85358c0bb39fa87183c9d3f9f8a3b148dab6303a4e796294f3e956472ba0e2ea5697382acd93c8b8f1b3a7a9d8517eebffd6301bfc8de7f7b701f0878a71faae1e25ad4", 16).toByteArray();
- String username = "username",
- password = "password",
- salt = "64c3289d04a6ecad",
- a = "3565fdc2";
- a_byte = new BigInteger(a, 16).toByteArray();
- client = new LeapSRPSession(username, password, a_byte);
-
- byte[] A = client.exponential();
-
- assertTrue(Arrays.equals(A, expected_A));
-
- /* Test 1: abytes = 5 */
- a = "67c152a3";
- expected_A = new BigInteger("11acfacc08178d48f95c0e69adb11f6d144dd0980ee6e44b391347592e3bd5e9cb841d243b3d9ac2adb25b367a2558e8829b22dcef96c0934378412383ccf95141c3cb5f17ada20f53a0225f56a07f2b0c0469ed6bbad3646f7b71bdd4bedf5cc6fac244b26d3195d8f55877ff94a925b0c0c8f7273eca733c0355b38360442e", 16).toByteArray();
-
- a_byte = new BigInteger(a, 16).toByteArray();
- client = new LeapSRPSession(username, password, a_byte);
-
- A = client.exponential();
-
- assertTrue(Arrays.equals(A, expected_A));
- }
-
- public void testResponse() throws NoSuchAlgorithmException {
- /* Test 1: with intermediate checks */
- byte[] expected_A = trim(new BigInteger("884380f70a62193bbe3589c4e1dbdc4467b6b5a1b4486e4b779023506fc1f885ae26fa4a5d817b3f38a35f3487b147b82d4bd0069faa64fdc845f7494a78251709e212698e42ced44b0f3849adc73f467afcb26983bd13bdc38906b178003373ddd0ac1d38ce8a39ffa3a7795787207a129a784f4b65ce0b302eb1bcf4045883", 16).toByteArray());
- byte[] expected_x = new BigInteger("4cb937fd74ee3bb53b79a3174d0c07c14131de9c825897cbca52154e74200602", 16).toByteArray();
- byte[] expected_M1 = trim(new BigInteger("e6a8efca2c07ef24e0b69be2d4d4a7e74742a4db7a92228218fec0008f7cc94b", 16).toByteArray());
- String username = "username",
- password = "password",
- salt = "64c3289d04a6ecad",
- a = "8c911355";
- byte[] a_byte = new BigInteger(a, 16).toByteArray();
- LeapSRPSession client = new LeapSRPSession(username, password, a_byte);
-
- byte[] x = client.calculatePasswordHash(username, password, new BigInteger(salt, 16).toByteArray());
- assertTrue(Arrays.equals(x, expected_x));
-
- byte[] A = client.exponential();
- assertTrue(Arrays.equals(A, expected_A));
-
- String B = "bc745ba25564fc312f44ea09fb663aa6d95867772e412a6a23f1bc24183e54b32f134372c560f4b3fda19ba7a56b0f84fdcdecc22be6fd256639e918e019691c40a39aa5c9631820e42b28da61b8c75b45afae9d77d63ac8f4dda093762be4a890fbd86061dbd7e5e7c03c4dacde769e0f564df00403e449c0535537f1ba7263";
-
- byte[] M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray());
- assertTrue(Arrays.equals(M1, expected_M1));
-
- /* Test 2: no intermediate checks */
- expected_A = trim(new BigInteger("9ffc407afd7e7ecd32a8ea68aa782b0254a7e2197a955b5aa646fc1fc43ff6ef2239f01b7d5b82f152c870d3e69f3321878ca2acda06dd8fb6ce02f41c7ed48061c78697b01cf353f4222311334c707358b6ec067e317527316bfa85b5ec74537e38b5b14c1100d14c96320f385e5b1dcccde07e728c7ef624353167a29ae461", 16).toByteArray());
- expected_M1 = trim(new BigInteger("c3203ec1dd55c96038276456c18c447fb4d2a2f896c73c31d56da1781cae79a8", 16).toByteArray());
- a = "38d5b211";
-
- a_byte = new BigInteger(a, 16).toByteArray();
- client = new LeapSRPSession(username, password, a_byte);
- x = client.calculatePasswordHash(username, password, new BigInteger(salt, 16).toByteArray());
- A = client.exponential();
-
- B = "b8ca7d93dbe2478966ffe025a9f2fb43b9995ce04af9523ea9a3fa4b132136076aa66ead1597c3da23f477ce1cfaf68b5dcc94e146db06cf8391d14a76ce53aab86067b13c93b135d7be6275669b3f51afec6cc41f19e0afca7c3ad5c4d6ee4c09d4b11bcd12e26c727ee56d173b92eea6926e72cc73deebe12dd6f30f44db8a";
- M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray());
-
- assertTrue(Arrays.equals(M1, expected_M1));
-
- /* Test 3: With intermediate values */
- expected_M1 = new BigInteger("4c01f65a9bb00f95e435593083040ae1e59e59800c598b42de821c21f3a35223", 16).toByteArray();
- expected_A = new BigInteger("1bceab3047a6f84495fdd5b4dbe891f0b30f870d7d4e38eaef728f6a7d4e9342d8dae8502fdae4f16b718d2e916a38b16b6def45559a5ebae417a1b115ba6b6a0451c7ff174c3e2507d7d1f18ef646fd065bc9ba165a2a0ae4d6da54f060427178b95b0eff745f5c3f8c4f19ea35addc3ce0daf2aca3328c98bafcf98286d115", 16).toByteArray();
- B = "41a7b384f2f52312fa79b9dc650ae894f543aea49800cf9477fbcf63e39cbfe6d422f7126777d645cdf749276a3ae9eb6dfcfdb887f8f60ac4094a343013fcebbd40e95b3153f403ab7bb21ea1315aa018bab6ab84017fcb084b3870a8bf1cb717b39c9a28177c61ce7d1738379be9d192dd9793b50ebc3afabe5e78b0a4b017";
- a = "36ee80ec";
-
- a_byte = new BigInteger(a, 16).toByteArray();
- client = new LeapSRPSession(username, password, a_byte);
- x = client.calculatePasswordHash(username, password, new BigInteger(salt, 16).toByteArray());
- A = client.exponential();
-
- M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray());
-
- assertTrue(Arrays.equals(M1, expected_M1));
- }
-
- public void testCalculateV() throws NoSuchAlgorithmException {
- String expected_v = "502f3ffddc78b866330550c2c60ebd68427c1793237d770e6390d1f794abd47b6786fa5025728d1ca4ec24cfc7a89808278330099ad66456a7c9c88be570b928f9825ac2ecdee31792335f7fa5fc9a78b692c487aa400c7d5cc5c1f2a3a74634c4afa0159600bbf22bf6dfb1e0d85061e55ce8df6243758066503bcf51c83848cf7184209731f89a90d888934c75798828859babe73c17009bf827723fc1bcd0";
-
- BigInteger k = new BigInteger("bf66c44a428916cad64aa7c679f3fd897ad4c375e9bbb4cbf2f5de241d618ef0", 16);
- BigInteger g = new BigInteger("2", 16);
- BigInteger N = new BigInteger(ConfigHelper.NG_1024, 16);
- BigInteger x = new BigInteger("4cb937fd74ee3bb53b79a3174d0c07c14131de9c825897cbca52154e74200602", 16);
-
- BigInteger v = k.multiply(g.modPow(x, N)); // g^x % N
-
- assertEquals(v.toString(16), expected_v);
- assertTrue(Arrays.equals(v.toByteArray(), new BigInteger(expected_v, 16).toByteArray()));
- }
-
- public void testGetU() throws NoSuchAlgorithmException {
- /* Test 1 */
- String Astr = "46b1d1fe038a617966821bd5bb6af967be1bcd6f54c2db5a474cb80b625870e4616953271501a82198d0c14e72b95cdcfc9ec867027b0389aacb313319d4e81604ccf09ce7841dc333be2e03610ae46ec0c8e06b8e86975e0984cae4d0b61c51f1fe5499a4d4d42460261a3e134f841f2cef4d68a583130ee8d730e0b51a858f";
- String Bstr = "5e1a9ac84b1d9212a0d8f8fe444a34e7da4556a1ef5aebc043ae7276099ccdb305fd7e1c179729e24b484a35c0e33b6a898477590b93e9a4044fc1b8d6bc73db8ac7778f546b25ec3f22e92ab7144e5b974dc58e82a333262063062b6944a2e4393d2a087e4906e6a8cfa0fdfd8a5e5930b7cdb45435cbee7c49dfa1d1216881";
- String ustr = "759c3cfb6bfaccf07eeb8e46fe6ea290291d4d32faca0681830a372983ab0a61";
-
- byte[] Abytes = new BigInteger(Astr, 16).toByteArray();
- byte[] Bbytes = new BigInteger(Bstr, 16).toByteArray();
- byte[] expected_u = new BigInteger(ustr, 16).toByteArray();
-
- MessageDigest u_digest = MessageDigest.getInstance("SHA256");
- u_digest.update(trim(Abytes));
- u_digest.update(trim(Bbytes));
- byte[] u = new BigInteger(1, u_digest.digest()).toByteArray();
-
- assertTrue(Arrays.equals(expected_u, u));
-
- /* Test 2 */
- Astr = "c4013381bdb2fdd901944b9d823360f367c52635b576b9a50d2db77141d357ed391c3ac5fa452c2bbdc35f96bfed21df61627b40aed8f67f21ebf81e5621333f44049d6c9f6ad36464041438350e1f86000a8e3bfb63d4128c18322d2517b0d3ead63fd504a9c8f2156d46e64268110cec5f3ccab54a21559c7ab3ad67fedf90";
- Bstr = "e5d988752e8f265f01b98a1dcdecc4b685bd512e7cd9507f3c29f206c27dac91e027641eed1765c4603bbd7a9aa7fac300ef67dafe611ba2dbe29a32d83d486296f328d38b44c0c211d01d3fe422aac168b6850c87782338969c54594fc87804d4db34910ad4b5452a81027842ac8d8d8288fd44872e4c719ac8fb971d0a33e1";
- ustr = "6510328f913b81ba662e564ee5afb7c395ea27c3c0276fc5ca51f0edecd4baf1";
-
- Abytes = new BigInteger(Astr, 16).toByteArray();
- Bbytes = new BigInteger(Bstr, 16).toByteArray();
- expected_u = new BigInteger(ustr, 16).toByteArray();
- expected_u = trim(expected_u);
-
- u_digest = MessageDigest.getInstance("SHA-256");
- u_digest.update(trim(Abytes));
- u_digest.update(trim(Bbytes));
- u = new BigInteger(1, u_digest.digest()).toByteArray();
- u = trim(u);
-
- assertTrue(Arrays.equals(expected_u, u));
-
- /* Test 3 */
- Astr = "d13973fe4e0e13423cd036caf0912e23a1f9b0c23966f5a5897c8ff17c5cbac8bab7f07d9ac4ee47396a7c68e80ce854c84f243148521277900aaa132a7b93b61e54d742d7f36edb4cdef54bc78cca69ac72653a7ae0fc47ec1e9a84024ea9487a61357e28eddc185e4fe01388e64e6b8f688dd74471d56dd244204522e08483";
- Bstr = "a6701686d9d987a43f06e8497330c8add8febd191a7a975bced0d058eb03ccc6805263349363b2d54ac435b01155dc41c6067287d9b93e3637ab3b7e8bc7d9cf38d9fdbb2ca9ee8ba1946a46cb555cb7dafcc177fcf7a4b0eb1e5db2249949c1fd15e0b7c1b3616f9e2649bdf074ed841efbdc9f29ee8c8bfcedeaed3dc49378";
- ustr = "78414ec80cf44225e7ed386dcf2ceb89837327ccae11b761fc77d48c0307977";
-
- Abytes = new BigInteger(Astr, 16).toByteArray();
- Bbytes = new BigInteger(Bstr, 16).toByteArray();
- expected_u = new BigInteger(ustr, 16).toByteArray();
- expected_u = trim(expected_u);
-
- u_digest = MessageDigest.getInstance("SHA-256");
- u_digest.update(trim(Abytes));
- u_digest.update(trim(Bbytes));
- u = new BigInteger(1, u_digest.digest()).toByteArray();
- u = trim(u);
-
- assertTrue(Arrays.equals(expected_u, u));
-
- /* Test 4 */
- Astr = "ee8bc0cb97dd9c9937759658ff9d791df1dd57b48c5febc2e98af028d0e36eaddf1a3fc555f2bcd6456827e8c7b07ec02a1f365457843bda226bfc1a55c4776879f9df6c916810131ec65a3a4cf473c6a34299d64c91cf26542ea0fc059d24422fc783460c3fafe26bf6f7c24904ae1c5a6421e2f5315030ab007ce8f2c2fd97";
- Bstr = "95ecbd13b28c7f38318fd664ee97d9e853b0d6e9cbff9a3775a3cc5d5077ffc146aec70d9439e75c19a34b67368b8bd7035ba6254e0a260d99b1e253aae2e0d8f4a13e1ed472f3ef0e3086300cd15d059f6be7d7141ee09071b1c5e5d1c83b250a3c8f1a587f8fe59d49aaeb2cfc7e13a5a58bc76cc8baf7f6a647982c67ee49";
- ustr = "e28737c7307c84e4d0866b7cf882f22852a764b109634f77a5eb986a96ffcf9a";
-
- Abytes = new BigInteger(Astr, 16).toByteArray();
- Bbytes = new BigInteger(Bstr, 16).toByteArray();
- expected_u = new BigInteger(ustr, 16).toByteArray();
- expected_u = trim(expected_u);
- assertEquals(new BigInteger(1, expected_u).toString(16), ustr);
-
- u_digest = MessageDigest.getInstance("SHA-256");
- u_digest.update(trim(Abytes));
- u_digest.update(trim(Bbytes));
- u = new BigInteger(1, u_digest.digest()).toByteArray();
- u = trim(u);
-
- assertTrue(Arrays.equals(expected_u, u));
- }
-
- @SmallTest
- public void testCalculatePasswordHash() throws UnsupportedEncodingException, NoSuchAlgorithmException {
- String salt_str = "", username_str = "", password_str = "";
- String expected_inner = "cfb9ae3ec5433076889c4fe5663926e20bf570cc7950a51c889a314fab2f5ed716bde9c1cc91be14",
- expected_x = "9736a5e386a18f35bb08cac0f7c70bdbe120f2efe019874d0eb23b85b1955858";
-
- /* Test 1 */
- salt_str = "cfb9ae3ec5433076";
- username_str = "nostradamus";
- password_str = "$[[//jjiilajfewahug43a89y¿";
- password_str = password_str.replaceAll("\\\\", "\\\\\\\\");
- // Calculate x = H(s | H(U | ':' | password))
- MessageDigest x_digest = MessageDigest.getInstance("SHA-256");
-
- // Try to convert the username to a byte[] using UTF-8
- byte[] user = null;
- byte[] password_bytes = null;
- byte[] colon = {};
-
- String encoding = "UTF-8";
- encoding = "ISO-8859-1";
- user = ConfigHelper.trim(username_str.getBytes(encoding));
- colon = ConfigHelper.trim(":".getBytes(encoding));
- password_bytes = ConfigHelper.trim(password_str.getBytes(encoding));
-
- // Build the hash
- x_digest.update(user);
- x_digest.update(colon);
- x_digest.update(password_bytes);
- byte[] h = x_digest.digest();
- byte[] salt_bytes = ConfigHelper.trim(new BigInteger(salt_str, 16).toByteArray());
-
- x_digest.reset();
- x_digest.update(salt_bytes);
- x_digest.update(h);
- byte[] x_digest_bytes = x_digest.digest();
- assertTrue(new BigInteger(1, x_digest_bytes).toString(16).equalsIgnoreCase(expected_x));
- }
-
- public void testCalculateS() throws NoSuchAlgorithmException {
- String expected_S = "34d71467d0a30c5787e6b4384c7176a724df28f6c1d3b0b7738238621be19080942ca5d4454ab3e5664d42970ea2d42d1188ab246afb1475c481111f30886c79cc99ddd1d711034bc4ac57a0c134fef40470e1ac3386f39abcd1bf9d0cc758a1f38a87b2f7261018cdc6191cd941292c77c320b3c664a9bb1325dd7a2bf62db4";
-
- String B_string = "d390da0991b84e20918764aed9bccf36fc70863f08a1d3fa0aecd9610d8c40d1895afaf3aa9b4582fb5bc673037dfc1bf0ca7d3d190a807dec563fe57d596b3551ec8a6461e0621b77fabfaa29234187063e715e2706522c65f35d89f3914a7cdf40ddd240ef3d22b5534469cf6b3b31e158f817dcf5b6b44b0914d4787d027e";
- String A_string = "c6385e56b9cb8987df3c58ffe6c47bfcd9f9d52f02b68048d72135a8522a0919b41683e3c732a0874e0555b8f288fa067842b1c40a56f1a7d910ad125e71238cb14ba47838f881cabf735d5414f4fcdd6855943621c271c5f013753d439fb124674c79e30d849e9178c780f7c25aded12f053ae41be68289787caf7c3cbb07a4";
- String a_string = "fc1c2d8d";
-
- BigInteger A = new BigInteger(A_string, 16);
- byte[] Bbytes = new BigInteger(B_string, 16).toByteArray();
- BigInteger a = new BigInteger(a_string, 16);
- BigInteger g = ConfigHelper.G;
- BigInteger N = new BigInteger(ConfigHelper.NG_1024, 16);
- BigInteger k = new BigInteger("bf66c44a428916cad64aa7c679f3fd897ad4c375e9bbb4cbf2f5de241d618ef0", 16);
- BigInteger x = new BigInteger("4cb937fd74ee3bb53b79a3174d0c07c14131de9c825897cbca52154e74200602", 16);
-
- /* GetU */
- MessageDigest u_digest = MessageDigest.getInstance("SHA256");
- u_digest.update(trim(A.toByteArray()));
- u_digest.update(trim(Bbytes));
- byte[] ub = new BigInteger(1, u_digest.digest()).toByteArray();
-
- BigInteger v = k.multiply(g.modPow(x, N)); // g^x % N
- String expected_v = "502f3ffddc78b866330550c2c60ebd68427c1793237d770e6390d1f794abd47b6786fa5025728d1ca4ec24cfc7a89808278330099ad66456a7c9c88be570b928f9825ac2ecdee31792335f7fa5fc9a78b692c487aa400c7d5cc5c1f2a3a74634c4afa0159600bbf22bf6dfb1e0d85061e55ce8df6243758066503bcf51c83848cf7184209731f89a90d888934c75798828859babe73c17009bf827723fc1bcd0";
- String v_string = v.toString(16);
-
- BigInteger B = new BigInteger(1, Bbytes);
- BigInteger u = new BigInteger(1, ub);
- String expected_u_string = "2d36f816df24da7b904c904a7e2a2500511df118ced26bda92a63aca792c93b";
- String u_string = u.toString(16);
-
- BigInteger B_v = B.subtract(v);
- BigInteger a_ux = a.add(u.multiply(x));
- byte[] a_ux_byte = a_ux.toByteArray();
- String expected_a_aux_string = "d8d0843a60d471ab46a761b775f8fd28bbbd8affbc704424c79b822ac36b1177925404db910072737df3c5083cf20ebd2f08e1381d80d91e4f6fc99f592203";
- byte[] expected_a_aux_byte = new BigInteger(expected_a_aux_string, 16).toByteArray();
-
- BigInteger S = B_v.modPow(a_ux, N);
-
- byte[] expected_S_bytes = new BigInteger(expected_S, 16).toByteArray();
- byte[] S_bytes = S.toByteArray();
- assertTrue(Arrays.equals(S_bytes, expected_S_bytes));
- assertEquals(S.toString(16), expected_S);
- }
-
- public void testXor() throws Exception {
- String expected_xor_string = "928ade491bc87bba9eb578701d44d30ed9080e60e542ba0d3b9c20ded9f592bf";
- byte[] expected_xor = new BigInteger(expected_xor_string, 16).toByteArray();
-
- byte[] nbytes = trim(new BigInteger(ConfigHelper.NG_1024, 16).toByteArray());
- byte[] gbytes = trim(ConfigHelper.G.toByteArray());
-
- byte[] ndigest = trim(MessageDigest.getInstance("SHA-256").digest(nbytes));
- byte[] gdigest = MessageDigest.getInstance("SHA-256").digest(gbytes);
-
- BigInteger ndigest_bigInteger = new BigInteger(1, ndigest);
- String expected_ndigest_string = "494b6a801b379f37c9ee25d5db7cd70ffcfe53d01b7c9e4470eaca46bda24b39";
- String ndigest_string = ndigest_bigInteger.toString(16);
- assertEquals(ndigest_string, expected_ndigest_string);
-
- BigInteger gdigest_bigInteger = new BigInteger(1, gdigest);
- String xor_string = ndigest_bigInteger.xor(gdigest_bigInteger).toString(16);
-
- byte[] xor = new BigInteger(xor_string, 16).toByteArray();
-
- assertTrue(Arrays.equals(expected_xor, xor));
- }
-
- public void testVerify() throws NoSuchAlgorithmException {
- byte[] expected_A = trim(new BigInteger("884380f70a62193bbe3589c4e1dbdc4467b6b5a1b4486e4b779023506fc1f885ae26fa4a5d817b3f38a35f3487b147b82d4bd0069faa64fdc845f7494a78251709e212698e42ced44b0f3849adc73f467afcb26983bd13bdc38906b178003373ddd0ac1d38ce8a39ffa3a7795787207a129a784f4b65ce0b302eb1bcf4045883", 16).toByteArray());
- byte[] expected_x = new BigInteger("4cb937fd74ee3bb53b79a3174d0c07c14131de9c825897cbca52154e74200602", 16).toByteArray();
- byte[] expected_M1 = trim(new BigInteger("e6a8efca2c07ef24e0b69be2d4d4a7e74742a4db7a92228218fec0008f7cc94b", 16).toByteArray());
- byte[] expected_M2 = trim(new BigInteger("6402e108415ab4a7cd223ec435570614c8aacc09fcf081ade2dc00275e90ceee", 16).toByteArray());
- String username = "username",
- password = "password",
- salt = "64c3289d04a6ecad",
- a = "8c911355";
- byte[] a_byte = new BigInteger(a, 16).toByteArray();
- LeapSRPSession client = new LeapSRPSession(username, password, a_byte);
-
- byte[] x = client.calculatePasswordHash(username, password, new BigInteger(salt, 16).toByteArray());
- assertTrue(Arrays.equals(x, expected_x));
-
- byte[] A = client.exponential();
- assertTrue(Arrays.equals(A, expected_A));
-
- String B = "bc745ba25564fc312f44ea09fb663aa6d95867772e412a6a23f1bc24183e54b32f134372c560f4b3fda19ba7a56b0f84fdcdecc22be6fd256639e918e019691c40a39aa5c9631820e42b28da61b8c75b45afae9d77d63ac8f4dda093762be4a890fbd86061dbd7e5e7c03c4dacde769e0f564df00403e449c0535537f1ba7263";
-
- byte[] M1 = client.response(new BigInteger(salt, 16).toByteArray(), new BigInteger(B, 16).toByteArray());
- assertTrue(Arrays.equals(M1, expected_M1));
-
- boolean verified = client.verify(expected_M2);
- assertTrue(verified);
-
- /* Test 2 */
- expected_A = trim(new BigInteger("180a1caf84efe93610a56772edea7b2d20ef3e9f34e578147b5402a898982f33131708233f9ddd2946246703c5db705f0859cca9cfc5b72ad5a05ec0c748545aa083d5b7b1bf06efe6737e9e0fd81b832b5cba983f1b9717041df8114385b93c8c669db06d62c5773b8e8a8f07e98a840a33d04d3448d4bcd2c042387c316750", 16).toByteArray());
- expected_M1 = trim(new BigInteger("a47782f23057a7e06704ea94389589b3c70971a63268acef2aefd74e234dd3c2", 16).toByteArray());
- a = "d89f0e33";
- expected_M2 = trim(new BigInteger("517278a03a0320a52dcb391caf5264d76149d7d9b71ed2b65536233344c550cf", 16).toByteArray());
-
- a_byte = new BigInteger(a, 16).toByteArray();
- client = new LeapSRPSession(username, password, a_byte);
- x = client.calculatePasswordHash(username, password, new BigInteger(salt, 16).toByteArray());
- A = client.exponential();
-
- B = "5f86fe2f7b7455e877e1760db8d3da1fcd4df0d10ec2a40298f87287bdb2f22c0ea54ff9b1f660cc1666459a7e2fd5501970b317490c3dfd3ba2e18f7be7526b72ea4d01e8f064754b935b107ced0892ce86112cbe32282f929907985fcb29f42c5d4dc32adeb29d12a611cac49cca3fefd2227efadc3989c2e72dd64a003141";
- 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 3 */
- expected_A = trim(new BigInteger("a9c556c30bf4c1b1fdc1bc9e672ab4751806acc8581042b3779faaf25f85f47dfc58828742e2d2a06c51acbbb9f3fae0e01f64df0775a269f5ee4a6e71bc37b8a368e04b9053d399bc5b809ffd6ecab775a577804f2a5ed2e829f15e6af13bf0b78b6b108cf591bc9960992904fd1433698a51e0d05ee954cf98cbfe7995621e", 16).toByteArray());
- expected_M1 = trim(new BigInteger("0afca3583c4146990ec7312f9f4b4d9cceebc43a19f96709bf3d0a17b11dcc1e", 16).toByteArray());
- a = "50e662d6";
- expected_M2 = trim(new BigInteger("3bfb91c7d04b6da6381fe3d2648d992cdc6bc67b8ee16d1cfa733f786d492261", 16).toByteArray());
-
- a_byte = new BigInteger(a, 16).toByteArray();
- client = new LeapSRPSession(username, password, a_byte);
- x = client.calculatePasswordHash(username, password, new BigInteger(salt, 16).toByteArray());
- A = client.exponential();
-
- B = "6fe41e8262f4f8bc4ed9f4e1b4802ae3adac9c348e6efc07f16c6f5704b95a1f12325097489372c3936584a37301ebab400a32ac6699f4556da84f076489060527bd50578a317a3ec8b814bf2f4dd9c4adad368610eb638aa81663a205ba26d8f0b9654bf3940357b867cd42725e8532b97a2410a557d291aa55c0b44f249361";
- 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 4: user abc, password abcdefghi */
- username = "abc";
- password = "abcdefghi";
- salt = "be26aac449a093e5";
- expected_A = trim(new BigInteger("c4013381bdb2fdd901944b9d823360f367c52635b576b9a50d2db77141d357ed391c3ac5fa452c2bbdc35f96bfed21df61627b40aed8f67f21ebf81e5621333f44049d6c9f6ad36464041438350e1f86000a8e3bfb63d4128c18322d2517b0d3ead63fd504a9c8f2156d46e64268110cec5f3ccab54a21559c7ab3ad67fedf90", 16).toByteArray());
- expected_x = trim(new BigInteger("6325967f1a161efd4e2d6e6fabbfccc32be05139cf82b08fb59c0a0db3f34bcf", 16).toByteArray());
- a = "5d4cde29";
- B = "e5d988752e8f265f01b98a1dcdecc4b685bd512e7cd9507f3c29f206c27dac91e027641eed1765c4603bbd7a9aa7fac300ef67dafe611ba2dbe29a32d83d486296f328d38b44c0c211d01d3fe422aac168b6850c87782338969c54594fc87804d4db34910ad4b5452a81027842ac8d8d8288fd44872e4c719ac8fb971d0a33e1";
- expected_M1 = trim(new BigInteger("e5972ddc53e6190735fc79cd823053a65ffb6041d69480adcba2f6a2dc2f2e86", 16).toByteArray());
- expected_M2 = trim(new BigInteger("8f4552b1021a4de621d8f50f0921c4d20651e702d9d71276f8f6c15b838de018", 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));
-
- A = client.exponential();
- assertTrue(Arrays.equals(A, expected_A));
-
- M1 = client.response(trim(new BigInteger(salt, 16).toByteArray()), new BigInteger(B, 16).toByteArray());
-
- assertTrue(Arrays.equals(M1, expected_M1));
-
- verified = client.verify(expected_M2);
- assertTrue(verified);
-
- /* Test 5: user abc, password abcdefghi */
- username = "abc";
- password = "abcdefghi";
- salt = "be26aac449a093e5";
- expected_A = trim(new BigInteger("d13973fe4e0e13423cd036caf0912e23a1f9b0c23966f5a5897c8ff17c5cbac8bab7f07d9ac4ee47396a7c68e80ce854c84f243148521277900aaa132a7b93b61e54d742d7f36edb4cdef54bc78cca69ac72653a7ae0fc47ec1e9a84024ea9487a61357e28eddc185e4fe01388e64e6b8f688dd74471d56dd244204522e08483", 16).toByteArray());
- expected_x = trim(new BigInteger("6325967f1a161efd4e2d6e6fabbfccc32be05139cf82b08fb59c0a0db3f34bcf", 16).toByteArray());
- a = "fc57e4b1";
- B = "a6701686d9d987a43f06e8497330c8add8febd191a7a975bced0d058eb03ccc6805263349363b2d54ac435b01155dc41c6067287d9b93e3637ab3b7e8bc7d9cf38d9fdbb2ca9ee8ba1946a46cb555cb7dafcc177fcf7a4b0eb1e5db2249949c1fd15e0b7c1b3616f9e2649bdf074ed841efbdc9f29ee8c8bfcedeaed3dc49378";
- expected_M1 = trim(new BigInteger("0b590fde631566d0d3420a898a9b469656e64bfaff165c146b78964eee7920b8", 16).toByteArray());
- expected_M2 = trim(new BigInteger("04cf3ab3b75dbc4b116ca2fec949bf3deca1e360e016d7ab2b8a49904c534a27", 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));
-
- A = client.exponential();
- assertTrue(Arrays.equals(A, expected_A));
-
- M1 = client.response(trim(new BigInteger(salt, 16).toByteArray()), new BigInteger(B, 16).toByteArray());
-
- assertTrue(Arrays.equals(M1, expected_M1));
-
- verified = client.verify(expected_M2);
- assertTrue(verified);
-
- /* Test 6: user and password of real use */
- username = "parmegv";
- password = "wR\"P}x@_,:k$`Y<i7PH9\\\\zubHtn[-4MoL+$(?k>Yd*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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* 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));
- }
-
- 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/TestProviderListActivity.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestProviderListActivity.java
deleted file mode 100644
index 4ab705e7..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestProviderListActivity.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.widget.ListView;
-
-import com.robotium.solo.Solo;
-
-import java.io.IOException;
-
-import se.leap.bitmaskclient.ProviderListActivity;
-import se.leap.bitmaskclient.R;
-
-public class TestProviderListActivity extends ActivityInstrumentationTestCase2<ProviderListActivity> {
-
- private Solo solo;
-
- public TestProviderListActivity() {
- super(ProviderListActivity.class);
- }
-
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- solo = new Solo(getInstrumentation(), getActivity());
- Screenshot.initialize(solo);
- }
-
- @Override
- protected void tearDown() throws Exception {
- solo.finishOpenedActivities();
- super.tearDown();
- }
-
- /**
- * Tests should run independently from each other. We need a better approach to test the amount of providers added
- */
- /*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();
- }
-
- private int predefinedProviders() {
- int predefined_providers = 0;
- try {
- predefined_providers = solo.getCurrentActivity().getAssets().list("urls").length;
- } catch (IOException e) {
- e.printStackTrace();
- return predefined_providers;
- }
-
- return predefined_providers;
- }
-
- public void testSelectProvider() {
- Screenshot.take("Initial CW");
- selectProvider("demo.bitmask.net");
- }
-
- private void selectProvider(String provider) {
- solo.clickOnText(provider);
- Screenshot.setTimeToSleep(1);
- Screenshot.take("Configuring provider");
- waitForProviderDetails();
- }
-
- private void waitForProviderDetails() {
- String text = solo.getString(R.string.provider_details_title);
- assertTrue("Provider details dialog did not appear", solo.waitForText(text, 1, 60*1000));
- Screenshot.take("Provider details");
- }
-
- public void testAddNewProvider() {
- //addProvider("calyx.net");
- addProvider("riseup.net", true);
- }
-
- public void testAddFalseProviderReturning404() {
- //addProvider("calyx.net");
- addProvider("startpage.com", false);
- }
-
- public void testAddFalseProviderReturning200() {
- //addProvider("calyx.net");
- addProvider("test.com", false);
- }
-
- private void addProvider(String url, boolean expectSuccess) {
-
- solo.clickOnActionBarItem(R.id.new_provider);
- solo.enterText(0, url);
- if ( BuildConfig.FLAVOR.equals("insecure")) {
- solo.clickOnCheckBox(0);
- }
- solo.clickOnText(solo.getString(R.string.save));
- if (expectSuccess) {
- waitForProviderDetails();
- } else {
- waitForNoValidProviderError();
- }
- solo.goBack();
- }
-
- private void waitForNoValidProviderError() {
- String text = solo.getString(R.string.malformed_url);
- assertTrue("Provider details dialog did not appear", solo.waitForText(text, 1, 60*1000));
- }
-
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestUserStatusFragment.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestUserStatusFragment.java
deleted file mode 100644
index d77b9796..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestUserStatusFragment.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-public class TestUserStatusFragment extends BaseTestDashboardFragment {
-
- public final String TAG = TestUserStatusFragment.class.getName();
-
- private final String provider = "demo.bitmask.net";
- private final String test_username = "parmegvtest1";
- private final String test_password = " S_Zw3'-";
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- changeProviderAndLogIn(provider);
- user_status_controller.clickUserSessionButton();
- user_status_controller.assertLoggedOut();
- }
-
- public void testLogInAndOut() {
- user_status_controller.clickUserSessionButton();
- Screenshot.take("Login dialog");
- user_status_controller.logIn(test_username, test_password);
- Screenshot.setTimeToSleep(2);
- Screenshot.takeWithSleep("Logging in");
- user_status_controller.logOut();
- }
-
- public void testFailedLogIn() {
- user_status_controller.clickUserSessionButton();
- user_status_controller.logIn(test_username, TAG, false);
- if(!user_status_controller.assertErrorLogInDialogAppears())
- throw new IllegalStateException();
- }
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java
deleted file mode 100644
index 70596c10..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Copyright (c) 2013, 2014, 2015 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package se.leap.bitmaskclient.test;
-
-import android.content.Context;
-import android.test.InstrumentationTestCase;
-
-import org.json.JSONObject;
-
-import java.util.Calendar;
-
-import se.leap.bitmaskclient.Provider;
-import se.leap.bitmaskclient.eip.VpnCertificateValidator;
-
-/**
- * @author parmegv
- * //FIXME: The class VpnCertificateValidator should be tested with unit tests!
- */
-public class TestVpnCertificateValidator extends InstrumentationTestCase {
-
- String certificate_valid_from_nov2012_to_nov2022 = "";
-
- Context context;
- FromAssets assets;
-
- @Override
- protected void setUp() throws Exception {
- context = getInstrumentation().getContext();
- assets = new FromAssets(context);
- JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE));
- certificate_valid_from_nov2012_to_nov2022 = secrets.getString(Provider.CA_CERT);
- super.setUp();
- }
-
-
- public void testIsValid() {
- VpnCertificateValidator validator = new VpnCertificateValidator(certificate_valid_from_nov2012_to_nov2022);
- Calendar calendar = Calendar.getInstance();
-
- calendar.set(Calendar.YEAR, 2006);
- calendar.set(Calendar.MONTH, Calendar.NOVEMBER);
- calendar.set(Calendar.DAY_OF_MONTH, 6); calendar.set(Calendar.YEAR, 2006);
- validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
- assertFalse(validator.isValid());
-
- calendar.set(Calendar.YEAR, 2011);
- calendar.set(Calendar.MONTH, Calendar.NOVEMBER);
- calendar.set(Calendar.DAY_OF_MONTH, 6);
- validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
- assertFalse(validator.isValid());
-
- calendar.set(Calendar.YEAR, 2012);
- calendar.set(Calendar.MONTH, Calendar.NOVEMBER);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
- assertTrue(validator.isValid());
-
- calendar.set(Calendar.YEAR, 2022);
- calendar.set(Calendar.MONTH, Calendar.OCTOBER);
- calendar.set(Calendar.DAY_OF_MONTH, 21);
- validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
- assertTrue(validator.isValid());
-
- calendar.set(Calendar.YEAR, 2022);
- calendar.set(Calendar.MONTH, Calendar.OCTOBER);
- calendar.set(Calendar.DAY_OF_MONTH, 23);
- validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
- assertFalse(validator.isValid());
-
- }
-
-} \ No newline at end of file
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java
deleted file mode 100644
index 3b0daf9a..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import android.view.*;
-
-import com.robotium.solo.*;
-
-import se.leap.bitmaskclient.R;
-
-import static junit.framework.Assert.assertTrue;
-
-public class UserStatusTestController {
- private final Solo solo;
-
- public UserStatusTestController(Solo solo) {
- this.solo = solo;
- }
-
- void clickUserSessionButton() {
- solo.clickOnView(getUserSessionButton());
- }
-
- View getUserSessionButton() throws IllegalStateException {
- View view = solo.getView(R.id.user_status_button);
- if(view == null)
- throw new IllegalStateException();
-
- return view;
- }
-
- void logIn(String username, String password, boolean expectSuccess) {
- solo.enterText(0, username);
- solo.enterText(1, password);
- // https://stackoverflow.com/questions/33560746/how-to-test-alertdialog-item-click-in-robotium-for-android-studio
- solo.clickOnView(solo.getView(android.R.id.button1));
- assertTrue(solo.waitForDialogToClose());
-
- if (expectSuccess) {
- assertLoggedIn();
- } else {
- solo.waitForText(solo.getString(R.string.cancel));
- assertTrue(solo.waitForText(solo.getString(R.string.login_button)));
- }
- }
-
- void logIn(String username, String password) {
- logIn(username, password, true);
- }
-
- private void assertLoggedIn() {
- String log_out = solo.getString(R.string.logout_button);
- assertTrue(solo.waitForText(log_out));
- }
-
- void assertLoggedOut() {
- String log_in = solo.getString(R.string.login_button);
- assertTrue(solo.waitForText(log_in));
- }
-
- void logOut() {
- assertLoggedIn();
- clickUserSessionButton();
-
- solo.clickOnActionBarItem(R.string.logout_button);
- solo.waitForDialogToClose();
- assertLoggedOut();
- }
-
- boolean assertErrorLogInDialogAppears() {
- assertTrue(solo.waitForDialogToOpen());
-
- String username_hint = solo.getEditText(0).getHint().toString();
- String correct_username_hint = solo.getString(R.string.username_hint);
- String password_hint = solo.getEditText(1).getHint().toString();
- String correct_password_hint = solo.getString(R.string.password_hint);
- String user_message = solo.getText(0).toString();
- String riseup_user_message = solo.getString(R.string.login_riseup_warning);
-
- return username_hint.equalsIgnoreCase(correct_username_hint)
- && password_hint.equalsIgnoreCase(correct_password_hint)
- && !user_message.equalsIgnoreCase(riseup_user_message)
- && !user_message.isEmpty();
- }
-}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java
deleted file mode 100644
index 4c6a6370..00000000
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package se.leap.bitmaskclient.test;
-
-import android.view.View;
-import android.widget.Button;
-
-import com.robotium.solo.Condition;
-import com.robotium.solo.Solo;
-
-import de.blinkt.openvpn.activities.DisconnectVPN;
-import mbanje.kurt.fabbutton.ProgressRingView;
-import se.leap.bitmaskclient.Dashboard;
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.userstatus.FabButton;
-
-import static junit.framework.Assert.assertTrue;
-
-public class VpnTestController {
-
- private final Solo solo;
-
- public VpnTestController(Solo solo) {
- this.solo = solo;
- }
-
- protected void turnVpnOnAndOff() {
- clickVpnButton();
- turningEipOn();
- clickVpnButton();
- turningEipOff();
- }
-
- protected void clickVpnButton() throws IllegalStateException {
- Button button = getVpnButton();
- if(!isVpnButton(button))
- throw new IllegalStateException();
- solo.clickOnButton(String.valueOf(button.getText()));
- }
-
- protected Button getVpnButton() {
- View button_view = solo.getView(R.id.vpn_main_button);
- if (button_view != null)
- return (Button) button_view;
- else
- return null;
- }
-
- private boolean isVpnButton(Button button) {
- return button != null && !button.getText().toString().isEmpty();
- }
-
- protected FabButton getVpnWholeIcon() {
- assertTrue(solo.waitForActivity(Dashboard.class, 5 * 1000));
-
- View view = solo.getView(R.id.vpn_status_image);
- if (view != null)
- return (FabButton) view;
- else
- return null;
- }
-
- protected void turningEipOn() {
- assertInProgress();
- int max_seconds_until_connected = 120;
-
- Condition condition = new Condition() {
- @Override
- public boolean isSatisfied() {
- return iconShowsConnected();
- }
- };
- assertTrue("condition iconShowsConnected not fulfilled within " + max_seconds_until_connected + " seconds." , solo.waitForCondition(condition, max_seconds_until_connected * 1000));
- sleepSeconds(2);
- }
-
- private void assertInProgress() {
- FabButton whole_icon = getVpnWholeIcon();
- ProgressRingView a;
- a = whole_icon != null ?
- (ProgressRingView) getVpnWholeIcon().findViewById(R.id.fabbutton_ring) :
- new ProgressRingView(solo.getCurrentActivity());
- BaseTestDashboardFragment.isShownWithinConfinesOfVisibleScreen(a);
- }
-
- private boolean iconShowsConnected() {
- View vpnIconView = getVpnWholeIcon();
- return vpnIconView.getTag().equals(R.drawable.ic_stat_vpn);
- }
-
- protected boolean iconShowsDisconnected() {
- View vpnIconView = getVpnWholeIcon();
- return vpnIconView.getTag().equals(R.drawable.ic_stat_vpn_offline);
- }
-
- protected void turningEipOff() {
- okToBrowserWarning();
- int max_seconds_until_connected = 120;
-
- Condition condition = new Condition() {
- @Override
- public boolean isSatisfied() {
- return iconShowsDisconnected();
- }
- };
- assertTrue(solo.waitForCondition(condition, max_seconds_until_connected * 1000));
- sleepSeconds(2);
- }
-
- private void okToBrowserWarning() {
- assertTrue(solo.waitForDialogToOpen());
- clickYes();
- solo.waitForDialogToClose();
- }
-
- private void clickYes() {
- String yes = solo.getString(android.R.string.yes);
- solo.clickOnButton(yes);
- }
-
- private void clickDisconnect() {
- String disconnect = solo.getString(R.string.cancel_connection);
- solo.clickOnButton(disconnect);
- }
-
- @SuppressWarnings("unused")
- private void sayOkToDisconnect() throws IllegalStateException {
- boolean disconnect_vpn_appeared = solo.waitForActivity(DisconnectVPN.class);
- if(disconnect_vpn_appeared){
- clickDisconnect();
- solo.waitForDialogToClose();
- }
- else throw new IllegalStateException();
- }
-
- void sleepSeconds(int seconds) {
- solo.sleep(seconds * 1000);
- }
-}