r8302: import mini HEIMDAL into the tree
[amitay/samba.git] / source4 / heimdal / lib / gssapi / gssapi_locl.h
1 /*
2  * Copyright (c) 1997 - 2004 Kungliga Tekniska Högskolan
3  * (Royal Institute of Technology, Stockholm, Sweden). 
4  * All rights reserved. 
5  *
6  * Redistribution and use in source and binary forms, with or without 
7  * modification, are permitted provided that the following conditions 
8  * are met: 
9  *
10  * 1. Redistributions of source code must retain the above copyright 
11  *    notice, this list of conditions and the following disclaimer. 
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright 
14  *    notice, this list of conditions and the following disclaimer in the 
15  *    documentation and/or other materials provided with the distribution. 
16  *
17  * 3. Neither the name of the Institute nor the names of its contributors 
18  *    may be used to endorse or promote products derived from this software 
19  *    without specific prior written permission. 
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
31  * SUCH DAMAGE. 
32  */
33
34 /* $Id: gssapi_locl.h,v 1.40 2005/06/16 20:34:03 lha Exp $ */
35
36 #ifndef GSSAPI_LOCL_H
37 #define GSSAPI_LOCL_H
38
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #include <krb5_locl.h>
44 #include <gssapi.h>
45 #include <assert.h>
46
47 #include "cfx.h"
48 #include "arcfour.h"
49
50 #include "spnego_asn1.h"
51
52 /*
53  *
54  */
55
56 struct gss_msg_order;
57
58 typedef struct gss_ctx_id_t_desc_struct {
59   struct krb5_auth_context_data *auth_context;
60   gss_name_t source, target;
61   enum gss_ctx_id_t_state {
62         INITIATOR_START = 1, INITIATOR_WAIT_FOR_MUTAL = 2, INITIATOR_READY= 3,
63         ACCEPTOR_START = 11, ACCEPTOR_WAIT_FOR_DCESTYLE = 12, ACCEPTOR_READY = 13
64   } state;
65   OM_uint32 flags;
66   enum {LOCAL = 1,
67         OPEN = 2,
68         COMPAT_OLD_DES3 = 4,
69         COMPAT_OLD_DES3_SELECTED = 8,
70         ACCEPTOR_SUBKEY = 16
71   } more_flags;
72   struct krb5_ticket *ticket;
73   krb5_keyblock *service_keyblock;
74   krb5_data fwd_data;
75   OM_uint32 lifetime;
76   HEIMDAL_MUTEX ctx_id_mutex;
77   struct gss_msg_order *order;
78 } gss_ctx_id_t_desc;
79
80 typedef struct gss_cred_id_t_desc_struct {
81   gss_name_t principal;
82   krb5_boolean made_keytab;
83   struct krb5_keytab_data *keytab;
84   OM_uint32 lifetime;
85   gss_cred_usage_t usage;
86   gss_OID_set mechanisms;
87   krb5_boolean made_ccache;
88   struct krb5_ccache_data *ccache;
89   HEIMDAL_MUTEX cred_id_mutex;
90 } gss_cred_id_t_desc;
91
92 /*
93  *
94  */
95
96 extern krb5_context gssapi_krb5_context;
97
98 extern krb5_keytab gssapi_krb5_keytab;
99 extern HEIMDAL_MUTEX gssapi_keytab_mutex;
100
101 struct gssapi_thr_context {
102     HEIMDAL_MUTEX mutex;
103     char *error_string;
104 };
105
106 /*
107  * Prototypes
108  */
109
110 krb5_error_code gssapi_krb5_init (void);
111
112 #define GSSAPI_KRB5_INIT() do {                                 \
113     krb5_error_code kret_gss_init;                              \
114     if((kret_gss_init = gssapi_krb5_init ()) != 0) {            \
115         *minor_status = kret_gss_init;                          \
116         return GSS_S_FAILURE;                                   \
117     }                                                           \
118 } while (0)
119
120 struct gssapi_thr_context *
121 gssapi_get_thread_context(int);
122
123 OM_uint32
124 _gsskrb5_create_ctx(
125         OM_uint32 * minor_status,
126         gss_ctx_id_t * context_handle,
127         const gss_channel_bindings_t input_chan_bindings,
128         enum gss_ctx_id_t_state state);
129
130 void
131 gsskrb5_is_cfx(gss_ctx_id_t, int *);
132
133 OM_uint32
134 gssapi_krb5_create_8003_checksum (
135                       OM_uint32 *minor_status,
136                       const gss_channel_bindings_t input_chan_bindings,
137                       OM_uint32 flags,
138                       const krb5_data *fwd_data,
139                       Checksum *result);
140
141 OM_uint32
142 gssapi_krb5_verify_8003_checksum (
143                       OM_uint32 *minor_status,
144                       const gss_channel_bindings_t input_chan_bindings,
145                       const Checksum *cksum,
146                       OM_uint32 *flags,
147                       krb5_data *fwd_data);
148
149 void
150 _gssapi_encap_length (size_t data_len,
151                       size_t *len,
152                       size_t *total_len,
153                       const gss_OID mech);
154
155 void
156 gssapi_krb5_encap_length (size_t data_len,
157                           size_t *len,
158                           size_t *total_len,
159                           const gss_OID mech);
160
161
162
163 OM_uint32
164 _gssapi_encapsulate(OM_uint32 *minor_status,
165                     const krb5_data *in_data,
166                     gss_buffer_t output_token,
167                     const gss_OID mech);
168
169
170 OM_uint32
171 gssapi_krb5_encapsulate(OM_uint32 *minor_status,    
172                         const krb5_data *in_data,
173                         gss_buffer_t output_token,
174                         const u_char *type,
175                         const gss_OID mech);
176
177 OM_uint32
178 gssapi_krb5_decapsulate(OM_uint32 *minor_status,
179                         gss_buffer_t input_token_buffer,
180                         krb5_data *out_data,
181                         const char *type,
182                         gss_OID oid);
183
184 u_char *
185 gssapi_krb5_make_header (u_char *p,
186                          size_t len,
187                          const u_char *type,
188                          const gss_OID mech);
189
190 u_char *
191 _gssapi_make_mech_header(u_char *p,
192                          size_t len,
193                          const gss_OID mech);
194
195 OM_uint32
196 _gssapi_verify_mech_header(u_char **str,
197                            size_t total_len,
198                            gss_OID oid);
199
200 OM_uint32
201 gssapi_krb5_verify_header(u_char **str,
202                           size_t total_len,
203                           const u_char *type,
204                           gss_OID oid);
205
206 OM_uint32
207 _gssapi_decapsulate(OM_uint32 *minor_status,
208                     gss_buffer_t input_token_buffer,
209                     krb5_data *out_data,
210                     const gss_OID mech);
211
212
213 ssize_t
214 gssapi_krb5_get_mech (const u_char *, size_t, const u_char **);
215
216 OM_uint32
217 _gssapi_verify_pad(gss_buffer_t, size_t, size_t *);
218
219 OM_uint32
220 gss_verify_mic_internal(OM_uint32 * minor_status,
221                         const gss_ctx_id_t context_handle,
222                         const gss_buffer_t message_buffer,
223                         const gss_buffer_t token_buffer,
224                         gss_qop_t * qop_state,
225                         char * type);
226
227 OM_uint32
228 gss_krb5_get_subkey(const gss_ctx_id_t context_handle,
229                     krb5_keyblock **key);
230
231 krb5_error_code
232 gss_address_to_krb5addr(OM_uint32 gss_addr_type,
233                         gss_buffer_desc *gss_addr,
234                         int16_t port,
235                         krb5_address *address);
236
237 /* sec_context flags */
238
239 #define SC_LOCAL_ADDRESS  0x01
240 #define SC_REMOTE_ADDRESS 0x02
241 #define SC_KEYBLOCK       0x04
242 #define SC_LOCAL_SUBKEY   0x08
243 #define SC_REMOTE_SUBKEY  0x10
244
245 int
246 gss_oid_equal(const gss_OID a, const gss_OID b);
247
248 void
249 gssapi_krb5_set_error_string (void);
250
251 char *
252 gssapi_krb5_get_error_string (void);
253
254 OM_uint32
255 _gss_DES3_get_mic_compat(OM_uint32 *, gss_ctx_id_t);
256
257 OM_uint32
258 _gss_spnego_require_mechlist_mic(OM_uint32 *, gss_ctx_id_t, krb5_boolean *);
259
260 krb5_error_code
261 _gss_check_compat(OM_uint32 *, gss_name_t, const char *,
262                   krb5_boolean *, krb5_boolean);
263
264 OM_uint32
265 gssapi_lifetime_left(OM_uint32 *, OM_uint32, OM_uint32 *);
266
267 /* sequence */
268
269 OM_uint32
270 _gssapi_msg_order_create(OM_uint32 *, struct gss_msg_order **, 
271                          OM_uint32, OM_uint32, OM_uint32, int);
272 OM_uint32
273 _gssapi_msg_order_destroy(struct gss_msg_order **);
274
275 OM_uint32
276 _gssapi_msg_order_check(struct gss_msg_order *, OM_uint32);
277
278 OM_uint32
279 _gssapi_msg_order_f(OM_uint32);
280
281 /* 8003 */
282
283 krb5_error_code
284 gssapi_encode_om_uint32(OM_uint32, u_char *);
285
286 krb5_error_code
287 gssapi_encode_be_om_uint32(OM_uint32, u_char *);
288
289 krb5_error_code
290 gssapi_decode_om_uint32(u_char *, OM_uint32 *);
291
292 krb5_error_code
293 gssapi_decode_be_om_uint32(u_char *, OM_uint32 *);
294
295 #endif