Comments (7)
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.
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.
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.
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.
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.
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.
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)
- CocoaPods Support HOT 2
- Occasional Nil value for String. HOT 3
- Lockbox +setDictionary: converts `NSNumber` into `NSString` HOT 2
- Save data for coredata HOT 6
- SecItemCopy and SecItemAdd errors HOT 1
- Cannot find interface declaration for 'NSObject', superclass of 'Lockbox' HOT 3
- Wiping Clean Keychain Keys HOT 2
- Migration to archiveObject HOT 5
- Sharing keys with iOS Today Widget HOT 2
- Exception thrown when unarchiveObjectForKey called on ios 8 HOT 7
- How to save NSData in Dictionary format HOT 2
- Lockbox unarchiveObjectForKey: returns nil sometimes HOT 2
- LockBox doesn't save info in xcode 8 HOT 7
- Doesn't work under iOS 10 HOT 4
- podspec does not define minimum iOS version HOT 2
- Not work in Xcode 11 HOT 3
- cash HOT 1
- Still can delete data, with "Keychain Access.app" HOT 2
- iOS 12 Deprecation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lockbox.