Bug#846953: [pkg-gnupg-maint] Bug#846953: gpg2 fails to decrypt with "No secret key" but gpg1 succeeds

2016-12-05 Thread Daniel Kahn Gillmor
Control: reassign 846953 gnupg-agent
Control: retitle 846953 gnupg-agent cannot deal with extremely large 
passphrase-encrypted keys
Control: forwarded 846953 https://bugs.gnupg.org/gnupg/issue2857

On Mon 2016-12-05 11:24:08 -0500, Daniel Kahn Gillmor wrote:
> on to the rest of it...
>
> do you have
> ~/.gnupg/private-keys-v1.d/DFE35C37A3C37A72BEE31A2E55252BA2A1EB0A2C.key
> ?
>
> is it (in)appropriately large compared to the other, smaller secret key
> material?
>
> (that path is derived from --with-keyrip, fwiw)
>
> can you try turning up the logging for gpg-agent (log-file and
> debug-level in ~/.gnupg/gpg-agent.conf, followed by restarting the
> agent) and see if it reports anything differently?
>
> Also, how did you generate such a large key?  gpg usually limits key
> generation to sane lengths.


OK, i'm now able to replicate the problem by making such a large key and
trying to use it with gpg-agent.  the key works fine as long as it has
no passphrase attached, but once i add a passphrase and try to use it,
gpg-agent crashes with:

2016-12-05 11:30:11 gpg-agent[24311] Fatal: out of core in secure memory while 
allocating 640 bytes
2016-12-05 11:30:11 gpg-agent[24311] socket file has been removed - shutting 
down

It'd be better to fail gracefully instead.

I'm attaching an encryption-capable 10240-bit RSA secret key (in OpenPGP
transferable secret key format, with passphrase "abc123") for use by
anyone who wants to test.  In a new GNUPGHOME, do:

gpg --batch --yes --import test-hugekey.key
echo test | gpg -r 861A97D02D4EE690A125DCC156CC9789743D4A89 --encrypt 
--armor --trust-model=always --batch --yes --output data.gpg
gpg --decrypt data.gpg

you'll note that the agent dies when doing that :/

I'm reassigning and retitling the bug to gnupg-agent, since that seems
to be where the problem lies.

I also noticed that upstream's https://bugs.gnupg.org/gnupg/issue2857 is
quite similar, so i'm marking this as "forwarded" there.

 --dkg



test-hugekey.key
Description: application/pgp-keys


signature.asc
Description: PGP signature


Bug#846953: [pkg-gnupg-maint] Bug#846953: gpg2 fails to decrypt with "No secret key" but gpg1 succeeds

2016-12-05 Thread Daniel Kahn Gillmor
On Mon 2016-12-05 09:40:38 -0500, Ryan Kavanagh wrote:
> I didn't have it set. Setting it now makes pinentry appear when I try to
> decrypt stdin (thanks!), but it unfortunately didn't fix the rest of the
> issue, e.g., I still can't decrypt files. (And I still can't decrypt
> stdin, though this is likely no longer due to lack of GPG_TTY).

cool, glad we got the passphrase-prompting bit sorted out.

on to the rest of it...

do you have
~/.gnupg/private-keys-v1.d/DFE35C37A3C37A72BEE31A2E55252BA2A1EB0A2C.key
?

is it (in)appropriately large compared to the other, smaller secret key
material?

(that path is derived from --with-keyrip, fwiw)

can you try turning up the logging for gpg-agent (log-file and
debug-level in ~/.gnupg/gpg-agent.conf, followed by restarting the
agent) and see if it reports anything differently?

Also, how did you generate such a large key?  gpg usually limits key
generation to sane lengths.

   --dkg


signature.asc
Description: PGP signature


Bug#846953: [pkg-gnupg-maint] Bug#846953: gpg2 fails to decrypt with "No secret key" but gpg1 succeeds

2016-12-05 Thread Ryan Kavanagh
Hi Daniel,

On Mon, Dec 05, 2016 at 09:20:09AM -0500, Daniel Kahn Gillmor wrote:
> > rak@zeta:~$ echo "ABC" | gpg -r$GPGKEY1 --encrypt | gpg --debug 8 --decrypt
> 
> do you have GPG_TTY set?  if not, can you retry the first command after
> having done:
> 
>GPG_TTY=$(tty)

