Skip to content
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

Allow to connect to a VPN server passing ovpn file path (in device's storage) and credentials parameters through api (adb) #1690

Open
jefftrigueiro opened this issue Mar 3, 2024 · 4 comments

Comments

@jefftrigueiro
Copy link

It would be very nice if we don't have to save a profile in the app to connect to a VPN server.

Something like:

adb -d shell am start -a android.intent.action.MAIN -n de.blinkt.openvpn/.api.ConnectVPN --es de.blinkt.openvpn.api.ovpnPath /sdcard/myVPNs/vpn1.ovpn --es de.blinkt.openvpn.api.username my_username --es de.blinkt.openvpn.api.password my_password

Thanks in advance.

@schwabe
Copy link
Owner

schwabe commented Mar 3, 2024

Why do you need that via adb? There is already an API (AIDL) that another app can use to do that. Also on newer Android versions, directly accessing the sdcard is almost impossible without user intervention anyway, so implementing this would only really work on older Android versions.

@jefftrigueiro
Copy link
Author

@schwabe so, through AIDL can I use the ovpn file to connect to a VPN server passing it as a parameter with the credentials too? Without the need to import it?

@schwabe
Copy link
Owner

schwabe commented Mar 4, 2024

Yes. Check IOpenVPNAPIService and also the remoteExample app in the repo. Especially this method:

	/** start a profile using a config as inline string. Make sure that all needed data is inlined,
	 * e.g., using <ca>...</ca> or <auth-user-pass>...</auth-user-pass>
	 * See the OpenVPN manual page for more on inlining files */
	void startVPN (in String inlineconfig);

@jefftrigueiro
Copy link
Author

Hello @schwabe
I have created a simple app to try out the remoteApp way, but I'm having some problems:

I am following the same flow that you did in MainFragment:

  1. Bind the service
  2. Check the permission for my app: mService?.prepare(packageName)
  3. In onActivityResult() I try to start the VPN server with mService!!.startVPN(config.toString())

But I'm getting the following error:
FATAL EXCEPTION: main Process: com.trigger.litevpn, PID: 11098 java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at android.os.Parcel.createExceptionOrNull(Parcel.java:3063) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at de.blinkt.openvpn.api.IOpenVPNAPIService$Stub$Proxy.startVPN(IOpenVPNAPIService.java:300) at com.trigger.litevpn.MainActivity.startVpn(MainActivity.kt:142) at com.trigger.litevpn.MainActivity.onActivityResult(MainActivity.kt:155) at com.trigger.litevpn.MainActivity$mConnection$1.onServiceConnected(MainActivity.kt:90) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2198) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2231) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8177) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

This error is happening in the class IOpenVPNAPIService generated by the AIDL:

@Override public void startVPN(java.lang.String inlineconfig) throws android.os.RemoteException { android.os.Parcel _data = android.os.Parcel.obtain(); android.os.Parcel _reply = android.os.Parcel.obtain(); try { _data.writeInterfaceToken(DESCRIPTOR); _data.writeString(inlineconfig); boolean _status = mRemote.transact(Stub.TRANSACTION_startVPN, _data, _reply, 0); _reply.readException(); } finally { _reply.recycle(); _data.recycle(); } }

I don't know what I'm doing wrong. I tried with your test.conf file and with another vaild ovpn file.
Can you please help me?
Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants