summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/build.gradle7
-rw-r--r--app/src/main/java/de/blinkt/openvpn/VpnProfile.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java35
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/PrivateKeyHelper.java106
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/RSAHelper.java72
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java19
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/base/utils/PrivateKeyHelperTest.java39
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java4
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java6
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java9
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java25
-rw-r--r--app/src/test/resources/private_ed25519_key.pem3
13 files changed, 200 insertions, 131 deletions
diff --git a/app/build.gradle b/app/build.gradle
index f3412c3f..9a318759 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -374,15 +374,16 @@ android {
}
}
-
-
-
dependencies {
testImplementation 'junit:junit:4.13.2'
//outdated mockito-core version due to powermock dependency
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation('org.powermock:powermock-api-mockito2:2.0.9')
// { exclude group: 'junit' exclude group: 'org.mockito' }
+
+ testImplementation 'org.robolectric:robolectric:4.13'
+ testImplementation 'org.conscrypt:conscrypt-openjdk-uber:2.5.2'
+
testImplementation 'org.powermock:powermock-module-junit4:2.0.9'
testImplementation 'org.powermock:powermock-core:2.0.9'
testImplementation 'org.powermock:powermock-module-junit4-rule:2.0.9'
diff --git a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
index 9da1e452..ae8901e0 100644
--- a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -444,7 +444,7 @@ public class VpnProfile implements Serializable, Cloneable {
// Client Cert + Key
cfg.append(insertFileData("cert", mClientCertFilename));
- mPrivateKey = ProviderObservable.getInstance().getCurrentProvider().getRSAPrivateKey();
+ mPrivateKey = ProviderObservable.getInstance().getCurrentProvider().getPrivateKey();
cfg.append("management-external-key nopadding pkcs1 pss digest\n");
break;
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
index 64e57cda..725c602a 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
@@ -28,7 +28,7 @@ import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_ALLOWED_REGIS
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_ALLOW_ANONYMOUS;
import static se.leap.bitmaskclient.base.models.Constants.TRANSPORT;
import static se.leap.bitmaskclient.base.models.Constants.TYPE;
-import static se.leap.bitmaskclient.base.utils.RSAHelper.parseRsaKeyFromString;
+import static se.leap.bitmaskclient.base.utils.PrivateKeyHelper.parsePrivateKeyFromString;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.ERRORS;
import android.os.Parcel;
@@ -44,7 +44,7 @@ import org.json.JSONObject;
import java.net.MalformedURLException;
import java.net.URL;
-import java.security.interfaces.RSAPrivateKey;
+import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Locale;
@@ -79,9 +79,8 @@ public final class Provider implements Parcelable {
private String certificatePinEncoding = "";
private String caCert = "";
private String apiVersion = "";
- private String privateKey = "";
-
- private transient RSAPrivateKey rsaPrivateKey = null;
+ private String privateKeyString = "";
+ private transient PrivateKey privateKey = null;
private String vpnCertificate = "";
private long lastEipServiceUpdate = 0L;
private long lastGeoIpUpdate = 0L;
@@ -416,7 +415,7 @@ public final class Provider implements Parcelable {
parcel.writeString(getEipServiceJsonString());
parcel.writeString(getGeoIpJsonString());
parcel.writeString(getMotdJsonString());
- parcel.writeString(getPrivateKey());
+ parcel.writeString(getPrivateKeyString());
parcel.writeString(getVpnCertificate());
parcel.writeLong(lastEipServiceUpdate);
parcel.writeLong(lastGeoIpUpdate);
@@ -471,7 +470,7 @@ public final class Provider implements Parcelable {
}
tmpString = in.readString();
if (!tmpString.isEmpty()) {
- this.setPrivateKey(tmpString);
+ this.setPrivateKeyString(tmpString);
}
tmpString = in.readString();
if (!tmpString.isEmpty()) {
@@ -510,7 +509,7 @@ public final class Provider implements Parcelable {
certificatePinEncoding.equals(p.getCertificatePinEncoding()) &&
caCert.equals(p.getCaCert()) &&
apiVersion.equals(p.getApiVersion()) &&
- privateKey.equals(p.getPrivateKey()) &&
+ privateKeyString.equals(p.getPrivateKeyString()) &&
vpnCertificate.equals(p.getVpnCertificate()) &&
allowAnonymous == p.allowsAnonymous() &&
allowRegistered == p.allowsRegistered();
@@ -697,23 +696,23 @@ public final class Provider implements Parcelable {
caCert.isEmpty();
}
- public String getPrivateKey() {
- return privateKey;
+ public String getPrivateKeyString() {
+ return privateKeyString;
}
- public RSAPrivateKey getRSAPrivateKey() {
- if (rsaPrivateKey == null) {
- rsaPrivateKey = parseRsaKeyFromString(privateKey);
+ public PrivateKey getPrivateKey() {
+ if (privateKey == null) {
+ privateKey = parsePrivateKeyFromString(privateKeyString);
}
- return rsaPrivateKey;
+ return privateKey;
}
- public void setPrivateKey(String privateKey) {
- this.privateKey = privateKey;
+ public void setPrivateKeyString(String privateKeyString) {
+ this.privateKeyString = privateKeyString;
}
public boolean hasPrivateKey() {
- return privateKey != null && privateKey.length() > 0;
+ return privateKeyString != null && privateKeyString.length() > 0;
}
public String getVpnCertificate() {
@@ -754,7 +753,7 @@ public final class Provider implements Parcelable {
certificatePinEncoding = "";
caCert = "";
apiVersion = "";
- privateKey = "";
+ privateKeyString = "";
vpnCertificate = "";
allowRegistered = false;
allowAnonymous = false;
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
index 8d1f21e5..c2c0d85e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
@@ -143,7 +143,7 @@ public class PreferenceHelper {
provider.define(new JSONObject(preferences.getString(Provider.KEY, "")));
provider.setCaCert(preferences.getString(Provider.CA_CERT, ""));
provider.setVpnCertificate(preferences.getString(PROVIDER_VPN_CERTIFICATE, ""));
- provider.setPrivateKey(preferences.getString(PROVIDER_PRIVATE_KEY, ""));
+ provider.setPrivateKeyString(preferences.getString(PROVIDER_PRIVATE_KEY, ""));
provider.setEipServiceJson(new JSONObject(preferences.getString(PROVIDER_EIP_DEFINITION, "")));
provider.setMotdJson(new JSONObject(preferences.getString(PROVIDER_MOTD, "")));
provider.setLastMotdSeen(preferences.getLong(PROVIDER_MOTD_LAST_SEEN, 0L));
@@ -242,7 +242,7 @@ public class PreferenceHelper {
putString(Provider.KEY, provider.getDefinitionString()).
putString(Provider.CA_CERT, provider.getCaCert()).
putString(PROVIDER_EIP_DEFINITION, provider.getEipServiceJsonString()).
- putString(PROVIDER_PRIVATE_KEY, provider.getPrivateKey()).
+ putString(PROVIDER_PRIVATE_KEY, provider.getPrivateKeyString()).
putString(PROVIDER_VPN_CERTIFICATE, provider.getVpnCertificate()).
putString(PROVIDER_MOTD, provider.getMotdJsonString()).
putStringSet(PROVIDER_MOTD_HASHES, provider.getMotdLastSeenHashes()).
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PrivateKeyHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PrivateKeyHelper.java
new file mode 100644
index 00000000..7abe9416
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PrivateKeyHelper.java
@@ -0,0 +1,106 @@
+package se.leap.bitmaskclient.base.utils;
+
+import android.os.Build;
+
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+
+import org.spongycastle.util.encoders.Base64;
+
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
+import java.security.interfaces.EdECPrivateKey;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.PKCS8EncodedKeySpec;
+
+import de.blinkt.openvpn.core.NativeUtils;
+
+public class PrivateKeyHelper {
+
+ public static final String RSA = "RSA";
+ public static final String ED_25519 = "Ed25519";
+
+ public static final String RSA_KEY_BEGIN = "-----BEGIN RSA PRIVATE KEY-----\n";
+ public static final String RSA_KEY_END = "-----END RSA PRIVATE KEY-----";
+ public static final String ED_25519_KEY_BEGIN = "-----BEGIN PRIVATE KEY-----\n";
+ public static final String ED_25519_KEY_END = "-----END PRIVATE KEY-----";
+
+
+ public interface PrivateKeyHelperInterface {
+
+
+ @Nullable PrivateKey parsePrivateKeyFromString(String privateKeyString);
+ }
+
+ public static class DefaultPrivateKeyHelper implements PrivateKeyHelperInterface {
+
+ public PrivateKey parsePrivateKeyFromString(String privateKeyString) {
+ if (privateKeyString == null || privateKeyString.isBlank()) {
+ return null;
+ }
+ if (privateKeyString.contains(RSA_KEY_BEGIN)) {
+ return parseRsaKeyFromString(privateKeyString);
+ } else if (privateKeyString.contains(ED_25519_KEY_BEGIN)) {
+ return parseECPrivateKey(privateKeyString);
+ } else {
+ return null;
+ }
+ }
+
+ private RSAPrivateKey parseRsaKeyFromString(String rsaKeyString) {
+ RSAPrivateKey key;
+ try {
+ KeyFactory kf;
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
+ kf = KeyFactory.getInstance(RSA, "BC");
+ } else {
+ kf = KeyFactory.getInstance(RSA);
+ }
+ rsaKeyString = rsaKeyString.replaceFirst(RSA_KEY_BEGIN, "").replaceFirst(RSA_KEY_END, "");
+
+ PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decode(rsaKeyString));
+ key = (RSAPrivateKey) kf.generatePrivate(keySpec);
+ } catch (InvalidKeySpecException | NoSuchAlgorithmException | NullPointerException |
+ NoSuchProviderException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ return key;
+ }
+
+ private EdECPrivateKey parseECPrivateKey(String ecKeyString) {
+ KeyFactory kf;
+ try {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
+ kf = KeyFactory.getInstance(ED_25519, "BC");
+ } else {
+ kf = KeyFactory.getInstance(ED_25519);
+ }
+ ecKeyString = ecKeyString.replaceFirst(ED_25519_KEY_BEGIN, "").replaceFirst(ED_25519_KEY_END, "");
+ PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decode(ecKeyString));
+ return (EdECPrivateKey) kf.generatePrivate(keySpec);
+ } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ }
+
+ private static PrivateKeyHelperInterface instance = new DefaultPrivateKeyHelper();
+
+ @VisibleForTesting
+ public PrivateKeyHelper(PrivateKeyHelperInterface helperInterface) {
+ if (!NativeUtils.isUnitTest()) {
+ throw new IllegalStateException("PrivateKeyHelper injected with PrivateKeyHelperInterface outside of an unit test");
+ }
+ instance = helperInterface;
+ }
+
+ public static @Nullable PrivateKey parsePrivateKeyFromString(String rsaKeyString) {
+ return instance.parsePrivateKeyFromString(rsaKeyString);
+ }
+}
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/RSAHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/RSAHelper.java
deleted file mode 100644
index 2872139a..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/RSAHelper.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package se.leap.bitmaskclient.base.utils;
-
-import android.os.Build;
-
-import androidx.annotation.VisibleForTesting;
-
-import org.spongycastle.util.encoders.Base64;
-
-import java.security.KeyFactory;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.interfaces.RSAPrivateKey;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.PKCS8EncodedKeySpec;
-
-import de.blinkt.openvpn.core.NativeUtils;
-
-public class RSAHelper {
-
- public interface RSAHelperInterface {
- RSAPrivateKey parseRsaKeyFromString(String rsaKeyString);
- }
-
- public static class DefaultRSAHelper implements RSAHelperInterface {
-
- @Override
- public RSAPrivateKey parseRsaKeyFromString(String rsaKeyString) {
- RSAPrivateKey key;
- try {
- KeyFactory kf;
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
- kf = KeyFactory.getInstance("RSA", "BC");
- } else {
- kf = KeyFactory.getInstance("RSA");
- }
- rsaKeyString = rsaKeyString.replaceFirst("-----BEGIN RSA PRIVATE KEY-----", "").replaceFirst("-----END RSA PRIVATE KEY-----", "");
- PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decode(rsaKeyString));
- key = (RSAPrivateKey) kf.generatePrivate(keySpec);
- } catch (InvalidKeySpecException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- } catch (NoSuchAlgorithmException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- } catch (NullPointerException e) {
- e.printStackTrace();
- return null;
- } catch (NoSuchProviderException e) {
- e.printStackTrace();
- return null;
- }
-
- return key;
- }
- }
-
- private static RSAHelperInterface instance = new DefaultRSAHelper();
-
- @VisibleForTesting
- public RSAHelper(RSAHelperInterface helperInterface) {
- if (!NativeUtils.isUnitTest()) {
- throw new IllegalStateException("RSAHelper injected with RSAHelperInterface outside of an unit test");
- }
- instance = helperInterface;
- }
-
- public static RSAPrivateKey parseRsaKeyFromString(String rsaKeyString) {
- return instance.parseRsaKeyFromString(rsaKeyString);
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
index e511e276..ea50e741 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
@@ -35,7 +35,11 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.deleteProviderDe
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getFromPersistedProvider;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getLongFromPersistedProvider;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getStringSetFromPersistedProvider;
-import static se.leap.bitmaskclient.base.utils.RSAHelper.parseRsaKeyFromString;
+import static se.leap.bitmaskclient.base.utils.PrivateKeyHelper.ED_25519_KEY_BEGIN;
+import static se.leap.bitmaskclient.base.utils.PrivateKeyHelper.ED_25519_KEY_END;
+import static se.leap.bitmaskclient.base.utils.PrivateKeyHelper.RSA_KEY_BEGIN;
+import static se.leap.bitmaskclient.base.utils.PrivateKeyHelper.RSA_KEY_END;
+import static se.leap.bitmaskclient.base.utils.PrivateKeyHelper.parsePrivateKeyFromString;
import android.content.Intent;
import android.content.res.Resources;
@@ -46,6 +50,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@@ -57,6 +62,7 @@ import java.util.concurrent.TimeoutException;
import se.leap.bitmaskclient.base.models.Provider;
import se.leap.bitmaskclient.base.utils.ConfigHelper;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
+import se.leap.bitmaskclient.base.utils.PrivateKeyHelper;
/**
* Implements the logic of the http api calls. The methods of this class needs to be called from
@@ -141,7 +147,7 @@ public abstract class ProviderApiManagerBase {
if (hasUpdatedProviderDetails(providerDomain)) {
provider.setCaCert(getPersistedProviderCA(providerDomain));
provider.define(getPersistedProviderDefinition(providerDomain));
- provider.setPrivateKey(getPersistedPrivateKey(providerDomain));
+ provider.setPrivateKeyString(getPersistedPrivateKey(providerDomain));
provider.setVpnCertificate(getPersistedVPNCertificate(providerDomain));
provider.setProviderApiIp(getPersistedProviderApiIp(providerDomain));
provider.setProviderIp(getPersistedProviderIp(providerDomain));
@@ -232,9 +238,14 @@ public abstract class ProviderApiManagerBase {
}
}
- RSAPrivateKey key = parseRsaKeyFromString(keyString);
+ PrivateKey key = parsePrivateKeyFromString(keyString);
keyString = Base64.encodeToString(key.getEncoded(), Base64.DEFAULT);
- provider.setPrivateKey( "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----");
+
+ if (key instanceof RSAPrivateKey) {
+ provider.setPrivateKeyString(RSA_KEY_BEGIN + keyString + RSA_KEY_END);
+ } else {
+ provider.setPrivateKeyString(ED_25519_KEY_BEGIN + keyString + ED_25519_KEY_END);
+ }
ArrayList<X509Certificate> certificates = ConfigHelper.parseX509CertificatesFromString(certificateString);
certificates.get(0).checkValidity();
diff --git a/app/src/test/java/se/leap/bitmaskclient/base/utils/PrivateKeyHelperTest.java b/app/src/test/java/se/leap/bitmaskclient/base/utils/PrivateKeyHelperTest.java
new file mode 100644
index 00000000..5ad9d2e7
--- /dev/null
+++ b/app/src/test/java/se/leap/bitmaskclient/base/utils/PrivateKeyHelperTest.java
@@ -0,0 +1,39 @@
+package se.leap.bitmaskclient.base.utils;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import android.os.Build;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+import java.io.IOException;
+import java.security.PrivateKey;
+import java.security.interfaces.EdECPrivateKey;
+import java.security.interfaces.RSAPrivateKey;
+
+import se.leap.bitmaskclient.testutils.TestSetupHelper;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(sdk = {Build.VERSION_CODES.P, Build.VERSION_CODES.O})
+public class PrivateKeyHelperTest {
+
+ @Test
+ public void parsePrivateKeyFromString_testRSA() throws IOException {
+ String rsa_key = TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("private_rsa_key.pem"));
+ PrivateKey pk = PrivateKeyHelper.parsePrivateKeyFromString(rsa_key);
+ assertNotNull(pk);
+ assertTrue(pk instanceof RSAPrivateKey);
+ }
+
+ @Test
+ public void parsePrivateKeyFromString_testEd25519() throws IOException {
+ String ed25519_key = TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("private_ed25519_key.pem"));
+ PrivateKey pk = PrivateKeyHelper.parsePrivateKeyFromString(ed25519_key);
+ assertNotNull(pk);
+ assertTrue(pk instanceof EdECPrivateKey);
+ }
+} \ No newline at end of file
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
index 7581a395..547bb3df 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
@@ -27,7 +27,7 @@ import de.blinkt.openvpn.core.connection.Obfs4Connection;
import se.leap.bitmaskclient.base.models.ProviderObservable;
import se.leap.bitmaskclient.base.utils.BuildConfigHelper;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-import se.leap.bitmaskclient.base.utils.RSAHelper;
+import se.leap.bitmaskclient.base.utils.PrivateKeyHelper;
import se.leap.bitmaskclient.testutils.MockHelper;
import se.leap.bitmaskclient.testutils.MockSharedPreferences;
import se.leap.bitmaskclient.testutils.TestSetupHelper;
@@ -1347,7 +1347,7 @@ public class VpnConfigGeneratorTest {
context = MockHelper.mockContext();
ProviderObservable providerObservable = MockHelper.mockProviderObservable(TestSetupHelper.getConfiguredProvider());
- RSAHelper rsaHelper = MockHelper.mockRSAHelper();
+ PrivateKeyHelper privateKeyHelper = MockHelper.mockPrivateKeyHelper();
sharedPreferences = new MockSharedPreferences();
preferenceHelper = new PreferenceHelper(new MockSharedPreferences());
when(context.getCacheDir()).thenReturn(new File("/data/data/se.leap.bitmask"));
diff --git a/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java
index 711d5487..2978edc7 100644
--- a/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java
@@ -22,7 +22,7 @@ import static se.leap.bitmaskclient.testutils.MockHelper.mockClientGenerator;
import static se.leap.bitmaskclient.testutils.MockHelper.mockContext;
import static se.leap.bitmaskclient.testutils.MockHelper.mockPreferenceHelper;
import static se.leap.bitmaskclient.testutils.MockHelper.mockProviderApiConnector;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockRSAHelper;
+import static se.leap.bitmaskclient.testutils.MockHelper.mockPrivateKeyHelper;
import static se.leap.bitmaskclient.testutils.MockHelper.mockResources;
import static se.leap.bitmaskclient.testutils.MockHelper.mockResultReceiver;
import static se.leap.bitmaskclient.testutils.TestSetupHelper.getConfiguredProvider;
@@ -51,7 +51,7 @@ import se.leap.bitmaskclient.base.utils.BuildConfigHelper;
import se.leap.bitmaskclient.base.utils.CertificateHelper;
import se.leap.bitmaskclient.base.utils.HandlerProvider;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-import se.leap.bitmaskclient.base.utils.RSAHelper;
+import se.leap.bitmaskclient.base.utils.PrivateKeyHelper;
import se.leap.bitmaskclient.testutils.MockSharedPreferences;
import se.leap.bitmaskclient.tor.TorStatusObservable;
@@ -221,7 +221,7 @@ public class ProviderApiManagerTest {
sharedPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_SNOWFLAKE, true).commit();
PreferenceHelper preferenceHelper = mockPreferenceHelper(provider, sharedPreferences);
CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- RSAHelper rsaHelper = mockRSAHelper();
+ PrivateKeyHelper privateKeyHelper = mockPrivateKeyHelper();
ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR_API_V4);
providerApiManager = new ProviderApiManager(mockResources, new ProviderApiManagerTest.TestProviderApiServiceCallback());
diff --git a/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java b/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java
index a446bcfa..646d32d8 100644
--- a/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java
+++ b/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java
@@ -48,7 +48,7 @@ import static se.leap.bitmaskclient.testutils.MockHelper.mockClientGenerator;
import static se.leap.bitmaskclient.testutils.MockHelper.mockContext;
import static se.leap.bitmaskclient.testutils.MockHelper.mockPreferenceHelper;
import static se.leap.bitmaskclient.testutils.MockHelper.mockProviderApiConnector;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockRSAHelper;
+import static se.leap.bitmaskclient.testutils.MockHelper.mockPrivateKeyHelper;
import static se.leap.bitmaskclient.testutils.MockHelper.mockResources;
import static se.leap.bitmaskclient.testutils.MockHelper.mockResultReceiver;
import static se.leap.bitmaskclient.testutils.TestSetupHelper.getConfiguredProvider;
@@ -79,10 +79,7 @@ import se.leap.bitmaskclient.base.utils.BuildConfigHelper;
import se.leap.bitmaskclient.base.utils.CertificateHelper;
import se.leap.bitmaskclient.base.utils.HandlerProvider;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-import se.leap.bitmaskclient.base.utils.RSAHelper;
-import se.leap.bitmaskclient.providersetup.ProviderApiConnector;
-import se.leap.bitmaskclient.providersetup.ProviderApiManagerBase;
-import se.leap.bitmaskclient.providersetup.ProviderApiManagerV3;
+import se.leap.bitmaskclient.base.utils.PrivateKeyHelper;
import se.leap.bitmaskclient.testutils.MockSharedPreferences;
import se.leap.bitmaskclient.tor.TorStatusObservable;
@@ -608,7 +605,7 @@ public class ProviderApiManagerV3Test {
Provider provider = getConfiguredProviderAPIv4();
PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- RSAHelper rsaHelper = mockRSAHelper();
+ PrivateKeyHelper privateKeyHelper = mockPrivateKeyHelper();
ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
providerApiManager = new ProviderApiManagerV3(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
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 1b94042e..5434e7bd 100644
--- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
+++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
@@ -10,7 +10,6 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
-import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_CONFIGURED;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_EIP_DEFINITION;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD_HASHES;
@@ -21,7 +20,6 @@ import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_VPN_CERTIFICA
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getEipDefinitionFromPreferences;
import android.content.Context;
-import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -30,9 +28,6 @@ import android.os.Bundle;
import android.os.Parcelable;
import android.os.ResultReceiver;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.Mockito;
@@ -47,17 +42,9 @@ import java.math.BigInteger;
import java.net.UnknownHostException;
import java.security.interfaces.RSAPrivateKey;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Base64;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
import java.util.Set;
-import java.util.Vector;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicBoolean;
import okhttp3.OkHttpClient;
import se.leap.bitmaskclient.R;
@@ -65,16 +52,14 @@ import se.leap.bitmaskclient.base.models.Provider;
import se.leap.bitmaskclient.base.models.ProviderObservable;
import se.leap.bitmaskclient.base.utils.CertificateHelper;
import se.leap.bitmaskclient.base.utils.FileHelper;
-import se.leap.bitmaskclient.base.utils.InputStreamHelper;
import se.leap.bitmaskclient.base.utils.BuildConfigHelper;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-import se.leap.bitmaskclient.base.utils.RSAHelper;
+import se.leap.bitmaskclient.base.utils.PrivateKeyHelper;
import se.leap.bitmaskclient.providersetup.ProviderApiConnector;
import se.leap.bitmaskclient.providersetup.connectivity.DnsResolver;
import se.leap.bitmaskclient.providersetup.connectivity.OkHttpClientGenerator;
import se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider;
import se.leap.bitmaskclient.testutils.matchers.BundleMatcher;
-import se.leap.bitmaskclient.tor.TorStatusObservable;
/**
* Created by cyberta on 29.01.18.
@@ -160,8 +145,8 @@ public class MockHelper {
return new FileHelper(new MockFileHelper(mockedFile));
}
- public static RSAHelper mockRSAHelper() {
- return new RSAHelper(rsaKeyString -> new RSAPrivateKey() {
+ public static PrivateKeyHelper mockPrivateKeyHelper() {
+ return new PrivateKeyHelper(rsaKeyString -> new RSAPrivateKey() {
@Override
public BigInteger getPrivateExponent() {
return BigInteger.TEN;
@@ -237,7 +222,7 @@ public class MockHelper {
PreferenceHelper preferenceHelper = new PreferenceHelper(sharedPreferences);
sharedPreferences.edit().
- putString(PROVIDER_PRIVATE_KEY, providerFromPrefs.getPrivateKey()).
+ putString(PROVIDER_PRIVATE_KEY, providerFromPrefs.getPrivateKeyString()).
putString(PROVIDER_VPN_CERTIFICATE, providerFromPrefs.getVpnCertificate()).
putString(Provider.KEY, providerFromPrefs.getDefinitionString()).
putString(Provider.CA_CERT_FINGERPRINT, providerFromPrefs.getCaCertFingerprint()).
@@ -257,7 +242,7 @@ public class MockHelper {
PreferenceHelper preferenceHelper = new PreferenceHelper(sharedPreferences);
sharedPreferences.edit().
- putString(PROVIDER_PRIVATE_KEY, provider.getPrivateKey()).
+ putString(PROVIDER_PRIVATE_KEY, provider.getPrivateKeyString()).
putString(PROVIDER_VPN_CERTIFICATE, provider.getVpnCertificate()).
putString(Provider.KEY, provider.getDefinitionString()).
putString(Provider.CA_CERT_FINGERPRINT, provider.getCaCertFingerprint()).
diff --git a/app/src/test/resources/private_ed25519_key.pem b/app/src/test/resources/private_ed25519_key.pem
new file mode 100644
index 00000000..eac4d4db
--- /dev/null
+++ b/app/src/test/resources/private_ed25519_key.pem
@@ -0,0 +1,3 @@
+-----BEGIN PRIVATE KEY-----
+MC4CAQAwBQYDK2VwBCIEIGVuE1J3PTf1TRv1xz5bXCyh5oXa3MieBg+Re9qGNZvU
+-----END PRIVATE KEY----- \ No newline at end of file