I didn't have it set. Setting it now makes pinentry appear when I try to
decrypt stdin (thanks!), but it unfortunately didn't fix the rest of the
issue, e.g., I still can't decrypt files. (And I still can't decrypt
stdin, though this is likely no longer due to lack of GPG_TTY).

> if you set GPG_TTY then gpg will tell gpg-agent (which will tell
> pinentry-curses) which terminal it should prompt on.

I now get prompted for my passphrase by pinentry-curses on the current
terminal, and entering a bogus passphrase causes pinentry-curses
to complain about a bad passphrase. So there is some checking (hopefully
by gpg-agent!) of the passphrase somewhere along the line:

rak@zeta:/tmp$ killall gpg-agent
rak@zeta:/tmp$ export GPG_TTY=$(tty)
rak@zeta:/tmp$ echo "abc" | gpg -r$GPGKEY --encrypt > abc.gpg && gpg --decrypt 
abc.gpg

gpg: encrypted with 10240-bit RSA key, ID 20E0235B0F5E9C64, created 2009-09-24
  "Ryan Kavanagh "
gpg: public key decryption failed: End of file
gpg: decryption failed: No secret key
rak@zeta:/tmp$ echo "abc" | gpg -r$GPGKEY --encrypt | gpg --decrypt

gpg: encrypted with 10240-bit RSA key, ID 20E0235B0F5E9C64, created 2009-09-24
  "Ryan Kavanagh "
gpg: public key decryption failed: End of file
gpg: decryption failed: No secret key
rak@zeta:/tmp$ echo "abc" | gpg -r$GPGKEY --encrypt | gpg --decrypt

gpg: encrypted with 10240-bit RSA key, ID 20E0235B0F5E9C64, created 2009-09-24
  "Ryan Kavanagh "
gpg: public key decryption failed: Bad passphrase
gpg: decryption failed: No secret key
rak@zeta:/tmp$ env | grep GPG_TTY
GPG_TTY=/dev/pts/7

> Upstream tends to recommend setting GPG_TTY in your .bashrc.

Noted, thanks!

Best wishes,
Ryan

-- 
|_)|_/  Ryan Kavanagh  | GPG: 4E46 9519 ED67 7734 268F
| \| \  https://ryanak.ca/ |  BD95 8F7B F8FC 4A11 C97A


signature.asc
Description: PGP signature


Bug#846953: [pkg-gnupg-maint] Bug#846953: gpg2 fails to decrypt with "No secret key" but gpg1 succeeds

2016-12-05 Thread Daniel Kahn Gillmor
On Sun 2016-12-04 20:37:47 -0500, Ryan Kavanagh wrote:
> Guessing from the bug report and from the fact that
> ~/.gnupg/.gpg-v21-migrated is empty, the first command was supposed to
> be an rm on that file.

whoop, yes, you're right.

> rak@zeta:~$ echo "ABC" | gpg -r$GPGKEY1 --encrypt | gpg --debug 8 --decrypt
> gpg: reading options from '/home/rak/.gnupg/gpg.conf'
> gpg: enabled debug flags: filter
> gpg: encrypted with 2048-bit ELG key, ID 6C6FA7C974FCFC3F, created 2006-02-22
>   "Ryan Kavanagh (kubuntu.org email alias) "
> gpg: public key decryption failed: Inappropriate ioctl for device
 […]
> rak@zeta:~$ readlink -f $(which pinentry)
> /usr/bin/pinentry-curses
 […]
> rak@zeta:~$ echo "abc" > /tmp/abc && gpg --clearsign /tmp/abc
> gpg: using "8F7BF8FC4A11C97A" as default secret key for signing
> 
> rak@zeta:~$ gpg --verify /tmp/abc.asc
> gpg: Signature made Sun 04 Dec 2016 08:34:55 PM EST
> gpg:using RSA key 4E469519ED677734268FBD958F7BF8FC4A11C97A
> 

do you have GPG_TTY set?  if not, can you retry the first command after
having done:

   GPG_TTY=$(tty)

in the failed example, stdin of --decrypt is set to the incoming data
stream.

in the two successful examples, stdin is just the terminal's attached
stdin.

if you set GPG_TTY then gpg will tell gpg-agent (which will tell
pinentry-curses) which terminal it should prompt on.

Upstream tends to recommend setting GPG_TTY in your .bashrc.

I will say that this:

