From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sebastian Fieber Newsgroups: gmane.emacs.bugs Subject: bug#40397: 28.0.50; epg decrypt does not verify signed content in smime encrypted and signed message Date: Thu, 23 Dec 2021 19:14:34 +0100 Message-ID: <87o8576ved.fsf@web.de> References: <87imih5am2.fsf@web.de> <87r1x4dujl.fsf@web.de> <87lfna22eh.fsf@web.de> <874ktxtr6d.fsf@web.de> <87d08lh0qa.fsf@gmail.com> <87wo6tayhy.fsf@web.de> <85r1x0mv6q.fsf@gmail.com> <87h7xv9k3x.fsf@web.de> <873655oaa5.fsf@gnus.org> <87bljsajvb.fsf@web.de> <87sgd4e011.fsf@gnus.org> <87fsw7ptc1.fsf_-_@gnus.org> <87y29zo81c.fsf@web.de> <874kcnnx5a.fsf@gnus.org> <878rwd3fyf.fsf@web.de> <87lf0cerm5.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28642"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 40397@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 23 19:15:31 2021 Return-path: 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 ) id 1n0Scl-0007J6-1k for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Dec 2021 19:15:31 +0100 Original-Received: from localhost ([::1]:35580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n0Scj-0001IN-MW for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Dec 2021 13:15:29 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:51360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n0ScN-0001Hr-5s for bug-gnu-emacs@gnu.org; Thu, 23 Dec 2021 13:15:08 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n0ScI-0001oO-6P for bug-gnu-emacs@gnu.org; Thu, 23 Dec 2021 13:15:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n0ScH-0000KW-Ue; Thu, 23 Dec 2021 13:15:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Sebastian Fieber Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bugs@gnus.org Resent-Date: Thu, 23 Dec 2021 18:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40397 X-GNU-PR-Package: emacs,gnus X-GNU-PR-Keywords: patch Original-Received: via spool by 40397-submit@debbugs.gnu.org id=B40397.16402832851231 (code B ref 40397); Thu, 23 Dec 2021 18:15:01 +0000 Original-Received: (at 40397) by debbugs.gnu.org; 23 Dec 2021 18:14:45 +0000 Original-Received: from localhost ([127.0.0.1]:34889 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n0Sc0-0000Jm-V2 for submit@debbugs.gnu.org; Thu, 23 Dec 2021 13:14:45 -0500 Original-Received: from mout.web.de ([212.227.17.11]:52835) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n0Sbx-0000JY-Qc for 40397@debbugs.gnu.org; Thu, 23 Dec 2021 13:14:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1640283275; bh=lCXFu4+jTbLpSiBqwc+wk+rPk8HePGzX5dCbWSJ3DqQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=BUtO/99kvhRN0ryiWkf/JceFLKixI/uZeoZ4TO4u0Xx8lastI+7+u794fstCe038B WnN+HQeYS9DBXLgbyrYmoqxGjMkzy0qYFRVA+b9OP6Qu/1dKZTVphNg5T5BDgCrcPb /vHTW3lGQO1pMsK5d4l6SP5SrVGtbsbuOYgz6sK0= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from comedian ([94.31.101.135]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MVJNd-1mrQ5M2Hg7-00SXpr; Thu, 23 Dec 2021 19:14:35 +0100 In-Reply-To: <87lf0cerm5.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 22 Dec 2021 13:44:34 +0100") X-Provags-ID: V03:K1:v4HmOlmFsjBGVRPldE4YDJI7X7xMe//3zgGQa/YrximcDjY5PHK kG/KaPIAZpcqCGsU/12rAAdS48AVvIX2dNN92DYKaQWC1JJi0oHsM38jJvB1BtOKZOG+8sC glgLQO4ndwmBQR17B8iokDCoOHYsMPWohLtMKEuZ4zGFd2/Wsw/HKAbgAxaWtQ3Wudl6Qb9 Pqfub8rPYcQN1ALslJC/A== X-UI-Out-Filterresults: notjunk:1;V03:K0:mtZNdTrTkzU=:yoRvK4TMOlNRa52+kdgTXv hIqyn4w8c+vSkE3TUxwP2/p0Smu4Qg6FpGIHL+QARyntGeSYVOysiEt5UDjQF9Wk1hKtfevVv SBnGvQ21YFOwQUf5YjDrGXxTr0PWfmS37wKfjRFa34qiSDolGTk2d7C7J8SGD8BMdiM5iVrTo USZSWx8V1neQhjsbPu+A8jixB+Sn1DFzIFv8aA555wGMhVGevn7fPetUrjAgXdbJGwohIOika PN+XYvk3P8E2SuK4PzqVBI3wJWzyY4I3V70rvLWNQ7+UfobveR+rE76FDG3IK1kdBBaMV97EQ gLB2JYO2K1WGC/UCDZENtFqUp9bEa8xiVFMd8b6YYR9JXvk8O9fkdcBralr2JlutClILtjbeM zj40DoP0t5EAB+3EjVS2jwfPubL87fovKeEfJU2WMldIP+thkaI3esnif2sQZ843BTxwC9Ftu i1oPwVH5uhSHxu4nN+yB9IBSOOeCa7wVXp/3qKHaE1aGWkBfeAyB69Jom2VN6rnkaYyNO1BBo AC9uvi3wygM4eId6yfp+FA4tY/O+uADUHdVEVIQhqQzIcRJ9b1ErOcmeYpl9DkZRkXFp2tdJW pAAsOLgU+ZNiCsp02sHchcCKgsnZTN6r41+vdw+fehJG73uG+0XIM+GHAVlbgDSY1K/HeQfyO 4FjpWj5ROyxbsuhx2DaTyngb79Uy94YmKJ4UnFrHYq2lRv84m+XhhvLcWBoqTrY/KeHLkUabf PhxWAolSKJk0hJw1Jqw3cQXJKU8Ej0O4FpbyJXcQqZv25DtaSUIzhoCO/EHMH5fcVOHHdDtn 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" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:222994 Archived-At: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 - --=-=-= Content-Type: text/plain On Mi, Dez 22 2021, Lars Ingebrigtsen wrote: > Still seems relevant to me, but the patch no longer applies due to other > changes in Gnus. Can you re-spin the patch for Emacs 29, and then I'll > get it committed. This one should apply :) - --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-fix-bug-40397.patch Content-Transfer-Encoding: quoted-printable From=203f85a1a72953f0877d2edcf56e872e7fe760b9f9 Mon Sep 17 00:00:00 2001 From: Sebastian Fieber Date: Mon, 6 Apr 2020 20:45:05 +0200 Subject: [PATCH] fix bug #40397 This fixes S/MIME encrypted AND signed mails where in the encrypted pkcs7 envelope is a signed pkcs7 structure. Also this patch enables proper security-buttons for pkcs7-mime encrypted and/or signed mails. Changes: =2D don't force Content-type header to text/plain in front of decrypted content for smime decryption using mm-view-pkcs7. This fixes the initial bug where the signed part was not verified due to the wrong content type header. =2D structure the result of mm-dissect-buffer of application/pkcs7-mime like a multipart mail so there is no loosing of information of verification and decryption results which can now be displayed by gnus-mime-display-security =2D adjust gnus-mime-display-part to handle application/pkcs7-mime like multipart/encrypted or multipart/signed =2D add dummy entries to mm-verify-function-alist and mm-decrypt-function-alist so gnus-mime-display-security correctly displays "S/MIME" and not "unknown protocol" =2D don't just check for multipart/signed in gnus-insert-mime-security-button but also for the pkcs7-mime mimetypes to print "Encrypted" or "Signed" accordingly in the security button =2D adjust mm-possibly-verify-or-decrypt to check for smime-type to ask wether to verify or decrypt the part and not to always ask to decrypt =2D adjust mm-view-pkcs7-decrypt and verify to call mm-sec-status so success information can be displayed by gnus-mime-display-security =2D in mm-view-pkcs7-verify also remove carriage returns like in mm-view-pkcs7-decrypt =2D adjust gnus-mime-security-verify-or-decrypt to handle pkcs7-mime right with the done changes TODO: mm-view-pkcs7-decrypt and verify error handling and reporting. ATM there is only the good case implemented - at least for reporting with gnus-mime-display-security. =2D-- lisp/gnus/gnus-art.el | 60 ++++++++++++++++++++++++++++--- lisp/gnus/mm-decode.el | 81 +++++++++++++++++++++++++++++++----------- lisp/gnus/mm-view.el | 25 +++++++++++-- 3 files changed, 138 insertions(+), 28 deletions(-) diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el index 6b9610d312..b130650df6 100644 =2D-- a/lisp/gnus/gnus-art.el +++ b/lisp/gnus/gnus-art.el @@ -5986,6 +5986,34 @@ gnus-mime-display-part ((equal (car handle) "multipart/encrypted") (gnus-add-wash-type 'encrypted) (gnus-mime-display-security handle)) + ;; pkcs7-mime handling: + ;; + ;; although not really multipart these are structured internally by + ;; mm-dissect-buffer like multipart to not discard the decryption + ;; and verification results + ;; + ;; application/pkcs7-mime + ((and (equal (car handle) "application/pkcs7-mime") + (equal (mm-handle-multipart-ctl-parameter handle 'protocol) + "application/pkcs7-mime_signed-data")) + (gnus-add-wash-type 'signed) + (gnus-mime-display-security handle)) + ((and (equal (car handle) "application/pkcs7-mime") + (equal (mm-handle-multipart-ctl-parameter handle 'protocol) + "application/pkcs7-mime_enveloped-data")) + (gnus-add-wash-type 'encrypted) + (gnus-mime-display-security handle)) + ;; application/x-pkcs7-mime + ((and (equal (car handle) "application/x-pkcs7-mime") + (equal (mm-handle-multipart-ctl-parameter handle 'protocol) + "application/x-pkcs7-mime_signed-data")) + (gnus-add-wash-type 'signed) + (gnus-mime-display-security handle)) + ((and (equal (car handle) "application/x-pkcs7-mime") + (equal (mm-handle-multipart-ctl-parameter handle 'protocol) + "application/x-pkcs7-mime_enveloped-data")) + (gnus-add-wash-type 'encrypted) + (gnus-mime-display-security handle)) ;; Other multiparts are handled like multipart/mixed. (t (gnus-mime-display-mixed (cdr handle))))) @@ -8733,9 +8761,16 @@ gnus-mime-security-verify-or-decrypt (with-current-buffer (mm-handle-multipart-original-buffer handle) (let* ((mm-verify-option 'known) (mm-decrypt-option 'known) =2D (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle))) + (pkcs7-mime-p (or (equal (car handle) "application/pkcs7-mime= ") + (equal (car handle) "application/x-pkcs7-mi= me"))) + (nparts (if pkcs7-mime-p + (list (mm-possibly-verify-or-decrypt (cadr handle= ) (cadadr handle))) + (mm-possibly-verify-or-decrypt (cdr handle) handle)= ))) (unless (eq nparts (cdr handle)) =2D (mm-destroy-parts (cdr handle)) + ;; if pkcs7-mime don't destroy the parts as the buffer in + ;; the cdr still needs to be accessible + (when (not pkcs7-mime-p) + (mm-destroy-parts (cdr handle))) (setcdr handle nparts)))) (gnus-mime-display-security handle) (when region @@ -8793,8 +8828,25 @@ gnus-insert-mime-security-button (or (nth 2 (assoc protocol mm-verify-function-alist)) (nth 2 (assoc protocol mm-decrypt-function-alist)) "Unknown") =2D (if (equal (car handle) "multipart/signed") =2D " Signed" " Encrypted") + (cond ((equal (car handle) "multipart/signed") " Signed") + ((equal (car handle) "multipart/encrypted") " Encrypted") + ((and (equal (car handle) "application/pkcs7-mime") + (equal (mm-handle-multipart-ctl-parameter handle 'p= rotocol) + "application/pkcs7-mime_signed-data")) + " Signed") + ((and (equal (car handle) "application/pkcs7-mime") + (equal (mm-handle-multipart-ctl-parameter handle 'p= rotocol) + "application/pkcs7-mime_enveloped-data")) + " Encrypted") + ;; application/x-pkcs7-mime + ((and (equal (car handle) "application/x-pkcs7-mime") + (equal (mm-handle-multipart-ctl-parameter handle 'p= rotocol) + "application/x-pkcs7-mime_signed-data")) + " Signed") + ((and (equal (car handle) "application/x-pkcs7-mime") + (equal (mm-handle-multipart-ctl-parameter handle 'p= rotocol) + "application/x-pkcs7-mime_enveloped-data")) + " Encrypted")) " Part")) (gnus-tmp-info (or (mm-handle-multipart-ctl-parameter handle 'gnus-info) diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el index 96695aabfd..da1a7c36a5 100644 =2D-- a/lisp/gnus/mm-decode.el +++ b/lisp/gnus/mm-decode.el @@ -473,6 +473,7 @@ mm-dissect-default-type (autoload 'mml2015-verify-test "mml2015") (autoload 'mml-smime-verify "mml-smime") (autoload 'mml-smime-verify-test "mml-smime") +(autoload 'mm-view-pkcs7-verify "mm-view") (defvar mm-verify-function-alist '(("application/pgp-signature" mml2015-verify "PGP" mml2015-verify-test) @@ -481,7 +482,15 @@ mm-verify-function-alist ("application/pkcs7-signature" mml-smime-verify "S/MIME" mml-smime-verify-test) ("application/x-pkcs7-signature" mml-smime-verify "S/MIME" =2D mml-smime-verify-test))) + mml-smime-verify-test) + ("application/x-pkcs7-signature" mml-smime-verify "S/MIME" + mml-smime-verify-test) + ;; these are only used for security-buttons and contain the + ;; smime-type after the underscore + ("application/pkcs7-mime_signed-data" mm-view-pkcs7-verify "S/MIME" + nil) + ("application/x-pkcs7-mime_signed-data" mml-view-pkcs7-verify "S/MIME" + nil))) (defcustom mm-verify-option 'never "Option of verifying signed parts. @@ -500,11 +509,16 @@ mm-verify-option (autoload 'mml2015-decrypt "mml2015") (autoload 'mml2015-decrypt-test "mml2015") +(autoload 'mm-view-pkcs7-decrypt "mm-view") (defvar mm-decrypt-function-alist '(("application/pgp-encrypted" mml2015-decrypt "PGP" mml2015-decrypt-tes= t) ("application/x-gnus-pgp-encrypted" mm-uu-pgp-encrypted-extract-1 "PGP" =2D mm-uu-pgp-encrypted-test))) + mm-uu-pgp-encrypted-test) + ;; these are only used for security-buttons and contain the + ;; smime-type after the underscore + ("application/pkcs7-mime_enveloped-data" mm-view-pkcs7-decrypt "S/MIME= " nil) + ("application/x-pkcs7-mime_enveloped-data" mm-view-pkcs7-decrypt "S/MI= ME" nil))) (defcustom mm-decrypt-option nil "Option of decrypting encrypted parts. @@ -682,14 +696,29 @@ mm-dissect-buffer (car ctl)) (cons (car ctl) (mm-dissect-multipart ctl from)))) (t =2D (mm-possibly-verify-or-decrypt =2D (mm-dissect-singlepart =2D ctl =2D (and cte (intern (downcase (mail-header-strip-cte cte)))) =2D no-strict-mime =2D (and cd (mail-header-parse-content-disposition cd)) =2D description id) =2D ctl from)))) + (let* ((handle + (mm-dissect-singlepart + ctl + (and cte (intern (downcase (mail-header-strip-cte cte))= )) + no-strict-mime + (and cd (mail-header-parse-content-disposition cd)) + description id)) + (intermediate-result (mm-possibly-verify-or-decrypt hand= le ctl from))) + (when (and (equal type "application") + (or (equal subtype "pkcs7-mime") + (equal subtype "x-pkcs7-mime"))) + (add-text-properties 0 + (length (car ctl)) + (list 'protocol + (concat (substring-no-properties= (car ctl)) + "_" + (cdr (assoc 'smime-type = ctl)))) + (car ctl)) + ;; if this is a pkcs7-mime lets treat this special and + ;; more like multipart so the pkcs7-mime part does not + ;; get ignored + (setq intermediate-result (cons (car ctl) (list intermediat= e-result)))) + intermediate-result)))) (when id (when (string-match " *<\\(.*\\)> *" id) (setq id (match-string 1 id))) @@ -1672,17 +1701,27 @@ mm-possibly-verify-or-decrypt (cond ((or (equal type "application/x-pkcs7-mime") (equal type "application/pkcs7-mime")) =2D (with-temp-buffer =2D (when (and (cond =2D ((eq mm-decrypt-option 'never) nil) =2D ((eq mm-decrypt-option 'always) t) =2D ((eq mm-decrypt-option 'known) t) =2D (t (y-or-n-p =2D (format "Decrypt (S/MIME) part? ")))) =2D (mm-view-pkcs7 parts from)) =2D (goto-char (point-min)) =2D (insert "Content-type: text/plain\n\n") =2D (setq parts (mm-dissect-buffer t))))) + (add-text-properties 0 (length (car ctl)) + (list 'buffer (car parts)) + (car ctl)) + (let* ((smime-type (cdr (assoc 'smime-type ctl))) + (envelope-p (string=3D smime-type "enveloped-data")) + (decrypt-or-sign-option (if envelope-p + mm-decrypt-option + mm-verify-option)) + (question (if envelope-p + "Decrypt (S/MIME) part? " + "Verify signed (S/MIME) part? "))) + (with-temp-buffer + (when (and (cond + ((eq decrypt-or-sign-option 'never) nil) + ((eq decrypt-or-sign-option 'always) t) + ((eq decrypt-or-sign-option 'known) t) + (t (y-or-n-p + (format question))))) + (mm-view-pkcs7 parts from) + (goto-char (point-min)) + (setq parts (mm-dissect-buffer t)))))) ((equal subtype "signed") (unless (and (setq protocol (mm-handle-multipart-ctl-parameter ctl 'protocol)) diff --git a/lisp/gnus/mm-view.el b/lisp/gnus/mm-view.el index 828ac633dc..34da9464ce 100644 =2D-- a/lisp/gnus/mm-view.el +++ b/lisp/gnus/mm-view.el @@ -591,8 +591,15 @@ mm-view-pkcs7-verify (with-temp-buffer (insert-buffer-substring (mm-handle-buffer handle)) (goto-char (point-min)) =2D (let ((part (base64-decode-string (buffer-string)))) =2D (epg-verify-string (epg-make-context 'CMS) part)))) + (let* ((part (base64-decode-string (buffer-string))) + (context (epg-make-context 'CMS)) + (plain (epg-verify-string context part))) + (mm-sec-status + 'gnus-info + (epg-verify-result-to-string (epg-context-result-for context= 'verify)) + 'gnus-details + nil) + plain))) (with-temp-buffer (insert "MIME-Version: 1.0\n") (mm-insert-headers "application/pkcs7-mime" "base64" "smime.p7m") @@ -601,6 +608,10 @@ mm-view-pkcs7-verify (if verified (insert verified) (insert-buffer-substring smime-details-buffer))) + (goto-char (point-min)) + (while (search-forward "\r\n" nil t) + (replace-match "\n")) + (goto-char (point-min)) t)) (autoload 'epg-decrypt-string "epg") @@ -612,7 +623,15 @@ mm-view-pkcs7-decrypt ;; Use EPG/gpgsm (let ((part (base64-decode-string (buffer-string)))) (erase-buffer) =2D (insert (epg-decrypt-string (epg-make-context 'CMS) part))) + (insert + (let* ((context (epg-make-context 'CMS)) + (plain (epg-decrypt-string context part))) + (mm-sec-status + 'gnus-info + "OK" + 'gnus-details + nil) + plain))) ;; Use openssl (insert "MIME-Version: 1.0\n") (mm-insert-headers "application/pkcs7-mime" "base64" "smime.p7m") =2D- 2.25.2 - --=-=-=-- -----BEGIN PGP SIGNATURE----- iQFMBAEBCAA2FiEExRi5b+8xM5Vpvu7L3jJw+EOyhogFAmHEvIoYHHNlYmFzdGlh bi5maWViZXJAd2ViLmRlAAoJEN4ycPhDsoaIkKkIAJ+tu42DlPifuSut5AlCdslt ecuVg2xg5xG5P64kxmLr7OcW0SnS+CaUEOj4tynxuVuMayUIKXNqmWJFHEpaQYUc rWbJ666P2IhyUIq1cb/hu7iJ3i7u2wHUns35WoqFC+bTI+O/zfmnpfVfBVvK6Xg0 W4TPePd6JiXyIrFGArusukQP6TZ6mn7vYNcETYWZ+UlBV/UgzQAc5LSx8eoFPXoi qkA6QLYI+TE2uGKbtzEBC7eqDF2HBnNbTOasrlJTVvEfIEd9IYBCXv6nEqvrITHg reYp75OTHSNop2ZI/fIQJLHWFb+KzOZBsrJ0rpnAOp8LYp7/p+iejigCNOmvEgA= =JY09 -----END PGP SIGNATURE-----