summaryrefslogtreecommitdiffstats
path: root/src/plugins/audit/test/au_test.c
diff options
context:
space:
mode:
authorZhanna Tsitkov <tsitkova@mit.edu>2013-07-20 15:47:42 -0400
committerBen Kaduk <kaduk@mit.edu>2013-10-04 20:25:49 -0400
commit1003f0173f266a6428ccf2c89976f0029d3ee831 (patch)
treea845ce60636aca59e80f4db95e4b6ec82788081c /src/plugins/audit/test/au_test.c
parentb6d5e3af806bb60c37a831a72eff3e7e99bea6e9 (diff)
downloadkrb5-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/plugins/audit/test/au_test.c')
-rw-r--r--src/plugins/audit/test/au_test.c228
1 files changed, 228 insertions, 0 deletions
diff --git a/src/plugins/audit/test/au_test.c b/src/plugins/audit/test/au_test.c
new file mode 100644
index 0000000000..54bf564b15
--- /dev/null
+++ b/src/plugins/audit/test/au_test.c
@@ -0,0 +1,228 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* plugins/audit/au_test.c - Test Audit plugin implementation */
+/*
+ * 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.
+ */
+/*
+ * This test is to verify the JSON-based KDC audit functionality.
+ * It utilized MIT Kerberos <kdc_j_encode.h> routines for JSON processing.
+ */
+
+#include <k5-int.h>
+#include <krb5/audit_plugin.h>
+#include <kdc_j_encode.h>
+#include "k5-thread.h"
+
+struct krb5_audit_moddata_st {
+ int au_fd;
+};
+
+krb5_error_code
+audit_test_initvt(krb5_context context, int maj_ver, int min_ver,
+ krb5_plugin_vtable vtable);
+
+static FILE *au_fd;
+static k5_mutex_t lock = K5_MUTEX_PARTIAL_INITIALIZER;
+
+/* Open connection to the audit system. Returns 0 on success. */
+static krb5_error_code
+open_au(krb5_audit_moddata *auctx)
+{
+ au_fd = fopen("au.log", "a+");
+ if ( au_fd < 0) {
+ return KRB5_PLUGIN_NO_HANDLE; /* audit module is unavailable */
+ }
+ k5_mutex_init(&lock);
+ return 0;
+}
+
+/* Close connection to the audit system. Returns 0. */
+static krb5_error_code
+close_au(krb5_audit_moddata auctx)
+{
+ fclose(au_fd);
+ k5_mutex_destroy(&lock);
+ return 0;
+}
+
+/* Log KDC-start event. Returns 0 on success. */
+static krb5_error_code
+j_kdc_start(krb5_audit_moddata auctx, krb5_boolean ev_success)
+{
+ krb5_error_code ret = 0;
+ char *jout = NULL;
+
+ ret = kau_j_kdc_start(ev_success, &jout);
+ if (ret)
+ return ret;
+ k5_mutex_lock(&lock);
+ fprintf(au_fd,"%s\n", jout);
+ fflush(au_fd);
+ k5_mutex_unlock(&lock);
+ free(jout);
+ return ret;
+}
+
+/* Log KDC-stop event. Returns 0 on success. */
+static krb5_error_code
+j_kdc_stop(krb5_audit_moddata auctx, krb5_boolean ev_success)
+{
+ krb5_error_code ret = 0;
+ char *jout = NULL;
+
+ ret = kau_j_kdc_stop(ev_success, &jout);
+ if (ret)
+ return ret;
+ k5_mutex_lock(&lock);
+ fprintf(au_fd,"%s\n", jout);
+ fflush(au_fd);
+ k5_mutex_unlock(&lock);
+ free(jout);
+ return ret;
+}
+
+/* Log AS_REQ event. Returns 0 on success. */
+static krb5_error_code
+j_as_req(krb5_audit_moddata auctx, krb5_boolean ev_success,
+ krb5_audit_state *state)
+{
+ krb5_error_code ret = 0;
+ char *jout = NULL;
+
+ ret = kau_j_as_req(ev_success, state, &jout);
+ if (ret)
+ return ret;
+ k5_mutex_lock(&lock);
+ fprintf(au_fd,"%s\n", jout);
+ fflush(au_fd);
+ k5_mutex_unlock(&lock);
+ free(jout);
+ return ret;
+}
+
+/* Log TGS_REQ event. Returns 0 on success. */
+static krb5_error_code
+j_tgs_req(krb5_audit_moddata auctx, krb5_boolean ev_success,
+ krb5_audit_state *state)
+{
+ krb5_error_code ret = 0;
+ char *jout = NULL;
+
+ ret = kau_j_tgs_req(ev_success, state, &jout);
+ if (ret)
+ return ret;
+ k5_mutex_lock(&lock);
+ fprintf(au_fd,"%s\n", jout);
+ fflush(au_fd);
+ k5_mutex_unlock(&lock);
+ free(jout);
+ return ret;
+}
+
+/* Log S4U2SELF event. Returns 0 on success. */
+static krb5_error_code
+j_tgs_s4u2self(krb5_audit_moddata auctx, krb5_boolean ev_success,
+ krb5_audit_state *state)
+{
+ krb5_error_code ret = 0;
+ char *jout = NULL;
+
+ ret = kau_j_tgs_s4u2self(ev_success, state, &jout);
+ if (ret)
+ return ret;
+ k5_mutex_lock(&lock);
+ fprintf(au_fd,"%s\n", jout);
+ fflush(au_fd);
+ k5_mutex_unlock(&lock);
+ free(jout);
+ return ret;
+}
+
+/* Log S4U2PROXY event. Returns 0 on success. */
+static krb5_error_code
+j_tgs_s4u2proxy(krb5_audit_moddata auctx, krb5_boolean ev_success,
+ krb5_audit_state *state)
+{
+ krb5_error_code ret = 0;
+ char *jout = NULL;
+
+ ret = kau_j_tgs_s4u2proxy(ev_success, state, &jout);
+ if (ret)
+ return ret;
+ k5_mutex_lock(&lock);
+ fprintf(au_fd,"%s\n", jout);
+ fflush(au_fd);
+ k5_mutex_unlock(&lock);
+ free(jout);
+ return ret;
+}
+
+/* Log user-to-user event. Returns 0 on success. */
+static krb5_error_code
+j_tgs_u2u(krb5_audit_moddata auctx, krb5_boolean ev_success,
+ krb5_audit_state *state)
+{
+ krb5_error_code ret = 0;
+ char *jout = NULL;
+
+ ret = kau_j_tgs_u2u(ev_success, state, &jout);
+ if (ret)
+ return ret;
+ k5_mutex_lock(&lock);
+ fprintf(au_fd,"%s\n", jout);
+ fflush(au_fd);
+ k5_mutex_unlock(&lock);
+ free(jout);
+ return ret;
+}
+
+krb5_error_code
+audit_test_initvt(krb5_context context, int maj_ver, int min_ver,
+ krb5_plugin_vtable vtable)
+{
+ krb5_audit_vtable vt;
+
+ if (maj_ver != 1)
+ return KRB5_PLUGIN_VER_NOTSUPP;
+
+ vt = (krb5_audit_vtable)vtable;
+ vt->name = "test";
+
+ vt->open = open_au;
+ vt->close = close_au;
+ vt->kdc_start = j_kdc_start;
+ vt->kdc_stop = j_kdc_stop;
+ vt->as_req = j_as_req;
+ vt->tgs_req = j_tgs_req;
+ vt->tgs_s4u2self = j_tgs_s4u2self;
+ vt->tgs_s4u2proxy = j_tgs_s4u2proxy;
+ vt->tgs_u2u = j_tgs_u2u;
+
+ return 0;
+}