1 ;;; mime-pgp.el --- mime-view internal methods foro 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;
45 ;; [OpenPGP/MIME] draft-yamamoto-openpgp-mime-00.txt: "MIME
46 ;; Security with OpenPGP (OpenPGP/MIME)" by Kazuhiko YAMAMOTO
47 ;; <kazu@iijlab.net> (1998/1)
54 (autoload 'pgg-decrypt-region "pgg"
55 "PGP decryption of current region." t)
56 (autoload 'pgg-verify-region "pgg"
57 "PGP verification of current region." t)
58 (autoload 'pgg-snarf-keys-region "pgg"
59 "Snarf PGP public keys in current region." t)
60 (autoload 'smime-decrypt-region "smime"
61 "S/MIME decryption of current region.")
62 (autoload 'smime-verify-region "smime"
63 "S/MIME verification of current region.")
66 ;;; @ Internal method for multipart/signed
68 ;;; It is based on RFC 1847 (security-multipart).
70 (defun mime-verify-multipart/signed (entity situation)
71 "Internal method to verify multipart/signed."
73 (nth 1 (mime-entity-children entity)) ; entity-info of signature
74 (list (assq 'mode situation)) ; play-mode
78 ;;; @ internal method for application/pgp
80 ;;; It is based on draft-kazu-pgp-mime-00.txt (PGP-kazu).
82 (defun mime-view-application/pgp (entity situation)
83 (let* ((p-win (or (get-buffer-window (current-buffer))
84 (get-largest-window)))
86 (format "%s-%s" (buffer-name) (mime-entity-number entity)))
87 (mother (current-buffer))
88 (preview-buffer (concat "*Preview-" (buffer-name) "*"))
90 (set-buffer (get-buffer-create new-name))
92 (mime-insert-entity entity)
94 (goto-char (point-min))
95 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
96 (pgg-verify-region (match-beginning 0)(point-max) nil 'fetch)
97 (goto-char (point-min))
101 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
104 (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
107 (goto-char (point-min))
108 (while (re-search-forward "^- -" nil t)
111 (setq representation-type (if (mime-entity-cooked-p entity)
115 (goto-char (point-min))
116 (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t))
117 (pgg-decrypt-region (point-min)(point-max))
118 (delete-region (point-min)(point-max))
119 (insert-buffer pgg-output-buffer)
120 (setq representation-type 'binary)
122 (setq major-mode 'mime-show-message-mode)
123 (save-window-excursion (mime-view-buffer nil preview-buffer mother
124 nil representation-type))
125 (set-window-buffer p-win preview-buffer)
129 ;;; @ Internal method for application/pgp-signature
131 ;;; It is based on RFC 2015 (PGP/MIME) and
132 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
134 (defun mime-verify-application/pgp-signature (entity situation)
135 "Internal method to check PGP/MIME signature."
136 (let* ((entity-node-id (mime-entity-node-id entity))
137 (mother (mime-entity-parent entity))
138 (knum (car entity-node-id))
142 (orig-entity (nth onum (mime-entity-children mother)))
143 (basename (expand-file-name "tm" temporary-file-directory))
144 (sig-file (concat (make-temp-name basename) ".asc"))
147 (mime-show-echo-buffer)
148 (set-buffer mime-echo-buffer-name)
150 (get-buffer-window mime-echo-buffer-name)
153 (mime-write-entity-content entity sig-file)
156 (mime-insert-entity orig-entity)
157 (goto-char (point-min))
158 (while (progn (end-of-line) (not (eobp)))
161 (setq status (pgg-verify-region (point-min)(point-max)
164 (set-buffer mime-echo-buffer-name)
165 (insert-buffer-substring (if status pgg-output-buffer
166 pgg-errors-buffer))))
167 (delete-file sig-file))
171 ;;; @ Internal method for application/pgp-encrypted
173 ;;; It is based on RFC 2015 (PGP/MIME) and
174 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
176 (defun mime-decrypt-application/pgp-encrypted (entity situation)
177 (let* ((entity-node-id (mime-entity-node-id entity))
178 (mother (mime-entity-parent entity))
179 (knum (car entity-node-id))
183 (orig-entity (nth onum (mime-entity-children mother))))
184 (mime-view-application/pgp orig-entity situation)
188 ;;; @ Internal method for application/pgp-keys
190 ;;; It is based on RFC 2015 (PGP/MIME) and
191 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
193 (defun mime-add-application/pgp-keys (entity situation)
195 (mime-show-echo-buffer)
196 (set-buffer mime-echo-buffer-name)
198 (get-buffer-window mime-echo-buffer-name)
202 (mime-insert-entity-content entity)
203 (mime-decode-region (point-min) (point-max)
204 (cdr (assq 'encoding situation)))
205 (let ((status (pgg-snarf-keys-region (point-min)(point-max))))
207 (set-buffer mime-echo-buffer-name)
208 (insert-buffer-substring (if status pgg-output-buffer
213 ;;; @ Internal method for application/pkcs7-signature
215 ;;; It is based on RFC 2633 (S/MIME version 3).
217 (defun mime-verify-application/pkcs7-signature (entity situation)
218 "Internal method to check S/MIME signature."
219 (let* ((entity-node-id (mime-entity-node-id entity))
220 (mother (mime-entity-parent entity))
221 (knum (car entity-node-id))
225 (orig-entity (nth onum (mime-entity-children mother)))
226 (basename (expand-file-name "tm" temporary-file-directory))
227 (sig-file (concat (make-temp-name basename) ".asc"))
230 (mime-show-echo-buffer)
231 (set-buffer mime-echo-buffer-name)
233 (get-buffer-window mime-echo-buffer-name)
236 (mime-write-entity entity sig-file)
239 (mime-insert-entity orig-entity)
240 (goto-char (point-min))
241 (while (progn (end-of-line) (not (eobp)))
244 (setq status (smime-verify-region (point-min)(point-max)
247 (set-buffer mime-echo-buffer-name)
248 (insert-buffer-substring (if status smime-output-buffer
249 smime-errors-buffer))))
250 (delete-file sig-file))
254 ;;; @ Internal method for application/pkcs7-mime
256 ;;; It is based on RFC 2633 (S/MIME version 3).
258 (defun mime-decrypt-application/pkcs7-mime (entity situation)
259 (let* ((p-win (or (get-buffer-window (current-buffer))
260 (get-largest-window)))
262 (format "%s-%s" (buffer-name) (mime-entity-number entity)))
263 (mother (current-buffer))
264 (preview-buffer (concat "*Preview-" (buffer-name) "*"))
266 (set-buffer (get-buffer-create new-name))
267 (let ((inhibit-read-only t)
270 (mime-insert-entity entity)
271 (smime-decrypt-region (point-min)(point-max))
272 (delete-region (point-min)(point-max))
273 (insert-buffer smime-output-buffer))
274 (setq major-mode 'mime-show-message-mode)
275 (save-window-excursion (mime-view-buffer nil preview-buffer mother
277 (set-window-buffer p-win preview-buffer)
286 (run-hooks 'mime-pgp-load-hook)
288 ;;; mime-pgp.el ends here