GPGME Express Phrase Request (Ruby)

In the example below, I tried the password and passphrase. I am also not allowed to run my code without the openpgp field requesting a passphrase, the following message:

Mac syntax "Please enter a passphrase to unlock the secret key for an OpenPGP certificate"

What do I need to change so that my code can work without a hint? I know that my password is correct in the code.

I tried:

ctx = GPGME::Ctx.new :password=> 'password'

and this:

ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc)

But both do not work. Any advice is appreciated.

  def self.passfunc(obj, uid_hint, passphrase_info, prev_was_bad, fd)
    io = IO.for_fd(fd, 'w')
    io.puts 'password'
    io.flush
  end

  def self.decrypt_file(local_file, decrypted_file = nil)
    # Set decrypted file path if one is not provided
    decrypted_file = local_file.chomp(File.extname(local_file)) + ".csv" if decrypted_file == nil
    encrypted_data = GPGME::Data.new(File.open(local_file))

    # Set the password and GPG Key to decryption
    ctx = GPGME::Ctx.new :password=> 'password'

    # I have tried the passphrase call back
    #ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc)

    #KEY= GPGME::Data.new(File.open("key.gpg"))
    ctx.import_keys Rebal::Config::KEY

    # Decrypt the data
    decrypted = ctx.decrypt encrypted_data
    decrypted.seek(0)

    #Write the data to a file
    File.write(decrypted_file, decrypted.read)

    #return path
    decrypted_file
  end

, , ... ruby ​​gpgme , , soltuion... pinentry ( ) gpgme - , , .

: , pinentry GPG2 GPG1.4. GPG1.4, .

- , GPG2 ,

+4
1

pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK GPG2:

GPGME::Ctx.new(
  pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK,
  passphrase_callback: method(:passfunc)
)
+2

Source: https://habr.com/ru/post/1525237/


All Articles