diff options
| author | Zhanna Tsitkov <tsitkova@mit.edu> | 2013-07-20 15:47:42 -0400 |
|---|---|---|
| committer | Ben Kaduk <kaduk@mit.edu> | 2013-10-04 20:25:49 -0400 |
| commit | 1003f0173f266a6428ccf2c89976f0029d3ee831 (patch) | |
| tree | a845ce60636aca59e80f4db95e4b6ec82788081c /src/kdc | |
| parent | b6d5e3af806bb60c37a831a72eff3e7e99bea6e9 (diff) | |
| download | krb5-1003f0173f266a6428ccf2c89976f0029d3ee831.tar.gz krb5-1003f0173f266a6428ccf2c89976f0029d3ee831.tar.xz krb5-1003f0173f266a6428ccf2c89976f0029d3ee831.zip | |
KDC Audit infrastructure and plugin implementation
Per project http://k5wiki.kerberos.org/wiki/Projects/Audit
The purpose of this project is to create an Audit infrastructure to monitor
security related events on the KDC.
The following events are targeted in the initial version:
- startup and shutdown of the KDC;
- AS_REQ and TGS_REQ exchanges. This includes client address and port, KDC
request and request ID, KDC reply, primary and derived ticket and their
ticket IDs, second ticket ID, cross-realm referral, was ticket renewed and
validated, local policy violation and protocol constraints, and KDC status
message.
Ticket ID is introduced to allow to link tickets to their initial TGT at any
stage of the Kerberos exchange. For the purpose of this project it is a private
to KDC ticket ID: each successfully created ticket is hashed and recorded
into audit log. The administrators can correlate the primary and derived
ticket IDs after the fact.
Request ID is a randomly generated alpha-numeric string. Using this ID an
administrator can easily correlate multiple audit events related to a single
request. It should be informative both in cases when the request is sent to
multiple KDCs, or to the same KDC multiple times.
For the purpose of testing and demo of the Audit, the JSON based modules are
implemented: "test" and "simple" audit modules respectively.
The file plugins/audit/j_dict.h is a dictionary used in this implememtations.
The new Audit system is build-time enabled and run-time pluggable.
[kaduk@mit.edu: remove potential KDC crashes, minor reordering]
ticket: 7712
target_version: 1.12
Diffstat (limited to 'src/kdc')
| -rw-r--r-- | src/kdc/Makefile.in | 2 | ||||
| -rw-r--r-- | src/kdc/do_as_req.c | 49 | ||||
| -rw-r--r-- | src/kdc/do_tgs_req.c | 81 | ||||
| -rw-r--r-- | src/kdc/kdc_audit.c | 331 | ||||
| -rw-r--r-- | src/kdc/kdc_audit.h | 82 | ||||
| -rw-r--r-- | src/kdc/main.c | 12 |
6 files changed, 552 insertions, 5 deletions
diff --git a/src/kdc/Makefile.in b/src/kdc/Makefile.in index 1b3b19b2c..1591e9ab0 100644 --- a/src/kdc/Makefile.in +++ b/src/kdc/Makefile.in @@ -22,6 +22,7 @@ SRCS= \ $(srcdir)/extern.c \ $(srcdir)/replay.c \ $(srcdir)/kdc_authdata.c \ + $(srcdir)/kdc_audit.c \ $(srcdir)/kdc_transit.c \ $(srcdir)/tgs_policy.c @@ -40,6 +41,7 @@ OBJS= \ extern.o \ replay.o \ kdc_authdata.o \ + kdc_audit.o \ kdc_transit.o \ tgs_policy.o diff --git a/src/kdc/do_as_req.c b/src/kdc/do_as_req.c index 036840739..268d4f452 100644 --- a/src/kdc/do_as_req.c +++ b/src/kdc/do_as_req.c @@ -2,8 +2,8 @@ /* kdc/do_as_req.c */ /* * Portions Copyright (C) 2007 Apple Inc. - * Copyright 1990,1991,2007,2008,2009 by the Massachusetts Institute of Technology. - * All Rights Reserved. + * Copyright 1990, 1991, 2007, 2008, 2009, 2013 by the Massachusetts Institute + * of Technology. All Rights Reserved. * * Export of this software from the United States of America may * require a specific license from the United States Government. @@ -68,6 +68,7 @@ #endif /* HAVE_NETINET_IN_H */ #include "kdc_util.h" +#include "kdc_audit.h" #include "policy.h" #include <kadm5/admin.h> #include "adm_proto.h" @@ -121,6 +122,7 @@ struct as_req_state { krb5_error_code preauth_err; kdc_realm_t *active_realm; + krb5_audit_state *au_state; }; static void @@ -137,6 +139,7 @@ finish_process_as_req(struct as_req_state *state, krb5_error_code errcode) loop_respond_fn oldrespond; void *oldarg; kdc_realm_t *kdc_active_realm = state->active_realm; + krb5_audit_state *au_state = state->au_state; assert(state); oldrespond = state->respond; @@ -145,6 +148,8 @@ finish_process_as_req(struct as_req_state *state, krb5_error_code errcode) if (errcode) goto egress; + au_state->stage = ENCR_REP; + if ((errcode = validate_forwardable(state->request, *state->client, *state->server, state->kdc_time, &state->status))) { @@ -277,6 +282,14 @@ finish_process_as_req(struct as_req_state *state, krb5_error_code errcode) state->status = "ENCRYPTING_TICKET"; goto egress; } + + errcode = kau_make_tkt_id(kdc_context, &state->ticket_reply, + &au_state->tkt_out_id); + if (errcode) { + state->status = "GENERATE_TICKET_ID"; + goto egress; + } + state->ticket_reply.enc_part.kvno = server_key->key_data_kvno; errcode = kdc_fast_response_handle_padata(state->rstate, state->request, @@ -332,6 +345,13 @@ finish_process_as_req(struct as_req_state *state, krb5_error_code errcode) egress: if (errcode != 0) assert (state->status != 0); + + au_state->status = state->status; + au_state->reply = &state->reply; + kau_as_req(kdc_context, + (errcode || state->preauth_err) ? FALSE : TRUE, au_state); + kau_free_kdc_req(au_state); + free_padata_context(kdc_context, state->pa_context); if (as_encrypting_key) krb5_free_keyblock(kdc_context, as_encrypting_key); @@ -456,6 +476,7 @@ process_as_req(krb5_kdc_req *request, krb5_data *req_pkt, krb5_data encoded_req_body; krb5_enctype useenctype; struct as_req_state *state; + krb5_audit_state *au_state = NULL; state = k5alloc(sizeof(*state), &errcode); if (state == NULL) { @@ -472,13 +493,29 @@ process_as_req(krb5_kdc_req *request, krb5_data *req_pkt, errcode = kdc_make_rstate(kdc_active_realm, &state->rstate); if (errcode != 0) { (*respond)(arg, errcode, NULL); + free(state); return; } + + /* Initialize audit state. */ + errcode = kau_init_kdc_req(kdc_context, state->request, from, &au_state); + if (errcode) { + (*respond)(arg, errcode, NULL); + kdc_free_rstate(state->rstate); + free(state); + return; + } + state->au_state = au_state; + if (state->request->msg_type != KRB5_AS_REQ) { state->status = "msg_type mismatch"; errcode = KRB5_BADMSGTYPE; goto errout; } + + /* Seed the audit trail with the request ID and basic information. */ + kau_as_req(kdc_context, TRUE, au_state); + if (fetch_asn1_field((unsigned char *) req_pkt->data, 1, 4, &encoded_req_body) != 0) { errcode = ASN1_BAD_ID; @@ -500,6 +537,7 @@ process_as_req(krb5_kdc_req *request, krb5_data *req_pkt, goto errout; } } + au_state->request = state->request; state->rock.request = state->request; state->rock.inner_body = state->inner_body; state->rock.rstate = state->rstate; @@ -559,10 +597,13 @@ process_as_req(krb5_kdc_req *request, krb5_data *req_pkt, if (!is_local_principal(kdc_active_realm, state->client->princ)) { /* Entry is a referral to another realm */ state->status = "REFERRAL"; + au_state->cl_realm = &state->client->princ->realm; errcode = KRB5KDC_ERR_WRONG_REALM; goto errout; } + au_state->stage = SRVC_PRINC; + if (!state->request->server) { state->status = "NULL_SERVER"; errcode = KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN; @@ -593,6 +634,8 @@ process_as_req(krb5_kdc_req *request, krb5_data *req_pkt, goto errout; } + au_state->stage = VALIDATE_POL; + if ((errcode = krb5_timeofday(kdc_context, &state->kdc_time))) { state->status = "TIMEOFDAY"; goto errout; @@ -609,6 +652,8 @@ process_as_req(krb5_kdc_req *request, krb5_data *req_pkt, goto errout; } + au_state->stage = ISSUE_TKT; + /* * Select the keytype for the ticket session key. */ diff --git a/src/kdc/do_tgs_req.c b/src/kdc/do_tgs_req.c index dada37530..c12de2b3e 100644 --- a/src/kdc/do_tgs_req.c +++ b/src/kdc/do_tgs_req.c @@ -1,8 +1,8 @@ /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* kdc/do_tgs_req.c - KDC Routines to deal with TGS_REQ's */ /* - * Copyright 1990,1991,2001,2007,2008,2009 by the Massachusetts Institute of Technology. - * All Rights Reserved. + * Copyright 1990, 1991, 2001, 2007, 2008, 2009, 2013 by the Massachusetts + * Institute of Technology. All Rights Reserved. * * Export of this software from the United States of America may * require a specific license from the United States Government. @@ -63,6 +63,7 @@ #endif #include "kdc_util.h" +#include "kdc_audit.h" #include "policy.h" #include "extern.h" #include "adm_proto.h" @@ -135,6 +136,7 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, krb5_data scratch; krb5_pa_data **e_data = NULL; kdc_realm_t *kdc_active_realm = NULL; + krb5_audit_state *au_state = NULL; memset(&reply, 0, sizeof(reply)); memset(&reply_encpart, 0, sizeof(reply_encpart)); @@ -163,6 +165,16 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, krb5_free_kdc_req(handle->kdc_err_context, request); return errcode; } + + /* Initialize audit state. */ + errcode = kau_init_kdc_req(kdc_context, request, from, &au_state); + if (errcode) { + krb5_free_kdc_req(handle->kdc_err_context, request); + return errcode; + } + /* Seed the audit trail with the request ID and basic information. */ + kau_tgs_req(kdc_context, TRUE, au_state); + errcode = kdc_process_tgs_req(kdc_active_realm, request, from, pkt, &header_ticket, &krbtgt, &tgskey, &subkey, &pa_tgs_req); @@ -179,6 +191,13 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, status="UNEXPECTED NULL in header_ticket"; goto cleanup; } + errcode = kau_make_tkt_id(kdc_context, header_ticket, + &au_state->tkt_in_id); + if (errcode) { + status = "GENERATE_TICKET_ID"; + goto cleanup; + } + scratch.length = pa_tgs_req->length; scratch.data = (char *) pa_tgs_req->contents; errcode = kdc_find_fast(&request, &scratch, subkey, @@ -188,6 +207,9 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, goto cleanup; } + /* Ignore (for now) the request modification due to FAST processing. */ + au_state->request = request; + /* * Pointer to the encrypted part of the header ticket, which may be * replaced to point to the encrypted part of the evidence ticket @@ -202,6 +224,8 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, * decrypted with the session key. */ + au_state->stage = SRVC_PRINC; + /* XXX make sure server here has the proper realm...taken from AP_REQ header? */ @@ -222,6 +246,8 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, is_referral = is_cross_tgs_principal(server->princ) && !krb5_principal_compare(kdc_context, request->server, server->princ); + au_state->stage = VALIDATE_POL; + if ((errcode = krb5_timeofday(kdc_context, &kdc_time))) { status = "TIME_OF_DAY"; goto cleanup; @@ -232,6 +258,8 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, kdc_time, &status, &e_data))) { if (!status) status = "UNKNOWN_REASON"; + if (retval == KDC_ERR_POLICY || retval == KDC_ERR_BADOPTION) + au_state->violation = PROT_CONSTRAINT; errcode = retval + ERROR_TABLE_BASE_krb5; goto cleanup; } @@ -250,6 +278,16 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, &s4u_x509_user, &client, &status); + if (s4u_x509_user != NULL || errcode != 0) { + if (s4u_x509_user != NULL) + au_state->s4u2self_user = s4u_x509_user->user_id.user; + if (errcode == KDC_ERR_POLICY || errcode == KDC_ERR_BADOPTION) + au_state->violation = PROT_CONSTRAINT; + au_state->status = status; + kau_s4u2self(kdc_context, errcode ? FALSE : TRUE, au_state); + au_state->s4u2self_user = NULL; + } + if (errcode) goto cleanup; if (s4u_x509_user != NULL) { @@ -263,6 +301,7 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, } } + /* Deal with user-to-user and constrained delegation */ errcode = decrypt_2ndtkt(kdc_active_realm, request, c_flags, &stkt_server, &status); if (errcode) @@ -277,6 +316,19 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, header_ticket->enc_part2->client, request->server, &status); + if (errcode == KDC_ERR_POLICY || errcode == KDC_ERR_BADOPTION) + au_state->violation = PROT_CONSTRAINT; + else if (errcode) + au_state->violation = LOCAL_POLICY; + au_state->status = status; + retval = kau_make_tkt_id(kdc_context, request->second_ticket[st_idx], + &au_state->evid_tkt_id); + if (retval) { + status = "GENERATE_TICKET_ID"; + errcode = retval; + goto cleanup; + } + kau_s4u2proxy(kdc_context, errcode ? FALSE : TRUE, au_state); if (errcode) goto cleanup; @@ -293,6 +345,8 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, } else assert(stkt_server == NULL); + au_state->stage = ISSUE_TKT; + errcode = gen_session_key(kdc_active_realm, request, server, &session_key, &status); if (errcode) @@ -621,6 +675,7 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, !isflagset(enc_tkt_reply.flags, TKT_FLG_TRANSIT_POLICY_CHECKED)) { errcode = KRB5KDC_ERR_POLICY; status = "BAD_TRANSIT"; + au_state->violation = LOCAL_POLICY; goto cleanup; } @@ -643,11 +698,14 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, altcprinc = client2; errcode = KRB5KDC_ERR_SERVER_NOMATCH; status = "2ND_TKT_MISMATCH"; + au_state->status = status; + kau_u2u(kdc_context, FALSE, au_state); goto cleanup; } ticket_kvno = 0; ticket_reply.enc_part.enctype = t2enc->session->enctype; + kau_u2u(kdc_context, TRUE, au_state); st_idx++; } else { ticket_kvno = server_key->key_data_kvno; @@ -663,6 +721,7 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, } ticket_reply.enc_part.kvno = ticket_kvno; /* Start assembling the response */ + au_state->stage = ENCR_REP; reply.msg_type = KRB5_TGS_REP; if (isflagset(c_flags, KRB5_KDB_FLAG_PROTOCOL_TRANSITION) && krb5int_find_pa_data(kdc_context, request->padata, @@ -675,8 +734,11 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, &reply_encpart); if (errcode) { status = "KDC_RETURN_S4U2SELF_PADATA"; - goto cleanup; + au_state->status = status; } + kau_s4u2self(kdc_context, errcode ? FALSE : TRUE, au_state); + if (errcode) + goto cleanup; } reply.client = enc_tkt_reply.client; @@ -730,6 +792,12 @@ process_tgs_req(struct server_handle *handle, krb5_data *pkt, goto cleanup; } + errcode = kau_make_tkt_id(kdc_context, &ticket_reply, &au_state->tkt_out_id); + if (errcode) { + status = "GENERATE_TICKET_ID"; + goto cleanup; + } + if (kdc_fast_hide_client(state)) reply.client = (krb5_principal)krb5_anonymous_principal(); errcode = krb5_encode_kdc_rep(kdc_context, KRB5_TGS_REP, &reply_encpart, @@ -757,6 +825,13 @@ cleanup: krb5_free_keyblock(kdc_context, reply_key); if (errcode) emsg = krb5_get_error_message (kdc_context, errcode); + + au_state->status = status; + if (!errcode) + au_state->reply = &reply; + kau_tgs_req(kdc_context, errcode ? FALSE : TRUE, au_state); + kau_free_kdc_req(au_state); + log_tgs_req(kdc_context, from, request, &reply, cprinc, sprinc, altcprinc, authtime, c_flags, status, errcode, emsg); diff --git a/src/kdc/kdc_audit.c b/src/kdc/kdc_audit.c new file mode 100644 index 000000000..c9a7f9f9d --- /dev/null +++ b/src/kdc/kdc_audit.c @@ -0,0 +1,331 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* kdc_audit.c - Interface for KDC audit plugins. */ +/* + * Copyright (C) 2013 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "k5-int.h" +#include "kdc_util.h" +#include "kdc_audit.h" +/* for krb5_klog_syslog */ +#include <syslog.h> +#include "adm_proto.h" + +struct audit_module_handle_st { + struct krb5_audit_vtable_st vt; + krb5_audit_moddata auctx; +}; +typedef struct audit_module_handle_st *audit_module_handle; + +static audit_module_handle *handles = NULL; + +static void +free_handles(audit_module_handle *list) +{ + audit_module_handle *hp, hdl; + + if (list == NULL) + return; + + for (hp = list; *hp != NULL; hp++) { + hdl = *hp; + if (hdl->vt.close != NULL) + hdl->vt.close(hdl->auctx); + free(hdl); + } + free(list); +} + +/* + * Load all available audit plugin modules and prepare for logging. The list of + * modules is stored as an array in handles. Use unload_audit_modules() to free + * resources allocated by this function. + */ +krb5_error_code +load_audit_modules(krb5_context context) +{ + krb5_error_code ret = 0; + krb5_plugin_initvt_fn *modules = NULL, *mod; + struct krb5_audit_vtable_st vtable; + audit_module_handle *list = NULL, hdl = NULL; + krb5_audit_moddata auctx; + int count = 0; + + if (context == NULL || handles != NULL) + return EINVAL; + + /* Get audit plugin vtable. */ + ret = k5_plugin_load_all(context, PLUGIN_INTERFACE_AUDIT, &modules); + if (ret) + return ret; + + /* Allocate handle, initialize vtable. */ + for (count = 0; modules[count] != NULL; count++); + list = k5calloc(count + 1, sizeof(*list), &ret); + if (list == NULL) + goto cleanup; + count = 0; + for (mod = modules; *mod != NULL; mod++) { + hdl = k5alloc(sizeof(*hdl), &ret); + if (hdl == NULL) + goto cleanup; + ret = (*mod)(context, 1, 1, (krb5_plugin_vtable)&hdl->vt); + if (ret) { + free(hdl); + hdl = NULL; + continue; + } + + vtable = hdl->vt; + if (vtable.open != NULL) { + ret = vtable.open(&auctx); + if (ret) { + krb5_klog_syslog(LOG_ERR, + _("audit plugin %s failed to open. error=%i"), + vtable.name, ret); + goto cleanup; + } + hdl->auctx = auctx; + } + list[count++] = hdl; + list[count] = NULL; + hdl = NULL; + } + list[count] = NULL; + handles = list; + list = NULL; + ret = 0; + +cleanup: + free(hdl); + k5_plugin_free_modules(context, modules); + free_handles(list); + return ret; +} + +/* Free resources allocated by load_audit_modules() function. */ +void +unload_audit_modules(krb5_context context) +{ + free_handles(handles); +} + +/* + * Write the output ticket ID into newly-allocated buffer. + * Returns 0 on success. + */ +krb5_error_code +kau_make_tkt_id(krb5_context context, + const krb5_ticket *ticket, char **out) +{ + krb5_error_code ret = 0; + char *hash = NULL, *ptr; + krb5_checksum cksum; + unsigned int i; + + *out = NULL; + + if (ticket == NULL) + return EINVAL; + + ret = krb5_c_make_checksum(context, CKSUMTYPE_RSA_MD5, NULL, 0, + &ticket->enc_part.ciphertext, &cksum); + if (ret) + return ret; + + hash = k5alloc(cksum.length * 2 + 1, &ret); + if (hash != NULL) { + for (i = 0, ptr = hash; i < cksum.length; i++, ptr += 2) + snprintf(ptr, 3, "%02X", cksum.contents[i]); + *ptr = '\0'; + *out = hash; + } + krb5_free_checksum_contents(context, &cksum); + + return 0; +} + +/* + * Create and initialize krb5_audit_state structure. + * Returns 0 on success. + */ +krb5_error_code +kau_init_kdc_req(krb5_context context, + krb5_kdc_req *request, const krb5_fulladdr *from, + krb5_audit_state **state_out) +{ + krb5_error_code ret = 0; + krb5_audit_state *state = NULL; + + state = k5calloc(1, sizeof(*state), &ret); + if (state == NULL) + return ret; + + state->request = request; + state->cl_addr = from->address; + state->cl_port = from->port; + state->stage = AUTHN_REQ_CL; + ret = krb5int_random_string(context, state->req_id, + sizeof(state->req_id)); + if (ret) { + free(state); + return ret; + } + *state_out = state; + + return 0; +} + +/* Free resources allocated by kau_init_kdc_req() and kau_make_tkt_id() + * routines. */ +void +kau_free_kdc_req(krb5_audit_state *state) +{ + free(state->tkt_in_id); + free(state->tkt_out_id); + free(state->evid_tkt_id); + free(state); +} + +/* Call the KDC start/stop audit plugin entry points. */ + +void +kau_kdc_stop(krb5_context context, const krb5_boolean ev_success) +{ + audit_module_handle *hp, hdl; + + if (handles == NULL) + return; + + for (hp = handles; *hp != NULL; hp++) { + hdl = *hp; + if (hdl->vt.kdc_stop != NULL) + hdl->vt.kdc_stop(hdl->auctx, ev_success); + } +} + +void +kau_kdc_start(krb5_context context, const krb5_boolean ev_success) +{ + audit_module_handle *hp, hdl; + + if (handles == NULL) + return; + + for (hp = handles; *hp != NULL; hp++) { + hdl = *hp; + if (hdl->vt.kdc_start != NULL) + hdl->vt.kdc_start(hdl->auctx, ev_success); + } +} + +/* Call the AS-REQ audit plugin entry point. */ +void +kau_as_req(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state) +{ + audit_module_handle *hp, hdl; + + if (handles == NULL) + return; + + for (hp = handles; *hp != NULL; hp++) { + hdl = *hp; + if (hdl->vt.as_req != NULL) + hdl->vt.as_req(hdl->auctx, ev_success, state); + } +} + +/* Call the TGS-REQ audit plugin entry point. */ +void +kau_tgs_req(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state) +{ + audit_module_handle *hp, hdl; + + if (handles == NULL) + return; + + for (hp = handles; *hp != NULL; hp++) { + hdl = *hp; + if (hdl->vt.tgs_req != NULL) + hdl->vt.tgs_req(hdl->auctx, ev_success, state); + } +} + +/* Call the S4U2Self audit plugin entry point. */ +void +kau_s4u2self(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state) +{ + audit_module_handle *hp, hdl; + + if (handles == NULL) + return; + + for (hp = handles; *hp != NULL; hp++) { + hdl = *hp; + if (hdl->vt.tgs_s4u2self != NULL) + hdl->vt.tgs_s4u2self(hdl->auctx, ev_success, state); + } +} + +/* Call the S4U2Proxy audit plugin entry point. */ +void +kau_s4u2proxy(krb5_context context,const krb5_boolean ev_success, + krb5_audit_state *state) +{ + audit_module_handle *hp, hdl; + + if (handles == NULL) + return; + + for (hp = handles; *hp != NULL; hp++) { + hdl = *hp; + if (hdl->vt.tgs_s4u2proxy != NULL) + hdl->vt.tgs_s4u2proxy(hdl->auctx, ev_success, state); + } +} + +/* Call the U2U audit plugin entry point. */ +void +kau_u2u(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state) +{ + audit_module_handle *hp, hdl; + + if (handles == NULL) + return; + + for (hp = handles; *hp != NULL; hp++) { + hdl = *hp; + if (hdl->vt.tgs_u2u != NULL) + hdl->vt.tgs_u2u(hdl->auctx, ev_success, state); + } +} diff --git a/src/kdc/kdc_audit.h b/src/kdc/kdc_audit.h new file mode 100644 index 000000000..c2f2e2177 --- /dev/null +++ b/src/kdc/kdc_audit.h @@ -0,0 +1,82 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* include/kdc_audit.h - KDC-facing API for audit */ +/* + * Copyright 2013 by the Massachusetts Institute of Technology. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef KRB5_KDC_AUDIT__ +#define KRB5_KDC_AUDIT__ + +#include <krb5/krb5.h> +#include <net-server.h> +#include <krb5/audit_plugin.h> + +krb5_error_code load_audit_modules(krb5_context context); +void unload_audit_modules(krb5_context context); + +/* Utilities */ + +krb5_error_code +kau_make_tkt_id(krb5_context context, + const krb5_ticket *ticket, char **out); + +krb5_error_code +kau_init_kdc_req(krb5_context context, krb5_kdc_req *request, + const krb5_fulladdr *from, krb5_audit_state **au_state); + +void kau_free_kdc_req(krb5_audit_state *state); + +/* KDC-facing audit API */ + +void +kau_kdc_start(krb5_context context, const krb5_boolean ev_success); + +void +kau_kdc_stop(krb5_context context, const krb5_boolean ev_success); + +void +kau_as_req(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state); + +void +kau_tgs_req(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state); + +void +kau_s4u2self(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state); + +void +kau_s4u2proxy(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state); + +void +kau_u2u(krb5_context context, const krb5_boolean ev_success, + krb5_audit_state *state); + +#endif /* KRB5_KDC_AUDIT__ */ diff --git a/src/kdc/main.c b/src/kdc/main.c index 950fa41d7..0f5961acb 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -38,6 +38,7 @@ #include <kadm5/admin.h> #include "adm_proto.h" #include "kdc_util.h" +#include "kdc_audit.h" #include "extern.h" #include "kdc5_err.h" #include "kdb_kt.h" @@ -1044,15 +1045,26 @@ int main(int argc, char **argv) /* We get here only in a worker child process; re-initialize realms. */ initialize_realms(kcontext, argc, argv); } + + /* Initialize audit system and audit KDC startup. */ + retval = load_audit_modules(kcontext); + if (retval) { + kdc_err(kcontext, retval, _("while loading audit plugin module(s)")); + finish_realms(); + return 1; + } krb5_klog_syslog(LOG_INFO, _("commencing operation")); if (nofork) fprintf(stderr, _("%s: starting...\n"), kdc_progname); + kau_kdc_start(kcontext, TRUE); verto_run(ctx); loop_free(ctx); + kau_kdc_stop(kcontext, TRUE); krb5_klog_syslog(LOG_INFO, _("shutting down")); unload_preauth_plugins(kcontext); unload_authdata_plugins(kcontext); + unload_audit_modules(kcontext); krb5_klog_close(kcontext); finish_realms(); if (shandle.kdc_realmlist) |