> gpg: public key decryption failed: Inappropriate ioctl for device
> gpg: decryption failed: No secret key

Is a very unclear set of error messages to give you a hint that this is
the case, though :/

   --dkg


signature.asc
Description: PGP signature


Bug#846953: [pkg-gnupg-maint] Bug#846953: gpg2 fails to decrypt with "No secret key" but gpg1 succeeds

2016-12-04 Thread Ryan Kavanagh
Hi Daniel,

On Sun, Dec 04, 2016 at 07:08:34PM -0500, Daniel Kahn Gillmor wrote:
> Please try:
> 
> ~/.gnupg/.gpg-v21-migrated
> gpg --list-secret-keys

Guessing from the bug report and from the fact that
~/.gnupg/.gpg-v21-migrated is empty, the first command was supposed to
be an rm on that file. It didn't work. I thought it might have something
to do with my stupidly big key size, but it doesn't work for my old
(reasonably sized) key either.

rak@zeta:~$ rm .gnupg/.gpg-v21-migrated
rak@zeta:~$ killall gpg-agent
rak@zeta:~$ ps aux | grep gpg-agent
rak347  0.0  0.0  12784   972 pts/5S+   20:29   0:00 grep gpg-agent
rak@zeta:~$ gpg --list-secret-keys
gpg: starting migration from earlier GnuPG versions
gpg: porting secret keys from '/home/rak/.gnupg/secring.gpg' to gpg-agent
gpg: key 7BD15207E95EDDC9: secret key imported
gpg: key 8F7BF8FC4A11C97A: secret key imported
gpg: key 5FA9C430B8F36FCA: secret key imported
gpg: migration succeeded

rak@zeta:~$ echo "ABC" | gpg -r$GPGKEY --encrypt | gpg --debug 8 --decrypt
gpg: reading options from '/home/rak/.gnupg/gpg.conf'
gpg: enabled debug flags: filter
gpg: encrypted with 10240-bit RSA key, ID 20E0235B0F5E9C64, created 2009-09-24
  "Ryan Kavanagh "
gpg: public key decryption failed: Inappropriate ioctl for device
gpg: decryption failed: No secret key
gpg: secmem usage: 0/65536 bytes in 0 blocks
rak@zeta:~$ echo "ABC" | gpg -r$GPGKEY1 --encrypt | gpg --debug 8 --decrypt
gpg: reading options from '/home/rak/.gnupg/gpg.conf'
gpg: enabled debug flags: filter
gpg: encrypted with 2048-bit ELG key, ID 6C6FA7C974FCFC3F, created 2006-02-22
  "Ryan Kavanagh (kubuntu.org email alias) "
gpg: public key decryption failed: Inappropriate ioctl for device
gpg: decryption failed: No secret key
gpg: secmem usage: 0/65536 bytes in 0 blocks

> If it doesn't work for you, please report back here, and let us know the
> output of:
> 
> readlink -f $(which pinentry)
> grep pinentry-program ~/.gnupg/gpg-agent.conf
> echo getinfo flavor | pinentry

rak@zeta:~$ readlink -f $(which pinentry)
/usr/bin/pinentry-curses
rak@zeta:~$ grep pinentry-program ~/.gnupg/gpg-agent.conf
grep: /home/rak/.gnupg/gpg-agent.conf: No such file or directory
rak@zeta:~$ echo getinfo flavor | pinentry
OK Pleased to meet you
D curses:curses
OK

I run gpg from a text-mode terminal. I would be surprised if it were a
pinentry problem, because I can successfully sign messages using
gpg2+pinentry, e.g.,

rak@zeta:~$ echo "abc" > /tmp/abc && gpg --clearsign /tmp/abc
gpg: using "8F7BF8FC4A11C97A" as default secret key for signing

rak@zeta:~$ gpg --verify /tmp/abc.asc
gpg: Signature made Sun 04 Dec 2016 08:34:55 PM EST
gpg:using RSA key 4E469519ED677734268FBD958F7BF8FC4A11C97A


Best wishes,
Ryan

-- 
|_)|_/  Ryan Kavanagh  | GPG: 4E46 9519 ED67 7734 268F
| \| \  https://ryanak.ca/ |  BD95 8F7B F8FC 4A11 C97A


signature.asc
Description: PGP signature


Bug#846953: [pkg-gnupg-maint] Bug#846953: gpg2 fails to decrypt with "No secret key" but gpg1 succeeds

