Posts

Post not yet marked as solved
0 Replies
443 Views
Hello, is there a way to create an iOS library (potentially a Cocoa Pod or a Swift Package) with a SiriKit custom intent to be used as a way to enhance any application with that library installed?
Posted
by pampanet.
Last updated
.
Post not yet marked as solved
1 Replies
2.2k Views
Hi, my question is regarding APNs p12 files downloadable from Apple Dev Accounts. I want to download the push certificate for the server from Apple Dev Account get the alias get the certificate get the private key I send this info later to a server for enabling push notifications. Issue: I could make a function to get the SecIdentity from the p12 file, but when extracting the private key Data for converting later to String, I get an error with the passphrase. The issue is only reproducible in macOS, as in iOS works fine. func buildAPNs(_ p12: NSData, _ password: String) throws -> ApplePushCertificate { &#9;&#9;&#9;&#9;var alias : CFString? = nil &#9;&#9;&#9;&#9;var cert: SecCertificate? = nil &#9;&#9;&#9;&#9;var privateKey: SecKey? = nil &#9;&#9;&#9;&#9;/* loadP12 does: &#9;&#9;&#9;&#9; let keychain = try makeTemporaryKeyChain() &#9;&#9;&#9;&#9; let passData = NSData(data: password.data(using: .utf8)!) as CFData &#9;&#9;&#9;&#9; let options : NSDictionary = [key: passData, keychainKey: keychain!] &#9;&#9;&#9;&#9; var items : CFArray? = NSArray() as CFArray &#9;&#9;&#9;&#9; let status: OSStatus = SecPKCS12Import(p12, options, &amp;items) &#9;&#9;&#9;&#9; */ &#9;&#9;&#9;&#9;let (securityError, rawItems, keychain) = try loadP12(p12: p12, password: password) &#9;&#9;&#9;&#9;let items = rawItems! as! Array&lt;Dictionary<String, Any&gt;> &#9;&#9;&#9;&#9;if securityError == errSecSuccess &amp;&amp; items.count > 0 { &#9;&#9;&#9;&#9;&#9;&#9;if let secIdentity = (items[0])[kSecImportItemIdentity as String] as! SecIdentity? { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let certSecurityError = SecIdentityCopyCertificate(secIdentity, &amp;cert) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let aliasSecurityError = SecCertificateCopyCommonName(cert!, &amp;alias) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let pkSecurityError = SecIdentityCopyPrivateKey(secIdentity, &amp;privateKey) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;guard pkSecurityError == errSecSuccess else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;throw NSError(domain: "Error with pk", code: Int(pkSecurityError), userInfo: nil) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;guard certSecurityError == errSecSuccess else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;throw NSError(domain: "Error with certificate", code: Int(pkSecurityError), userInfo: nil) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;guard aliasSecurityError == noErr else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;throw NSError(domain: "Error with alias", code: Int(pkSecurityError), userInfo: nil) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;return ApplePushCertificate(alias: String(alias!), &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;certificate: cert!, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;privateKey: privateKey!, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;keychain: keychain) &#9;&#9;} with this ApplePushCertificate I call func getKeyData(apnsCert: ApplePushCertificate)-> String { let keyData = SecKeyCopyExternalRepresentation(apnsCert.privateKey, &amp;error) //call (keyData as Data).base64EncodedString() } the error when trying to create keyData is: Error Domain=NSOSStatusErrorDomain Code=-25260 "MacOS error: -25260" UserInfo={NSDescription=MacOS error: -25260} How can I solve this issue for MacOS? I tried the same code (without creating a temporary keychain) in iOS and works fine without errors
Posted
by pampanet.
Last updated
.