auth/gensec: add gensec_set_channel_bindings() function
[abartlet/samba-autobuild/.git] / auth / gensec / gensec.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    Generic Authentication Interface
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #ifndef __GENSEC_H__
24 #define __GENSEC_H__
25
26 #include "../lib/util/data_blob.h"
27 #include "libcli/util/ntstatus.h"
28
29 #define GENSEC_SASL_NAME_NTLMSSP "NTLM"
30
31 #define GENSEC_OID_NTLMSSP "1.3.6.1.4.1.311.2.2.10"
32 #define GENSEC_OID_SPNEGO "1.3.6.1.5.5.2"
33 #define GENSEC_OID_KERBEROS5 "1.2.840.113554.1.2.2"
34 #define GENSEC_OID_KERBEROS5_OLD "1.2.840.48018.1.2.2"
35 #define GENSEC_OID_KERBEROS5_USER2USER "1.2.840.113554.1.2.2.3"
36
37 #define GENSEC_FINAL_AUTH_TYPE_KRB5 "krb5"
38 #define GENSEC_FINAL_AUTH_TYPE_NTLMSSP "NTLMSSP"
39
40 enum gensec_priority {
41         GENSEC_SPNEGO = 90,
42         GENSEC_GSSAPI = 80,
43         GENSEC_KRB5 = 70,
44         GENSEC_SCHANNEL = 60,
45         GENSEC_NTLMSSP = 50,
46         GENSEC_SASL = 20,
47         GENSEC_OTHER = 10,
48         GENSEC_EXTERNAL = 0
49 };
50
51 struct gensec_security;
52 struct gensec_target {
53         const char *principal;
54         const char *hostname;
55         const char *service;
56         const char *service_description;
57 };
58
59 #define GENSEC_FEATURE_SESSION_KEY      0x00000001
60 #define GENSEC_FEATURE_SIGN             0x00000002
61 #define GENSEC_FEATURE_SEAL             0x00000004
62 #define GENSEC_FEATURE_DCE_STYLE        0x00000008
63 #define GENSEC_FEATURE_ASYNC_REPLIES    0x00000010
64 #define GENSEC_FEATURE_DATAGRAM_MODE    0x00000020
65 #define GENSEC_FEATURE_SIGN_PKT_HEADER  0x00000040
66 #define GENSEC_FEATURE_NEW_SPNEGO       0x00000080
67 #define GENSEC_FEATURE_UNIX_TOKEN       0x00000100
68 #define GENSEC_FEATURE_NTLM_CCACHE      0x00000200
69 #define GENSEC_FEATURE_LDAP_STYLE       0x00000400
70 #define GENSEC_FEATURE_NO_AUTHZ_LOG     0x00000800
71 #define GENSEC_FEATURE_SMB_TRANSPORT    0x00001000
72 #define GENSEC_FEATURE_LDAPS_TRANSPORT  0x00002000
73 #define GENSEC_FEATURE_CB_OPTIONAL      0x00004000
74
75 #define GENSEC_EXPIRE_TIME_INFINITY (NTTIME)0x8000000000000000LL
76
77 /* GENSEC mode */
78 enum gensec_role
79 {
80         GENSEC_SERVER,
81         GENSEC_CLIENT
82 };
83
84 struct auth_session_info;
85 struct cli_credentials;
86 struct gensec_settings;
87 struct tevent_context;
88 struct tevent_req;
89 struct smb_krb5_context;
90 struct tsocket_address;
91
92 struct gensec_settings {
93         struct loadparm_context *lp_ctx;
94         const char *target_hostname;
95
96         /* this allows callers to specify a specific set of ops that
97          * should be used, rather than those loaded by the plugin
98          * mechanism */
99         const struct gensec_security_ops * const *backends;
100
101         /* To fill in our own name in the NTLMSSP server */
102         const char *server_dns_domain;
103         const char *server_dns_name;
104         const char *server_netbios_domain;
105         const char *server_netbios_name;
106 };
107
108 struct gensec_security_ops;
109 struct gensec_security_ops_wrapper;
110
111 /* Change to 1, loadable modules now take a TALLOC_CTX * init() parameter. */
112 #define GENSEC_INTERFACE_VERSION 1
113
114 /* this structure is used by backends to determine the size of some critical types */
115 struct gensec_critical_sizes;
116 const struct gensec_critical_sizes *gensec_interface_version(void);
117
118 /* Socket wrapper */
119
120 struct gensec_security;
121 struct auth4_context;
122 struct auth_user_info_dc;
123
124 struct loadparm_context;
125
126 NTSTATUS gensec_subcontext_start(TALLOC_CTX *mem_ctx,
127                                  struct gensec_security *parent,
128                                  struct gensec_security **gensec_security);
129 NTSTATUS gensec_client_start(TALLOC_CTX *mem_ctx,
130                              struct gensec_security **gensec_security,
131                              struct gensec_settings *settings);
132 NTSTATUS gensec_start_mech_by_ops(struct gensec_security *gensec_security,
133                                   const struct gensec_security_ops *ops);
134 NTSTATUS gensec_start_mech_by_sasl_list(struct gensec_security *gensec_security,
135                                                  const char **sasl_names);
136 void gensec_set_max_update_size(struct gensec_security *gensec_security,
137                                 uint32_t max_update_size);
138 size_t gensec_max_update_size(struct gensec_security *gensec_security);
139 NTSTATUS gensec_update(struct gensec_security *gensec_security,
140                        TALLOC_CTX *out_mem_ctx,
141                        const DATA_BLOB in, DATA_BLOB *out);
142 struct tevent_req *gensec_update_send(TALLOC_CTX *mem_ctx,
143                                       struct tevent_context *ev,
144                                       struct gensec_security *gensec_security,
145                                       const DATA_BLOB in);
146 NTSTATUS gensec_update_recv(struct tevent_req *req, TALLOC_CTX *out_mem_ctx, DATA_BLOB *out);
147
148 #define GENSEC_UPDATE_IS_NTERROR(status) ( \
149         !NT_STATUS_IS_OK(status) && \
150         !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) \
151         )
152
153 /**
154  * @brief Ask for features for a following authentication
155  *
156  * Typically only one specific feature bit should be passed,
157  * but it also works to ask for more features.
158  *
159  * The features must be requested before starting the
160  * gensec_update*() loop.
161  *
162  * The current exception is GENSEC_FEATURE_SIGN_PKT_HEADER,
163  * it can also be requested once the gensec_update*() loop
164  * returned NT_STATUS_OK.
165  *
166  * The features should not be changed during the gensec_update*()
167  * loop.
168  *
169  * @param[in]  gensec_security The context to be used
170  *
171  * @param[in]  feature         The requested feature[s].
172  *
173  */
174 void gensec_want_feature(struct gensec_security *gensec_security,
175                          uint32_t feature);
176 /**
177  * @brief Ask for one feature after the finished authentication
178  *
179  * Because the return value is bool, the caller can only
180  * ask for one feature at a time.
181  *
182  * The features must be requested after the finished
183  * gensec_update*() loop.
184  *
185  * The current exception is GENSEC_FEATURE_SIGN_PKT_HEADER,
186  * it can also be requested before the gensec_update*() loop,
187  * as the return value only indicates if the backend supports
188  * dcerpc header signing, not if header signing will be used
189  * between client and server. It will be used only if the caller
190  * also used gensec_want_feature(GENSEC_FEATURE_SIGN_PKT_HEADER).
191  *
192  * @param[in]  gensec_security The context to be used.
193  *
194  * @param[in]  feature         The requested feature.
195  *
196  * @return                     true if the feature is supported, false if not.
197  */
198 bool gensec_have_feature(struct gensec_security *gensec_security,
199                          uint32_t feature);
200 NTTIME gensec_expire_time(struct gensec_security *gensec_security);
201 NTSTATUS gensec_set_credentials(struct gensec_security *gensec_security, struct cli_credentials *credentials);
202 /**
203  * Set the target service (such as 'http' or 'host') on a GENSEC context - ensures it is talloc()ed
204  *
205  * This is used for Kerberos service principal name resolution.
206  */
207
208 NTSTATUS gensec_set_target_service(struct gensec_security *gensec_security, const char *service);
209 const char *gensec_get_target_service(struct gensec_security *gensec_security);
210 NTSTATUS gensec_set_target_hostname(struct gensec_security *gensec_security, const char *hostname);
211 const char *gensec_get_target_hostname(struct gensec_security *gensec_security);
212 /**
213  * Set the target service (such as 'samr') on an GENSEC context - ensures it is talloc()ed.
214  *
215  * This is not the Kerberos service principal, instead this is a
216  * constant value that can be logged as part of authentication and
217  * authorization logging
218  */
219 const char *gensec_get_target_service_description(struct gensec_security *gensec_security);
220 NTSTATUS gensec_set_target_service_description(struct gensec_security *gensec_security,
221                                                const char *service);
222 NTSTATUS gensec_session_key(struct gensec_security *gensec_security,
223                             TALLOC_CTX *mem_ctx,
224                             DATA_BLOB *session_key);
225 NTSTATUS gensec_start_mech_by_oid(struct gensec_security *gensec_security,
226                                   const char *mech_oid);
227 const char *gensec_get_name_by_oid(struct gensec_security *gensec_security, const char *oid_string);
228 struct cli_credentials *gensec_get_credentials(struct gensec_security *gensec_security);
229 NTSTATUS gensec_init(void);
230 NTSTATUS gensec_register(TALLOC_CTX *ctx,
231                 const struct gensec_security_ops *ops);
232 const struct gensec_security_ops *gensec_security_by_oid(struct gensec_security *gensec_security,
233                                                          const char *oid_string);
234 const struct gensec_security_ops *gensec_security_by_sasl_name(struct gensec_security *gensec_security,
235                                                                const char *sasl_name);
236 const struct gensec_security_ops *gensec_security_by_auth_type(
237                                 struct gensec_security *gensec_security,
238                                 uint32_t auth_type);
239 const struct gensec_security_ops *gensec_security_by_name(struct gensec_security *gensec_security,
240                                                           const char *name);
241 const struct gensec_security_ops **gensec_security_mechs(struct gensec_security *gensec_security,
242                                                    TALLOC_CTX *mem_ctx);
243 const struct gensec_security_ops_wrapper *gensec_security_by_oid_list(
244                                         struct gensec_security *gensec_security,
245                                         TALLOC_CTX *mem_ctx,
246                                         const char * const *oid_strings,
247                                         const char *skip);
248 const char **gensec_security_oids(struct gensec_security *gensec_security,
249                                   TALLOC_CTX *mem_ctx,
250                                   const char *skip);
251 const char **gensec_security_oids_from_ops_wrapped(TALLOC_CTX *mem_ctx,
252                                 const struct gensec_security_ops_wrapper *wops);
253 size_t gensec_max_input_size(struct gensec_security *gensec_security);
254 size_t gensec_max_wrapped_size(struct gensec_security *gensec_security);
255 NTSTATUS gensec_unseal_packet(struct gensec_security *gensec_security,
256                               uint8_t *data, size_t length,
257                               const uint8_t *whole_pdu, size_t pdu_length,
258                               const DATA_BLOB *sig);
259 NTSTATUS gensec_check_packet(struct gensec_security *gensec_security,
260                              const uint8_t *data, size_t length,
261                              const uint8_t *whole_pdu, size_t pdu_length,
262                              const DATA_BLOB *sig);
263 size_t gensec_sig_size(struct gensec_security *gensec_security, size_t data_size);
264 NTSTATUS gensec_seal_packet(struct gensec_security *gensec_security,
265                             TALLOC_CTX *mem_ctx,
266                             uint8_t *data, size_t length,
267                             const uint8_t *whole_pdu, size_t pdu_length,
268                             DATA_BLOB *sig);
269 NTSTATUS gensec_sign_packet(struct gensec_security *gensec_security,
270                             TALLOC_CTX *mem_ctx,
271                             const uint8_t *data, size_t length,
272                             const uint8_t *whole_pdu, size_t pdu_length,
273                             DATA_BLOB *sig);
274 NTSTATUS gensec_start_mech_by_authtype(struct gensec_security *gensec_security,
275                                        uint8_t auth_type, uint8_t auth_level);
276 const char *gensec_get_name_by_authtype(struct gensec_security *gensec_security, uint8_t authtype);
277 NTSTATUS gensec_server_start(TALLOC_CTX *mem_ctx,
278                              struct gensec_settings *settings,
279                              struct auth4_context *auth_context,
280                              struct gensec_security **gensec_security);
281 NTSTATUS gensec_session_info(struct gensec_security *gensec_security,
282                              TALLOC_CTX *mem_ctx,
283                              struct auth_session_info **session_info);
284
285 NTSTATUS gensec_set_local_address(struct gensec_security *gensec_security,
286                 const struct tsocket_address *local);
287 NTSTATUS gensec_set_remote_address(struct gensec_security *gensec_security,
288                 const struct tsocket_address *remote);
289 const struct tsocket_address *gensec_get_local_address(struct gensec_security *gensec_security);
290 const struct tsocket_address *gensec_get_remote_address(struct gensec_security *gensec_security);
291
292 NTSTATUS gensec_start_mech_by_name(struct gensec_security *gensec_security,
293                                         const char *name);
294
295 NTSTATUS gensec_unwrap(struct gensec_security *gensec_security,
296                        TALLOC_CTX *mem_ctx,
297                        const DATA_BLOB *in,
298                        DATA_BLOB *out);
299 NTSTATUS gensec_wrap(struct gensec_security *gensec_security,
300                      TALLOC_CTX *mem_ctx,
301                      const DATA_BLOB *in,
302                      DATA_BLOB *out);
303
304 bool gensec_security_ops_enabled(const struct gensec_security_ops *ops, struct gensec_security *security);
305
306 NTSTATUS gensec_start_mech_by_sasl_name(struct gensec_security *gensec_security,
307                                         const char *sasl_name);
308 const char **gensec_security_sasl_names(struct gensec_security *gensec_security,
309                                         TALLOC_CTX *mem_ctx);
310
311 int gensec_setting_int(struct gensec_settings *settings, const char *mechanism, const char *name, int default_value);
312 bool gensec_setting_bool(struct gensec_settings *settings, const char *mechanism, const char *name, bool default_value);
313
314 NTSTATUS gensec_set_target_principal(struct gensec_security *gensec_security, const char *principal);
315 const char *gensec_get_target_principal(struct gensec_security *gensec_security);
316
317 NTSTATUS gensec_set_channel_bindings(struct gensec_security *gensec_security,
318                                      uint32_t initiator_addrtype,
319                                      const DATA_BLOB *initiator_address,
320                                      uint32_t acceptor_addrtype,
321                                      const DATA_BLOB *acceptor_address,
322                                      const DATA_BLOB *application_data);
323
324 NTSTATUS gensec_generate_session_info_pac(TALLOC_CTX *mem_ctx,
325                                           struct gensec_security *gensec_security,
326                                           struct smb_krb5_context *smb_krb5_context,
327                                           DATA_BLOB *pac_blob,
328                                           const char *principal_string,
329                                           const struct tsocket_address *remote_address,
330                                           struct auth_session_info **session_info);
331
332 NTSTATUS gensec_magic_check_krb5_oid(struct gensec_security *unused,
333                                         const DATA_BLOB *blob);
334
335 #endif /* __GENSEC_H__ */