Domanda

Sto usando rubino gpgme gemma (1.0.8). La mia passphrase callback non è chiamato:

def passfunc(*args)
  fd = args.last
  io = IO.for_fd(fd, 'w')
  io.puts "mypassphrase"
  io.flush
end

opts = {
  :passphrase_callback => method(:passfunc)
}
GPGME.decrypt(input,output, opts)

Qualcuno ha esempio funzionante di passphrase richiamata?

È stato utile?

Soluzione

Esempio di richiamata si possono trovare nel seguente esempio di lavoro. Si firma un file in modalità indipendente, vale a dire, il file di firma è separato dal file originale. Esso utilizza il portachiavi di default in ~ / .gnupg o qualcosa di simile. Per usare una directory diversa per il vostro portachiavi, impostare la variabile di ambiente ENV [ "GNUPGHOME"] = "" prima chiamata GPGME :: segno ().

#!/usr/bin/ruby
require 'rubygems'
require 'gpgme'

puts "Signing #{ARGV[0]}" 
input = File.open(ARGV[0],'r')

PASSWD = "abc"

def passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd)
    puts("Passphrase for #{uid_hint}: ")
    io = IO.for_fd(fd, 'w')
    io.write(PASSWD+"\n")
    io.flush
end

output = File.open(ARGV[0]+'.asc','w')

sign = GPGME::sign(input, {
        :passphrase_callback => method(:passfunc), 
        :mode => GPGME::SIG_MODE_DETACH
    })
output.write(sign)
output.close
input.close

Altri suggerimenti

Ecco un altro esempio di lavoro per te, che non fa uso di una firma distaccata. Per verificare ciò, è sufficiente modificare 'user@host.name' per l'identificativo della chiave e fare questo: GPG.decrypt (GPG.encrypt ( 'del testo',: armatura => true))

require 'gpgme'
require 'highline/import'

module GPG
  ENCRYPT_KEY = 'user@host.com'
  @gpg = GPGME::Crypto.new

  class << self

    def decrypt(encrypted_data, options = {})
      options = { :passphrase_callback => self.method(:passfunc) }.merge(options)
      @gpg.decrypt(encrypted_data, options).read 
    end

    def encrypt(data_to_encrypt, options = {})
      options = { :passphrase_callback => self.method(:passfunc), :armor => true }.merge(options)
      @gpg.encrypt(data_to_encrypt, options).read
    end

    private
      def get_passphrase
        ask("Enter passphrase for #{ENCRYPT_KEY}: ") { |q| q.echo = '*' }
      end

      def passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd)
        begin
          system('stty -echo')
          io = IO.for_fd(fd, 'w')
          io.puts(get_passphrase)
          io.flush
        ensure
          (0 ... $_.length).each do |i| $_[i] = ?0 end if $_
          system('stty echo')
        end
        $stderr.puts
      end
  end
end

Saluti!,

- Carl

E 'importante notare che, come di GnuPG 2.0 (e 1.4 quando l'opzione use-agent è utilizzato) pinentry viene utilizzato per la raccolta passphrase. Ciò significa che la richiamata GPGME passphrase essere invocato . Questo è descritto qui e un esempio di utilizzo può essere trovato nella gpgme-tool esempio

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top