New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perform class check on kSecAttrAccount keychain value during migration #114
Conversation
Valet.xcodeproj/project.pbxproj
Outdated
@@ -974,7 +974,7 @@ | |||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; | |||
GCC_WARN_UNUSED_FUNCTION = YES; | |||
GCC_WARN_UNUSED_VARIABLE = YES; | |||
IPHONEOS_DEPLOYMENT_TARGET = 6.0; | |||
IPHONEOS_DEPLOYMENT_TARGET = 9.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Xcode wouldn't build unless this was > 8.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a breaking change, requiring a major version bump. Let's revert this part of the change since it'll affect people using us in submodules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to revert the breaking change and bump a bugfix version in the podspec before this can be merged. Good fix & test though! Appreciate the change :)
Valet.xcodeproj/project.pbxproj
Outdated
@@ -974,7 +974,7 @@ | |||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; | |||
GCC_WARN_UNUSED_FUNCTION = YES; | |||
GCC_WARN_UNUSED_VARIABLE = YES; | |||
IPHONEOS_DEPLOYMENT_TARGET = 6.0; | |||
IPHONEOS_DEPLOYMENT_TARGET = 9.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a breaking change, requiring a major version bump. Let's revert this part of the change since it'll affect people using us in submodules?
@dfed that makes sense. I've removed the deployment target change |
Looks like CI is failing
Possible that CI is running against a different SDK that didn't have this issue? |
ah, looks like the mac test failed. apparently adding an NSData entry for when inspecting the keychain during migration in OSX:
in iOS:
|
ValetTests/ValetTests.m
Outdated
for (VALValet *const additionalValet in self.additionalValets) { | ||
[additionalValet removeAllObjects]; | ||
} | ||
|
||
for (NSDictionary *keychainEntry in self.manualKeychainEntries) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems much simpler to do this than some of the other workarounds to reset the keychain:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable solution! Since this cleanup is needed for only one test may be best to keep the cleanup localized to that test. I'm a big fan of putting the cleanup at the top of the test, so if tearDown is aborted the next run of the test still succeeds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, what about a finally block? I didn't know this existed and it does the same thing i wanted to get out of tearDown()
: something that is ensured to run regardless of whether an exception is thrown and execution stops.
NSDictionary *keychainEntry = <..>
@try {
.. all the code
}
@finally {
SecItemDelete(keychainEntry);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm throwing straw men out there now (but I have been bit by these in the past): finally
won't prevent against
- Hitting cmd+. in the middle of the test
- Another test polluting the keychain
Normally I don't protect against these kinds of issues in my tests. But since keychain is both persistent and a black box I like to control for as many factors as I can in each test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah gotcha. thanks for all the tips and the open source search terms
Really good find re Mac/iOS not having the same implementation here. Not surprising at all – there are lovely subtle differences between the two implementations... keychain on iOS and Mac have entirely different implementations under then hood (the code is open source). Thank you again for the fix! Last thing before we get an approval is making the test more resilient to a rerun after failing halfway through the prior run. Almost there! (Keychain is always more complex than it looks. Always. 😅) |
where does one find the open source code? i remember @EricMuller22 entering some magical google search term... |
I tend to google "Apple open source secitem" 🙂 Here's some of it: https://opensource.apple.com/source/Security/Security-55471/sec/Security/SecItem.c |
…ncheck. * #113 * `(migrateObjectsMatchingQuery: removeOnCompletion:)` assumes that data in `kSecAttrAccount` is a NSString. * This can cause a crash if the value in kSecAttrAccount is an NSData object, for example.
@dfed I placed the |
@EricMuller22 want to merge/release? I'll get to it tomorrow if not. |
LGTM, I'll let you handle merge/release though @dfed, going to be in meetings all day 😞 |
Posted this SO question https://stackoverflow.com/questions/47602876 to see if anyone knows why OSX and iOS handle NSData objects in |
(migrateObjectsMatchingQuery: removeOnCompletion:)
assumes that data inkSecAttrAccount
is a NSString.