summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-02-25 19:58:37 +0100
committercyBerta <cyberta@riseup.net>2021-02-25 20:15:09 +0100
commitb07f5effd54670f8bbf34cdd3f95735ae07e4c85 (patch)
treeb2b3daa491006928d98889a4837bc6c15ef61dba /app
parent2b1dcf4f6b4ed7405a14c5dfb50ef16dfa416fbf (diff)
ensure the private api and the preshipped certificate will be used to setup the provider in custom builds
Diffstat (limited to 'app')
-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
6 files changed, 69 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);