annotate lisp/url/url-pgp.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; url-pgp.el,v --- PGP Uniform Resource Locator retrieval code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Author: wmperry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Created: 1996/05/24 15:27:10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Version: 1.3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: comm, data, processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1993, 1994, 1995 by William M. Perry (wmperry@spry.com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; This file is not part of GNU Emacs, but the same permissions apply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (require 'url-vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (require 'url-parse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; UUencoding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; ----------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; These functions are needed for the (RI)PEM encoding. PGP can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; handle binary data, but (RI)PEM requires that it be uuencoded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; first, or it will barf severely. How rude.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defun url-uuencode-buffer (&optional buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 "UUencode buffer BUFF, with a default of the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (setq buff (or buff (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (set-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (url-lazy-message "UUencoding...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (call-process-region (point-min) (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 url-uuencode-program t t nil "url-temp-file")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (url-lazy-message "UUencoding... done.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defun url-uudecode-buffer (&optional buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "UUdecode buffer BUFF, with a default of the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (setq buff (or buff (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (let ((newname (url-generate-unique-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (set-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (re-search-forward "^begin [0-9][0-9][0-9] \\(.*\\)$" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (replace-match (concat "begin 600 " newname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (url-lazy-message "UUdecoding...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (call-process-region (point-min) (point-max) url-uudecode-program)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (url-lazy-message "UUdecoding...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (insert-file-contents-literally newname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (url-lazy-message "UUdecoding... done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (delete-file newname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (error nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; Decoding PGP/PEM responses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; --------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; A PGP/PEM encrypted/signed response contains all the real headers,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; so this is just a quick decrypt-then-reparse hack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defun url-decode-pgp/pem (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Decode a pgp/pem response from an HTTP/1.0 server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 This expects the decoded message to contain all the necessary HTTP/1.0 headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 to correctly act on the decoded message (new content-type, etc)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (mc-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (url-parse-mime-headers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;; PGP/PEM Encryption
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; ------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; This implements the highly secure PGP/PEM encrypted requests, as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; specified by NCSA and CERN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; The complete online spec of this scheme was done by Tony Sanders
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; <sanders@bsdi.com>, and can be seen at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; http://www.bsdi.com/HTTP:TNG/ripem-http.txt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; This section of code makes use of the EXCELLENT mailcrypt.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;; package by Jin S Choi (jsc@mit.edu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defun url-public-key-exists (entity scheme)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "Return t iff a key for ENTITY exists using public key system SCHEME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ENTITY is the username/hostname combination we are checking for.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 SCHEME is a symbol representing what public key encryption program to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 Currently only 'pgp (Pretty Good Privacy) and 'pem (RIPEM) are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 recognized."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (let (retval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ((eq 'pgp scheme) ; PGP encryption
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (set-buffer (get-buffer-create " *keytmp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (call-process mc-pgp-path nil t nil "+batchmode" "-kxaf" entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (setq retval (search-forward mc-pgp-key-begin-line nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ((eq 'pem scheme) ; PEM encryption
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (set-buffer (find-file-noselect mc-ripem-pubkeyfile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (setq retval (search-forward entity nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (url-warn 'security
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 "Bad value for SCHEME in url-public-key-exists %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 scheme))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (kill-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defun url-get-server-keys (entity &optional scheme)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "Make sure the key for ENTITY exists using SCHEME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ENTITY is the username/hostname combination to get the info for.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 This should be a string you could pass to 'finger'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 SCHEME is a symbol representing what public key encryption program to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 Currently only 'pgp (Pretty Good Privacy) and 'pem (RIPEM) are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 recognized."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (or scheme (setq scheme mc-default-scheme))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ((url-public-key-exists entity scheme) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (string-match "\\([^@]+\\)@\\(.*\\)" entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (let ((url-working-buffer " *url-get-keys*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (url-retrieve (format "gopher://%s:79/0%s/w" (url-match entity 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (url-match entity 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (mc-snarf-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (kill-buffer url-working-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defun url-fetch-with-pgp (url recipient type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "Retrieve a document with public-key authentication.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 URL is the url to request from the server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 RECIPIENT is the server's entity name (usually webmaster@host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 TYPE is a symbol representing what public key encryption program to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Currently only 'pgp (Pretty Good Privacy) and 'pem (RIPEM) are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 recognized."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (or noninteractive (require 'mailcrypt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (let ((request (url-create-mime-request url "PGP-Redirect"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (url-request-data nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (url-request-extra-headers nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (url-get-server-keys recipient type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (set-buffer (get-buffer-create " *url-encryption*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (insert "\n\n" mail-header-separator "\n" request)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (mc-encrypt-message recipient type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (if (re-search-forward (concat "\n" mail-header-separator "\n") nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (delete-region (point-min) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq url-request-data (buffer-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 url-request-extra-headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (list (cons "Authorized" (format "%s entity=\"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ((eq type 'pgp) "PGP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ((eq type 'pem) "PEM"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 url-pgp/pem-entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (cons "Content-type" (format "application/x-www-%s-reply"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ((eq type 'pgp) "pgp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ((eq type 'pem) "pem")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (kill-buffer " *url-encryption*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (url-retrieve (url-expand-file-name "/") t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (provide 'url-pgp)