ss-abramchuk / OpenVPNAdapter

Objective-C wrapper for OpenVPN library. Compatible with iOS and macOS.
GNU Affero General Public License v3.0
473 stars 209 forks source link

VPN Status Connecting only. #147

Open rakeshdev16 opened 4 years ago

rakeshdev16 commented 4 years ago

Hi,

I have followed the same steps as explained here as well as in your medium article. Everything works however when I try to connect the VPN status shows "Connecting" only and does not connect. Can you please tell me what could be the possible reason for this issue.

Thank you.

Ankur0713 commented 4 years ago

I also have same issue. Can you please help in solving this?

nirwanrajat commented 4 years ago

I am facing same issue. Please suggest ?

ss-abramchuk commented 4 years ago

Hi guys,

First of all, have you checked the log?

nirwanrajat commented 4 years ago

Yes, I checked the log.... but no error or log is printed

basheerpaliyathu commented 4 years ago

the Logs may not work there (in Extensions), you can debug it by attaching the target to process: (PacketTunnelProvider). but the extension may process very fast and you may not be able to attach it to debug process,

you can try it by the : https://github.com/mutualmobile/MMWormhole

i strongly suggest you to check the Bundle ID provided . tunnelProtocol.providerBundleIdentifier = "com.example.vpn.PacketTunnelProvider"

nirwanrajat commented 4 years ago

Thanks @basheerpaliyathu ,I debug it by attaching the target to process and also by printing message on console.

Yes, I have checked my "providerBundleIdentifier" that is correct

nirwanrajat commented 4 years ago

Hi @ss-abramchuk , i follow the Medium Tutorial ( https://medium.com/better-programming/how-to-build-an-openvpn-client-on-ios-c8f927c11e80 ) and your github also and i have re-created project many times but always facing the same problem. Even it is not throwing any error only stuck in connecting state then never change the VPN status.

ss-abramchuk commented 4 years ago

This is definitely configuration issue. Here you can download working project. Compare it with yours and make sure providerBundleIdentifier is really correct. I.e. if your app identifier is com.example.vpn-client then providerBundleIdentifier should be something like com.example.vpn-client.tunnel-provider.

nirwanrajat commented 4 years ago

Thanks @ss-abramchuk for providing project. I check it with my project and i do it exactly same as yours but the result is still same "Connecting" and the "providerBundleIdentifier" is correct i have checked.

As i try with make some changes, like i change "username" key with "user" in ViewController but in "PacketTunnelProvider" it is "username" so in that case status change connecting->disconnecting->disconnected.

So i think "startTunnel()" method in "PacketTunnelProvider" class gets called and after that somewhere it stuck.

So i think it is not a configuration issue. If you have any suggestion please suggest. Thanks

ss-abramchuk commented 4 years ago

Check device log thoroughly, you need to check records containing bundle identifier of your tunnel provider. Also, try debuging startTunnel step by step. If you add _ = DispatchSemaphore(value: 0).wait(timeout: .now() + 20) at the beginning of the startTunnel method it will give you more time to attach to the process.

ss-abramchuk commented 4 years ago

BTW, if you use NSLog within tunnel provider you will see these log messages in the device log.

ArohiMagotra commented 4 years ago

I have corrected "PacketTunnelProvider" in my project and now I m getting "Update Required" error message on my iPhone in VPN settings.

nirwanrajat commented 4 years ago

Hi @ss-abramchuk

Thanks for your response. I debug it in my code by adding breakpoint and it works fine and I find that OpenVPNAdapterDelegate below method is called infinitely in loop. It is printing below 3 messages (logMessage) in infinite loop:

"Contacting xx.xxx.xxx.xxx:xxx via TCPv4\n"

"Connecting to [xx.xxx.xxx.xxx]:xxx (xx.xxx.xxx.xxx) via TCPv4\n"

"Server poll timeout, trying next remote entry...\n"

Where xx.xxx.xxx.xxx:xxx is my server address.

func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleLogMessage logMessage: String) { NSLog("[Log] (logMessage)") print(logMessage) }

And func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleEvent event: OpenVPNAdapterEvent, message: String?) this method is try again and again to reconnecting. This method change its state wait->reconnecting infinitely.

Now i am not sure why "Server poll timeout, trying next remote entry..." is happen. Can you please help?

nirwanrajat commented 4 years ago

Hi @ss-abramchuk

I have resolved my issue. This issue is, when we get some error from server then try to reconnect VPN and it goes in infinite loop so it stuck in connecting state for infinite.

rakeshdev16 commented 4 years ago

Hi nirwanrajat , How did you fix it?

nirwanrajat commented 4 years ago

Hi @rakeshdev16

In my case i have some error at server end so it is throwing error as mention above by me. When get this error it goes to reconnect VPN and it start infinite loop i.e, "connecting->error->reconnecting->connecting".

After fixing error at server it works smooth.

First of all you check that your "startTunnel" method in "PacketTunnelProvider" is getting call or not. If it is not getting call that means your NetworkExtension Target is not configure correctly.

For checking your startTunnel method place a breakpoint in this method and then select "Debug->Attach to Process by PID or Name->" then in PID or Process Name write your Network Extension Target name. Now breakpoint in your startTunnel method works if it is getting call.

Feel free if you have any doubt.

duyhct commented 4 years ago

Hi guys, i'm following step by step and do my example. I have a problem: When i start VPN by button -> it's work and connect VPN successfull. But when i connect VPN in Settings iOS, it's stuck (like my video). Anyone has this problem?

Stuck_VPN_Connecting 1.mp4.zip

khatri6168 commented 4 years ago

r "startTunnel" method in "PacketTunnelProvider" is getting call or not.

@nirwanrajat Hello

i am try many time and create new project many time but this r "startTunnel" method in "PacketTunnelProvider" are not call. so can you please tell me how to configure this do you have any step to configure correctly please help me.

amir-ardalanuk commented 3 years ago

@ss-abramchuk Hey Sir Thank you for responding I set a breakpoint on the startTunnel function in NEPacketTunnelProvider we have created on network extension but It never calls I stack on connecting