granoff / Lockbox

Objective-C utility class for storing data securely in the key chain.
MIT License
849 stars 87 forks source link

overwriting keys #10

Open core-code opened 11 years ago

core-code commented 11 years ago

this fails for me on the mac on line 3 that tries to set the new key @"1". only the first setting for a key ever succeeds

assert([Lockbox setString:@"1" forKey:@"test"]);
assert([[Lockbox stringForKey:@"test"] isEqualToString:@"1"]);
assert([Lockbox setString:@"2" forKey:@"test"]);
assert([[Lockbox stringForKey:@"test"] isEqualToString:@"2"]);
core-code commented 11 years ago

...new key @"2"

granoff commented 11 years ago

Thanks for reporting this. Unfortunately, I cannot reproduce this, and my unit tests (newly added to this project) confirm that the class is working as expected.

It'd be interesting if you wouldn't mind grabbing the latest code from my master branch and running the unit tests on your machine. (Open the LockBox project and go to Product -> Test). Do they all pass?

core-code commented 11 years ago

did you test on Mac OS X? i couldn't even get it to compile on Mac OS X without some changes...

yes i had the latest code, obtaining old code isn't even easy with github ;)

granoff commented 11 years ago

The tests (which I just pushed to this repo) run on Mac OS X.

core-code commented 11 years ago

thanks i'll have a look tomorrow.

core-code commented 11 years ago

i couldn't find a way to run the tests on Mac OS X directly from the provided xcode project as it is iOS only and chaning it didn't really work. additionally the main Lockbox.m still didn't compile on Mac OS X without minor changes.

i've creates a new project "test", imported Lockbox master and still get the same behaviour.

https://dl.dropbox.com/u/7221986/lockbox.zip

just run test/test.xcodeproj and see it hanging in the assertion

granoff commented 11 years ago

Hmm. Ok, it doesn't work under Cocoa, just Cocoa Touch.

I ran your code and stepped through it and saw the same issues you saw. The project provided with this repo is an iOS project. I think the issue is that the keychain under Mac OS works slightly differently than under iOS, which is unfortunate to be sure.

I don't have the time right now to figure this out for Cocoa; sorry. The issue has something to do with the dictionary provided to SecItemDelete() because it is returning a status indicating it cannot find the key in question to remove, before we set the new value. But I would be happy to accept a pull request that makes the class work for both Cocoa and Cocoa Touch. :-)

core-code commented 11 years ago

no problem. i've switched to another keychain wrapper which works fine out-of-box, just wanted to let you know about the issues.

granoff commented 11 years ago

I appreciate it; thanks. Truth be told, I am an iOS developer and I developed the class for an iOS project. I don't do Mac OS work, but I suppose I might someday. So I'll leave this issue open as a reminder that there's an issue for Cocoa use.