summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2021-02-26 08:53:28 +0000
committercyberta <cyberta@riseup.net>2021-02-26 08:53:28 +0000
commit8bb73089566e78a195f21f4746c9db416abf95a4 (patch)
treebba73954ec2754f85060622f60d69a19f00980c3
parentc62389eaae3768e236875ee5fd20bde29e381c94 (diff)
parentcb1510c9f3ea27d5cffc0c0e370f8270d454e39b (diff)
Merge branch 'fix_custom_preshipping' into 'master'
ensure the private api and the preshipped certificate will be used to setup... Closes #9029 See merge request leap/bitmask_android!130
-rw-r--r--app/src/insecure/assets/urls/cdev.bitmask.net.url3
-rw-r--r--app/src/insecure/assets/urls/dev.bitmask.net.url3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java7
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java26
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java30
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java35
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java2
7 files changed, 71 insertions, 35 deletions
diff --git a/app/src/insecure/assets/urls/cdev.bitmask.net.url b/app/src/insecure/assets/urls/cdev.bitmask.net.url
deleted file mode 100644
index 4ceca5ee..00000000
--- a/app/src/insecure/assets/urls/cdev.bitmask.net.url
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "main_url" : "https://cdev.bitmask.net/"
-} \ No newline at end of file
diff --git a/app/src/insecure/assets/urls/dev.bitmask.net.url b/app/src/insecure/assets/urls/dev.bitmask.net.url
deleted file mode 100644
index 5d4ae485..00000000
--- a/app/src/insecure/assets/urls/dev.bitmask.net.url
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "main_url" : "https://dev.bitmask.net/"
-} \ No newline at end of file
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
index d649aaf5..e60019fc 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
@@ -104,6 +104,13 @@ public interface Constants {
String PROVIDER_PROFILE_UUID = "Constants.PROVIDER_PROFILE_UUID";
String PROVIDER_PROFILE = "Constants.PROVIDER_PROFILE";
+ ////////////////////////////////////////////////
+ // PRESHIPPED PROVIDER CONFIG
+ ////////////////////////////////////////////////
+ String URLS = "urls";
+ String EXT_JSON = ".json";
+ String EXT_PEM = ".pem";
+
//////////////////////////////////////////////
// CREDENTIAL CONSTANTS
/////////////////////////////////////////////
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java
index 77189dff..8a526499 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/InputStreamHelper.java
@@ -1,7 +1,11 @@
package se.leap.bitmaskclient.base.utils;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
/**
@@ -18,4 +22,26 @@ public class InputStreamHelper {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
+
+ public static String extractKeyFromInputStream(InputStream inputStream, String key) {
+ String value = "";
+
+ JSONObject fileContents = inputStreamToJson(inputStream);
+ if (fileContents != null)
+ value = fileContents.optString(key);
+ return value;
+ }
+
+ public static JSONObject inputStreamToJson(InputStream inputStream) {
+ JSONObject json = null;
+ try {
+ byte[] bytes = new byte[inputStream.available()];
+ if (inputStream.read(bytes) > 0)
+ json = new JSONObject(new String(bytes));
+ inputStream.reset();
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ }
+ return json;
+ }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java
index d33a175f..654fb8e2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java
@@ -22,12 +22,16 @@ import java.util.Set;
import se.leap.bitmaskclient.base.models.Provider;
+import static se.leap.bitmaskclient.base.models.Constants.EXT_JSON;
+import static se.leap.bitmaskclient.base.models.Constants.EXT_PEM;
+import static se.leap.bitmaskclient.base.models.Constants.URLS;
import static se.leap.bitmaskclient.base.models.Provider.GEOIP_URL;
import static se.leap.bitmaskclient.base.models.Provider.MAIN_URL;
import static se.leap.bitmaskclient.base.models.Provider.PROVIDER_API_IP;
import static se.leap.bitmaskclient.base.models.Provider.PROVIDER_IP;
import static se.leap.bitmaskclient.base.utils.FileHelper.createFile;
import static se.leap.bitmaskclient.base.utils.FileHelper.persistFile;
+import static se.leap.bitmaskclient.base.utils.InputStreamHelper.extractKeyFromInputStream;
import static se.leap.bitmaskclient.base.utils.InputStreamHelper.getInputStreamFrom;
import static se.leap.bitmaskclient.base.utils.InputStreamHelper.loadInputStreamAsString;
@@ -45,10 +49,6 @@ public class ProviderManager implements AdapteeCollection<Provider> {
private static ProviderManager instance;
- final private static String URLS = "urls";
- final private static String EXT_JSON = ".json";
- final private static String EXT_PEM = ".pem";
-
public static ProviderManager getInstance(AssetManager assetsManager, File externalFilesDir) {
if (instance == null)
instance = new ProviderManager(assetsManager, externalFilesDir);
@@ -138,28 +138,6 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return providers;
}
- private String extractKeyFromInputStream(InputStream inputStream, String key) {
- String value = "";
-
- JSONObject fileContents = inputStreamToJson(inputStream);
- if (fileContents != null)
- value = fileContents.optString(key);
- return value;
- }
-
- private JSONObject inputStreamToJson(InputStream inputStream) {
- JSONObject json = null;
- try {
- byte[] bytes = new byte[inputStream.available()];
- if (inputStream.read(bytes) > 0)
- json = new JSONObject(new String(bytes));
- inputStream.reset();
- } catch (IOException | JSONException e) {
- e.printStackTrace();
- }
- return json;
- }
-
public List<Provider> providers() {
List<Provider> allProviders = new ArrayList<>();
allProviders.addAll(defaultProviders);
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java
index 161c53d3..b90d14f8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java
@@ -17,19 +17,33 @@
package se.leap.bitmaskclient.providersetup.activities;
import android.content.Intent;
+import android.content.res.AssetManager;
import android.os.Bundle;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+
import se.leap.bitmaskclient.BuildConfig;
+import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.models.Provider;
import se.leap.bitmaskclient.providersetup.ProviderAPICommand;
-import se.leap.bitmaskclient.R;
+import static se.leap.bitmaskclient.BuildConfig.customProviderApiIp;
+import static se.leap.bitmaskclient.BuildConfig.customProviderIp;
+import static se.leap.bitmaskclient.BuildConfig.customProviderUrl;
+import static se.leap.bitmaskclient.BuildConfig.geoipUrl;
+import static se.leap.bitmaskclient.base.models.Constants.EXT_JSON;
+import static se.leap.bitmaskclient.base.models.Constants.EXT_PEM;
import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
+import static se.leap.bitmaskclient.base.utils.ConfigHelper.preferAnonymousUsage;
+import static se.leap.bitmaskclient.base.utils.InputStreamHelper.loadInputStreamAsString;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.SET_UP_PROVIDER;
import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.SETTING_UP_PROVIDER;
-import static se.leap.bitmaskclient.base.utils.ConfigHelper.preferAnonymousUsage;
/**
* Created by cyberta on 17.08.18.
@@ -42,7 +56,7 @@ public class CustomProviderSetupActivity extends ProviderSetupBaseActivity {
super.onCreate(savedInstanceState);
setUpInitialUI();
restoreState(savedInstanceState);
- setProvider(new Provider(BuildConfig.customProviderUrl, BuildConfig.geoipUrl, BuildConfig.customProviderIp, BuildConfig.customProviderApiIp));
+ setDefaultProvider();
}
@Override
@@ -54,6 +68,21 @@ public class CustomProviderSetupActivity extends ProviderSetupBaseActivity {
}
}
+ private void setDefaultProvider() {
+ try {
+ AssetManager assetsManager = getAssets();
+ Provider customProvider = new Provider(customProviderUrl, geoipUrl, customProviderIp, customProviderApiIp);
+ String certificate = loadInputStreamAsString(assetsManager.open(customProvider.getDomain() + EXT_PEM));
+ String providerDefinition = loadInputStreamAsString(assetsManager.open(customProvider.getDomain() + EXT_JSON));
+ customProvider.setCaCert(certificate);
+ customProvider.define(new JSONObject(providerDefinition));
+ setProvider(customProvider);
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ setProvider(new Provider(customProviderUrl, geoipUrl, customProviderIp, customProviderApiIp));
+ }
+ }
+
private void setUpInitialUI() {
setContentView(R.layout.a_custom_provider_setup);
setProviderHeaderText(R.string.setup_provider);
diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
index d4b7c5d1..5a341cd1 100644
--- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
+++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
@@ -366,6 +366,8 @@ public class MockHelper {
return getClass().getClassLoader().getResourceAsStream(filename);
}
});
+ when(InputStreamHelper.extractKeyFromInputStream(any(InputStream.class), anyString())).thenCallRealMethod();
+ when(InputStreamHelper.inputStreamToJson(any(InputStream.class))).thenCallRealMethod();
}