3
메신저 서명 된 인증서를 제공하는 서버와 통신 할 수 있도록 내 앱 키 체인에 루트 인증서를 쓰려고합니다. 스위프트의 IOS 키 체인에 인증서 추가
class func setCertificate(certData: NSData, forKey keyName: String) -> Bool
{
var secCert = SecCertificateCreateWithData(kCFAllocatorDefault, certData)
var keychainQueryDictionary: NSMutableDictionary = self.setupKeychainQueryDictionaryForKey(keyName)
keychainQueryDictionary[kSecClassCertificate as NSString] = secCert.takeRetainedValue()
// Protect the keychain entry so it's only valid when the device is unlocked
keychainQueryDictionary[SecAttrAccessible] = kSecAttrAccessibleWhenUnlocked
// Disable icloud sync of keychain data
keychainQueryDictionary[kSecAttrSynchronizable as NSString] = kCFBooleanFalse
let status: OSStatus = SecItemAdd(keychainQueryDictionary, nil)
println(status)
if status == errSecSuccess
{
return true
}
return false
}
그러나 OSStatus 반환이 -50 (함수에 전달 된 하나 이상의 매개 변수 곳 유효하지 않습니다.), 난 등 캐스트 수많은하지만 어디받지를 시도했습니다. 해당 형식에 문제가있는 경우 SecCertificateCreateWithData가 nil을 반환하므로 인증서가 유효합니다.
이
private class func setupKeychainQueryDictionaryForKey(keyName: String) -> NSMutableDictionary
{
// Setup dictionary to access keychain and specify we are using a generic password (rather than a certificate, internet password, etc)
var keychainQueryDictionary: NSMutableDictionary = [SecClass:kSecClassGenericPassword]
// Uniquely identify this keychain accessor
keychainQueryDictionary[SecAttrService] = KeychainManager.serviceName
// Uniquely identify the account who will be accessing the keychain
var encodedIdentifier: NSData? = keyName.dataUsingEncoding(NSUTF8StringEncoding)
keychainQueryDictionary[SecAttrGeneric] = encodedIdentifier
keychainQueryDictionary[SecAttrAccount] = encodedIdentifier
return keychainQueryDictionary
}
사람이 누구로부터 신속한 또는 조언에 이런 짓을 한 키 체인 쿼리를 설정하는 내 기능은 무엇입니까?
건배
나뿐만 아니라이 일에 관심을; 해결책을 찾았 니? 또한 iOS 코드를 사용하여 자체 서명 된 인증서를 만드시겠습니까? 그렇다면, 나는 어떻게 알고 싶어합니다. OpenSSL을 사용하는 솔루션을 찾았는데 Apple API 만 사용하는 것이 불가능하다고 생각합니다. 물론 뭔가를 놓친 것 같습니다. – Stefan