Class: Ciborg::Keychain

Inherits:
Object
  • Object
show all
Defined in:
lib/ciborg/keychain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/ciborg/keychain.rb', line 5

def config
  @config
end

#pathObject (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

Returns:

  • (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