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;
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)
62 ;;; @ Internal method for multipart/signed
64 ;;; It is based on RFC 1847 (security-multipart).
66 (defun mime-verify-multipart/signed (entity situation)
67 "Internal method to verify multipart/signed."
69 (nth 1 (mime-entity-children entity)) ; entity-info of signature
70 (list (assq 'mode situation)) ; play-mode
74 ;;; @ internal method for application/pgp
76 ;;; It is based on draft-kazu-pgp-mime-00.txt (PGP-kazu).
78 (defun mime-view-application/pgp (entity situation)
79 (let* ((p-win (or (get-buffer-window (current-buffer))
80 (get-largest-window)))
82 (format "%s-%s" (buffer-name) (mime-entity-number entity)))
83 (mother (current-buffer))
84 (preview-buffer (concat "*Preview-" (buffer-name) "*"))
86 (set-buffer (get-buffer-create new-name))
88 (mime-insert-entity entity)
90 (goto-char (point-min))
91 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
92 (pgg-verify-region (match-beginning 0)(point-max) nil 'fetch)
93 (goto-char (point-min))
97 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
100 (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
103 (goto-char (point-min))
104 (while (re-search-forward "^- -" nil t)
107 (setq representation-type (if (mime-entity-cooked-p entity)
111 (goto-char (point-min))
112 (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t))
113 (pgg-decrypt-region (point-min)(point-max))
114 (delete-region (point-min)(point-max))
115 (insert-buffer pgg-output-buffer)
116 (setq representation-type 'binary)
118 (setq major-mode 'mime-show-message-mode)
119 (save-window-excursion (mime-view-buffer nil preview-buffer mother
120 nil representation-type))
121 (set-window-buffer p-win preview-buffer)
125 ;;; @ Internal method for application/pgp-signature
127 ;;; It is based on RFC 2015 (PGP/MIME) and
128 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
130 (defun mime-verify-application/pgp-signature (entity situation)
131 "Internal method to check PGP/MIME signature."
132 (let* ((entity-node-id (mime-entity-node-id entity))
133 (mother (mime-entity-parent entity))
134 (knum (car entity-node-id))
138 (orig-entity (nth onum (mime-entity-children mother)))
139 (basename (expand-file-name "tm" temporary-file-directory))
140 (sig-file (concat (make-temp-name basename) ".asc"))
142 (save-excursion (mime-show-echo-buffer))
143 (mime-write-entity-content entity sig-file)
146 (mime-insert-entity orig-entity)
147 (goto-char (point-min))
148 (while (progn (end-of-line) (not (eobp)))
151 (setq status (pgg-verify-region (point-min)(point-max)
154 (set-buffer mime-echo-buffer-name)
155 (insert-buffer-substring (if status pgg-output-buffer
156 pgg-errors-buffer))))
157 (delete-file sig-file))
158 (let ((other-window-scroll-buffer mime-echo-buffer-name))
159 (scroll-other-window 8)
164 ;;; @ Internal method for application/pgp-encrypted
166 ;;; It is based on RFC 2015 (PGP/MIME) and
167 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
169 (defun mime-decrypt-application/pgp-encrypted (entity situation)
170 (let* ((entity-node-id (mime-entity-node-id entity))
171 (mother (mime-entity-parent entity))
172 (knum (car entity-node-id))
176 (orig-entity (nth onum (mime-entity-children mother))))
177 (mime-view-application/pgp orig-entity situation)
181 ;;; @ Internal method for application/pgp-keys
183 ;;; It is based on RFC 2015 (PGP/MIME) and
184 ;;; draft-yamamoto-openpgp-mime-00.txt (OpenPGP/MIME).
186 (defun mime-add-application/pgp-keys (entity situation)
187 (save-excursion (mime-show-echo-buffer))
189 (mime-insert-entity-content entity)
190 (mime-decode-region (point-min) (point-max)
191 (cdr (assq 'encoding situation)))
192 (let ((status (pgg-snarf-keys-region (point-min)(point-max))))
194 (set-buffer mime-echo-buffer-name)
195 (insert-buffer-substring (if status pgg-output-buffer
198 (let ((other-window-scroll-buffer mime-echo-buffer-name))
199 (scroll-other-window 8)
208 (run-hooks 'mime-pgp-load-hook)
210 ;;; mime-pgp.el ends here