New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you add support for VPN service for android? #5

Open
crocket opened this Issue Dec 16, 2013 · 16 comments

Comments

Projects
None yet
9 participants
@crocket

crocket commented Dec 16, 2013

People ported openvpn to android as ics-openvpn.
Perhaps, tinc could be ported to android with support for VPN service, too.

With built-in VPN service, I wouldn't have to root my device.

@Vilbrekin

This comment has been minimized.

Show comment
Hide comment
@Vilbrekin

Vilbrekin Jan 30, 2014

Owner

Interesting idea indeed. However it would require an important amount of work which I can't deal with right now.
There's also a limitation on Android's VPN interface, which limit's it to TUN mode, while I mainly use TAP mode.

Owner

Vilbrekin commented Jan 30, 2014

Interesting idea indeed. However it would require an important amount of work which I can't deal with right now.
There's also a limitation on Android's VPN interface, which limit's it to TUN mode, while I mainly use TAP mode.

@msva

This comment has been minimized.

Show comment
Hide comment
@msva

msva Mar 12, 2014

So, as far as I understand your comments from #6 and here — it is impossible to just give a vpn-group permission for application in android?

msva commented Mar 12, 2014

So, as far as I understand your comments from #6 and here — it is impossible to just give a vpn-group permission for application in android?

@Vilbrekin

This comment has been minimized.

Show comment
Hide comment
@Vilbrekin

Vilbrekin Mar 12, 2014

Owner

Indeed, I tried yesterday and the process didn't get access to /dev/tun either.
Looking at the documentation, I don't think this is the purpose of the BIND_VPN_SERVICE permission.

Owner

Vilbrekin commented Mar 12, 2014

Indeed, I tried yesterday and the process didn't get access to /dev/tun either.
Looking at the documentation, I don't think this is the purpose of the BIND_VPN_SERVICE permission.

@sandymac

This comment has been minimized.

Show comment
Hide comment
@sandymac

sandymac Jun 24, 2014

My untested, unreliable understanding is this:

  • Adding android.permission.BIND_VPN_SERVICE to the app's service give it's access to the vpn group and thus access to /dev/tun http://developer.android.com/reference/android/net/VpnService.html
  • This would not grant root privileges so that ifconfig/route/ip could be executed. There apears to be a Builder inferface for this http://developer.android.com/reference/android/net/VpnService.Builder.html Sadly they only include add commands.
  • It tinc_gui were to insert provided stub ifconfig/route/ip commands to the PATH for the tinc-up scripts and these commands communicated back to tinc_gui which add* command to execute you may be able to get a non-root tinc working correctly until a subnet-down was needed.

sandymac commented Jun 24, 2014

My untested, unreliable understanding is this:

  • Adding android.permission.BIND_VPN_SERVICE to the app's service give it's access to the vpn group and thus access to /dev/tun http://developer.android.com/reference/android/net/VpnService.html
  • This would not grant root privileges so that ifconfig/route/ip could be executed. There apears to be a Builder inferface for this http://developer.android.com/reference/android/net/VpnService.Builder.html Sadly they only include add commands.
  • It tinc_gui were to insert provided stub ifconfig/route/ip commands to the PATH for the tinc-up scripts and these commands communicated back to tinc_gui which add* command to execute you may be able to get a non-root tinc working correctly until a subnet-down was needed.
@gujiejie

This comment has been minimized.

Show comment
Hide comment
@gujiejie

gujiejie Jun 24, 2014

very well thanks

gujiejie commented Jun 24, 2014

very well thanks

@Vilbrekin

This comment has been minimized.

Show comment
Hide comment
@Vilbrekin

Vilbrekin Jun 24, 2014

Owner

@sandymac: thanks for your comments. However as per my testing, the BIND_VPN_SERVICE permission doesn't give the app access to /dev/tun device, which is needed for the standalone daemon to use it.

Owner

Vilbrekin commented Jun 24, 2014

@sandymac: thanks for your comments. However as per my testing, the BIND_VPN_SERVICE permission doesn't give the app access to /dev/tun device, which is needed for the standalone daemon to use it.

@stv0g

This comment has been minimized.

Show comment
Hide comment
@stv0g

stv0g Jul 6, 2014

Hi,
Probably we can work around tun/tap devices at all.
I think we can use tinc's "DeviceType" option to implement an alternative.
There's already a device type called "uml" which send/receive IP packets over standard Unix sockets.

TincGui would need to register an Android VPN service via android.net.VpnService and create a Unix socket via android.net.LocalSocket.

Androids VPN service interface provides a file descriptor for sending/receiving IP packets. This file descriptor must then be forwarded to the local Unix socket.

Unfortunately my Java skills are somehow limited to implement this. But I' willing to put some effort in creating the socket support for tinc.

Cheers,
Steffen

stv0g commented Jul 6, 2014

Hi,
Probably we can work around tun/tap devices at all.
I think we can use tinc's "DeviceType" option to implement an alternative.
There's already a device type called "uml" which send/receive IP packets over standard Unix sockets.

TincGui would need to register an Android VPN service via android.net.VpnService and create a Unix socket via android.net.LocalSocket.

