DISTCHECK_CONFIGURE_FLAGS = \
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
bin_PROGRAMS= tr/trust_router tid/example/tidc tid/example/tids common/dh_test/tr_dh_test
-AM_CPPFLAGS=-I$(srcdir)/include
-AM_CFLAGS = -Wall -Werror=missing-prototypes -Werror -Wno-parentheses
+AM_CPPFLAGS=-I$(srcdir)/include $(GLIB_CFLAGS)
+AM_CFLAGS = -Wall -Werror=missing-prototypes -Werror -Wno-parentheses $(GLIB_CFLAGS)
SUBDIRS = gsscon
common_srcs = common/tr_name.c \
common/tr_constraint.c \
common/tr_rp.c \
tr/tr.c
-tr_trust_router_LDADD = gsscon/libgsscon.la libtr_tid.la
+tr_trust_router_LDADD = gsscon/libgsscon.la libtr_tid.la $(GLIB_LIBS)
tid_example_tidc_SOURCES = tid/example/tidc_main.c
-tid_example_tidc_LDADD = gsscon/libgsscon.la libtr_tid.la
+tid_example_tidc_LDADD = gsscon/libgsscon.la libtr_tid.la $(GLIB_LIBS)
tid_example_tids_SOURCES = tid/example/tids_main.c
$(common_srcs)
libtr_tid_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden
-libtr_tid_la_LIBADD = gsscon/libgsscon.la
+libtr_tid_la_LIBADD = gsscon/libgsscon.la $(GLIB_LIBS)
libtr_tid_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2 -no-undefined
pkginclude_HEADERS = include/trust_router/tid.h include/trust_router/tr_name.h \
return NULL;
}
- if (NULL == (comm = talloc(trc, TR_COMM))) {
- tr_debug("tr_cfg_parse_one_comm: Out of memory.");
+ if (NULL == (comm = talloc_zero(trc, TR_COMM))) {
+ tr_crit("tr_cfg_parse_one_comm: Out of memory.");
*rc = TR_CFG_NOMEM;
return NULL;
}
- memset(comm, 0, sizeof(TR_COMM));
if ((NULL == (jid = json_object_get(jcomm, "community_id"))) ||
(!json_is_string(jid)) ||
if (TR_CFG_SUCCESS != *rc) {
tr_debug("tr_cfg_parse_comm: Can't parse RP realms for comm %s .", comm->id->buf);
tr_free_name(comm->id);
- /* TBD -- free idps? */;
return NULL;
}
+ if (TR_COMM_APC == comm->type) {
+ json_t *jexpire = json_object_get(jcomm, "expiration_interval");
+ comm->expiration_interval = 43200; /*30 days*/
+ if (jexpire) {
+ if (!json_is_integer(jexpire)) {
+ fprintf(stderr, "tr_parse_comm: expirae_interval is not an integer\n");
+ return NULL;
+ }
+ comm->expiration_interval = json_integer_value(jexpire);
+ if (comm->expiration_interval <= 10)
+ comm->expiration_interval = 11; /* Freeradius waits 10 minutes between successful TR queries*/
+ if (comm->expiration_interval > 129600) /* 90 days*/
+ comm->expiration_interval = 129600;
+ }
+ }
+
return comm;
}
{
json_t *jsrvr = NULL;
json_t *jstr = NULL;
+ gchar *time_str = g_time_val_to_iso8601(&srvr->key_expiration);
tr_debug("Encoding one server.");
jstr = json_string(inet_ntoa(srvr->aaa_server_addr));
json_object_set_new(jsrvr, "server_addr", jstr);
+ json_object_set_new(jsrvr,
+ "key_expiration", json_string(time_str));
+ g_free(time_str);
/* Server DH Block */
jstr = json_string(srvr->key_name->buf);
json_object_set_new(jsrvr, "key_name", jstr);
json_object_set_new(jsrvr, "server_dh", tr_msg_encode_dh(srvr->aaa_server_dh));
-
- // tr_debug("tr_msg_encode_one_server(): jsrvr contains:");
- // tr_debug("%s", json_dumps(jsrvr, 0));
+ if (srvr->path)
+ /* The path is owned by the srvr, so grab an extra ref*/
+ json_object_set(jsrvr, "path", srvr->path);
return jsrvr;
}
AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
fi
AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
+PKG_CHECK_MODULES([GLIB], [glib-2.0])
AC_CHECK_LIB([gssapi_krb5], [gss_init_sec_context])
AC_CHECK_LIB([com_err], [error_message])
/*
- * Copyright (c) 2012-2014, JANET(UK)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. 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.
- *
- * 3. Neither the name of JANET(UK) nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * 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.
- *
- */
-/*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012-2015, JANET(UK)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#ifndef TID_INTERNAL_H
#define TID_INTERNAL_H
+#include <glib.h>
#include <trust_router/tid.h>
#include <jansson.h>
+
struct tid_srvr_blk {
struct in_addr aaa_server_addr;
TR_NAME *key_name;
DH *aaa_server_dh; /* AAA server's public dh information */
+ GTimeVal key_expiration; /**< absolute time at which key expires*/
+ json_t *path;/**< Path of trust routers that the request traversed*/
};
struct tid_resp {
TR_NAME *orig_coi;
TID_SRVR_BLK *servers; /* array of servers */
size_t num_servers;
- /* TBD -- Trust Path Used */
+ json_t *error_path; /**< Path that a request generating an error traveled*/
};
+
struct tid_req {
struct tid_req *next_req;
int resp_sent;
DH *tidc_dh; /* Client's public dh information */
TIDC_RESP_FUNC *resp_func;
void *cookie;
- json_t *json_references; /** References to objects dereferenced on request destruction*/
+ time_t expiration_interval; /**< Time to key expire in minutes*/
+ json_t *json_references; /**< References to objects dereferenced on request destruction*/
+ json_t *path; /**< Path of systems this request has traversed; added by receiver*/
};
+
struct tidc_instance {
TID_REQ *req_list;
// TBD -- Do we still need a separate private key */
// int priv_len;
DH *client_dh; /* Client's DH struct with priv and pub keys */
};
+
struct tids_instance {
int req_count;
char *priv_key;
reference they already hold to the TID_REQ.*/
void tid_req_cleanup_json(TID_REQ *, json_t *json);
+int tid_req_add_path(TID_REQ *, const char *this_system, unsigned port);
#endif
/*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2015, JANET(UK)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
TR_APC *apcs;
TR_IDP_REALM *idp_realms;
TR_RP_REALM *rp_realms;
+ time_t expiration_interval; /*Minutes to key expiration; only valid for an APC*/
} TR_COMM;
TR_COMM *tr_comm_lookup(TR_INSTANCE *tr, TR_NAME *comm);
typedef struct _tr_constraint_set TR_CONSTRAINT_SET;
+typedef struct _tid_path TID_PATH;
typedef struct tid_resp TID_RESP;
void tid_resp_set_orig_coi(TID_RESP *resp, TR_NAME *orig_coi);
TR_EXPORT TID_SRVR_BLK *tid_resp_get_server(TID_RESP *resp, size_t index);
TR_EXPORT size_t tid_resp_get_num_servers(const TID_RESP *resp);
+TR_EXPORT const TID_PATH *tid_resp_get_error_path(const TID_RESP *);
+
+/** Get either the error_path or the path of the first server block for
+ * a successful response*/
+TR_EXPORT const TID_PATH *tid_resp_get_a_path(const TID_RESP *);
/* Server blocks*/
TR_EXPORT void tid_srvr_get_address(const TID_SRVR_BLK *,
const struct sockaddr **out_addr, size_t *out_sa_len);
TR_EXPORT DH *tid_srvr_get_dh(TID_SRVR_BLK *);
TR_EXPORT const TR_NAME *tid_srvr_get_key_name(const TID_SRVR_BLK *);
+TR_EXPORT const TID_PATH *tid_srvr_get_path(const TID_SRVR_BLK *);
+
#define tid_resp_servers_foreach(RESP, SERVER, INDEX) \
for (INDEX=0,SERVER=NULL; \
/*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2014-2015, JANET(UK)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
static int destroy_tid_req(TID_REQ *req)
{
+ OM_uint32 minor;
if (req->json_references)
json_decref(req->json_references);
+ if (req->gssctx)
+ gss_delete_sec_context( &minor, &req->gssctx, NULL);
return 0;
}
talloc_free(req);
}
+int tid_req_add_path(TID_REQ *req,
+ const char *this_system, unsigned port)
+{
+ char *path_element = talloc_asprintf(req, "%s:%u",
+ this_system, port);
+ if (!req->path) {
+ req->path = json_array();
+ if (!req->path)
+ return -1;
+ tid_req_cleanup_json(req, req->path);
+ }
+ return json_array_append( req->path, json_string(path_element));
+}
+
+
void tid_srvr_get_address(const TID_SRVR_BLK *blk,
const struct sockaddr **out_addr,
return resp->num_servers;
}
+
+const TID_PATH *tid_srvr_get_path( const TID_SRVR_BLK *block)
+{
+ if (!block)
+ return NULL;
+ return (const TID_PATH *) block->path;
+}
+
+const TID_PATH *tid_resp_get_error_path( const TID_RESP *resp)
+{
+ if (!resp)
+ return NULL;
+ return (const TID_PATH *) resp->error_path;
+}
+
+const TID_PATH *tid_resp_get_a_path( const TID_RESP *const_resp)
+{
+ size_t index;
+ TID_SRVR_BLK *server;
+ TID_RESP *resp = (TID_RESP *) const_resp;
+ if (!resp)
+ return NULL;
+
+
+ if (resp->error_path)
+ return (const TID_PATH *) resp->error_path;
+ tid_resp_servers_foreach( resp, server, index) {
+ if (server->path)
+ return (const TID_PATH *) server->path;
+ }
+ return NULL;
+
+}
/*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2014-2015, JANET(UK)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
/*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2015, JANET(UK)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
static int tr_tids_req_handler (TIDS_INSTANCE *tids,
TID_REQ *orig_req,
TID_RESP *resp,
- void *tr)
+ void *tr_in)
{
TIDC_INSTANCE *tidc = NULL;
TR_RESP_COOKIE resp_cookie;
TID_REQ *fwd_req = NULL;
TR_COMM *cfg_comm = NULL;
TR_COMM *cfg_apc = NULL;
+ TR_INSTANCE *tr = (TR_INSTANCE *) tr_in;
int oaction = TR_FILTER_ACTION_REJECT;
int rc = 0;
return -1;
}
- if (NULL == (cfg_comm = tr_comm_lookup((TR_INSTANCE *)tids->cookie, orig_req->comm))) {
+ if (NULL == (cfg_comm = tr_comm_lookup(tids->cookie, orig_req->comm))) {
tr_notice("tr_tids_req_hander: Request for unknown comm: %s.", orig_req->comm->buf);
tids_send_err_response(tids, orig_req, "Unknown community");
return -1;
/* Check that the rp_realm matches the filter for the GSS name that
* was received. */
- if ((!((TR_INSTANCE *)tr)->rp_gss) ||
- (!((TR_INSTANCE *)tr)->rp_gss->filter)) {
+ if ((!(tr)->rp_gss) ||
+ (!(tr)->rp_gss->filter)) {
tr_notice("tr_tids_req_handler: No GSS name for incoming request.");
tids_send_err_response(tids, orig_req, "No GSS name for request");
return -1;
}
- if ((TR_FILTER_NO_MATCH == tr_filter_process_rp_permitted(orig_req->rp_realm, ((TR_INSTANCE *)tr)->rp_gss->filter, orig_req->cons, &fwd_req->cons, &oaction)) ||
+ if ((TR_FILTER_NO_MATCH == tr_filter_process_rp_permitted(orig_req->rp_realm, (tr)->rp_gss->filter, orig_req->cons, &fwd_req->cons, &oaction)) ||
(TR_FILTER_ACTION_REJECT == oaction)) {
tr_notice("tr_tids_req_handler: RP realm (%s) does not match RP Realm filter for GSS name", orig_req->rp_realm->buf);
tids_send_err_response(tids, orig_req, "RP Realm filter error");
apc = tr_dup_name(cfg_comm->apcs->id);
/* Check that the APC is configured */
- if (NULL == (cfg_apc = tr_comm_lookup((TR_INSTANCE *)tids->cookie, apc))) {
+ if (NULL == (cfg_apc = tr_comm_lookup(tids->cookie, apc))) {
tr_notice("tr_tids_req_hander: Request for unknown comm: %s.", apc->buf);
tids_send_err_response(tids, orig_req, "Unknown APC");
return -1;
/* send a TID request to the AAA server(s), and get the answer(s) */
/* TBD -- Handle multiple servers */
+ if (cfg_apc)
+ fwd_req->expiration_interval = cfg_apc->expiration_interval;
+ else fwd_req->expiration_interval = cfg_comm->expiration_interval;
/* Create a TID client instance */
if (NULL == (tidc = tidc_create())) {
tr_crit("tr_tids_req_hander: Unable to allocate TIDC instance.");
}
static int tr_tids_gss_handler(gss_name_t client_name, TR_NAME *gss_name,
- void *tr)
+ void *tr_in)
{
TR_RP_CLIENT *rp;
+ TR_INSTANCE *tr = (TR_INSTANCE *) tr_in;
if ((!client_name) || (!gss_name) || (!tr)) {
tr_debug("tr_tidc_gss_handler: Bad parameters.");
/* Store the rp client in the TR_INSTANCE structure for now...
* TBD -- fix me for new tasking model. */
- ((TR_INSTANCE *)tr)->rp_gss = rp;
+ (tr)->rp_gss = rp;
tr_debug("Client's GSS Name: %s", gss_name->buf);
+
return 0;
}