1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
4 * Portions Copyright (C) 2007 Apple Inc.
5 * Copyright 1990, 2007, 2014 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
27 * Declarations for policy.c
30 #ifndef __KRB5_KDC_UTIL__
31 #define __KRB5_KDC_UTIL__
33 #include <krb5/kdcpreauth_plugin.h>
35 #include "net-server.h"
36 #include "realm_data.h"
39 krb5_error_code check_hot_list (krb5_ticket *);
40 krb5_boolean is_local_principal(kdc_realm_t *kdc_active_realm,
41 krb5_const_principal princ1);
42 krb5_boolean krb5_is_tgs_principal (krb5_const_principal);
43 krb5_boolean is_cross_tgs_principal(krb5_const_principal);
45 add_to_transited (krb5_data *,
51 compress_transited (krb5_data *,
55 concat_authorization_data (krb5_context,
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 (kdc_realm_t *, krb5_kdc_req *,
66 const krb5_fulladdr *,
69 krb5_db_entry **krbtgt_ptr,
70 krb5_keyblock **, krb5_keyblock **,
71 krb5_pa_data **pa_tgs_req);
74 kdc_get_server_key (krb5_context, krb5_ticket *, unsigned int,
75 krb5_boolean match_enctype,
76 krb5_db_entry **, krb5_keyblock **, krb5_kvno *);
79 get_local_tgt(krb5_context context, const krb5_data *realm,
80 krb5_db_entry *candidate, krb5_db_entry **alias_out,
81 krb5_db_entry **storage_out);
84 validate_as_request (kdc_realm_t *, krb5_kdc_req *, krb5_db_entry,
85 krb5_db_entry, krb5_timestamp,
86 const char **, krb5_pa_data ***);
89 validate_forwardable(krb5_kdc_req *, krb5_db_entry,
90 krb5_db_entry, krb5_timestamp,
94 validate_tgs_request (kdc_realm_t *, krb5_kdc_req *, krb5_db_entry,
95 krb5_ticket *, krb5_timestamp,
96 const char **, krb5_pa_data ***);
99 check_indicators(krb5_context context, krb5_db_entry *server,
100 krb5_data *const *indicators);
103 fetch_asn1_field (unsigned char *, unsigned int, unsigned int, krb5_data *);
106 select_session_keytype (kdc_realm_t *kdc_active_realm,
107 krb5_db_entry *server,
109 krb5_enctype *ktypes);
111 void limit_string (char *name);
114 ktypes2str(char *s, size_t len, int nktypes, krb5_enctype *ktype);
117 rep_etypes2str(char *s, size_t len, krb5_kdc_rep *rep);
121 authind_contains(krb5_data *const *indicators, const char *ind);
124 authind_add(krb5_context context, const char *ind, krb5_data ***indicators);
127 authind_extract(krb5_context context, krb5_authdata **authdata,
128 krb5_data ***indicators);
132 cammac_create(krb5_context context, krb5_enc_tkt_part *enc_tkt_reply,
133 krb5_keyblock *server_key, krb5_db_entry *krbtgt,
134 krb5_authdata **contents, krb5_authdata ***cammac_out);
137 cammac_check_kdcver(krb5_context context, krb5_cammac *cammac,
138 krb5_enc_tkt_part *enc_tkt, krb5_db_entry *krbtgt);
142 process_as_req (krb5_kdc_req *, krb5_data *,
143 const krb5_fulladdr *, const krb5_fulladdr *, kdc_realm_t *,
144 verto_ctx *, loop_respond_fn, void *);
148 process_tgs_req (krb5_kdc_req *, krb5_data *, const krb5_fulladdr *,
149 kdc_realm_t *, krb5_data ** );
153 const krb5_fulladdr *,
154 const krb5_fulladdr *,
162 kdc_err(krb5_context call_context, errcode_t code, const char *fmt, ...)
163 #if !defined(__cplusplus) && (__GNUC__ > 2)
164 __attribute__((__format__(__printf__, 3, 4)))
170 enctype_requires_etype_info_2(krb5_enctype enctype);
173 missing_required_preauth (krb5_db_entry *client,
174 krb5_db_entry *server,
175 krb5_enc_tkt_part *enc_tkt_reply);
176 typedef void (*kdc_hint_respond_fn)(void *arg);
178 get_preauth_hint_list(krb5_kdc_req *request,
179 krb5_kdcpreauth_rock rock, krb5_pa_data ***e_data_out,
180 kdc_hint_respond_fn respond, void *arg);
182 load_preauth_plugins(struct server_handle * handle, krb5_context context,
185 unload_preauth_plugins(krb5_context context);
187 typedef void (*kdc_preauth_respond_fn)(void *arg, krb5_error_code code);
190 check_padata(krb5_context context, krb5_kdcpreauth_rock rock,
191 krb5_data *req_pkt, krb5_kdc_req *request,
192 krb5_enc_tkt_part *enc_tkt_reply, void **padata_context,
193 krb5_pa_data ***e_data, krb5_boolean *typed_e_data,
194 kdc_preauth_respond_fn respond, void *state);
197 return_padata(krb5_context context, krb5_kdcpreauth_rock rock,
198 krb5_data *req_pkt, krb5_kdc_req *request, krb5_kdc_rep *reply,
199 krb5_keyblock *encrypting_key, void **padata_context);
202 free_padata_context(krb5_context context, void *padata_context);
205 alloc_pa_data(krb5_preauthtype pa_type, size_t len, krb5_pa_data **out);
208 add_pa_data_element(krb5_pa_data ***list, krb5_pa_data *pa);
210 /* kdc_preauth_ec.c */
212 kdcpreauth_encrypted_challenge_initvt(krb5_context context, int maj_ver,
213 int min_ver, krb5_plugin_vtable vtable);
215 /* kdc_preauth_enctsc.c */
217 kdcpreauth_encrypted_timestamp_initvt(krb5_context context, int maj_ver,
218 int min_ver, krb5_plugin_vtable vtable);
222 load_authdata_plugins(krb5_context context);
224 unload_authdata_plugins(krb5_context context);
227 get_auth_indicators(krb5_context context, krb5_enc_tkt_part *enc_tkt,
228 krb5_db_entry *local_tgt, krb5_data ***indicators_out);
231 handle_authdata (krb5_context context,
233 krb5_db_entry *client,
234 krb5_db_entry *server,
235 krb5_db_entry *header_server,
236 krb5_db_entry *local_tgt,
237 krb5_keyblock *client_key,
238 krb5_keyblock *server_key,
239 krb5_keyblock *header_key,
241 krb5_kdc_req *request,
242 krb5_const_principal for_user_princ,
243 krb5_enc_tkt_part *enc_tkt_request,
244 krb5_data *const *auth_indicators,
245 krb5_enc_tkt_part *enc_tkt_reply);
248 krb5_error_code kdc_init_lookaside(krb5_context context);
249 krb5_boolean kdc_check_lookaside (krb5_context, krb5_data *, krb5_data **);
250 void kdc_insert_lookaside (krb5_context, krb5_data *, krb5_data *);
251 void kdc_remove_lookaside (krb5_context kcontext, krb5_data *);
252 void kdc_free_lookaside(krb5_context);
255 void reset_for_hangup(void *);
258 include_pac_p(krb5_context context, krb5_kdc_req *request);
261 return_enc_padata(krb5_context context,
262 krb5_data *req_pkt, krb5_kdc_req *request,
263 krb5_keyblock *reply_key,
264 krb5_db_entry *server,
265 krb5_enc_kdc_rep_part *reply_encpart,
266 krb5_boolean is_referral);
269 kdc_process_s4u2self_req (kdc_realm_t *kdc_active_realm,
270 krb5_kdc_req *request,
271 krb5_const_principal client_princ,
272 krb5_const_principal header_srv_princ,
273 krb5_boolean issuing_referral,
274 const krb5_db_entry *server,
275 krb5_keyblock *tgs_subkey,
276 krb5_keyblock *tgs_session,
277 krb5_timestamp kdc_time,
278 krb5_pa_s4u_x509_user **s4u2self_req,
279 krb5_db_entry **princ_ptr,
280 const char **status);
283 kdc_make_s4u2self_rep (krb5_context context,
284 krb5_keyblock *tgs_subkey,
285 krb5_keyblock *tgs_session,
286 krb5_pa_s4u_x509_user *req_s4u_user,
288 krb5_enc_kdc_rep_part *reply_encpart);
291 kdc_process_s4u2proxy_req (kdc_realm_t *kdc_active_realm,
292 krb5_kdc_req *request,
293 const krb5_enc_tkt_part *t2enc,
294 const krb5_db_entry *server,
295 krb5_const_principal server_princ,
296 krb5_const_principal proxy_princ,
297 const char **status);
300 kdc_check_transited_list (kdc_realm_t *kdc_active_realm,
301 const krb5_data *trans,
302 const krb5_data *realm1,
303 const krb5_data *realm2);
306 audit_as_request (krb5_kdc_req *request,
307 krb5_db_entry *client,
308 krb5_db_entry *server,
309 krb5_timestamp authtime,
310 krb5_error_code errcode);
313 audit_tgs_request (krb5_kdc_req *request,
314 krb5_const_principal client,
315 krb5_db_entry *server,
316 krb5_timestamp authtime,
317 krb5_error_code errcode);
320 validate_transit_path(krb5_context context,
321 krb5_const_principal client,
322 krb5_db_entry *server,
323 krb5_db_entry *krbtgt);
325 kdc_get_ticket_endtime(kdc_realm_t *kdc_active_realm,
327 krb5_timestamp endtime,
329 krb5_db_entry *client,
330 krb5_db_entry *server,
331 krb5_timestamp *out_endtime);
334 kdc_get_ticket_renewtime(kdc_realm_t *realm, krb5_kdc_req *request,
335 krb5_enc_tkt_part *tgt, krb5_db_entry *client,
336 krb5_db_entry *server, krb5_enc_tkt_part *tkt);
339 log_as_req(krb5_context context,
340 const krb5_fulladdr *local_addr,
341 const krb5_fulladdr *remote_addr,
342 krb5_kdc_req *request, krb5_kdc_rep *reply,
343 krb5_db_entry *client, const char *cname,
344 krb5_db_entry *server, const char *sname,
345 krb5_timestamp authtime,
346 const char *status, krb5_error_code errcode, const char *emsg);
348 log_tgs_req(krb5_context ctx, const krb5_fulladdr *from,
349 krb5_kdc_req *request, krb5_kdc_rep *reply,
350 krb5_principal cprinc, krb5_principal sprinc,
351 krb5_principal altcprinc,
352 krb5_timestamp authtime,
353 unsigned int c_flags,
354 const char *status, krb5_error_code errcode, const char *emsg);
356 log_tgs_badtrans(krb5_context ctx, krb5_principal cprinc,
357 krb5_principal sprinc, krb5_data *trcont,
358 krb5_error_code errcode);
361 log_tgs_alt_tgt(krb5_context context, krb5_principal p);
364 enum krb5_fast_kdc_flags {
365 KRB5_FAST_REPLY_KEY_USED = 0x1,
366 KRB5_FAST_REPLY_KEY_REPLACED = 0x02
370 * If *requestptr contains FX_FAST padata, compute the armor key, verify the
371 * checksum over checksummed_data, decode the FAST request, and substitute
372 * *requestptr with the inner request. Set the armor_key, cookie, and
373 * fast_options fields in state. state->cookie will be set for a non-FAST
374 * request if it contains FX_COOKIE padata. If inner_body_out is non-NULL, set
375 * *inner_body_out to a copy of the encoded inner body, or to NULL if the
376 * request is not a FAST request.
379 kdc_find_fast (krb5_kdc_req **requestptr, krb5_data *checksummed_data,
380 krb5_keyblock *tgs_subkey, krb5_keyblock *tgs_session,
381 struct kdc_request_state *state, krb5_data **inner_body_out);
384 kdc_fast_response_handle_padata (struct kdc_request_state *state,
385 krb5_kdc_req *request,
387 krb5_enctype enctype);
389 kdc_fast_handle_error (krb5_context context,
390 struct kdc_request_state *state,
391 krb5_kdc_req *request,
392 krb5_pa_data **in_padata, krb5_error *err,
393 krb5_data **fast_edata_out);
395 krb5_error_code kdc_fast_handle_reply_key(struct kdc_request_state *state,
396 krb5_keyblock *existing_key,
397 krb5_keyblock **out_key);
401 kdc_fast_hide_client(struct kdc_request_state *state);
404 kdc_handle_protected_negotiation( krb5_context context,
405 krb5_data *req_pkt, krb5_kdc_req *request,
406 const krb5_keyblock *reply_key,
407 krb5_pa_data ***out_enc_padata);
410 kdc_fast_read_cookie(krb5_context context, struct kdc_request_state *state,
411 krb5_kdc_req *req, krb5_db_entry *local_tgt);
413 krb5_boolean kdc_fast_search_cookie(struct kdc_request_state *state,
414 krb5_preauthtype pa_type, krb5_data *out);
416 krb5_error_code kdc_fast_set_cookie(struct kdc_request_state *state,
417 krb5_preauthtype pa_type,
418 const krb5_data *data);
421 kdc_fast_make_cookie(krb5_context context, struct kdc_request_state *state,
422 krb5_db_entry *local_tgt,
423 krb5_const_principal client_princ,
424 krb5_pa_data **cookie_out);
426 /* Information handle for kdcpreauth callbacks. All pointers are aliases. */
427 struct krb5_kdcpreauth_rock_st {
428 krb5_kdc_req *request;
429 krb5_data *inner_body;
430 krb5_db_entry *client;
431 krb5_db_entry *local_tgt;
432 krb5_key_data *client_key;
433 krb5_keyblock *client_keyblock;
434 struct kdc_request_state *rstate;
436 krb5_data ***auth_indicators;
437 krb5_boolean send_freshness_token;
440 #define isflagset(flagfield, flag) (flagfield & (flag))
441 #define setflag(flagfield, flag) (flagfield |= (flag))
442 #define clear(flagfield, flag) (flagfield &= ~(flag))
445 #define min(a, b) ((a) < (b) ? (a) : (b))
446 #define max(a, b) ((a) > (b) ? (a) : (b))
449 #define ts_min(a, b) (ts_after(a, b) ? (b) : (a))
451 #define ADDRTYPE2FAMILY(X) \
452 ((X) == ADDRTYPE_INET6 ? AF_INET6 : (X) == ADDRTYPE_INET ? AF_INET : -1)
454 /* RFC 4120: KRB5KDC_ERR_KEY_TOO_WEAK
455 * RFC 4556: KRB5KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED */
456 #define KRB5KDC_ERR_KEY_TOO_WEAK KRB5KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED
457 /* TGS-REQ options where the service can be a non-TGS principal */
459 #define NON_TGT_OPTION (KDC_OPT_FORWARDED | KDC_OPT_PROXY | KDC_OPT_RENEW | \
462 /* TGS-REQ options which are not compatible with referrals */
463 #define NO_REFERRAL_OPTION (NON_TGT_OPTION | KDC_OPT_ENC_TKT_IN_SKEY)
466 * Mask of KDC options that request the corresponding ticket flag with
467 * the same number. Some of these are invalid for AS-REQs, but
468 * validate_as_request() takes care of that. KDC_OPT_RENEWABLE isn't
469 * here because it needs special handling in
470 * kdc_get_ticket_renewtime().
472 * According to RFC 4120 section 3.1.3 the following AS-REQ options
473 * request their corresponding ticket flags if local policy allows:
475 * KDC_OPT_FORWARDABLE KDC_OPT_ALLOW_POSTDATE
476 * KDC_OPT_POSTDATED KDC_OPT_PROXIABLE
479 * RFC 1510 section A.6 shows pseudocode indicating that the following
480 * TGS-REQ options request their corresponding ticket flags if local
483 * KDC_OPT_FORWARDABLE KDC_OPT_FORWARDED
484 * KDC_OPT_PROXIABLE KDC_OPT_PROXY
485 * KDC_OPT_POSTDATED KDC_OPT_RENEWABLE
487 * The above list omits KDC_OPT_ALLOW_POSTDATE, but RFC 4120 section
488 * 5.4.1 says the TGS also handles it.
490 * RFC 6112 makes KDC_OPT_REQUEST_ANONYMOUS the same bit number as
493 #define OPTS_COMMON_FLAGS_MASK \
494 (KDC_OPT_FORWARDABLE | KDC_OPT_FORWARDED | \
495 KDC_OPT_PROXIABLE | KDC_OPT_PROXY | \
496 KDC_OPT_ALLOW_POSTDATE | KDC_OPT_POSTDATED | \
497 KDC_OPT_REQUEST_ANONYMOUS)
499 /* Copy KDC options that request the corresponding ticket flags. */
500 #define OPTS2FLAGS(x) (x & OPTS_COMMON_FLAGS_MASK)
503 * Mask of ticket flags for the TGS to propagate from a ticket to a
506 * RFC 4120 section 2.1 says the following flags are carried forward
507 * from an initial ticket to derivative tickets:
512 * RFC 4120 section 2.6 says TKT_FLG_FORWARDED is carried forward to
513 * derivative tickets. Proxy tickets are basically identical to
514 * forwarded tickets except that a TGT may never be proxied, therefore
515 * tickets derived from proxy tickets should have TKT_FLAG_PROXY set.
516 * RFC 4120 and RFC 1510 apparently have an accidental omission in not
517 * requiring that tickets derived from a proxy ticket have
518 * TKT_FLG_PROXY set. Previous code also omitted this behavior.
520 * RFC 6112 section 4.2 implies that TKT_FLG_ANONYMOUS must be
521 * propagated from an anonymous ticket to derivative tickets.
523 #define TGS_COPIED_FLAGS_MASK \
524 (TKT_FLG_FORWARDED | TKT_FLG_PROXY | \
525 TKT_FLG_PRE_AUTH | TKT_FLG_HW_AUTH | \
528 /* Copy appropriate header ticket flags to new ticket. */
529 #define COPY_TKT_FLAGS(x) (x & TGS_COPIED_FLAGS_MASK)
531 int check_anon(kdc_realm_t *kdc_active_realm,
532 krb5_principal client, krb5_principal server);
533 int errcode_to_protocol(krb5_error_code code);
535 char *data2string(krb5_data *d);
537 #endif /* __KRB5_KDC_UTIL__ */