sshkey 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -9
- data/lib/sshkey.rb +14 -0
- data/lib/sshkey/version.rb +1 -1
- data/test/sshkey_test.rb +17 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c6a9c5ef164d05f4575e492f588a6e6aee6506e
|
4
|
+
data.tar.gz: bc65fc61b32246e9a5fa1de721188923abad2fc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfb36e68eaf79b51f30b4655acbf3da004b64faea378148e12bc8fe5831fe68d89eb636119cd2212d5adbad9bbb7fbb303b25f5e8464e169b508569f01050874
|
7
|
+
data.tar.gz: 458c373b8e718990b7667931d260dc02af65a7d463842135c5a7a9fef35a8fe43451bae4e67d5ea742425a2c10b8ab2c76f136176e0d1dfeed873e168d827ee7
|
data/README.md
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
|
3
3
|
Generate private and public SSH keys (RSA and DSA supported) using pure Ruby.
|
4
4
|
|
5
|
-
|
5
|
+
[![Build Status](https://secure.travis-ci.org/bensie/sshkey.svg?branch=master)](http://travis-ci.org/bensie/sshkey)
|
6
6
|
|
7
|
-
|
7
|
+
## Requirements
|
8
8
|
|
9
|
-
|
9
|
+
Tested / supported on CRuby 1.8.7+ and JRuby.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
gem install sshkey
|
10
14
|
|
11
15
|
## Usage
|
12
16
|
|
@@ -98,14 +102,17 @@ k.bits
|
|
98
102
|
#### Fingerprints
|
99
103
|
|
100
104
|
It is often helpful to use a fingerprint to visually or programmatically check if one key
|
101
|
-
matches another. Fetch
|
105
|
+
matches another. Fetch an MD5, SHA1, or SHA256 fingerprint of the SSH public key.
|
102
106
|
|
103
107
|
```ruby
|
104
108
|
k.md5_fingerprint
|
105
|
-
# => "
|
109
|
+
# => "04:1b:d4:18:df:87:60:94:8c:83:8a:7b:5a:35:59:3d"
|
106
110
|
|
107
111
|
k.sha1_fingerprint
|
108
|
-
# => "
|
112
|
+
# => "e5:c2:43:9e:e4:0c:0c:47:82:7a:3b:e9:61:13:bd:9c:43:eb:4c:b7"
|
113
|
+
|
114
|
+
k.sha256_fingerprint
|
115
|
+
# => "x1GEnx1SRY/QwxjMAoyO6mhQlaBedDHtYLEmfeUXy3o="
|
109
116
|
```
|
110
117
|
|
111
118
|
#### Public Key Directives
|
@@ -172,7 +179,7 @@ SSHKey.valid_ssh_public_key? "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE
|
|
172
179
|
|
173
180
|
#### Bit length
|
174
181
|
|
175
|
-
Determine the
|
182
|
+
Determine the strength of the key in bits as an integer. Returns `SSHKey::PublicKeyError` if bits cannot be determined.
|
176
183
|
|
177
184
|
```ruby
|
178
185
|
SSHKey.ssh_public_key_bits "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o/7TYi63yAopsrJ6TP+lDGdyQ+nVVp+5ojAIy9h8/h99UlNxjkiFT2YhI3Fl/pgNDRO4PVo6tlgb3CwiAZjSdeE5RnF79Dkj5XsM4j+FLMoXtbRw0K9ok9RKjz6ygIs1JDmaOdXexFnq4nAYU3fSLUa6WoccqTHe8bFuJoAv1gbnx09Js8YcVMD96mpTJ3V/MK5YfIv10dbtrDhGug3IS1V2J+0BB9orbQja554N+4S0I9rFBgVCpvPmQqddDHd/AdGkLv/zjEfGytjnvp68bEfDinkQkPfuxw01yd5MbcvLv39VVICWtKbqW263HT5LvSxwKorR7"
|
@@ -181,14 +188,16 @@ SSHKey.ssh_public_key_bits "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o
|
|
181
188
|
|
182
189
|
#### Fingerprints
|
183
190
|
|
184
|
-
Fetch
|
185
|
-
|
191
|
+
Fetch an MD5, SHA1, or SHA256 fingerprint of the SSH public key.
|
192
|
+
Returns `SSHKey::PublicKeyError` if a fingerprint cannot be determined.
|
186
193
|
|
187
194
|
```ruby
|
188
195
|
SSHKey.fingerprint "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o/7TYi63yAopsrJ6TP+lDGdyQ+nVVp+5ojAIy9h8/h99UlNxjkiFT2YhI3Fl/pgNDRO4PVo6tlgb3CwiAZjSdeE5RnF79Dkj5XsM4j+FLMoXtbRw0K9ok9RKjz6ygIs1JDmaOdXexFnq4nAYU3fSLUa6WoccqTHe8bFuJoAv1gbnx09Js8YcVMD96mpTJ3V/MK5YfIv10dbtrDhGug3IS1V2J+0BB9orbQja554N+4S0I9rFBgVCpvPmQqddDHd/AdGkLv/zjEfGytjnvp68bEfDinkQkPfuxw01yd5MbcvLv39VVICWtKbqW263HT5LvSxwKorR7"
|
189
196
|
# => "04:1b:d4:18:df:87:60:94:8c:83:8a:7b:5a:35:59:3d"
|
190
197
|
SSHKey.sha1_fingerprint "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o/7TYi63yAopsrJ6TP+lDGdyQ+nVVp+5ojAIy9h8/h99UlNxjkiFT2YhI3Fl/pgNDRO4PVo6tlgb3CwiAZjSdeE5RnF79Dkj5XsM4j+FLMoXtbRw0K9ok9RKjz6ygIs1JDmaOdXexFnq4nAYU3fSLUa6WoccqTHe8bFuJoAv1gbnx09Js8YcVMD96mpTJ3V/MK5YfIv10dbtrDhGug3IS1V2J+0BB9orbQja554N+4S0I9rFBgVCpvPmQqddDHd/AdGkLv/zjEfGytjnvp68bEfDinkQkPfuxw01yd5MbcvLv39VVICWtKbqW263HT5LvSxwKorR7"
|
191
198
|
# => "e5:c2:43:9e:e4:0c:0c:47:82:7a:3b:e9:61:13:bd:9c:43:eb:4c:b7"
|
199
|
+
SSHKey.sha256_fingerprint "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9HuXvYJPtQE/o/7TYi63yAopsrJ6TP+lDGdyQ+nVVp+5ojAIy9h8/h99UlNxjkiFT2YhI3Fl/pgNDRO4PVo6tlgb3CwiAZjSdeE5RnF79Dkj5XsM4j+FLMoXtbRw0K9ok9RKjz6ygIs1JDmaOdXexFnq4nAYU3fSLUa6WoccqTHe8bFuJoAv1gbnx09Js8YcVMD96mpTJ3V/MK5YfIv10dbtrDhGug3IS1V2J+0BB9orbQja554N+4S0I9rFBgVCpvPmQqddDHd/AdGkLv/zjEfGytjnvp68bEfDinkQkPfuxw01yd5MbcvLv39VVICWtKbqW263HT5LvSxwKorR7"
|
200
|
+
# => "x1GEnx1SRY/QwxjMAoyO6mhQlaBedDHtYLEmfeUXy3o="
|
192
201
|
```
|
193
202
|
|
194
203
|
#### Convert to SSH2 Public Key
|
data/lib/sshkey.rb
CHANGED
@@ -89,6 +89,15 @@ class SSHKey
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
# SHA256 fingerprint for the given SSH key
|
93
|
+
def sha256_fingerprint(key)
|
94
|
+
if key.match(/PRIVATE/)
|
95
|
+
new(key).sha256_fingerprint
|
96
|
+
else
|
97
|
+
Base64.encode64(Digest::SHA256.digest(decoded_key(key))).gsub("\n", "")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
92
101
|
# Convert an existing SSH public key to SSH2 (RFC4716) public key
|
93
102
|
#
|
94
103
|
# ==== Parameters
|
@@ -251,6 +260,11 @@ class SSHKey
|
|
251
260
|
Digest::SHA1.hexdigest(ssh_public_key_conversion).gsub(/(.{2})(?=.)/, '\1:\2')
|
252
261
|
end
|
253
262
|
|
263
|
+
# SHA256 fingerprint for the given SSH public key
|
264
|
+
def sha256_fingerprint
|
265
|
+
Base64.encode64(Digest::SHA256.digest(ssh_public_key_conversion)).gsub("\n", "")
|
266
|
+
end
|
267
|
+
|
254
268
|
# Determine the length (bits) of the key as an integer
|
255
269
|
def bits
|
256
270
|
self.class.ssh_public_key_bits(ssh_public_key)
|
data/lib/sshkey/version.rb
CHANGED
data/test/sshkey_test.rb
CHANGED
@@ -87,6 +87,10 @@ EOF
|
|
87
87
|
KEY2_SHA1_FINGERPRINT = "9a:52:78:2b:6b:cb:39:b7:85:ed:90:8a:28:62:aa:b3:98:88:e6:07"
|
88
88
|
KEY3_SHA1_FINGERPRINT = "15:68:c6:72:ac:18:d1:fc:ab:a2:b7:b5:8c:d1:fe:8f:b9:ae:a9:47"
|
89
89
|
|
90
|
+
KEY1_SHA256_FINGERPRINT = "js3llFehloxCfsVuDw5xu3NtS9AOAxcXY8WL6vkDIts="
|
91
|
+
KEY2_SHA256_FINGERPRINT = "23f/6U/LdxIFx1CQFKHylw76n+LIHYoY4nRxKcFoos4="
|
92
|
+
KEY3_SHA256_FINGERPRINT = "mPqEPQlOPGORrTJrU17sPax1jOqeutZja6MOsFIca+8="
|
93
|
+
|
90
94
|
KEY1_RANDOMART = <<-EOF.rstrip
|
91
95
|
+--[ RSA 2048]----+
|
92
96
|
|o+ o.. |
|
@@ -252,7 +256,7 @@ EOF
|
|
252
256
|
|
253
257
|
assert_equal expected1, @key1.ssh2_public_key
|
254
258
|
assert_equal expected2, @key2.ssh2_public_key({})
|
255
|
-
assert_equal expected3, @key3.ssh2_public_key({'Comment' => '1024-bit DSA with provided comment',
|
259
|
+
assert_equal expected3, @key3.ssh2_public_key({'Comment' => '1024-bit DSA with provided comment',
|
256
260
|
'x-private-use-header' => 'some value that is long enough to go to wrap around to a new line.'})
|
257
261
|
end
|
258
262
|
|
@@ -343,7 +347,7 @@ EOF
|
|
343
347
|
assert_equal( "byte array too short", exception2.message )
|
344
348
|
assert_equal( "cannot determine key type", exception3.message )
|
345
349
|
end
|
346
|
-
|
350
|
+
|
347
351
|
def test_ssh2_public_key_bits
|
348
352
|
public_key1 = "ssh-rsa #{SSH_PUBLIC_KEY1} me@example.com"
|
349
353
|
public_key2 = "ssh-rsa #{SSH_PUBLIC_KEY2}"
|
@@ -375,6 +379,10 @@ end
|
|
375
379
|
assert_equal KEY2_SHA1_FINGERPRINT, @key2.sha1_fingerprint
|
376
380
|
assert_equal KEY3_SHA1_FINGERPRINT, @key3.sha1_fingerprint
|
377
381
|
|
382
|
+
assert_equal KEY1_SHA256_FINGERPRINT, @key1.sha256_fingerprint
|
383
|
+
assert_equal KEY2_SHA256_FINGERPRINT, @key2.sha256_fingerprint
|
384
|
+
assert_equal KEY3_SHA256_FINGERPRINT, @key3.sha256_fingerprint
|
385
|
+
|
378
386
|
assert_equal KEY1_MD5_FINGERPRINT, SSHKey.md5_fingerprint(SSH_PRIVATE_KEY1)
|
379
387
|
assert_equal KEY1_MD5_FINGERPRINT, SSHKey.md5_fingerprint("ssh-rsa #{SSH_PUBLIC_KEY1}")
|
380
388
|
assert_equal KEY2_MD5_FINGERPRINT, SSHKey.md5_fingerprint(SSH_PRIVATE_KEY2)
|
@@ -388,6 +396,13 @@ end
|
|
388
396
|
assert_equal KEY2_SHA1_FINGERPRINT, SSHKey.sha1_fingerprint("ssh-rsa #{SSH_PUBLIC_KEY2} me@me.com")
|
389
397
|
assert_equal KEY3_SHA1_FINGERPRINT, SSHKey.sha1_fingerprint(SSH_PRIVATE_KEY3)
|
390
398
|
assert_equal KEY3_SHA1_FINGERPRINT, SSHKey.sha1_fingerprint("ssh-dss #{SSH_PUBLIC_KEY3}")
|
399
|
+
|
400
|
+
assert_equal KEY1_SHA256_FINGERPRINT, SSHKey.sha256_fingerprint(SSH_PRIVATE_KEY1)
|
401
|
+
assert_equal KEY1_SHA256_FINGERPRINT, SSHKey.sha256_fingerprint("ssh-rsa #{SSH_PUBLIC_KEY1}")
|
402
|
+
assert_equal KEY2_SHA256_FINGERPRINT, SSHKey.sha256_fingerprint(SSH_PRIVATE_KEY2)
|
403
|
+
assert_equal KEY2_SHA256_FINGERPRINT, SSHKey.sha256_fingerprint("ssh-rsa #{SSH_PUBLIC_KEY2} me@me.com")
|
404
|
+
assert_equal KEY3_SHA256_FINGERPRINT, SSHKey.sha256_fingerprint(SSH_PRIVATE_KEY3)
|
405
|
+
assert_equal KEY3_SHA256_FINGERPRINT, SSHKey.sha256_fingerprint("ssh-dss #{SSH_PUBLIC_KEY3}")
|
391
406
|
end
|
392
407
|
|
393
408
|
def test_bits
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project: sshkey
|
79
|
-
rubygems_version: 2.4.5
|
79
|
+
rubygems_version: 2.4.5.1
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: SSH private/public key generator in Ruby
|