Skip to content

Instantly share code, notes, and snippets.

@ay
Created May 3, 2016 08:06
Show Gist options
  • Save ay/ab2ecb0a8af6a1409cfcd27f29c453e3 to your computer and use it in GitHub Desktop.
Save ay/ab2ecb0a8af6a1409cfcd27f29c453e3 to your computer and use it in GitHub Desktop.
A patched Homebrew formula for GnuPG 2.1.11. This includes the patch for https://bugs.gnupg.org/gnupg/issue2229 from commit acac103: http://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=patch;h=acac103ba5772ae738ce5409d17feab80596cde6
class Gnupg21 < Formula
desc "GNU Privacy Guard: a free PGP replacement"
homepage "https://www.gnupg.org/"
url "https://gnupg.org/ftp/gcrypt/gnupg/gnupg-2.1.11.tar.bz2"
mirror "https://www.mirrorservice.org/sites/ftp.gnupg.org/gcrypt/gnupg/gnupg-2.1.11.tar.bz2"
sha256 "b7b0fb2c8c5d47d7ec916d4a1097c0ddcb94a12bb1c0ac424ad86b1ee316b61a"
bottle do
sha256 "725cb9cebd07ca0ab9ea56a5742c765b77f0eed17f7c4428b575c40eea35ac8b" => :el_capitan
sha256 "a699c10bc5324df5b88cd1612b7aa9c4b841986d7438eed542a4b59816cf41e2" => :yosemite
sha256 "8c43114c858a4975c0fd1b3b52703e2be6b4ac2d8a40fb89dd9366db425b39a0" => :mavericks
end
head do
url "git://git.gnupg.org/gnupg.git"
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
end
option "with-gpgsplit", "Additionally install the gpgsplit utility"
depends_on "pkg-config" => :build
depends_on "sqlite" => :build if MacOS.version == :mavericks
depends_on "npth"
depends_on "gnutls"
depends_on "libgpg-error"
depends_on "libgcrypt"
depends_on "libksba"
depends_on "libassuan"
depends_on "pinentry"
depends_on "gettext"
depends_on "adns"
depends_on "libusb-compat" => :recommended
depends_on "readline" => :optional
depends_on "homebrew/fuse/encfs" => :optional
conflicts_with "gnupg2",
:because => "GPG2.1.x is incompatible with the 2.0.x branch."
conflicts_with "gpg-agent",
:because => "GPG2.1.x ships an internal gpg-agent which it must use."
conflicts_with "dirmngr",
:because => "GPG2.1.x ships an internal dirmngr which it it must use."
conflicts_with "fwknop",
:because => "fwknop expects to use a `gpgme` with Homebrew/Homebrew's gnupg2."
conflicts_with "gpgme",
:because => "gpgme currently requires 1.x.x or 2.0.x."
# Fixes a bug that may cause `make check` to fail
# See https://bugs.gnupg.org/gnupg/issue2229
patch :DATA
def install
(var/"run").mkpath
ENV.append "LDFLAGS", "-lresolv"
ENV["gl_cv_absolute_stdint_h"] = "#{MacOS.sdk_path}/usr/include/stdint.h"
args = %W[
--disable-dependency-tracking
--disable-silent-rules
--prefix=#{prefix}
--sbindir=#{bin}
--sysconfdir=#{etc}
--enable-symcryptrun
--with-pinentry-pgm=#{Formula["pinentry"].opt_bin}/pinentry
]
args << "--with-readline=#{Formula["readline"].opt_prefix}" if build.with? "readline"
if build.head?
args << "--enable-maintainer-mode"
system "./autogen.sh", "--force"
system "automake", "--add-missing"
end
# Adjust package name to fit our scheme of packaging both gnupg 1.x and
# and 2.1.x and gpg-agent separately.
inreplace "configure" do |s|
s.gsub! "PACKAGE_NAME='gnupg'", "PACKAGE_NAME='gnupg2'"
s.gsub! "PACKAGE_TARNAME='gnupg'", "PACKAGE_TARNAME='gnupg2'"
end
system "./configure", *args
system "make"
system "make", "check"
system "make", "install"
bin.install "tools/gpgsplit" => "gpgsplit2" if build.with? "gpgsplit"
# Move man files that conflict with 1.x.
mv share/"doc/gnupg2/FAQ", share/"doc/gnupg2/FAQ21"
mv share/"doc/gnupg2/examples/gpgconf.conf", share/"doc/gnupg2/examples/gpgconf21.conf"
mv share/"info/gnupg.info", share/"info/gnupg21.info"
mv man7/"gnupg.7", man7/"gnupg21.7"
end
def caveats; <<-EOS.undent
Once you run the new gpg2 binary you will find it incredibly
difficult to go back to using `gnupg2` from Homebrew/Homebrew.
The new 2.1.x moves to a new keychain format that can't be
and won't be understood by the 2.0.x branch or lower.
If you use this `gnupg21` formula for a while and decide
you don't like it, you will lose the keys you've imported since.
For this reason, we strongly advise that you make a backup
of your `~/.gnupg` directory.
For full details of the changes, please visit:
https://www.gnupg.org/faq/whats-new-in-2.1.html
If you are upgrading to gnupg21 from gnupg2 you should execute:
`killall gpg-agent && gpg-agent --daemon`
After install. See:
https://github.com/Homebrew/homebrew-versions/issues/681
EOS
end
test do
system "#{bin}/gpgconf"
end
end
__END__
diff --git a/common/simple-pwquery.c b/common/simple-pwquery.c
index 90d04c0..b2d666c 100644
--- a/common/simple-pwquery.c
+++ b/common/simple-pwquery.c
@@ -618,6 +618,7 @@ simple_query (const char *query)
int fd = -1;
int nread;
char response[500];
+ int have = 0;
int rc;
rc = agent_open (&fd);
@@ -628,40 +629,78 @@ simple_query (const char *query)
if (rc)
goto leave;
- /* get response */
- nread = readline (fd, response, 499);
- if (nread < 0)
- {
- rc = -nread;
- goto leave;
- }
- if (nread < 3)
+ while (1)
{
- rc = SPWQ_PROTOCOL_ERROR;
- goto leave;
- }
+ if (! have || ! strchr (response, '\n'))
+ /* get response */
+ {
+ nread = readline (fd, &response[have],
+ sizeof (response) - 1 /* NUL */ - have);
+ if (nread < 0)
+ {
+ rc = -nread;
+ goto leave;
+ }
+ have += nread;
+ if (have < 3)
+ {
+ rc = SPWQ_PROTOCOL_ERROR;
+ goto leave;
+ }
+ response[have] = 0;
+ }
- if (response[0] == 'O' && response[1] == 'K')
- /* OK, do nothing. */;
- else if ((nread > 7 && !memcmp (response, "ERR 111", 7)
- && (response[7] == ' ' || response[7] == '\n') )
- || ((nread > 4 && !memcmp (response, "ERR ", 4)
- && (strtoul (response+4, NULL, 0) & 0xffff) == 99)) )
- {
- /* 111 is the old Assuan code for canceled which might still
- be in use by old installations. 99 is GPG_ERR_CANCELED as
- used by modern gpg-agents; 0xffff is used to mask out the
- error source. */
+ if (response[0] == 'O' && response[1] == 'K')
+ /* OK, do nothing. */;
+ else if ((nread > 7 && !memcmp (response, "ERR 111", 7)
+ && (response[7] == ' ' || response[7] == '\n') )
+ || ((nread > 4 && !memcmp (response, "ERR ", 4)
+ && (strtoul (response+4, NULL, 0) & 0xffff) == 99)) )
+ {
+ /* 111 is the old Assuan code for canceled which might still
+ be in use by old installations. 99 is GPG_ERR_CANCELED as
+ used by modern gpg-agents; 0xffff is used to mask out the
+ error source. */
#ifdef SPWQ_USE_LOGGING
- log_info (_("canceled by user\n") );
+ log_info (_("canceled by user\n") );
#endif
- }
- else
- {
+ }
+ else if (response[0] == 'S' && response[1] == ' ')
+ {
+ char *nextline;
+ int consumed;
+
+ nextline = strchr (response, '\n');
+ if (! nextline)
+ /* Point to the NUL. */
+ nextline = &response[have];
+ else
+ /* Move past the \n. */
+ nextline ++;
+
+ consumed = (size_t) nextline - (size_t) response;
+
+ /* Skip any additional newlines. */
+ while (consumed < have && response[consumed] == '\n')
+ consumed ++;
+
+ have -= consumed;
+
+ if (have)
+ memmove (response, &response[consumed], have + 1);
+
+ continue;
+ }
+ else
+ {
#ifdef SPWQ_USE_LOGGING
- log_error (_("problem with the agent\n"));
+ log_error (_("problem with the agent (unexpected response \"%s\"\n"),
+ response);
#endif
- rc = SPWQ_ERR_RESPONSE;
+ rc = SPWQ_ERR_RESPONSE;
+ }
+
+ break;
}
leave:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment