From: ueno Date: Thu, 20 Apr 2006 03:31:26 +0000 (+0000) Subject: * mime-pgp.el: Require 'epg. X-Git-Tag: emiko-1_14_1-epg-0_0_1~9 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=304098ff54ffac983b90be924bc1e92393cc8233;p=elisp%2Fsemi.git * mime-pgp.el: Require 'epg. (mime-view-application/pgp): Use EasyPG. (mime-verify-application/pgp-signature): Ditto. (mime-add-application/pgp-keys): Ditto. * mime-edit.el: Require 'epa. (mime-edit-user-agent-value): Added EasyPG version number. (mime-edit-sign-pgp-mime): Use EasyPG. (mime-edit-encrypt-pgp-mime): Ditto. (mime-edit-sign-pgp-kazu): Ditto. (mime-edit-encrypt-pgp-kazu): Ditto. (mime-edit-insert-key): Ditto. (mime-edit-decode-multipart-in-buffer): Ditto. --- diff --git a/ChangeLog b/ChangeLog index 17d3e77..d50035f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2006-04-20 Daiki Ueno + + * mime-pgp.el: Require 'epg. + (mime-view-application/pgp): Use EasyPG. + (mime-verify-application/pgp-signature): Ditto. + (mime-add-application/pgp-keys): Ditto. + + * mime-edit.el: Require 'epa. + (mime-edit-user-agent-value): Added EasyPG version number. + (mime-edit-sign-pgp-mime): Use EasyPG. + (mime-edit-encrypt-pgp-mime): Ditto. + (mime-edit-sign-pgp-kazu): Ditto. + (mime-edit-encrypt-pgp-kazu): Ditto. + (mime-edit-insert-key): Ditto. + (mime-edit-decode-multipart-in-buffer): Ditto. + 2006-02-18 TAKAHASHI Kaoru * mime-edit.el (mime-edit-delete-trailing-whitespace): New diff --git a/mime-edit.el b/mime-edit.el index 816cd3b..f21e16a 100644 --- a/mime-edit.el +++ b/mime-edit.el @@ -113,15 +113,8 @@ (require 'mime-view) (require 'signature) (require 'alist) -(require 'pgg-def) -(require 'pgg-parse) - -(autoload 'pgg-encrypt-region "pgg" - "PGP encryption of current region." t) -(autoload 'pgg-sign-region "pgg" - "PGP signature of current region." t) -(autoload 'pgg-insert-key "pgg" - "Insert PGP public key at point." t) +(require 'epa) + (autoload 'smime-encrypt-buffer "smime" "S/MIME encryption of current buffer.") (autoload 'smime-sign-buffer "smime" @@ -619,6 +612,7 @@ If it is not specified for a major-mode, ") " (if (fboundp 'apel-version) (concat (apel-version) " ")) + "EasyPG/ " epg-version-number " " (if (featurep 'xemacs) (concat (cond ((and (featurep 'chise) (boundp 'xemacs-chise-version)) @@ -1673,6 +1667,8 @@ Parameter must be '(PROMPT CHOICE1 (CHOICE2...))." (ctype (car ret)) (encoding (nth 1 ret)) (pgp-boundary (concat "pgp-sign-" boundary)) + (context (epg-make-context)) + signature micalg) (mime-edit-delete-trailing-whitespace) ; RFC3156 (goto-char beg) @@ -1680,35 +1676,46 @@ Parameter must be '(PROMPT CHOICE1 (CHOICE2...))." (if encoding (insert (format "Content-Transfer-Encoding: %s\n" encoding))) (insert "\n") - (or (let ((pgg-default-user-id - (or mime-edit-pgp-user-id - (if from - (nth 1 (std11-extract-address-components from)) - pgg-default-user-id)))) - (pgg-sign-region (point-min)(point-max))) - (throw 'mime-edit-error 'pgp-error)) - (setq micalg - (cdr (assq 'hash-algorithm - (cdar (with-current-buffer pgg-output-buffer - (pgg-parse-armor-region - (point-min)(point-max)))))) - micalg - (if micalg - (concat "; micalg=pgp-" (downcase (symbol-name micalg))) - "")) + (epg-context-set-armor context t) + (epg-context-set-textmode context t) + (epg-context-set-signers + context + (epa-select-keys + "\ +Select keys for signing. +If no one is selected, default secret key is used. " + (if from + (list (nth 1 (std11-extract-address-components from)))) + t)) + (condition-case error + (setq signature + (epg-sign-string context + (buffer-substring (point-min) (point-max)) + 'detached)) + (error (signal 'mime-edit-error (cdr error)))) + (setq micalg (cdr (assq 'digest-algorithm + (car (epg-context-result-for context 'sign))))) (goto-char beg) (insert (format "--[[multipart/signed; boundary=\"%s\"%s; protocol=\"application/pgp-signature\"][7bit]] --%s -" pgp-boundary micalg pgp-boundary)) +" + pgp-boundary + (if micalg + (concat "; micalg=pgp-" + (downcase + (cdr (assq micalg + epg-digest-algorithm-alist)))) + "") + pgp-boundary)) (goto-char (point-max)) (insert (format "\n--%s Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit " pgp-boundary)) - (insert-buffer-substring pgg-output-buffer) + (insert signature) (goto-char (point-max)) (insert (format "\n--%s--\n" pgp-boundary)))))) @@ -1744,17 +1751,18 @@ Content-Transfer-Encoding: 7bit (defun mime-edit-encrypt-pgp-mime (beg end boundary) (save-excursion (save-restriction - (let (from recipients header) + (let (recipients header) (let ((ret (mime-edit-make-encrypt-recipient-header))) - (setq from (aref ret 0) - recipients (aref ret 1) + (setq recipients (aref ret 1) header (aref ret 2))) (narrow-to-region beg end) (let* ((ret (mime-edit-translate-region beg end boundary)) (ctype (car ret)) (encoding (nth 1 ret)) - (pgp-boundary (concat "pgp-" boundary))) + (pgp-boundary (concat "pgp-" boundary)) + (context (epg-make-context)) + cipher) (goto-char beg) (insert header) (insert (format "Content-Type: %s\n" ctype)) @@ -1762,19 +1770,22 @@ Content-Transfer-Encoding: 7bit (insert (format "Content-Transfer-Encoding: %s\n" encoding))) (insert "\n") (mime-encode-header-in-buffer) - (or (let ((pgg-default-user-id - (or mime-edit-pgp-user-id - (if from - (nth 1 (std11-extract-address-components from)) - pgg-default-user-id)))) - (pgg-encrypt-region - (point-min) (point-max) - (mapcar (lambda (recipient) - (nth 1 (std11-extract-address-components - recipient))) - (split-string recipients - "\\([ \t\n]*,[ \t\n]*\\)+")))) - (throw 'mime-edit-error 'pgp-error)) + (epg-context-set-armor context t) + (condition-case error + (setq cipher + (epg-encrypt-string + context + (buffer-substring (point-min) (point-max)) + (epa-select-keys + "\ +Select recipents for encryption. +If no one is selected, symmetric encryption will be performed. " + (mapcar (lambda (recipient) + (nth 1 (std11-extract-address-components + recipient))) + (split-string recipients + "\\([ \t\n]*,[ \t\n]*\\)+"))))) + (error (signal 'mime-edit-error (cdr error)))) (delete-region (point-min)(point-max)) (goto-char beg) (insert (format "--[[multipart/encrypted; @@ -1788,7 +1799,7 @@ Content-Type: application/octet-stream Content-Transfer-Encoding: 7bit " pgp-boundary pgp-boundary pgp-boundary)) - (insert-buffer-substring pgg-output-buffer) + (insert cipher) (goto-char (point-max)) (insert (format "\n--%s--\n" pgp-boundary))))))) @@ -1799,14 +1810,20 @@ Content-Transfer-Encoding: 7bit (let* ((ret (mime-edit-translate-region beg end boundary)) (ctype (car ret)) - (encoding (nth 1 ret))) + (encoding (nth 1 ret)) + (context (epg-make-context)) + signature) (goto-char beg) (insert (format "Content-Type: %s\n" ctype)) (if encoding (insert (format "Content-Transfer-Encoding: %s\n" encoding))) (insert "\n") - (or (pgg-sign-region beg (point-max) 'clearsign) - (throw 'mime-edit-error 'pgp-error)) + (condition-case error + (setq signature + (epg-sign-string context + (buffer-substring beg (point-max)) + 'clearsign)) + (error (signal 'mime-edit-error (cdr error)))) (goto-char beg) (insert "--[[application/pgp; format=mime][7bit]]\n") @@ -1823,18 +1840,34 @@ Content-Transfer-Encoding: 7bit (let* ((ret (mime-edit-translate-region beg end boundary)) (ctype (car ret)) - (encoding (nth 1 ret))) + (encoding (nth 1 ret)) + (context (epg-make-context)) + cipher) (goto-char beg) (insert header) (insert (format "Content-Type: %s\n" ctype)) (if encoding (insert (format "Content-Transfer-Encoding: %s\n" encoding))) (insert "\n") - (or (pgg-encrypt-region beg (point-max) recipients) - (throw 'mime-edit-error 'pgp-error)) + (epg-context-set-armor context t) + (condition-case error + (setq cipher + (epg-encrypt-string + context + (buffer-substring beg (point-max)) + (epa-select-keys + "\ +Select recipents for encryption. +If no one is selected, symmetric encryption will be performed. " + (mapcar (lambda (recipient) + (nth 1 (std11-extract-address-components + recipient))) + (split-string recipients + "\\([ \t\n]*,[ \t\n]*\\)+"))))) + (error (signal 'mime-edit-error (cdr error)))) (goto-char beg) (insert - "--[[application/pgp; format=mime][7bit]]\n") + "--[[application/pgp; format=mime][7bit]]\n" cipher) ))))) (defun mime-edit-sign-smime (beg end boundary) @@ -2282,7 +2315,10 @@ and insert data encoded as ENCODING." (interactive "P") (mime-edit-insert-tag "application" "pgp-keys") (mime-edit-define-encoding "7bit") - (pgg-insert-key) + (let ((context (epg-make-context))) + (epg-context-set-armor t) + (epg-export-keys-to-string context + (epa-select-keys "Select keys for export. "))) (if (and (not (eobp)) (not (looking-at mime-edit-single-part-tag-regexp))) (insert (mime-make-text-tag) "\n"))) @@ -2596,8 +2632,11 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" nil t)) (prog1 (save-window-excursion - (pgg-decrypt-region (match-beginning 0) - (point-max))) + (epg-decrypt-string + (epg-make-context) + (buffer-substring + (match-beginning 0) + (point-max)))) (delete-region (point-min)(point-max)))) (insert-buffer-substring pgg-output-buffer) (mime-edit-decode-message-in-buffer diff --git a/mime-pgp.el b/mime-pgp.el index 7b4aa91..2cdb2cb 100644 --- a/mime-pgp.el +++ b/mime-pgp.el @@ -51,14 +51,7 @@ ;;; Code: (require 'mime-play) -(require 'pgg-def) - -(autoload 'pgg-decrypt-region "pgg" - "PGP decryption of current region." t) -(autoload 'pgg-verify-region "pgg" - "PGP verification of current region." t) -(autoload 'pgg-snarf-keys-region "pgg" - "Snarf PGP public keys in current region." t) +(require 'epg) ;;; @ Internal method for multipart/signed ;;; @@ -83,14 +76,26 @@ (format "%s-%s" (buffer-name) (mime-entity-number entity))) (mother (current-buffer)) (preview-buffer (concat "*Preview-" (buffer-name) "*")) - representation-type message-buf) + representation-type message-buf context signature plain) (set-buffer (setq message-buf (get-buffer-create new-name))) (erase-buffer) (mime-insert-entity entity) (cond ((progn (goto-char (point-min)) (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)) - (pgg-verify-region (match-beginning 0)(point-max) nil 'fetch) + (setq context (epg-make-context)) + (epg-verify-string + context + (buffer-substring (match-beginning 0)(point-max))) + (setq signature + (reverse (epg-context-result-for context 'verify))) + (while signature + (message "%s: %s %s %s" + (epg-signature-status (car signature)) + (epg-signature-key-id (car signature)) + (epg-signature-user-id (car signature)) + (epg-signature-validity (car signature))) + (setq signature (cdr signature))) (goto-char (point-min)) (delete-region (point-min) @@ -109,9 +114,13 @@ ((progn (goto-char (point-min)) (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t)) - (pgg-decrypt-region (point-min)(point-max)) + (setq context (epg-make-context)) + (setq plain + (epg-decrypt-string + context + (buffer-substring (point-min)(point-max)))) (delete-region (point-min)(point-max)) - (insert-buffer pgg-output-buffer) + (insert plain) (setq representation-type 'binary))) (setq major-mode 'mime-show-message-mode) (save-window-excursion @@ -136,27 +145,24 @@ (1- knum) (1+ knum))) (orig-entity (nth onum (mime-entity-children mother))) - (sig-file (make-temp-file "tm" nil ".asc"))) - (save-excursion - (mime-show-echo-buffer) - (set-buffer mime-echo-buffer-name) - (set-window-start - (get-buffer-window mime-echo-buffer-name) - (point-max))) - (mime-write-entity-content entity sig-file) - (unwind-protect - (with-temp-buffer - (mime-insert-entity orig-entity) - (goto-char (point-min)) - (while (progn (end-of-line) (not (eobp))) - (insert "\r") - (forward-line 1)) - (pgg-verify-region (point-min)(point-max) - sig-file 'fetch) - (save-excursion - (set-buffer mime-echo-buffer-name) - (insert-buffer-substring pgg-errors-buffer))) - (delete-file sig-file)))) + (context (epg-make-context)) + signature) + (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) + (buffer-substring))) + (setq signature + (reverse (epg-context-result-for context 'verify))) + (while signature + (message "%s: %s %s %s" + (epg-signature-status (car signature)) + (epg-signature-key-id (car signature)) + (epg-signature-user-id (car signature)) + (epg-signature-validity (car signature))) + (setq signature (cdr signature))))) ;;; @ Internal method for application/pgp-encrypted @@ -181,20 +187,13 @@ ;;; draft-ietf-openpgp-mime-02.txt (OpenPGP/MIME). (defun mime-add-application/pgp-keys (entity situation) - (save-excursion - (mime-show-echo-buffer) - (set-buffer mime-echo-buffer-name) - (set-window-start - (get-buffer-window mime-echo-buffer-name) - (point-max))) (with-temp-buffer (mime-insert-entity-content entity) (mime-decode-region (point-min) (point-max) (cdr (assq 'encoding situation))) - (pgg-snarf-keys-region (point-min)(point-max)) - (save-excursion - (set-buffer mime-echo-buffer-name) - (insert-buffer-substring pgg-errors-buffer)))) + (epg-import-keys-from-string (epg-make-context) + (buffer-substring (point-min)(point-max))) + (epa-list-keys))) ;;; @ Internal method for application/pkcs7-signature