Class: Dr::GnuPG
Instance Method Summary collapse
- #export_pub(key, location) ⇒ Object
- #generate_key(name, mail, pass) ⇒ Object
- #get_id ⇒ Object
-
#initialize(keyring) ⇒ GnuPG
constructor
A new instance of GnuPG.
Methods included from Logger
Constructor Details
#initialize(keyring) ⇒ GnuPG
Returns a new instance of GnuPG.
8 9 10 11 12 13 14 |
# File 'lib/dr/gnupg.rb', line 8 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
65 66 67 68 69 70 71 72 |
# File 'lib/dr/gnupg.rb', line 65 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
16 17 18 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 |
# File 'lib/dr/gnupg.rb', line 16 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 = " gpg --batch --gen-key --homedir \#{@keyring} <<EOF\n Key-Type: RSA\n Key-Length: 2048\n Subkey-Type: ELG-E\n Subkey-Length: 2048\n Name-Real: \#{name}\n Name-Email: \#{mail}\n \#{passphrase}\n Expire-Date: 0\n %commit\nEOF\n" # 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 |
#get_id ⇒ Object
62 63 |
# File 'lib/dr/gnupg.rb', line 62 def get_id end |