0

所以我正在尝试使用 NEVPNManager 以编程方式设置我的 VPN。我被困在配置上,真的很困惑去哪里。

sharedSecretReference 真的让我大吃一惊。我在其他地方看到过说我需要使用钥匙串的事情,但是如何以及为什么。我可以手动使用大约 6 个选项连接到这个 VPN,所以我为什么需要这么多。

如果您发现其他任何我可能做错的事情,请告诉我。这是我目前使用的确切代码

    NEVPNProtocolIPSec *p = [[NEVPNProtocolIPSec alloc] init];
    p.username = [config objectForKey: @"username"];
    p.passwordReference = [config objectForKey: @"password"];
    p.serverAddress = [config objectForKey: @"ip"];
    p.localIdentifier = [config objectForKey: @"vpn"];
    p.remoteIdentifier = [config objectForKey: @"vpn"];
    p.useExtendedAuthentication = NO;
    p.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret;   
    p.disconnectOnSleep = NO;

    p.sharedSecretReference = [config objectForKey: @"psk"];
4

1 回答 1

2

重要的是要了解您提供NEVPNManager的配置可用于启动 VPN 连接,即使您的应用程序处于非活动状态(通过“设置”应用程序)。VPN 管理器需要能够从钥匙串中获取安全数据(共享密钥或密码),而无需通过您的应用程序。为此,它使用对钥匙串中秘密的持久引用,而不是秘密本身。如果您使用类似的库,KeychainAccess则很容易获取此参考并进行设置:

let keychain = Keychain()
let persistentRefSharedSecret = keychain[attributes: "my_shared_secret"].persistentRef
let persistentRefPassword = keychain[attributes: "my_password"].persistentRef

...

p.sharedSecretReference = persistentRefSharedSecret
p.passwordReference = persistentRefPassword
于 2017-10-28T22:04:43.243 回答