标签: nevpnmanager

在iOS 8中使用NEVPNManager,如何以编程方式创建到自定义VPN类型的VPN连接?(例如思科任何连接)

在Apple的Configurator工具中查看VPN配置,它提供了许多不同类型的VPN,例如

  • L2TP
  • PPTP
  • Cisco AnyConnect
  • 瞻博网络SSL
  • Check Point Mobile VPN等

我想以编程方式使用创建自定义VPN配置NEVPNManager,但是查看NetworkExtension框架中添加的对象列表,只有2个协议类 - NEVPNProtocolIPSecNEVPNProtocolIKEv2.

我是VPN的世界的新手,所以我的问题是:

这些专有VPN类型(例如Cisco AnyConnect)是IPSec或IKEv2的变体,因此我可以使用其中一个协议类进行设置,还是目前无法使用NEVPNManager进行此类设置

vpn ios ios8 nevpnmanager

13
推荐指数
1
解决办法
1469
查看次数

iOS VPN连接模块将4G切换到WiFi连接

我正在使用下面的随需连接规则在Swift中创建VPN连接:

        let config = NEVPNProtocolIPSec()
        config.serverAddress = ""
        config.username = ""
        config.passwordReference = ""
        config.authenticationMethod = .sharedSecret
        config.sharedSecretReference = ""
        config.useExtendedAuthentication = true
        config.disconnectOnSleep = true

        let connectRule = NEOnDemandRuleConnect()
        connectRule.interfaceTypeMatch = .any
        vpnManager.onDemandRules = [connectRule]

        vpnManager.protocolConfiguration = config
        vpnManager.localizedDescription = ""
        vpnManager.isOnDemandEnabled = true
        vpnManager.isEnabled = true
Run Code Online (Sandbox Code Playgroud)

这种连接工作正常.如果我使用WiFi,它会在断开WiFi连接后重新连接,但反之亦然.如果我正在使用蜂窝连接并尝试激活WiFi,则手机将无法连接至WiFi,直到我手动断开其与VPN的连接.我相信一个活跃的VPN连接阻止从4G切换到WiFi.

我该如何解决这个问题?

vpn xcode swift nevpnmanager

13
推荐指数
1
解决办法
774
查看次数

macOS 催化剂上钥匙串项的 PersistentRef

背景

我正在尝试构建一个使用本机 IKEv2 实现连接到 VPN 的应用程序。该应用程序应为 iOS 构建,但也应使用 Catalyst 平台在 macOS 上运行。

情况

在 iOS/macOS 中使用本机 IKEv2 实现连接到 VPN 时 - 要使用用户名和密码身份验证,应用程序必须将持久的钥匙串引用传递给包含密码的钥匙串项目。(参考

问题

在 iOS 上它工作得很好,但是在 Catalyst 平台上启动 VPN 连接时,VPN 服务无法使用给定的持久引用检索密码。控制台打印:

[] (null): Failed to copy content, SecKeychainItemCopyContent returned The contents of this item cannot be retrieved.
Run Code Online (Sandbox Code Playgroud)

钥匙串项存储在钥匙串中,持久引用不是nil,但由于某种原因,操作系统的 VPN 服务无法检索密码。

如果我尝试使用相同的持久引用检索密码 - 一切都按预期工作,并检索密码。

let query: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrPersistentReference as String: persistentRef,
    kSecReturnData as String: true
]
        
var item: CFTypeRef?
let …
Run Code Online (Sandbox Code Playgroud)

macos keychain swift nevpnmanager mac-catalyst

7
推荐指数
1
解决办法
184
查看次数

重启应用程序后是否连接了NEVPNManager检查?

我使用框架编写VPN工具NetworkExtension.我可以连接IPSec的通过NEVPNManager.sharedManager,什么时候都能抢通知VPN连接状态改变.但是当我杀死应用程序并重新打开它时,NEVPNManager.Connect.Status总是零,比手段无法显示正确的连接状态.怎么解决?

