无法为VPN(NEVPNProtocolIPSec)swift添加共享密钥

时间:2019-03-18 11:32:35

标签: ios swift macos vpn

当我尝试连接显示的消息为No VPN shared secret was provided. Verify your settings and try reconnecting.时,我正在为iOS和macOS开发VPN应用程序 存储密码和共享密钥,我正在使用keychainAccess [https://github.com/kishikawakatsumi/KeychainAccess#requirements]。我用来保存首选项的阻止代码下面的原因是什么?

        let p = NEVPNProtocolIPSec()

          p.username = "vpn"
        let ip = self.getIFAddresses()
        print(ip)
        p.serverAddress =  "167.179.69.252"
            p.remoteIdentifier = "167.179.69.252"
            p.localIdentifier = "192.168.xx.xx"



            p.authenticationMethod = .sharedSecret

                    do {
                        try self.kcs.set("vpn", key: "sharedPsw")
                        try self.kcs.set("vpn", key: "password")

                        }
                        catch let error {
                            print(error)
                        }

            p.sharedSecretReference =  self.kcs[attributes: "sharedPsw"]?.persistentRef
            p.passwordReference =  self.kcs[attributes: "password"]?.persistentRef

        p.useExtendedAuthentication = false
        p.disconnectOnSleep = false
        self.vpnManager.protocolConfiguration = p
        self.vpnManager.localizedDescription = "secure_VPN"
        self.vpnManager.isEnabled = true
        self.vpnManager.isOnDemandEnabled = true

            self.vpnManager.saveToPreferences { error in
                guard error == nil else {
                    print("NEVPNManager.saveToPreferencesWithCompletionHandler failed: \(error!.localizedDescription)")
                    return
                }
            }
        }

有什么建议吗?

预先感谢!

0 个答案:

没有答案