net-ssh 2.0.10 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
+ === 2.0.11 / 24 Feb 2009
2
+
3
+ * Add :key_data option for specifying raw private keys in PEM format [Alex Holems, Andrew Babkin]
4
+
5
+
1
6
  === 2.0.10 / 4 Feb 2009
2
7
 
3
8
  * Added Net::SSH.configuration_for to make it easier to query the SSH configuration file(s) [Jamis Buck]
@@ -62,7 +62,7 @@ module Net
62
62
  # Net::SSH.start for a description of each option.
63
63
  VALID_OPTIONS = [
64
64
  :auth_methods, :compression, :compression_level, :config, :encryption,
65
- :forward_agent, :hmac, :host_key, :kex, :keys, :languages,
65
+ :forward_agent, :hmac, :host_key, :kex, :keys, :key_data, :languages,
66
66
  :logger, :paranoid, :password, :port, :proxy, :rekey_blocks_limit,
67
67
  :rekey_limit, :rekey_packet_limit, :timeout, :verbose,
68
68
  :global_known_hosts_file, :user_known_hosts_file, :host_key_alias,
@@ -123,6 +123,8 @@ module Net
123
123
  # * :kex => the key exchange algorithm (or algorithms) to use
124
124
  # * :keys => an array of file names of private keys to use for publickey
125
125
  # and hostbased authentication
126
+ # * :key_data => an array of strings, with each element of the array being
127
+ # a raw private key in PEM format.
126
128
  # * :logger => the logger instance to use when logging
127
129
  # * :paranoid => either true, false, or :very, specifying how strict
128
130
  # host-key verification should be
@@ -27,6 +27,9 @@ module Net
27
27
  # The list of user key files that will be examined
28
28
  attr_reader :key_files
29
29
 
30
+ # The list of user key data that will be examined
31
+ attr_reader :key_data
32
+
30
33
  # The map of loaded identities
31
34
  attr_reader :known_identities
32
35
 
@@ -38,6 +41,7 @@ module Net
38
41
  def initialize(logger, options={})
39
42
  self.logger = logger
40
43
  @key_files = []
44
+ @key_data = []
41
45
  @use_agent = true
42
46
  @known_identities = {}
43
47
  @agent = nil
@@ -50,6 +54,7 @@ module Net
50
54
  # files.
51
55
  def clear!
52
56
  key_files.clear
57
+ key_data.clear
53
58
  known_identities.clear
54
59
  self
55
60
  end
@@ -60,6 +65,12 @@ module Net
60
65
  self
61
66
  end
62
67
 
68
+ # Add the given key_file to the list of keys that will be used.
69
+ def add_key_data(key_data_)
70
+ key_data.push(key_data_).uniq!
71
+ self
72
+ end
73
+
63
74
  # This is used as a hint to the KeyManager indicating that the agent
64
75
  # connection is no longer needed. Any other open resources may be closed
65
76
  # at this time.
@@ -109,6 +120,13 @@ module Net
109
120
  end
110
121
  end
111
122
 
123
+ key_data.each do |data|
124
+ private_key = KeyFactory.load_data_private_key(data)
125
+ key = private_key.send(:public_key)
126
+ known_identities[key] = { :from => :key_data, :data => data, :key => private_key }
127
+ yield key
128
+ end
129
+
112
130
  self
113
131
  end
114
132
 
@@ -53,7 +53,8 @@ module Net; module SSH; module Authentication
53
53
  message = expect_message(SERVICE_ACCEPT)
54
54
 
55
55
  key_manager = KeyManager.new(logger, options)
56
- keys.each { |key| key_manager.add(key) }
56
+ keys.each { |key| key_manager.add(key) } unless keys.empty?
57
+ key_data.each { |key2| key_manager.add_key_data(key2) } unless key_data.empty?
57
58
 
58
59
  attempted = []
59
60
 
@@ -123,5 +124,11 @@ module Net; module SSH; module Authentication
123
124
  %w(~/.ssh/id_dsa ~/.ssh/id_rsa ~/.ssh2/id_dsa ~/.ssh2/id_rsa)
124
125
  )
125
126
  end
127
+
128
+ # Returns an array of the key data that should be used when
129
+ # attempting any key-based authentication mechanism.
130
+ def key_data
131
+ Array(options[:key_data])
132
+ end
126
133
  end
127
134
  end; end; end
@@ -35,23 +35,31 @@ module Net; module SSH
35
35
  # encrypted (requiring a passphrase to use), the user will be
36
36
  # prompted to enter their password unless passphrase works.
37
37
  def load_private_key(filename, passphrase=nil)
38
- file = File.read(File.expand_path(filename))
38
+ data = File.read(File.expand_path(filename))
39
+ load_data_private_key(data, passphrase, filename)
40
+ end
39
41
 
40
- if file.match(/-----BEGIN DSA PRIVATE KEY-----/)
42
+ # Loads a private key. It will correctly determine
43
+ # whether the file describes an RSA or DSA key, and will load it
44
+ # appropriately. The new key is returned. If the key itself is
45
+ # encrypted (requiring a passphrase to use), the user will be
46
+ # prompted to enter their password unless passphrase works.
47
+ def load_data_private_key(data, passphrase=nil, filename="")
48
+ if data.match(/-----BEGIN DSA PRIVATE KEY-----/)
41
49
  key_type = OpenSSL::PKey::DSA
42
- elsif file.match(/-----BEGIN RSA PRIVATE KEY-----/)
50
+ elsif data.match(/-----BEGIN RSA PRIVATE KEY-----/)
43
51
  key_type = OpenSSL::PKey::RSA
