sshkey 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -53,9 +53,13 @@ k.comment
53
53
  # => "foo@bar.com"
54
54
 
55
55
  # Returns the MD5 fingerprint as a string
56
- k.fingerprint
56
+ k.md5_fingerprint
57
57
  # => "2a:89:84:c9:29:05:d1:f8:49:79:1c:ba:73:99:eb:af"
58
58
 
59
+ # Returns the SHA1 fingerprint as a string
60
+ k.sha1_fingerprint
61
+ # => "e4:f9:79:f2:fe:d6:be:2d:ef:2e:c2:fa:aa:f8:b0:17:34:fe:0d:c0"
62
+
59
63
  # Validates SSH Public Key
60
64
  SSHKey.valid_ssh_public_key? "ssh-rsa AAAAB3NzaC1yc2EA...."
61
65
  # => true
@@ -1,24 +1,47 @@
1
1
  require 'openssl'
2
2
  require 'base64'
3
3
  require 'digest/md5'
4
+ require 'digest/sha1'
4
5
 
5
6
  class SSHKey
6
7
  SSH_TYPES = {"rsa" => "ssh-rsa", "dsa" => "ssh-dss"}
7
8
  SSH_CONVERSION = {"rsa" => ["e", "n"], "dsa" => ["p", "q", "g", "pub_key"]}
8
9
 
9
10
  attr_reader :key_object, :comment, :type
10
-
11
+ attr_accessor :passphrase
12
+
13
+ # Generate a new keypair and return an SSHKey object
14
+ #
15
+ # The default behavior when providing no options will generate a 2048-bit RSA
16
+ # keypair.
17
+ #
18
+ # ==== Parameters
19
+ # * options<~Hash>:
20
+ # * :type<~String> - "rsa" or "dsa", "rsa" by default
21
+ # * :bits<~Integer> - Bit length
22
+ # * :comment<~String> - Comment to use for the public key, defaults to ""
23
+ # * :passphrase<~String> - Encrypt the key with this passphrase
24
+ #
11
25
  def self.generate(options = {})
12
- type = options[:type] || "rsa"
13
- bits = options[:bits] || 2048
26
+ type = options[:type] || "rsa"
27
+ bits = options[:bits] || 2048
28
+ cipher = OpenSSL::Cipher::Cipher.new("AES-128-CBC") if options[:passphrase]
29
+
14
30
  case type.downcase
15
- when "rsa" then SSHKey.new(OpenSSL::PKey::RSA.generate(bits).to_pem, options)
16
- when "dsa" then SSHKey.new(OpenSSL::PKey::DSA.generate(bits).to_pem, options)
31
+ when "rsa" then SSHKey.new(OpenSSL::PKey::RSA.generate(bits).to_pem(cipher, options[:passphrase]), options)
32
+ when "dsa" then SSHKey.new(OpenSSL::PKey::DSA.generate(bits).to_pem(cipher, options[:passphrase]), options)
17
33
  else
18
- raise "Unknown key type #{type}"
34
+ raise "Unknown key type: #{type}"
19
35
  end
20
36
  end
21
37
 
38
+ # Validate an existing SSH public key
39
+ #
40
+ # Returns true or false depending on the validity of the public key provided
41
+ #
42
+ # ==== Parameters
43
+ # * ssh_public_key<~String> - "ssh-rsa AAAAB3NzaC1yc2EA...."
44
+ #
22
45
  def self.valid_ssh_public_key?(ssh_public_key)
23
46
  ssh_type, encoded_key = ssh_public_key.split(" ")
24
47
  type = SSH_TYPES.invert[ssh_type]
@@ -45,11 +68,6 @@ class SSHKey
45
68
  false
46
69
  end
47
70
 
48
- def self.valid?(ssh_public_key)
49
- puts "DEPRECATION WARNING: SSHKey.valid? has been renamed to SSHKey.valid_ssh_public_key? for clarity. SSHKey.valid? will be removed in 1.3."
50
- valid_ssh_public_key?(ssh_public_key)
51
- end
52
-
53
71
  def self.from_byte_array(byte_array, expected_size = nil)
54
72
  num = 0
