4

I'm new to Swift and iOS. Suppose there was no KeyChain API. Would it be safe to put a user's password (plain text) in core data?

Assume it won't be sent over the network, but only stored in the phone. How could an attacker get the password? Could other apps access the info in core data?

If this isn't safe, what steps could be taken to make it safe?

  • Core data can be backed up to iCloud and iTunes, which means anyone having access to the iCloud accound or the computer can recover your key. – André Borie Jan 5 '17 at 13:04
  • While I'm not an iOS developer nor do I have extensive knowledge in Apple API / filesystem. I would like to inquire as to why is the password being stored in plaintext? Can you not store a hash of the password even if it's in an apple recommend container? – Parth Maniar Mar 10 '17 at 3:07
3

There are multiple parts to this answer. First, everything stored on the file system of an iOS device is encrypted, provided the device uses a passcode. Hence with respect to the data actually on the iOS device, provided you're not trying to hide the data from the user who knows the passcode, you can have some confidence that core data is secure.

However just to be clear, Core Data is not actually a way of storing data. It is a common interface to an object store, which is usually backed by sqlite on the device's file system.

As pointed out by André, this sqlite file may be backed up, leaving it exposed to prying eyes.

Apple's recommendation (that I agree with) is that passwords should only ever be stored in the keychain, which is easy to do, and allows you to control when the entry is accessible (ie. while the device is locked, after first unlock, etc.).

Other apps can never access your app's data in iOS, irrespective of where you write it (unless jailbroken).

Here's a Ray Wenderlich tutorial that walks you through doing this with swift: https://www.raywenderlich.com/92667/securing-ios-data-keychain-touch-id-1password

  • I would add that the Keychain can also store certs that can be used to en/decrypt data before storing it to yr SSD. I recommend creating several certs (ssh keys) then breaking them up into chunks and encrypting each chunk using successive layers, then use Keychain to store these chunks (and possibly also have some parts stored via anither method). The more complex your scheme is, the more havkers will give up and move along to a weaker target. Although no security should be assumed impervious, at leasy CYA. – CommaToast Oct 17 '17 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.