Module: SSH::Key::Helper

Included in:
Signer, Verifier
Defined in:
lib/ssh/key/helper.rb

Instance Method Summary collapse

Instance Method Details

#add_key_file(path, passphrase = nil) ⇒ Object

Add a private key to this signer.



8
9
10
11
# File 'lib/ssh/key/helper.rb', line 8

def add_key_file(path, passphrase=nil)
  @logger.info "Adding key from file #{path} (with#{passphrase ? "" : "out"} passphrase)"
  @keys << Net::SSH::KeyFactory.load_private_key(path, passphrase)
end

#add_key_from_host(hostname) ⇒ Object

Add a public key from your known_hosts file



14
15
16
17
18
19
20
21
# File 'lib/ssh/key/helper.rb', line 14

def add_key_from_host(hostname)
  hostkey = %x{ssh-keygen -F "#{hostname}"}.split("\n")[1].chomp.split(" ",2)[-1] rescue nil
  if hostkey == nil
    raise SSH::Key::KeyNotFound.new("Could not find host key '#{hostname}' " \
                                     "in known_hosts (using ssh-keygen -F)")
  end
  @keys << Net::SSH::KeyFactory.load_data_public_key(hostkey)
end

#add_public_key_data(data) ⇒ Object

Add a public key from a ublic key string



24
25
26
27
# File 'lib/ssh/key/helper.rb', line 24

def add_public_key_data(data)
  @logger.info "Adding key from data #{data}"
  @keys << Net::SSH::KeyFactory.load_data_public_key(data)
end