annotate lisp/w3/ssl.el @ 118:7d55a9ba150c r20-1b11

Import from CVS: tag r20-1b11
author cvs
date Mon, 13 Aug 2007 09:24:17 +0200
parents 8d2a9b52c682
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; ssl.el,v --- ssl functions for emacsen without them builtin
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2 ;; Author: wmperry
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
3 ;; Created: 1997/03/31 16:22:42
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
4 ;; Version: 1.14
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Keywords: comm
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1995, 1996 by William M. Perry (wmperry@cs.indiana.edu)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
10 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ;;; any later version.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
29 (require 'cl)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
30 (require 'base64)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
31
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
32 (eval-and-compile
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
33 (condition-case ()
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
34 (require 'custom)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
35 (error nil))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
36 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
37 nil ;; We've got what we needed
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
38 ;; We have the old custom-library, hack around it!
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
39 (defmacro defgroup (&rest args)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
40 nil)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
41 (defmacro defcustom (var value doc &rest args)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
42 (` (defvar (, var) (, value) (, doc))))))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
43
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
44 (defgroup ssl nil
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
45 "Support for `Secure Sockets Layer' encryption."
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
46 :group 'comm)
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
47
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
48 (defcustom ssl-certificate-directory "~/.w3/certs/"
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
49 "*Directory to store CA certificates in"
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
50 :group 'ssl
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
51 :type 'directory)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
52
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
53 (defcustom ssl-rehash-program-name "c_rehash"
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
54 "*Program to run after adding a cert to a directory .
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
55 Run with one argument, the directory name."
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
56 :group 'ssl
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
57 :type 'string)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
58
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
59 (defcustom ssl-view-certificate-program-name "x509"
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
60 "*The program to run to provide a human-readable view of a certificate."
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
61 :group 'ssl
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
62 :type 'string)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
63
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
64 (defcustom ssl-view-certificate-program-arguments '("-text" "-inform" "DER")
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
65 "*Arguments that should be passed to the certificate viewing program.
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
66 The certificate is piped to it.
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
67 Maybe a way of passing a file should be implemented"
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
68 :group 'ssl
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
69 :type 'list)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
70
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
71 (defcustom ssl-certificate-directory-style 'ssleay
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
72 "*Style of cert database to use, the only valid value right now is `ssleay'.
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
73 This means a directory of pem encoded certificates with hash symlinks."
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
74 :group 'ssl
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
75 :type '(choice (const :tag "SSLeay" :value ssleay)))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
76
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
77 (defcustom ssl-certificate-verification-policy 0
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
78 "*How far up the certificate chain we should verify."
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
79 :group 'ssl
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
80 :type '(choice (const :tag "No verification" :value 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
81 (const :tag "Verification required" :value 1)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
82 (const :tag "Reject connection if verification fails" :value 3)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
83 (const :tag "SSL_VERIFY_CLIENT_ONCE" :value 5)))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
84
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
85 (defcustom ssl-program-name "s_client"
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
86 "*The program to run in a subprocess to open an SSL connection."
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
87 :group 'ssl
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
88 :type 'string)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
89
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
90 (defcustom ssl-program-arguments
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
91 '(;;"-quiet"
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
92 "-host" host
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
93 "-port" service
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 44
diff changeset
94 "-verify" (int-to-string ssl-certificate-verification-policy)
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
95 "-CApath" ssl-certificate-directory
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
96 )
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
97 "*Arguments that should be passed to the program `ssl-program-name'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
98 This should be used if your SSL program needs command line switches to
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
99 specify any behaviour (certificate file locations, etc).
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
100 The special symbols 'host and 'port may be used in the list of arguments
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
101 and will be replaced with the hostname and service/port that will be connected
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
102 to."
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
103 :group 'ssl
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
104 :type 'list)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
105
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
106 (defun ssl-accept-ca-certificate ()
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
107 "Ask if the user is willing to accept a new CA certificate. The buffer-name
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
108 should be the intended name of the certificate, and the buffer should probably
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
109 be in DER encoding"
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
110 ;; TODO, check if it is really new or if we already know it
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
111 (let* ((process-connection-type nil)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
112 (tmpbuf (generate-new-buffer "X509 CA Certificate Information"))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
113 (response (save-excursion
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
114 (and (eq 0
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
115 (apply 'call-process-region
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
116 (point-min) (point-max)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
117 ssl-view-certificate-program-name
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
118 nil tmpbuf t
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
119 ssl-view-certificate-program-arguments))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
120 (switch-to-buffer tmpbuf)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
121 (goto-char (point-min))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
122 (or (recenter) t)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
123 (yes-or-no-p
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
124 "Accept this CA to vouch for secure server identities? ")
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
125 (kill-buffer tmpbuf)))))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
126 (if (not response)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
127 nil
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
128 (if (not (file-directory-p ssl-certificate-directory))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
129 (make-directory ssl-certificate-directory))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
130 (case ssl-certificate-directory-style
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
131 (ssleay
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
132 (base64-encode-region (point-min) (point-max))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
133 (goto-char (point-min))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
134 (insert "-----BEGIN CERTIFICATE-----\n")
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
135 (goto-char (point-max))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
136 (insert "-----END CERTIFICATE-----\n")
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
137 (let ((f (expand-file-name
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
138 (concat (file-name-sans-extension (buffer-name)) ".pem")
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
139 ssl-certificate-directory)))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
140 (write-file f)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
141 (call-process ssl-rehash-program-name
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
142 nil nil nil
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
143 (expand-file-name ssl-certificate-directory))))))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 (defun open-ssl-stream (name buffer host service)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 "Open a SSL connection for a service to a host.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147 Returns a subprocess-object to represent the connection.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148 Input and output work as for subprocesses; `delete-process' closes it.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149 Args are NAME BUFFER HOST SERVICE.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150 NAME is name for process. It is modified if necessary to make it unique.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 BUFFER is the buffer (or buffer-name) to associate with the process.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 Process output goes at end of that buffer, unless you specify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 an output stream or filter function to handle the output.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
154 BUFFER may be also nil, meaning that this process is not associated
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155 with any buffer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 Third arg is name of the host to connect to, or its IP address.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 Fourth arg SERVICE is name of the service desired, or an integer
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
158 specifying a port number to connect to."
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
159 (if (integerp service) (setq service (int-to-string service)))
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
160 (let* ((process-connection-type nil)
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
161 (port service)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
162 (proc (eval
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
163 (`
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
164 (start-process name buffer ssl-program-name
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 22
diff changeset
165 (,@ ssl-program-arguments))))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
166 (process-kill-without-query proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
167 proc))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
168
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
169 (provide 'ssl)