GNU bug report logs - #65316
29.1.50; EPA can falsely report "wrong passphrase" when decryption fails

Previous Next

Package: emacs;

Reported by: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>

Date: Tue, 15 Aug 2023 19:08:01 UTC

Severity: normal

Found in version 29.1.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 65316 in the body.
You can then email your comments to 65316 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#65316; Package emacs. (Tue, 15 Aug 2023 19:08:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 15 Aug 2023 19:08:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.1.50; EPA can falsely report "wrong passphrase" when decryption
 fails
Date: Tue, 15 Aug 2023 21:06:35 +0200
Placeholder to draw a bug number ... details and patch to follow.

--------------------------------------------------

In GNU Emacs 29.1.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version
 3.24.24, cairo version 1.16.0) of 2023-08-15 built on sappc2
Repository revision: 26949819df07cb36ed773cc9df6ca91f5f49e3d5
Repository branch: false-positives-from-epa--wrong-password-p
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure -C --with-native-compilation'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LC_COLLATE: POSIX
  value of $LC_TIME: POSIX
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65316; Package emacs. (Tue, 15 Aug 2023 19:50:04 GMT) Full text and rfc822 format available.

Message #8 received at 65316 <at> debbugs.gnu.org (full text, mbox):

From: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>
To: 65316 <at> debbugs.gnu.org
Subject: Re: 29.1.50; EPA can falsely report "wrong passphrase" when
 decryption fails
Date: Tue, 15 Aug 2023 21:49:07 +0200
[Message part 1 (text/plain, inline)]
Package: epa.el
Tags: patch

Repro Case:

# prepare a public-key-encrypted file test.gpg in cwd

# make pinentry executable non-executable
sudo chmod a-x /usr/bin/pinentry

emacs -Q

C-x C-f test.gpg RET

=> Wrong passphrase: No secret key

Where Emacs 27 would report in a separate *Error* buffer:

----------------------------------------
Error while decrypting with "/usr/bin/gpg":

gpg: encrypted with 3072-bit RSA key, ID D0EB77D91C0802D6, created 2022-12-03
      "test-key"
gpg: public key decryption failed: No pinentry
gpg: decryption failed: No secret key
----------------------------------------

