passepartoutvpn / tunnelkit

VPN client library for Apple platforms.
GNU General Public License v3.0
9 stars 8 forks source link

After starting vpn, an error appears again and again. Please help me. #296

Closed DanielJefferson123 closed 1 year ago

DanielJefferson123 commented 2 years ago

NSError? domain: "NEVPNConnectionErrorDomainPlugin" - code: 7 "NSLocalizedDescription" : "The VPN session failed because an internal error occurred."

Client configuration is the following: tls-client remote x.x.x.x port 1194 proto udp dev tun0 remote-cert-tls server cipher AES-256-CBC auth SHA256 comp-lzo key-direction 1 redirect-gateway def1 keepalive 20 240 tun-mtu 1350

-----BEGIN OpenVPN Static key V1----- 3da045ffc92e88512287a4b0af1fd23c … -----END OpenVPN Static key V1----- -----BEGIN CERTIFICATE----- MIIDMDCCAhigAwIBAgIUb3XhqouZsbSmZZA3PMb1VTQckTcwDQYJKoZIhvcNAQEL … -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- MIIDQzCCAiugAwIBAgIRAK2w9hQhMcbpc5uh5XMp85IwDQYJKoZIhvcNAQELBQAw … -----END CERTIFICATE----- -----BEGIN ENCRYPTED PRIVATE KEY----- MIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIUxNdq06/lXMCAggA … -----END ENCRYPTED PRIVATE KEY-----

I appreciate keeshux that made the tunnelkit project. This project help me so much for understanding OpenVPN. This project is good and helpful. I downloaded tunnelkit project and I modified some codes in demo mac app. After running connect(), error appears again and again. I tried to solve the errors but I can't. I hope that keeshux and someone help me. And then I want to talk directly with keeshux on tunnelkit project. The following is my connect function.

// where ovpnCfg is the URL to the config file func connectWithOVPN(conf ovpnCfg: URL) {

   do {
      let conf = try OpenVPN.ConfigurationParser.parsed(fromURL: ovpnCfg,passphrase:"12345")
      let ovpnConf = conf.configuration // OpenVPN.Configuration
      var builder = ovpnConf.builder()
       builder.usesPIAPatches = false
       builder.renegotiatesAfter = nil
      let customConfiguration = builder.build()
       customConfiguration.print()

      cfg = OpenVPN.ProviderConfiguration("PcxfVPN.OpenVPN",
                                          appGroup: appGroup,
                                          configuration: customConfiguration)
       let credentials = OpenVPN.Credentials("user", "12345")
       cfg?.username = credentials.username
       let passwordReference: Data
       do {
           passwordReference = try keychain.set(password: credentials.password, for: credentials.username, context: tunnelIdentifier)
       } catch {
           print("Keychain failure: \(error)")
           Logger.log(path:textPath.stringValue, "Keychain failure: \(error)")
           textLog.string = textLog.string + "Keychain failure: \(error) \r\n"
           return
       }
       Task {
           var extra = NetworkExtensionExtra()
           extra.passwordReference = passwordReference
           try await vpn.reconnect(tunnelIdentifier,
                                   configuration: cfg!, // needs to be NetworkExtensionConfiguration
                                   extra: extra,
                                   after: .seconds(2))
       }

   } catch (let error) {
      print("**** The error is \(error.localizedDescription)")
   }
}
keeshux commented 2 years ago

Entitlements I guess.

keeshux commented 1 year ago

I've been unable to ever reproduce this. Sorry, closing.