Class: OpenPGP::Client::GnuPG
- Inherits:
-
Object
- Object
- OpenPGP::Client::GnuPG
- Defined in:
- lib/openpgp/client/gnupg.rb
Overview
GNU Privacy Guard (GnuPG) implementation.
Constant Summary collapse
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#card_edit ⇒ Object
Presents a menu to work with a smartcard.
-
#card_status ⇒ Object
Shows the content of the smart card.
-
#change_pin ⇒ Object
Presents a menu to allow changing the PIN of a smartcard.
-
#check_sigs ⇒ Object
Same as
list_sigs
, but the signatures are verified. -
#check_trustdb ⇒ Object
Does trust database maintenance without user interaction.
-
#clearsign ⇒ Object
Makes a clear text signature.
-
#dearmor(file) ⇒ Object
Unpacks an arbitrary input from an OpenPGP ASCII armor.
-
#decrypt(file) ⇒ Object
Decrypts data.
-
#decrypt_files(*files) ⇒ Object
Identical to –multifile –decrypt.
-
#delete_key(name) ⇒ Object
Removes key from the public keyring.
-
#delete_secret_and_public_key(name) ⇒ Object
Removes key from the secret and public keyring.
-
#delete_secret_key(name) ⇒ Object
Removes key from the secret and public keyring.
-
#desig_revoke(name) ⇒ Object
Generates a designated revocation certificate for a key.
-
#detach_sign ⇒ Object
Makes a detached signature.
-
#dump_options ⇒ Object
Prints a list of all available options and commands.
-
#edit_key(key) ⇒ Object
Present a menu which enables you to do most of the key management related tasks.
-
#enarmor(file) ⇒ Object
Packs an arbitrary input into an OpenPGP ASCII armor.
-
#encrypt ⇒ Object
Encrypts data.
-
#encrypt_files(*files) ⇒ Object
Identical to –multifile –encrypt.
-
#export(*keys) ⇒ Object
Exports keys from the public keyring.
-
#export_ownertrust ⇒ Object
Sends the ownertrust values to stdout.
-
#export_secret_keys ⇒ Object
Exports the secret keys.
-
#export_secret_subkeys ⇒ Object
Exports the secret subkeys.
-
#fast_import(*keys) ⇒ Object
Alias for
import
. -
#fetch_keys(*uris) ⇒ Object
Retrieves keys located at the specified URIs.
-
#fingerprint(*keys) ⇒ Object
Lists all keys (or the specified ones) along with their fingerprints.
-
#gen_key ⇒ Object
Generates a new key pair.
-
#gen_prime(mode, bits, qbits = nil) ⇒ Object
Generates a prime number.
-
#gen_random(level = 0, count = nil) ⇒ Object
Emits
count
random bytes of the given quality level. -
#gen_revoke(name) ⇒ Object
Generates a revocation certificate for the complete key.
-
#help ⇒ Object
Prints a usage message summarizing the most useful command-line options.
-
#import(*keys) ⇒ Object
Imports/merges keys, adding the given keys to the keyring.
-
#import_ownertrust(*files) ⇒ Object
Updates the trustdb with the ownertrust values stored in
files
or stdin. -
#initialize(options = {}) ⇒ GnuPG
constructor
A new instance of GnuPG.
-
#list_keys(*keys) ⇒ Object
Lists keys from the public keyrings.
-
#list_packets ⇒ Object
Lists only the sequence of packets.
-
#list_public_keys(*keys) ⇒ Object
Lists keys from the public keyrings.
-
#list_secret_keys(*keys) ⇒ Object
Lists keys from the secret keyrings.
-
#list_sigs ⇒ Object
Same as
list_keys
, but the signatures are listed too. -
#lsign_key(name) ⇒ Object
Signs a public key with your secret key but marks it as non-exportable.
-
#print_md(algo, *files) ⇒ Object
Prints message digest of algorithm
algo
for all given files or stdin. -
#print_mds(*files) ⇒ Object
Prints message digests of all available algorithms for all given files or stdin.
-
#rebuild_keydb_caches ⇒ Object
Creates signature caches in the keyring.
-
#recv_keys(*keys) ⇒ Object
Imports the keys with the given key IDs from a keyserver.
-
#refresh_keys(*keys) ⇒ Object
Requests updates from a keyserver for keys that already exist on the local keyring.
-
#search_keys(*names) ⇒ Object
Searches the keyserver for the given names.
-
#send_keys(*keys) ⇒ Object
Sends keys to a keyserver.
-
#sign ⇒ Object
Makes a signature.
-
#sign_key(name) ⇒ Object
Signs a public key with your secret key.
-
#store(file) ⇒ Object
Stores only (make a simple RFC1991 literal data packet).
-
#symmetric(file) ⇒ Object
Encrypts with a symmetric cipher using a passphrase.
-
#update_trustdb ⇒ Object
Does trust database maintenance.
-
#verify(file) ⇒ Object
Verifies data.
-
#verify_files(*files) ⇒ Object
Identical to –multifile –verify.
-
#version ⇒ Object
Prints the program version and licensing information.
-
#warranty ⇒ Object
Prints warranty information.
Constructor Details
#initialize(options = {}) ⇒ GnuPG
Returns a new instance of GnuPG.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/openpgp/client/gnupg.rb', line 11 def initialize( = {}) @options = { :homedir => ENV['GNUPGHOME'] || '~/.gnupg', :version => false, } @options.merge!() if .has_key?(:options) ([:options]) end end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/openpgp/client/gnupg.rb', line 9 def @options end |
Instance Method Details
#card_edit ⇒ Object
Presents a menu to work with a smartcard.
216 217 218 |
# File 'lib/openpgp/client/gnupg.rb', line 216 def card_edit raise NotImplementedError # TODO end |
#card_status ⇒ Object
Shows the content of the smart card.
222 223 224 |
# File 'lib/openpgp/client/gnupg.rb', line 222 def card_status raise NotImplementedError # TODO end |
#change_pin ⇒ Object
Presents a menu to allow changing the PIN of a smartcard.
228 229 230 |
# File 'lib/openpgp/client/gnupg.rb', line 228 def change_pin raise NotImplementedError # TODO end |
#check_sigs ⇒ Object
Same as list_sigs
, but the signatures are verified.
197 198 199 |
# File 'lib/openpgp/client/gnupg.rb', line 197 def check_sigs raise NotImplementedError # TODO end |
#check_trustdb ⇒ Object
Does trust database maintenance without user interaction.
319 320 321 |
# File 'lib/openpgp/client/gnupg.rb', line 319 def check_trustdb raise NotImplementedError # TODO end |
#clearsign ⇒ Object
Makes a clear text signature.
69 70 71 |
# File 'lib/openpgp/client/gnupg.rb', line 69 def clearsign raise NotImplementedError # TODO end |
#dearmor(file) ⇒ Object
Unpacks an arbitrary input from an OpenPGP ASCII armor.
405 406 407 408 |
# File 'lib/openpgp/client/gnupg.rb', line 405 def dearmor(file) data = OpenPGP.dearmor(File.read(file)) puts data # FIXME end |
#decrypt(file) ⇒ Object
Decrypts data.
112 113 114 |
# File 'lib/openpgp/client/gnupg.rb', line 112 def decrypt(file) raise NotImplementedError # TODO end |
#decrypt_files(*files) ⇒ Object
Identical to –multifile –decrypt.
138 139 140 141 |
# File 'lib/openpgp/client/gnupg.rb', line 138 def decrypt_files(*files) [:multifile] = true files.each { |file| decrypt(file) } end |
#delete_key(name) ⇒ Object
Removes key from the public keyring.
234 235 236 |
# File 'lib/openpgp/client/gnupg.rb', line 234 def delete_key(name) raise NotImplementedError # TODO end |
#delete_secret_and_public_key(name) ⇒ Object
Removes key from the secret and public keyring. If a secret key exists, it will be removed first.
246 247 248 |
# File 'lib/openpgp/client/gnupg.rb', line 246 def delete_secret_and_public_key(name) raise NotImplementedError # TODO end |
#delete_secret_key(name) ⇒ Object
Removes key from the secret and public keyring.
240 241 242 |
# File 'lib/openpgp/client/gnupg.rb', line 240 def delete_secret_key(name) raise NotImplementedError # TODO end |
#desig_revoke(name) ⇒ Object
Generates a designated revocation certificate for a key.
426 427 428 |
# File 'lib/openpgp/client/gnupg.rb', line 426 def desig_revoke(name) raise NotImplementedError # TODO end |
#detach_sign ⇒ Object
Makes a detached signature.
75 76 77 |
# File 'lib/openpgp/client/gnupg.rb', line 75 def detach_sign raise NotImplementedError # TODO end |
#dump_options ⇒ Object
Prints a list of all available options and commands.
50 51 52 53 54 55 56 57 |
# File 'lib/openpgp/client/gnupg.rb', line 50 def self.class.public_instance_methods(false).each do |command| if command =~ /^[\w\d_]+$/ puts "--#{command.to_s.gsub('_', '-')}" end end # TODO: list available options, too. end |
#edit_key(key) ⇒ Object
Present a menu which enables you to do most of the key management related tasks.
432 433 434 |
# File 'lib/openpgp/client/gnupg.rb', line 432 def edit_key(key) raise NotImplementedError # TODO end |
#enarmor(file) ⇒ Object
Packs an arbitrary input into an OpenPGP ASCII armor.
398 399 400 401 |
# File 'lib/openpgp/client/gnupg.rb', line 398 def enarmor(file) text = OpenPGP.enarmor(File.read(file), :armored_file, :comment => 'Use "gpg --dearmor" for unpacking', :line_length => 64) puts text # FIXME end |
#encrypt ⇒ Object
Encrypts data.
81 82 83 |
# File 'lib/openpgp/client/gnupg.rb', line 81 def encrypt raise NotImplementedError # TODO end |
#encrypt_files(*files) ⇒ Object
Identical to –multifile –encrypt.
131 132 133 134 |
# File 'lib/openpgp/client/gnupg.rb', line 131 def encrypt_files(*files) [:multifile] = true files.each { |file| encrypt(file) } end |
#export(*keys) ⇒ Object
Exports keys from the public keyring.
252 253 254 |
# File 'lib/openpgp/client/gnupg.rb', line 252 def export(*keys) raise NotImplementedError # TODO end |
#export_ownertrust ⇒ Object
Sends the ownertrust values to stdout.
325 326 327 |
# File 'lib/openpgp/client/gnupg.rb', line 325 def export_ownertrust raise NotImplementedError # TODO end |
#export_secret_keys ⇒ Object
Exports the secret keys.
264 265 266 |
# File 'lib/openpgp/client/gnupg.rb', line 264 def export_secret_keys raise NotImplementedError # TODO end |
#export_secret_subkeys ⇒ Object
Exports the secret subkeys.
270 271 272 |
# File 'lib/openpgp/client/gnupg.rb', line 270 def export_secret_subkeys raise NotImplementedError # TODO end |
#fast_import(*keys) ⇒ Object
Alias for import
.
282 283 284 |
# File 'lib/openpgp/client/gnupg.rb', line 282 def fast_import(*keys) import(*keys) end |
#fetch_keys(*uris) ⇒ Object
Retrieves keys located at the specified URIs.
306 307 308 309 |
# File 'lib/openpgp/client/gnupg.rb', line 306 def fetch_keys(*uris) require 'open-uri' raise NotImplementedError # TODO end |
#fingerprint(*keys) ⇒ Object
Lists all keys (or the specified ones) along with their fingerprints.
203 204 205 206 |
# File 'lib/openpgp/client/gnupg.rb', line 203 def fingerprint(*keys) [:fingerprint] = true list_keys(*keys) end |
#gen_key ⇒ Object
Generates a new key pair.
414 415 416 |
# File 'lib/openpgp/client/gnupg.rb', line 414 def gen_key raise NotImplementedError # TODO end |
#gen_prime(mode, bits, qbits = nil) ⇒ Object
Generates a prime number.
387 388 389 390 391 392 393 394 |
# File 'lib/openpgp/client/gnupg.rb', line 387 def gen_prime(mode, bits, qbits = nil) case mode.to_i when 1..4 raise NotImplementedError # TODO else wrong_args "--gen-prime mode bits [qbits]" end end |
#gen_random(level = 0, count = nil) ⇒ Object
Emits count
random bytes of the given quality level.
370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/openpgp/client/gnupg.rb', line 370 def gen_random(level = 0, count = nil) wrong_args "--gen-random 0|1|2 [count]" unless (0..2).include?(level) require 'openssl' count = count.to_i if count endless = count.nil? while endless || count > 0 n = !endless && count < 99 ? count : 99 p = Random.bytes(n) print [:armor] ? [p].pack('m').delete("\n") : p count -= n unless endless end puts if [:armor] end |
#gen_revoke(name) ⇒ Object
Generates a revocation certificate for the complete key.
420 421 422 |
# File 'lib/openpgp/client/gnupg.rb', line 420 def gen_revoke(name) raise NotImplementedError # TODO end |
#help ⇒ Object
Prints a usage message summarizing the most useful command-line options.
40 |
# File 'lib/openpgp/client/gnupg.rb', line 40 def help() end |
#import(*keys) ⇒ Object
Imports/merges keys, adding the given keys to the keyring.
276 277 278 |
# File 'lib/openpgp/client/gnupg.rb', line 276 def import(*keys) raise NotImplementedError # TODO end |
#import_ownertrust(*files) ⇒ Object
Updates the trustdb with the ownertrust values stored in files
or stdin.
331 332 333 |
# File 'lib/openpgp/client/gnupg.rb', line 331 def import_ownertrust(*files) raise NotImplementedError # TODO end |
#list_keys(*keys) ⇒ Object
Lists keys from the public keyrings.
145 146 147 |
# File 'lib/openpgp/client/gnupg.rb', line 145 def list_keys(*keys) list_public_keys(*keys) end |
#list_packets ⇒ Object
Lists only the sequence of packets.
210 211 212 |
# File 'lib/openpgp/client/gnupg.rb', line 210 def list_packets raise NotImplementedError # TODO end |
#list_public_keys(*keys) ⇒ Object
Lists keys from the public keyrings.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/openpgp/client/gnupg.rb', line 151 def list_public_keys(*keys) public_keyrings.each do |keyring_filename, keyring| puts (keyring_filename = File.(keyring_filename)) print '-' * keyring_filename.size keyring.each do |packet| case packet when Packet::PublicSubkey print_key_listing(packet, :sub) when Packet::PublicKey print_key_listing(packet, :pub) when Packet::UserID print_uid_listing(packet) end end end end |
#list_secret_keys(*keys) ⇒ Object
Lists keys from the secret keyrings.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/openpgp/client/gnupg.rb', line 171 def list_secret_keys(*keys) secret_keyrings.each do |keyring_filename, keyring| puts (keyring_filename = File.(keyring_filename)) print '-' * keyring_filename.size keyring.each do |packet| case packet when Packet::SecretSubkey print_key_listing(packet, :ssb) when Packet::SecretKey print_key_listing(packet, :sec) when Packet::UserID print_uid_listing(packet) end end end end |
#list_sigs ⇒ Object
Same as list_keys
, but the signatures are listed too.
191 192 193 |
# File 'lib/openpgp/client/gnupg.rb', line 191 def list_sigs raise NotImplementedError # TODO end |
#lsign_key(name) ⇒ Object
Signs a public key with your secret key but marks it as non-exportable.
444 445 446 |
# File 'lib/openpgp/client/gnupg.rb', line 444 def lsign_key(name) raise NotImplementedError # TODO end |
#print_md(algo, *files) ⇒ Object
Prints message digest of algorithm algo
for all given files or stdin.
343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/openpgp/client/gnupg.rb', line 343 def print_md(algo, *files) unless digest_algorithms.include?(algorithm = algo.to_s.upcase.to_sym) abort "gpg: invalid hash algorithm `#{algo}'" else digest = Digest.for(algorithm) end files.each do |file| puts (prefix = "#{file}: ") << format_fingerprint(digest.file(file).hexdigest, prefix.size) end end |
#print_mds(*files) ⇒ Object
Prints message digests of all available algorithms for all given files or stdin.
357 358 359 360 361 362 363 364 365 366 |
# File 'lib/openpgp/client/gnupg.rb', line 357 def print_mds(*files) files.each do |file| digest_algorithms.each do |algorithm| algorithm = :RMD160 if algorithm == :RIPEMD160 digest = Digest.for(algorithm) puts (prefix = "#{file}: #{algorithm.to_s.rjust(6)} = ") << format_fingerprint(digest.file(file).hexdigest, prefix.size) end end end |
#rebuild_keydb_caches ⇒ Object
Creates signature caches in the keyring.
337 338 339 |
# File 'lib/openpgp/client/gnupg.rb', line 337 def rebuild_keydb_caches raise NotImplementedError # TODO end |
#recv_keys(*keys) ⇒ Object
Imports the keys with the given key IDs from a keyserver.
288 289 290 |
# File 'lib/openpgp/client/gnupg.rb', line 288 def recv_keys(*keys) raise NotImplementedError # TODO end |
#refresh_keys(*keys) ⇒ Object
Requests updates from a keyserver for keys that already exist on the local keyring.
294 295 296 |
# File 'lib/openpgp/client/gnupg.rb', line 294 def refresh_keys(*keys) raise NotImplementedError # TODO end |
#search_keys(*names) ⇒ Object
Searches the keyserver for the given names.
300 301 302 |
# File 'lib/openpgp/client/gnupg.rb', line 300 def search_keys(*names) raise NotImplementedError # TODO end |
#send_keys(*keys) ⇒ Object
Sends keys to a keyserver.
258 259 260 |
# File 'lib/openpgp/client/gnupg.rb', line 258 def send_keys(*keys) raise NotImplementedError # TODO end |
#sign ⇒ Object
Makes a signature.
63 64 65 |
# File 'lib/openpgp/client/gnupg.rb', line 63 def sign raise NotImplementedError # TODO end |
#sign_key(name) ⇒ Object
Signs a public key with your secret key.
438 439 440 |
# File 'lib/openpgp/client/gnupg.rb', line 438 def sign_key(name) raise NotImplementedError # TODO end |
#store(file) ⇒ Object
Stores only (make a simple RFC1991 literal data packet).
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/openpgp/client/gnupg.rb', line 99 def store(file) Message.write(stdout) do |msg| msg << Packet::LiteralData.new({ :format => :b, :filename => File.basename(file), :timestamp => File.mtime(file), :data => File.read(file), }) end end |
#symmetric(file) ⇒ Object
Encrypts with a symmetric cipher using a passphrase.
87 88 89 90 91 92 93 94 95 |
# File 'lib/openpgp/client/gnupg.rb', line 87 def symmetric(file) print OpenPGP.encrypt(File.read(file), { :symmetric => true, :passphrase => read_passphrase, :cipher => cipher_algorithm, :digest => digest_algorithm, :compress => compress_algorithm, }) end |
#update_trustdb ⇒ Object
Does trust database maintenance.
313 314 315 |
# File 'lib/openpgp/client/gnupg.rb', line 313 def update_trustdb raise NotImplementedError # TODO end |
#verify(file) ⇒ Object
Verifies data.
118 119 120 |
# File 'lib/openpgp/client/gnupg.rb', line 118 def verify(file) raise NotImplementedError # TODO end |
#verify_files(*files) ⇒ Object
Identical to –multifile –verify.
124 125 126 127 |
# File 'lib/openpgp/client/gnupg.rb', line 124 def verify_files(*files) [:multifile] = true files.each { |file| verify(file) } end |
#version ⇒ Object
Prints the program version and licensing information.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/openpgp/client/gnupg.rb', line 27 def version puts "gpg.rb (GnuPG compatible) #{VERSION}" puts puts "Home: #{[:homedir]}" puts "Supported algorithms:" puts "Pubkey: " # TODO puts "Cipher: #{cipher_algorithms.keys.map(&:to_s).sort.join(', ')}" puts "Hash: #{digest_algorithms.join(', ')}" puts "Compression: #{compress_algorithms.keys.map(&:to_s).sort.join(', ')}" end |
#warranty ⇒ Object
Prints warranty information.
44 45 46 |
# File 'lib/openpgp/client/gnupg.rb', line 44 def warranty raise NotImplementedError end |