From fd5d57e705a35abbe1bc9a2219f3ca39e4c41253 Mon Sep 17 00:00:00 2001 From: yamaoka Date: Fri, 26 Mar 1999 06:39:19 +0000 Subject: [PATCH] * NEWS, mime-ui-en.sgml, mime-ui-ja.sgml: Update for the command `mime-mc-setversion'. * semi-setup (TopLevel): Autoload "mime-mc" for the command `mime-mc-setversion'. * mime-mc.el (mime-mc-pgp50-sign-region): Use "micalg=pgp-sha1" instead of "micalg=pgp-md5"; use `mime-mc-pgp50-sign-parser' for the parser if a detached sign is required. (mime-mc-pgp50-sign-parser): New function for parsing a detached sign. (mime-mc-setversion): New command. * mime-edit.el (mime-edit-preview-message): Inherit the value of `mime-edit-pgp-processing' from the editing buffer to the encoding buffer. (mime-edit-encrypt-pgp-mime): Swap the prefix string of boundary "gpg-" with "pgp-". --- ChangeLog | 21 ++++++++ NEWS | 8 +-- mime-edit.el | 6 ++- mime-mc.el | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- mime-ui-en.sgml | 10 +++- mime-ui-ja.sgml | 10 +++- semi-setup.el | 4 ++ 7 files changed, 206 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17b5ba8..8c7c266 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +1999-03-25 Katsumi Yamaoka + + * NEWS, mime-ui-en.sgml, mime-ui-ja.sgml: Update for the command + `mime-mc-setversion'. + + * semi-setup.el (TopLevel): Autoload "mime-mc" for the command + `mime-mc-setversion'. + + * mime-mc.el (mime-mc-pgp50-sign-region): Use "micalg=pgp-sha1" + instead of "micalg=pgp-md5"; use `mime-mc-pgp50-sign-parser' for + the parser if a detached sign is required. + (mime-mc-pgp50-sign-parser): New function for parsing a detached + sign. + (mime-mc-setversion): New command. + + * mime-edit.el (mime-edit-preview-message): Inherit the value of + `mime-edit-pgp-processing' from the editing buffer to the encoding + buffer. + (mime-edit-encrypt-pgp-mime): Swap the prefix string of boundary + "gpg-" with "pgp-". + 1999-03-24 Katsumi Yamaoka * NEWS, README.en, mime-ui-en.sgml, mime-ui-ja.sgml: Update for diff --git a/NEWS b/NEWS index 28c5a0e..0179014 100644 --- a/NEWS +++ b/NEWS @@ -5,10 +5,10 @@ Copyright (C) 1998,1999 Free Software Foundation, Inc. ** PGP 5.0i and GnuPG are now supported for PGP/MIME -You can select the various PGP or GnuPG commands by the new user -option `pgp-version'. Note that Mailcrypt 3.5.3 or later is needed -for PGP 5.0i or GnuPG. A user interface for editing or viewing has -never changed. + You can select the various PGP or GnuPG commands by the user option +`pgp-version' or the command `mime-mc-setversion'. Note that Mailcrypt +3.5.3 or later is needed for PGP 5.0i or GnuPG. A user interface for +editing or viewing has never changed. ** Function `mime-play-entity' diff --git a/mime-edit.el b/mime-edit.el index ab98d43..ab33a04 100644 --- a/mime-edit.el +++ b/mime-edit.el @@ -1799,8 +1799,8 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))." (ctype (car ret)) (encoding (nth 1 ret)) (pgp-boundary (concat (if (eq 'gpg pgp-version) - "pgp-" - "gpg-") + "gpg-" + "pgp-") boundary))) (goto-char beg) (insert header) @@ -2553,6 +2553,7 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (buf-name (buffer-name)) (temp-buf-name (concat "*temp-article:" buf-name "*")) (buf (get-buffer temp-buf-name)) + (pgp-processing mime-edit-pgp-processing) ) (if buf (progn @@ -2568,6 +2569,7 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (setq mail-header-separator separator) (make-local-variable 'mime-edit-buffer) (setq mime-edit-buffer the-buf) + (setq mime-edit-pgp-processing pgp-processing) (run-hooks 'mime-edit-translate-hook) (mime-edit-translate-buffer) diff --git a/mime-mc.el b/mime-mc.el index 7312e48..63c49f7 100644 --- a/mime-mc.el +++ b/mime-mc.el @@ -57,6 +57,36 @@ ;;; @ Generic functions ;;; +(defun mime-mc-setversion (&optional version) + "Select `pgp-version' and `mc-default-scheme' if possible. +VERSION should be a string or a symbol." + (interactive) + (let ((oldversion pgp-version) + (table '(("GnuPG" . gpg) ("PGP 5.0i" . pgp50) ("PGP 2.6" . pgp) + ("gnupg" . gpg) ("gpg" . gpg) ("pgp5" . pgp50) + ("pgp50" . pgp50) ("pgp2" . pgp) ("pgp" . pgp) + ("5.0" . pgp50) ("2.6" . pgp)))) + (if (interactive-p) + (setq version (completing-read + (format "Select PGP version (currently %s): " + (car (rassoc oldversion table))) + table nil t) + pgp-version (or (cdr (assoc version table)) + oldversion)) + (if (stringp version) + (setq pgp-version (or (cdr (assoc version table)) oldversion)) + (if (memq version '(gpg pgp50 pgp)) + (setq pgp-version version) + ))) + (condition-case nil + (mc-setversion + (cdr (assq pgp-version + '((gpg . "gpg") (pgp50 . "5.0") (pgp . "2.6")))) + ) + (error nil)) + (message "PGP version set to %s." (car (rassq pgp-version table))) + )) + (defun mime-mc-insert-public-key (&optional userid scheme) (mc-insert-public-key userid @@ -110,18 +140,22 @@ (erase-buffer) (set-buffer obuf) (buffer-disable-undo mybuf) + (if passwd (setq args (append '("--passphrase-fd" "0") args))) (setq args (append (list (concat "2>" stderr-tempfilename)) args)) (setq args (append (list (concat "3>" status-tempfilename)) args)) (setq args (append '("--status-fd" "3") args)) + (if mc-gpg-extra-args (setq args (append mc-gpg-extra-args args))) + (mc-gpg-debug-print (format "prog is %s, args are %s" program (mapconcat '(lambda (x) (format "'%s'" x)) args " "))) + (setq proc (apply 'start-process-shell-command "*GPG*" mybuf program args)) @@ -141,8 +175,10 @@ (setq status (process-status proc)) (setq rc (process-exit-status proc)) (mc-gpg-debug-print (format "prog finished, rc=%s" rc)) + ;; Hack to force a status_notify() in Emacs 19.29 (delete-process proc) + ;; remove the annoying "yes your process has finished" message (set-buffer mybuf) (goto-char (point-max)) @@ -152,30 +188,36 @@ ;; CRNL -> NL (while (search-forward "\r\n" nil t) (replace-match "\n")) + ;; ponder process death: signal, not just rc!=0 (if (or (eq 'stop status) (eq 'signal status)) ;; process died (error "%s exited abnormally: '%s'" program rc) ;;is rc a string? ) + (if (= 127 rc) (error "%s could not be found" program) ;; at least on my system ) + ;; fill stderr buf (setq stderr-buf (get-buffer-create " *mailcrypt stderr temp")) (buffer-disable-undo stderr-buf) (set-buffer stderr-buf) (erase-buffer) (insert-file-contents stderr-tempfilename) + ;; fill status buf (setq status-buf (get-buffer-create " *mailcrypt status temp")) (buffer-disable-undo status-buf) (set-buffer status-buf) (erase-buffer) (insert-file-contents status-tempfilename) + ;; feed the parser (set-buffer mybuf) (setq parser-result (funcall parser mybuf stderr-buf status-buf rc)) (mc-gpg-debug-print (format " parser returned %s" parser-result)) + ;; what did the parser tell us? (if (car parser-result) ;; yes, replace region @@ -200,6 +242,7 @@ Content-Transfer-Encoding: 7bit (goto-char beg) (insert-buffer-substring mybuf) ))) + ;; return result (cdr parser-result) ) @@ -304,17 +347,21 @@ Content-Transfer-Encoding: 7bit (setq proc (apply 'start-process-shell-command "*PGP*" mybuf program "2>&1" args)) + ;; Now hand the process to the parser, which returns the exit ;; status of the dead process and the limits of the region ;; containing the PGP results. (setq results (funcall parser proc obuf beg end mybuf passwd)) (setq result (car results)) (setq rgn (cadr results)) + ;; Hack to force a status_notify() in Emacs 19.29 (set-buffer mybuf) + ;; Hurm. FIXME; must get better result codes. (if (stringp result) (mc-message result)) + ;; If the parser found something, migrate it to the old ;; buffer. In particular, the parser's job is to return ;; a cons of the form ( beg . end ) delimited the result @@ -343,8 +390,10 @@ Content-Transfer-Encoding: 7bit ) (set-buffer mybuf) (delete-region (car rgn) (cdr rgn)))) + ;; Return nil on failure and exit code on success (if rgn result nil)) + ;; Cleanup even on nonlocal exit (if (and proc (eq 'run (process-status proc))) (interrupt-process proc)) @@ -352,6 +401,110 @@ Content-Transfer-Encoding: 7bit (or buffer (null mybuf) (kill-buffer mybuf)) rgn))) +(defun mime-mc-pgp50-sign-parser (proc oldbuf start end newbuf passwd) + ;; This function is a copy of `mc-pgp50-sign-parser', however it is + ;; modified for parsing a detached sign. + (let (result results rgn) + ;; (setenv "PGPPASSFD" "0") + (set-buffer newbuf) + (goto-char (point-max)) + (progn + (unwind-protect + (with-expect proc + (message "Sending passphrase...") + (expect-send (concat passwd "\n")) + (or mc-passwd-timeout (mc-deactivate-passwd t)) + (expect "No files specified. Using stdin." + (message "Passphrase sent. Signing...") + (set-buffer oldbuf) + (process-send-region proc start end) + (set-buffer newbuf) + (process-send-eof proc) + + ;; Test output of the program, looking for + ;; errors. + (expect-cond + + ;; OPTION 1: Great! The data is now signed! + ("-----END PGP SIGNATURE-----" + + ;; Catch the exit status. + (setq result (process-exit-status proc)) + (delete-process proc) + (message "Signing complete.") + + ;; Delete everything preceding the signed data. + (goto-char (point-max)) + (re-search-backward + ;; "-----BEGIN PGP SIGNED MESSAGE-----" nil t) + "-----BEGIN PGP SIGNATURE-----" nil t) + (delete-region (point-min) (match-beginning 0)) + (setq rgn (point-min)) + + ;; Convert out CR/NL -> NL + (goto-char (point-min)) + (while (search-forward "\r\n" nil t) + (replace-match "\n")) + + ;; Delete everything after the signature. + (goto-char (point-min)) + (re-search-forward + "-----END PGP SIGNATURE-----\n" nil t) + (delete-region (match-end 0) (point-max)) + + ;; Return the exit status, with the region + ;; limits! + (setq rgn (cons rgn (point-max))) + (setq results (list result rgn))) + + + ;; OPTION 1.a: The data is now signed, but is 8bit data. + ("-----END PGP MESSAGE-----" + + ;; Catch the exit status. + (setq result (process-exit-status proc)) + (delete-process proc) + (message "Signing complete.") + + ;; Delete everything preceding the signed data. + (goto-char (point-max)) + (re-search-backward + "-----BEGIN PGP MESSAGE-----" nil t) + (delete-region (point-min) (match-beginning 0)) + (setq rgn (point-min)) + + ;; Convert out CR/NL -> NL + (goto-char (point-min)) + (while (search-forward "\r\n" nil t) + (replace-match "\n")) + + ;; Delete everything after the signature. + (goto-char (point-min)) + (re-search-forward + "-----END PGP MESSAGE-----\n" nil t) + (delete-region (match-end 0) (point-max)) + + ;; Return the exit status, with the region + ;; limits! + (setq rgn (cons rgn (point-max))) + (setq results (list result rgn))) + + + ;; OPTION 2: Awww...bad passphrase! + ("Enter pass phrase:" + (mc-deactivate-passwd t) + (interrupt-process proc) + (delete-process proc) + + ;; Return the bad news. + (setq results '("Incorrect passphrase" nil))) + + ;; OPTION 3: The program exits. + (exit + (setq results (list + (process-exit-status proc) nil))))))) + results))) + (defun mime-mc-pgp50-sign-region (start end &optional id unclear boundary) (if (not (fboundp 'mc-pgp50-sign-parser)) (load "mc-pgp5") @@ -359,7 +512,9 @@ Content-Transfer-Encoding: 7bit (let ((process-environment process-environment) (buffer (get-buffer-create mc-buffer-name)) passwd args key - (parser (function mc-pgp50-sign-parser)) + (parser (if boundary + (function mime-mc-pgp50-sign-parser) + (function mc-pgp50-sign-parser))) (pgp-path mc-pgp50-pgps-path) ) (setq key (mc-pgp50-lookup-key (or id mc-pgp50-user-id))) @@ -389,7 +544,7 @@ Content-Transfer-Encoding: 7bit (insert (format "\ --[[multipart/signed; protocol=\"application/pgp-signature\"; - boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary)) + boundary=\"%s\"; micalg=pgp-sha1][7bit]]\n" boundary)) )) (message "Signing as %s ... Done." (car key)) t) diff --git a/mime-ui-en.sgml b/mime-ui-en.sgml index 49f60ca..d77f473 100644 --- a/mime-ui-en.sgml +++ b/mime-ui-en.sgml @@ -411,8 +411,7 @@ Encrypt to specified region. C-c C-x C-q avoid to encode tags in specified region. In other words, tags is -interpreted as such string. (In current version, it may be -incomplete. Maybe PGP-signature does not work for this enclosure.) +interpreted as such string. @@ -645,6 +644,13 @@ FUNCTION and FILE, but they will be used for PGP 5.0i or GnuPG. Return function to do service method. + + version +

+Select `pgp-version' and `mc-default-scheme' if possible. VERSION +should be a string or a symbol. + +

Mouse button Buttons diff --git a/mime-ui-ja.sgml b/mime-ui-ja.sgml index bda633d..a5540ad 100644 --- a/mime-ui-ja.sgml +++ b/mime-ui-ja.sgml @@ -423,8 +423,7 @@ enclosure を作るための操作としては以下のようなものがあります。 C-c C-x C-q 指定した region 内の tag を無効にし、その tag を文字列として利用できる -ようにします。(現在の版ではうまく働かないことがあります。また、電子署 -名との併用に関しても不完全です) +ようにします。 @@ -660,6 +659,13 @@ FUNCTION and FILE, but they will be used for PGP 5.0i or GnuPG. Return function to do service method. + + version +

+Select `pgp-version' and `mc-default-scheme' if possible. VERSION +should be a string or a symbol. + +

押釦 Buttons diff --git a/semi-setup.el b/semi-setup.el index b1493a6..db4e5c3 100644 --- a/semi-setup.el +++ b/semi-setup.el @@ -126,6 +126,10 @@ it is used as hook to set." )) ) +(if mime-setup-enable-pgp + (autoload 'mime-mc-setversion "mime-mc" nil t) + ) + ;;; @ for mime-edit ;;; -- 1.7.10.4