Skip to content

Commit

Permalink
Backported net-ssh ask_passphrase functionality
Browse files Browse the repository at this point in the history
MSP-10038
  • Loading branch information
farias-r7 committed Jun 18, 2014
1 parent b8cedf1 commit f24d665
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/net/ssh/key_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ def get(name)
# appropriately. The new key is returned. If the key itself is
# encrypted (requiring a passphrase to use), the user will be
# prompted to enter their password unless passphrase works.
def load_private_key(filename, passphrase=nil)
def load_private_key(filename, passphrase=nil, ask_passphrase=true)
data = File.open(File.expand_path(filename), "rb") {|f| f.read(f.stat.size)}
load_data_private_key(data, passphrase, filename)
load_data_private_key(data, passphrase, ask_passphrase, filename)
end

# Loads a private key. It will correctly determine
# whether the file describes an RSA or DSA key, and will load it
# appropriately. The new key is returned. If the key itself is
# encrypted (requiring a passphrase to use), the user will be
# prompted to enter their password unless passphrase works.
def load_data_private_key(data, passphrase=nil, filename="")
def load_data_private_key(data, passphrase=nil, ask_passphrase= true, filename="")
if data.match(/-----BEGIN DSA PRIVATE KEY-----/)
key_type = OpenSSL::PKey::DSA
elsif data.match(/-----BEGIN RSA PRIVATE KEY-----/)
Expand All @@ -62,7 +62,7 @@ def load_data_private_key(data, passphrase=nil, filename="")
begin
return key_type.new(data, passphrase || 'invalid')
rescue OpenSSL::PKey::RSAError, OpenSSL::PKey::DSAError => e
if encrypted_key
if encrypted_key && ask_passphrase
tries += 1
if tries <= 3
passphrase = prompt("Enter passphrase for #{filename}:", false)
Expand Down

0 comments on commit f24d665

Please sign in to comment.