sshkey 1.1.0 → 1.1.1
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.
- data/README.rdoc +7 -3
- data/lib/sshkey/version.rb +1 -1
- data/lib/sshkey.rb +3 -1
- data/test/sshkey_test.rb +7 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -21,15 +21,15 @@ Both of these will return an SSHKey object with the following methods:
|
|
21
21
|
# Returns an OpenSSL::PKey::RSA key object
|
22
22
|
# See http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/classes/OpenSSL/PKey/RSA.html
|
23
23
|
k.key_object
|
24
|
-
# => -----BEGIN RSA PRIVATE KEY-----\nMIIEowI
|
24
|
+
# => -----BEGIN RSA PRIVATE KEY-----\nMIIEowI...
|
25
25
|
|
26
26
|
# Returns the RSA Private Key as a string
|
27
27
|
k.rsa_private_key
|
28
|
-
# => "-----BEGIN RSA PRIVATE KEY-----\nMIIEowI"
|
28
|
+
# => "-----BEGIN RSA PRIVATE KEY-----\nMIIEowI..."
|
29
29
|
|
30
30
|
# Returns the RSA Public Key as a string
|
31
31
|
k.rsa_public_key
|
32
|
-
# => "-----BEGIN RSA PUBLIC KEY-----\nMIIBCg"
|
32
|
+
# => "-----BEGIN RSA PUBLIC KEY-----\nMIIBCg..."
|
33
33
|
|
34
34
|
# Returns the SSH Public Key as a string
|
35
35
|
k.ssh_public_key
|
@@ -39,6 +39,10 @@ Both of these will return an SSHKey object with the following methods:
|
|
39
39
|
k.comment
|
40
40
|
# => "foo@bar.com"
|
41
41
|
|
42
|
+
# Returns the fingerprint as a string
|
43
|
+
k.fingerprint
|
44
|
+
# => "2a:89:84:c9:29:05:d1:f8:49:79:1c:ba:73:99:eb:af"
|
45
|
+
|
42
46
|
== Copyright
|
43
47
|
|
44
48
|
Copyright (c) 2011 James Miller
|
data/lib/sshkey/version.rb
CHANGED
data/lib/sshkey.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'base64'
|
3
|
+
require 'digest/md5'
|
3
4
|
|
4
5
|
class SSHKey
|
5
6
|
|
@@ -7,7 +8,7 @@ class SSHKey
|
|
7
8
|
SSHKey.new(OpenSSL::PKey::RSA.generate(2048).to_pem, options)
|
8
9
|
end
|
9
10
|
|
10
|
-
attr_reader :key_object, :comment, :rsa_private_key, :rsa_public_key, :ssh_public_key
|
11
|
+
attr_reader :key_object, :comment, :rsa_private_key, :rsa_public_key, :ssh_public_key, :fingerprint
|
11
12
|
|
12
13
|
def initialize(private_key, options = {})
|
13
14
|
@key_object = OpenSSL::PKey::RSA.new(private_key)
|
@@ -15,6 +16,7 @@ class SSHKey
|
|
15
16
|
@rsa_private_key = @key_object.to_pem
|
16
17
|
@rsa_public_key = @key_object.public_key.to_pem
|
17
18
|
@ssh_public_key = ["ssh-rsa", Base64.strict_encode64(ssh_public_key_conversion), @comment].join(" ").strip
|
19
|
+
@fingerprint = Digest::MD5.hexdigest(ssh_public_key_conversion).gsub(/(.{2})(?=.)/, '\1:\2')
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
data/test/sshkey_test.rb
CHANGED
@@ -64,7 +64,8 @@ EOF
|
|
64
64
|
SSH_PUBLIC_KEY1 = 'AAAAB3NzaC1yc2EAAAABIwAAAQEArfTA/lKVR84IMc9ZzXOCHr8DVtR8hzWuEVHF6KElavRHlk14g0SZu3m908Ejm/XF3EfNHjX9wN+62IMA0QBxkBMFCuLF+U/oeUs0NoDdAEKxjj4n6lq6Ss8aLct+anMy7D1jwvOLbcwV54w1d5JDdlZVdZ6AvHm9otwJq6rNpDgdmXY4HgC2nM9csFpuy0cDpL6fdJx9lcNL2RnkRC4+RMsIB+PxDw0j3vDi04dYLBXMGYjyeGH+mIFpL3PTPXGXwL2XDYXZ2H4SQX6bOoKmazTXq6QXuEB665njh1GxXldoIMcSshoJL0hrk3WrTOG22N2CQA+IfHgrXJ+A+QUzKQ=='
|
65
65
|
SSH_PUBLIC_KEY2 = 'AAAAB3NzaC1yc2EAAAABIwAAAQEAxl6TpN7uFiY/JZ8qDnD7UrxDP+ABeh2PVg8Du1LEgXNk0+YWCeP5S6oHklqaWeDlbmAs1oHsBwCMAVpMa5tgONOLvz4JgwgkiqQEbKR8ofWJ+LADUElvqRVGmGiNEMLI6GJWeneL4sjmbb8d6U+M53c6iWG0si9XE5m7teBQSsCl0Tk3qMIkQGw5zpJeCXjZ8KpJhIJRYgexFkGgPlYRV+UYIhxpUW90t0Ra5i6JOFYwq98k5S/6SJIZQ/A9F4JNzwLw3eVxZj0yVHWxkGz1+TyELNY1kOyMxnZaqSfGzSQJTrnIXpdweVHuYh1LtOgedRQhCyiELeSMGwio1vRPKw=='
|
66
66
|
|
67
|
-
|
67
|
+
KEY1_FINGERPRINT = "2a:89:84:c9:29:05:d1:f8:49:79:1c:ba:73:99:eb:af"
|
68
|
+
KEY2_FINGERPRINT = "3c:af:74:87:cc:cc:a1:12:05:1a:09:b7:7b:ce:ed:ce"
|
68
69
|
|
69
70
|
def setup
|
70
71
|
@key1 = SSHKey.new(SSH_PRIVATE_KEY1, :comment => "me@example.com")
|
@@ -115,6 +116,11 @@ EOF
|
|
115
116
|
assert_equal 25041821909255634338594631709409930006900629565221199423527442992482865961613864019776541767273966885435978473182530882048894721263421597979360058644777295324028381353356143013803778109979347540540538361684778724178534886189535456555760676722894784592989232554962714835255398111716791175503010379276254975882143986862239829255392231575481418297073759441882528318940783011390002193682320028951031205422825662402426266933458263786546846123394508656926946338411182471843223455365249418245551220933173115037201835242811305615780499842939975996344432437312062643436832423359634116147870328774728910949553186982115987967787, @key2.key_object.n.to_i
|
116
117
|
end
|
117
118
|
|
119
|
+
def test_fingerprint
|
120
|
+
assert_equal KEY1_FINGERPRINT, @key1.fingerprint
|
121
|
+
assert_equal KEY2_FINGERPRINT, @key2.fingerprint
|
122
|
+
end
|
123
|
+
|
118
124
|
def test_to_byte_array
|
119
125
|
ba1 = @key1.send(:to_byte_array, 35)
|
120
126
|
ba2 = @key1.send(:to_byte_array, 65537)
|