MacCatalyst VPN 连接每次连接都询问密码

问题描述

当我们尝试与 MacCatalyst 连接时,系统在每次连接时都要求输入密码,但在处理仅为 MacOS 创建的项目时,它直接连接而不要求输入密码。 KeychainWrapper 类中“set”函数输出对于两个项目是相同的,但是当我比较钥匙串访问中的两个密钥时,附件和我的代码显示了差异

Keychain Screenshot

这是我的 IKEv2 连接代码

public func connectIKEv2(config: Configuration,onError: @escaping (String)->Void) {
    let p = NEVPNProtocolIKEv2()

    p.authenticationMethod = NEVPNIKEAuthenticationMethod.none
    p.deadPeerDetectionRate = NEVPNIKEv2DeadPeerDetectionRate.medium
    p.disableRedirect = false
    p.enableRevocationCheck = false
    p.enablePFS = false
    p.useExtendedAuthentication = true
    p.remoteIdentifier = config.server
    p.useConfigurationAttributeInternalIPsubnet = false
    p.serverAddress = config.server
    p.username = config.account
    p.passwordReference = config.getpasswordRef()
    
    loadProfile { _ in
        self.manager.protocolConfiguration = p
        self.manager.ondemandRules = [NEondemandRuleConnect()]
        self.manager.isondemandEnabled = true

        self.manager.isEnabled = true
        self.saveProfile { success in
            if !success {
                onError("Unable to save vpn profile")
                return
            }
            else {
                print("Mayank: Profile saved")
            }
            self.loadProfile() { success in
                if !success {
                    onError("Unable to load profile")
                    return
                }
                let result = self.startVPNTunnel()
                if !result {
                    onError("Can't connect")
                }
                else {
                    print("Mayank: connecting with result")
                    print(result)

                }
            }
        }
    }
}

这是 KeychainWrapper 设置函数

@discardableResult open func set(_ value: String,forKey key: String,withAccessibility accessibility: KeychainItemAccessibility? = nil) -> Bool {
    if let data = value.data(using: .utf8) {
        return set(data,forKey: key,withAccessibility: accessibility)
    } else {
        return false
    }
}

@discardableResult open func set(_ value: Data,withAccessibility accessibility: KeychainItemAccessibility? = nil) -> Bool {
    var keychainQueryDictionary: [String:Any] = setupKeychainQueryDictionary(forKey: key,withAccessibility: accessibility)
    keychainQueryDictionary[SecValueData] = value
    if let accessibility = accessibility {
        keychainQueryDictionary[SecAttrAccessible] = accessibility.keychainAttrValue
    } else {
        keychainQueryDictionary[SecAttrAccessible] = KeychainItemAccessibility.whenUnlocked.keychainAttrValue
    }
    let status: Osstatus = SecItemAdd(keychainQueryDictionary as CFDictionary,nil)
    if status == errSecSuccess {
        return true
    } else if status == errSecDuplicateItem {
        return update(value,withAccessibility: accessibility)
    } else {
        return false
    }
}

private func update(_ value: Data,withAccessibility: accessibility)
    let updateDictionary = [SecValueData:value]
    if let accessibility = accessibility {
        keychainQueryDictionary[SecAttrAccessible] = accessibility.keychainAttrValue
    }
    let status: Osstatus = SecItemUpdate(keychainQueryDictionary as CFDictionary,updateDictionary as CFDictionary)
    if status == errSecSuccess {
        return true
    } else {
        return false
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)