~ubuntu-branches/ubuntu/raring/ruby-net-ssh/raring

« back to all changes in this revision

Viewing changes to lib/net/ssh/key_factory.rb

  • Committer: Package Import Robot
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-25 14:30:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110925143059-g8zjooqx28sig5o5
Tags: 1:2.2.1-1
* New upstream release.
* Switch to my @debian.org email-address.
* Switch from Conflicts to Breaks.
* debian/patches/disable-test1.patch: refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
      # appropriately. The new key is returned. If the key itself is
35
35
      # encrypted (requiring a passphrase to use), the user will be
36
36
      # prompted to enter their password unless passphrase works. 
37
 
      def load_private_key(filename, passphrase=nil)
 
37
      def load_private_key(filename, passphrase=nil, ask_passphrase=true)
38
38
        data = File.read(File.expand_path(filename))
39
 
        load_data_private_key(data, passphrase, filename)
 
39
        load_data_private_key(data, passphrase, ask_passphrase, filename)
40
40
      end
41
41
 
42
42
      # Loads a private key. It will correctly determine
44
44
      # appropriately. The new key is returned. If the key itself is
45
45
      # encrypted (requiring a passphrase to use), the user will be
46
46
      # prompted to enter their password unless passphrase works. 
47
 
      def load_data_private_key(data, passphrase=nil, filename="")
 
47
      def load_data_private_key(data, passphrase=nil, ask_passphrase=true, filename="")
48
48
        if data.match(/-----BEGIN DSA PRIVATE KEY-----/)
49
49
          key_type = OpenSSL::PKey::DSA
50
50
        elsif data.match(/-----BEGIN RSA PRIVATE KEY-----/)
61
61
        begin
62
62
          return key_type.new(data, passphrase || 'invalid')
63
63
        rescue OpenSSL::PKey::RSAError, OpenSSL::PKey::DSAError => e
64
 
          if encrypted_key
 
64
          if encrypted_key && ask_passphrase
65
65
            tries += 1
66
66
            if tries <= 3
67
67
              passphrase = prompt("Enter passphrase for #{filename}:", false)