55
73
  raise "Byte array too short" if !expected_size.nil? && expected_size != byte_array.size
@@ -59,59 +77,78 @@ class SSHKey
59
77
  num
60
78
  end
61
79
 
80
+ # Create a new SSHKey object
81
+ #
82
+ # ==== Parameters
83
+ # * private_key - Existing RSA or DSA private key
84
+ # * options<~Hash>
85
+ # * :comment<~String> - Comment to use for the public key, defaults to ""
86
+ # * :passphrase<~String> - If the key is encrypted, supply the passphrase
87
+ #
62
88
  def initialize(private_key, options = {})
89
+ @passphrase = options[:passphrase]
90
+ @comment = options[:comment] || ""
63
91
  begin
64
- @key_object = OpenSSL::PKey::RSA.new(private_key)
92
+ @key_object = OpenSSL::PKey::RSA.new(private_key, passphrase)
65
93
  @type = "rsa"
66
94
  rescue
67
- @key_object = OpenSSL::PKey::DSA.new(private_key)
95
+ @key_object = OpenSSL::PKey::DSA.new(private_key, passphrase)
68
96
  @type = "dsa"
69
97
  end
70
-
71
- @comment = options[:comment] || ""
72
98
  end
73
99
 
100
+ # Fetch the RSA/DSA private key
101
+ #
102
+ # rsa_private_key and dsa_private_key are aliased for backward compatibility
74
103
  def private_key
75
104
  key_object.to_pem
76
105
  end
106
+ alias_method :rsa_private_key, :private_key
107
+ alias_method :dsa_private_key, :private_key
77
108
 
78
- def public_key
79
- key_object.public_key.to_pem
80
- end
81
-
82
- ########################
83
- # Backward compatibility
84
- def rsa_private_key
85
- private_key if type == "rsa"
109
+ # Fetch the encrypted RSA/DSA private key using the passphrase provided
110
+ #
111
+ # If no passphrase is set, returns the unencrypted private key
112
+ def encrypted_private_key
113
+ return private_key unless passphrase
114
+ key_object.to_pem(OpenSSL::Cipher::Cipher.new("AES-128-CBC"), passphrase)
86
115
  end
87
116
 
88
- def rsa_public_key
89
- public_key if type == "rsa"
90
- end
91
-
92
- def dsa_private_key
93
- private_key if type == "dsa"
94
- end
95
-
96
- def dsa_public_key
97
- public_key if type == "dsa"
117
+ # Fetch the RSA/DSA public key
118
+ #
119
+ # rsa_public_key and dsa_public_key are aliased for backward compatibility
120
+ def public_key
121
+ key_object.public_key.to_pem
98
122
  end
99
- ########################
123
+ alias_method :rsa_public_key, :public_key
124
+ alias_method :dsa_public_key, :public_key
100
125
 
126
+ # SSH public key
101
127
  def ssh_public_key
102
128
  [SSH_TYPES[type], Base64.encode64(ssh_public_key_conversion).gsub("\n", ""), comment].join(" ").strip
103
129
  end
104
130
 
105
- def fingerprint
131
+ # Fingerprints
132
+ #
133
+ # MD5 fingerprint for the given SSH public key
134
+ def md5_fingerprint
106
135
  Digest::MD5.hexdigest(ssh_public_key_conversion).gsub(/(.{2})(?=.)/, '\1:\2')
107
136
  end
137
+ alias_method :fingerprint, :md5_fingerprint
138
+
139
+ # SHA1 fingerprint for the given SSH public key
140
+ def sha1_fingerprint
141
+ Digest::SHA1.hexdigest(ssh_public_key_conversion).gsub(/(.{2})(?=.)/, '\1:\2')
142
+ end
108
143
 
109
144
  private
110
145
 
146
+ # SSH Public Key Conversion
147
+ #
111
148
  # All data type encoding is defined in the section #5 of RFC #4251.
112
- # String and mpint (multiple precision integer) types are encoded this way :
149
+ # String and mpint (multiple precision integer) types are encoded this way:
113
150
  # 4-bytes word: data length (unsigned big-endian 32 bits integer)
114
- # n bytes : binary representation of the data
151
+ # n bytes: binary representation of the data
115
152
 
116
153
  # For instance, the "ssh-rsa" string is encoded as the following byte array
117
154
  # [0, 0, 0, 7, 's', 's', 'h', '-', 'r', 's', 'a']
@@ -1,3 +1,3 @@
1
1
  class SSHKey
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -75,21 +75,107 @@ GzM8qwTcXd06uIZAJdTHIQ==
75
75
  -----END DSA PRIVATE KEY-----
76
76
  EOF
77
77
 
78
+ ENCRYPTED_PRIVATE_KEY = <<-EOF
79
+ -----BEGIN RSA PRIVATE KEY-----
80
+ Proc-Type: 4,ENCRYPTED
81
+ DEK-Info: AES-128-CBC,3514D8812B519059944A811726594515
82
+
83
+ fSr1v51I65MZrSs7u12nype6RH6NS15xN5FDPaPKV++EBPxysEzicU5QHDt/aHa3
84
+ t87nXkra1M400+zNgFcfi5Ga7w5SBmqEjdNgwhUV2/j1Yqqlr5c7l804OfIPxdE6
85
+ ELoWH7pen72JnlZe6gXq495W96QTg3IzIWdiKEbKJlEwrNBligqT7GB2mup8nY1D
86
+ o71R07dIrvfDy3xVgCoRjX4LKUilO6nRnwVCFRgVQTEVKclqt8NiSFGMjzv3iekR
87
+ f1fJ8Wm6CiST8zdetIXgMnHEK1KELhNeMhI/42Tn/gHPDsckBiKLtM+85OOT92wh
88
+ L9o/KUySdcsb/ld0yT/kAc99/wqNitHAqUEcLshIWDVhqoT1XK46hEuRN782AN2U
89
+ shQKirF8QFopYF+u9K2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e8O81/3rnw28DthDQO
105
+ SuzrY0HinPEFomwMGbfhosB5kOmBXEk7XbSWWHhK0QG63CYqp5caUst2Mie21b0Y
106
+ FgFTrS1VqUiqDjCmt8F8UCPQS89aFm096wqtmwDO+VWKanuHUUShtTPlYyLe1RTm
107
+ wqh1BBa05ydM0Vf1NagFB4JNT1qSIL5x4XtkOFwqcdXWYvwYfT8PkZjX/kz+W7jb
108
+ -----END RSA PRIVATE KEY-----
109
+ EOF
110
+
111
+ DECRYPTED_PRIVATE_KEY = <<-EOF
112
+ -----BEGIN RSA PRIVATE KEY-----
113
+ MIIEpAIBAAKCAQEA33H9u4rG0SVMzK8PFyIi30kVHvogmpKVOQL2g2tozi2GipkA
114
+ imzoCW9jIx1jo6zo0kMKCbMdJCNUc93tQxkJAAWA07WYwE9z+J6MC/3urb4Q0UAZ
115
+ orlNyN3pPP8ATFIQomd0wW/EHwbmknlJOIZY4MNUQpNJunnBAAzZyLef6+sbLzQZ
116
+ wc0/vgtmatoCxh4mZWFuFMopkMqScYDKxL30xXXPRGfJvAVWZDnY3ErJSe7uyefI
117
+ Zo/lp4tsH5XGMcFm+nLs++nJjYZ6Ud/ie1g+ZCJv5Qit1m7zCVjiJ4RVMC/4yTb7
118
+ CO8n4PhX8gR9d1DRPVvlKa1sZfQeULEIXMniKQIDAQABAoIBAQDEXS74s5rJjhgS
119
+ AP4n/E3dICK5mGMytAMDmUD+eVQfbQ7BmnhJLjA0qnjbESbRXlE1Bsk5gPjpG0tK
120
+ kAvEXan1JOD0LLDSwIBQSzUUDNLGSTQKUGS3BlX/YlVoz0h5ydzofDa1D/2wrqXO
121
+ r1vTmu1ciQvxffLbN8iOvLxfkk+uSMhqnhf/q3WVinu+VALPg8e/v3p4VbnSfP4D
122
+ eClBiMKEKRFdsa9xBxShijcX1HxjIvp3zDgb127fo2iFw09PIHUZCUo6M77iGrQY
123
+ mscoA+5q1qSyD6Btw0EkKK55ytNMC2T+KfGYV0ySwhadmM+5+G64etvNGCn/j7C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RUBO0MY5b3DZ69J/mRzUifN1O6twk4er2ph0JpryuUwZohLpcVZwqoGWmPQy/ZHmV1b3RtT9GWUa+HUqKdMhFVOx/iq1khVfLi83whjMMvXj3ecqd0yzGxGHnSsjVKefa2ywCLHrh4nlUVIaXI5gQpgMyVbMcromDe1WZzoAAACBAIwTRPAEcroqOzaebiVspFcmsXxDQ4wXQZQdho1ExW6FKS8s7/6pItmZYXTvJDwLXgq2/iK1fRRcKk2PJEaSuJR7WeNGsJKfWmQ2UbOhqA3wWLDazIZtcMKjFzD0hM4E8qgjHjMvKDE6WgT6SFP+tqx3nnh7pJWwsbGjSMQexpyR'
81
146
 
