annotate lisp/net/tls.el @ 79838:2ec37d0d0d39

(c-guess-basic-syntax): prevent a macro call inside a struct being recognised as a K&R argument.
author Alan Mackenzie <acm@muc.de>
date Mon, 14 Jan 2008 19:17:31 +0000
parents 6888fd3398e8
children eaecf88d90b5 107ccd98fa12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
1 ;;; tls.el --- TLS/SSL support via wrapper around GnuTLS
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
2
64701
34bd8e434dd7 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2002, 2003, 2004,
79714
6888fd3398e8 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 79332
diff changeset
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
5
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
6 ;; Author: Simon Josefsson <simon@josefsson.org>
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
7 ;; Keywords: comm, tls, gnutls, ssl
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
8
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
10
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78230
84cf1e2214c5 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 77021
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
14 ;; any later version.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
15
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
20
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62437
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62437
diff changeset
24 ;; Boston, MA 02110-1301, USA.
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
25
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
26 ;;; Commentary:
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
27
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
28 ;; This package implements a simple wrapper around "gnutls-cli" to
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
29 ;; make Emacs support TLS/SSL.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
30 ;;
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
31 ;; Usage is the same as `open-network-stream', i.e.:
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
32 ;;
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
33 ;; (setq tmp (open-tls-stream "test" (current-buffer) "news.mozilla.org" 563))
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
34 ;; ...
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
35 ;; #<process test>
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
36 ;; (process-send-string tmp "mode reader\n")
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
37 ;; 200 secnews.netscape.com Netscape-Collabra/3.52 03615 NNRP ready ...
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
38 ;; nil
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
39 ;; (process-send-string tmp "quit\n")
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
40 ;; 205
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
41 ;; nil
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
42
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
43 ;; To use this package as a replacement for ssl.el by William M. Perry
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
44 ;; <wmperry@cs.indiana.edu>, you need to evaluate the following:
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
45 ;;
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
46 ;; (defalias 'open-ssl-stream 'open-tls-stream)
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
47
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
48 ;;; Code:
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
49
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
50 (eval-and-compile
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
51 (autoload 'format-spec "format-spec")
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
52 (autoload 'format-spec-make "format-spec"))
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
53
79332
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
54 (eval-when-compile
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
55 (require 'rx))
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
56
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
57 (defgroup tls nil
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
58 "Transport Layer Security (TLS) parameters."
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
59 :group 'comm)
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
60
79332
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
61 (defcustom tls-end-of-info
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
62 (rx
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
63 (or
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
64 ;; `openssl s_client` regexp
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
65 (sequence
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
66 ;; see ssl/ssl_txt.c lines 219--220
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
67 line-start
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
68 " Verify return code: "
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
69 (one-or-more not-newline)
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
70 "\n"
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
71 ;; according to apps/s_client.c line 1515 this is always the last
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
72 ;; line that is printed by s_client before the real data
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
73 "---\n")
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
74 ;; `gnutls` regexp
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
75 (sequence
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
76 ;; see src/cli.c lines 721--
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
77 (sequence line-start "- Simple Client Mode:\n")
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
78 (zero-or-more
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
79 (or
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
80 "\n" ; ignore blank lines
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
81 ;; XXX: we have no way of knowing if the STARTTLS handshake
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
82 ;; sequence has completed successfully, because `gnutls` will
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
83 ;; only report failure.
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
84 (sequence line-start "\*\*\* Starting TLS handshake\n"))))))
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
85 "Regexp matching end of TLS client informational messages.
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
86 Client data stream begins after the last character matched by
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
87 this. The default matches `openssl s_client' (version 0.9.8c)
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
88 and `gnutls-cli' (version 2.0.1) output."
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
89 :version "22.2"
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
90 :type 'regexp
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
91 :group 'tls)
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
92
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
93 (defcustom tls-program '("gnutls-cli -p %p %h"
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
94 "gnutls-cli -p %p %h --protocols ssl3"
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
95 "openssl s_client -connect %h:%p -no_ssl2")
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
96 "List of strings containing commands to start TLS stream to a host.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
97 Each entry in the list is tried until a connection is successful.
76521
dc6ada4b3839 (tls-program): Doc fix.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 76125
diff changeset
98 %h is replaced with server hostname, %p with port to connect to.
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
99 The program should read input on stdin and write output to
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
100 stdout. Also see `tls-success' for what the program should output
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
101 after successful negotiation."
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
102 :type '(repeat string)
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
103 :version "22.1"
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
104 :group 'tls)
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
105
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
106 (defcustom tls-process-connection-type nil
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
107 "*Value for `process-connection-type' to use when starting TLS process."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
108 :version "22.1"
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
109 :type 'boolean
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
110 :group 'tls)
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
111
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
112 (defcustom tls-success "- Handshake was completed\\|SSL handshake has read "
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
113 "*Regular expression indicating completed TLS handshakes.
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
114 The default is what GNUTLS's \"gnutls-cli\" or OpenSSL's
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
115 \"openssl s_client\" outputs."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
116 :version "22.1"
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
117 :type 'regexp
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
118 :group 'tls)
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
119
57448
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
120 (defcustom tls-certtool-program (executable-find "certtool")
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
121 "Name of GnuTLS certtool.
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
122 Used by `tls-certificate-information'."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
123 :version "22.1"
76125
428a3ee993db (tls-certtool-program): Fix custom type.
John Paul Wallington <jpw@pobox.com>
parents: 75347
diff changeset
124 :type 'string
57448
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
125 :group 'tls)
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
126
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
127 (defun tls-certificate-information (der)
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
128 "Parse X.509 certificate in DER format into an assoc list."
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
129 (let ((certificate (concat "-----BEGIN CERTIFICATE-----\n"
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
130 (base64-encode-string der)
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
131 "\n-----END CERTIFICATE-----\n"))
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
132 (exit-code 0))
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
133 (with-current-buffer (get-buffer-create " *certtool*")
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
134 (erase-buffer)
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
135 (insert certificate)
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
136 (setq exit-code (condition-case ()
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
137 (call-process-region (point-min) (point-max)
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
138 tls-certtool-program
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
139 t (list (current-buffer) nil) t
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
140 "--certificate-info")
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
141 (error -1)))
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
142 (if (/= exit-code 0)
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
143 nil
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
144 (let ((vals nil))
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
145 (goto-char (point-min))
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
146 (while (re-search-forward "^\\([^:]+\\): \\(.*\\)" nil t)
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
147 (push (cons (match-string 1) (match-string 2)) vals))
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
148 (nreverse vals))))))
821d95294db5 (tls-certtool-program): New variable.
Simon Josefsson <jas@extundo.com>
parents: 56927
diff changeset
149
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
150 (defun open-tls-stream (name buffer host port)
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
151 "Open a TLS connection for a port to a host.
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
152 Returns a subprocess-object to represent the connection.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
153 Input and output work as for subprocesses; `delete-process' closes it.
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
154 Args are NAME BUFFER HOST PORT.
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
155 NAME is name for process. It is modified if necessary to make it unique.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
156 BUFFER is the buffer (or buffer-name) to associate with the process.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
157 Process output goes at end of that buffer, unless you specify
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
158 an output stream or filter function to handle the output.
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
159 BUFFER may be also nil, meaning that this process is not associated
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
160 with any buffer
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
161 Third arg is name of the host to connect to, or its IP address.
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
162 Fourth arg PORT is an integer specifying a port to connect to."
77020
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
163 (let ((cmds tls-program)
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
164 (use-temp-buffer (null buffer))
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
165 process cmd done)
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
166 (if use-temp-buffer
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
167 (setq buffer (generate-new-buffer " TLS")))
79332
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
168 (save-excursion
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
169 (set-buffer buffer)
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
170 (message "Opening TLS connection to `%s'..." host)
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
171 (while (and (not done) (setq cmd (pop cmds)))
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
172 (message "Opening TLS connection with `%s'..." cmd)
77020
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
173 (let ((process-connection-type tls-process-connection-type)
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
174 response)
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
175 (setq process (start-process
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
176 name buffer shell-file-name shell-command-switch
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
177 (format-spec
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
178 cmd
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
179 (format-spec-make
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
180 ?h host
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
181 ?p (if (integerp port)
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
182 (int-to-string port)
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64701
diff changeset
183 port)))))
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
184 (while (and process
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
185 (memq (process-status process) '(open run))
79332
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
186 (progn
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
187 (goto-char (point-min))
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
188 (not (setq done (re-search-forward tls-success nil t)))))
76538
a4570ccecc89 (open-tls-stream): In handshake-waiting loop,
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 76521
diff changeset
189 (unless (accept-process-output process 1)
79332
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
190 (sit-for 1)))
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
191 (message "Opening TLS connection with `%s'...%s" cmd
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
192 (if done "done" "failed"))
79332
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
193 (if (not done)
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
194 (delete-process process)
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
195 ;; advance point to after all informational messages that
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
196 ;; `openssl s_client' and `gnutls' print
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
197 (let ((start-of-data nil))
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
198 (while
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
199 (not (setq start-of-data
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
200 ;; the string matching `tls-end-of-info'
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
201 ;; might come in separate chunks from
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
202 ;; `accept-process-output', so start the
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
203 ;; search where `tls-success' ended
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
204 (save-excursion
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
205 (if (re-search-forward tls-end-of-info nil t)
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
206 (match-end 0)))))
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
207 (accept-process-output process 1))
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
208 (if start-of-data
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
209 ;; move point to start of client data
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
210 (goto-char start-of-data)))
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
211 (setq done process))))
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
212 (message "Opening TLS connection to `%s'...%s"
79332
3b71ad7b480c Riccardo Murri <riccardo.murri at gmail.com>
Glenn Morris <rgm@gnu.org>
parents: 78230
diff changeset
213 host (if done "done" "failed")))
77020
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
214 (when use-temp-buffer
77021
26293d3a753d Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 77020
diff changeset
215 (if done (set-process-buffer process nil))
77020
15108eee2bb3 Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 77019
diff changeset
216 (kill-buffer buffer))
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
217 done))
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
218
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
219 (provide 'tls)
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
220
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 50313
diff changeset
221 ;;; arch-tag: 5596d1c4-facc-4bc4-94a9-9863b928d7ac
50313
59ddec11881f Initial revision
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
222 ;;; tls.el ends here