annotate src/gnutls.c @ 110705:039bf20a0a30

Add minor comment (Bug#7001).
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 02 Oct 2010 19:10:41 -0400
parents 056ce44cedcd
children 3ccf1931ae33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
1 /* GnuTLS glue for GNU Emacs.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
2 Copyright (C) 2010 Free Software Foundation, Inc.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
3
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
5
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
6 GNU Emacs is free software: you can redistribute it and/or modify
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
8 the Free Software Foundation, either version 3 of the License, or
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
9 (at your option) any later version.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
10
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
14 GNU General Public License for more details.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
15
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
18
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
19 #include <config.h>
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
20 #include <errno.h>
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
21 #include <setjmp.h>
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
22
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
23 #include "lisp.h"
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
24 #include "process.h"
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
25
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
26 #ifdef HAVE_GNUTLS
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
27 #include <gnutls/gnutls.h>
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
28
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
29 Lisp_Object Qgnutls_code;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
30 Lisp_Object Qgnutls_anon, Qgnutls_x509pki;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
31 Lisp_Object Qgnutls_e_interrupted, Qgnutls_e_again,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
32 Qgnutls_e_invalid_session, Qgnutls_e_not_ready_for_handshake;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
33 int global_initialized;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
34
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
35 void
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
36 emacs_gnutls_handshake (struct Lisp_Process *proc)
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
37 {
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
38 gnutls_session_t state = proc->gnutls_state;
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
39 int ret;
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
40
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
41 if (proc->gnutls_initstage < GNUTLS_STAGE_HANDSHAKE_CANDO)
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
42 return;
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
43
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
44 if (proc->gnutls_initstage < GNUTLS_STAGE_TRANSPORT_POINTERS_SET)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
45 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
46 gnutls_transport_set_ptr2 (state,
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
47 (gnutls_transport_ptr_t) (long) proc->infd,
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
48 (gnutls_transport_ptr_t) (long) proc->outfd);
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
49
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
50 proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
51 }
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
52
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
53 ret = gnutls_handshake (state);
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
54 proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED;
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
55
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
56 if (ret == GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
57 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
58 /* here we're finally done. */
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
59 proc->gnutls_initstage = GNUTLS_STAGE_READY;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
60 }
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
61 }
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
62
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
63 int
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
64 emacs_gnutls_write (int fildes, struct Lisp_Process *proc, char *buf,
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
65 unsigned int nbyte)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
66 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
67 register int rtnval, bytes_written;
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
68 gnutls_session_t state = proc->gnutls_state;
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
69
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
70 if (proc->gnutls_initstage != GNUTLS_STAGE_READY)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
71 return -1;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
72
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
73 bytes_written = 0;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
74
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
75 while (nbyte > 0)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
76 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
77 rtnval = gnutls_write (state, buf, nbyte);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
78
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
79 if (rtnval == -1)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
80 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
81 if (errno == EINTR)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
82 continue;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
83 else
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
84 return (bytes_written ? bytes_written : -1);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
85 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
86
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
87 buf += rtnval;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
88 nbyte -= rtnval;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
89 bytes_written += rtnval;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
90 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
91 fsync (STDOUT_FILENO);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
92
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
93 return (bytes_written);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
94 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
95
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
96 int
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
97 emacs_gnutls_read (int fildes, struct Lisp_Process *proc, char *buf,
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
98 unsigned int nbyte)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
99 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
100 register int rtnval;
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
101 gnutls_session_t state = proc->gnutls_state;
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
102
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
103 if (proc->gnutls_initstage != GNUTLS_STAGE_READY)
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
104 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
105 emacs_gnutls_handshake (proc);
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
106 return -1;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
107 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
108
110608
06497cf3e920 (emacs_gnutls_read): Don't infloop while reading.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110606
diff changeset
109 rtnval = gnutls_read (state, buf, nbyte);
06497cf3e920 (emacs_gnutls_read): Don't infloop while reading.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110606
diff changeset
110 if (rtnval >= 0)
06497cf3e920 (emacs_gnutls_read): Don't infloop while reading.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110606
diff changeset
111 return rtnval;
06497cf3e920 (emacs_gnutls_read): Don't infloop while reading.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110606
diff changeset
112 else
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
113 return 0;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
114 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
115
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
116 /* convert an integer error to a Lisp_Object; it will be either a
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
117 known symbol like `gnutls_e_interrupted' and `gnutls_e_again' or
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
118 simply the integer value of the error. GNUTLS_E_SUCCESS is mapped
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
119 to Qt. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
120 Lisp_Object gnutls_make_error (int error)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
121 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
122 switch (error)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
123 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
124 case GNUTLS_E_SUCCESS:
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
125 return Qt;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
126 case GNUTLS_E_AGAIN:
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
127 return Qgnutls_e_again;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
128 case GNUTLS_E_INTERRUPTED:
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
129 return Qgnutls_e_interrupted;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
130 case GNUTLS_E_INVALID_SESSION:
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
131 return Qgnutls_e_invalid_session;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
132 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
133
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
134 return make_number (error);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
135 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
136
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
137 DEFUN ("gnutls-get-initstage", Fgnutls_get_initstage, Sgnutls_get_initstage, 1, 1, 0,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
138 doc: /* Return the GnuTLS init stage of PROCESS.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
139 See also `gnutls-boot'. */)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
140 (Lisp_Object proc)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
141 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
142 CHECK_PROCESS (proc);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
143
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
144 return make_number (GNUTLS_INITSTAGE (proc));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
145 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
146
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
147 DEFUN ("gnutls-errorp", Fgnutls_errorp, Sgnutls_errorp, 1, 1, 0,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
148 doc: /* Returns t if ERROR (as generated by gnutls_make_error)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
149 indicates a GnuTLS problem. */)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
150 (Lisp_Object error)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
151 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
152 if (EQ (error, Qt)) return Qnil;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
153
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
154 return Qt;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
155 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
156
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
157 DEFUN ("gnutls-error-fatalp", Fgnutls_error_fatalp, Sgnutls_error_fatalp, 1, 1, 0,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
158 doc: /* Checks if ERROR is fatal.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
159 ERROR is an integer or a symbol with an integer `gnutls-code' property. */)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
160 (Lisp_Object err)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
161 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
162 Lisp_Object code;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
163
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
164 if (EQ (err, Qt)) return Qnil;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
165
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
166 if (SYMBOLP (err))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
167 {
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
168 code = Fget (err, Qgnutls_code);
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
169 if (NUMBERP (code))
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
170 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
171 err = code;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
172 }
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
173 else
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
174 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
175 error ("Symbol has no numeric gnutls-code property");
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
176 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
177 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
178
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
179 if (!NUMBERP (err))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
180 error ("Not an error symbol or code");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
181
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
182 if (0 == gnutls_error_is_fatal (XINT (err)))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
183 return Qnil;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
184
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
185 return Qt;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
186 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
187
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
188 DEFUN ("gnutls-error-string", Fgnutls_error_string, Sgnutls_error_string, 1, 1, 0,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
189 doc: /* Returns a description of ERROR.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
190 ERROR is an integer or a symbol with an integer `gnutls-code' property. */)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
191 (Lisp_Object err)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
192 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
193 Lisp_Object code;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
194
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
195 if (EQ (err, Qt)) return build_string ("Not an error");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
196
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
197 if (SYMBOLP (err))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
198 {
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
199 code = Fget (err, Qgnutls_code);
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
200 if (NUMBERP (code))
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
201 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
202 err = code;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
203 }
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
204 else
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
205 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
206 return build_string ("Symbol has no numeric gnutls-code property");
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
207 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
208 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
209
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
210 if (!NUMBERP (err))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
211 return build_string ("Not an error symbol or code");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
212
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
213 return build_string (gnutls_strerror (XINT (err)));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
214 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
215
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
216 DEFUN ("gnutls-deinit", Fgnutls_deinit, Sgnutls_deinit, 1, 1, 0,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
217 doc: /* Deallocate GNU TLS resources associated with PROCESS.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
218 See also `gnutls-init'. */)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
219 (Lisp_Object proc)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
220 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
221 gnutls_session_t state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
222
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
223 CHECK_PROCESS (proc);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
224 state = XPROCESS (proc)->gnutls_state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
225
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
226 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
227 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
228 gnutls_deinit (state);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
229 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1;
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
230 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
231
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
232 return Qt;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
233 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
234
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
235 /* Initializes global GNU TLS state to defaults.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
236 Call `gnutls-global-deinit' when GNU TLS usage is no longer needed.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
237 Returns zero on success. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
238 Lisp_Object gnutls_emacs_global_init (void)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
239 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
240 int ret = GNUTLS_E_SUCCESS;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
241
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
242 if (!global_initialized)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
243 ret = gnutls_global_init ();
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
244
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
245 global_initialized = 1;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
246
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
247 return gnutls_make_error (ret);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
248 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
249
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
250 /* Deinitializes global GNU TLS state.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
251 See also `gnutls-global-init'. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
252 Lisp_Object gnutls_emacs_global_deinit (void)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
253 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
254 if (global_initialized)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
255 gnutls_global_deinit ();
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
256
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
257 global_initialized = 0;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
258
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
259 return gnutls_make_error (GNUTLS_E_SUCCESS);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
260 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
261
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
262 static void gnutls_log_function (int level, const char* string)
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
263 {
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
264 message("gnutls.c: [%d] %s", level, string);
110606
b4f4c3e9b976 Add debugging to the gnutls library, and finish handshaking when it's done.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110584
diff changeset
265 }
b4f4c3e9b976 Add debugging to the gnutls library, and finish handshaking when it's done.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110584
diff changeset
266
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
267 DEFUN ("gnutls-boot", Fgnutls_boot, Sgnutls_boot, 3, 7, 0,
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
268 doc: /* Initializes client-mode GnuTLS for process PROC.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
269 Currently only client mode is supported. Returns a success/failure
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
270 value you can check with `gnutls-errorp'.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
271
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
272 PRIORITY_STRING is a string describing the priority.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
273 TYPE is either `gnutls-anon' or `gnutls-x509pki'.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
274 TRUSTFILE is a PEM encoded trust file for `gnutls-x509pki'.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
275 KEYFILE is ... for `gnutls-x509pki' (TODO).
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
276 CALLBACK is ... for `gnutls-x509pki' (TODO).
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
277 LOGLEVEL is the debug level requested from GnuTLS, try 4.
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
278
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
279 LOGLEVEL will be set for this process AND globally for GnuTLS. So if
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
280 you set it higher or lower at any point, it affects global debugging.
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
281
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
282 Note that the priority is set on the client. The server does not use
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
283 the protocols's priority except for disabling protocols that were not
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
284 specified.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
285
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
286 Processes must be initialized with this function before other GNU TLS
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
287 functions are used. This function allocates resources which can only
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
288 be deallocated by calling `gnutls-deinit' or by calling it again.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
289
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
290 Each authentication type may need additional information in order to
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
291 work. For X.509 PKI (`gnutls-x509pki'), you need TRUSTFILE and
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
292 KEYFILE and optionally CALLBACK. */)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
293 (Lisp_Object proc, Lisp_Object priority_string, Lisp_Object type,
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
294 Lisp_Object trustfile, Lisp_Object keyfile, Lisp_Object callback,
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
295 Lisp_Object loglevel)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
296 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
297 int ret = GNUTLS_E_SUCCESS;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
298
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
299 int max_log_level = 0;
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
300
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
301 /* TODO: GNUTLS_X509_FMT_DER is also an option. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
302 int file_format = GNUTLS_X509_FMT_PEM;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
303
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
304 gnutls_session_t state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
305 gnutls_certificate_credentials_t x509_cred;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
306 gnutls_anon_client_credentials_t anon_cred;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
307 Lisp_Object global_init;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
308
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
309 CHECK_PROCESS (proc);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
310 CHECK_SYMBOL (type);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
311 CHECK_STRING (priority_string);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
312
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
313 state = XPROCESS (proc)->gnutls_state;
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
314 XPROCESS (proc)->gnutls_p = 1;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
315
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
316 if (NUMBERP (loglevel))
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
317 {
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
318 gnutls_global_set_log_function (gnutls_log_function);
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
319 gnutls_global_set_log_level (XINT (loglevel));
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
320 max_log_level = XINT (loglevel);
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
321 XPROCESS (proc)->gnutls_log_level = max_log_level;
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
322 }
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
323
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
324 /* always initialize globals. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
325 global_init = gnutls_emacs_global_init ();
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
326 if (! NILP (Fgnutls_errorp (global_init)))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
327 return global_init;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
328
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
329 /* deinit and free resources. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
330 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_CRED_ALLOC)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
331 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
332 GNUTLS_LOG (1, max_log_level, "deallocating credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
333
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
334 if (EQ (type, Qgnutls_x509pki))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
335 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
336 GNUTLS_LOG (2, max_log_level, "deallocating x509 credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
337 x509_cred = XPROCESS (proc)->gnutls_x509_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
338 gnutls_certificate_free_credentials (x509_cred);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
339 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
340 else if (EQ (type, Qgnutls_anon))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
341 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
342 GNUTLS_LOG (2, max_log_level, "deallocating anon credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
343 anon_cred = XPROCESS (proc)->gnutls_anon_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
344 gnutls_anon_free_client_credentials (anon_cred);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
345 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
346 else
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
347 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
348 error ("unknown credential type");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
349 ret = GNUTLS_EMACS_ERROR_INVALID_TYPE;
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
350 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
351
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
352 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
353 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
354 GNUTLS_LOG (1, max_log_level, "deallocating x509 credentials");
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
355 Fgnutls_deinit (proc);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
356 }
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
357 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
358
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
359 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
360
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
361 GNUTLS_LOG (1, max_log_level, "allocating credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
362
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
363 if (EQ (type, Qgnutls_x509pki))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
364 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
365 GNUTLS_LOG (2, max_log_level, "allocating x509 credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
366 x509_cred = XPROCESS (proc)->gnutls_x509_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
367 if (gnutls_certificate_allocate_credentials (&x509_cred) < 0)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
368 memory_full ();
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
369 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
370 else if (EQ (type, Qgnutls_anon))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
371 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
372 GNUTLS_LOG (2, max_log_level, "allocating anon credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
373 anon_cred = XPROCESS (proc)->gnutls_anon_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
374 if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
375 memory_full ();
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
376 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
377 else
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
378 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
379 error ("unknown credential type");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
380 ret = GNUTLS_EMACS_ERROR_INVALID_TYPE;
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
381 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
382
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
383 if (ret < GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
384 return gnutls_make_error (ret);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
385
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
386 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_ALLOC;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
387
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
388 if (EQ (type, Qgnutls_x509pki))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
389 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
390 if (STRINGP (trustfile))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
391 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
392 GNUTLS_LOG (1, max_log_level, "setting the trustfile");
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
393 ret = gnutls_certificate_set_x509_trust_file
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
394 (x509_cred,
110636
31e098898561 * src/gnutls.c (Fgnutls_boot): Remove unused vars `data' and `srp_cred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110611
diff changeset
395 SDATA (trustfile),
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
396 file_format);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
397
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
398 if (ret < GNUTLS_E_SUCCESS)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
399 return gnutls_make_error (ret);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
400 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
401
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
402 if (STRINGP (keyfile))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
403 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
404 GNUTLS_LOG (1, max_log_level, "setting the keyfile");
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
405 ret = gnutls_certificate_set_x509_crl_file
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
406 (x509_cred,
110636
31e098898561 * src/gnutls.c (Fgnutls_boot): Remove unused vars `data' and `srp_cred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110611
diff changeset
407 SDATA (keyfile),
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
408 file_format);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
409
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
410 if (ret < GNUTLS_E_SUCCESS)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
411 return gnutls_make_error (ret);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
412 }
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
413 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
414
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
415 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
416
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
417 GNUTLS_LOG (1, max_log_level, "gnutls_init");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
418
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
419 ret = gnutls_init (&state, GNUTLS_CLIENT);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
420
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
421 if (ret < GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
422 return gnutls_make_error (ret);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
423
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
424 XPROCESS (proc)->gnutls_state = state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
425
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
426 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
427
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
428 GNUTLS_LOG (1, max_log_level, "setting the priority string");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
429
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
430 ret = gnutls_priority_set_direct(state,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
431 (char*) SDATA (priority_string),
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
432 NULL);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
433
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
434 if (ret < GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
435 return gnutls_make_error (ret);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
436
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
437 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
438
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
439 if (EQ (type, Qgnutls_x509pki))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
440 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
441 ret = gnutls_cred_set (state, GNUTLS_CRD_CERTIFICATE, x509_cred);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
442 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
443 else if (EQ (type, Qgnutls_anon))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
444 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
445 ret = gnutls_cred_set (state, GNUTLS_CRD_ANON, anon_cred);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
446 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
447 else
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
448 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
449 error ("unknown credential type");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
450 ret = GNUTLS_EMACS_ERROR_INVALID_TYPE;
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
451 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
452
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
453 if (ret < GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
454 return gnutls_make_error (ret);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
455
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
456 XPROCESS (proc)->gnutls_anon_cred = anon_cred;
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
457 XPROCESS (proc)->gnutls_x509_cred = x509_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
458 XPROCESS (proc)->gnutls_cred_type = type;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
459
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
460 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_SET;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
461
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
462 emacs_gnutls_handshake (XPROCESS (proc));
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
463
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
464 return gnutls_make_error (GNUTLS_E_SUCCESS);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
465 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
466
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
467 DEFUN ("gnutls-bye", Fgnutls_bye,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
468 Sgnutls_bye, 2, 2, 0,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
469 doc: /* Terminate current GNU TLS connection for PROCESS.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
470 The connection should have been initiated using `gnutls-handshake'.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
471
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
472 If CONT is not nil the TLS connection gets terminated and further
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
473 receives and sends will be disallowed. If the return value is zero you
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
474 may continue using the connection. If CONT is nil, GnuTLS actually
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
475 sends an alert containing a close request and waits for the peer to
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
476 reply with the same message. In order to reuse the connection you
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
477 should wait for an EOF from the peer.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
478
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
479 This function may also return `gnutls-e-again', or
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
480 `gnutls-e-interrupted'. */)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
481 (Lisp_Object proc, Lisp_Object cont)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
482 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
483 gnutls_session_t state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
484 int ret;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
485
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
486 CHECK_PROCESS (proc);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
487
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
488 state = XPROCESS (proc)->gnutls_state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
489
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
490 ret = gnutls_bye (state,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
491 NILP (cont) ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
492
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
493 return gnutls_make_error (ret);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
494 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
495
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
496 void
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
497 syms_of_gnutls (void)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
498 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
499 global_initialized = 0;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
500
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
501 Qgnutls_code = intern_c_string ("gnutls-code");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
502 staticpro (&Qgnutls_code);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
503
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
504 Qgnutls_anon = intern_c_string ("gnutls-anon");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
505 staticpro (&Qgnutls_anon);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
506
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
507 Qgnutls_x509pki = intern_c_string ("gnutls-x509pki");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
508 staticpro (&Qgnutls_x509pki);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
509
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
510 Qgnutls_e_interrupted = intern_c_string ("gnutls-e-interrupted");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
511 staticpro (&Qgnutls_e_interrupted);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
512 Fput (Qgnutls_e_interrupted, Qgnutls_code,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
513 make_number (GNUTLS_E_INTERRUPTED));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
514
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
515 Qgnutls_e_again = intern_c_string ("gnutls-e-again");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
516 staticpro (&Qgnutls_e_again);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
517 Fput (Qgnutls_e_again, Qgnutls_code,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
518 make_number (GNUTLS_E_AGAIN));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
519
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
520 Qgnutls_e_invalid_session = intern_c_string ("gnutls-e-invalid-session");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
521 staticpro (&Qgnutls_e_invalid_session);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
522 Fput (Qgnutls_e_invalid_session, Qgnutls_code,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
523 make_number (GNUTLS_E_INVALID_SESSION));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
524
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
525 Qgnutls_e_not_ready_for_handshake =
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
526 intern_c_string ("gnutls-e-not-ready-for-handshake");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
527 staticpro (&Qgnutls_e_not_ready_for_handshake);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
528 Fput (Qgnutls_e_not_ready_for_handshake, Qgnutls_code,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
529 make_number (GNUTLS_E_APPLICATION_ERROR_MIN));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
530
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
531 defsubr (&Sgnutls_get_initstage);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
532 defsubr (&Sgnutls_errorp);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
533 defsubr (&Sgnutls_error_fatalp);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
534 defsubr (&Sgnutls_error_string);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
535 defsubr (&Sgnutls_boot);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
536 defsubr (&Sgnutls_deinit);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
537 defsubr (&Sgnutls_bye);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
538 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
539 #endif