When we try to connect with MacCatalyst, the system asks for a password every connection, but when working on a project created for only MacOS, it connects directly without asking for a password. The output of the “set” functions in the KeychainWrapper class is the same for both projects, but when I compare both keys in keychain access, there are differences as show in the attachment and my codes
Here is my IKEv2 connection codes:
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)
}
}
}
}
}
Here is KeychainWrapper set functions:
@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, forKey key: String, 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, forKey: key, withAccessibility: accessibility)
} else {
return false
}
}
private func update(_ value: Data, forKey key: String, withAccessibility accessibility: KeychainItemAccessibility? = nil) -> Bool {
var keychainQueryDictionary: [String:Any] = setupKeychainQueryDictionary(forKey: key, 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
}
}