From: yamaoka Date: Thu, 8 Apr 1999 11:14:45 +0000 (+0000) Subject: * mime-mc.el (mime-mc-pgp50-sign-region, mime-mc-gpg-sign-region): Detect and X-Git-Tag: semi-pgpgpg_04~1 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03583f53c1ed80e9d4ec760e7011bd1094750b3f;p=elisp%2Fsemi.git * mime-mc.el (mime-mc-pgp50-sign-region, mime-mc-gpg-sign-region): Detect and cache the value of message integrity check algorithm before signing if the value of `mime-mc-ommit-micalg' is nil. (mime-mc-gpg-process-region): Show boundary in `mc-gpg-debug-buffer'. (mime-mc-pgp-process-region, mime-mc-pgp50-process-region, mime-mc-gpg-process-region): Add doc string. (mime-mc-micalg-alist): New variable. (mime-mc-ommit-micalg): New user option. (TopLevel): Require `alist' and `std11'. * mime-pgp.el (TopLevel): Add comment that this module is based on draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME) as well. --- diff --git a/ChangeLog b/ChangeLog index 6371613..1503943 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +1999-04-08 Katsumi Yamaoka + + * mime-mc.el (mime-mc-pgp50-sign-region, mime-mc-gpg-sign-region): + Detect and cache the value of message integrity check algorithm + before signing if the value of `mime-mc-ommit-micalg' is nil. + (mime-mc-gpg-process-region): Show boundary in + `mc-gpg-debug-buffer'. + (mime-mc-pgp-process-region, mime-mc-pgp50-process-region, + mime-mc-gpg-process-region): Add doc string. + (mime-mc-micalg-alist): New variable. + (mime-mc-ommit-micalg): New user option. + (TopLevel): Require `alist' and `std11'. + + * mime-pgp.el (TopLevel): Add comment that this module is based on + draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME) as well. + 1999-04-06 Katsumi Yamaoka * mime-pgp.el (mime-pgp-bad-signature-post-function-pgp50-us): New diff --git a/mime-mc.el b/mime-mc.el index 598fbcc..95830e1 100644 --- a/mime-mc.el +++ b/mime-mc.el @@ -25,6 +25,8 @@ ;;; Code: +(require 'alist) +(require 'std11) (require 'semi-def) (require 'mailcrypt) @@ -46,6 +48,29 @@ (mc-snarf-keys "mc-toplev") ))) +(defcustom mime-mc-shell-file-name "/bin/sh" + "File name to load inferior shells from. Bourne shell or its equivalent +\(not tcsh) is needed for \"2>\"." + :group 'mime + :type 'file) + +(defcustom mime-mc-ommit-micalg nil + "Non-nil value means to ommit the micalg parameter for multipart/signed. +See draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME) for more information." + :group 'mime + :type 'boolean) + + +;;; @ Internal variable +;;; + +(defvar mime-mc-micalg-alist nil + "Alist of KeyID and the value of message integrity check algorithm.") + + +;;; @ External variables (for avoid byte compile warnings) +;;; + (defvar mc-gpg-comment) (defvar mc-gpg-extra-args) (defvar mc-gpg-path) @@ -57,12 +82,6 @@ (defvar mc-pgp-path) (defvar mc-pgp-user-id) -(defcustom mime-mc-shell-file-name "/bin/sh" - "File name to load inferior shells from. Bourne shell or its equivalent -\(not tcsh) is needed for \"2>\"." - :group 'mime - :type 'file) - ;;; @ Generic functions ;;; @@ -124,6 +143,8 @@ VERSION should be a string or a symbol." (defun mime-mc-gpg-process-region (beg end passwd program args parser bufferdummy boundary) + "Similar to `mc-gpg-process-region', however enclose an processed data +with BOUNDARY if it is specified." (let ((obuf (current-buffer)) (process-connection-type nil) (shell-file-name mime-mc-shell-file-name) @@ -134,8 +155,9 @@ VERSION should be a string or a symbol." proc rc status parser-result ) (mc-gpg-debug-print (format - "(mc-gpg-process-region beg=%s end=%s passwd=%s program=%s args=%s parser=%s bufferdummy=%s)" - beg end passwd program args parser bufferdummy)) + "(mc-gpg-process-region beg=%s end=%s passwd=%s program=%s args=%s parser=%s bufferdummy=%s boundary=%s)" + beg end passwd program args parser bufferdummy + boundary)) (setq stderr-tempfilename (make-temp-name (expand-file-name "mailcrypt-gpg-stderr-" mc-temp-directory))) @@ -283,31 +305,53 @@ Content-Transfer-Encoding: 7bit passwd args key (parser (function mc-gpg-insert-parser)) (pgp-path mc-gpg-path) - ) + micalg) (setq key (mc-gpg-lookup-key (or id mc-gpg-user-id))) (setq passwd (mc-activate-passwd (cdr key) (format "GnuPG passphrase for %s (%s): " (car key) (cdr key)))) - (setq args - (cons - (if boundary - "--detach-sign" - (if unclear - "--sign" - "--clearsign")) - (list "--armor" "--batch" "--textmode" "--verbose" - "--local-user" (cdr key)))) + (setq args (cons + (if boundary + "--detach-sign" + (if unclear + "--sign" + "--clearsign") + ) + (list "--armor" "--batch" "--textmode" "--verbose" + "--local-user" (cdr key)) + )) (if mc-gpg-comment (setq args (nconc args (list "--comment" (format "\"%s\"" mc-gpg-comment)))) ) - (if (and boundary - (string-match "^pgp-" boundary)) - (setq boundary - (concat "gpg-" (substring boundary (match-end 0)))) - ) + (if boundary + (progn + (if (string-match "^pgp-" boundary) + (setq boundary + (concat "gpg-" (substring boundary (match-end 0)))) + ) + (if (not (or mime-mc-ommit-micalg + (setq micalg + (cdr (assoc (cdr key) mime-mc-micalg-alist))) + )) + (with-temp-buffer + (message "Detecting the value of `micalg'...") + (insert "\n") + (mime-mc-gpg-process-region + 1 2 passwd pgp-path + (list "--clearsign" "--armor" "--batch" "--textmode" + "--verbose" "--local-user" (cdr key)) + parser buffer nil + ) + (std11-narrow-to-header) + (setq micalg + (downcase (or (std11-fetch-field "Hash") "md5")) + ) + (set-alist 'mime-mc-micalg-alist (cdr key) micalg) + )) + )) (message "Signing as %s ..." (car key)) (if (mime-mc-gpg-process-region start end passwd pgp-path args parser buffer boundary) @@ -318,8 +362,13 @@ Content-Transfer-Encoding: 7bit (insert (format "\ --[[multipart/signed; protocol=\"application/pgp-signature\"; - boundary=\"%s\"; micalg=pgp-sha1][7bit]]\n" boundary)) - )) + boundary=\"%s\"%s][7bit]]\n" + boundary + (if mime-mc-ommit-micalg + "" + (concat "; micalg=pgp-" micalg) + ) + )))) (message "Signing as %s ... Done." (car key)) t) nil))) @@ -342,6 +391,8 @@ Content-Transfer-Encoding: 7bit (defun mime-mc-pgp50-process-region (beg end passwd program args parser &optional buffer boundary) + "Similar to `mc-pgp50-process-region', however enclose an processed data +with BOUNDARY if it is specified." (let ((obuf (current-buffer)) (process-connection-type nil) (shell-file-name mime-mc-shell-file-name) @@ -525,24 +576,40 @@ Content-Transfer-Encoding: 7bit (function mime-mc-pgp50-sign-parser) (function mc-pgp50-sign-parser))) (pgp-path mc-pgp50-pgps-path) - ) + micalg) (setq key (mc-pgp50-lookup-key (or id mc-pgp50-user-id))) (setq passwd (mc-activate-passwd (cdr key) (format "PGP passphrase for %s (%s): " (car key) (cdr key)))) (setenv "PGPPASSFD" "0") - (setq args - (cons - (if boundary - "-fbat" - "-fat") - (list "+verbose=1" "+language=us" - (format "+clearsig=%s" (if unclear "off" "on")) - "+batchmode" "-u" (cdr key)))) + (setq args (if boundary + (list "-fbat" "+verbose=1" "+language=us" "+batchmode" + "-u" (cdr key)) + (list "-fat" "+verbose=1" "+language=us" + (format "+clearsig=%s" (if unclear "off" "on")) + "+batchmode" "-u" (cdr key)) + )) (if mc-pgp50-comment (setq args (cons (format "+comment=\"%s\"" mc-pgp50-comment) args)) ) + (if (and boundary + (not (or mime-mc-ommit-micalg + (setq micalg + (cdr (assoc (cdr key) mime-mc-micalg-alist))) + ))) + (with-temp-buffer + (message "Detecting the value of `micalg'...") + (insert "\n") + (mime-mc-pgp50-process-region + 1 2 passwd pgp-path + (list "-fat" "+verbose=1" "+language=us" "+clearsig=on" + "+batchmode" "-u" (cdr key)) + (function mc-pgp50-sign-parser) buffer nil) + (std11-narrow-to-header) + (setq micalg (downcase (or (std11-fetch-field "Hash") "md5"))) + (set-alist 'mime-mc-micalg-alist (cdr key) micalg) + )) (message "Signing as %s ..." (car key)) (if (mime-mc-pgp50-process-region start end passwd pgp-path args parser buffer boundary) @@ -553,8 +620,13 @@ Content-Transfer-Encoding: 7bit (insert (format "\ --[[multipart/signed; protocol=\"application/pgp-signature\"; - boundary=\"%s\"; micalg=pgp-sha1][7bit]]\n" boundary)) - )) + boundary=\"%s\"%s][7bit]]\n" + boundary + (if mime-mc-ommit-micalg + "" + (concat "; micalg=pgp-" micalg) + ) + )))) (message "Signing as %s ... Done." (car key)) t) nil))) @@ -577,6 +649,8 @@ Content-Transfer-Encoding: 7bit (defun mime-mc-process-region (beg end passwd program args parser &optional buffer boundary) + "Similar to `mc-pgp-process-region', however enclose an processed data +with BOUNDARY if it is specified." (let ((obuf (current-buffer)) (process-connection-type nil) mybuf result rgn proc) @@ -682,8 +756,13 @@ Content-Transfer-Encoding: 7bit (insert (format "\ --[[multipart/signed; protocol=\"application/pgp-signature\"; - boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary)) - )) + boundary=\"%s\"%s][7bit]]\n" + boundary + (if mime-mc-ommit-micalg + "" + "; micalg=pgp-md5" + ) + )))) (message "Signing as %s ... Done." (car key)) t) nil))) diff --git a/mime-pgp.el b/mime-pgp.el index e013220..b948ab3 100644 --- a/mime-pgp.el +++ b/mime-pgp.el @@ -42,6 +42,10 @@ ;; by Kazuhiko Yamamoto (1995/10; ;; expired) +;; [OpenPGP/MIME] draft-yamamoto-openpgp-mime-00.txt: "MIME +;; Security with OpenPGP (OpenPGP/MIME)" by Kazuhiko YAMAMOTO +;; (1998/1) + ;;; Code: (require 'std11) @@ -114,27 +118,12 @@ (set-window-buffer p-win mime-preview-buffer) )) -(defun mime-pgp-detect-version (entity) - "Detect PGP version from detached signature." - (with-temp-buffer - (mime-insert-entity-content entity) - (std11-narrow-to-header) - (let ((version (std11-fetch-field "Version"))) - (cond ((not version) - pgp-version) - ((string-match "GnuPG" version) - 'gpg) - ((string-match "5\\.0i" version) - 'pgp50) - ((string-match "2\\.6" version) - 'pgp) - (t - pgp-version))))) - ;;; @ Internal method for application/pgp-signature ;;; -;;; It is based on RFC 2015 (PGP/MIME). +;;; It is based on RFC 2015 (PGP/MIME) and +;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME). + (defcustom mime-pgp-command-alist '((gpg . "gpg") (pgp50 . "pgp") @@ -306,6 +295,23 @@ or \"v\" for choosing a command of PGP 5.0i." (cdr (assq pgp-version mime-pgp-key-expected-regexp-alist)) ))) +(defun mime-pgp-detect-version (entity) + "Detect PGP version from detached signature." + (with-temp-buffer + (mime-insert-entity-content entity) + (std11-narrow-to-header) + (let ((version (std11-fetch-field "Version"))) + (cond ((not version) + pgp-version) + ((string-match "GnuPG" version) + 'gpg) + ((string-match "5\\.0i" version) + 'pgp50) + ((string-match "2\\.6" version) + 'pgp) + (t + pgp-version))))) + (defun mime-pgp-check-signature (output-buffer orig-file) (with-current-buffer output-buffer (erase-buffer) @@ -464,7 +470,8 @@ key-ID if it is found." ;;; @ Internal method for application/pgp-encrypted ;;; -;;; It is based on RFC 2015 (PGP/MIME). +;;; It is based on RFC 2015 (PGP/MIME) and +;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME). (defun mime-decrypt-application/pgp-encrypted (entity situation) (let* ((entity-node-id (mime-entity-node-id entity)) @@ -481,7 +488,8 @@ key-ID if it is found." ;;; @ Internal method for application/pgp-keys ;;; -;;; It is based on RFC 2015 (PGP/MIME). +;;; It is based on RFC 2015 (PGP/MIME) and +;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME). (defun mime-add-application/pgp-keys (entity situation) (let* ((start (mime-entity-point-min entity))