Mercurial > emacs
annotate lisp/net/gnutls.el @ 110640:f7f67bd95f3d
Minor diary-lib change.
* lisp/calendar/diary-lib.el (diary-list-entries): Move the
"Preparing..." message entirely here.
(diary-simple-display, diary-fancy-display): Move "Preparing..."
messages to diary-list-entries.
(diary-include-other-diary-files): Use LIST-ONLY rather than setting
diary-display-function.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 28 Sep 2010 21:10:34 -0700 |
parents | 6c735824d0c1 |
children | 256dd50b2a63 |
rev | line source |
---|---|
110584 | 1 ;;; gnutls.el --- Support SSL and TLS connections through GnuTLS |
2 ;; Copyright (C) 2010 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Ted Zlatanov <tzz@lifelogs.com> | |
5 ;; Keywords: comm, tls, ssl, encryption | |
6 ;; Originally-By: Simon Josefsson (See http://josefsson.org/emacs-security/) | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation, either version 3 of the License, or | |
13 ;; (at your option) any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
22 | |
23 ;;; Commentary: | |
24 | |
25 ;; This package provides language bindings for the GnuTLS library | |
26 ;; using the corresponding core functions in gnutls.c. | |
27 | |
28 ;; Simple test: | |
29 ;; | |
30 ;; (setq jas (open-ssl-stream "ssl" (current-buffer) "www.pdc.kth.se" 443)) | |
31 ;; (process-send-string jas "GET /\r\n\r\n") | |
32 | |
33 ;;; Code: | |
34 | |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
35 (defgroup gnutls nil |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
36 "Emacs interface to the GnuTLS library." |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
37 :prefix "gnutls-" |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
38 :group 'net-utils) |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
39 |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
40 (defcustom gnutls-log-level 2 |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
41 "Logging level to be used by `starttls-negotiate' and GnuTLS." |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
42 :type 'integer |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
43 :group 'gnutls) |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
44 |
110584 | 45 (defun open-ssl-stream (name buffer host service) |
46 "Open a SSL connection for a service to a host. | |
47 Returns a subprocess-object to represent the connection. | |
48 Input and output work as for subprocesses; `delete-process' closes it. | |
49 Args are NAME BUFFER HOST SERVICE. | |
50 NAME is name for process. It is modified if necessary to make it unique. | |
51 BUFFER is the buffer (or `buffer-name') to associate with the process. | |
52 Process output goes at end of that buffer, unless you specify | |
53 an output stream or filter function to handle the output. | |
54 BUFFER may be also nil, meaning that this process is not associated | |
55 with any buffer | |
56 Third arg is name of the host to connect to, or its IP address. | |
57 Fourth arg SERVICE is name of the service desired, or an integer | |
58 specifying a port number to connect to." | |
59 (let ((proc (open-network-stream name buffer host service))) | |
60 (starttls-negotiate proc nil 'gnutls-x509pki))) | |
61 | |
62 ;; (open-ssl-stream "tls" "tls-buffer" "yourserver.com" "https") | |
63 (defun starttls-negotiate (proc &optional priority-string | |
64 credentials credentials-file) | |
65 "Negotiate a SSL or TLS connection. | |
66 PROC is the process returned by `starttls-open-stream'. | |
67 PRIORITY-STRING is as per the GnuTLS docs. | |
68 CREDENTIALS is `gnutls-x509pki' or `gnutls-anon'. | |
69 CREDENTIALS-FILE is a filename with meaning dependent on CREDENTIALS." | |
70 (let* ((credentials (or credentials 'gnutls-x509pki)) | |
71 (credentials-file (or credentials-file | |
72 "/etc/ssl/certs/ca-certificates.crt" | |
73 ;"/etc/ssl/certs/ca.pem" | |
74 )) | |
75 | |
76 (priority-string (or priority-string | |
77 (cond | |
78 ((eq credentials 'gnutls-anon) | |
79 "NORMAL:+ANON-DH:!ARCFOUR-128") | |
80 ((eq credentials 'gnutls-x509pki) | |
81 "NORMAL")))) | |
82 ret) | |
83 | |
84 (gnutls-message-maybe | |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
85 (setq ret (gnutls-boot proc priority-string |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
86 credentials credentials-file |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
87 nil nil gnutls-log-level)) |
110584 | 88 "boot: %s") |
89 | |
90 (when (gnutls-errorp ret) | |
91 (error "Could not boot GnuTLS for this process")); | |
92 | |
93 (let ((ret 'gnutls-e-again) | |
94 (n 25000)) | |
110606
b4f4c3e9b976
Add debugging to the gnutls library, and finish handshaking when it's done.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110591
diff
changeset
|
95 (while (and (not (eq ret t)) |
b4f4c3e9b976
Add debugging to the gnutls library, and finish handshaking when it's done.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110591
diff
changeset
|
96 (not (gnutls-error-fatalp ret)) |
110584 | 97 (> n 0)) |
110591
ab4cdde63001
(starttls-negotiate): Avoid the cl.el decf function.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110584
diff
changeset
|
98 (setq n (1- n)) |
110606
b4f4c3e9b976
Add debugging to the gnutls library, and finish handshaking when it's done.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110591
diff
changeset
|
99 (setq ret (gnutls-handshake proc)) |
110584 | 100 ) |
101 (if (gnutls-errorp ret) | |
102 (progn | |
103 (message "Ouch, error return %s (%s)" | |
104 ret (gnutls-error-string ret)) | |
105 (setq proc nil)) | |
106 (message "Handshake complete %s." ret))) | |
107 proc)) | |
108 | |
109 (defun starttls-open-stream (name buffer host service) | |
110 "Open a TLS connection for a service to a host. | |
111 Returns a subprocess-object to represent the connection. | |
112 Input and output work as for subprocesses; `delete-process' closes it. | |
113 Args are NAME BUFFER HOST SERVICE. | |
114 NAME is name for process. It is modified if necessary to make it unique. | |
115 BUFFER is the buffer (or `buffer-name') to associate with the process. | |
116 Process output goes at end of that buffer, unless you specify | |
117 an output stream or filter function to handle the output. | |
118 BUFFER may be also nil, meaning that this process is not associated | |
119 with any buffer | |
120 Third arg is name of the host to connect to, or its IP address. | |
121 Fourth arg SERVICE is name of the service desired, or an integer | |
122 specifying a port number to connect to." | |
123 (open-network-stream name buffer host service)) | |
124 | |
125 (defun gnutls-message-maybe (doit format &rest params) | |
126 "When DOIT, message with the caller name followed by FORMAT on PARAMS." | |
127 ;; (apply 'debug format (or params '(nil))) | |
128 (when (gnutls-errorp doit) | |
129 (message "%s: (err=[%s] %s) %s" | |
130 "gnutls.el" | |
131 doit (gnutls-error-string doit) | |
132 (apply 'format format (or params '(nil)))))) | |
133 | |
134 (provide 'ssl) | |
135 (provide 'gnutls) | |
136 (provide 'starttls) | |
137 | |
138 ;;; gnutls.el ends here |