HACK-TODO: tls_tstream...
[metze/samba/wip.git] / source4 / lib / tls / tls.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    transport layer security handling code
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _TLS_H_
23 #define _TLS_H_
24
25 #include "lib/socket/socket.h"
26
27 struct loadparm_context;
28
29 /*
30   call tls_initialise() once per task to startup the tls subsystem
31 */
32 struct tls_params *tls_initialise(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
33
34 /*
35   call tls_init_server() on each new server connection
36
37   the 'plain_chars' parameter is a list of chars that when they occur
38   as the first character from the client on the connection tell the
39   tls code that this is a non-tls connection. This can be used to have
40   tls and non-tls servers on the same port. If this is NULL then only
41   tls connections will be allowed
42 */
43 struct socket_context *tls_init_server(struct tls_params *parms,
44                                     struct socket_context *sock, 
45                                     struct tevent_fd *fde,
46                                     const char *plain_chars);
47
48 /*
49   call tls_init_client() on each new client connection
50 */
51 struct socket_context *tls_init_client(struct socket_context *sock, 
52                                     struct tevent_fd *fde,
53                                     const char *cafile);
54
55 /*
56   return True if a connection used tls
57 */
58 bool tls_enabled(struct socket_context *tls);
59
60
61 /*
62   true if tls support is compiled in
63 */
64 bool tls_support(struct tls_params *parms);
65
66 const struct socket_ops *socket_tls_ops(enum socket_type type);
67
68 struct tstream_context;
69 struct tstream_tls_params;
70
71 /**
72  * @brief Initiate a TLS tunnel on top of a given tstream
73  *
74  * @param[in]  mem_ctx
75  * @param[in]  ev
76  *
77  * @param[in]  plain_stream             The plain tstream which is used as transport.
78  *                                      It's important that the caller keeps the "plain"
79  *                                      tstream_context arround during the whole life
80  *                                      time of the "tls" tstream_context!
81  *                                      Note: tstream_disconnect_send()/recv() doesn't
82  *                                      disconnect the "plain" tstream_context.
83  *
84  * @param[in]  tls_params               ...
85  *
86  * @return
87  *
88  * @see tstream_tls_connect_recv
89  */
90 #ifdef DOXYGEN
91 struct tevent_req *tstream_tls_connect_send(TALLOC_CTX *mem_ctx,
92                                             struct tevent_context *ev,
93                                             struct tstream_context *plain_stream,
94                                             struct tstream_tls_params *tls_params);
95 #else
96 struct tevent_req *_tstream_tls_connect_send(TALLOC_CTX *mem_ctx,
97                                              struct tevent_context *ev,
98                                              struct tstream_context *plain_stream,
99                                              struct tstream_tls_params *tls_params,
100                                              const char *location);
101 #define tstream_tls_connect_send(mem_ctx, ev, plain_stream, tls_params); \
102         _tstream_tls_connect_send(mem_ctx, ev, plain_stream, tls_params, __location__)
103 #endif
104
105 /**
106  * @brief Receives the async result of tevent_tls_connect_send
107  *
108  * @param[in]  req
109  *
110  * @param[out] perrno
111  *
112  * @param[in]  mem_ctx
113  *
114  * @param[out] tls_stream
115  *
116  * @return
117  *
118  * @see tstream_tls_connect_send
119  */
120 int tstream_tls_connect_recv(struct tevent_req *req,
121                              int *perrno,
122                              TALLOC_CTX *mem_ctx,
123                              struct tstream_context **tls_stream);
124
125 /**
126  * @brief Accept a TLS tunnel on top of a given tstream
127  *
128  * @param[in]  mem_ctx
129  * @param[in]  ev
130  *
131  * @param[in]  plain_stream             The plain tstream which is used as transport.
132  *                                      It's important that the caller keeps the "plain"
133  *                                      tstream_context arround during the whole life
134  *                                      time of the "tls" tstream_context!
135  *                                      Note: tstream_disconnect_send()/recv() doesn't
136  *                                      disconnect the "plain" tstream_context.
137  *
138  * @param[in]  tls_params               ...
139  *
140  * @return
141  *
142  * @see tstream_tls_accept_recv
143  */
144 #ifdef DOXYGEN
145 struct tevent_req *tstream_tls_accept_send(TALLOC_CTX *mem_ctx,
146                                            struct tevent_context *ev,
147                                            struct tstream_context *plain_stream,
148                                            struct tstream_tls_params *tls_params);
149 #else
150 struct tevent_req *_tstream_tls_accept_send(TALLOC_CTX *mem_ctx,
151                                             struct tevent_context *ev,
152                                             struct tstream_context *plain_stream,
153                                             struct tstream_tls_params *tls_params,
154                                             const char *location);
155 #define tstream_tls_accept_send(mem_ctx, ev, plain_stream, tls_params); \
156         _tstream_tls_accept_send(mem_ctx, ev, plain_stream, tls_params, __location__)
157 #endif
158
159 /**
160  * @brief Receives the async result of tevent_tls_accept_send
161  *
162  * @param[in]  req
163  *
164  * @param[out] perrno
165  *
166  * @param[in]  mem_ctx
167  *
168  * @param[out] tls_stream
169  *
170  * @return
171  *
172  * @see tstream_tls_accept_send
173  */
174 int tstream_tls_accept_recv(struct tevent_req *req,
175                             int *perrno,
176                             TALLOC_CTX *mem_ctx,
177                             struct tstream_context **tls_stream);
178
179 #endif /* _TLS_H_ */