FuturraGroup / OpenVPNXor

Library for simple connection via OpenVPN protocol with Xor patch.
MIT License
9 stars 1 forks source link

It seems not be working with vpngate .ovpn files #13

Closed tomassilny closed 2 weeks ago

tomassilny commented 1 month ago

Hello,

I tried to connect to a VPN server using .ovpn files from VPN Gate, but it seems not to be working well. I've tried multiple servers with no success.

I was able to call configureVPN, and it created a new VPN connection in the settings:

99510

However, it seems wrong as the server address doesn't look correct. Could you please check if it works on your side with VPN gate servers, or give me some advice on what I might be doing wrong?

This is my code:

import SwiftUI
import OpenVPNXor

struct ContentView: View {
    @State private var showAlert = false
    @State private var alertMessage = ""

    var body: some View {
        VStack {
            Button("Click Me") {
                configureVPN()
            }
            .alert(isPresented: $showAlert) {
                Alert(title: Text("VPN Status"), message: Text(alertMessage), dismissButton: .default(Text("OK")))
            }
        }
        .padding()
    }

    private func configureVPN() {
        // Find the .ovpn file
        guard let path = Bundle.main.path(forResource: "vpngate_public-vpn-90.opengw.net_tcp_443 (2)", ofType: "ovpn") else {
            alertMessage = "Failed to find .ovpn file in bundle."
            showAlert = true
            return
        }

        do {
            OpenVPNManager.setup(openvpnPacketTunnelIdentifier: "com.deletethis.TestVPN.VPN", appGroupIdentifier: "group.com.deletethis.TestVPN")

            // Load the .ovpn file data
            let url = URL(fileURLWithPath: path)
            let data = try Data(contentsOf: url)

            // Configure the VPN
            OpenVPNManager.shared.configureVPN(openVPNConfiguration: data, login: "vpn", pass: "vpn") { success in
                DispatchQueue.main.async {
                    if success {
                        OpenVPNManager.shared.connectVPN { errorDescription in
                            if let errorDescription = errorDescription {
                                alertMessage = "Failed to connect VPN: \(errorDescription)"
                            } else {
                                alertMessage = "VPN connected successfully."
                            }
                            showAlert = true
                        }
                    } else {
                        alertMessage = "Failed to configure VPN."
                        showAlert = true
                    }
                }
            }
        } catch {
            alertMessage = "Failed to load .ovpn file: \(error)"
            showAlert = true
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

The error message I get: OpenVPNXor: error in starting tunnel

Thank you!

sergey-zhuravel commented 1 month ago

I checked and it works for me. Perhaps the config was not correct or you configured the PacketTunnelProvider incorrectly. See Usage section.

tomassilny commented 1 month ago

Thanks for your reply @sergey-zhuravel. do you know how to call setup using Objective-C?

sergey-zhuravel commented 2 weeks ago

In Objective-C everything is the same as in Swift, just a different syntax