add openvpn connection logic draft
This commit is contained in:
parent
c057786011
commit
1ceee8901e
6 changed files with 527 additions and 322 deletions
|
@ -14,8 +14,17 @@
|
|||
<!-- %%INSERT_FEATURES -->
|
||||
|
||||
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
|
||||
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:extractNativeLibs="true">
|
||||
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop">
|
||||
<application
|
||||
android:hardwareAccelerated="true"
|
||||
android:name="org.qtproject.qt5.android.bindings.QtApplication"
|
||||
android:label="-- %%INSERT_APP_NAME%% --"
|
||||
android:extractNativeLibs="true">
|
||||
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
|
||||
android:name="org.qtproject.qt5.android.bindings.QtActivity"
|
||||
|
||||
android:label="-- %%INSERT_APP_NAME%% --"
|
||||
android:screenOrientation="unspecified"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
|
@ -83,13 +92,14 @@
|
|||
</activity>
|
||||
|
||||
<service android:name=".VPNService"
|
||||
|
||||
android:permission="android.permission.BIND_VPN_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.VpnService"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service android:name="org.amnezia.vpn.qt.VPNPermissionHelper"
|
||||
android:process=":QtOnlyProcess"
|
||||
|
||||
android:permission="android.permission.BIND_VPN_SERVICE">
|
||||
</service>
|
||||
|
||||
|
|
113
client/android/src/org/amnezia/vpn/OpenVPNThreadv3.kt
Normal file
113
client/android/src/org/amnezia/vpn/OpenVPNThreadv3.kt
Normal file
|
@ -0,0 +1,113 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.amnezia.vpn
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.system.OsConstants
|
||||
import java.io.File
|
||||
import com.wireguard.android.util.SharedLibraryLoader
|
||||
import com.wireguard.config.*
|
||||
import com.wireguard.crypto.Key
|
||||
import org.json.JSONObject
|
||||
|
||||
import net.openvpn.ovpn3.ClientAPI_Config
|
||||
import net.openvpn.ovpn3.ClientAPI_EvalConfig
|
||||
import net.openvpn.ovpn3.ClientAPI_Event
|
||||
import net.openvpn.ovpn3.ClientAPI_ExternalPKICertRequest
|
||||
import net.openvpn.ovpn3.ClientAPI_ExternalPKISignRequest
|
||||
import net.openvpn.ovpn3.ClientAPI_LogInfo
|
||||
import net.openvpn.ovpn3.ClientAPI_OpenVPNClient
|
||||
import net.openvpn.ovpn3.ClientAPI_ProvideCreds
|
||||
import net.openvpn.ovpn3.ClientAPI_Status
|
||||
import net.openvpn.ovpn3.ClientAPI_TransportStats
|
||||
|
||||
class OpenVPNThreadv3(var service: VPNService): ClientAPI_OpenVPNClient(), Runnable {
|
||||
private val tag = "OpenVPNThreadv3"
|
||||
private var mConfig: JSONObject? = null
|
||||
private var mConnectionTime: Long = 0
|
||||
private var mAlreadyInitialised = false
|
||||
private var mService: VPNService = service
|
||||
|
||||
private var currentTunnelHandle = -1
|
||||
|
||||
override fun run() {
|
||||
//TEMP
|
||||
Log.i(tag, "run()")
|
||||
val lConfigData: String = readFileDirectlyAsText("/data/local/tmp/osinit.ovpn")
|
||||
val config: ClientAPI_Config = ClientAPI_Config()
|
||||
config.content = lConfigData
|
||||
|
||||
val lCreds: ClientAPI_ProvideCreds = ClientAPI_ProvideCreds()
|
||||
//username from config or GUI
|
||||
lCreds.username = "username"
|
||||
//password from config or GUI
|
||||
lCreds.password = "password"
|
||||
|
||||
provide_creds(lCreds)
|
||||
|
||||
|
||||
eval_config(config)
|
||||
connect()
|
||||
Log.i(tag, "connect()")
|
||||
}
|
||||
|
||||
fun readFileDirectlyAsText(fileName: String): String = File(fileName).readText(Charsets.UTF_8)
|
||||
|
||||
override fun log(arg0: ClientAPI_LogInfo){
|
||||
Log.i(tag, arg0.getText())
|
||||
}
|
||||
|
||||
override fun event(event: ClientAPI_Event ){
|
||||
Log.i(tag, event.getName())
|
||||
}
|
||||
|
||||
|
||||
|
||||
// override fun reconnect() {
|
||||
// reconnect(1);
|
||||
// }
|
||||
override fun tun_builder_new(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun tun_builder_establish(): Int {
|
||||
Log.v(tag, "tun_builder_establish")
|
||||
return mService.turnOn(null)!!.detachFd()
|
||||
}
|
||||
|
||||
override fun tun_builder_add_address(address: String , prefix_length: Int , gateway: String , ipv6:Boolean , net30: Boolean ): Boolean {
|
||||
Log.v(tag, "tun_builder_add_address")
|
||||
mService.addAddress(address, prefix_length)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun tun_builder_add_route(address: String, prefix_length: Int, metric: Int, ipv6: Boolean): Boolean {
|
||||
if (address.equals("remote_host"))
|
||||
return false
|
||||
|
||||
mService.addRoute(address, prefix_length);
|
||||
return true
|
||||
}
|
||||
|
||||
override fun tun_builder_set_remote_address(address: String , ipv6: Boolean): Boolean {
|
||||
mService.setMtu(1500)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun tun_builder_set_mtu(mtu: Int): Boolean {
|
||||
mService.setMtu(mtu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun tun_builder_add_dns_server(address: String , ipv6: Boolean): Boolean {
|
||||
mService.addDNS(address)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.amnezia.vpn
|
||||
|
||||
|
@ -8,6 +8,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.os.ParcelFileDescriptor
|
||||
import android.system.OsConstants
|
||||
import com.wireguard.android.util.SharedLibraryLoader
|
||||
import com.wireguard.config.*
|
||||
|
@ -20,7 +21,10 @@ class VPNService : android.net.VpnService() {
|
|||
private var mConfig: JSONObject? = null
|
||||
private var mConnectionTime: Long = 0
|
||||
private var mAlreadyInitialised = false
|
||||
private var mbuilder: Builder = Builder()
|
||||
|
||||
|
||||
private var mOpenVPNThreadv3: OpenVPNThreadv3? = null
|
||||
private var currentTunnelHandle = -1
|
||||
|
||||
fun init() {
|
||||
|
@ -29,9 +33,12 @@ class VPNService : android.net.VpnService() {
|
|||
}
|
||||
Log.init(this)
|
||||
SharedLibraryLoader.loadSharedLibrary(this, "wg-go")
|
||||
Log.i(tag, "loaded lib")
|
||||
SharedLibraryLoader.loadSharedLibrary(this, "ovpn3")
|
||||
Log.i(tag, "Loaded libs")
|
||||
Log.e(tag, "Wireguard Version ${wgVersion()}")
|
||||
mOpenVPNThreadv3 = OpenVPNThreadv3 (this)
|
||||
mAlreadyInitialised = true
|
||||
|
||||
}
|
||||
|
||||
override fun onUnbind(intent: Intent?): Boolean {
|
||||
|
@ -60,28 +67,32 @@ class VPNService : android.net.VpnService() {
|
|||
*/
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
init()
|
||||
intent?.let {
|
||||
if (intent.getBooleanExtra("startOnly", false)) {
|
||||
Log.i(tag, "Start only!")
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
}
|
||||
// This start is from always-on
|
||||
if (this.mConfig == null) {
|
||||
// We don't have tunnel to turn on - Try to create one with last config the service got
|
||||
val prefs = Prefs.get(this)
|
||||
val lastConfString = prefs.getString("lastConf", "")
|
||||
if (lastConfString.isNullOrEmpty()) {
|
||||
// We have nothing to connect to -> Exit
|
||||
Log.e(
|
||||
tag,
|
||||
"VPN service was triggered without defining a Server or having a tunnel"
|
||||
)
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
this.mConfig = JSONObject(lastConfString)
|
||||
}
|
||||
turnOn(this.mConfig!!)
|
||||
// intent?.let {
|
||||
// if (intent.getBooleanExtra("startOnly", false)) {
|
||||
// Log.i(tag, "Start only!")
|
||||
// return super.onStartCommand(intent, flags, startId)
|
||||
// }
|
||||
// }
|
||||
// // This start is from always-on
|
||||
// if (this.mConfig == null) {
|
||||
// // We don't have tunnel to turn on - Try to create one with last config the service got
|
||||
// val prefs = Prefs.get(this)
|
||||
// val lastConfString = prefs.getString("lastConf", "")
|
||||
// if (lastConfString.isNullOrEmpty()) {
|
||||
// // We have nothing to connect to -> Exit
|
||||
// Log.e(
|
||||
// tag,
|
||||
// "VPN service was triggered without defining a Server or having a tunnel"
|
||||
// )
|
||||
// return super.onStartCommand(intent, flags, startId)
|
||||
// }
|
||||
// this.mConfig = JSONObject(lastConfString)
|
||||
// }
|
||||
|
||||
|
||||
// Log.v(tag, "onStartCommand:" + this.mConfig)
|
||||
// turnOn(this.mConfig)
|
||||
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
|
@ -138,55 +149,105 @@ class VPNService : android.net.VpnService() {
|
|||
return false
|
||||
}
|
||||
|
||||
fun turnOn(json: JSONObject) {
|
||||
Log.sensitive(tag, json.toString())
|
||||
val wireguard_conf = buildWireugardConfig(json)
|
||||
fun turnOn(json: JSONObject?): ParcelFileDescriptor? {
|
||||
Log.sensitive(tag, "" + json.toString())
|
||||
// val wireguard_conf = buildWireugardConfig(json)
|
||||
|
||||
if (!checkPermissions()) {
|
||||
Log.e(tag, "turn on was called without no permissions present!")
|
||||
isUp = false
|
||||
return
|
||||
return null
|
||||
}
|
||||
Log.i(tag, "Permission okay")
|
||||
if (currentTunnelHandle != -1) {
|
||||
Log.e(tag, "Tunnel already up")
|
||||
// Turn the tunnel down because this might be a switch
|
||||
wgTurnOff(currentTunnelHandle)
|
||||
}
|
||||
val wgConfig: String = wireguard_conf!!.toWgUserspaceString()
|
||||
val builder = Builder()
|
||||
setupBuilder(wireguard_conf, builder)
|
||||
builder.setSession("mvpn0")
|
||||
builder.establish().use { tun ->
|
||||
if (tun == null)return
|
||||
Log.i(tag, "Go backend " + wgVersion())
|
||||
currentTunnelHandle = wgTurnOn("mvpn0", tun.detachFd(), wgConfig)
|
||||
}
|
||||
if (currentTunnelHandle < 0) {
|
||||
Log.e(tag, "Activation Error Code -> $currentTunnelHandle")
|
||||
isUp = false
|
||||
return
|
||||
}
|
||||
protect(wgGetSocketV4(currentTunnelHandle))
|
||||
protect(wgGetSocketV6(currentTunnelHandle))
|
||||
mConfig = json
|
||||
isUp = true
|
||||
// Log.i(tag, "Permission okay")
|
||||
// if (currentTunnelHandle != -1) {
|
||||
// Log.e(tag, "Tunnel already up")
|
||||
// // Turn the tunnel down because this might be a switch
|
||||
// wgTurnOff(currentTunnelHandle)
|
||||
// }
|
||||
// val wgConfig: String = wireguard_conf!!.toWgUserspaceString()
|
||||
// val builder = Builder()
|
||||
// setupBuilder(wireguard_conf, builder)
|
||||
// builder.setSession("mvpn0")
|
||||
// builder.establish().use { tun ->
|
||||
// if (tun == null)return
|
||||
// Log.i(tag, "Go backend " + wgVersion())
|
||||
// currentTunnelHandle = wgTurnOn("mvpn0", tun.detachFd(), wgConfig)
|
||||
// }
|
||||
// if (currentTunnelHandle < 0) {
|
||||
// Log.e(tag, "Activation Error Code -> $currentTunnelHandle")
|
||||
// isUp = false
|
||||
// return
|
||||
// }
|
||||
// protect(wgGetSocketV4(currentTunnelHandle))
|
||||
// protect(wgGetSocketV6(currentTunnelHandle))
|
||||
// mConfig = json
|
||||
// isUp = true
|
||||
|
||||
// Store the config in case the service gets
|
||||
// asked boot vpn from the OS
|
||||
val prefs = Prefs.get(this)
|
||||
prefs.edit()
|
||||
.putString("lastConf", json.toString())
|
||||
.apply()
|
||||
// // Store the config in case the service gets
|
||||
// // asked boot vpn from the OS
|
||||
// val prefs = Prefs.get(this)
|
||||
// prefs.edit()
|
||||
// .putString("lastConf", json.toString())
|
||||
// .apply()
|
||||
|
||||
// NotificationUtil.show(this) // Go foreground
|
||||
|
||||
// val builder = Builder()
|
||||
// // setupBuilder(wireguard_conf, builder)
|
||||
// builder.addAddress("192.168.194.1", 24)
|
||||
// builder.addDnsServer("8.8.8.8")
|
||||
// builder.addRoute("0.0.0.0", 0)
|
||||
// builder.setSession("mvpn0")
|
||||
// builder.establish()
|
||||
|
||||
|
||||
// Configure a new interface from our VpnService instance. This must be done
|
||||
// from inside a VpnService.
|
||||
|
||||
// val builder = Builder()
|
||||
// Create a local TUN interface using predetermined addresses. In your app,
|
||||
// you typically use values returned from the VPN gateway during handshaking.
|
||||
// val localTunnel = builder
|
||||
// .addAddress("10.0.20.1", 0)
|
||||
// .addRoute("192.168.111.0", 24)
|
||||
// .addDnsServer("192.168.111.1")
|
||||
// .establish()
|
||||
val localTunnel = mbuilder.establish()
|
||||
|
||||
Log.v(tag, "builder.establish()")
|
||||
|
||||
startOpenVpn()
|
||||
|
||||
return localTunnel
|
||||
|
||||
NotificationUtil.show(this) // Go foreground
|
||||
}
|
||||
|
||||
|
||||
fun setMtu(mtu: Int) {
|
||||
Log.v(tag, "setMtu()" + mtu)
|
||||
mbuilder.setMtu(mtu)
|
||||
}
|
||||
|
||||
fun addAddress(ip: String, len: Int){
|
||||
Log.v(tag, "addAddress()" + ip + " " + len)
|
||||
mbuilder.addAddress(ip, len)
|
||||
}
|
||||
|
||||
fun addRoute(ip: String, len: Int){
|
||||
Log.v(tag, "addRoute()" + ip + " " + len)
|
||||
mbuilder.addRoute(ip, len)
|
||||
}
|
||||
|
||||
fun addDNS(ip: String){
|
||||
mbuilder.addDnsServer(ip)
|
||||
}
|
||||
|
||||
|
||||
fun turnOff() {
|
||||
Log.v(tag, "Try to disable tunnel")
|
||||
wgTurnOff(currentTunnelHandle)
|
||||
currentTunnelHandle = -1
|
||||
stopForeground(false)
|
||||
// wgTurnOff(currentTunnelHandle)
|
||||
// currentTunnelHandle = -1
|
||||
// stopForeground(false)
|
||||
isUp = false
|
||||
}
|
||||
|
||||
|
@ -242,7 +303,7 @@ class VPNService : android.net.VpnService() {
|
|||
|
||||
/**
|
||||
* Create a Wireguard [Config] from a [json] string -
|
||||
* The [json] will be created in AndroidController.cpp
|
||||
* The [json] will be created in AndroidVpnProtocol.cpp
|
||||
*/
|
||||
private fun buildWireugardConfig(obj: JSONObject): Config {
|
||||
val confBuilder = Config.Builder()
|
||||
|
@ -283,6 +344,14 @@ class VPNService : android.net.VpnService() {
|
|||
return confBuilder.build()
|
||||
}
|
||||
|
||||
|
||||
private fun startOpenVpn() {
|
||||
Thread ({
|
||||
mOpenVPNThreadv3?.run()
|
||||
}).start()
|
||||
Log.i(tag, "OpenVPNThreadv3 start")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun startService(c: Context) {
|
||||
|
@ -306,4 +375,4 @@ class VPNService : android.net.VpnService() {
|
|||
@JvmStatic
|
||||
private external fun wgVersion(): String?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.amnezia.vpn
|
||||
import android.os.Binder
|
||||
|
@ -31,6 +31,7 @@ class VPNServiceBinder(service: VPNService) : Binder() {
|
|||
const val resumeActivate = 7
|
||||
const val setNotificationText = 8
|
||||
const val setFallBackNotification = 9
|
||||
const val myLog = 10
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,10 +50,11 @@ class VPNServiceBinder(service: VPNService) : Binder() {
|
|||
ACTIONS.activate -> {
|
||||
try {
|
||||
Log.i(tag, "Activiation Requested, parsing Config")
|
||||
// [data] is here a json containing the wireguard conf
|
||||
// [data] is here a json containing the wireguard/openvpn conf
|
||||
val buffer = data.createByteArray()
|
||||
val json = buffer?.let { String(it) }
|
||||
val config = JSONObject(json)
|
||||
Log.v(tag, "config: " + config.toString())
|
||||
Log.v(tag, "Stored new Tunnel config in Service")
|
||||
|
||||
if (!mService.checkPermissions()) {
|
||||
|
@ -95,6 +97,7 @@ class VPNServiceBinder(service: VPNService) : Binder() {
|
|||
obj.put("connected", mService.isUp)
|
||||
obj.put("time", mService.connectionTime)
|
||||
dispatchEvent(EVENTS.init, obj.toString())
|
||||
Log.i(tag, "ACTIONS.registerEventListener")
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -117,7 +120,7 @@ class VPNServiceBinder(service: VPNService) : Binder() {
|
|||
return true
|
||||
}
|
||||
ACTIONS.setFallBackNotification -> {
|
||||
NotificationUtil.saveFallBackMessage(data, mService)
|
||||
// NotificationUtil.saveFallBackMessage(data, mService)
|
||||
return true
|
||||
}
|
||||
IBinder.LAST_CALL_TRANSACTION -> {
|
||||
|
@ -167,4 +170,4 @@ class VPNServiceBinder(service: VPNService) : Binder() {
|
|||
const val backendLogs = 4
|
||||
const val activationError = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,18 @@ package org.amnezia.vpn.qt
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
|
||||
class VPNPermissionHelper : android.net.VpnService() {
|
||||
|
||||
private val tag = "VPNPermissionHelper"
|
||||
/**
|
||||
* This small service does nothing else then checking if the vpn permission
|
||||
* is present and prompting if not.
|
||||
*/
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
val intent = prepare(this.applicationContext)
|
||||
Log.i(tag, "VPNPermissionHelper onStartCommand")
|
||||
if (intent != null) {
|
||||
startActivityForResult(intent)
|
||||
}
|
||||
|
|
|
@ -271,63 +271,69 @@ ErrorCode VpnConnection::connectToVpn(int serverIndex,
|
|||
m_vpnProtocol.reset();
|
||||
}
|
||||
|
||||
if (container == DockerContainer::None || container == DockerContainer::OpenVpn) {
|
||||
ErrorCode e = createVpnConfiguration(serverIndex, credentials, DockerContainer::OpenVpn, containerConfig);
|
||||
if (e) {
|
||||
emit connectionStateChanged(VpnProtocol::Error);
|
||||
return e;
|
||||
}
|
||||
// if (container == DockerContainer::None || container == DockerContainer::OpenVpn) {
|
||||
// ErrorCode e = createVpnConfiguration(serverIndex, credentials, DockerContainer::OpenVpn, containerConfig);
|
||||
// if (e) {
|
||||
// emit connectionStateChanged(VpnProtocol::Error);
|
||||
// return e;
|
||||
// }
|
||||
|
||||
m_vpnProtocol.reset(new OpenVpnProtocol(m_vpnConfiguration));
|
||||
e = static_cast<OpenVpnProtocol *>(m_vpnProtocol.data())->checkAndSetupTapDriver();
|
||||
if (e) {
|
||||
emit connectionStateChanged(VpnProtocol::Error);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
else if (container == DockerContainer::ShadowSocks) {
|
||||
ErrorCode e = createVpnConfiguration(serverIndex, credentials, DockerContainer::ShadowSocks, containerConfig);
|
||||
if (e) {
|
||||
emit connectionStateChanged(VpnProtocol::Error);
|
||||
return e;
|
||||
}
|
||||
// m_vpnProtocol.reset(new OpenVpnProtocol(m_vpnConfiguration));
|
||||
// e = static_cast<OpenVpnProtocol *>(m_vpnProtocol.data())->checkAndSetupTapDriver();
|
||||
// if (e) {
|
||||
// emit connectionStateChanged(VpnProtocol::Error);
|
||||
// return e;
|
||||
// }
|
||||
// }
|
||||
// else if (container == DockerContainer::ShadowSocks) {
|
||||
// ErrorCode e = createVpnConfiguration(serverIndex, credentials, DockerContainer::ShadowSocks, containerConfig);
|
||||
// if (e) {
|
||||
// emit connectionStateChanged(VpnProtocol::Error);
|
||||
// return e;
|
||||
// }
|
||||
|
||||
m_vpnProtocol.reset(new ShadowSocksVpnProtocol(m_vpnConfiguration));
|
||||
e = static_cast<OpenVpnProtocol *>(m_vpnProtocol.data())->checkAndSetupTapDriver();
|
||||
if (e) {
|
||||
emit connectionStateChanged(VpnProtocol::Error);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
else if (container == DockerContainer::Cloak) {
|
||||
ErrorCode e = createVpnConfiguration(serverIndex, credentials, DockerContainer::Cloak, containerConfig);
|
||||
if (e) {
|
||||
emit connectionStateChanged(VpnProtocol::Error);
|
||||
return e;
|
||||
}
|
||||
// m_vpnProtocol.reset(new ShadowSocksVpnProtocol(m_vpnConfiguration));
|
||||
// e = static_cast<OpenVpnProtocol *>(m_vpnProtocol.data())->checkAndSetupTapDriver();
|
||||
// if (e) {
|
||||
// emit connectionStateChanged(VpnProtocol::Error);
|
||||
// return e;
|
||||
// }
|
||||
// }
|
||||
// else if (container == DockerContainer::Cloak) {
|
||||
// ErrorCode e = createVpnConfiguration(serverIndex, credentials, DockerContainer::Cloak, containerConfig);
|
||||
// if (e) {
|
||||
// emit connectionStateChanged(VpnProtocol::Error);
|
||||
// return e;
|
||||
// }
|
||||
|
||||
m_vpnProtocol.reset(new OpenVpnOverCloakProtocol(m_vpnConfiguration));
|
||||
e = static_cast<OpenVpnProtocol *>(m_vpnProtocol.data())->checkAndSetupTapDriver();
|
||||
if (e) {
|
||||
emit connectionStateChanged(VpnProtocol::Error);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
else if (container == DockerContainer::WireGuard) {
|
||||
ErrorCode e = createVpnConfiguration(serverIndex, credentials, DockerContainer::WireGuard, containerConfig);
|
||||
if (e) {
|
||||
emit connectionStateChanged(VpnProtocol::Error);
|
||||
return e;
|
||||
}
|
||||
// m_vpnProtocol.reset(new OpenVpnOverCloakProtocol(m_vpnConfiguration));
|
||||
// e = static_cast<OpenVpnProtocol *>(m_vpnProtocol.data())->checkAndSetupTapDriver();
|
||||
// if (e) {
|
||||
// emit connectionStateChanged(VpnProtocol::Error);
|
||||
// return e;
|
||||
// }
|
||||
// }
|
||||
// else if (container == DockerContainer::WireGuard) {
|
||||
// ErrorCode e = createVpnConfiguration(serverIndex, credentials, DockerContainer::WireGuard, containerConfig);
|
||||
// if (e) {
|
||||
// emit connectionStateChanged(VpnProtocol::Error);
|
||||
// return e;
|
||||
// }
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
AndroidVpnProtocol *androidVpnProtocol = new AndroidVpnProtocol(Protocol::WireGuard, m_vpnConfiguration);
|
||||
//#ifdef Q_OS_ANDROID
|
||||
// AndroidVpnProtocol *androidVpnProtocol = new AndroidVpnProtocol(Protocol::WireGuard, m_vpnConfiguration);
|
||||
// androidVpnProtocol->initialize();
|
||||
// m_vpnProtocol.reset(androidVpnProtocol);
|
||||
//#else
|
||||
// m_vpnProtocol.reset(new WireguardProtocol(m_vpnConfiguration));
|
||||
//#endif
|
||||
// }
|
||||
|
||||
|
||||
|
||||
AndroidVpnProtocol *androidVpnProtocol = new AndroidVpnProtocol(Protocol::OpenVpn, m_vpnConfiguration);
|
||||
androidVpnProtocol->initialize();
|
||||
m_vpnProtocol.reset(androidVpnProtocol);
|
||||
#else
|
||||
m_vpnProtocol.reset(new WireguardProtocol(m_vpnConfiguration));
|
||||
#endif
|
||||
}
|
||||
|
||||
connect(m_vpnProtocol.data(), &VpnProtocol::protocolError, this, &VpnConnection::vpnProtocolError);
|
||||
connect(m_vpnProtocol.data(), SIGNAL(connectionStateChanged(VpnProtocol::ConnectionState)), this, SLOT(onConnectionStateChanged(VpnProtocol::ConnectionState)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue