1 ;;; mime-pgp.el --- mime-view internal methods for PGP.
3 ;; Copyright (C) 1995,1996,1997,1998,1999 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Daiki Ueno <ueno@ueda.info.waseda.ac.jp>
8 ;; Renamed: 1997/2/27 from tm-pgp.el
9 ;; Keywords: PGP, security, MIME, multimedia, mail, news
11 ;; This file is part of SEMI (Secure Emacs MIME Interface).
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
30 ;; This module is based on
32 ;; [security-multipart] RFC 1847: "Security Multiparts for MIME:
33 ;; Multipart/Signed and Multipart/Encrypted" by
34 ;; Jim Galvin <galvin@tis.com>, Sandy Murphy <sandy@tis.com>,
35 ;; Steve Crocker <crocker@cybercash.com> and
36 ;; Ned Freed <ned@innosoft.com> (1995/10)
38 ;; [PGP/MIME] RFC 2015: "MIME Security with Pretty Good Privacy
39 ;; (PGP)" by Michael Elkins <elkins@aero.org> (1996/6)
41 ;; [PGP-kazu] draft-kazu-pgp-mime-00.txt: "PGP MIME Integration"
42 ;; by Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp> (1995/10;
51 ;;; @ Internal method for multipart/signed
53 ;;; It is based on RFC 1847 (security-multipart).
55 (defun mime-verify-multipart/signed (entity situation)
56 "Internal method to verify multipart/signed."
58 (nth 1 (mime-entity-children entity)) ; entity-info of signature
59 (list (assq 'mode situation)) ; play-mode
63 ;;; @ internal method for application/pgp
65 ;;; It is based on draft-kazu-pgp-mime-00.txt (PGP-kazu).
67 (defun mime-view-application/pgp (entity situation)
68 (let* ((p-win (or (get-buffer-window (current-buffer))
69 (get-largest-window)))
71 (format "%s-%s" (buffer-name) (mime-entity-number entity)))
72 (mother (current-buffer))
73 (preview-buffer (concat "*Preview-" (buffer-name) "*"))
75 (set-buffer (get-buffer-create new-name))
77 (mime-insert-entity entity)
79 (goto-char (point-min))
80 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
81 (funcall (pgp-function 'verify)
82 (point-min)(point-max))
83 (goto-char (point-min))
87 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
90 (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
93 (goto-char (point-min))
94 (while (re-search-forward "^- -" nil t)
97 (setq representation-type (if (mime-entity-cooked-p entity)
101 (goto-char (point-min))
102 (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t))
103 (funcall (pgp-function 'decrypt)
104 (point-min)(point-max))
105 (delete-region (point-min)(point-max))
106 (insert-buffer pgg-output-buffer)
107 (setq representation-type 'binary)
109 (setq major-mode 'mime-show-message-mode)
110 (save-window-excursion (mime-view-buffer nil preview-buffer mother
111 nil representation-type))
112 (set-window-buffer p-win preview-buffer)
116 ;;; @ Internal method for application/pgp-signature
118 ;;; It is based on RFC 2015 (PGP/MIME).
120 (defvar mime-pgp-command "pgp"
121 "*Name of the PGP command.")
123 (defvar mime-pgp-default-language 'en
124 "*Symbol of language for pgp.
125 It should be ISO 639 2 letter language code such as en, ja, ...")
127 (defvar mime-pgp-good-signature-regexp-alist
128 '((en . "Good signature from user.*$"))
129 "Alist of language vs regexp to detect ``Good signature''.")
131 (defvar mime-pgp-key-expected-regexp-alist
132 '((en . "Key matching expected Key ID \\(\\S +\\) not found"))
133 "Alist of language vs regexp to detect ``Key expected''.")
135 (defun mime-pgp-check-signature (output-buffer sig-file orig-file)
137 (set-buffer output-buffer)
139 (let* ((lang (or mime-pgp-default-language 'en))
140 (status (call-process-region (point-min)(point-max)
142 nil output-buffer nil
143 sig-file orig-file (format "+language=%s" lang)))
144 (regexp (cdr (assq lang mime-pgp-good-signature-regexp-alist))))
147 (set-buffer output-buffer)
148 (goto-char (point-min))
150 (cond ((not (stringp regexp))
151 "Please specify right regexp for specified language")
152 ((re-search-forward regexp nil t)
153 (buffer-substring (match-beginning 0) (match-end 0)))
154 (t "Bad signature")))
157 (defun mime-verify-application/pgp-signature (entity situation)
158 "Internal method to check PGP/MIME signature."
159 (let* ((entity-node-id (mime-entity-node-id entity))
160 (mother (mime-entity-parent entity))
161 (knum (car entity-node-id))
165 (orig-entity (nth onum (mime-entity-children mother)))
166 (basename (expand-file-name "tm" temporary-file-directory))
167 (sig-file (concat (make-temp-name basename) ".asc"))
169 (save-excursion (mime-show-echo-buffer))
170 (mime-write-entity-content entity sig-file)
173 (mime-insert-entity orig-entity)
174 (goto-char (point-min))
175 (while (progn (end-of-line) (not (eobp)))
178 (let ((pgg-output-buffer mime-echo-buffer-name))
179 (funcall (pgp-function 'verify)
180 (point-min)(point-max) sig-file 'fetch)))
181 (delete-file sig-file))
185 ;;; @ Internal method for application/pgp-encrypted
187 ;;; It is based on RFC 2015 (PGP/MIME).
189 (defun mime-decrypt-application/pgp-encrypted (entity situation)
190 (let* ((entity-node-id (mime-entity-node-id entity))
191 (mother (mime-entity-parent entity))
192 (knum (car entity-node-id))
196 (orig-entity (nth onum (mime-entity-children mother))))
197 (mime-view-application/pgp orig-entity situation)
201 ;;; @ Internal method for application/pgp-keys
203 ;;; It is based on RFC 2015 (PGP/MIME).
205 (defun mime-add-application/pgp-keys (entity situation)
206 (let* ((start (mime-entity-header-start-point entity))
207 (end (mime-entity-body-end-point entity))
208 (entity-number (mime-entity-number entity))
209 (new-name (format "%s-%s" (buffer-name) entity-number))
210 (encoding (cdr (assq 'encoding situation)))
212 (setq str (buffer-substring start end))
213 (switch-to-buffer new-name)
214 (setq buffer-read-only nil)
217 (goto-char (point-min))
218 (if (re-search-forward "^\n" nil t)
219 (delete-region (point-min) (match-end 0))
221 (mime-decode-region (point-min)(point-max) encoding)
222 (funcall (pgp-function 'snarf-keys)
223 (point-min)(point-max))
224 (kill-buffer (current-buffer))
233 (run-hooks 'mime-pgp-load-hook)
235 ;;; mime-pgp.el ends here