Closed agrigg closed 6 years ago
I was able to resolve this by turning on Keychain Sharing between my main app and the Packet Tunnel Provider and then looking up the password from the keychain. I ended up just pulling the password using the username as the key, but if anyone needs to get the value of the password using the persistent ref this code worked for me:
func passwordForPersistentRef(passwordRef: Data) -> String? {
let query: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: "[YourService]",
kSecAttrAccessGroup as String: "[TeamID].[KeychainSharingGroupName]",
kSecMatchItemList as String: [passwordRef] as CFArray,
kSecMatchLimit as String: kSecMatchLimitOne,
kSecReturnData as String: true]
var result: AnyObject?
var password: String?
let resultCodeLoad = withUnsafeMutablePointer(to: &result) {
SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
}
if resultCodeLoad == noErr {
if let result = result as? Data {
password = NSString(data: result, encoding: String.Encoding.utf8.rawValue) as? String
}
} else {
print("Error loading from Keychain: \(resultCodeLoad)")
}
return password;
}
The ReadMe shows the following code
I'm able to pull the username from the protocolConfiguration without any issues.
But the sample doesn't show how to convert the protocolConfiguration.passwordReference to a String to pass off to the OpenVPNCredentials. How do I take the password reference and get the password as a string?