Skip to content
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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

cfis
Copy link

@cfis cfis commented Feb 17, 2017

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).

Charlie Savage added 23 commits February 16, 2017 20:13
…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).
@cfis
Copy link
Author

cfis commented Jan 4, 2019

Any chance this could get merged?

Copy link
Owner

@fcheung fcheung left a 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)
Copy link
Owner

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)
Copy link
Owner

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
Copy link
Owner

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)
Copy link
Owner

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"
Copy link
Owner

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
Copy link
Owner

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)
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants