Class: Dr::GnuPG
Instance Method Summary collapse
- #export_pub(key, location) ⇒ Object
- #generate_key(name, mail, pass) ⇒ Object
- #get_key_id(key) ⇒ Object
-
#initialize(keyring) ⇒ GnuPG
constructor
A new instance of GnuPG.
Methods included from Logger
#log, log, set_logfile, set_verbosity, #tag
Constructor Details
#initialize(keyring) ⇒ GnuPG
Returns a new instance of GnuPG.
11 12 13 14 15 16 17 |
# File 'lib/dr/gnupg.rb', line 11 def initialize(keyring) @keyring = keyring # initialise the keyring FileUtils.mkdir_p @keyring FileUtils.chmod_R 0700, @keyring end |
Instance Method Details
#export_pub(key, location) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/dr/gnupg.rb', line 72 def export_pub(key, location) # TODO: Remove the key before exporting (so gpg doesn't ask about it) log(:info, tag("gpg", "Exporting key")) cmd = "gpg --armor --homedir #{@keyring} \ --output #{location} \ --export #{key}" gpg_cmd = ShellCmd.new cmd, :tag => "gpg" end |
#generate_key(name, mail, pass) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dr/gnupg.rb', line 19 def generate_key(name, mail, pass) #kill_rngd = false #unless File.exists? "/var/run/rngd.pid" # print "Starting rngd (root permissions required) ... " # Kernel.system "sudo rngd -p #{@keyring}/rngd.pid -r /dev/urandom" # kill_rngd = true # puts "[OK]" #end log(:info, tag("gpg", "Generating the GPG key")) passphrase = "Passphrase: #{pass}" if pass.length > 0 cmd = <<-END gpg --batch --gen-key --homedir #{@keyring} <<EOF Key-Type: RSA Key-Length: 2048 Subkey-Type: ELG-E Subkey-Length: 2048 Name-Real: #{name} Name-Email: #{mail} #{passphrase} Expire-Date: 0 %commit EOF END # TODO: Add timeout to this one gpg_cmd = ShellCmd.new cmd, :tag => "gpg" cmd = "gpg --list-keys --with-colons --homedir #{@keyring}" gpg_cmd = ShellCmd.new cmd, :tag => "gpg" key_list = gpg_cmd.out.split "\n" key_entry = key_list.grep(/^pub/).grep(/#{name}/).grep(/#{mail}/) key = key_entry[0].split(":")[4][8..-1] log(:info, tag("gpg", "Key done")) #if kill_rngd # print "Stopping rngd (root permissions required) ... " # Kernel.system "sudo kill `cat #{@keyring}/rngd.pid`" # Kernel.system "sudo rm -f #{@keyring}/rngd.pid" # puts "[OK]" #end key end |