sshkg 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +41 -0
- data/bin/sshkg +6 -6
- data/lib/loader.rb +12 -0
- data/lib/sshkg/generator.rb +17 -3
- data/lib/{util/opt_parser.rb → sshkg/options_parser.rb} +6 -4
- data/lib/sshkg/version.rb +9 -9
- data/test/unit/tc_generator.rb +78 -0
- metadata +59 -27
- data/README.textile +0 -0
- data/lib/sshkg/config.rb +0 -24
- data/lib/sshkg.rb +0 -5
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= SSH Key Generator
|
2
|
+
|
3
|
+
A little wrapper over secure shell private/public key generator utility
|
4
|
+
|
5
|
+
|
6
|
+
== Installing
|
7
|
+
|
8
|
+
The latest stable version is published in gemcutter/rubygems.
|
9
|
+
|
10
|
+
gem install sshkg
|
11
|
+
|
12
|
+
|
13
|
+
== How to use
|
14
|
+
|
15
|
+
Help is your friend RTFM
|
16
|
+
|
17
|
+
sshkg --help
|
18
|
+
|
19
|
+
|
20
|
+
== License
|
21
|
+
|
22
|
+
Copyright (c) 2010-2030 Javier Juarez Martinez
|
23
|
+
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
25
|
+
a copy of this software and associated documentation files (the
|
26
|
+
"Software"), to deal in the Software without restriction, including
|
27
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
28
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
29
|
+
permit persons to whom the Software is furnished to do so, subject to
|
30
|
+
the following conditions:
|
31
|
+
|
32
|
+
The above copyright notice and this permission notice shall be
|
33
|
+
included in all copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
36
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
37
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
38
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
39
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
40
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
41
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/sshkg
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
$:.unshift( File.join( File.dirname( __FILE__ ),
|
4
|
-
|
3
|
+
$:.unshift( File.join( File.dirname( __FILE__ ), %w[.. lib] ) )
|
4
|
+
|
5
|
+
require 'loader'
|
5
6
|
|
6
7
|
##
|
7
8
|
# ::Main::
|
8
|
-
|
9
|
+
ConfigContext.user = Choice.choices[:user]
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
11
|
+
ConfigContext.load( File.expand_path( Choice.choices[:config] ) )
|
12
|
+
SSHKeyGenerator.generate( ConfigContext.all )
|
data/lib/loader.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
$:.unshift( File.join( File.dirname( __FILE__ ), 'sshkg' ) )
|
4
|
+
|
5
|
+
begin
|
6
|
+
Dir.glob( File.join( File.dirname( __FILE__ ), "**", "*.rb" ) ).each do |library|
|
7
|
+
|
8
|
+
require library
|
9
|
+
end
|
10
|
+
rescue LoadError => le
|
11
|
+
MiniLogger.error( le.message )
|
12
|
+
end
|
data/lib/sshkg/generator.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'config_context'
|
3
|
+
|
4
|
+
|
1
5
|
module SSHKeyGenerator
|
2
6
|
extend self
|
3
7
|
|
4
|
-
|
8
|
+
DEFAULT_TYPE = :dsa
|
9
|
+
DEFAULT_BITS = 1024
|
10
|
+
DEFAULT_COMMENT = "example.com"
|
11
|
+
|
12
|
+
def generate( atts = { } )
|
5
13
|
|
6
|
-
|
14
|
+
raise ArgumentError.new( "There is an argument problem" ) if atts.empty?
|
15
|
+
raise ArgumentError.new( "You need an user id" ) unless atts[:user]
|
7
16
|
|
8
|
-
|
17
|
+
user = atts[:user]
|
18
|
+
type = atts[:type] ? atts[:type] : DEFAULT_TYPE
|
19
|
+
bits = atts[:bits] ? atts[:bits] : DEFAULT_BITS
|
20
|
+
comment = atts[:comment] ? atts[:comment] : DEFAULT_COMMENT
|
21
|
+
|
22
|
+
%x{ssh-keygen -q -b #{bits} -t #{type} -f id_#{type}.#{user} -C #{user}@#{comment} 2>/dev/null </dev/null}
|
9
23
|
end
|
10
24
|
end
|
@@ -1,18 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'choice'
|
2
3
|
|
4
|
+
|
3
5
|
Choice.options do
|
4
6
|
header ''
|
5
7
|
header ' Specific options:'
|
6
8
|
|
7
|
-
option :config do
|
9
|
+
option :config, :required=>true do
|
8
10
|
short '-c'
|
9
|
-
long '--config
|
11
|
+
long '--config'
|
10
12
|
desc 'The yaml config file'
|
11
13
|
end
|
12
14
|
|
13
|
-
option :user do
|
15
|
+
option :user, :required=>true do
|
14
16
|
short '-u'
|
15
|
-
long '--user
|
17
|
+
long '--user'
|
16
18
|
desc 'The user identificator'
|
17
19
|
end
|
18
20
|
|
data/lib/sshkg/version.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
module SSHKeyGenerator
|
1
|
+
module SSHKeyGenerator
|
2
2
|
module Version
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
INFO = {
|
4
|
+
:major =>0,
|
5
|
+
:minor =>2,
|
6
|
+
:patch =>0
|
7
|
+
}
|
6
8
|
|
7
|
-
|
9
|
+
NAME = 'sshkg'
|
10
|
+
VERSION = INFO.values.join( '.' )
|
8
11
|
end
|
9
|
-
|
10
|
-
NAME = "sshkg"
|
11
|
-
VERSION = Version::STRING
|
12
|
-
end
|
12
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
$:.unshift( File.join( File.dirname( __FILE__ ), %w[.. .. lib sshkg] ) )
|
2
|
+
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'shoulda'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'generator'
|
9
|
+
|
10
|
+
|
11
|
+
class TestSSHKeyGenerator < Test::Unit::TestCase
|
12
|
+
|
13
|
+
context "A SSH key generator context" do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
|
17
|
+
@test_dsa_user = "dsauser"
|
18
|
+
@test_dsa_comment = "dsacomment"
|
19
|
+
@test_dsa_key_file_name = "id_dsa.#{@test_dsa_user}"
|
20
|
+
@test_dsa_public_key_file_name = "id_dsa.#{@test_dsa_user}.pub"
|
21
|
+
|
22
|
+
@test_rsa_user = "rsauser"
|
23
|
+
@test_rsa_comment = "rsacomment"
|
24
|
+
@test_rsa_key_file_name = "id_rsa.#{@test_rsa_user}"
|
25
|
+
@test_rsa_public_key_file_name = "id_rsa.#{@test_rsa_user}.pub"
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
teardown do
|
30
|
+
|
31
|
+
FileUtils.rm_f( @test_dsa_key_file_name )
|
32
|
+
FileUtils.rm_f( @test_dsa_public_key_file_name )
|
33
|
+
|
34
|
+
FileUtils.rm_f( @test_rsa_key_file_name )
|
35
|
+
FileUtils.rm_f( @test_rsa_public_key_file_name )
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
should "raise an ArgumentError" do
|
40
|
+
|
41
|
+
assert_raises( ArgumentError ) { SSHKeyGenerator.generate( ) }
|
42
|
+
assert_raises( ArgumentError ) { SSHKeyGenerator.generate( :type=>:dsa, :comment=>@test_dsa_comment ) }
|
43
|
+
assert_raises( ArgumentError ) { SSHKeyGenerator.generate( :type=>:rsa, :comment=>@test_rsa_comment ) }
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
should "generate a default key" do
|
48
|
+
|
49
|
+
SSHKeyGenerator.generate( :user=>@test_dsa_user )
|
50
|
+
|
51
|
+
assert( File.exist?( @test_dsa_key_file_name ) )
|
52
|
+
|
53
|
+
assert( File.exist?( @test_dsa_public_key_file_name ) )
|
54
|
+
assert( File.read( @test_dsa_public_key_file_name ) =~ /^ssh-dss (.+) #{@test_dsa_user}\@example.com$/ )
|
55
|
+
|
56
|
+
FileUtils.rm_f( @test_dsa_key_file_name )
|
57
|
+
FileUtils.rm_f( @test_dsa_public_key_file_name )
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
should "generate a pair of DSA keys" do
|
62
|
+
|
63
|
+
SSHKeyGenerator.generate( :user=>@test_dsa_user, :type=>:dsa, :bits=>1024, :comment=>@test_dsa_comment )
|
64
|
+
|
65
|
+
assert( File.exist?( @test_dsa_public_key_file_name ) )
|
66
|
+
assert( File.read( @test_dsa_public_key_file_name ) =~ /^ssh-dss (.+) #{@test_dsa_user}\@#{@test_dsa_comment}$/ )
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
should "generate a pair of RSA keys" do
|
71
|
+
|
72
|
+
SSHKeyGenerator.generate( :user=>@test_rsa_user, :type=>:rsa, :bits=>2048, :comment=>@test_rsa_comment )
|
73
|
+
|
74
|
+
assert( File.exist?( @test_rsa_public_key_file_name ) )
|
75
|
+
assert( File.read( @test_rsa_public_key_file_name ) =~ /ssh-rsa (.+) #{@test_rsa_user}\@#{@test_rsa_comment}$/ )
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Javier Juarez
|
@@ -15,10 +10,53 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2011-03-31 00:00:00 +02:00
|
19
14
|
default_executable: sshkg
|
20
|
-
dependencies:
|
21
|
-
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: choice
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: config_context
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: choice
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: config_context
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
22
60
|
description: A wrapper over ssh-keygem for rubyists
|
23
61
|
email: javier.juarez@gmail.com
|
24
62
|
executables:
|
@@ -26,22 +64,22 @@ executables:
|
|
26
64
|
extensions: []
|
27
65
|
|
28
66
|
extra_rdoc_files:
|
29
|
-
- README.
|
67
|
+
- README.rdoc
|
30
68
|
files:
|
31
69
|
- bin/sshkg
|
32
|
-
- lib/
|
33
|
-
- lib/sshkg/config.rb
|
70
|
+
- lib/loader.rb
|
34
71
|
- lib/sshkg/generator.rb
|
72
|
+
- lib/sshkg/options_parser.rb
|
35
73
|
- lib/sshkg/version.rb
|
36
|
-
-
|
37
|
-
- README.
|
74
|
+
- test/unit/tc_generator.rb
|
75
|
+
- README.rdoc
|
38
76
|
has_rdoc: true
|
39
77
|
homepage: http://github.com/jjuarez/sshkg
|
40
78
|
licenses: []
|
41
79
|
|
42
80
|
post_install_message:
|
43
|
-
rdoc_options:
|
44
|
-
|
81
|
+
rdoc_options: []
|
82
|
+
|
45
83
|
require_paths:
|
46
84
|
- lib
|
47
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -49,25 +87,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
87
|
requirements:
|
50
88
|
- - ">="
|
51
89
|
- !ruby/object:Gem::Version
|
52
|
-
hash: 3
|
53
|
-
segments:
|
54
|
-
- 0
|
55
90
|
version: "0"
|
56
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
92
|
none: false
|
58
93
|
requirements:
|
59
94
|
- - ">="
|
60
95
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 3
|
62
|
-
segments:
|
63
|
-
- 0
|
64
96
|
version: "0"
|
65
97
|
requirements: []
|
66
98
|
|
67
|
-
rubyforge_project:
|
68
|
-
rubygems_version: 1.
|
99
|
+
rubyforge_project: http://github.com/jjuarez/sshkg
|
100
|
+
rubygems_version: 1.6.2
|
69
101
|
signing_key:
|
70
102
|
specification_version: 3
|
71
103
|
summary: A very simple gem that helps to automate the generation of SSH Keys
|
72
|
-
test_files:
|
73
|
-
|
104
|
+
test_files:
|
105
|
+
- test/unit/tc_generator.rb
|
data/README.textile
DELETED
File without changes
|
data/lib/sshkg/config.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module SSHKeyGenerator
|
4
|
-
|
5
|
-
class Config
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def load( user, file_name )
|
9
|
-
@config = YAML.load_file( file_name )
|
10
|
-
@config[:user] = user
|
11
|
-
end
|
12
|
-
|
13
|
-
def [] key
|
14
|
-
@config[key] ? @config[key] : @config[key.to_s] if @config
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_h()
|
18
|
-
{ :type =>Config[:type],
|
19
|
-
:file =>"id_#{Config[:type]}.#{Config[:user]}",
|
20
|
-
:comment =>"#{Config[:user]}@#{Config[:comment]}" } if @config
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|