-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
macOS keychain sanity test #5885
Conversation
When requesting kSecClassIdentity items from the keychain sometimes invalid items are returned. These cause errSecInvalidItemRef to be returned from SecKeychainItemCopyAttributesAndData and result in an empty row in the table. Catch the error and avoid returning empty rows.
Add a simple sanity test for macOS keychain items. Closes: osquery#5021
e105018
to
1a1f75a
Compare
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.
General diff looks fine. Small request for an assert. (See the other test code for an example)
// This attr does not exist, skip it. | ||
continue; | ||
} else if (status != errSecSuccess) { | ||
// If this keychain item is not valid then don't add it to results. |
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 think we will have to free attr_list
here with SecKeychainItemFreeAttributesAndData(...)
before returning.
Something along the lines of:
if (attr_list != null) {
SecKeychainItemFreeAttributesAndData(attr_list, nullptr);
}
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.
As far as I can tell we only get a non-NULL attr_list when the call succeeded (status == errSecSuccess) so I don't think we have anything to deallocate in the error case.
Rename variable from status to os_status following review.
Add an assert for number of rows to the macOS keychain items test following review.
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 LGTM. @sharvilshah are you ok with the response? @willnewton any chance you're participating in Hacktoberfest? Happy to tag if that's the case, thanks!
Yes, this looks good. I had a cursory look and these APIs are a bit different than iOKit one. Thanks @willnewton |
@directionless looks like this is just on your review, mind taking another quick glance and then stamping if you're all set? |
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.
Sorry to bounce this back -- I think you need to ensure you have a result to test. At least, that's the pattern we seem to use elsewhere in the tests.
Yes, if you could tag for Hacktoberfest that would be great. |
The assert should be checking for greater than zero rows, not greater than or equal to zero.
LGTM |
This adds a sanity test for the macOS keychain table. Running this test exposed an issue which was causing a number of blank rows to be returned at the end of the table. An additional patch avoids this issue by adding some more error checking to the keychain APIs used and allows the test to pass.
This PR is intended to close issue #5021