1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
5 * Portions Copyright (C) 2007 Apple Inc.
6 * Copyright 1990, 2007 by the Massachusetts Institute of Technology.
8 * Export of this software from the United States of America may
9 * require a specific license from the United States Government.
10 * It is the responsibility of any person or organization contemplating
11 * export to obtain such a license before exporting.
13 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14 * distribute this software and its documentation for any purpose and
15 * without fee is hereby granted, provided that the above copyright
16 * notice appear in all copies and that both that copyright notice and
17 * this permission notice appear in supporting documentation, and that
18 * the name of M.I.T. not be used in advertising or publicity pertaining
19 * to distribution of the software without specific, written prior
20 * permission. Furthermore if you modify this software you must label
21 * your software as modified software and not distribute it in such a
22 * fashion that it might be confused with the original M.I.T. software.
23 * M.I.T. makes no representations about the suitability of
24 * this software for any purpose. It is provided "as is" without express
25 * or implied warranty.
28 * Declarations for policy.c
31 #ifndef __KRB5_KDC_UTIL__
32 #define __KRB5_KDC_UTIL__
36 typedef struct _krb5_fulladdr {
37 krb5_address * address;
41 krb5_error_code check_hot_list (krb5_ticket *);
42 krb5_boolean realm_compare (krb5_const_principal, krb5_const_principal);
43 krb5_boolean is_local_principal(krb5_const_principal princ1);
44 krb5_boolean krb5_is_tgs_principal (krb5_const_principal);
46 add_to_transited (krb5_data *,
52 compress_transited (krb5_data *,
56 concat_authorization_data (krb5_authdata **,
60 fetch_last_req_info (krb5_db_entry *, krb5_last_req_entry ***);
63 kdc_convert_key (krb5_keyblock *, krb5_keyblock *, int);
65 kdc_process_tgs_req (krb5_kdc_req *,
66 const krb5_fulladdr *,
69 krb5_db_entry *krbtgt,
71 krb5_keyblock **, krb5_keyblock **,
72 krb5_pa_data **pa_tgs_req);
75 kdc_get_server_key (krb5_ticket *, unsigned int,
76 krb5_boolean match_enctype,
77 krb5_db_entry *, int *,
78 krb5_keyblock **, krb5_kvno *);
81 validate_as_request (krb5_kdc_req *, krb5_db_entry,
82 krb5_db_entry, krb5_timestamp,
83 const char **, krb5_data *);
86 validate_forwardable(krb5_kdc_req *, krb5_db_entry,
87 krb5_db_entry, krb5_timestamp,
91 validate_tgs_request (krb5_kdc_req *, krb5_db_entry,
92 krb5_ticket *, krb5_timestamp,
93 const char **, krb5_data *);
96 fetch_asn1_field (unsigned char *, unsigned int, unsigned int, krb5_data *);
99 dbentry_has_key_for_enctype (krb5_context context,
100 krb5_db_entry *client,
101 krb5_enctype enctype);
104 dbentry_supports_enctype (krb5_context context,
105 krb5_db_entry *client,
106 krb5_enctype enctype);
109 select_session_keytype (krb5_context context,
110 krb5_db_entry *server,
112 krb5_enctype *ktypes);
115 get_salt_from_key (krb5_context, krb5_principal,
116 krb5_key_data *, krb5_data *);
118 void limit_string (char *name);
121 ktypes2str(char *s, size_t len, int nktypes, krb5_enctype *ktype);
124 rep_etypes2str(char *s, size_t len, krb5_kdc_rep *rep);
128 process_as_req (krb5_kdc_req *, krb5_data *,
129 const krb5_fulladdr *,
134 process_tgs_req (krb5_data *,
135 const krb5_fulladdr *,
139 dispatch (krb5_data *,
140 const krb5_fulladdr *,
144 krb5_error_code kdc_initialize_rcache (krb5_context, char *);
147 setup_server_realm (krb5_principal);
149 kdc_err(krb5_context call_context, errcode_t code, const char *fmt, ...)
150 #if !defined(__cplusplus) && (__GNUC__ > 2)
151 __attribute__((__format__(__printf__, 3, 4)))
156 krb5_error_code listen_and_process (void);
157 krb5_error_code setup_network (void);
158 krb5_error_code closedown_network (void);
162 against_local_policy_as (krb5_kdc_req *, krb5_db_entry,
163 krb5_db_entry, krb5_timestamp,
164 const char **, krb5_data *);
167 against_local_policy_tgs (krb5_kdc_req *, krb5_db_entry,
168 krb5_ticket *, const char **,
173 enctype_requires_etype_info_2(krb5_enctype enctype);
176 missing_required_preauth (krb5_db_entry *client,
177 krb5_db_entry *server,
178 krb5_enc_tkt_part *enc_tkt_reply);
180 get_preauth_hint_list (krb5_kdc_req * request,
181 krb5_db_entry *client,
182 krb5_db_entry *server,
185 load_preauth_plugins(krb5_context context);
187 unload_preauth_plugins(krb5_context context);
190 check_padata (krb5_context context,
191 krb5_db_entry *client, krb5_data *req_pkt,
192 krb5_kdc_req *request,
193 krb5_enc_tkt_part *enc_tkt_reply,
194 void **padata_context, krb5_data *e_data);
197 return_padata (krb5_context context, krb5_db_entry *client,
198 krb5_data *req_pkt, krb5_kdc_req *request,
200 krb5_key_data *client_key, krb5_keyblock *encrypting_key,
201 void **padata_context);
204 free_padata_context (krb5_context context, void **padata_context);
207 find_pa_data (krb5_pa_data **padata, krb5_preauthtype pa_type);
210 add_pa_data_element (krb5_context context,
211 krb5_pa_data *padata,
212 krb5_pa_data ***out_padata,
217 load_authdata_plugins(krb5_context context);
219 unload_authdata_plugins(krb5_context context);
222 handle_authdata (krb5_context context,
224 krb5_db_entry *client,
225 krb5_db_entry *server,
226 krb5_db_entry *krbtgt,
227 krb5_keyblock *client_key,
228 krb5_keyblock *server_key,
229 krb5_keyblock *krbtgt_key,
231 krb5_kdc_req *request,
232 krb5_const_principal for_user_princ,
233 krb5_enc_tkt_part *enc_tkt_request,
234 krb5_enc_tkt_part *enc_tkt_reply);
237 krb5_boolean kdc_check_lookaside (krb5_data *, krb5_data **);
238 void kdc_insert_lookaside (krb5_data *, krb5_data *);
239 void kdc_free_lookaside(krb5_context);
243 get_principal_locked (krb5_context kcontext,
244 krb5_const_principal search_for,
245 krb5_db_entry *entries, int *nentries,
248 get_principal (krb5_context kcontext,
249 krb5_const_principal search_for,
250 krb5_db_entry *entries, int *nentries, krb5_boolean *more);
253 include_pac_p(krb5_context context, krb5_kdc_req *request);
256 return_enc_padata(krb5_context context,
257 krb5_data *req_pkt, krb5_kdc_req *request,
258 krb5_keyblock *reply_key,
259 krb5_db_entry *server,
260 krb5_enc_kdc_rep_part *reply_encpart);
263 sign_db_authdata (krb5_context context,
265 krb5_const_principal client_princ,
266 krb5_db_entry *client,
267 krb5_db_entry *server,
268 krb5_db_entry *krbtgt,
269 krb5_keyblock *client_key,
270 krb5_keyblock *server_key,
271 krb5_keyblock *krbtgt_key,
272 krb5_timestamp authtime,
273 krb5_authdata **tgs_authdata,
274 krb5_keyblock *session_key,
275 krb5_authdata ***ret_authdata);
278 kdc_process_s4u2self_req (krb5_context context,
279 krb5_kdc_req *request,
280 krb5_const_principal client_princ,
281 const krb5_db_entry *server,
282 krb5_keyblock *tgs_subkey,
283 krb5_keyblock *tgs_session,
284 krb5_timestamp kdc_time,
285 krb5_pa_s4u_x509_user **s4u2self_req,
286 krb5_db_entry *princ,
288 const char **status);
291 kdc_make_s4u2self_rep (krb5_context context,
292 krb5_keyblock *tgs_subkey,
293 krb5_keyblock *tgs_session,
294 krb5_pa_s4u_x509_user *req_s4u_user,
296 krb5_enc_kdc_rep_part *reply_encpart);
299 kdc_process_s4u2proxy_req (krb5_context context,
300 krb5_kdc_req *request,
301 const krb5_enc_tkt_part *t2enc,
302 const krb5_db_entry *server,
303 krb5_const_principal server_princ,
304 krb5_const_principal proxy_princ,
305 const char **status);
308 kdc_check_transited_list (krb5_context context,
309 const krb5_data *trans,
310 const krb5_data *realm1,
311 const krb5_data *realm2);
314 audit_as_request (krb5_kdc_req *request,
315 krb5_db_entry *client,
316 krb5_db_entry *server,
317 krb5_timestamp authtime,
318 krb5_error_code errcode);
321 audit_tgs_request (krb5_kdc_req *request,
322 krb5_const_principal client,
323 krb5_db_entry *server,
324 krb5_timestamp authtime,
325 krb5_error_code errcode);
328 validate_transit_path(krb5_context context,
329 krb5_const_principal client,
330 krb5_db_entry *server,
331 krb5_db_entry *krbtgt);
333 kdc_get_ticket_endtime(krb5_context context,
335 krb5_timestamp endtime,
337 krb5_db_entry *client,
338 krb5_db_entry *server,
339 krb5_timestamp *out_endtime);
342 log_as_req(const krb5_fulladdr *from,
343 krb5_kdc_req *request, krb5_kdc_rep *reply,
344 krb5_db_entry *client, const char *cname,
345 krb5_db_entry *server, const char *sname,
346 krb5_timestamp authtime,
347 const char *status, krb5_error_code errcode, const char *emsg);
349 log_tgs_req(const krb5_fulladdr *from,
350 krb5_kdc_req *request, krb5_kdc_rep *reply,
351 const char *cname, const char *sname, const char *altcname,
352 krb5_timestamp authtime,
353 unsigned int c_flags, const char *s4u_name,
354 const char *status, krb5_error_code errcode, const char *emsg);
356 log_tgs_alt_tgt(krb5_principal p);
360 struct kdc_request_state {
361 krb5_keyblock *armor_key;
362 krb5_keyblock *strengthen_key;
363 krb5_pa_data *cookie;
364 krb5_int32 fast_options;
365 krb5_int32 fast_internal_flags;
368 krb5_error_code kdc_make_rstate(struct kdc_request_state **out);
369 void kdc_free_rstate (struct kdc_request_state *s);
372 enum krb5_fast_kdc_flags {
373 KRB5_FAST_REPLY_KEY_USED = 0x1,
374 KRB5_FAST_REPLY_KEY_REPLACED = 0x02
378 kdc_find_fast (krb5_kdc_req **requestptr, krb5_data *checksummed_data,
379 krb5_keyblock *tgs_subkey, krb5_keyblock *tgs_session,
380 struct kdc_request_state *state);
383 kdc_fast_response_handle_padata (struct kdc_request_state *state,
384 krb5_kdc_req *request,
386 krb5_enctype enctype);
388 kdc_fast_handle_error (krb5_context context,
389 struct kdc_request_state *state,
390 krb5_kdc_req *request,
391 krb5_pa_data **in_padata, krb5_error *err);
393 krb5_error_code kdc_fast_handle_reply_key(struct kdc_request_state *state,
394 krb5_keyblock *existing_key,
395 krb5_keyblock **out_key);
398 krb5_error_code kdc_preauth_get_cookie(struct kdc_request_state *state,
399 krb5_pa_data **cookie);
401 kdc_handle_protected_negotiation( krb5_data *req_pkt, krb5_kdc_req *request,
402 const krb5_keyblock *reply_key,
403 krb5_pa_data **out_enc_padata, int *idx);
405 krb5int_get_domain_realm_mapping(krb5_context context,
406 const char *host, char ***realmsp);
409 #define isflagset(flagfield, flag) (flagfield & (flag))
410 #define setflag(flagfield, flag) (flagfield |= (flag))
411 #define clear(flagfield, flag) (flagfield &= ~(flag))
414 #define min(a, b) ((a) < (b) ? (a) : (b))
415 #define max(a, b) ((a) > (b) ? (a) : (b))
418 #ifdef KRB5_USE_INET6
419 #define ADDRTYPE2FAMILY(X) \
420 ((X) == ADDRTYPE_INET6 ? AF_INET6 : (X) == ADDRTYPE_INET ? AF_INET : -1)
422 #define ADDRTYPE2FAMILY(X) \
423 ((X) == ADDRTYPE_INET ? AF_INET : -1)
426 /* RFC 4120: KRB5KDC_ERR_KEY_TOO_WEAK
427 * RFC 4556: KRB5KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED */
428 #define KRB5KDC_ERR_KEY_TOO_WEAK KRB5KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED
430 #endif /* __KRB5_KDC_UTIL__ */