Giter VIP home page Giter VIP logo

Comments (7)

granoff avatar granoff commented on July 21, 2024

Had you been using the Lockbox 3 archiveObject methods at all? The deprecated Lockbox 2 setXxx methods and the newer archiveObject methods are incompatible. That is you cannot use setString and unarchiveObject together. The only way to migrate from Lockbox 2 to Lockbox 3 is to use getString and then archiveObject, and then unarchiveObject will work. I only mention this for clarity, as it sounds like you have only been using the set/get methods.

For what it's worth, I wrote a new library named Strongbox (see README for a reference) that implements Lockbox3 in Swift. Not sure that is going to help here, but wanted to mention it.

I think I am going to need to see how you are storing and retrieving your objects to be more helpful.

from lockbox.

Menthuss avatar Menthuss commented on July 21, 2024

I've only used 1.4.9 for both Swift 2.3 and 3.

To give you an example, I'm storing and retrieving the user's authentication token in Lockbox like so:

In Swift 2.3:
Lockbox.setString(authToken, forKey: Constants.KEY_AUTH_TOKEN)
Lockbox.stringForKey(Constants.KEY_AUTH_TOKEN)
In Swift 3:
Lockbox.setString(authToken, forKey: Constants.KEY_AUTH_TOKEN)
Lockbox.string(forKey: Constants.KEY_AUTH_TOKEN)

The problem is that all of my keys return nil in the Swift 3 version of my app, which means that all of the user's settings are gone. I'm guessing the underlying logic in how Lockbox interacts with Keychain changed in Swift 3 and therefore, Lockbox can't find the old associated values anymore.

from lockbox.

granoff avatar granoff commented on July 21, 2024

I bet if you were to step into the call to string(forKey:...) you would discover what is really going on. Can you help me out and do that? My guess would be an error is occurring, so Lockbox is returning nil, but the error would be most helpful to know!

from lockbox.

Menthuss avatar Menthuss commented on July 21, 2024

I've stepped through the code and if I'm reading this right, Keychain is returning a errSecItemNotFound error when trying to look for the associated value.

This is inside the objectForKey function:
CFDataRef data = nil;
OSStatus status = SecItemCopyMatching ( (LOCKBOX_DICTREF) query, (CFTypeRef *) &data );
if (status != errSecSuccess && status != errSecItemNotFound)
DLog(@"SecItemCopyMatching failed for key %@: %d", hierKey, (int)status);

The key itself is correct so I'm worried that something changed in the way Keychain works during the move from Swift 2.3 to 3.

EDIT: I just found out that the key itself is NOT correct. To be more specific, the prefix that is put before the key name before it is passed onto Keychain is org.cocoapods.Lockbox.[keyname] in the Swift 3 version while it's my app's identifier in the Swift 2.3 version.

This might be a good time to migrate to a newer version of Lockbox or perhaps even Strongbox. Does Strongbox have the deprecated functions for retrieving values the old way like Lockbox V3 does?

EDIT2: Well, I managed to find a workaround by copying the Lockbox files to my project and using [NSBundle bundleWithIdentifier] along with my app's package name to find the correct values. This isn't really ideal however. I wouldn't mind migrating to Strongbox but it seems to have a minimal deployment target of iOS 10 while my app has 9 as its minimum...

from lockbox.

granoff avatar granoff commented on July 21, 2024

That nuance of the keychain, using Lockbox rather than Strongbox, may be an oddity of the bridging that is happening between Objective-C and Swift. Weird and not what what I would have expected. Thanks for the providing the details.

If you want to stick with Lockbox, I would at least try the latest version; v1.4.9 is pretty old.

To get around the minimum deployment target of Strongbox, to at least try it, you could fork the repo and make the necessary changes to see if it helps. Strongbox does not have Lockbox's setXxx/getXxx methods, however.

from lockbox.

Menthuss avatar Menthuss commented on July 21, 2024

Well, I've managed to implement Lockbox v3 in my project. The way to fix my problem was quite simple: I simply had to use the init(withPrefix) initialiser instead of the default one to ensure that Lockbox would have the correct prefix for keys. Funny how some solutions can be so simple.

Thanks for your help.

from lockbox.

granoff avatar granoff commented on July 21, 2024

Great news! Thanks for the update. Sorry for the confusion on this. Certainly the weird behavior of the keychain is a little concerning, but I am glad that an included API solved the problem for you.

from lockbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.