public
Description: Pure Ruby implementation of an SSH (protocol 2) client
Homepage: http://rubyforge.org/projects/net-ssh
Clone URL: git://github.com/jamis/net-ssh.git
Search Repo:
Fix hmac key truncation bug that causes hmacs other than SHA1 to fail
jamis (author)
Wed May 14 10:31:50 -0700 2008
commit  b42295ad9b4b778a1fecf3aa6fee4bf5091fac12
tree    da3968d3d9eb712ae0174f2c094252ec724c35b1
parent  83a43136fed5ef5f6dae7b0762c16615749023d1
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 === *unreleased*
0
 
0
+* Fixed key truncation bug that caused hmacs other than SHA1 to fail with "corrupt hmac" errors [Jamis Buck]
0
+
0
 * Fix detection and loading of public keys when the keys don't actually exist [David Dollar]
0
 
0
 
...
31
32
33
34
35
 
 
36
37
38
 
 
 
 
 
 
39
40
41
...
31
32
33
 
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
0
@@ -31,11 +31,17 @@
0
       define_method(attribute) { self.class.send(attribute) }
0
     end
0
 
0
- # The key to use for this instance.
0
- attr_accessor :key
0
+ # The key in use for this instance.
0
+ attr_reader :key
0
 
0
     def initialize(key=nil)
0
       self.key = key
0
+ end
0
+
0
+ # Sets the key to the given value, truncating it so that it is the correct
0
+ # length.
0
+ def key=(value)
0
+ @key = value ? value.to_s[0,key_length] : nil
0
     end
0
 
0
     # Compute the HMAC digest for the given data string.
...
24
25
26
 
 
 
 
 
27
28
29
...
24
25
26
27
28
29
30
31
32
33
34
0
@@ -24,6 +24,11 @@
0
       assert_equal "\275\345\006\307y~Oi\035<.\341\031\250<\257", hmac.digest("hello world")
0
     end
0
 
0
+ def test_key_should_be_truncated_to_required_length
0
+ hmac = subject.new("12345678901234567890")
0
+ assert_equal "1234567890123456", hmac.key
0
+ end
0
+
0
     private
0
 
0
       def subject
...
7
8
9
10
 
11
12
13
...
7
8
9
 
10
11
12
13
0
@@ -7,7 +7,7 @@
0
     Net::SSH::Transport::HMAC::MAP.each do |name, value|
0
       method = name.tr("-", "_")
0
       define_method("test_get_with_#{method}_returns_new_hmac_instance") do
0
- key = "abcdefghijklmnopqrstuvwxyz"[0..Net::SSH::Transport::HMAC::MAP[name].key_length]
0
+ key = "abcdefghijklmnopqrstuvwxyz"[0,Net::SSH::Transport::HMAC::MAP[name].key_length]
0
         hmac = Net::SSH::Transport::HMAC.get(name, key)
0
         assert_instance_of Net::SSH::Transport::HMAC::MAP[name], hmac
0
         assert_equal key, hmac.key

Comments

    No one has commented yet.