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.

For an iOS app that communicates with a RESTful service over HTTPS, should the session key be stored in Keychain or NSUserDefaults? Username and password are stored in Keychain, and it would seem trivial to also store the sessionKey.

But from a security standpoint, does that get you any added security? Presumably if somebody is able to get to your NSUserDefaults, they're also able to see your HTTPS requests traffic from that app?

share|improve this question
1  
I'm not an iOS developer, but session keys should not be stored anywhere persistent. Keychains are usually persistent databases so would be unsuitable. A session key lives in memory only. –  lynks Jul 11 '13 at 16:01
1  
Same disclaimer (I'm not an iOS dev), but it would be even better to not store the username:password, but rather get a token from the service (if possible) and only store that in the keychain. That way the user can revoke access without changing the password, and there's no risk of the password leaking… –  Joel L Jan 31 at 15:14
add comment

1 Answer

up vote 1 down vote accepted

NSUserDefaults is not encrypted and is stored in a plain text .plist file - it can be easily opened and read, both on device and when synced to a Mac. NSUserDefaults is for preferences, not for storing secure login information Sensitive data like passwords and keys. Keys should be stored in the Keychain. Apple's Keychain Services Programming Guide states that a "keychain is an encrypted container that holds passwords for multiple applications and secure services. Keychains are secure storage containers, which means that when the keychain is locked, no one can access its protected contents". Moreover, in iOS, each application only has access to its own keychain items.

As lynks suggested, session keys should not be stored persistently. Regardless, I recommend viewing the following examples/frameworks:

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.