summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2020-05-18 23:47:22 +0200
committerArne Schwabe <arne@rfc2549.org>2020-05-18 23:47:22 +0200
commit47ecc7c36a6a606965073c22a101e2b4695a53f3 (patch)
tree7dfbcb12b968766e85499cb4d09ea62b575486e0
parent9ffa99d5ae76eca272cc46fe160e4d048bbb4d97 (diff)
Fix tls-cryptv2 profile generation
-rw-r--r--main/build.gradle.kts2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/VpnProfile.java2
-rw-r--r--main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.kt76
3 files changed, 61 insertions, 19 deletions
diff --git a/main/build.gradle.kts b/main/build.gradle.kts
index 6f9c966f..7c4fa61a 100644
--- a/main/build.gradle.kts
+++ b/main/build.gradle.kts
@@ -181,7 +181,7 @@ dependencies {
dependencies.add("uiImplementation", "androidx.preference:preference:$preferenceVersion")
dependencies.add("uiImplementation", "androidx.preference:preference-ktx:$preferenceVersion")
dependencies.add("uiImplementation", "com.google.android.material:material:$materialVersion")
-
+ dependencies.add("uiImplementation", "androidx.webkit:webkit:1.2.0")
testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72")
testImplementation("junit:junit:4.13")
diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
index bf1b995b..e6815dcf 100644
--- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -501,7 +501,7 @@ public class VpnProfile implements Serializable, Cloneable {
else
cfg.append(insertFileData("tls-auth", mTLSAuthFilename));
- if (!TextUtils.isEmpty(mTLSAuthDirection) && !useTlsCrypt) {
+ if (!TextUtils.isEmpty(mTLSAuthDirection) && !useTlsCrypt && !useTlsCrypt2) {
cfg.append("key-direction ");
cfg.append(mTLSAuthDirection);
cfg.append("\n");
diff --git a/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.kt b/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.kt
index d4a4f61b..da887a0b 100644
--- a/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.kt
+++ b/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.kt
@@ -5,21 +5,17 @@
package de.blinkt.openvpn.core
-import android.app.Application
import android.content.Context
+import androidx.test.core.app.ApplicationProvider
import de.blinkt.openvpn.R
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
-
+import org.robolectric.annotation.Config
import java.io.IOException
import java.io.StringReader
-import java.util.Arrays
-
-import de.blinkt.openvpn.VpnProfile
-import org.robolectric.annotation.Config
+import java.util.*
/**
* Created by arne on 03.10.16.
@@ -74,13 +70,13 @@ class TestConfigParser {
cp.parseConfig(StringReader(miniconfig + fakeCerts))
val vp = cp.convertProfile()
- val outConfig = vp.getConfigFile(RuntimeEnvironment.application, false)
+ val outConfig = vp.getConfigFile(ApplicationProvider.getApplicationContext(), false)
cp = ConfigParser()
cp.parseConfig(StringReader(outConfig))
val vp2 = cp.convertProfile()
- val outConfig2 = vp2.getConfigFile(RuntimeEnvironment.application, false)
+ val outConfig2 = vp2.getConfigFile(ApplicationProvider.getApplicationContext(), false)
Assert.assertEquals(outConfig, outConfig2)
Assert.assertFalse(vp.mUseCustomConfig)
@@ -148,7 +144,7 @@ class TestConfigParser {
Assert.assertEquals("8080", vp.mConnections[2].mProxyPort)
Assert.assertEquals(Connection.ProxyType.HTTP, vp.mConnections[2].mProxyType)
- val c = RuntimeEnvironment.application
+ val c:Context = ApplicationProvider.getApplicationContext()
val err = vp.checkProfile(c, false)
Assert.assertTrue("Failed with " + c.getString(err), err == R.string.no_error_found)
}
@@ -190,11 +186,11 @@ class TestConfigParser {
val cp = ConfigParser()
cp.parseConfig(StringReader(proxy))
val vp = cp.convertProfile()
- var config = vp.getConfigFile(RuntimeEnvironment.application, true)
+ var config = vp.getConfigFile(ApplicationProvider.getApplicationContext(), true)
Assert.assertTrue(config.contains("username12"))
Assert.assertTrue(config.contains("http-proxy 1.2.3.4"))
- config = vp.getConfigFile(RuntimeEnvironment.application, false)
+ config = vp.getConfigFile(ApplicationProvider.getApplicationContext(), false)
Assert.assertFalse(config.contains("username12"))
Assert.assertFalse(config.contains("http-proxy 1.2.3.4"))
@@ -236,13 +232,13 @@ class TestConfigParser {
val cp = ConfigParser()
cp.parseConfig(StringReader(proxyconf))
val vp = cp.convertProfile()
- var config = vp.getConfigFile(RuntimeEnvironment.application, true)
+ var config = vp.getConfigFile(ApplicationProvider.getApplicationContext(), true)
- Assert.assertEquals(vp.checkProfile(RuntimeEnvironment.application, true).toLong(), R.string.no_error_found.toLong())
- Assert.assertEquals(vp.checkProfile(RuntimeEnvironment.application, false).toLong(), R.string.no_error_found.toLong())
+ Assert.assertEquals(vp.checkProfile(ApplicationProvider.getApplicationContext(), true).toLong(), R.string.no_error_found.toLong())
+ Assert.assertEquals(vp.checkProfile(ApplicationProvider.getApplicationContext(), false).toLong(), R.string.no_error_found.toLong())
- config = vp.getConfigFile(RuntimeEnvironment.application, false)
+ config = vp.getConfigFile(ApplicationProvider.getApplicationContext(), false)
Assert.assertTrue(config.contains("http-proxy 1.2.3.4"))
Assert.assertFalse(config.contains("management-query-proxy"))
@@ -255,8 +251,54 @@ class TestConfigParser {
vp.mConnections[vp.mConnections.size - 1].mProxyType = Connection.ProxyType.ORBOT
- Assert.assertEquals(vp.checkProfile(RuntimeEnvironment.application, false).toLong(), R.string.error_orbot_and_proxy_options.toLong())
+ Assert.assertEquals(vp.checkProfile(ApplicationProvider.getApplicationContext(), false).toLong(), R.string.error_orbot_and_proxy_options.toLong())
+
+ }
+
+
+ @Test
+ fun testTlscryptV2Import()
+ {
+ val conf = """<ca>
+Here
+</ca>
+
+<cert>
+no
+</cert>
+
+cipher AES-256-GCM
+client
+compress
+dev-type tun
+explicit-exit-notify
+<key>
+useful
+</key>
+nobind
+persist-key
+persist-tun
+remote home.evil.cloud 65443 udp
+remote home.evil.cloud 65443 tcp-client
+remote-cert-tls server
+<tls-crypt-v2>
+content
+</tls-crypt-v2>
+topology subnet
+verb 4
+verify-x509-name homevpn.evil.cloud name
+
+""";
+ val cp = ConfigParser()
+ cp.parseConfig(StringReader(conf))
+
+ val vp = cp.convertProfile()
+
+ val config = vp.getConfigFile(ApplicationProvider.getApplicationContext(), true)
+
+ Assert.assertEquals("tls-crypt-v2", vp.mTLSAuthDirection)
+ Assert.assertFalse(config.contains("key-direction"))
}
}