net-ssh 2.0.7 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 2.0.8 / 29 December 2008
2
+
3
+ * Fix private key change from 2.0.7 so that keys are loaded just-in-time, avoiding unecessary prompts from encrypted keys. [Jamis Buck]
4
+
5
+
1
6
  === 2.0.7 / 29 December 2008
2
7
 
3
8
  * Make key manager use private keys instead of requiring public key to exist [arilerner@mac.com]
@@ -74,17 +74,16 @@ module Net
74
74
  @agent = nil
75
75
  end
76
76
 
77
- # Returns an array of identities (public keys) known to this manager.
77
+ # Iterates over all available identities (public keys) known to this
78
+ # manager. As it finds one, it will then yield it to the caller.
78
79
  # The origin of the identities may be from files on disk or from an
79
80
  # ssh-agent. Note that identities from an ssh-agent are always listed
80
81
  # first in the array, with other identities coming after.
81
- def identities
82
- identities = []
83
-
82
+ def each_identity
84
83
  if agent
85
84
  agent.identities.each do |key|
86
- identities.push key
87
85
  known_identities[key] = { :from => :agent }
86
+ yield key
88
87
  end
89
88
  end
90
89
 
@@ -93,15 +92,15 @@ module Net
93
92
  begin
94
93
  private_key = KeyFactory.load_private_key(file)
95
94
  key = private_key.send :public_key
96
- identities.push key
97
95
  known_identities[key] = { :from => :file, :file => file }
96
+ yield key
98
97
  rescue Exception => e
99
98
  error { "could not load public key file `#{file}.pub': #{e.class} (#{e.message})" }
100
99
  end
101
100
  end
102
101
  end
103
102
 
104
- identities
103
+ self
105
104
  end
106
105
 
107
106
  # Sign the given data, using the corresponding private key of the given
@@ -14,7 +14,7 @@ module Net
14
14
  def authenticate(next_service, username, password=nil)
15
15
  return false unless key_manager
16
16
 
17
- key_manager.identities.each do |identity|
17
+ key_manager.each_identity do |identity|
18
18
  return true if authenticate_with(identity, next_service,
19
19
  username, key_manager)
20
20
  end
@@ -16,7 +16,7 @@ module Net
16
16
  def authenticate(next_service, username, password=nil)
17
17
  return false unless key_manager
18
18
 
19
- key_manager.identities.each do |identity|
19
+ key_manager.each_identity do |identity|
20
20
  return true if authenticate_with(identity, next_service, username)
21
21
  end
22
22
 
@@ -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 = 7
54
+ TINY = 8
55
55
 
56
56
  # The current version of the Net::SSH library as a Version instance
57
57
  CURRENT = new(MAJOR, MINOR, TINY)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{net-ssh}
3
- s.version = "2.0.7"
3
+ s.version = "2.0.8"
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"]
@@ -79,7 +79,11 @@ module Authentication; module Methods
79
79
  end
80
80
 
81
81
  def key_manager(options={})
82
- @key_manager ||= stub("key_manager", :identities => options[:keys] || keys)
82
+ @key_manager ||= begin
83
+ manager = stub("key_manager")
84
+ manager.stubs(:each_identity).multiple_yields(*(options[:keys] || keys))
85
+ manager
86
+ end
83
87
  end
84
88
 
85
89
  def subject(options={})
@@ -107,4 +111,4 @@ module Authentication; module Methods
107
111
 
108
112
  end
109
113
 
110
- end; end
114
+ end; end
@@ -110,7 +110,11 @@ module Authentication; module Methods
110
110
  end
111
111
 
112
112
  def key_manager(options={})
113
- @key_manager ||= stub("key_manager", :identities => options[:keys] || keys)
113
+ @key_manager ||= begin
114
+ manager = stub("key_manager")
115
+ manager.stubs(:each_identity).multiple_yields(*(options[:keys] || keys))
116
+ manager
117
+ end
114
118
  end
115
119
 
116
120
  def subject(options={})
@@ -120,4 +124,4 @@ module Authentication; module Methods
120
124
 
121
125
  end
122
126
 
123
- end; end
127
+ end; end
@@ -28,13 +28,15 @@ module Authentication
28
28
  assert !manager.use_agent?
29
29
  end
30
30
 
31
- def test_identities_should_load_from_key_files
31
+ def test_each_identity_should_load_from_key_files
32
32
  manager.stubs(:agent).returns(nil)
33
33
 
34
34
  stub_file_key "/first", rsa
35
35
  stub_file_key "/second", dsa
36
36
 
37
- identities = manager.identities
37
+ identities = []
38
+ manager.each_identity { |identity| identities << identity }
39
+
38
40
  assert_equal 2, identities.length
39
41
  assert_equal rsa.to_blob, identities.first.to_blob
40
42
  assert_equal dsa.to_blob, identities.last.to_blob
@@ -45,7 +47,9 @@ module Authentication
45
47
 
46
48
  def test_identities_should_load_from_agent
47
49
  manager.stubs(:agent).returns(agent)
48
- identities = manager.identities
50
+
51
+ identities = []
52
+ manager.each_identity { |identity| identities << identity }
49
53
 
50
54
  assert_equal 2, identities.length
51
55
  assert_equal rsa.to_blob, identities.first.to_blob
@@ -57,7 +61,7 @@ module Authentication
57
61
 
58
62
  def test_sign_with_agent_originated_key_should_request_signature_from_agent
59
63
  manager.stubs(:agent).returns(agent)
60
- manager.identities
64
+ manager.each_identity { |identity| } # preload the known_identities
61
65
  agent.expects(:sign).with(rsa, "hello, world").returns("abcxyz123")
62
66
  assert_equal "abcxyz123", manager.sign(rsa, "hello, world")
63
67
  end
@@ -66,7 +70,7 @@ module Authentication
66
70
  manager.stubs(:agent).returns(nil)
67
71
  stub_file_key "/first", rsa(512), true
68
72
  rsa.expects(:ssh_do_sign).with("hello, world").returns("abcxyz123")
69
- manager.identities
73
+ manager.each_identity { |identity| } # preload the known_identities
70
74
  assert_equal "\0\0\0\assh-rsa\0\0\0\011abcxyz123", manager.sign(rsa, "hello, world")
71
75
  end
72
76
 
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.7
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck