sshkey 1.0.0 → 1.1.0
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/LICENSE +20 -0
- data/README.rdoc +44 -0
- data/lib/sshkey.rb +8 -8
- data/lib/sshkey/version.rb +1 -1
- data/test/sshkey_test.rb +13 -8
- metadata +5 -3
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 James Miller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= sshkey
|
2
|
+
|
3
|
+
Generate private/public SSH keys using Ruby without the `ssh-keygen` system command.
|
4
|
+
|
5
|
+
gem install sshkey
|
6
|
+
|
7
|
+
Currently requires Ruby 1.9.
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
Generate an SSH Keypair with foo@bar.com as the comment - providing a comment is optional
|
12
|
+
|
13
|
+
k = SSHKey.generate(:comment => "foo@bar.com")
|
14
|
+
|
15
|
+
Return an SSHKey object from an existing RSA Private Key (provided as a string)
|
16
|
+
|
17
|
+
k = SSHKey.new(File.read("~/.ssh/id_rsa"), :comment => "foo@bar.com")
|
18
|
+
|
19
|
+
Both of these will return an SSHKey object with the following methods:
|
20
|
+
|
21
|
+
# Returns an OpenSSL::PKey::RSA key object
|
22
|
+
# See http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/classes/OpenSSL/PKey/RSA.html
|
23
|
+
k.key_object
|
24
|
+
# => -----BEGIN RSA PRIVATE KEY-----\nMIIEowI
|
25
|
+
|
26
|
+
# Returns the RSA Private Key as a string
|
27
|
+
k.rsa_private_key
|
28
|
+
# => "-----BEGIN RSA PRIVATE KEY-----\nMIIEowI"
|
29
|
+
|
30
|
+
# Returns the RSA Public Key as a string
|
31
|
+
k.rsa_public_key
|
32
|
+
# => "-----BEGIN RSA PUBLIC KEY-----\nMIIBCg"
|
33
|
+
|
34
|
+
# Returns the SSH Public Key as a string
|
35
|
+
k.ssh_public_key
|
36
|
+
# => "ssh-rsa AAAAB3NzaC1yc2EA...."
|
37
|
+
|
38
|
+
# Returns the comment as a string
|
39
|
+
k.comment
|
40
|
+
# => "foo@bar.com"
|
41
|
+
|
42
|
+
== Copyright
|
43
|
+
|
44
|
+
Copyright (c) 2011 James Miller
|
data/lib/sshkey.rb
CHANGED
@@ -3,18 +3,18 @@ require 'base64'
|
|
3
3
|
|
4
4
|
class SSHKey
|
5
5
|
|
6
|
-
def self.generate(
|
7
|
-
SSHKey.new(OpenSSL::PKey::RSA.generate(2048),
|
6
|
+
def self.generate(options = {})
|
7
|
+
SSHKey.new(OpenSSL::PKey::RSA.generate(2048).to_pem, options)
|
8
8
|
end
|
9
9
|
|
10
10
|
attr_reader :key_object, :comment, :rsa_private_key, :rsa_public_key, :ssh_public_key
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
@key_object =
|
14
|
-
@comment = comment
|
15
|
-
@rsa_private_key = key_object.to_pem
|
16
|
-
@rsa_public_key = key_object.public_key.to_pem
|
17
|
-
@ssh_public_key = ["ssh-rsa", Base64.strict_encode64(ssh_public_key_conversion), @comment].join(" ")
|
12
|
+
def initialize(private_key, options = {})
|
13
|
+
@key_object = OpenSSL::PKey::RSA.new(private_key)
|
14
|
+
@comment = options[:comment] || ""
|
15
|
+
@rsa_private_key = @key_object.to_pem
|
16
|
+
@rsa_public_key = @key_object.public_key.to_pem
|
17
|
+
@ssh_public_key = ["ssh-rsa", Base64.strict_encode64(ssh_public_key_conversion), @comment].join(" ").strip
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
data/lib/sshkey/version.rb
CHANGED
data/test/sshkey_test.rb
CHANGED
@@ -67,14 +67,15 @@ EOF
|
|
67
67
|
FINGERPRINT = "2a:89:84:c9:29:05:d1:f8:49:79:1c:ba:73:99:eb:af"
|
68
68
|
|
69
69
|
def setup
|
70
|
-
@key1 = SSHKey.new(
|
71
|
-
@key2 = SSHKey.new(
|
70
|
+
@key1 = SSHKey.new(SSH_PRIVATE_KEY1, :comment => "me@example.com")
|
71
|
+
@key2 = SSHKey.new(SSH_PRIVATE_KEY2, :comment => "me@example.com")
|
72
|
+
@key_without_comment = SSHKey.new(SSH_PRIVATE_KEY1)
|
72
73
|
end
|
73
74
|
|
74
75
|
def test_private_key1
|
75
76
|
assert_equal SSH_PRIVATE_KEY1, @key1.rsa_private_key
|
76
77
|
end
|
77
|
-
|
78
|
+
|
78
79
|
def test_private_key2
|
79
80
|
assert_equal SSH_PRIVATE_KEY2, @key2.rsa_private_key
|
80
81
|
end
|
@@ -82,7 +83,7 @@ EOF
|
|
82
83
|
def test_ssh_public_key_decoded1
|
83
84
|
assert_equal Base64.strict_decode64(SSH_PUBLIC_KEY1), @key1.send(:ssh_public_key_conversion)
|
84
85
|
end
|
85
|
-
|
86
|
+
|
86
87
|
def test_ssh_public_key_decoded2
|
87
88
|
assert_equal Base64.strict_decode64(SSH_PUBLIC_KEY2), @key2.send(:ssh_public_key_conversion)
|
88
89
|
end
|
@@ -90,16 +91,18 @@ EOF
|
|
90
91
|
def test_ssh_public_key_encoded1
|
91
92
|
assert_equal SSH_PUBLIC_KEY1, Base64.strict_encode64(@key1.send(:ssh_public_key_conversion))
|
92
93
|
end
|
93
|
-
|
94
|
+
|
94
95
|
def test_ssh_public_key_encoded2
|
95
96
|
assert_equal SSH_PUBLIC_KEY2, Base64.strict_encode64(@key2.send(:ssh_public_key_conversion))
|
96
97
|
end
|
97
|
-
|
98
|
+
|
98
99
|
def test_ssh_public_key_output
|
99
|
-
expected1 = "ssh-rsa
|
100
|
-
expected2 = "ssh-rsa
|
100
|
+
expected1 = "ssh-rsa #{SSH_PUBLIC_KEY1} me@example.com"
|
101
|
+
expected2 = "ssh-rsa #{SSH_PUBLIC_KEY2} me@example.com"
|
102
|
+
expected3 = "ssh-rsa #{SSH_PUBLIC_KEY1}"
|
101
103
|
assert_equal expected1, @key1.ssh_public_key
|
102
104
|
assert_equal expected2, @key2.ssh_public_key
|
105
|
+
assert_equal expected3, @key_without_comment.ssh_public_key
|
103
106
|
end
|
104
107
|
|
105
108
|
def test_exponent
|
@@ -115,7 +118,9 @@ EOF
|
|
115
118
|
def test_to_byte_array
|
116
119
|
ba1 = @key1.send(:to_byte_array, 35)
|
117
120
|
ba2 = @key1.send(:to_byte_array, 65537)
|
121
|
+
ba3 = [0, 1, 255, 256, -1, -128, -256].map{|i| @key1.send(:to_byte_array, i)}
|
118
122
|
assert_equal [35], ba1
|
119
123
|
assert_equal [1, 0, 1], ba2
|
124
|
+
assert_equal [[0], [1], [0, 255], [1, 0], [255], [128], [255, 0]], ba3
|
120
125
|
end
|
121
126
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sshkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Miller
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-12
|
13
|
+
date: 2011-03-12 23:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -26,6 +26,8 @@ extra_rdoc_files: []
|
|
26
26
|
files:
|
27
27
|
- .gitignore
|
28
28
|
- Gemfile
|
29
|
+
- LICENSE
|
30
|
+
- README.rdoc
|
29
31
|
- Rakefile
|
30
32
|
- lib/sshkey.rb
|
31
33
|
- lib/sshkey/version.rb
|
@@ -55,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
57
|
requirements: []
|
56
58
|
|
57
59
|
rubyforge_project: sshkey
|
58
|
-
rubygems_version: 1.
|
60
|
+
rubygems_version: 1.6.2
|
59
61
|
signing_key:
|
60
62
|
specification_version: 3
|
61
63
|
summary: SSH private/public key generator in Ruby
|