1 ;;; mime-pgp.el --- mime-view internal methods for PGP.
3 ;; Copyright (C) 1995,1996,1997,1998,1999,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
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.")
64 (defvar smime-output-buffer)
65 (defvar smime-errors-buffer)
68 ;;; @ Internal method for multipart/signed
70 ;;; It is based on RFC 1847 (security-multipart).
72 (defun mime-verify-multipart/signed (entity situation)
73 "Internal method to verify multipart/signed."
75 (nth 1 (mime-entity-children entity)) ; entity-info of signature
76 (list (assq 'mode situation)) ; play-mode
80 ;;; @ internal method for application/pgp
82 ;;; It is based on draft-kazu-pgp-mime-00.txt (PGP-kazu).
84 (defun mime-view-application/pgp (entity situation)
85 (let* ((p-win (or (get-buffer-window (current-buffer))
86 (get-largest-window)))
88 (format "%s-%s" (buffer-name) (mime-entity-number entity)))
89 (mother (current-buffer))
90 (preview-buffer (concat "*Preview-" (buffer-name) "*"))
91 representation-type message-buf)
92 (set-buffer (setq message-buf (get-buffer-create new-name)))
94 (mime-insert-entity entity)
96 (goto-char (point-min))
97 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
98 (pgg-verify-region (match-beginning 0)(point-max) nil 'fetch)
99 (goto-char (point-min))
103 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
106 (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
109 (goto-char (point-min))
110 (while (re-search-forward "^- -" nil t)
112 (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)))
121 (setq major-mode 'mime-show-message-mode)
122 (save-window-excursion
123 (mime-view-buffer nil preview-buffer mother
124 nil representation-type)
125 (make-local-variable 'mime-view-temp-message-buffer)
126 (setq mime-view-temp-message-buffer message-buf))
127 (set-window-buffer p-win preview-buffer)))
130 ;;; @ Internal method for application/pgp-signature
132 ;;; It is based on RFC 2015 (PGP/MIME) and
133 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
135 (defun mime-verify-application/pgp-signature (entity situation)
136 "Internal method to check PGP/MIME signature."
137 (let* ((entity-node-id (mime-entity-node-id entity))
138 (mother (mime-entity-parent entity))
139 (knum (car entity-node-id))
143 (orig-entity (nth onum (mime-entity-children mother)))
144 (sig-file (make-temp-file "tm" nil ".asc"))
147 (mime-show-echo-buffer)
148 (set-buffer mime-echo-buffer-name)
150 (get-buffer-window mime-echo-buffer-name)
152 (mime-write-entity-content entity sig-file)
155 (mime-insert-entity orig-entity)
156 (goto-char (point-min))
157 (while (progn (end-of-line) (not (eobp)))
160 (setq status (pgg-verify-region (point-min)(point-max)
163 (set-buffer mime-echo-buffer-name)
164 (insert-buffer-substring (if status pgg-output-buffer
165 pgg-errors-buffer))))
166 (delete-file sig-file))))
169 ;;; @ Internal method for application/pgp-encrypted
171 ;;; It is based on RFC 2015 (PGP/MIME) and
172 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
174 (defun mime-decrypt-application/pgp-encrypted (entity situation)
175 (let* ((entity-node-id (mime-entity-node-id entity))
176 (mother (mime-entity-parent entity))
177 (knum (car entity-node-id))
181 (orig-entity (nth onum (mime-entity-children mother))))
182 (mime-view-application/pgp orig-entity situation)))
185 ;;; @ Internal method for application/pgp-keys
187 ;;; It is based on RFC 2015 (PGP/MIME) and
188 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
190 (defun mime-add-application/pgp-keys (entity situation)
192 (mime-show-echo-buffer)
193 (set-buffer mime-echo-buffer-name)
195 (get-buffer-window mime-echo-buffer-name)
198 (mime-insert-entity-content entity)
199 (mime-decode-region (point-min) (point-max)
200 (cdr (assq 'encoding situation)))
201 (let ((status (pgg-snarf-keys-region (point-min)(point-max))))
203 (set-buffer mime-echo-buffer-name)
204 (insert-buffer-substring (if status pgg-output-buffer
205 pgg-errors-buffer))))))
208 ;;; @ Internal method for application/pkcs7-signature
210 ;;; It is based on RFC 2633 (S/MIME version 3).
212 (defun mime-verify-application/pkcs7-signature (entity situation)
213 "Internal method to check S/MIME signature."
214 (let* ((entity-node-id (mime-entity-node-id entity))
215 (mother (mime-entity-parent entity))
216 (knum (car entity-node-id))
220 (orig-entity (nth onum (mime-entity-children mother)))
221 (sig-file (make-temp-file "tm" nil ".asc"))
224 (mime-show-echo-buffer)
225 (set-buffer mime-echo-buffer-name)
227 (get-buffer-window mime-echo-buffer-name)
229 (mime-write-entity entity sig-file)
232 (mime-insert-entity orig-entity)
233 (goto-char (point-min))
234 (while (progn (end-of-line) (not (eobp)))
237 (setq status (smime-verify-region (point-min)(point-max)
240 (set-buffer mime-echo-buffer-name)
241 (insert-buffer-substring (if status smime-output-buffer
242 smime-errors-buffer))))
243 (delete-file sig-file))))
246 ;;; @ Internal method for application/pkcs7-mime
248 ;;; It is based on RFC 2633 (S/MIME version 3).
250 (defun mime-view-application/pkcs7-mime (entity situation)
251 (let* ((p-win (or (get-buffer-window (current-buffer))
252 (get-largest-window)))
254 (format "%s-%s" (buffer-name) (mime-entity-number entity)))
255 (mother (current-buffer))
256 (preview-buffer (concat "*Preview-" (buffer-name) "*"))
258 (when (memq (or (cdr (assq 'smime-type situation)) 'enveloped-data)
259 '(enveloped-data signed-data))
260 (set-buffer (setq message-buf (get-buffer-create new-name)))
261 (let ((inhibit-read-only t)
264 (mime-insert-entity entity)
265 (smime-decrypt-region (point-min)(point-max))
266 (delete-region (point-min)(point-max))
267 (insert-buffer smime-output-buffer))
268 (setq major-mode 'mime-show-message-mode)
269 (save-window-excursion
270 (mime-view-buffer nil preview-buffer mother
272 (make-local-variable 'mime-view-temp-message-buffer)
273 (setq mime-view-temp-message-buffer message-buf))
274 (set-window-buffer p-win preview-buffer))))
282 (run-hooks 'mime-pgp-load-hook)
284 ;;; mime-pgp.el ends here