82
- KEY1_FINGERPRINT = "2a:89:84:c9:29:05:d1:f8:49:79:1c:ba:73:99:eb:af"
83
- KEY2_FINGERPRINT = "3c:af:74:87:cc:cc:a1:12:05:1a:09:b7:7b:ce:ed:ce"
84
- KEY3_FINGERPRINT = "14:f6:6a:12:96:be:44:32:e6:3c:77:43:94:52:f5:7a"
147
+ KEY1_MD5_FINGERPRINT = "2a:89:84:c9:29:05:d1:f8:49:79:1c:ba:73:99:eb:af"
148
+ KEY2_MD5_FINGERPRINT = "3c:af:74:87:cc:cc:a1:12:05:1a:09:b7:7b:ce:ed:ce"
149
+ KEY3_MD5_FINGERPRINT = "14:f6:6a:12:96:be:44:32:e6:3c:77:43:94:52:f5:7a"
150
+
151
+ KEY1_SHA1_FINGERPRINT = "e4:f9:79:f2:fe:d6:be:2d:ef:2e:c2:fa:aa:f8:b0:17:34:fe:0d:c0"
152
+ KEY2_SHA1_FINGERPRINT = "9a:52:78:2b:6b:cb:39:b7:85:ed:90:8a:28:62:aa:b3:98:88:e6:07"
153
+ KEY3_SHA1_FINGERPRINT = "15:68:c6:72:ac:18:d1:fc:ab:a2:b7:b5:8c:d1:fe:8f:b9:ae:a9:47"
85
154
 
86
155
  def setup
87
156
  @key1 = SSHKey.new(SSH_PRIVATE_KEY1, :comment => "me@example.com")
88
157
  @key2 = SSHKey.new(SSH_PRIVATE_KEY2, :comment => "me@example.com")
89
158
  @key3 = SSHKey.new(SSH_PRIVATE_KEY3, :comment => "me@example.com")
159
+ @key_encrypted = SSHKey.new(ENCRYPTED_PRIVATE_KEY, :passphrase => "password")
90
160
  @key_without_comment = SSHKey.new(SSH_PRIVATE_KEY1)
91
161
  end
92
162
 
163
+ def test_generator_with_no_args
164
+ assert_kind_of SSHKey, SSHKey.generate
165
+ end
166
+
167
+ def test_generator_with_comment
168
+ assert_equal "foo", SSHKey.generate(:comment => "foo").comment
169
+ end
170
+
171
+ def test_generator_with_type
172
+ assert_equal "dsa", SSHKey.generate(:type => "dsa").type
173
+ end
174
+
175
+ def test_generator_with_passphrase
176
+ assert_equal "password", SSHKey.generate(:passphrase => "password").passphrase
177
+ end
178
+
93
179
  def test_private_key1
94
180
  assert_equal SSH_PRIVATE_KEY1, @key1.private_key
95
181
  assert_equal SSH_PRIVATE_KEY1, @key1.rsa_private_key
