Skip to content

Allow Updating Keys and Certificates in a KeyChain#9

Open
cfis wants to merge 23 commits into
fcheung:masterfrom
cfis:cfis
Open

Allow Updating Keys and Certificates in a KeyChain#9
cfis wants to merge 23 commits into
fcheung:masterfrom
cfis:cfis

Conversation

@cfis

@cfis cfis commented Feb 17, 2017

Copy link
Copy Markdown

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

cfis commented Jan 4, 2019

Copy link
Copy Markdown
Author

Any chance this could get merged?

@fcheung fcheung left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread lib/keychain/access.rb
access_buffer = FFI::MemoryPointer.new(:pointer)
status = Sec.SecKeychainItemCopyAccess(self, access_buffer)
Sec.check_osstatus status
Access.new(access_buffer.read_pointer)

Copy link
Copy Markdown
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?)

Comment thread lib/keychain/access.rb
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
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here too?

Comment thread lib/keychain/acl.rb
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
Copy Markdown
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

Comment thread lib/keychain/key.rb
self
else
pointer = Sec.SecKeyCopyPublicKey(self)
self.class.new(pointer)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release_on_gc?

Comment thread lib/keychain/scope.rb
@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
Copy Markdown
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?

Comment thread lib/keychain/sec.rb
end

# Removes the item from the associated keychain
def delete

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

Comment thread lib/keychain/sec.rb
query = build_refresh_query
status = Sec.SecItemCopyMatching(query, result)
Sec.check_osstatus(status)
cf_dict = CF::Base.typecast(result.read_pointer)

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