rye 0.3.2 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +20 -0
- data/README.rdoc +68 -22
- data/bin/rye +131 -0
- data/bin/try +40 -17
- data/lib/rye.rb +150 -13
- data/lib/rye/box.rb +141 -125
- data/lib/rye/cmd.rb +23 -0
- data/lib/rye/key.rb +134 -0
- data/lib/rye/rap.rb +9 -0
- data/lib/rye/set.rb +9 -0
- data/rye.gemspec +14 -3
- data/try/copying.rb +19 -0
- data/try/keys.rb +139 -0
- data/tst/10-key1 +27 -0
- data/tst/10-key1.pub +1 -0
- data/tst/10-key2 +30 -0
- data/tst/10-key2.pub +1 -0
- data/tst/10_keys_test.rb +88 -0
- data/{test/10_rye_test.rb → tst/50_rye_test.rb} +11 -20
- metadata +34 -5
data/lib/rye/rap.rb
CHANGED
@@ -20,6 +20,11 @@ module Rye;
|
|
20
20
|
|
21
21
|
# An array containing any STDERR output
|
22
22
|
attr_reader :stderr
|
23
|
+
attr_accessor :exit_code
|
24
|
+
attr_accessor :exit_signal
|
25
|
+
|
26
|
+
# The command that was executed.
|
27
|
+
attr_accessor :cmd
|
23
28
|
|
24
29
|
# * +obj+ an instance of Rye::Box or Rye::Set
|
25
30
|
# * +args+ anything that can sent to Array#new
|
@@ -68,6 +73,10 @@ module Rye;
|
|
68
73
|
super
|
69
74
|
end
|
70
75
|
|
76
|
+
def >>(*other)
|
77
|
+
p other
|
78
|
+
end
|
79
|
+
|
71
80
|
#---
|
72
81
|
# If Box's shell methods return Rap objects, then
|
73
82
|
# we can do stuff like this
|
data/lib/rye/set.rb
CHANGED
@@ -6,6 +6,7 @@ module Rye
|
|
6
6
|
class Set
|
7
7
|
attr_reader :name
|
8
8
|
attr_reader :boxes
|
9
|
+
attr_reader :opts
|
9
10
|
|
10
11
|
# * +name+ The name of the set of machines
|
11
12
|
# * +opts+ a hash of optional arguments
|
@@ -76,6 +77,14 @@ module Rye
|
|
76
77
|
Rye.keys
|
77
78
|
end
|
78
79
|
|
80
|
+
def to_s
|
81
|
+
"%s: %s" % [self.name, ]
|
82
|
+
end
|
83
|
+
|
84
|
+
def inspect
|
85
|
+
%q{#<%s:%s boxes=%s opts=%s>} % [self.class.to_s, self.name, self.boxes.join(','), self.opts.inspect]
|
86
|
+
end
|
87
|
+
|
79
88
|
# See Rye::Box.[]
|
80
89
|
def [](key=nil)
|
81
90
|
run_command(:cd, key)
|
data/rye.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@spec = Gem::Specification.new do |s|
|
2
2
|
s.name = "rye"
|
3
3
|
s.rubyforge_project = "rye"
|
4
|
-
s.version = "0.
|
4
|
+
s.version = "0.4"
|
5
5
|
s.summary = "Rye: Run system commands via SSH locally and remotely in a Ruby way."
|
6
6
|
s.description = s.summary
|
7
7
|
s.author = "Delano Mandelbaum"
|
@@ -11,7 +11,9 @@
|
|
11
11
|
# = DEPENDENCIES =
|
12
12
|
# Add all gem dependencies
|
13
13
|
s.add_dependency 'net-ssh'
|
14
|
+
s.add_dependency 'net-scp'
|
14
15
|
s.add_dependency 'highline'
|
16
|
+
s.add_dependency 'drydock'
|
15
17
|
|
16
18
|
# = MANIFEST =
|
17
19
|
# The complete list of files to be included in the release. When GitHub packages your gem,
|
@@ -24,22 +26,31 @@
|
|
24
26
|
LICENSE.txt
|
25
27
|
README.rdoc
|
26
28
|
Rakefile
|
29
|
+
bin/rye
|
27
30
|
bin/try
|
28
31
|
lib/esc.rb
|
29
32
|
lib/rye.rb
|
30
33
|
lib/rye/box.rb
|
31
34
|
lib/rye/cmd.rb
|
35
|
+
lib/rye/key.rb
|
32
36
|
lib/rye/rap.rb
|
33
37
|
lib/rye/set.rb
|
34
38
|
lib/sys.rb
|
35
39
|
rye.gemspec
|
36
|
-
|
40
|
+
try/copying.rb
|
41
|
+
try/keys.rb
|
42
|
+
tst/10-key1
|
43
|
+
tst/10-key1.pub
|
44
|
+
tst/10-key2
|
45
|
+
tst/10-key2.pub
|
46
|
+
tst/10_keys_test.rb
|
47
|
+
tst/50_rye_test.rb
|
37
48
|
)
|
38
49
|
|
39
50
|
# = EXECUTABLES =
|
40
51
|
# The list of executables in your project (if any). Don't include the path,
|
41
52
|
# just the base filename.
|
42
|
-
|
53
|
+
s.executables = %w[rye]
|
43
54
|
|
44
55
|
|
45
56
|
s.extra_rdoc_files = %w[README.rdoc LICENSE.txt]
|
data/try/copying.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# THIS IS A SCRAP FILE.
|
4
|
+
|
5
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
+
|
7
|
+
require 'rye'
|
8
|
+
|
9
|
+
boxA = Rye::Box.new('ryehost', :user => "root")
|
10
|
+
boxB = Rye::Box.new('127.0.0.1', :user => 'delano', :safe => false, :debug => STDOUT)
|
11
|
+
set = Rye::Set.new
|
12
|
+
set.add_boxes(boxA, boxB)
|
13
|
+
|
14
|
+
#p boxA['/tmp/ssh-test'].cat.stderr
|
15
|
+
|
16
|
+
#boxB['/tmp/ssh-test'].copy_to boxA['/tmp'], boxA['/tmp']
|
17
|
+
|
18
|
+
|
19
|
+
p boxA.ls(:a)
|
data/try/keys.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# THIS IS A SCRAP FILE.
|
4
|
+
|
5
|
+
__END__
|
6
|
+
require 'openssl'
|
7
|
+
key = OpenSSL::PKey::RSA.generate(1024)
|
8
|
+
pub = key.public_key
|
9
|
+
ca = OpenSSL::X509::Name.parse("/C=US/ST=Florida/L=Miami/O=Waitingf/OU=Poopstat/CN=waitingf.org/emailAddress=bkerley@brycekerley.net")
|
10
|
+
cert = OpenSSL::X509::Certificate.new
|
11
|
+
cert.version = 2
|
12
|
+
cert.serial = 1
|
13
|
+
cert.subject = ca
|
14
|
+
cert.issuer = ca
|
15
|
+
cert.public_key = pub
|
16
|
+
cert.not_before = Time.now
|
17
|
+
cert.not_after = Time.now + 3600
|
18
|
+
File.open("private.pem", "w") { |f| f.write key.to_pem }
|
19
|
+
File.open("cert.pem", "w") { |f| f.write cert.to_pem }
|
20
|
+
|
21
|
+
require "openssl"
|
22
|
+
|
23
|
+
|
24
|
+
pkey = OpenSSL::PKey::RSA.new(512)
|
25
|
+
cert = OpenSSL::X509::Certificate.new
|
26
|
+
cert.version = 1
|
27
|
+
cert.subject = cert.issuer = OpenSSL::X509::Name.parse("/C=FOO")
|
28
|
+
cert.public_key = pkey.public_key
|
29
|
+
cert.not_before = Time.now
|
30
|
+
cert.not_after = Time.now+3600*24*365
|
31
|
+
cert.sign(pkey, OpenSSL::Digest::SHA1.new)
|
32
|
+
p12 = OpenSSL::PKCS12.create("passwd", "FriendlyName", pkey, cert)
|
33
|
+
#puts p12.to_der
|
34
|
+
|
35
|
+
__END__
|
36
|
+
# Tasks demonstrated:
|
37
|
+
# Creating a public-private key pair
|
38
|
+
# Saving individual keys to disk in PEM format
|
39
|
+
# Reading individual keys from disk
|
40
|
+
# Encyrpting with public key
|
41
|
+
# Decrypting with private key
|
42
|
+
# Checking whether a key has public | private key
|
43
|
+
|
44
|
+
require 'openssl'
|
45
|
+
|
46
|
+
# in a real rsa implementation, message would be the symmetric key
|
47
|
+
# used to encrypt the real message data
|
48
|
+
# which would be 'yourpass' in snippet http://www.bigbold.com/snippets/posts/show/576
|
49
|
+
message = "This is some cool text."
|
50
|
+
puts "\nOriginal Message: #{message}\n"
|
51
|
+
|
52
|
+
puts "Using ruby-openssl to generate the public and private keys\n"
|
53
|
+
|
54
|
+
# .generate creates an object containing both keys
|
55
|
+
new_key = OpenSSL::PKey::RSA.generate( 1024 )
|
56
|
+
puts "Does the generated key object have the public key? #{new_key.public?}\n"
|
57
|
+
puts "Does the generated key object have the private key? #{new_key.private?}\n\n"
|
58
|
+
|
59
|
+
# write the new keys as PEM's
|
60
|
+
new_public = new_key.public_key
|
61
|
+
puts "New public key pem:\n#{new_public}\n"
|
62
|
+
puts "The new public key in human readable form:\n"
|
63
|
+
puts new_public.to_text + "\n"
|
64
|
+
|
65
|
+
output_public = File.new("./new_public.pem", "w")
|
66
|
+
output_public.puts new_public
|
67
|
+
output_public.close
|
68
|
+
|
69
|
+
new_private = new_key.to_pem
|
70
|
+
puts "new private key pem:\n#{new_private}\n"
|
71
|
+
|
72
|
+
output_private = File.new("./new_private.pem", "w")
|
73
|
+
output_private.puts new_private
|
74
|
+
output_private.close
|
75
|
+
|
76
|
+
puts "\nEncrypt/decrypt using previously saved pem files on disk...\n"
|
77
|
+
# we encrypt with the public key
|
78
|
+
# note: of course the public key PEM contains only the public key
|
79
|
+
puts "Reading Public Key PEM...\n"
|
80
|
+
public_key = OpenSSL::PKey::RSA.new(File.read("./new_public.pem"))
|
81
|
+
puts "Does the public pem file have the public key? #{public_key.public?}\n"
|
82
|
+
puts "Does the public pem file have the private key? #{public_key.private?}\n"
|
83
|
+
puts "\nEncrypting with public key ...\n"
|
84
|
+
cipher_text = public_key.public_encrypt( message )
|
85
|
+
puts "cipher text:\n#{cipher_text}\n"
|
86
|
+
|
87
|
+
# get the private key from pem file and decrypt
|
88
|
+
# note the private key PEM contains both keys
|
89
|
+
puts "\nReading Private Key PEM...\n"
|
90
|
+
private_key = OpenSSL::PKey::RSA.new(File.read("./new_private.pem"))
|
91
|
+
puts "Does the private pem file have the public key? #{private_key.public?}\n"
|
92
|
+
puts "Does the private pem file have the private key? #{private_key.private?}\n"
|
93
|
+
puts "\nDecrypting with private key ...\n"
|
94
|
+
clear_text = private_key.private_decrypt( cipher_text )
|
95
|
+
puts "\ndecoded text:\n#{clear_text}\n\n"
|
96
|
+
|
97
|
+
|
98
|
+
__END__
|
99
|
+
|
100
|
+
# outputs: -rw-r--r--
|
101
|
+
def self.calc_mode pbit
|
102
|
+
# permission bit
|
103
|
+
mode = Array.new(10, '-')
|
104
|
+
mt = pbit & 0170000
|
105
|
+
# S_IFMT
|
106
|
+
case mt
|
107
|
+
# S_IFDIR
|
108
|
+
when 00040000
|
109
|
+
mode[0] = 'd'
|
110
|
+
# S_IFBLK
|
111
|
+
when 0060000
|
112
|
+
mode[0] = 'b'
|
113
|
+
# S_IFCHR
|
114
|
+
when 0020000
|
115
|
+
mode[0] = 'c'
|
116
|
+
# S_IFLNK
|
117
|
+
when 0120000
|
118
|
+
mode[0] = 'l'
|
119
|
+
# S_IFFIFO
|
120
|
+
when 0010000
|
121
|
+
mode[0] = 'p'
|
122
|
+
# S_IFSOCK
|
123
|
+
when 0140000
|
124
|
+
mode[0] = 's'
|
125
|
+
end
|
126
|
+
u = pbit & 00700
|
127
|
+
g = pbit & 00070
|
128
|
+
o = pbit & 00007
|
129
|
+
mode[1] = 'r' if u & 00400 != 0
|
130
|
+
mode[2] = 'w' if u & 00200 != 0
|
131
|
+
mode[3] = 'x' if u & 00100 != 0
|
132
|
+
mode[4] = 'r' if g & 00040 != 0
|
133
|
+
mode[5] = 'w' if g & 00020 != 0
|
134
|
+
mode[6] = 'x' if g & 00010 != 0
|
135
|
+
mode[7] = 'r' if o & 00004 != 0
|
136
|
+
mode[8] = 'w' if o & 00002 != 0
|
137
|
+
mode[9] = 'x' if o & 00001 != 0
|
138
|
+
mode.join('')
|
139
|
+
end
|
data/tst/10-key1
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIIEogIBAAKCAQEAzRTl7NX++irdkHdH68/JFu9EXimuih6wgfDn0cIC15isHons
|
3
|
+
sxN5i7SuIDfP9zLc9QJWgfUyn0nsdOp5Di8KStvidlMnNeZUSA2YwjQUH++1z4z5
|
4
|
+
bbjUixCBkn8Jv6uV+CxPeB3DFJKOrc1DKfkzf1oaUhEPPcfS78ZGM7fEW5wXX8zX
|
5
|
+
OS0BnRvX9oTpQtypdm6vjcdZnW76eSudjJvk0yruV6UquEcud+RVNtJlM7uqgm2C
|
6
|
+
EBhD18qxQINwTG0NFALYMaNzXKrAu6MSvk9uHof/nSk4V5IwBh+2fQAyvukp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OqbAoGADRUrYep89l/O4KYjClD2EqWQ38khx0MCYVItbh7/
|
22
|
+
BvBX5AeKaEOzJeCjpQBduAHBjQ+sOHVuTXPYPcsQ+oYbTEEh7bbdOp8Z8FgKXxjz
|
23
|
+
4j+Vb1KFCBytY9anCFqJiUV8c6cVevMZToM/IV5bYRYe78Ov0QRuM8yq5knzbWCw
|
24
|
+
cccCgYEAx681uFoi74fmii8cecItcxW1jPT+C9kmh1bpN6hgTeoWH9W0fi0we77D
|
25
|
+
35I5hd7Qxh+6DhW75dWcWil6V3UqsBkpzlOx8+SdXJT7J5IDSNuCIRctct1prEqS
|
26
|
+
C6x5mIzPqKTY/Ebn12u68HMNecGVWQXNJrfYceQ9HyDKYC5OrRg=
|
27
|
+
-----END RSA PRIVATE KEY-----
|
data/tst/10-key1.pub
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzRTl7NX++irdkHdH68/JFu9EXimuih6wgfDn0cIC15isHonssxN5i7SuIDfP9zLc9QJWgfUyn0nsdOp5Di8KStvidlMnNeZUSA2YwjQUH++1z4z5bbjUixCBkn8Jv6uV+CxPeB3DFJKOrc1DKfkzf1oaUhEPPcfS78ZGM7fEW5wXX8zXOS0BnRvX9oTpQtypdm6vjcdZnW76eSudjJvk0yruV6UquEcud+RVNtJlM7uqgm2CEBhD18qxQINwTG0NFALYMaNzXKrAu6MSvk9uHof/nSk4V5IwBh+2fQAyvukpgmqvL5yYVm1mXGs4DwG9ukJ+PuGzh02sUKcGoc3yIw== delano@vanya.local
|
data/tst/10-key2
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
Proc-Type: 4,ENCRYPTED
|
3
|
+
DEK-Info: DES-EDE3-CBC,A2D419194B51170A
|
4
|
+
|
5
|
+
5GWquKZfufjYD/dcjU7aZ8LauEQzJSF+o9pz8X1eeuqcJ8bc68tm7LtJP1kiPQcD
|
6
|
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afzpZd6fXBK/L8/yufSFehSflMIg4BOdjk6xlC5ls9MLjbz+zZz9ZzXQg0xJ/JR6Q== delano@vanya.local
|
data/tst/10_keys_test.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
TEST_HOME = File.dirname(__FILE__)
|
4
|
+
$:.unshift File.join(TEST_HOME, '..', 'lib')
|
5
|
+
|
6
|
+
require 'rye'
|
7
|
+
|
8
|
+
private_key_path = File.join(TEST_HOME, '10-key1')
|
9
|
+
rpk = Rye::Key.from_file(private_key_path)
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
puts "RYE::KEY PUBLIC KEY GOOD TIMES: #{private_key_path}", $/
|
14
|
+
puts "1-2 should be the same. I don't understand why they are not."
|
15
|
+
puts "3-6 should have identical key content (ignoring spaces and 'ssh-rsa')"
|
16
|
+
|
17
|
+
# PKCS#1 RSAPublicKey* (PEM header: BEGIN RSA PUBLIC KEY)
|
18
|
+
puts "[1] PEM encoded public key (via Rye::Key#public_key)"
|
19
|
+
puts rpk.public_key.to_pem
|
20
|
+
# -----BEGIN RSA PUBLIC KEY-----
|
21
|
+
# MIIBCAKCAQEAzRTl7NX++irdkHdH68/JFu9EXimuih6wgfDn0cIC15isHonssxN5
|
22
|
+
# i7SuIDfP9zLc9QJWgfUyn0nsdOp5Di8KStvidlMnNeZUSA2YwjQUH++1z4z5bbjU
|
23
|
+
# ixCBkn8Jv6uV+CxPeB3DFJKOrc1DKfkzf1oaUhEPPcfS78ZGM7fEW5wXX8zXOS0B
|
24
|
+
# nRvX9oTpQtypdm6vjcdZnW76eSudjJvk0yruV6UquEcud+RVNtJlM7uqgm2CEBhD
|
25
|
+
# 18qxQINwTG0NFALYMaNzXKrAu6MSvk9uHof/nSk4V5IwBh+2fQAyvukpgmqvL5yY
|
26
|
+
# Vm1mXGs4DwG9ukJ+PuGzh02sUKcGoc3yIwIBIw==
|
27
|
+
# -----END RSA PUBLIC KEY-----
|
28
|
+
|
29
|
+
# X.509 SubjectPublicKeyInfo** (PEM header: BEGIN PUBLIC KEY)
|
30
|
+
puts $/, "[2] PEM encoded public key (via openssl rsa -in #{private_key_path} -pubout)"
|
31
|
+
puts Rye.shell('openssl', "rsa -in #{private_key_path} -pubout")
|
32
|
+
# -----BEGIN PUBLIC KEY-----
|
33
|
+
# MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAzRTl7NX++irdkHdH68/J
|
34
|
+
# Fu9EXimuih6wgfDn0cIC15isHonssxN5i7SuIDfP9zLc9QJWgfUyn0nsdOp5Di8K
|
35
|
+
# StvidlMnNeZUSA2YwjQUH++1z4z5bbjUixCBkn8Jv6uV+CxPeB3DFJKOrc1DKfkz
|
36
|
+
# f1oaUhEPPcfS78ZGM7fEW5wXX8zXOS0BnRvX9oTpQtypdm6vjcdZnW76eSudjJvk
|
37
|
+
# 0yruV6UquEcud+RVNtJlM7uqgm2CEBhD18qxQINwTG0NFALYMaNzXKrAu6MSvk9u
|
38
|
+
# Hof/nSk4V5IwBh+2fQAyvukpgmqvL5yYVm1mXGs4DwG9ukJ+PuGzh02sUKcGoc3y
|
39
|
+
# IwIBIw==
|
40
|
+
# -----END PUBLIC KEY-----
|
41
|
+
|
42
|
+
|
43
|
+
puts $/, "[3] Base64 encoded"
|
44
|
+
puts Base64.encode64(rpk.public_key.to_blob)
|
45
|
+
# AAAAB3NzaC1yc2EAAAABIwAAAQEAzRTl7NX++irdkHdH68/JFu9EXimuih6w
|
46
|
+
# gfDn0cIC15isHonssxN5i7SuIDfP9zLc9QJWgfUyn0nsdOp5Di8KStvidlMn
|
47
|
+
# NeZUSA2YwjQUH++1z4z5bbjUixCBkn8Jv6uV+CxPeB3DFJKOrc1DKfkzf1oa
|
48
|
+
# UhEPPcfS78ZGM7fEW5wXX8zXOS0BnRvX9oTpQtypdm6vjcdZnW76eSudjJvk
|
49
|
+
# 0yruV6UquEcud+RVNtJlM7uqgm2CEBhD18qxQINwTG0NFALYMaNzXKrAu6MS
|
50
|
+
# vk9uHof/nSk4V5IwBh+2fQAyvukpgmqvL5yYVm1mXGs4DwG9ukJ+PuGzh02s
|
51
|
+
# UKcGoc3yIw==
|
52
|
+
|
53
|
+
puts $/, "[4] Base64 encoded, SSH2 format (manual)"
|
54
|
+
puts Base64.encode64(rpk.public_key.to_blob).strip.gsub(/[\r\n]/, '')
|
55
|
+
# AAAAB3NzaC1yc2EAAAABIwAAAQEAzRTl7NX++irdkHdH68/JFu9EXimuih6wgfDn0cIC15isHonssxN5i7SuIDfP9zLc9QJWgfUyn0nsdOp5Di8KStvidlMnNeZUSA2YwjQUH++1z4z5bbjUixCBkn8Jv6uV+CxPeB3DFJKOrc1DKfkzf1oaUhEPPcfS78ZGM7fEW5wXX8zXOS0BnRvX9oTpQtypdm6vjcdZnW76eSudjJvk0yruV6UquEcud+RVNtJlM7uqgm2CEBhD18qxQINwTG0NFALYMaNzXKrAu6MSvk9uHof/nSk4V5IwBh+2fQAyvukpgmqvL5yYVm1mXGs4DwG9ukJ+PuGzh02sUKcGoc3yIw==
|
56
|
+
|
57
|
+
puts $/, "[5] Base64 encoded, SSH2 format (via Rye::Key.public_key.to_ssh2)"
|
58
|
+
puts rpk.public_key.to_ssh2
|
59
|
+
# ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzRTl7NX++irdkHdH68/JFu9EXimuih6wgfDn0cIC15isHonssxN5i7SuIDfP9zLc9QJWgfUyn0nsdOp5Di8KStvidlMnNeZUSA2YwjQUH++1z4z5bbjUixCBkn8Jv6uV+CxPeB3DFJKOrc1DKfkzf1oaUhEPPcfS78ZGM7fEW5wXX8zXOS0BnRvX9oTpQtypdm6vjcdZnW76eSudjJvk0yruV6UquEcud+RVNtJlM7uqgm2CEBhD18qxQINwTG0NFALYMaNzXKrAu6MSvk9uHof/nSk4V5IwBh+2fQAyvukpgmqvL5yYVm1mXGs4DwG9ukJ+PuGzh02sUKcGoc3yIw==
|
60
|
+
|
61
|
+
puts $/, "[6] Base64 encoded, SSH2 format (via ssh-keygen -y -f #{private_key_path})"
|
62
|
+
puts Rye.shell('ssh-keygen', "-y -f #{private_key_path}")
|
63
|
+
# ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzRTl7NX++irdkHdH68/JFu9EXimuih6wgfDn0cIC15isHonssxN5i7SuIDfP9zLc9QJWgfUyn0nsdOp5Di8KStvidlMnNeZUSA2YwjQUH++1z4z5bbjUixCBkn8Jv6uV+CxPeB3DFJKOrc1DKfkzf1oaUhEPPcfS78ZGM7fEW5wXX8zXOS0BnRvX9oTpQtypdm6vjcdZnW76eSudjJvk0yruV6UquEcud+RVNtJlM7uqgm2CEBhD18qxQINwTG0NFALYMaNzXKrAu6MSvk9uHof/nSk4V5IwBh+2fQAyvukpgmqvL5yYVm1mXGs4DwG9ukJ+PuGzh02sUKcGoc3yIw==
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
__END__
|
69
|
+
|
70
|
+
* http://cryptosys.net/pki/rsakeyformats.html
|
71
|
+
|
72
|
+
Public key formats supported
|
73
|
+
|
74
|
+
* PKCS#1 RSAPublicKey* (PEM header: BEGIN RSA PUBLIC KEY)
|
75
|
+
* X.509 SubjectPublicKeyInfo** (PEM header: BEGIN PUBLIC KEY)
|
76
|
+
* XML <RSAKeyValue>
|
77
|
+
|
78
|
+
Encrypted private key format supported
|
79
|
+
|
80
|
+
* PKCS#8 EncryptedPrivateKeyInfo** (PEM header: BEGIN ENCRYPTED PRIVATE KEY)
|
81
|
+
|
82
|
+
Private key formats supported (unencrypted)
|
83
|
+
|
84
|
+
* PKCS#1 RSAPrivateKey** (PEM header: BEGIN RSA PRIVATE KEY)
|
85
|
+
* PKCS#8 PrivateKeyInfo* (PEM header: BEGIN PRIVATE KEY)
|
86
|
+
* XML <RSAKeyPair> and <RSAKeyValue>
|
87
|
+
|
88
|
+
|
@@ -14,15 +14,15 @@ require 'rye'
|
|
14
14
|
|
15
15
|
|
16
16
|
machine_key = {
|
17
|
-
:host => '
|
18
|
-
:user => "
|
17
|
+
:host => 'localhost',
|
18
|
+
:user => "delano",
|
19
19
|
:key => '/proj/git/rudy/.rudy/key-test-app.private'
|
20
20
|
}
|
21
21
|
|
22
22
|
machine_pass = {
|
23
|
-
:host => '
|
24
|
-
:user => '
|
25
|
-
:pass => 'pablo9001'
|
23
|
+
:host => 'localhost',
|
24
|
+
:user => 'delano',
|
25
|
+
# :pass => 'pablo9001'
|
26
26
|
}
|
27
27
|
|
28
28
|
machine_local = {
|
@@ -46,18 +46,9 @@ Benchmark.bmbm do |x|
|
|
46
46
|
x.report('rset-P:') { puts "%10s:%s:%s" % rset_parallel.uname }
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
local_files = rbox_local['/tmp/ssh-test'].ls
|
56
|
-
remote_files = rbox_remote['/etc/ssh'].ls
|
57
|
-
diff = remote_files - local_files
|
58
|
-
|
59
|
-
puts "ETC DIFF:"
|
60
|
-
puts diff
|
61
|
-
|
62
|
-
rbox_remote = Rye::Box.new('ec2-75-101-255-188.compute-1.amazonaws.com', :user => 'root', :debug => STDOUT, :safe => false, :keys => '/proj/git/rudy/.rudy/key-test-app.private')
|
63
|
-
|
49
|
+
# Parallel should obviously be faster here
|
50
|
+
Benchmark.bmbm do |x|
|
51
|
+
x.report('rbox: ') { puts "%10s:%s:%s" % [rbox_key.sleep(2), rbox_local.sleep(2), rbox_pass.sleep(2)] }
|
52
|
+
x.report('rset-S:') { puts "%10s:%s:%s" % rset_serial.sleep(2) }
|
53
|
+
x.report('rset-P:') { puts "%10s:%s:%s" % rset_parallel.sleep(2) }
|
54
|
+
end
|