2016-12-04 Thread Daniel Kahn Gillmor
Hi Ryan--

On Sun 2016-12-04 10:52:12 -0500, Ryan Kavanagh wrote:
> I'm unable to decrypt messages with gpg2, but can decrypt them with gpg1. See
> below for details. Please let me know if I can provide any further debugging
> information.

This sounds a lot like https://bugs.gnupg.org/gnupg/issue2811

Please try:

~/.gnupg/.gpg-v21-migrated
gpg --list-secret-keys

and then try the decryption again with gpg.

If this works for you, please report back here!

If it doesn't work for you, please report back here, and let us know the
output of:

readlink -f $(which pinentry)
grep pinentry-program ~/.gnupg/gpg-agent.conf
echo getinfo flavor | pinentry

and what context you're running gpg from: within a graphical session, in
a text-mode terminal, etc.

Thanks!

--dkg



signature.asc
Description: PGP signature


Bug#846953: gpg2 fails to decrypt with "No secret key" but gpg1 succeeds

2016-12-04 Thread Ryan Kavanagh
Package: gnupg
Version: 2.1.16-2
Severity: important

I'm unable to decrypt messages with gpg2, but can decrypt them with gpg1. See
below for details. Please let me know if I can provide any further debugging
information.

Best wishes,
Ryan

rak@zeta:~$ echo $GPGKEY
4A11C97A
rak@zeta:~$ echo "ABC" | gpg -r$GPGKEY --encrypt | gpg --debug 8 --decrypt
gpg: reading options from '/home/rak/.gnupg/gpg.conf'
gpg: enabled debug flags: filter
gpg: encrypted with 10240-bit RSA key, ID 20E0235B0F5E9C64, created 2009-09-24
  "Ryan Kavanagh "
gpg: public key decryption failed: Inappropriate ioctl for device
gpg: decryption failed: No secret key
gpg: secmem usage: 0/65536 bytes in 0 blocks
rak@zeta:~$ echo "ABC" | gpg -r$GPGKEY --encrypt | gpg1 --debug 8 --decrypt
gpg: reading options from `/home/rak/.gnupg/gpg.conf'

You need a passphrase to unlock the secret key for
user: "Ryan Kavanagh "
10240-bit RSA key, ID 0F5E9C64, created 2009-09-24 (main key ID 4A11C97A)

gpg: problem with the agent - disabling agent use
gpg: encrypted with 10240-bit RSA key, ID 0F5E9C64, created 2009-09-24
  "Ryan Kavanagh "
gpg: DBG: begin inflate: avail_in=0, avail_out=8192, inbuf=2048
gpg: DBG: enter inflate: avail_in=20, avail_out=8192
gpg: DBG: leave inflate: avail_in=0, avail_out=8180, zrc=1
gpg: DBG: do_uncompress: returning 12 bytes
ABC
secmem usage: 1600/35360 bytes in 3/35 blocks of pool 36832/65536
rak@zeta:~$ gpg --version
gpg (GnuPG) 2.1.16
libgcrypt 1.7.3-beta
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: /home/rak/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
rak@zeta:~$ gpg1 --version
gpg (GnuPG) 1.4.21
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
rak@zeta:~$

-- System Information:
Debian Release: stretch/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1, 
'experimental-debug'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.8.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8) (ignored: LC_ALL 
set to en_CA.UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages gnupg depends on:
ii  gnupg-agent2.1.16-2
ii  libassuan0 2.4.3-2
ii  libbz2-1.0 1.0.6-8
ii  libc6  2.24-7
ii  libgcrypt201.7.3-2
ii  libgpg-error0  1.25-1
ii  libksba8   1.3.5-2
ii  libreadline7   7.0-1
ii  libsqlite3-0   3.15.2-1
ii  zlib1g 1:1.2.8.dfsg-2+b3

Versions of packages gnupg recommends:
ii  dirmngr 2.1.16-2
pn  gnupg-l10n  

Versions of packages gnupg suggests:
pn  parcimonie  
pn  xloadimage  

-- no debconf information

-- 
|_)|_/  Ryan Kavanagh  | GPG: 4E46 9519 ED67 7734 268F
| \| \  https://ryanak.ca/ |  BD95 8F7B F8FC 4A11 C97A


signature.asc
Description: PGP signature