Muhammad Sabeel Ahmed
Muhammad Sabeel Ahmed

Reputation: 473

Creating VPN by using OpenVPN

I am facing issue to connect VPN on Android 10 and getting below message in logcat. This is Error of permissions. Looking for solution. Also added android:requestLegacyExternalStorage="true" in Mainfest but not work for me.

D/ConnectionStatus: IO Exceptionjava.io.IOException: Cannot run program "/data/user/0/com.casvpnapp/cache/pie_openvpn.x86_64": error=13, Permission denied

D/de.blinkt.openvpn.core.OpenVPNService: onStartCommand: Australia
I/VpnState: VPN_GENERATE_CONFIG  LEVEL_START
D/ConnectionStatus: ---/data/user/0/com.casvpnapp/cache/android.conf
D/ConnectionStatus: ---/data/user/0/com.casvpnapp/cache/android.conf
D/de.blinkt.openvpn.core.OpenVPNService: startOpenVPN: argv:3
D/ConnectionStatus: --[Ljava.lang.String;@ef1521a
I/OpenVPN: Starting openvpn  [Ljava.lang.String;@ef1521a
D/ConnectionStatus: ---29
    startOpenVPNThread---/data/user/0/com.casvpnapp/cache/pie_openvpn.x86_64
D/ConnectionStatus: IO Exceptionjava.io.IOException: Cannot run program "/data/user/0/com.casvpnapp/cache/pie_openvpn.x86_64": error=13, Permission denied
E/OpenVPN: OpenVPNThread Got java.lang.NullPointerException: Attempt to invoke virtual method 'void java.lang.Process.destroy()' on a null object reference
I/VpnState: NOPROCESS No process running. LEVEL_NOTCONNECTED
W/Thread-20: type=1400 audit(0.0:55): avc: granted { execute } for name="pie_openvpn.x86_64" dev="vdc" ino=23035 scontext=u:r:untrusted_app:s0:c139,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c139,c256,c512,c768 tclass=file app=com.casvpnapp
I/OpenVPN: Exiting

Upvotes: 5

Views: 5260

Answers (2)

Muhammad Mehroz Anjum
Muhammad Mehroz Anjum

Reputation: 101

I recently ran into exactly same issue. I was using clone of EasyVPN-Free. After close examination I found that most of these apps are using same approach and using older versions of ics-openvpn core.

Looks like you are also using older version ics-openvpn in your app which was not compatible with android 10 as its trying to start a process by loading ovpn binary from assets (instead of using JNI lib for this) which is prohibited by Android 10.

To fix this issue find following method in Class VPNLaunchHelper.java:

private static String writeMiniVPN(Context context)

Add following lines in the beginning

String nativeAPI = NativeUtils.getNativeAPI();
/* Q does not allow executing binaries written in temp directory anymore */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
    return new File(context.getApplicationInfo().nativeLibraryDir, "libovpnexec.so").getPath();

Now find the following line and comment / remove it:

String nativeAPI = NativeUtils.getNativeAPI();

[Update]

As originally suggested by Md. Ikramul Murad

Add below code in manifest file:

<application     android:extractNativeLibs="true"     ... >

Now get libovpnexec.so for your target platforms and paste them appropriately in jniLibs folder of your app this should fix your exception on android.

You can refer to this EasyVPN-Free fork which i have specifically made to fix this issue.

I hope that this will help all others who might ran into same issue.

Upvotes: 10

Ashraf789
Ashraf789

Reputation: 329

It seems it's a problem with your OpenVPN library. Although I have also developed a VPN app based on the OpenVPN library it's working fine for me. You can check my source code.

https://github.com/ashraf789/Cake-VPN

Upvotes: 4

Related Questions