Class: Ciborg::Keychain
- Inherits:
-
Object
- Object
- Ciborg::Keychain
- Defined in:
- lib/ciborg/keychain.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #add_certificate(certificate) ⇒ Object
- #fetch_remote_certificate(host) ⇒ Object
- #has_key?(key_name) ⇒ Boolean
-
#initialize(keychain_path) ⇒ Keychain
constructor
A new instance of Keychain.
Constructor Details
#initialize(keychain_path) ⇒ Keychain
Returns a new instance of Keychain.
7 8 9 |
# File 'lib/ciborg/keychain.rb', line 7 def initialize(keychain_path) @path = keychain_path end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/ciborg/keychain.rb', line 5 def config @config end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/ciborg/keychain.rb', line 5 def path @path end |
Instance Method Details
#add_certificate(certificate) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ciborg/keychain.rb', line 19 def add_certificate(certificate) certificate_file = Tempfile.new("ciborg.crt").tap do |f| f.write(certificate) f.close end system("sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain #{certificate_file.path}") end |
#fetch_remote_certificate(host) ⇒ Object
15 16 17 |
# File 'lib/ciborg/keychain.rb', line 15 def fetch_remote_certificate(host) http_client.get(host).peer_cert.to_s end |
#has_key?(key_name) ⇒ Boolean
11 12 13 |
# File 'lib/ciborg/keychain.rb', line 11 def has_key?(key_name) system("sudo security find-certificate -c \"#{key_name}\" #{path} > /dev/null 2>&1") end |