Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with set_passphrase_cb #11

Closed
crayfishx opened this issue Jul 19, 2012 · 3 comments
Closed

Problem with set_passphrase_cb #11

crayfishx opened this issue Jul 19, 2012 · 3 comments

Comments

@crayfishx
Copy link

I need to be able to implement gpgme from a systems tool and pass the key password as a string. However, using the password attribute to Ctx.new does not accomplish this. This is the code I'm using...


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

file = "/tmp/encrypted.gpg"
cipher = File.open(file).read
ctx = GPGME::Ctx.new( { :password => 'foobar' } )
raw = GPGME::Data.new(cipher)
txt = GPGME::Data.new
txt = ctx.decrypt(raw)
txt.seek 0
puts txt

I've walked through the Ruby side of things and it looks like set_passphrase_callback is called correctly with passfunc set to #<Method: GPGME::Ctx.pass_function> and hook_value being the value of my password but the pass_function never gets called. GPGME seems to want to use gpg-agent. Without gpg-agent running I get prompted by GPG for a password, which then works. If I run gpg-agent then it works seamlessly no matter what value I put into :password above.

The problem seems to be on the C side rather than the ruby side, but have you seen this behaviour before? This is gnupg2-2.0.14-4, gpgme-1.1.8-3 with the 2.0.1 gpgme gem on CentOS

A few other notes...

  • gpg-agent is not running anywhere
  • I have no GPG_* variables set in my environment

Thanks in advance for any help.

@ueno
Copy link
Owner

ueno commented Jul 27, 2012

Since gnupg2 does all the crypt stuff in gpg-agent, you cannot intercept the passphrase handling.
A work around is to install gnupg1 and set the executable path with GPGME::Engine.set_info.

@ueno ueno closed this as completed Jul 30, 2012
@joekiller
Copy link

It may be helpful to mention that this feature is GPG1 compatible only in the documentation of http://rdoc.info/github/ueno/ruby-gpgme/GPGME/Ctx#set_passphrase_callback-instance_method so that people don't waste their time trying to get it to work. I just happened to stumble upon this issue report and now understand why my code wasn't working for 2 days.

@ueno
Copy link
Owner

ueno commented Jun 6, 2013

@joekiller thanks, done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants