Subject: [sup-devel] [PATCH v2] prefer gpg2 (GnuPG 2.x) over gpg (GnuPG 1.x)

From: Sascha Silbe <[email-masked]>
Date: Tue, 11 Jan 2011 19:59:43 +0100

Since 1.9.14 GnuPG can automatically start gpg-agent if it's not already
running (using a well-known socket location). When using GnuPG 1.x gpg-agent
needs to already be running at the time sup is started because the socket
location is random and passed via environment variables.

Autostarting gpg-agent is particularly convenient when using sup via ssh
as gpg-agent would need to be started manually (for local X sessions OTOH
it's often started automatically by distro scripts).

Signed-off-by: Sascha Silbe <[email-masked]>
---
 lib/sup/crypto.rb |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

v1->v2:
  fallback to gpg if gpg2 is not available

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 537745d..16ebaf9 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -25,9 +25,10 @@ EOS
   def initialize
     @mutex = Mutex.new

-    bin = `which gpg`.chomp
-    @cmd = case bin
-    when /\S/
+    @cmd = if (bin = `which gpg2`.chomp) =~ /\S/
+      debug "crypto: detected gpg binary in #{bin}"
+      "#{bin} --quiet --batch --no-verbose --logger-fd 1 --use-agent"
+    elsif (bin = `which gpg`.chomp) =~ /\S/
       debug "crypto: detected gpg binary in #{bin}"
       "#{bin} --quiet --batch --no-verbose --logger-fd 1 --use-agent"
     else
--
1.7.2.3

_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Gaudenz Steinlin <[email-masked]>
Date: Tue, 11 Jan 2011 21:20:12 +0100

> it's often started automatically by distro scripts).

AFAICS this change is not compatible with the rework of the GPG
handling done in the gpgme branch. I was under the impression (from
previous discussion on this list) that this branch is going to be
merged soon (at least into next).

Gaudenz

-- 
Ever tried. Ever failed. No matter.
Try again. Fail again. Fail better.
~ Samuel Beckett ~
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Ben Walton <[email-masked]>
Date: Tue, 11 Jan 2011 10:34:41 -0500

Excerpts from Sascha Silbe's message of Tue Jan 11 10:21:53 -0500 2011:

Hi Sascha,

> Since 1.9.14 GnuPG can automatically start gpg-agent if it's not
> already running (using a well-known socket location). When using
> GnuPG 1.x gpg-agent needs to already be running at the time sup is
> started because the socket location is random and passed via
> environment variables.

I like the intent of this patch, but at the very least, it should
determine if gpg2 is available and then fall back to gpg if it's not.

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302

---

From: Sascha Silbe <[email-masked]>
Date: Tue, 18 Jan 2011 19:20:21 +0100

v1->v2: rebase on next

 lib/sup/crypto.rb |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 02f14d0..f44efb3 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -48,6 +48,11 @@ EOS
     GPGME.check_version({:protocol => GPGME::PROTOCOL_OpenPGP})
     rescue NameError, GPGME::Error
       @gpgme_present = false
+      return
+    end
+
+    if (bin = `which gpg2`.chomp) =~ /\S/
+      GPGME.set_engine_info GPGME::PROTOCOL_OpenPGP, bin, nil
     end
   end
 
-- 
1.7.2.3

---

From: Sascha Silbe <[email-masked]>
Date: Tue, 11 Jan 2011 19:30:25 +0100

Excerpts from Alvaro Herrera's message of Tue Jan 11 16:45:09 +0100 2011:

> I think it should fall back to using `which gpg` in case gpg2 is not
> available.

Good point. Will post a new version.

Sascha

-- 
http://sascha.silbe.org/
http://www.infra-silbe.de/
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Sascha Silbe <[email-masked]>
Date: Tue, 11 Jan 2011 16:21:53 +0100

Autostarting gpg-agent is particularly convenient when using sup via ssh
as gpg-agent would need to be started manually otherwise (for local X
sessions OTOH it's often started automatically by distro scripts).

Signed-off-by: Sascha Silbe <[email-masked]>
---
 lib/sup/crypto.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

If there's anyone who would like to stick to GnuPG 1.x (the only advantage
is the smaller size of the binary), we might need to make this configurable
(or overridable via the gpg-args hook).

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 537745d..916f04c 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -25,7 +25,7 @@ EOS
   def initialize
     @mutex = Mutex.new

-    bin = `which gpg`.chomp
+    bin = `which gpg2`.chomp
     @cmd = case bin
     when /\S/
       debug "crypto: detected gpg binary in #{bin}"
--
1.7.2.3

---

From: Rich Lane <[email-masked]>
Date: Tue, 18 Jan 2011 22:37:34 -0500

Applied to master.

---

From: Alvaro Herrera <[email-masked]>
Date: Tue, 11 Jan 2011 12:45:09 -0300

-- 
Álvaro Herrera <[email-masked]>
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel