does every iOS app has it's own single keychain on device? - ios

I'm really confused and hence asking this - does every iOS app has it's own keychain on device(iPhone) or there is only one keychain on device (iPhone) which is used by the different apps ?
Thanks

As mentioned in Apple docs. For the iPhone, there is only one keychain and apps can store their keychain items in it.
In iOS, apps have access to a single keychain (which logically
encompasses the iCloud keychain). This keychain is automatically
unlocked when the user unlocks the device and then locked when the
device is locked. An app can access only its own keychain items, or
those shared with a group to which the app belongs. It can't manage
the keychain container itself.
Reference: https://developer.apple.com/documentation/security/keychain_services/keychains

Related

Does iOS clean keychain items automatically?

I use KeychainItemWrapper to store an identifier of my users in keychain of iOS. I noticed that when we uninstall the app, the identifier persist in the keychain yet; but I'm wonder Does iOS will clean the items automatically when the keychain goes so big? or some other applications can remove or access the items?
It will be deleted if the device is wiped or restored, whatever that resets your device.
Access to the keychain is tied to the provisioning profile used to sign the app. Consequently no other apps would be able to access that app's keychain info. This answers your question about some other App being able to access your App's keychain items or not.
For reference: Same Question on Apple Developer Forum

Is iOS Keychain service different from iCloud keychain?

I have been reading the document, but I am getting confused.
There is iOS Keychain here.
And there is iCloud Keychain here.
They both called keychain and both able to store locally and sync to other devices.
Are they just the same thing?
Or iOS keychain service doesn't require iCloud account for local storage at all?
iOS Keychain is a service which allows you to persist user-sensitive information in your application.
iCloud Keychain is a service provided by Apple which syncs your Safari passwords as well as Mail, Contacts, Calendar, and Messages synced across all of the devices signed in with a specific Apple ID.

Does two device will have the same 'UUID'

In my iOS app, I have to restrict the user to use iOS app per device. To do this I found a solution that we can use the identifierForVendor method of UUID (Universally Unique Identifier) which will generate a unique ID to uniquely identify an app on a device. (Here, I am not using UDID (Unique Device Identifier) because Apple rejects apps if the app uses UDID).
So my question as is there any possibilities that the two devices will have the same UUID. any idea?
EDIT 1:
I have one more doubt as if I installed the same app on different two devices and save its UUID string into the device KeyChain. Both devices have same iCloud account. Now while doing iCloud sync for this two devices, is one my device KeyChain will gets overwritten?
EDIT 2:
I have found answer for EDIT 1 as 'Yes, through iCloud Keychain, the keychain would be synced to another one of my devices, and I’d get the same device identifier from here and from below answer too'
For the item to be synced with iCloud keychain, I’d need to explicitly set the kSecAttrSynchronizable attribute. Using the SecItem API, we can set this attribute while adding a keychain item.
Is there any tutorial how to add item in Keychain (Without third party libraries)?
No, Two device does not have the same UUID. I am 100% Sure about it. So go with identifierForVendor method.
But, The UUID may be changed when you reinstall the the application in your device (If there is not other application for the same vendor).
The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.
EDIT
YOUR QUESTION
I have one more doubt as if I installed the same app on different two devices and save its UUID string into the device KeyChain. Both devices have same iCloud account. Now while doing iCloud sync for this two devices, is one my device KeyChain will gets overwritten?
ANSWER
YES. Your keychain will gets overwritten. So you have same UUID for both 2 devices.
I thought is NO!
The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.
Normally, the vendor is determined by data provided by the App Store. If the app was not installed from the app store (such as enterprise apps and apps still in development), then a vendor identifier is calculated based on the app’s bundle ID. The bundle ID is assumed to be in reverse-DNS format.

Potential Loss of Keychain Access Issue After Application Move Account A To B in iOS

Our iOS app is transfer from Account A to B, Earlier we had used the certificates which was created in Account A and upload a build on iTunes Connect using certificates of Account A.
Now when we uploading app on iTunesconenct for Beta Testing that time we have used the certificates which was created in Account B(Due to Transfer App Account).
So, Now application identifier of the live app is different from the application identifier of the Beta TestFlight Testing App on App Store. And we have got the warning potential loss of keychain access.
Right Now, We are using SSKeychain Wrapper for Store UUID to track user.
[SSKeychain setPassword:UUID forService:#"com.example.appname” account:#“appname” error:&error]
If App ID Prefix changed then SSKeychain loss it’s access?
Because We track UUID in database for further use using SSKeychain. My doubt is if APPID Prefix changed then it is also effect the SSKeychain and it is generate new UUID for all devices?
So, How we can solve this issue ? Please let us know about solutions of this issue.
The keychain access is tied to the App(s) ID Prefix(s). They must have the same prefix. We had a case where different Apps in the same Developer Account and different Prefix(s) and they would not share the same keychain access. Had to have Apple fix so all were the same.
In your case, if you move the app to account B, the App ID will have a different prefix and would not be able to access the "old" keychain.
As far as I know there is NO workaround for this if the App Prefix has changed.
Yes, all devices would get a new keychain store for data and would not be able to access the "old" keychain data.

Is keychain data that I store restricted to my app?

If I put some information into the keychain, my app is the only one who is able to have access to that data, correct?
The keychain data are shared across a developer's applications.
From the apple documentation:
Keychain data for an app is stored outside of the app’s sandbox. When
the user backs up app data using iTunes, the keychain data is also
backed up. Before iOS 4.0, keychain data could only be restored to the
device from which the backup was made. In iOS 4.0 and later, a
keychain item that is password protected can be restored to a
different device only if its accessibility is not set to
kSecAttrAccessibleAlwaysThisDeviceOnly or any other value that
restricts it to the current device. Upgrading an app does not affect
that app’s keychain data.
Here is an example of sharing keychain information between applications.
The data an app puts into the Keychain is restricted to a single developer's apps. It can be shared by multiple apps by the same developer if desired or restricted to that app.
See WWDC13 2013 video "Protecting Secrets with the Keychain". You can access it either on you computer or on an iOS device with the Apple WWDC app.

Resources