From 93452613f785fcbf39de30c806711d718b284d41 Mon Sep 17 00:00:00 2001 From: ueno Date: Sun, 23 Apr 2006 02:21:39 +0000 Subject: [PATCH] * mime-pgp.el (mime-verify-application/*-signature): New function. (mime-verify-application/pgp-signature): Abolished. (mime-verify-application/pkcs7-signature): Abolished. --- mime-edit.el | 5 ++--- mime-pgp.el | 69 ++++++++++++++++++--------------------------------------- semi-setup.el | 6 ++--- 3 files changed, 26 insertions(+), 54 deletions(-) diff --git a/mime-edit.el b/mime-edit.el index 70cfbed..d810941 100644 --- a/mime-edit.el +++ b/mime-edit.el @@ -1873,8 +1873,7 @@ If no one is selected, symmetric encryption will be performed. " ))))) (defun mime-edit-convert-lbt-string (string) - (let ((index 0) - (length (length string))) + (let ((index 0)) (while (setq index (string-match "\n" string index)) (setq string (replace-match "\r\n" nil nil string) index (+ index 2))) ;(length "\r\n") @@ -2377,7 +2376,7 @@ and insert data encoded as ENCODING." (mime-edit-insert-tag "application" "pgp-keys") (mime-edit-define-encoding "7bit") (let ((context (epg-make-context))) - (epg-context-set-armor t) + (epg-context-set-armor context t) (epg-export-keys-to-string context (epa-select-keys context "Select keys for export. "))) diff --git a/mime-pgp.el b/mime-pgp.el index bbaea2c..5709244 100644 --- a/mime-pgp.el +++ b/mime-pgp.el @@ -125,13 +125,7 @@ (set-window-buffer p-win preview-buffer))) -;;; @ Internal method for application/pgp-signature -;;; -;;; It is based on RFC 2015 (PGP/MIME) and -;;; draft-ietf-openpgp-mime-02.txt (OpenPGP/MIME). - -(defun mime-verify-application/pgp-signature (entity situation) - "Internal method to check PGP/MIME signature." +(defun mime-verify-application/*-signature (entity situation) (let* ((entity-node-id (mime-entity-node-id entity)) (mother (mime-entity-parent entity)) (knum (car entity-node-id)) @@ -139,7 +133,16 @@ (1- knum) (1+ knum))) (orig-entity (nth onum (mime-entity-children mother))) - (context (epg-make-context))) + (protocol (cdr (assoc "protocol" (mime-entity-parameters mother)))) + (context (epg-make-context + (if (equal protocol "application/pgp-signature") + 'OpenPGP + (if (string-match + "\\`application/\\(x-\\)?pkcs7-signature\\'" + protocol) + 'CMS + (error "Unknown protocol: %s" protocol))))) + verify-result) (epg-verify-string context (mime-entity-content entity) (with-temp-buffer @@ -150,9 +153,17 @@ (while (search-forward "\n" nil t) (replace-match "\r\n")) (buffer-substring))) + (setq verify-result + (mapcar (lambda (signature) + (unless (stringp (epg-signature-user-id signature)) + (setq signature (copy-sequence signature)) + (epg-signature-set-user-id + signature + (epg-decode-dn (epg-signature-user-id signature)))) + signature) + (epg-context-result-for context 'verify))) (message "%s" - (epg-verify-result-to-string - (epg-context-result-for context 'verify))))) + (epg-verify-result-to-string verify-result)))) ;;; @ Internal method for application/pgp-encrypted @@ -186,44 +197,6 @@ (epa-list-keys))) -;;; @ Internal method for application/pkcs7-signature -;;; -;;; It is based on the S/MIME user interface in Gnus. - -(defun mime-verify-application/pkcs7-signature (entity situation) - "Internal method to check S/MIME signature." - (let* ((entity-node-id (mime-entity-node-id entity)) - (mother (mime-entity-parent entity)) - (knum (car entity-node-id)) - (onum (if (> knum 0) - (1- knum) - (1+ knum))) - (orig-entity (nth onum (mime-entity-children mother))) - (context (epg-make-context 'CMS)) - verify-result) - (epg-verify-string context - (mime-entity-content entity) - (with-temp-buffer - (if (fboundp 'set-buffer-multibyte) - (set-buffer-multibyte nil)) - (mime-insert-entity orig-entity) - (goto-char (point-min)) - (while (search-forward "\n" nil t) - (replace-match "\r\n")) - (buffer-substring))) - (setq verify-result - (mapcar (lambda (signature) - (unless (stringp (epg-signature-user-id signature)) - (setq signature (copy-sequence signature)) - (epg-signature-set-user-id - signature - (epg-decode-dn (epg-signature-user-id signature)))) - signature) - (epg-context-result-for context 'verify))) - (message "%s" - (epg-verify-result-to-string verify-result)))) - - ;;; @ Internal method for application/pkcs7-mime ;;; ;;; It is based on RFC 2633 (S/MIME version 3). diff --git a/semi-setup.el b/semi-setup.el index 7a3aa11..ada262c 100644 --- a/semi-setup.el +++ b/semi-setup.el @@ -98,7 +98,7 @@ (mime-add-condition 'action '((type . application)(subtype . pgp-signature) - (method . mime-verify-application/pgp-signature)) + (method . mime-verify-application/*-signature)) 'strict "mime-pgp") (mime-add-condition @@ -116,13 +116,13 @@ (mime-add-condition 'action '((type . application)(subtype . pkcs7-signature) - (method . mime-verify-application/pkcs7-signature)) + (method . mime-verify-application/*-signature)) 'strict "mime-pgp") (mime-add-condition 'action '((type . application)(subtype . x-pkcs7-signature) - (method . mime-verify-application/pkcs7-signature)) + (method . mime-verify-application/*-signature)) 'strict "mime-pgp") (mime-add-condition -- 1.7.10.4