From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Ulrich Mueller <ulm@gentoo.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#67012: 29.1;
 epa-sign-file pinentry loopback mode does not work with S/MIME
Date: Thu, 09 Nov 2023 07:56:47 +0100
Message-ID: <u4jhvqus0@gentoo.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="35967"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Gnus/5.13 (Gnus v5.13)
To: 67012@debbugs.gnu.org
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 09 07:57:54 2023
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1r0yzB-000973-UZ
	for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 Nov 2023 07:57:54 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1r0yyk-00060s-BH; Thu, 09 Nov 2023 01:57:26 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1r0yyi-00060R-Km
 for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 01:57:24 -0500
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1r0yyi-0000Bf-Cp
 for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 01:57:24 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1r0yzK-00041t-Ja
 for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 01:58:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Ulrich Mueller <ulm@gentoo.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Thu, 09 Nov 2023 06:58:02 +0000
Resent-Message-ID: <handler.67012.B.169951307615474@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 67012
X-GNU-PR-Package: emacs
X-Debbugs-Original-To: bug-gnu-emacs@gnu.org
Original-Received: via spool by submit@debbugs.gnu.org id=B.169951307615474
 (code B ref -1); Thu, 09 Nov 2023 06:58:02 +0000
Original-Received: (at submit) by debbugs.gnu.org; 9 Nov 2023 06:57:56 +0000
Original-Received: from localhost ([127.0.0.1]:46692 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1r0yzD-00041W-M9
 for submit@debbugs.gnu.org; Thu, 09 Nov 2023 01:57:56 -0500
Original-Received: from lists.gnu.org ([2001:470:142::17]:41004)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ulm@gentoo.org>) id 1r0yz9-00041G-U3
 for submit@debbugs.gnu.org; Thu, 09 Nov 2023 01:57:54 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <ulm@gentoo.org>) id 1r0yyQ-0005zg-Dr
 for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 01:57:06 -0500
Original-Received: from woodpecker.gentoo.org ([140.211.166.183] helo=smtp.gentoo.org)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256)
 (Exim 4.90_1) (envelope-from <ulm@gentoo.org>) id 1r0yyM-00008z-Py
 for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 01:57:05 -0500
Received-SPF: pass client-ip=140.211.166.183; envelope-from=ulm@gentoo.org;
 helo=smtp.gentoo.org
X-Spam_score_int: -41
X-Spam_score: -4.2
X-Spam_bar: ----
X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3,
 RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:274031
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/274031>

I was originally trying to sign e-mail messages with S/MIME using
mml-secure-sign-smime followed by message-send, which fails when I
customize epg-pinentry-mode as loopback.

