Calling the Key Binding service with errSecNotAvailable when completing a goal using the command line tools and iphone simulator is installed on hardware version 6.0 (10A403). If I change the simulator version to another previous version (4.3, 5.0, 5.1) and repeat the execution using the same script command line, the calls will succeed.
I am running the latest version of Xcode 4.5, and the command line tools are being downloaded from Xcode.
To reproduce this error, follow these steps:
- Configuring an ios library project with OCUnit target
- Install Base SDK on 6.0
- Set the target deployment level for iOS 4.3.
- Copy and paste the code at the end of the message into the test project (it will only try to save the password and get it)
- Add Security.framework to OCUnit Target
Run the OCUnit target in Xcode and see a test pass with any hardware version installed in the iphone simulator (just change it between runs).
Run the OCUnit target from the command line using:
xcodebuild -target TARGET_NAME_HERE -sdk iphonesimulator -configuration Release TEST_AFTER_BUILD=YES
with iphone simulator installed on hardware version 6.0 and the test will fail . If you change the iphone simulator hardware version to 4.3, 5.0 or 5.1 and run the script command line again, the test will succeed .
Is this a command line issue? iphone simulator problem? OCUnit target launched from command line?
Who likes unit tests that pass only when comets are aligned ??
Any ideas?
Here is the code:
#define KEYCHAIN_ITEM_ATTRIBUTES (id)kSecClassGenericPassword, kSecClass, @"MyService", kSecAttrService, @"MyPassword", kSecAttrAccount const NSString* MyPassword = @"blabla"; - (void)testExample { // remove previous keychain item OSStatus status = SecItemDelete((CFTypeRef)[NSDictionary dictionaryWithObjectsAndKeys:KEYCHAIN_ITEM_ATTRIBUTES, nil]); NSLog(@"SecItemDelete status:%ld",status); NSParameterAssert(status == errSecSuccess || status == errSecItemNotFound); // add keychain item with new value NSData *data = [MyPassword dataUsingEncoding:NSUTF8StringEncoding]; status = SecItemAdd((CFTypeRef)[NSDictionary dictionaryWithObjectsAndKeys:KEYCHAIN_ITEM_ATTRIBUTES, data, kSecValueData, nil], NULL); NSLog(@"SecItemAdd status:%ld",status); NSParameterAssert(status == errSecSuccess); // get password status = SecItemCopyMatching((CFTypeRef)[NSDictionary dictionaryWithObjectsAndKeys:KEYCHAIN_ITEM_ATTRIBUTES, kSecMatchLimitOne, kSecMatchLimit, kCFBooleanTrue, kSecReturnData, nil], (CFTypeRef *)&data); NSLog(@"SecItemCopyMatching status:%ld",status); NSParameterAssert(status == errSecSuccess); if (status == errSecItemNotFound) NSLog(@"SecItemCopyMatching status:%ld", status); else NSLog(@"SecItemCopyMatching result:%@",[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]); }
Regarding the start of the securityd daemon, I can check its start using
launchctl list | grep securityd
after running the simulator and receiving
- 0 com.apple.iPhoneSimulator:com.apple.securityd
I also tried stopping this securityd daemon and starting another manually ... I looked at the GTM RunIPhoneUnitTest.sh script for a simple line that I could use, but when I try this
launchctl submit -l ios6securityd -- /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/usr/libexec/securityd
gives me a status code of -5 for this daemon.