Giter VIP home page Giter VIP logo

Comments (21)

ss-abramchuk avatar ss-abramchuk commented on June 4, 2024 1

I've added a few snippets to the Readme file. Despite the fact that some comments are missing yet it should help you to figure out. You can find them on feature/documentation branch.

from openvpnadapter.

ss-abramchuk avatar ss-abramchuk commented on June 4, 2024 1

BTW, little workaround how to debug a tunnel provider extension. Add the following line at the beginning of startTunnel(options:completionHandler:) method: let _ = DispatchSemaphore(value: 0).wait(timeout: .now() + .seconds(20)). This will give you enough time to manually attach to the process. You can do it via Debug -> Attach to Proccess. When tunnel provider extension is active you will see its process there.

After that your break points will work and using editable breakpoints you can output log messages to the console window.

from openvpnadapter.

ss-abramchuk avatar ss-abramchuk commented on June 4, 2024

Hi @netgfx, in order to run the example you need to provide OpenVPN configuration to the tunnel provider and start the tunnel. You should use NETunnelProviderManager for that.

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

Can I pass the OpenVPN configuration as a file (converted to NSData?), or do I need to hardcode each value?

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

I figured out how to load a local file, I slightly modified the ProfileLoader

public struct ProfileLoader {
    
    static func getVPNProfile(type: ProfileType) -> Data {
        let fileName = type.rawValue
        
        guard
            let path = Bundle.main.path(forResource: fileName, ofType: "ovpn"),
            let profile = try? Data(contentsOf: URL(fileURLWithPath: path))
        else {
            fatalError("Failed to retrieve OpenVPN profile")
        }
        
        return profile
    }
    
}

But I still can't figure out how to call the TunnelProvider, is there an example or some resource to show how can I start the NETunnelProviderManager in swift?

Thanks!

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

thank you much appreciated! I will give it a try tonight and see how it goes.

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

It does seem to run after adding those snippets, however the Extension application seems to be crashing. This is one of the logs, if something makes sense please share

ncident Identifier: 79FDE541-FE9A-4CAD-9A78-FECD2B848ABE
CrashReporter Key:   3919b1ba6c307e4b20b6e92f0c941edb3f6ac1a6
Hardware Model:      iPhone8,4
Process:             OpenVPN iOS Tunnel Provider [455]
Path:                /private/var/containers/Bundle/Application/40B99581-DACF-4720-87D2-657BC3C1FD79/OpenVPN iOS Client.app/PlugIns/OpenVPN iOS Tunnel Provider.appex/OpenVPN iOS Tunnel Provider
Identifier:          openvpn.main.app.extension
Version:             1 (1.0.0)
Code Type:           ARM-64 (Native)
Role:                Unspecified
Parent Process:      launchd [1]
Coalition:           openvpn.main.app.extension [628]


Date/Time:           2018-02-14 12:23:20.9783 +0200
Launch Time:         2018-02-14 12:23:20.7800 +0200
OS Version:          iPhone OS 11.2.5 (15D60)
Baseband Version:    6.30.04
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001058cb95c
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread:  2

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib        	0x0000000185023568 mach_msg_trap + 8
1   libsystem_kernel.dylib        	0x00000001850233e0 mach_msg + 72
2   CoreFoundation                	0x00000001854d7108 __CFRunLoopServiceMachPort + 196
3   CoreFoundation                	0x00000001854d4cd4 __CFRunLoopRun + 1424
4   CoreFoundation                	0x00000001853f4c58 CFRunLoopRunSpecific + 436
5   Foundation                    	0x0000000185e29594 -[NSRunLoop+ 50580 (NSRunLoop) runMode:beforeDate:] + 304
6   Foundation                    	0x0000000185e7b56c -[NSRunLoop+ 386412 (NSRunLoop) run] + 88
7   libxpc.dylib                  	0x00000001851a0e10 _xpc_objc_main + 516
8   libxpc.dylib                  	0x00000001851a2efc xpc_main + 180
9   Foundation                    	0x0000000186055bb4 service_connection_handler + 0
10  PlugInKit                     	0x000000018aa15d48 -[PKService run] + 752
11  PlugInKit                     	0x000000018aa1590c +[PKService main] + 56
12  PlugInKit                     	0x000000018aa15d6c +[PKService _defaultRun:arguments:] + 20
13  Foundation                    	0x0000000186036cf0 NSExtensionMain + 64
14  libdyld.dylib                 	0x0000000184f1456c start + 4

Thread 1:
0   libsystem_pthread.dylib       	0x0000000185156b68 start_wqthread + 0

