Monday, July 24, 2017

GPGME:: How to supress the interactive popup (passphrase)

 I spent days to overcome this issue, when I use GPGME each time the interactive popup came up, which is not desirable for my own project. Here is the solution.
Since the GPGME::Ctx requires you the optional parameter (passwpord | passphrase_callback) you need to pass those hash keypairs as arguments:


...
      @context = GPGME::Ctx.new(
        pinentry_mode:       GPGME::PINENTRY_MODE_LOOPBACK,
        passphrase_callback: method(:passfunc)
      )
    end

    def passfunc(obj, uid_hint, passphrase_info, prev_was_bad, fd)
      io = IO.for_fd(fd, "w")
      io.puts "your passphrase"
      io.flush
    end




Then without the complicated gpg-agent settings, you can supress the popup. I think looking at the source code is the best way to handle this since it is obvious that there the codes requires the function as argument.

You can refer to the following link for the further information:
https://stackoverflow.com/questions/21554292/gpgme-passphrase-prompt-issue-ruby
http://www.rubydoc.info/github/ueno/ruby-gpgme/GPGME/Ctx

No comments:

Post a Comment