-
Notifications
You must be signed in to change notification settings - Fork 15
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
Allow Updating Keys and Certificates in a KeyChain #9
base: master
Are you sure you want to change the base?
Conversation
…ored in a key chain. It does this by moving access to SecItemUpdate to the Sec::Base class. This was inspired by the section “Adding, Removing, and Working With Keys and Certificates” in the Key Services Programming Guide which mentions SecItemAdd, SecItemUpdate and SecItemCopyMatching as base functions that should be used on keys and certificates stored in the KeyChain. This patch does make it possible for example to change a key’s name as stored in the keychain (my particular use case).
…for certificate start and finish times.
…ptions in Scope class.
Any chance this could get merged? |
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.
Hi,
thanks for this! Looks 99% good, just a few small comments that i've left - mostly memory related. I've also fixed the travis build on master - if you could merge master again & see if get gets travis green on your branch than that would be super.
access_buffer = FFI::MemoryPointer.new(:pointer) | ||
status = Sec.SecKeychainItemCopyAccess(self, access_buffer) | ||
Sec.check_osstatus status | ||
Access.new(access_buffer.read_pointer) |
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.
Do you need a release_on_gc here (to eventually release the result of SecKeychainItemCopyAccess?)
access_buffer = FFI::MemoryPointer.new(:pointer) | ||
status = Sec.SecAccessCreate(description.to_cf, trusted_apps.to_cf, access_buffer) | ||
Sec.check_osstatus status | ||
self.new(access_buffer.read_pointer) |
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.
And here too?
unless applications_ref.read_pointer.null? | ||
applications_cf = CF::Base.typecast(applications_ref.read_pointer).release_on_gc | ||
@applications = applications_cf.to_ruby | ||
applications_cf.release |
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 this is releaseing applications_ref a second time
self | ||
else | ||
pointer = Sec.SecKeyCopyPublicKey(self) | ||
self.class.new(pointer) |
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.
release_on_gc?
@conditions.each do |key, value| | ||
key_cf = inverse_attributes[key] || INVERSE_ATTR_MAP[key] | ||
if key_cf.nil? | ||
raise "Unknown search key: #{key}. Type: #{@kind}. Please look at the class's ATTR_MAP constant for accepted keys" |
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.
raise ArgumentError rather than runtime error for these?
Sec.check_osstatus(status) | ||
CF::Base.new(out.read_pointer).release_on_gc | ||
end | ||
|
||
# Removes the item from the associated keychain | ||
def delete |
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 this only makes sense if some of the things that inherit from Sec::Base cease to do so (Access, TrustedApplication, ACL, maybe more), since those aren't (If I understand correctly) keychain items
query = build_refresh_query | ||
status = Sec.SecItemCopyMatching(query, result) | ||
Sec.check_osstatus(status) | ||
cf_dict = CF::Base.typecast(result.read_pointer) |
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 this is another missing release (although it looks like this was in the original code too)
The goal of this patch is to enable updating keys and certificates stored in a key chain. It does this by moving access to SecItemUpdate to the Sec::Base class. This was inspired by the section “Adding, Removing, and Working With Keys and Certificates” in the Key Services Programming Guide which mentions SecItemAdd, SecItemUpdate and SecItemCopyMatching as base functions that should be used on keys and certificates stored in the KeyChain. This patch does make it possible for example to change a key’s name as stored in the keychain (my particular use case).