Thread 2 name:  Dispatch queue: com.apple.NSXPCConnection.user.endpoint
Thread 2 Crashed:
0   libswiftCore.dylib            	0x00000001058cb95c 0x1056ec000 + 1964380
1   libswiftCore.dylib            	0x00000001058cb95c 0x1056ec000 + 1964380
2   OpenVPN iOS Tunnel Provider   	0x0000000104ea7cd4 0x104ea0000 + 31956
3   OpenVPN iOS Tunnel Provider   	0x0000000104ea8660 0x104ea0000 + 34400
4   NetworkExtension              	0x0000000191e8e828 -[NEExtensionPacketTunnelProviderContext startWithOptions:completionHandler:] + 264
5   Foundation                    	0x000000018604fddc __NSXPCCONNECTION_IS_CALLING_OUT_TO_EXPORTED_OBJECT_S2__ + 20
6   Foundation                    	0x000000018604e528 -[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 2584
7   Foundation                    	0x0000000185e246e0 message_handler + 240
8   libxpc.dylib                  	0x0000000185192634 _xpc_connection_call_event_handler + 68
9   libxpc.dylib                  	0x000000018518ffc8 _xpc_connection_mach_event + 984
10  libdispatch.dylib             	0x0000000184eaeae4 _dispatch_client_callout4 + 16
11  libdispatch.dylib             	0x0000000184ec5454 _dispatch_mach_msg_invoke$VARIANT$mp + 356
12  libdispatch.dylib             	0x0000000184eb8824 _dispatch_queue_serial_drain$VARIANT$mp + 200
13  libdispatch.dylib             	0x0000000184ec60d0 _dispatch_mach_invoke$VARIANT$mp + 952
14  libdispatch.dylib             	0x0000000184eb8824 _dispatch_queue_serial_drain$VARIANT$mp + 200
15  libdispatch.dylib             	0x0000000184eb92fc _dispatch_queue_invoke$VARIANT$mp + 340
16  libdispatch.dylib             	0x0000000184eb9d20 _dispatch_root_queue_drain_deferred_wlh$VARIANT$mp + 404
17  libdispatch.dylib             	0x0000000184ec203c _dispatch_workloop_worker_thread$VARIANT$mp + 644
18  libsystem_pthread.dylib       	0x0000000185156f1c _pthread_wqthread + 932
19  libsystem_pthread.dylib       	0x0000000185156b6c start_wqthread + 4

Thread 3:
0   libsystem_pthread.dylib       	0x0000000185156b68 start_wqthread + 0

Thread 2 crashed with ARM Thread State (64-bit):
    x0: 0x0000000104fc5400   x1: 0x0000000000000c03   x2: 0x0000000000000c03   x3: 0x0000000000000004
    x4: 0x0000000000000004   x5: 0x0000000000000010   x6: 0x00d7000004210103   x7: 0x0000000000000190
    x8: 0x0000000000000000   x9: 0x0000000106134000  x10: 0x0000000000003fff  x11: 0x0000000106130000
   x12: 0x0000000000000a2d  x13: 0x0000000000000a2d  x14: 0x0000000044054492  x15: 0x0000000000100000
   x16: 0x0000000185151c9c  x17: 0x0000000000000000  x18: 0xfffffff00d29925c  x19: 0x000000000000006b
   x20: 0x0000000104ebff50  x21: 0x0000000000000000  x22: 0x000000000000004d  x23: 0x0000000104ebffc0
   x24: 0x0000000000000028  x25: 0x0000000000000002  x26: 0x0000000104ebff1a  x27: 0x000000010612b740
   x28: 0x0000000000000000   fp: 0x000000016b0715a0   lr: 0x00000001058cb95c
    sp: 0x000000016b071540   pc: 0x00000001058cb95c cpsr: 0x60000000

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

I figured out what the problem was. I was passing username and password although the server didn't request them.

I have successfully connected to the server, (server throws no errors), but the status of the adapter connection is connecting.
I tried to debug the extension AppId but it either throws no errors. Is there a way to debug this further?

Have you seen behaviour like this?

Server OpenVPN version is 2.4.4 if it helps.

Thanks!

from openvpnadapter.

ss-abramchuk avatar ss-abramchuk commented on June 4, 2024

You can try to increase log verbosity and check log messages using this method of OpenVPNAdapterDelegate -> openVPNAdapter(openVPNAdapter:handleLogMessage:)

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

i have this

// Use this method to process any log message returned by OpenVPN library.
    func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleLogMessage logMessage: String) {
        NSLog("LOG: ",logMessage)
        NSLog(openVPNAdapter.connectionInfo.debugDescription)
    }

I should throw some logs right?