@@ -105,6 +191,20 @@ EOF
105
191
  assert_equal SSH_PRIVATE_KEY3, @key3.dsa_private_key
106
192
  end
107
193
 
194
+ def test_encrypted_private_key_can_be_decrypted
195
+ assert_equal DECRYPTED_PRIVATE_KEY, @key_encrypted.private_key
196
+ end
197
+
198
+ def test_encrypted_private_key_matches_when_reencrypted
199
+ key = SSHKey.new(@key_encrypted.encrypted_private_key, :passphrase => "password")
200
+ assert_equal DECRYPTED_PRIVATE_KEY, key.private_key
201
+ assert_equal DECRYPTED_KEY_FINGERPRINT, key.md5_fingerprint
202
+ end
203
+
204
+ def test_unencrypted_private_key_returns_private_key_when_asked_for_encrypted
205
+ assert_equal SSH_PRIVATE_KEY1, @key1.encrypted_private_key
206
+ end
207
+
108
208
  def test_ssh_public_key_decoded1
109
209
  assert_equal Base64.decode64(SSH_PUBLIC_KEY1), @key1.send(:ssh_public_key_conversion)
110
210
  end
@@ -151,16 +251,16 @@ EOF
151
251
  invalid4 = "ssh-rsa A#{SSH_PUBLIC_KEY1}"
152
252
  invalid5 = "ssh-rsa #{SSH_PUBLIC_KEY3} me@example.com"
153
253
 
154
- assert SSHKey.valid?(expected1)
155
- assert SSHKey.valid?(expected2)
156
- assert SSHKey.valid?(expected3)
157
- assert SSHKey.valid?(expected4)
254
+ assert SSHKey.valid_ssh_public_key?(expected1)
255
+ assert SSHKey.valid_ssh_public_key?(expected2)
256
+ assert SSHKey.valid_ssh_public_key?(expected3)
257
+ assert SSHKey.valid_ssh_public_key?(expected4)
158
258
 
159
- assert !SSHKey.valid?(invalid1)
160
- assert !SSHKey.valid?(invalid2)
161
- assert !SSHKey.valid?(invalid3)
162
- assert !SSHKey.valid?(invalid4)
163
- assert !SSHKey.valid?(invalid5)
259
+ assert !SSHKey.valid_ssh_public_key?(invalid1)
260
+ assert !SSHKey.valid_ssh_public_key?(invalid2)
261
+ assert !SSHKey.valid_ssh_public_key?(invalid3)
262
+ assert !SSHKey.valid_ssh_public_key?(invalid4)
263
+ assert !SSHKey.valid_ssh_public_key?(invalid5)
164
264
  end
165
265
 
166
266
  def test_exponent
@@ -174,9 +274,14 @@ EOF
174
274
  end
175
275
 
176
276
  def test_fingerprint
177
- assert_equal KEY1_FINGERPRINT, @key1.fingerprint
178
- assert_equal KEY2_FINGERPRINT, @key2.fingerprint
179
- assert_equal KEY3_FINGERPRINT, @key3.fingerprint
277
+ assert_equal KEY1_MD5_FINGERPRINT, @key1.md5_fingerprint
278
+ assert_equal KEY1_MD5_FINGERPRINT, @key1.fingerprint # Aliased method
279
+ assert_equal KEY2_MD5_FINGERPRINT, @key2.md5_fingerprint
280
+ assert_equal KEY3_MD5_FINGERPRINT, @key3.md5_fingerprint
281
+
282
+ assert_equal KEY1_SHA1_FINGERPRINT, @key1.sha1_fingerprint
283
+ assert_equal KEY2_SHA1_FINGERPRINT, @key2.sha1_fingerprint
284
+ assert_equal KEY3_SHA1_FINGERPRINT, @key3.sha1_fingerprint
180
285
  end
181
286
 
182
287
  def test_to_byte_array
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-09 00:00:00.000000000 Z
12
+ date: 2011-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70227494691020 !ruby/object:Gem::Requirement
16
+ requirement: &70360303706000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70227494691020
24
+ version_requirements: *70360303706000
25
25
  description: Generate private/public SSH keypairs using pure Ruby
26
26
  email:
27
27
  - bensie@gmail.com