44
- elsif file.match(/-----BEGIN (.*) PRIVATE KEY-----/)
52
+ elsif data.match(/-----BEGIN (.*) PRIVATE KEY-----/)
45
53
  raise OpenSSL::PKey::PKeyError, "not a supported key type '#{$1}'"
46
54
  else
47
55
  raise OpenSSL::PKey::PKeyError, "not a private key (#{filename})"
48
56
  end
49
57
 
50
- encrypted_key = file.match(/ENCRYPTED/)
58
+ encrypted_key = data.match(/ENCRYPTED/)
51
59
  tries = 0
52
60
 
53
61
  begin
54
- return key_type.new(file, passphrase || 'invalid')
62
+ return key_type.new(data, passphrase || 'invalid')
55
63
  rescue OpenSSL::PKey::RSAError, OpenSSL::PKey::DSAError => e
56
64
  if encrypted_key
57
65
  tries += 1
@@ -72,6 +80,13 @@ module Net; module SSH
72
80
  # appropriately. The new public key is returned.
73
81
  def load_public_key(filename)
74
82
  data = File.read(File.expand_path(filename))
83
+ load_data_public_key(data, filename)
84
+ end
85
+
86
+ # Loads a public key. It will correctly determine whether
87
+ # the file describes an RSA or DSA key, and will load it
88
+ # appropriately. The new public key is returned.
89
+ def load_data_public_key(data, filename="")
75
90
  type, blob = data.split(/ /)
76
91
 
77
92
  raise Net::SSH::Exception, "public key at #{filename} is not valid" if blob.nil?
@@ -51,7 +51,7 @@ module Net; module SSH
51
51
  MINOR = 0
52
52
 
53
53
  # The tiny component of this version of the Net::SSH library
54
- TINY = 10
54
+ TINY = 11
55
55
 
56
56
  # The current version of the Net::SSH library as a Version instance
57
57
  CURRENT = new(MAJOR, MINOR, TINY)
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{net-ssh}
3
- s.version = "2.0.10"
3
+ s.version = "2.0.11"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Jamis Buck"]
7
- s.date = %q{2009-02-04}
7
+ s.date = %q{2009-02-24}
8
8
  s.description = %q{a pure-Ruby implementation of the SSH2 client protocol}
9
9
  s.email = %q{jamis@jamisbuck.org}
10
10
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/net/ssh/authentication/agent.rb", "lib/net/ssh/authentication/constants.rb", "lib/net/ssh/authentication/key_manager.rb", "lib/net/ssh/authentication/methods/abstract.rb", "lib/net/ssh/authentication/methods/hostbased.rb", "lib/net/ssh/authentication/methods/keyboard_interactive.rb", "lib/net/ssh/authentication/methods/password.rb", "lib/net/ssh/authentication/methods/publickey.rb", "lib/net/ssh/authentication/pageant.rb", "lib/net/ssh/authentication/session.rb", "lib/net/ssh/buffer.rb", "lib/net/ssh/buffered_io.rb", "lib/net/ssh/config.rb", "lib/net/ssh/connection/channel.rb", "lib/net/ssh/connection/constants.rb", "lib/net/ssh/connection/session.rb", "lib/net/ssh/connection/term.rb", "lib/net/ssh/errors.rb", "lib/net/ssh/key_factory.rb", "lib/net/ssh/known_hosts.rb", "lib/net/ssh/loggable.rb", "lib/net/ssh/packet.rb", "lib/net/ssh/prompt.rb", "lib/net/ssh/proxy/errors.rb", "lib/net/ssh/proxy/http.rb", "lib/net/ssh/proxy/socks4.rb", "lib/net/ssh/proxy/socks5.rb", "lib/net/ssh/ruby_compat.rb", "lib/net/ssh/service/forward.rb", "lib/net/ssh/test/channel.rb", "lib/net/ssh/test/extensions.rb", "lib/net/ssh/test/kex.rb", "lib/net/ssh/test/local_packet.rb", "lib/net/ssh/test/packet.rb", "lib/net/ssh/test/remote_packet.rb", "lib/net/ssh/test/script.rb", "lib/net/ssh/test/socket.rb", "lib/net/ssh/test.rb", "lib/net/ssh/transport/algorithms.rb", "lib/net/ssh/transport/cipher_factory.rb", "lib/net/ssh/transport/constants.rb", "lib/net/ssh/transport/hmac/abstract.rb", "lib/net/ssh/transport/hmac/md5.rb", "lib/net/ssh/transport/hmac/md5_96.rb", "lib/net/ssh/transport/hmac/none.rb", "lib/net/ssh/transport/hmac/sha1.rb", "lib/net/ssh/transport/hmac/sha1_96.rb", "lib/net/ssh/transport/hmac.rb", "lib/net/ssh/transport/identity_cipher.rb", "lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb", "lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb", "lib/net/ssh/transport/kex.rb", "lib/net/ssh/transport/openssl.rb", "lib/net/ssh/transport/packet_stream.rb", "lib/net/ssh/transport/server_version.rb", "lib/net/ssh/transport/session.rb", "lib/net/ssh/transport/state.rb", "lib/net/ssh/verifiers/lenient.rb", "lib/net/ssh/verifiers/null.rb", "lib/net/ssh/verifiers/strict.rb", "lib/net/ssh/version.rb", "lib/net/ssh.rb", "README.rdoc", "THANKS.rdoc"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-04 00:00:00 -07:00
12
+ date: 2009-02-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency