X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fcrypto.rb;h=7f044b99428d0beb80bfb22fa1f4cda6bc127011;hb=3de96fb9b308afe600c7ccfcee75913f039ef4f6;hp=0003fec7bc60314dd14d89387d25ae886a7972c6;hpb=787d8691058b0c20f19087e41d71944365ec4554;p=sup diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb index 0003fec..7f044b9 100644 --- a/lib/sup/crypto.rb +++ b/lib/sup/crypto.rb @@ -13,17 +13,15 @@ class CryptoManager def initialize @mutex = Mutex.new - self.class.i_am_the_instance self bin = `which gpg`.chomp - @cmd = case bin when /\S/ - Redwood::log "crypto: detected gpg binary in #{bin}" + debug "crypto: detected gpg binary in #{bin}" "#{bin} --quiet --batch --no-verbose --logger-fd 1 --use-agent" else - Redwood::log "crypto: no gpg binary detected" + debug "crypto: no gpg binary detected" nil end end @@ -53,7 +51,7 @@ class CryptoManager payload_fn.write format_payload(payload) payload_fn.close - recipient_opts = to.map { |r| "--recipient '<#{r}>'" }.join(" ") + recipient_opts = (to + [ from ] ).map { |r| "--recipient '<#{r}>'" }.join(" ") sign_opts = sign ? "--sign --local-user '#{from}'" : "" gpg_output = run_gpg "--output - --armor --encrypt --textmode #{sign_opts} #{recipient_opts} #{payload_fn.path}" raise Error, (gpg_output || "gpg command failed: #{cmd}") unless $?.success? @@ -116,21 +114,19 @@ class CryptoManager output = run_gpg "--decrypt #{payload_fn.path}" if $?.success? - decrypted_payload, sig_lines = - if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m - [$1, $2] + decrypted_payload, sig_lines = if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m + [$1, $2] + else + [output, nil] + end + + sig = if sig_lines # encrypted & signed + if sig_lines =~ /^gpg: (Good signature from .*$)/ + Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n") else - [output, nil] - end - - sig = - if sig_lines # encrypted & signed - if sig_lines =~ /^gpg: (Good signature from .*$)/ - Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n") - else - Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n") - end + Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n") end + end notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display" [RMail::Parser.read(decrypted_payload), sig, notice] @@ -145,7 +141,7 @@ private def unknown_status lines=[] Chunk::CryptoNotice.new :unknown, "Unable to determine validity of cryptographic signature", lines end - + def cant_find_binary ["Can't find gpg binary in path."] end @@ -158,9 +154,7 @@ private def run_gpg args cmd = "#{@cmd} #{args} 2> /dev/null" - #Redwood::log "crypto: running: #{cmd}" output = `#{cmd}` - #Redwood::log "crypto: output: #{output.inspect}" unless $?.success? output end end