Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

My iOS app has to handle storing private keys for the user. Normally I would just use Keychain Services for this as I would a password, but it would be great if I could sync the keys between the user's devices.

Apple's iCloud documentation says not to use iCloud for passwords, but is it safe to use for private keys? Apparently, iCloud data is encrypted in transit and on the server.

Are there any security risks in syncing private keys over the iCloud key-value store?

share|improve this question
add comment

2 Answers

I'd scrap the direct syncing option and simply allow the user to export their private key to a location of their choice, e.g. iCloud, DropBox, internal storage, etc., in an encrypted format.

On export I'd do something like this:

  • Ask the user for a password to use. Don't impose any restrictions on them - it's their job to use a good password!
  • Use a strong key-derivation algorithm such as PBKDF2 to generate a storage key. Use a decent number of rounds.
  • Prefix the private key blob in memory with four known bytes (a magic number), e.g. 'NATG', to form your plaintext.
  • Encrypt the plaintext with AES-128 or a similar block cipher, in CBC mode, using the storage key and a randomly generated IV.
  • Export the ciphertext and IV into a file.

On import:

  • Extract the ciphertext and IV from the file.
  • Ask the user for the password and generate the same key using PBKDF2.
  • Decrypt the ciphertext using the IV and key.
  • Check that the first four bytes of plaintext match your known bytes. If not, it's the wrong password. If so, we're in the money!
  • Remove the first four bytes and you've got the private key!

This allows users to quickly and easily sync private keys via the communications service they want, whether it be iCloud or DropBox or even email, with a reasonable level of security. If their account gets broken into, the attacker still has to crack their password. If they've used a decent one, PBKDF2 should do a decent job of making their cracking attempt infeasible.

share|improve this answer
    
Great explanation and suggestion, thank you! Out of curiosity, could this also be applied to something like an OAuth token? –  Nathan G. Mar 17 '13 at 22:11
    
Sure. But at that point it's probably easier to just get them to type the OAuth token in on each side ;) –  Polynomial Mar 17 '13 at 22:57
add comment

Private keys are in essence the same as passwords. In order to be an effective security device, they need to be kept secret. So no, if it documentation says that it shouldn't be for passwords, it stands to reason that it isn't safe enough to be used for private keys either.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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