ios nevpnmanager networkextension

6
推荐指数
2
解决办法
1846
查看次数

NEVPNManager.saveToPreferencesWithCompletionHandler出错

我的目标平台是OS X 10.10/Xcode 7.2我正在尝试保存NEVPNManager的首选项,我在domain = NEConfigurationErrorDomain中出错:

Error Domain = NEConfigurationErrorDomain Code = 10 "permission denied" UserInfo = 0x610000073280 {NSLocalizedDescription = permission denied}
Run Code Online (Sandbox Code Playgroud)

示例代码如下:

let manager = NEVPNManager.sharedManager()
manager.loadFromPreferencesWithCompletionHandler { (error) -> Void in
    if((error) != nil) {
        print("VPN load preferences error")
        print(error!)
        exit(0)
    }
    if manager.`protocol`  == nil {
        let proto = NEVPNProtocolIKEv2()
        proto.serverAddress = "host.net"
        proto.username = "username"
        Keychain.save("vpnpassword", data: "password".dataUsingEncoding(NSUTF8StringEncoding)!)
        proto.passwordReference = Keychain.load("vpnpassword") // I got the same error without passwordReference too
        proto.authenticationMethod = NEVPNIKEAuthenticationMethod.None
        manager.`protocol` = proto …
Run Code Online (Sandbox Code Playgroud)

macos vpn osx-yosemite nevpnmanager

5
推荐指数
1
解决办法
1197
查看次数

使用证书连接到 VPN - iOS/Swift

我正在建立需要证书进行身份验证的 VPN 连接。

下面的代码是我如何设置 VPN 所需的配置。参数 identityData 是我将证书作为数据放置的位置。

func setupVPN(){
guard let vpnManager = NEVPNManager.shared() else { return }

vpnManager.loadFromPreferences { error in

    var hasProtocolConfig = false;

    if #available(iOS 9, *) {
        hasProtocolConfig = self.vpnManager.protocolConfiguration != nil
    } else {
        hasProtocolConfig = self.vpnManager.`protocol` != nil
    }

    if hasProtocolConfig == true {

        let p = NEVPNProtocolIKEv2()
        // All preferences here
        if let vpnData = self.vpnData {
        p.serverAddress = vpnData.getePDGAddress() // "X.X.X.X"
        p.localIdentifier = vpnData.getlocalIdentifier() // "XXXYYYZZWWWWWWWWWW@pppp.ppp.pppppp.pppppp.ppppppppppp.org"
        p.remoteIdentifier = vpnData.getAPN() // "gggggg.uuuuuuuuuuu" …
Run Code Online (Sandbox Code Playgroud)

vpn certificate ios nevpnmanager

5
推荐指数
1
解决办法
1739
查看次数

如何检测是否安装了NEVPNManager配置?

我正在使用 NetworkExtension 框架在 iOS 上使用 VPN。我能够安装配置并建立连接。我的问题是是否有办法检测 VPN 配置是否仍然安装或检测用户是否已卸载配置?

我不一定要在后台寻找通知或任何东西,但我要寻找的是一些方法/解决方法,当应用程序被带到前台时我会做些什么?

我正在使用具有中间 CA 颁发的证书的证书身份验证,并尝试从这里“评估信任”方法:检查 iOS 上是否安装了配置文件

这对我不起作用。我总是变得值得信赖。我也试过这个:

if([NEVPNManager sharedManager].protocol){
   //installed
}else{
   //not installed
}
Run Code Online (Sandbox Code Playgroud)

但这也行不通。卸载后协议仍然有效。如果我退出并重新启动应用程序,则协议无效。

任何建议表示赞赏。

objective-c ios nevpnmanager

4
推荐指数
1
解决办法
2059
查看次数

NEVPNManager在Swift中连接到VPN

我无法找到关于如何做到这一点的明确答案,所以这就是我创建这个帖子的原因.
我正在开发一个Swift应用程序(Swift 2),我想用一个函数连接VPN服务器.所以我想创建一个

func connect() {
    //Handle the connection to the VPN 
}
Run Code Online (Sandbox Code Playgroud)

我从制作VPN的开发者那里收到了这个https://gist.github.com/matthijsotterloo/cedf256f7f1c2a9a8f624481b7083afd文件(当然我更换了证书,密钥,网址和登录信息.现在我的问题是如何连接到这个VPN服务器功能?我已经发现我必须使用NEVPNManager,但我真的无法找到如何构建它.

希望有人可以帮助我.

谢谢!

vpn ios swift nevpnmanager ios9

4
推荐指数
1
解决办法
5440
查看次数

iOS NETunnelProviderManager保存多个配置

我正在尝试将我的VPN配置保存到已经有效的首选项(我可以连接到我的VPN).但由于某些原因,每次我再次运行代码而不是使用最后一个配置时,它会创建一个新的代码.所以,我最终得到了一堆配置.

这是我目前的代码,如果有人能让我知道它出了什么问题会很棒.谢谢!

// Initialize Manager
NETunnelProviderManager *manager = [[NETunnelProviderManager alloc] init];

[manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
    if (error) {
        NSLog(@"Load Error: %@", error.description);
    } else {

        // Create the protocol object
        NETunnelProviderProtocol *protocol = [[NETunnelProviderProtocol alloc] init]; // Create the protocol object

        // Configure the protocol object
        protocol.providerBundleIdentifier = @"com.nfisc.testvpn.ptp";                 // Bundle ID of tunnel provider
        protocol.providerConfiguration = @{};                                         // Currently blank, but will be used later
        protocol.serverAddress = @"0.0.0.0";                                          // Ommited for security reasons
        protocol.username = @"username";                                              // The username …
Run Code Online (Sandbox Code Playgroud)

network-programming objective-c ios nevpnmanager networkextension

4
推荐指数
1
解决办法
1559
查看次数

使用 NEVPNManager 创建个人 VPN 连接

我正在尝试在我的应用程序中创建 VPN 连接。我浏览此链接 https://developer.apple.com/documentation/networkextension/nevpnmanager 但没有找到任何使用 NEVPNManager 的官方代码,甚至没有找到任何使用此 NEVPNManager 的教程。

我对 VPN 概念很陌生,对此了解不多。那么有人可以提供一些解决方案吗?

ios nevpnmanager networkextension

4
推荐指数
1
解决办法
2万
查看次数

"Error Domain = NEVPNErrorDomain Code = 1 \"(null)\""连接VPN服务器时

我只是第一次连接到VPN服务器时出现"Error Domain = NEVPNErrorDomain Code = 1 \"(null)\"",以后它可以正常工作.

在尝试启动类似于我的问题的TunnelProvider网络扩展时检查了NEVPNErrorDomain错误1,并按照其在此解决方案中说的方式但仍然得到相同的错误.

所以这是我使用网络扩展连接到VPN服务器的代码.

func initVPNTunnelProviderManager(){

    self.vpnManager.loadFromPreferences { (error) -> Void in

        if((error) != nil) {
            print("VPN Preferences error: 1")
        }
        else {

            let p = NEVPNProtocolIKEv2()
            p.username = "******"
            p.remoteIdentifier = "*****"
            p.serverAddress = "******"

            let keychain = KeychainSwift()
            let data = keychain.getData("vpnPassword")

            p.passwordReference = data
            p.authenticationMethod = NEVPNIKEAuthenticationMethod.none
            p.useExtendedAuthentication = true
            p.disconnectOnSleep = false

            self.vpnManager.protocolConfiguration = p
            self.vpnManager.isEnabled = true

            self.vpnManager.saveToPreferences(completionHandler: { (error) -> Void in …
Run Code Online (Sandbox Code Playgroud)

vpn tunnel ios nevpnmanager networkextension

4
推荐指数
1
解决办法
2496
查看次数