The root cause is in function `epa--wrong-password-p', defined as
follows:

----------------------------------------
(defun epa--wrong-password-p (context)
  (let ((error-string (epg-context-error-output context)))
    (and (string-match
          "decryption failed: \\(Bad session key\\|No secret key\\)"
          error-string)
         (match-string 1 error-string))))
----------------------------------------

It should not search for "No secret key" but rather for "Bad
passphrase".  "No secret key" just means that there is no secret key
available to decrypt the file, "Bad passphrase" means that no secret
keys can be used because of a wrong passphrase.

I collected a couple of non-bad-passphrase error messages from GnuPG
decryption failures, all done with:

  [emacs-29]$ gpg --version
  gpg (GnuPG) 2.2.27
  libgcrypt 1.8.8

----------------------------------------
# public key, chmod a-x /usr/bin/pinentry
gpg: encrypted with 3072-bit RSA key, ID D0EB77D91C0802D6, created 2022-12-03
      "test-key"
gpg: public key decryption failed: No pinentry
gpg: decryption failed: No secret key

# symmetric, chmod a-x /usr/bin/pinentry
gpg: AES256.CFB encrypted data
gpg: problem with the agent: No pinentry
gpg: encrypted with 1 passphrase
gpg: decryption failed: No secret key

# public key, 0744 empty GnuPG home directory
gpg: WARNING: unsafe permissions on homedir '/home/jschmidt/work/emacs-29/xxx'
gpg: encrypted with RSA key, ID D0EB77D91C0802D6
gpg: decryption failed: No secret key

# public key, 0400 empty GnuPG home directory
gpg: failed to create temporary file '/home/jschmidt/work/emacs-29/xxx/.#lk0x00005571263a1230.sappc2.4974': Permission denied
gpg: keyblock resource '/home/jschmidt/work/emacs-29/xxx/pubring.kbx': Permission denied
gpg: encrypted with RSA key, ID D0EB77D91C0802D6
gpg: decryption failed: No secret key

# public key, 0700 empty GnuPG home directory
gpg: encrypted with RSA key, ID D0EB77D91C0802D6
gpg: decryption failed: No secret key
----------------------------------------

And here the real bad-passphrase messages:

----------------------------------------
# symmetric, bad passphrase entered
gpg: AES256.CFB encrypted data
gpg: encrypted with 1 passphrase
gpg: decryption failed: Bad session key

# public key, bad passphrase entered
gpg: encrypted with 3072-bit RSA key, ID D0EB77D91C0802D6, created 2022-12-03
      "test-key"
gpg: public key decryption failed: Bad passphrase
gpg: decryption failed: No secret key
----------------------------------------

Patch attached.
[0001-Avoid-false-wrong-passphrase-messages-in-EPA.patch (text/x-patch, attachment)]

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Thu, 17 Aug 2023 08:13:02 GMT) Full text and rfc822 format available.

Notification sent to Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>:
bug acknowledged by developer. (Thu, 17 Aug 2023 08:13:02 GMT) Full text and rfc822 format available.

Message #13 received at 65316-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>
Cc: 65316-done <at> debbugs.gnu.org
Subject: Re: bug#65316: 29.1.50;
 EPA can falsely report "wrong passphrase" when decryption fails
Date: Thu, 17 Aug 2023 11:12:18 +0300
> Date: Tue, 15 Aug 2023 21:49:07 +0200
> From:  Jens Schmidt via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> # prepare a public-key-encrypted file test.gpg in cwd
> 
> # make pinentry executable non-executable
> sudo chmod a-x /usr/bin/pinentry
> 
> emacs -Q
> 
> C-x C-f test.gpg RET
> 
> => Wrong passphrase: No secret key
> 
> Where Emacs 27 would report in a separate *Error* buffer:
> 
> ----------------------------------------
> Error while decrypting with "/usr/bin/gpg":
> 
> gpg: encrypted with 3072-bit RSA key, ID D0EB77D91C0802D6, created 2022-12-03
>       "test-key"
> gpg: public key decryption failed: No pinentry
> gpg: decryption failed: No secret key
> ----------------------------------------
> 
> The root cause is in function `epa--wrong-password-p', defined as
> follows:
> 
> ----------------------------------------
> (defun epa--wrong-password-p (context)
>   (let ((error-string (epg-context-error-output context)))
>     (and (string-match
>           "decryption failed: \\(Bad session key\\|No secret key\\)"
>           error-string)
>          (match-string 1 error-string))))
> ----------------------------------------
> 
> It should not search for "No secret key" but rather for "Bad
> passphrase".  "No secret key" just means that there is no secret key
> available to decrypt the file, "Bad passphrase" means that no secret
> keys can be used because of a wrong passphrase.
> 
> I collected a couple of non-bad-passphrase error messages from GnuPG
> decryption failures, all done with:
> 
>   [emacs-29]$ gpg --version
>   gpg (GnuPG) 2.2.27
>   libgcrypt 1.8.8
> 
> ----------------------------------------
> # public key, chmod a-x /usr/bin/pinentry
> gpg: encrypted with 3072-bit RSA key, ID D0EB77D91C0802D6, created 2022-12-03
>       "test-key"
> gpg: public key decryption failed: No pinentry
> gpg: decryption failed: No secret key
> 
> # symmetric, chmod a-x /usr/bin/pinentry
> gpg: AES256.CFB encrypted data
> gpg: problem with the agent: No pinentry
> gpg: encrypted with 1 passphrase
> gpg: decryption failed: No secret key
> 
> # public key, 0744 empty GnuPG home directory
> gpg: WARNING: unsafe permissions on homedir '/home/jschmidt/work/emacs-29/xxx'
> gpg: encrypted with RSA key, ID D0EB77D91C0802D6
> gpg: decryption failed: No secret key
> 
> # public key, 0400 empty GnuPG home directory
> gpg: failed to create temporary file '/home/jschmidt/work/emacs-29/xxx/.#lk0x00005571263a1230.sappc2.4974': Permission denied
> gpg: keyblock resource '/home/jschmidt/work/emacs-29/xxx/pubring.kbx': Permission denied
> gpg: encrypted with RSA key, ID D0EB77D91C0802D6
> gpg: decryption failed: No secret key
> 
> # public key, 0700 empty GnuPG home directory
> gpg: encrypted with RSA key, ID D0EB77D91C0802D6
> gpg: decryption failed: No secret key
> ----------------------------------------
> 
> And here the real bad-passphrase messages:
> 
> ----------------------------------------
> # symmetric, bad passphrase entered
> gpg: AES256.CFB encrypted data
> gpg: encrypted with 1 passphrase
> gpg: decryption failed: Bad session key
> 
> # public key, bad passphrase entered
> gpg: encrypted with 3072-bit RSA key, ID D0EB77D91C0802D6, created 2022-12-03
>       "test-key"
> gpg: public key decryption failed: Bad passphrase
> gpg: decryption failed: No secret key
> ----------------------------------------
> 
> Patch attached.

Thanks, installed on the emacs-29 branch, and closing the bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 14 Sep 2023 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 282 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.