Androids VPN service interface provides a file descriptor for sending/receiving IP packets. This file descriptor must then be forwarded to the local Unix socket.

Unfortunately my Java skills are somehow limited to implement this. But I' willing to put some effort in creating the socket support for tinc.

Cheers,
Steffen

@culugyx

This comment has been minimized.

Show comment
Hide comment
@culugyx

culugyx Jan 7, 2017

I have created a patchset for non-root/VpnService use. The repo is at https://github.com/culugyx/tinc_gui

It's not intensively tested/documented and might be unstable, but at least works here, on android M.

culugyx commented Jan 7, 2017

I have created a patchset for non-root/VpnService use. The repo is at https://github.com/culugyx/tinc_gui

It's not intensively tested/documented and might be unstable, but at least works here, on android M.

@culugyx

This comment has been minimized.

Show comment
Hide comment
@culugyx

culugyx Jan 7, 2017

@stv0g I think ics-openvpn has a similar architecture to your idea (sending/receiving file descriptors). Here I avoided fd transferring by linking tinc directly to tinc_gui and use JNI. Passing fds is much easier in a single process.

culugyx commented Jan 7, 2017

@stv0g I think ics-openvpn has a similar architecture to your idea (sending/receiving file descriptors). Here I avoided fd transferring by linking tinc directly to tinc_gui and use JNI. Passing fds is much easier in a single process.

@Vilbrekin

This comment has been minimized.

Show comment
Hide comment
@Vilbrekin

Vilbrekin Jan 7, 2017

Owner

Thanks for sharing. I'm surprised how few java code is actually required for this change.
Would be nice keeping both possibilities however (root + non root), as I think Android VPN services do not support TAP mode.

Owner

Vilbrekin commented Jan 7, 2017

Thanks for sharing. I'm surprised how few java code is actually required for this change.
Would be nice keeping both possibilities however (root + non root), as I think Android VPN services do not support TAP mode.

@culugyx

This comment has been minimized.

Show comment
Hide comment
@culugyx

culugyx Jan 8, 2017

VpnService appears only to support TUN mode (IFF_TUN | IFF_NO_PI):
https://android.googlesource.com/platform/frameworks/base/+/android-6.0.1_r77/services/core/jni/com_android_server_connectivity_Vpn.cpp

If both modes are to be kept, maybe we can use pref_key_super_user to determine which mode to use. A few more Java code will be necessary (of which I'm not quite familiar). On the JNI side, tinc can be compiled twice as both shared lib and executable with different flags.

Currently, I tried to add reconnect_on_net_change function, but it still crashes occasionally on network changes.

culugyx commented Jan 8, 2017

VpnService appears only to support TUN mode (IFF_TUN | IFF_NO_PI):
https://android.googlesource.com/platform/frameworks/base/+/android-6.0.1_r77/services/core/jni/com_android_server_connectivity_Vpn.cpp

If both modes are to be kept, maybe we can use pref_key_super_user to determine which mode to use. A few more Java code will be necessary (of which I'm not quite familiar). On the JNI side, tinc can be compiled twice as both shared lib and executable with different flags.

Currently, I tried to add reconnect_on_net_change function, but it still crashes occasionally on network changes.

@msva

This comment has been minimized.

Show comment
Hide comment
@msva

msva Jan 11, 2017

It will definitely be nice to have possibility to use Mode=switch (tap) without root.
And, unfortunatelly, I can't see a way for that except like @stv0g said :(

msva commented Jan 11, 2017

It will definitely be nice to have possibility to use Mode=switch (tap) without root.
And, unfortunatelly, I can't see a way for that except like @stv0g said :(

@culugyx

This comment has been minimized.

Show comment
Hide comment
@culugyx

culugyx Jan 19, 2017

I've made changes so that both root and non-root mode can co-exist and switch depend on use_super_user.

culugyx commented Jan 19, 2017

I've made changes so that both root and non-root mode can co-exist and switch depend on use_super_user.

@codemac

This comment has been minimized.

Show comment
Hide comment
@codemac

codemac Feb 25, 2017

@culugyx do you have an apk or anything? Would really love this feature!

codemac commented Feb 25, 2017

@culugyx do you have an apk or anything? Would really love this feature!

@culugyx

This comment has been minimized.

Show comment
Hide comment
@culugyx

culugyx Feb 27, 2017

@codemac
Hi, I've uploaded an apk to my repository for preview.

https://github.com/culugyx/tinc_gui/wiki
https://github.com/culugyx/tinc_gui/releases (please read the warnings before trying it)

culugyx commented Feb 27, 2017

@codemac
Hi, I've uploaded an apk to my repository for preview.

https://github.com/culugyx/tinc_gui/wiki
https://github.com/culugyx/tinc_gui/releases (please read the warnings before trying it)

@rkeene

This comment has been minimized.

Show comment
Hide comment
@rkeene

rkeene Jun 23, 2017

Is this still "wontfix" ? It would be real handy if it was fixed, even if only supporting mode = route

rkeene commented Jun 23, 2017

Is this still "wontfix" ? It would be real handy if it was fixed, even if only supporting mode = route

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment