From: Sam Hartman Date: Mon, 9 Mar 2015 11:54:12 +0000 (-0400) Subject: Initial path and expiration utilities X-Git-Tag: 1.5~24 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=trust_router.git;a=commitdiff_plain;h=6d25b3102660eb86fee5709465180a67429b2a79 Initial path and expiration utilities Add path functions to tid_req and tid_resp Add path members and expiration to tid_req and tid_resp Update copyrights --- diff --git a/include/tid_internal.h b/include/tid_internal.h index 0593425..882b3fa 100644 --- a/include/tid_internal.h +++ b/include/tid_internal.h @@ -1,38 +1,5 @@ /* - * 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 @@ -70,10 +37,13 @@ #include #include + struct tid_srvr_blk { struct in_addr aaa_server_addr; TR_NAME *key_name; DH *aaa_server_dh; /* AAA server's public dh information */ + char *expiration_time; /**< absolute time at which key expires*/ + json_t *path;/**< Path of trust routers that the request traversed*/ }; struct tid_resp { @@ -86,8 +56,9 @@ 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; @@ -102,8 +73,11 @@ struct tid_req { 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 */ @@ -111,6 +85,7 @@ struct tidc_instance { // int priv_len; DH *client_dh; /* Client's DH struct with priv and pub keys */ }; + struct tids_instance { int req_count; char *priv_key; @@ -127,4 +102,5 @@ struct tids_instance { 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 diff --git a/include/trust_router/tid.h b/include/trust_router/tid.h index 391faca..4d245b8 100644 --- a/include/trust_router/tid.h +++ b/include/trust_router/tid.h @@ -55,6 +55,7 @@ typedef struct tid_srvr_blk TID_SRVR_BLK; typedef struct _tr_constraint_set TR_CONSTRAINT_SET; +typedef struct _tid_path TID_PATH; typedef struct tid_resp TID_RESP; @@ -114,11 +115,18 @@ TR_EXPORT TR_NAME *tid_resp_get_orig_coi(TID_RESP *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; \ diff --git a/tid/tid_req.c b/tid/tid_req.c index 7bf33dd..159451d 100644 --- a/tid/tid_req.c +++ b/tid/tid_req.c @@ -1,5 +1,5 @@ /* - * 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 @@ -211,6 +211,21 @@ void tid_req_free(TID_REQ *req) 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, diff --git a/tid/tid_resp.c b/tid/tid_resp.c index 14cc213..2611b3b 100644 --- a/tid/tid_resp.c +++ b/tid/tid_resp.c @@ -112,3 +112,36 @@ size_t tid_resp_get_num_servers(const TID_RESP *resp) 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; + +} diff --git a/tid/tidc.c b/tid/tidc.c index 649706c..bd88671 100644 --- a/tid/tidc.c +++ b/tid/tidc.c @@ -1,5 +1,5 @@ /* - * 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