-
Notifications
You must be signed in to change notification settings - Fork 1
/
keygen.rb
40 lines (31 loc) · 999 Bytes
/
keygen.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'lib/execute'
require 'lib/settings'
settings = Poppet::Settings.new
batch_file = settings["keys"] + "/batch.txt"
passphrase = settings["passphrase"]
key_name = settings["key_name"]
pubkey = "keys/#{key_name}.pub"
private_key = "keys/#{key_name}.sec"
raise "stop!" if File.exist?(pubkey) or File.exist?(private_key)
name = ARGV[0] #TODO: argument parsing
# TODO: move into lib/encrypt.rb
File.open(batch_file, "w") do |f|
f.puts <<-BATCH
%echo Generating a standard key
Key-Type: RSA
Key-Length: 1024
Name-Real: #{name}
Name-Comment: Poppet
Name-Email: poppet
Expire-Date: 0
Passphrase: #{passphrase}
%pubring #{pubkey}
%secring #{private_key}
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
BATCH
end
entropy_maker = "ls -R /"
Poppet::Execute.execute("#{entropy_maker} 2> /dev/null > /dev/null &")
puts Poppet::Execute.execute("gpg --batch --gen-key #{batch_file}/batch.txt")