-
Notifications
You must be signed in to change notification settings - Fork 15
Allow Updating Keys and Certificates in a KeyChain #9
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
Open
cfis
wants to merge
23
commits into
fcheung:master
Choose a base branch
from
cfis:cfis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
81f5861
The goal of this patch is to enable updating keys and certificates st…
315934f
Add support for querying certificate information. Add helper methods…
9515277
Add support for determining the type of key - public, private or symm…
21dcbba
Read attributes on demand and move delete method to the base class.
54d3762
Add helper methods for certificates and identities.
aa0c322
Separate out and expand access apis.
6d13b73
Merge branch 'master' into cfis
0bba4ff
Fix up local variable.
cbc5f2a
Fix creating ruby PKCS12 object.
33c83f6
Update to newer gem versions.
5a92aef
Allow any app to access certificate - helps in identity tests.
1414f70
Fix up tests.
49ca1c9
Go back to previous way of handling attributes.
9821085
Update item attribute based on latest Apple documentation.
76a547c
Add concept of updateable attributes versus hard coding them in updat…
cd3d6b6
Add support for scope/search match keys. Also centralize all search …
3aed287
Add a couple of missing attributes.
38bc125
Formatting.
4c8c5c4
Add helper method for querying certificates.
187c8c8
Add in needed require.
8652747
Add rake tasks for packaging gem.
1b48ace
Update dependencies and versions.
607933a
By default trust the application importing the keychain item.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| require 'rubygems/package_task' | ||
| require 'rspec/core/rake_task' | ||
|
|
||
| RSpec::Core::RakeTask.new('spec') | ||
|
|
||
| task :default => :spec | ||
| task :default => :spec | ||
|
|
||
| # Read the spec file | ||
| spec = Gem::Specification.load('keychain.gemspec') | ||
|
|
||
| # Setup gem package task | ||
| Gem::PackageTask.new(spec) do |pkg| | ||
| pkg.package_dir = 'pkg' | ||
| pkg.need_tar = false | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,49 @@ | ||
| module Sec | ||
| attach_function 'SecAccessCreate', [:pointer, :pointer, :pointer], :osstatus | ||
| attach_function 'SecKeychainItemCopyAccess', [:pointer, :pointer], :osstatus | ||
| attach_function 'SecAccessCopyACLList', [:pointer, :pointer], :osstatus | ||
| attach_function 'SecAccessCopyMatchingACLList', [:pointer, :pointer], :pointer | ||
| attach_function 'SecKeychainItemSetAccess', [:pointer, :pointer], :osstatus | ||
| end | ||
|
|
||
| module Keychain | ||
| module AccessMixin | ||
| def access | ||
| access_buffer = FFI::MemoryPointer.new(:pointer) | ||
| status = Sec.SecKeychainItemCopyAccess(self, access_buffer) | ||
| Sec.check_osstatus status | ||
| Access.new(access_buffer.read_pointer) | ||
| end | ||
|
|
||
| def access=(value) | ||
| status = Sec.SecKeychainItemSetAccess(self, value.to_cf) | ||
| Sec.check_osstatus status | ||
| end | ||
| end | ||
|
|
||
| class Access < Sec::Base | ||
| register_type 'SecAccess' | ||
|
|
||
| def self.create(description, trusted_apps = []) | ||
| 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) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here too? |
||
| end | ||
|
|
||
| def acls | ||
| acl_list_ref = FFI::MemoryPointer.new(:pointer) | ||
| status = Sec.SecAccessCopyACLList(self, acl_list_ref) | ||
| Sec.check_osstatus status | ||
| array_ref = CF::Base.typecast(acl_list_ref.read_pointer).release_on_gc | ||
| array_ref.to_ruby | ||
| end | ||
|
|
||
| def matching_acls(authorization_tag) | ||
| access_buffer = FFI::MemoryPointer.new(:pointer) | ||
| authorization_tag_cf = CF::Base.typecast(authorization_tag) | ||
| acl_list_ref = Sec.SecAccessCopyMatchingACLList(self, authorization_tag_cf) | ||
| acl_list_ref.null? ? Array.new : CF::Base.typecast(acl_list_ref) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| module Sec | ||
| attach_function 'SecACLCopyContents', [:pointer, :pointer, :pointer, :pointer], :osstatus | ||
| attach_function 'SecACLRemove', [:pointer], :osstatus | ||
| attach_function 'SecACLCopyAuthorizations', [:pointer], :pointer | ||
| attach_function 'SecACLSetContents', [:pointer, :pointer, :pointer, :pointer], :osstatus | ||
| attach_variable 'kSecACLAuthorizationAny', :pointer | ||
| attach_variable 'kSecACLAuthorizationLogin', :pointer | ||
| attach_variable 'kSecACLAuthorizationGenKey', :pointer | ||
| attach_variable 'kSecACLAuthorizationDelete', :pointer | ||
| attach_variable 'kSecACLAuthorizationExportWrapped', :pointer | ||
| attach_variable 'kSecACLAuthorizationExportClear', :pointer | ||
| attach_variable 'kSecACLAuthorizationImportWrapped', :pointer | ||
| attach_variable 'kSecACLAuthorizationImportClear', :pointer | ||
| attach_variable 'kSecACLAuthorizationSign', :pointer | ||
| attach_variable 'kSecACLAuthorizationEncrypt', :pointer | ||
| attach_variable 'kSecACLAuthorizationDecrypt', :pointer | ||
| attach_variable 'kSecACLAuthorizationMAC', :pointer | ||
| attach_variable 'kSecACLAuthorizationDerive', :pointer | ||
| end | ||
|
|
||
| module Keychain | ||
| class Acl < Sec::Base | ||
| register_type 'SecACL' | ||
|
|
||
| attr_reader :applications, :description, :prompt | ||
|
|
||
| def initialize(ptr) | ||
| super(ptr) | ||
|
|
||
| applications_ref = FFI::MemoryPointer.new(:pointer) | ||
| description_ref = FFI::MemoryPointer.new(:pointer) | ||
| prompt_ref = FFI::MemoryPointer.new(:pointer) | ||
| status = Sec.SecACLCopyContents(self, applications_ref, description_ref, prompt_ref) | ||
| Sec.check_osstatus(status) | ||
|
|
||
| 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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is releaseing applications_ref a second time |
||
| end | ||
|
|
||
| unless description_ref.read_pointer.null? | ||
| description_cf = CF::Base.typecast(description_ref.read_pointer).release_on_gc | ||
| @description = description_cf.to_ruby | ||
| end | ||
|
|
||
| unless prompt_ref.read_pointer.null? | ||
| prompt_cf = CF::Base.typecast(prompt_ref.read_pointer).release_on_gc | ||
| @prompt = prompt_cf.to_ruby | ||
| end | ||
| end | ||
|
|
||
| def authorizations | ||
| authorizations_ref = Sec.SecACLCopyAuthorizations(self) | ||
| authorizations_cf = CF::Base.typecast(authorizations_ref) | ||
| result = authorizations_cf.to_ruby | ||
| authorizations_cf.release | ||
| result | ||
| end | ||
|
|
||
| def delete | ||
| status = Sec.SecACLRemove(self) | ||
| Sec.check_osstatus(status) | ||
| end | ||
|
|
||
| def applications=(apps) | ||
| apps_cf = apps ? apps.to_cf : nil | ||
| description_cf = apps ? self.description.to_cf : nil | ||
| prompt_cf = apps ? self.prompt.to_cf : nil | ||
| status = Sec.SecACLSetContents(self, apps_cf, description_cf, prompt_cf) | ||
| Sec.check_osstatus(status) | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?)