Also I see on your examples and snippets that you add this on the end of the PacketTunnelProvider

extension NEPacketTunnelFlow: OpenVPNAdapterPacketFlow {}
but when I try to add it XCode throws error stating that: Redundant conformance of 'NEPacketTunnelFlow' to protocol 'OpenVPNAdapterPacketFlow'

Is this the reason I don't get logs?

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

Also I see that this gets printed, maybe it is relevant?

OpenVPN iOS Tunnel Provider(libswiftFoundation.dylib)[2301]: UNUSED OPTIONS
1 [tls-client] 
3 [tls-cipher] [TLS-DHE-RSA-WITH-AES-256-GCM-SHA384] 
8 [resolv-retry] [infinite] 
9 [nobind] 
10 [persist-key] 
11 [persist-tun] 
13 [verb] [9]

is there something wrong with the configuration? of the .ovpn file?

from openvpnadapter.

Taherismail17 avatar Taherismail17 commented on June 4, 2024

I am having an issue to actually connect to the VPN. I can copy it to settings but then it doesnt connect. I also am unaware on how to get debugging/logging to work

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

@Taherismail17 I used https://lemonjar.com/iosconsole/ to get more logs from the extension, it somewhat worked, but I see that authentication is valid and accepted from the server and then the client just disconnects (no other client-log, or server log) apart from

TUN Error: cannot acquire tun interface socket
Failed to establish tunnel in a reasonable time

any help is appreciated!

from openvpnadapter.

Taherismail17 avatar Taherismail17 commented on June 4, 2024

@netgfx I wasn’t able to get to the point where I could start a proper connection. Do you have your project hosted? I can definitely determine the OpenVPN and the connection because I have a bunch of profiles that work

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

Yes the server is hosted, the client is run locally from a device.

I also have an .ovpn file that works for android/windows/linux machines but not with the iOS client.

from openvpnadapter.

ss-abramchuk avatar ss-abramchuk commented on June 4, 2024

@netgfx To be able to establish connection you should assign the object that adopts OpenVPNAdapterDelegate protocol to the delegate property of the instance of OpenVPNAdapter class. There are 3 required methods:

  • openVPNAdapter(_:configureTunnelWithNetworkSettings:completionHandler:)
  • openVPNAdapter(_:handleEvent:message:)
  • openVPNAdapter(_:handleError:)

The first is the most important because it configures a tunnel and provides an object responsible for reading/writing datagrams. It should be implemented in this way:

func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings, completionHandler: @escaping (OpenVPNAdapterPacketFlow?) -> Void) {
    setTunnelNetworkSettings(networkSettings) { (error) in
        completionHandler(error == nil ? self.packetFlow : nil)
    }
}

You need to provide an object that adopts OpenVPNAdapterPacketFlow protocol to the completionHandler if here is no error during tunnel setting, otherwise provide nil. And ensure that you use latest version of adapter. Right now it can be found on develop branch.

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

I have the functions above. However i have the outdated Adapter from the example branch, how do i update to the most current one? Replacing the old /OpenVPNAdapter folder didn't work
because it can't find NSError+Message.m and OpenVPNTunnelSettings.m
do I need to call it via carthage?

from openvpnadapter.

ss-abramchuk avatar ss-abramchuk commented on June 4, 2024

Yep, the easiest way is to use carthage

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

Should I change to the new OpenVPNAdapter in both client and extension?

Because I tried it and it throws two errors
Umbrella header 'Umbrella-Header.h' not found
and
Could not build Objective-C module 'OpenVPNAdapter'

from openvpnadapter.

netgfx avatar netgfx commented on June 4, 2024

Ok got it working after all.

For the next guy, until proper branch is fixed with latest Adapter code, you need to do the following:

  • Download example branch (this one has outdated Adapter code)
  • Download develop branch
  • Open and run it with XCode
  • Build it, and take the .framework file from /debug-iphoneos
  • Place the .framework inside the example folder
  • Open the example project with xcode
  • Remove the OpenVPNAdapter from targets
  • Remove the OpenVPNAdapter folder reference
  • Include or replace the newly acquired OpenVPNAdapter.framework on the example folder.
  • Reference it via Embedded binaries on OpenVPN iOS Client and OpenVPN iOS Tunnel Provider from Targets
  • On xcode hit debug> (hold-alt)+clean
  • Build/Run

You should be able to connect if everything else is correct (.ovpn config, delegates, etc)

from openvpnadapter.

Taherismail17 avatar Taherismail17 commented on June 4, 2024

status changed to disconnected, last stop reason Plugin failed

I am getting this error.

from openvpnadapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.