From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/68204 Path: news.gmane.org!not-for-mail From: Daniel Dehennin Newsgroups: gmane.emacs.gnus.general Subject: mml2015-epg-sign do not use from header Date: Sun, 25 Jan 2009 21:11:37 +0100 Message-ID: <87k58jqh6u.fsf@hati.baby-gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1232914338 22749 80.91.229.12 (25 Jan 2009 20:12:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 Jan 2009 20:12:18 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M16645@lists.math.uh.edu Sun Jan 25 21:13:31 2009 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1LRBMG-0004xG-8w for ding-account@gmane.org; Sun, 25 Jan 2009 21:13:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1LRBKo-0003FA-RT; Sun, 25 Jan 2009 14:11:58 -0600 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1LRBKm-0003Eq-KF for ding@lists.math.uh.edu; Sun, 25 Jan 2009 14:11:56 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtp (Exim 4.69) (envelope-from ) id 1LRBKj-0001ED-RZ for ding@lists.math.uh.edu; Sun, 25 Jan 2009 14:11:56 -0600 Original-Received: from zion.asgardr.info ([82.233.222.74]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1LRBL1-0006rV-00 for ; Sun, 25 Jan 2009 21:12:11 +0100 Original-Received: from hati.asgardr.info ([192.168.1.2] helo=hati.baby-gnu.org) by zion.asgardr.info with esmtp (Exim 4.69) (envelope-from ) id 1LRBKV-0005IG-Aq for ding@gnus.org; Sun, 25 Jan 2009 21:11:39 +0100 User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) Organisation: Dark Church of Emacs X-Spam-Score: -1.7 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:68204 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, I'm using EasyPG backend to mml2015 and see that the from header is not used for mail siging. Looking at the code I see that the sender address is not used. I create 3 new functions and use them to simplify/correct mml2015-epg-sign and mml2015-epg-encrypt behavior. =20 Here is my changelog: * lisp/mml2015.el (mml2015-epg-split-addresses): Split a string of addresses delimited by "[ \f\t\n\r\v,]+". (mml2015-epg-prompt-select-key): Wrapper around epa-select-keys for prompting the keys to use. (mml2015-epg-choose-key): Choose keys for a certain usage for a list of names. Names are mail addresses used by epg to narrow selection. * lisp/mml2015.el (mml2015-epg-sign): Use sender for signing, get first address if From filed contains more that one. Change variable name to reflect the use of only one address for signin. Use mml2015-epg-choose-key. * lisp/mml2015.el (mml2015-epg-encrypt): Fetch one sender from (message-options-get 'message-sender). Fetch recipients from (message-options-get 'message-recipients). Use mml2015-epg-choose-key. Regards. =2D-=20 Daniel Dehennin R=C3=A9cup=C3=A9rer ma clef GPG: gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=mml2015.diff Content-Transfer-Encoding: quoted-printable Content-Description: Use from header for signing with epg =3D=3D=3D modified file 'lisp/mml2015.el' =2D-- lisp/mml2015.el 2009-01-22 07:02:15 +0000 +++ lisp/mml2015.el 2009-01-25 15:04:23 +0000 @@ -1025,6 +1025,82 @@ (setq pointer (cdr pointer)))) (setq keys (cdr keys))))) =20 +(defun mml2015-epg-split-addresses (config addresses) +"Split a string of addresses delimited by [ \f\t\n\r\v,]+." + (mapcar + (lambda (address) + (or (epg-expand-group config address) + (concat "<" address ">"))) + (split-string + (or addresses + (read-string "Addresses: ")) + "[ \f\t\n\r\v,]+"))) + +(defun mml2015-epg-prompt-select-key (context &optional name usage) +"Return a key matching NAME. +USAGE is nil or encrypt to search private keyring. +USAGE is t or sign to search secret keyring. +Mostly a wrapper around epa-select-keys." + (let ((action (cond + ((memq usage '(t sign)) "signing") + ((memq usage '(nil encrypt)) "encryption") + (t "encryption"))) + (key-type (cond + ((memq usage '(t sign)) 'secret) + ((memq usage '(nil encrypt)) 'public) + (t 'public))) + (no-selection (cond + ((memq usage '(t sign)) "default secret key is used") + ((memq usage '(nil encrypt)) "symmetric encryption will be performed") + (t "symmetric encryption will be performed")))) + (epa-select-keys context + (format "\ +Select a key for %s. +If no one is selected, %s +If more than one is select, first one is used. " + action no-selection) + name key-type))) + +(defun mml2015-epg-choose-key (context &optional names usage) +"Return a list of keys for each NAMES matching USAGE." + (let ((key-type (cond + ((memq usage '(t sign)) 'secret) + ((memq usage '(nil encrypt)) 'public) + (t 'public))) + (key-type-name (cond + ((memq usage '(t sign)) "secret") + ((memq usage '(nil encrypt)) "public") + (t "public"))) + signer-key) + (if names + (delq nil + (mapcar + (lambda (name) + (if (and + ;; Fail to fetch a key + (not (setq signer-key (or + ;; Does sender has keys ? + (and (epg-list-keys context name key-type) + (or (and (not mml2015-verbose) + (mml2015-epg-find-usable-key + (epg-list-keys context name key-type) + usage)) + (mml2015-epg-find-usable-key + (mml2015-epg-prompt-select-key context name usage) + usage))) + ;; Ask for what ever secret key we have in keyring + (mml2015-epg-find-usable-key + (mml2015-epg-prompt-select-key context nil usage) + usage)))) + ;; No key, ask for abortion + (y-or-n-p + (format + "No %s key selected for %s; abort? " + key-type name))) + (error "No %s key for %s: aborted." key-type-name name)) + signer-key) + names))))) + (defun mml2015-epg-decrypt (handle ctl) (catch 'error (let ((inhibit-redisplay t) @@ -1179,38 +1255,23 @@ (mml2015-extract-cleartext-signature)))) =20 (defun mml2015-epg-sign (cont) =2D (let* ((inhibit-redisplay t) + (let ((inhibit-redisplay t) (context (epg-make-context)) + (config (epg-configuration)) (boundary (mml-compute-boundary cont)) =2D signer-key =2D (signers =2D (or (message-options-get 'mml2015-epg-signers) =2D (message-options-set =2D 'mml2015-epg-signers =2D (if mml2015-verbose =2D (epa-select-keys context "\ =2DSelect keys for signing. =2DIf no one is selected, default secret key is used. " =2D mml2015-signers t) =2D (if mml2015-signers =2D (delq nil =2D (mapcar =2D (lambda (signer) =2D (setq signer-key (mml2015-epg-find-usable-key =2D (epg-list-keys context signer t) =2D 'sign)) =2D (unless (or signer-key =2D (y-or-n-p =2D (format =2D "No secret key for %s; skip it? " =2D signer))) =2D (error "No secret key for %s" signer)) =2D signer-key) =2D mml2015-signers))))))) =2D signature micalg) + sender signer signer-key signature micalg) + ;; Only one sender address + (setq sender (list (car (mml2015-epg-split-addresses=20 + config=20 + (message-options-get 'message-sender))))) + (setq signer (or=20 + (message-options-get 'mml2015-epg-signers) + (message-options-set + 'mml2015-epg-signers + (mml2015-epg-choose-key context sender 'sign)))) (epg-context-set-armor context t) (epg-context-set-textmode context t) =2D (epg-context-set-signers context signers) + (epg-context-set-signers context signer) (if mml2015-cache-passphrase (epg-context-set-passphrase-callback context @@ -1249,75 +1310,35 @@ (let ((inhibit-redisplay t) (context (epg-make-context)) (config (epg-configuration)) =2D (recipients (message-options-get 'mml2015-epg-recipients)) =2D cipher signers (boundary (mml-compute-boundary cont)) =2D recipient-key signer-key) + sender recipients signer cipher) + ;; Only one sender + (setq sender (list (car (mml2015-epg-split-addresses=20 + config + (message-options-get 'message-sender))))) + ;; All recipients + (setq recipients (mml2015-epg-split-addresses=20 + config + (message-options-get 'message-recipients))) +=20=20=20=20 + (when mml2015-encrypt-to-self + (if (not sender) + (error "Message sender not set")) + (setq recipients (nconc recipients sender))) + (setq recipients (or + (message-options-get 'mml2015-epg-recipients) + (message-options-set + 'mml2015-epg-recipients + (mml2015-epg-choose-key context recipients 'encrypt)))) (unless recipients =2D (setq recipients =2D (apply #'nconc =2D (mapcar =2D (lambda (recipient) =2D (or (epg-expand-group config recipient) =2D (list (concat "<" recipient ">")))) =2D (split-string =2D (or (message-options-get 'message-recipients) =2D (message-options-set 'message-recipients =2D (read-string "Recipients: "))) =2D "[ \f\t\n\r\v,]+")))) =2D (when mml2015-encrypt-to-self =2D (unless mml2015-signers =2D (error "mml2015-signers not set")) =2D (setq recipients (nconc recipients mml2015-signers))) =2D (if mml2015-verbose =2D (setq recipients =2D (epa-select-keys context "\ =2DSelect recipients for encryption. =2DIf no one is selected, symmetric encryption will be performed. " =2D recipients)) =2D (setq recipients =2D (delq nil =2D (mapcar =2D (lambda (recipient) =2D (setq recipient-key (mml2015-epg-find-usable-key =2D (epg-list-keys context recipient) =2D 'encrypt)) =2D (unless (or recipient-key =2D (y-or-n-p =2D (format "No public key for %s; skip it? " =2D recipient))) =2D (error "No public key for %s" recipient)) =2D recipient-key) =2D recipients))) =2D (unless recipients =2D (error "No recipient specified"))) =2D (message-options-set 'mml2015-epg-recipients recipients)) + (error "No recipient specified")) (when sign =2D (setq signers =2D (or (message-options-get 'mml2015-epg-signers) =2D (message-options-set =2D 'mml2015-epg-signers =2D (if mml2015-verbose =2D (epa-select-keys context "\ =2DSelect keys for signing. =2DIf no one is selected, default secret key is used. " =2D mml2015-signers t) =2D (if mml2015-signers =2D (delq nil =2D (mapcar =2D (lambda (signer) =2D (setq signer-key (mml2015-epg-find-usable-key =2D (epg-list-keys context signer t) =2D 'sign)) =2D (unless (or signer-key =2D (y-or-n-p =2D (format =2D "No secret key for %s; skip it? " =2D signer))) =2D (error "No secret key for %s" signer)) =2D signer-key) =2D mml2015-signers))))))) =2D (epg-context-set-signers context signers)) + (setq signer (or=20 + (message-options-get 'mml2015-epg-signers) + (message-options-set + 'mml2015-epg-signers + (mml2015-epg-choose-key context sender 'sign))))) + (epg-context-set-signers context signer) (epg-context-set-armor context t) (epg-context-set-textmode context t) (if mml2015-cache-passphrase --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAkl8x3kACgkQb97L6l6P4FuV2ACfTwsKFC2OjmoggBmLEA5g9Ycn Ii4AoIEQsgNKTHmgwDQ+8qRkTzPZ2kK+ =rAbx -----END PGP SIGNATURE----- --==-=-=--