3

I am looking to implement a solution to open a L2TP/IPSEC connection from the android application so I can simply pass the server ip, pre-shared key, username and password and so the device is connected to this VPN server

I looked here https://developer.android.com/reference/android/net/VpnService.html that we need to extend and build our own VPN solutions to do that.

Is there any available solutions for that so we can use it instead of reinventing the wheel?

I tried the below implementations of VpnService but none of them worked for me

And tried this

and got the below error

mtpd: Start VPN daemon: mtpd W/libc: Set property "ctl.start" to "mtpd" Unable to set property "ctl.start" to "mtpd": connection failed; errno=13 (Permission denied) E/SysPropJNI: SystemProperties_set key:ctl.start,val:mtpd W/System.err: java.io.IOException: cannot start service: mtpd W/System.err: at com.mega.speed.vpn.DaemonProxy.start(DaemonProxy.java:58) W/System.err: at com.mega.speed.vpn.VpnDaemons.startDaemon(VpnDaemons.java:92) at com.mega.speed.vpn.VpnDaemons.startMtpd(VpnDaemons.java:113) at com.mega.speed.vpn.VpnDaemons.startL2tp(VpnDaemons.java:36) W/System.err: at com.mega.speed.vpn.L2tpService.connect(L2tpService.java:16) at com.mega.speed.fragments.HotspotFragment.onCreateView(HotspotFragment.java:125) W/System.err: at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460) W/System.err: at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) W/System.err: at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) W/System.err: at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) W/System.err: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733) at android.os.Handler.handleCallback(Handler.java:808) W/System.err:
at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7529) W/System.err: at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

Jad Chahine
  • 6,849
  • 8
  • 37
  • 59
  • If you are asking "how do I set up the device to use a VPN programmatically from my app?", that should not be possible except perhaps by device admin/device owner apps. If you are asking "how would I do L2TP/IPSEC from my app that is not itself a VPN?", I have no idea, as I have not implemented a VPN. – CommonsWare Jul 16 '19 at 19:35
  • @CommonsWare thanks, so you agree that the only possible way to open a vpn connection is to implement a VPN as we don't have anymore a vpn implementation in android? – Jad Chahine Jul 17 '19 at 12:26
  • We do have a VPN implementation in Android... for *users*. See Settings > Network & Internet > VPN on Android 9.0, for example. – CommonsWare Jul 17 '19 at 12:32
  • yes it's ok for this.. but I mean we don't have a native vpn implementation in android "programmatically", yes? – Jad Chahine Jul 17 '19 at 12:34
  • 1
    Well, that gets back to my original comment. I do not know what you are trying to do: programmatically set up a VPN the way the user can through Settings (hopefully not possible, at least for ordinary apps) or implement a VPN-style protocol in your own app (presumably possible, but I have not done it). – CommonsWare Jul 17 '19 at 12:36
  • yes I'm trying to implement a VPN-style protocol in my own app, I found some implemented solutions but it's not working.. thanks – Jad Chahine Jul 17 '19 at 13:46
  • @JadChahine Have you found any good solution for IPsec/L2TP protocol? – Noman Aziz Jul 19 '21 at 06:57
  • @NomanAziz unfortunately no ... – Jad Chahine Jul 19 '21 at 08:02
  • Have you tried with ics-openvpn? – Noman Aziz Jul 19 '21 at 09:29
  • the requirement asked by the networking team was to use IPsec/L2TP so I didn't tried other things – Jad Chahine Jul 19 '21 at 09:56

0 Answers0