Security

RSS for tag

Secure the data your app manages and control access to your app using the Security framework.

Posts under Security tag

202 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Type mismatch in SessionGetInfo() swift
The Apple documentation for SessionGetInfo for swift mentions that this API takes third argument of type UnsafeMutablePointer<SessionAttributeBits>? but I m getting the below error when I pass an argument of this type. Cannot convert value of type 'UnsafeMutablePointer<SessionAttributeBits>' to expected argument type 'UnsafeMutablePointer<UInt32>' Why is it expecting a different type. The documentation states otherwise. How to resolve this? Is this a Bug? public static func GetSessionInfo () -> Void { var sessionID = SecuritySessionId() var sessionAttrs = SessionAttributeBits() let status = SessionGetInfo(callerSecuritySession, &sessionID, &sessionAttrs) //error:Cannot convert value of type 'UnsafeMutablePointer<SessionAttributeBits>' to expected argument type 'UnsafeMutablePointer<UInt32>' if status != errSessionSuccess { print("Could not get session info. Error \(status)") } }
6
0
650
Feb ’24
Secure enclave protected private key in CryptoKit vs Security framework
My goal is: Generate a public and private key pair Add the private key to the keychain and protect it with the secure enclave Create a self-signed certificate with the public key and send it to a server Add the certificate to the keychain When I communicate with the server I want to create a SecIdentity during the client challenge which is basically a SecCertificate + SecKey combo. For the certificate generation I would like to use the swift-certificates library to not have to compose manually the certificate fields and signature. My problem is that the swift-certificates during the Certificate initialisation needs a SecureEnclave.P256.Signing.PrivateKey private key and to add a key to the keychain we need a SecKey object. And unfortunately there is no clean way to create from one of them the other one. I read several threads here about this, but I haven't found a clean solution for it. I tried to approach the problem from two directions: First: Create the key with the SecKeyCreateRandomKey, mark in the attributes that I want to protect the key with secure enclave and also mark that I want the private key to be kSecAttrIsPermanent so it is automatically saved in the keychain The SecKeyCreateRandomKey returns a SecKey which is a reference to the private key from the keychain (!) Unfortunately I haven't found a clean way to convert a SecKey to a -> SecureEnclave.P256.Signing.PrivateKey There is a workaround to SecKeyCopyAttributes of the private key and to extract the bytes from the attributes["toid"], but I guess it's not safe to use an undocumented key ("toid") if there is no constant defined to it (the name could be changed in future releases) Second approach: Create a SecureEnclave.P256.Signing.PrivateKey Create the Certificate using the swift-certificates The created private key is protected by the secure enclave but it's not added automatically to the keychain so we should add it to can query after that the SecIdentity (!) Unfortunately I haven't found a way to convert the SecureEnclave.P256.Signing.PrivateKey to -> SecKey. There are threads which say that the SecKeyCreateWithData(...) helps us, but unfortunately if we set the kSecAttrTokenIDSecureEnclave in the attribute dictionary, the method creates a brand new key for us, regardless the passed data. So the initial key will never be the same as the newly created SecKey. This we can see in the method's implementation. So I got stuck with both approaches because seemingly there is no clean way to switch between SecureEnclave.P256.Signing.PrivateKey and SecKey. One solution would be to compose manually the certificate, without swift-certificates because like that we would not need a SecureEnclave.P256.Signing.PrivateKey object. But I would like to avoid the manual composition and signature calculation... Anybody has any idea?
2
1
1.1k
Jan ’24
Private key is not accessible when device is locked
We have implemented a Notification Service Extension in our app to handle remote notification and access keychain to get certificate and identity to refresh network relay configuration. Using SecItemCopyMatching to get SecIdentityRef works when device is unlocked. Whenever push notification arrives and device is locked, our notification service extension failed to access keychain to get identity reference with error code -25308 errSecInteractionNotAllowed. It looks like keychain is locked when device is locked. Is there a way to make keychain unlocked?
1
0
547
Jan ’24
Screensaver is not coming when system.login.screensaver is updated to use authenticate-session-owner-or-admin
On recent macOS versions(Sonoma or previous), if system.login.screensaver is updated to use “authenticate-session-owner-or-admin” then fancy screensaver is not coming up, instead we are seeing only black screensaver ( black screen). Note: Observed we are getting fancy screensavers with this setting on macOS BigSur. Can you please let us know if this is an intentional change from macOS or we have any settings to enable to get fancy screensavers with recent macOS versions? Thanks & Regards, Tata Chaitanya
2
0
530
Jan ’24
APNS Key Vs Certificate Security
I've learned that providing an APNS “Key (Cannot expire)” instead of an APNS “Certificate (Can expire)” will provide the app "access to all topics" for all apps within the organization ‘team’ that the key is forged from. 1.) Can someone elaborate on the specifics for what that means from a security prospective? For instance, if my organization 'team' manages many applications under the same umbrella account and provides the same (or different) APNS key to each app, but one of the apps accidentally (or intentionally) wants to utilize the APNS key to affect the other apps, what are the potential consequences? And, is it possible to create a new APNS key for each app to close any security concerns for multiple apps managed under the same account, or are we stuck with every key having access to all topics?
1
1
1.4k
Jan ’24
Unable to create 'Shared Web Credentials' on fresh TestFlight Install
Hey Apple team (and eskimo 🙏), Our FinTech app uses iCloud Keychain shared web credentials to store a secure encryption password in iCloud Keychain. Some of our new users seem to run into an issue where the app fails to successfully create a shared web credential. All users are required to have the following two settings enabled: Settings --> Passwords --> Password Options --> Autofill from iCloud Passwords & Keychain Settings --> Apple D - -> iCloud - -> Passwords and Keychain --> 'Sync this iPhone' The issue appears to resolve itself when the user restarts their iPhone. We've had this bug 3 times now and would like to understand the root cause. We have a couple hypotheses: iOS is failing to verify that the domain for the shared web credential is valid via <domain>/.well-known/apple-app-site-association (and then restarting triggers reverification) Users were on a version of iOS where it was bugged (and then restarting finally completed an update to a new version). We've verified that the bug happened on 17.0.2 with one user (until they updated and it fixed itself)
1
0
536
Jan ’24
Keychain change notifications?
Is there a way to find out when the set of keychains changes? ie, when a keychain is added or removed? I searched here and grepped through the headers in Security.framework but nothing leaped out at me -- which could just mean I missed something, as happens frequently. (This is on macOS.)
4
0
510
Jan ’24
Firebase’s Remote Config in context of an Authorization Plugin
I am trying to use Firebase’s Remote Config in the context of an Authorization Plugin. I’m doing this in order to implement feature flag support in our Auth Plugin. When I try to fetch remote Firebase settings, I get a -34018 indicating that there is an error with access to the keychain on the Mac. Based on https://forums.developer.apple.com/forums/thread/114456, I have an entitlement problem. It’s my impression that it is not possible to grant entitlements to an Authorization Plugin, so I’m wondering if this kind of keychain access that Firebase requires is simply not possible. Or, if perhaps there is something I can do with entitlements to get this to work? Working with macOS 13.6.2, XCode 15.1
3
0
565
Jan ’24
Find Internet password from keychain?
I have a internet password stored in my keychain with below details: Internet Password Item: Account: user Server: some Ip address(Let's say w.x.y.z) Protocol: htpx But when I use the below code, I receive item not found. But when I remove kSecAttrProtocol attribute from my dictionary, it works. The document says kSecProtocolTypeHTTPProxy corresponds to htpx. Not sure what I am doing wrong, Please guide. I have a dependency on SecProtocolType in my code to look for an internet password in keychain. https://developer.apple.com/documentation/security/secprotocoltype/ksecprotocoltypehttpproxy/ NSString *account = @"user"; NSString *server = @"w.x.y.z"; SecProtocolType protocol = kSecProtocolTypeHTTPProxy; NSDictionary *query = @{ (__bridge id)kSecClass: (__bridge id)kSecClassInternetPassword, (__bridge id)kSecAttrAccount: account, (__bridge id)kSecAttrServer: server, (__bridge id)kSecAttrProtocol:@(protocol), (__bridge id)kSecReturnAttributes: (__bridge id)kCFBooleanTrue, (__bridge id)kSecReturnData: (__bridge id)kCFBooleanFalse, (__bridge id)kSecMatchLimit: (__bridge id)kSecMatchLimitOne }; CFDictionaryRef result = NULL; OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&result); if (status == errSecSuccess) { NSDictionary *passwordItem = CFBridgingRelease(result); NSLog(@"Internet Password Item Found:"); } else if (status == errSecItemNotFound) { NSLog(@"Internet Password Item Not Found"); } else { NSLog(@"Error retrieving Internet password: %d (%@)", (int)status, CFBridgingRelease(SecCopyErrorMessageString(status, NULL))); }
3
0
517
Jan ’24
Custom SFAuthorizationPluginView for Lock Screen
Hi, I have a bundle with my custom lock screen which is a subclass of SFAuthorizationPluginView. I have implemented : override func view(for viewType: SFViewType) -> NSView? and override func buttonPressed(_ inButtonType: SFButtonType), as required in apple's documentation. I have replaced the default UI in the system.login.screensaver.plist with my mchanism. (the custom plist is in the end of this post) When I lock the screen, I get a black screen with the mouse hovering over. I can see in my logs that my view is loaded and the overriden function view(for viewType: SFViewType) is called. When I change the authenticate.plist to display my custom UI, it is displayed properly. Why do I get a black screen when activating the lock screen, but do get my UI when authentication is needed? What I am missing with the lock screen? Here is the system.login.screensaver.plist: ################################################################## <key>class</key> <string>evaluate-mechanisms</string> <key>comment</key> <string>The owner or any administrator can unlock the screensaver, set rule to &quot;authenticate-session-owner-or-admin&quot; to enable SecurityAgent.</string> <key>created</key> <real>711292439.260325</real> <key>mechanisms</key> <array> <string>MyBnndle:LockScreen</string> </array> <key>modified</key> <real>717407094.6108691</real> <key>shared</key> <true/> <key>tries</key> <integer>10000</integer> <key>version</key> <integer>1</integer> cheers, sivan
1
0
419
Jan ’24
Stealth Mode broken in Sleep
Hello here, There is a macOS feature called Stealth Mode under Firewall in System Settings. It's supposedly blocks ICMP request messages (aka Ping). It seems to work fine, only until the device is put to sleep. This can be done either manually from Apple Menu -> Sleep, or by simply closing the MacBook lid. The device suddenly starts replying to pings roughly 10 seconds after entering sleep mode. Exactly the same seems to happen even if I enable pf with a rule: block all Does anyone know what's happening? Seems like packet filtering or firewall is not applied anymore after the OS is put to sleep. Are the ICMP packets handled by the Kernel or WNIC firmware after sleep? I reported this through Apple Feedback Assistant but they were very dismissive and simply said they were not able to reproduce this.
0
0
329
Jan ’24
Unable to consistently detect lock/unlock events with Swift
I need to detect lock & unlock events in my swift iOS application. I have tried using AppDelegate functions like UIApplicationProtectedDataWillBecomeUnavailable & UIApplicationProtectedDataDidBecomeAvailable to record the lock and unlock events respectively, but have found this to be inconsistent. UIApplicationProtectedDataWillBecomeUnavailable is not called immediately after the lock event, and sometimes misses the event altogether. Is there a different approach to this problem that guarantees detecting lock & unlock correctly every time?
2
0
628
Jan ’24
How to set ATS preferences in Xcode 15 But no plist?
I want to allow network access in my app but I have an error nw_proxy_resolver_create_parsed_array [C1.1.1 proxy pac] Evaluation error: NSURLErrorDomain: -1003 which crashes my app although the seek command works and I get a correct value back from the internet server. I understood I could fix this as foilows? There is a section Info. Within Xcode 15 where you can find Custom macOS Application Target Properties. I selected App Transport Security Settings and the after pressing the drop down menu selected Allow Arbitrary Loads. Then to the left of that I press the menu and it shows YES and NO but if I try to select either of them neither appears in the key value box? Also I thought this would create a new Info.plist which I could then add my key values- but nothing happens.. I am very new to the so any help is much apprecated
2
0
589
Jun ’24
Keys created with SecKeyCreateRandomKey cannot be extracted
Hi I've been running after a problem on my iOS app, I'm creating hundreds of keypairs with SecKeyCreateRandomKey for several different usernames, in this case, different identifiers kSecAttrApplicationTag. After I create the key pairs I extract the public keys using SecItemCopyMatching, again, hundreds of them. Problem is, without a logic explanation, some of those keys cannot be extracted. After running after the issue for hours, I noticed that EVERY time I try to extract a public key and the identifier have exactly 87 chars, the public key cannot be found. Doesn't matter the content or names used on the identifier, every time the length hits 87, SecItemCopyMatching returns -25300 is this some kind of limitation that is not explained on the documentation? thanks digging deeply I noticed several identifier sizes fail to extract the key: [982:69528] key with 7 chars is invalid [982:69528] key with 23 chars is invalid [982:69528] key with 39 chars is invalid [982:69528] key with 55 chars is invalid [982:69528] key with 71 chars is invalid [982:69528] key with 87 chars is invalid [982:69528] key with 103 chars is invalid [982:69528] key with 119 chars is invalid [982:69528] key with 135 chars is invalid [982:69528] key with 151 chars is invalid [982:69528] key with 167 chars is invalid [982:69528] key with 183 chars is invalid [982:69528] key with 199 chars is invalid [982:69528] key with 215 chars is invalid [982:69528] key with 231 chars is invalid [982:69528] key with 247 chars is invalid [982:69528] key with 263 chars is invalid [982:69528] key with 279 chars is invalid [982:69528] key with 295 chars is invalid
5
0
411
Jan ’24
how to set an identity and get a certificate CN from a pkcs12 file
I am working on a Swift app which does a TLS connection to a server. I want to set an identity, which the server will validate. I'm given a pkcs12 file. The cert is not trusted locally on my system, but the server can validate it. First, I didn't need to import the cert - I just want to create an identity that I can use with my connection. I don't think that's possible, so I do this: var importStatus = SecPKCS12Import(pkcs12Data as CFData, importOptions as CFDictionary, &importArray) The first time I call this, it's successful. I have come to extract the identity (and certificate) from the importArray returned, but in my case, even though I get an errSecSuccess return status, the importArray is empty. So first question: why would it be empty? ( if the code is run again, I get an errSecDuplicateItem - I don't need to store it in the keychain but I guess I'm being forced to) When I imported, I used a UUID as my identifier - I set it in the options: let importOptions: [String: Any] = [ kSecImportExportPassphrase as String: password, kSecImportItemLabel as String: identifier ] So I try to retrieve the identity from the keychain: let identityQuery = [ kSecClass: kSecClassIdentity, kSecReturnRef: true, kSecAttrLabel: identifier ] as NSDictionary var identityItem: CFTypeRef? let status = SecItemCopyMatching(identityQuery as CFDictionary, &identityItem) where I pass the UUID as identifier, but I actually get back my apple identity, not the certificate. However, if I pass in the certificate's CN, (hard-coded for my testing) I get the right identity back. So my second question: am I doing something wrong? If i pass an ItemLabel on import, can I retrieve the certificate using that same label? So for me to get this working, I need to know the CN of my cert, or I need the ItemLabel to work so that I can just retrieve using a UUID. To determine the CN of my cert, the only apple API I found is this: SecCertificateCopyCommonName which requires the cert to be in .der format, rather than .pkcs12. So I have a bit of a chicken and egg problem. So my last question - is there a way to extract the CN from the pkcs12 file, or to convert the Data from .pkcs12 to .der? Thanks!
4
0
858
Dec ’23
ASP rejection of signed command line application
I am trying to run something I built with the CLI versions of clang on my M3 MBP. The application is signed: codesign -d -v /usr/local/bin/wine* Executable=/usr/local/bin/wine Identifier=org.winehq.wine Format=Mach-O thin (arm64) CodeDirectory v=20400 size=275 flags=0x0(none) hashes=3+2 location=embedded Signature size=8972 Timestamp=Dec 15, 2023 at 10:35:06 AM Info.plist entries=12 TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=1 size=176 Executable=/usr/local/bin/wineboot Identifier=wineboot Format=generic CodeDirectory v=20200 size=168 flags=0x0(none) hashes=1+2 location=embedded Signature size=9053 Timestamp=Dec 15, 2023 at 10:35:06 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=2 size=216 Executable=/usr/local/bin/winebuild Identifier=winebuild Format=Mach-O thin (arm64) CodeDirectory v=20400 size=1933 flags=0x0(none) hashes=55+2 location=embedded Signature size=8972 Timestamp=Dec 15, 2023 at 10:35:06 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=1 size=172 Executable=/usr/local/bin/winecfg Identifier=winecfg Format=generic CodeDirectory v=20200 size=167 flags=0x0(none) hashes=1+2 location=embedded Signature size=9053 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=2 size=216 Executable=/usr/local/bin/wineconsole Identifier=wineconsole Format=generic CodeDirectory v=20200 size=171 flags=0x0(none) hashes=1+2 location=embedded Signature size=9053 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=2 size=220 Executable=/usr/local/bin/winegcc Identifier=winegcc Format=Mach-O thin (arm64) CodeDirectory v=20400 size=747 flags=0x0(none) hashes=18+2 location=embedded Signature size=8972 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=1 size=168 Executable=/usr/local/bin/winedbg Identifier=winedbg Format=generic CodeDirectory v=20200 size=167 flags=0x0(none) hashes=1+2 location=embedded Signature size=9052 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=2 size=216 Executable=/usr/local/bin/winedump Identifier=winedump Format=Mach-O thin (arm64) CodeDirectory v=20400 size=3052 flags=0x0(none) hashes=90+2 location=embedded Signature size=8972 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=1 size=168 Executable=/usr/local/bin/winefile Identifier=winefile Format=generic CodeDirectory v=20200 size=168 flags=0x0(none) hashes=1+2 location=embedded Signature size=9053 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=2 size=216 Executable=/usr/local/bin/winegcc Identifier=winegcc Format=Mach-O thin (arm64) CodeDirectory v=20400 size=747 flags=0x0(none) hashes=18+2 location=embedded Signature size=8972 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=1 size=168 Executable=/usr/local/bin/winegcc Identifier=winegcc Format=Mach-O thin (arm64) CodeDirectory v=20400 size=747 flags=0x0(none) hashes=18+2 location=embedded Signature size=8972 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=1 size=168 Executable=/usr/local/bin/winemaker Identifier=winemaker Format=generic CodeDirectory v=20200 size=169 flags=0x0(none) hashes=1+2 location=embedded Signature size=9052 Timestamp=Dec 15, 2023 at 10:35:07 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=2 size=224 Executable=/usr/local/bin/winemine Identifier=winemine Format=generic CodeDirectory v=20200 size=168 flags=0x0(none) hashes=1+2 location=embedded Signature size=9052 Timestamp=Dec 15, 2023 at 10:35:08 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=2 size=216 Executable=/usr/local/bin/winepath Identifier=winepath Format=generic CodeDirectory v=20200 size=168 flags=0x0(none) hashes=1+2 location=embedded Signature size=9053 Timestamp=Dec 15, 2023 at 10:35:08 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=2 size=216 Executable=/usr/local/bin/wineserver Identifier=wineserver Format=Mach-O thin (arm64) CodeDirectory v=20400 size=5838 flags=0x0(none) hashes=177+2 location=embedded Signature size=8972 Timestamp=Dec 15, 2023 at 10:35:08 AM Info.plist=not bound TeamIdentifier=L479DU3G63 Sealed Resources=none Internal requirements count=1 size=172 but I still get: default 11:47:19.051342-0500 kernel ASP: Security policy would not allow process: 1501, /usr/local/bin/wine Permissions: ls -al wine* -rwxr-xr-x 1 root wheel 28368 Dec 15 10:35 wine -rwxr-xr-x@ 1 root wheel 1973 Dec 14 23:41 wineboot -rwxr-xr-x 1 root wheel 245424 Dec 15 10:35 winebuild -rwxr-xr-x@ 1 root wheel 1973 Dec 14 23:41 winecfg -rwxr-xr-x@ 1 root wheel 1973 Dec 14 23:41 wineconsole lrwxr-xr-x 1 root wheel 7 Dec 14 23:41 winecpp -> winegcc -rwxr-xr-x@ 1 root wheel 1973 Dec 14 23:41 winedbg -rwxr-xr-x 1 root wheel 388400 Dec 15 10:35 winedump -rwxr-xr-x@ 1 root wheel 1973 Dec 14 23:41 winefile lrwxr-xr-x 1 root wheel 7 Dec 14 23:41 wineg++ -> winegcc -rwxr-xr-x 1 root wheel 91840 Dec 15 10:35 winegcc -rwxr-xr-x@ 1 root wheel 95127 Dec 14 23:41 winemaker -rwxr-xr-x@ 1 root wheel 1973 Dec 14 23:41 winemine -rwxr-xr-x@ 1 root wheel 1973 Dec 14 23:41 winepath -rwxr-xr-x 1 root wheel 747120 Dec 15 10:35 wineserver xattr wine* wineboot: com.apple.cs.CodeDirectory wineboot: com.apple.cs.CodeRequirements wineboot: com.apple.cs.CodeRequirements-1 wineboot: com.apple.cs.CodeSignature winecfg: com.apple.cs.CodeDirectory winecfg: com.apple.cs.CodeRequirements winecfg: com.apple.cs.CodeRequirements-1 winecfg: com.apple.cs.CodeSignature wineconsole: com.apple.cs.CodeDirectory wineconsole: com.apple.cs.CodeRequirements wineconsole: com.apple.cs.CodeRequirements-1 wineconsole: com.apple.cs.CodeSignature winedbg: com.apple.cs.CodeDirectory winedbg: com.apple.cs.CodeRequirements winedbg: com.apple.cs.CodeRequirements-1 winedbg: com.apple.cs.CodeSignature winefile: com.apple.cs.CodeDirectory winefile: com.apple.cs.CodeRequirements winefile: com.apple.cs.CodeRequirements-1 etc., etc... Since this is a new machine, maybe something is missing? How do I debug this problem? The most common response to ASP would not allow progress is that there is an unsigned binary. If this is the case, how do I find what binary it is? Thanks! Gene R.
1
0
534
Dec ’23
Safari Security Vulnerability - CSP policy bypassed script on Safari while chrome successfully blocking it.
on our web pages we have allowed certain sources of scripts though content-security-policy meta tag which is working fine as expected on Chrome browser and on Internet Edge. However there is a script called morosa.top when it inserted in our html page, safari is not able to block it while it was supposed to block. if this script gets executed it start taking screenshots of screen and post it to hacker. Please check this could be a potential issue. [Edited by Moderator]
1
0
641
Jan ’24