The problem also occurs with epa-sign-file, which is easier to reproduce
(because it doesn't need as much configuration). So I am reporting the
bug for this command.

To reproduce, emacs -Q, then execute in the *scratch* buffer:

   (write-region "hello\n" nil "hello.txt")
   (require 'epa)

   (let ((epg-pinentry-mode 'loopback)
         (epa-protocol 'CMS))
     (epa-sign-file
      "hello.txt"
      (epa-select-keys (epg-make-context epa-protocol) "Key:" nil t)
      'normal))

This asks interactively to select a key. After doing so, it fails with
the following error (shown in an "*Error* (EPA Info)" buffer):

   Error while signing with "/usr/bin/gpgsm":

   gpgsm: ignoring gpg-agent inquiry 'PASSPHRASE'
   gpgsm: error creating signature: No passphrase given <GPG Agent>

Debugger *Backtrace* (key IDs x-ed out):

   Debugger entered--Lisp error: (epg-error "Sign failed" "")
     signal(epg-error ("Sign failed" ""))
     epa-sign-file("hello.txt" (#s(epg-key :owner-trust nil :sub-key-list (=
#s(epg-sub-key :validity nil :capability (encrypt sign) :secret-p nil :algo=
rithm 1 :length 4096 :id "XXXXXXXXXXXXXXXX" :creation-time 20231107 :expira=
tion-time 20251106 :fingerprint "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")=
) :user-id-list (#s(epg-user-id :validity nil :string (("CN" . "Ulrich M=C3=
=BCller") ("OU" . "Institut fuer Kernphysik") ("O" . "Johannes Gutenberg-Un=
iversitaet Mainz") ("L" . "Mainz") ("ST" . "Rheinland-Pfalz") ("C" . "DE"))=
 :signature-list nil) #s(epg-user-id :validity nil :string "<ulm@uni-mainz.=
de>" :signature-list nil)))) normal)
     (let ((epg-pinentry-mode 'loopback) (epa-protocol 'CMS)) (epa-sign-fil=
e "hello.txt" (epa-select-keys (epg-make-context epa-protocol) "Key:" nil t=
) 'normal))
     (progn (let ((epg-pinentry-mode 'loopback) (epa-protocol 'CMS)) (epa-s=
ign-file "hello.txt" (epa-select-keys (epg-make-context epa-protocol) "Key:=
" nil t) 'normal)))
     eval((progn (let ((epg-pinentry-mode 'loopback) (epa-protocol 'CMS)) (=
epa-sign-file "hello.txt" (epa-select-keys (epg-make-context epa-protocol) =
"Key:" nil t) 'normal))) t)
     elisp--eval-last-sexp(t)
     eval-last-sexp(t)
     eval-print-last-sexp(nil)
     funcall-interactively(eval-print-last-sexp nil)
     call-interactively(eval-print-last-sexp nil nil)
     command-execute(eval-print-last-sexp)

When I change epg-pinentry-mode to ask or epa-protocol to OpenPGP in
the let-binding, things work as expected. In other words, only the
combination of S/MIME and pinentry loopback fails.

   |          | OpenPGP | CMS   |
   |----------+---------+-------|
   | ask      | works   | works |
   | loopback | works   | fails |

I use pinentry-gnome3, in case this should matter:

   $ readlink /usr/bin/pinentry
   pinentry-gnome3


In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.18.0) of 2023-10-24 built on localhost
Windowing system distributor 'The X.Org Foundation', version 11.0.12101009
System Description: Gentoo Linux

Configured using:
 'configure --prefix=3D/usr --build=3Dx86_64-pc-linux-gnu
 --host=3Dx86_64-pc-linux-gnu --mandir=3D/usr/share/man
 --infodir=3D/usr/share/info --datadir=3D/usr/share --sysconfdir=3D/etc
 --localstatedir=3D/var/lib --datarootdir=3D/usr/share
 --disable-silent-rules --docdir=3D/usr/share/doc/emacs-29.1-r5
 --htmldir=3D/usr/share/doc/emacs-29.1-r5/html --libdir=3D/usr/lib64
 --program-suffix=3D-emacs-29 --includedir=3D/usr/include/emacs-29
 --infodir=3D/usr/share/info/emacs-29 --localstatedir=3D/var
 --enable-locallisppath=3D/etc/emacs:/usr/share/emacs/site-lisp
 --without-compress-install --without-hesiod --without-pop
 --with-file-notification=3Dinotify --with-pdumper --enable-acl
 --with-dbus --with-modules --with-gameuser=3D:gamestat --with-libgmp
 --with-gpm --without-native-compilation --without-json
 --without-kerberos --without-kerberos5 --with-lcms2 --with-xml2
 --without-mailutils --without-selinux --with-small-ja-dic
 --without-sqlite3 --with-gnutls --without-libsystemd --with-threads
 --without-tree-sitter --without-wide-int --with-sound=3Dalsa --with-zlib
 --with-x --without-pgtk --without-ns --without-gconf --with-gsettings
 --without-toolkit-scroll-bars --with-xpm --with-xft --with-cairo
 --with-harfbuzz --with-libotf --with-m17n-flt --with-x-toolkit=3Dlucid
 --with-xaw3d --with-gif --with-jpeg --with-png --with-rsvg --with-tiff
 --without-webp --with-imagemagick --with-dumping=3Dpdumper
 'CFLAGS=3D-march=3Dnative -ggdb -O2 -pipe' 'LDFLAGS=3D-Wl,-O1
 -Wl,--as-needed''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ
IMAGEMAGICK JPEG LCMS2 LIBOTF LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY
PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF X11 XAW3D XDBE XIM XINPUT2
XPM LUCID ZLIB

Important settings:
  value of $LC_CTYPE: en_GB.UTF-8
  value of $LC_TIME: en_GB.UTF-8
  value of $LANG: POSIX
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug org-element org-persist org-id
org-refile avl-tree generator oc-basic ol-eww eww xdg url-queue mm-url
ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect gnus-art mm-uu mml2015
mm-view mml-smime smime gnutls dig gnus-sum shr pixel-fill kinsoku
url-file svg dom browse-url url url-proxy url-privacy url-expand
url-methods url-history url-cookie generate-lisp-file url-domsuf
url-util url-parse auth-source cl-seq eieio eieio-core cl-macs json map
url-vars gnus-group gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud
nnimap nnmail mail-source utf7 nnoo parse-time gnus-spec gnus-int
gnus-range message sendmail mailcap yank-media puny rfc822 mml mml-sec
password-cache mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047
rfc2045 ietf-drums mailabbrev gmm-utils mailheader gnus-win gnus
nnheader gnus-util mail-utils range mm-util mail-prsvr wid-edit
ol-docview doc-view filenotify jka-compr image-mode exif dired
dired-loaddefs ol-bibtex bibtex iso8601 ol-bbdb ol-w3m ol-doi
org-link-doi org ob ob-tangle ob-ref ob-lob ob-table ob-exp org-macro
org-src ob-comint org-pcomplete pcomplete comint ansi-osc ansi-color
ring org-list org-footnote org-faces org-entities noutline outline icons
ob-emacs-lisp ob-core ob-eval org-cycle org-table ol rx org-fold
org-fold-core org-keys oc org-loaddefs cal-menu calendar cal-loaddefs
org-version org-compat org-macs format-spec misearch multi-isearch
epa-file thingatpt shortdoc text-property-search cl-extra help-fns
radix-tree cl-print byte-opt gv bytecomp byte-compile debug backtrace
help-mode find-func time-date subr-x cl-loaddefs cl-lib epa derived epg
rfc6068 epg-config rmc iso-transl tooltip cconv eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo x-toolkit
xinput2 x multi-tty make-network-process emacs)

Memory information:
((conses 16 251336 23421)
 (symbols 48 19880 0)
 (strings 32 72160 3511)
 (string-bytes 1 2156491)
 (vectors 16 36926)
 (vector-slots 8 414217 18678)
 (floats 8 337 164)
 (intervals 56 2847 255)
 (buffers 976 16))