From b387b630c6c844f6d23cc14908444adb48ebabfe Mon Sep 17 00:00:00 2001 From: Margaret Wasserman Date: Mon, 1 Apr 2013 08:29:52 -0400 Subject: [PATCH] Added keyname to server block in request/response. --- common/tr_msg.c | 9 +++++++-- include/trust_router/tid.h | 1 + tid/example/tids_main.c | 13 ++++++++++++- tid/tids.c | 5 +++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/common/tr_msg.c b/common/tr_msg.c index 914868d..2a149a6 100644 --- a/common/tr_msg.c +++ b/common/tr_msg.c @@ -172,11 +172,13 @@ static json_t *tr_msg_encode_one_server(TID_SRVR_BLK *srvr) jsrvr = json_object(); - /* Server IP Address -- TBD */ - jstr = json_string("127.0.0.1"); + /* Server IP Address -- TBD handle IPv6 */ + jstr = json_string(inet_ntoa(srvr->aaa_server_addr)); json_object_set_new(jsrvr, "server_addr", jstr); /* 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)); // fprintf(stderr,"tr_msg_encode_one_server(): jsrvr contains:\n"); @@ -188,6 +190,7 @@ static TID_SRVR_BLK *tr_msg_decode_one_server(json_t *jsrvr) { TID_SRVR_BLK *srvr; json_t *jsrvr_addr = NULL; + json_t *jsrvr_kn = NULL; json_t *jsrvr_dh = NULL; if (jsrvr == NULL) @@ -197,6 +200,7 @@ static TID_SRVR_BLK *tr_msg_decode_one_server(json_t *jsrvr) return NULL; if ((NULL == (jsrvr_addr = json_object_get(jsrvr, "server_addr"))) || + (NULL == (jsrvr_kn = json_object_get(jsrvr, "key_name"))) || (NULL == (jsrvr_dh = json_object_get(jsrvr, "server_dh")))) { fprintf (stderr, "tr_msg_decode_one_server(): Error parsing required fields.\n"); free(srvr); @@ -205,6 +209,7 @@ static TID_SRVR_BLK *tr_msg_decode_one_server(json_t *jsrvr) /* TBD -- handle IPv6 Addresses */ inet_aton(json_string_value(jsrvr_addr), &(srvr->aaa_server_addr)); + srvr->key_name = tr_new_name((char *)json_string_value(jsrvr_kn)); srvr->aaa_server_dh = tr_msg_decode_dh(jsrvr_dh); return srvr; diff --git a/include/trust_router/tid.h b/include/trust_router/tid.h index 0273268..0001bd1 100644 --- a/include/trust_router/tid.h +++ b/include/trust_router/tid.h @@ -55,6 +55,7 @@ typedef enum tid_rc { typedef struct tid_srvr_blk { struct tid_srvr_blk *next; struct in_addr aaa_server_addr; + TR_NAME *key_name; DH *aaa_server_dh; /* AAA server's public dh information */ } TID_SRVR_BLK; diff --git a/tid/example/tids_main.c b/tid/example/tids_main.c index be2ab09..5a525d9 100644 --- a/tid/example/tids_main.c +++ b/tid/example/tids_main.c @@ -84,6 +84,17 @@ static int tids_req_handler (TIDS_INSTANCE * tids, return -1; } + /* Hard-code the IP Address in the response. If this were a AAA server, we'd expect + * this to be set by the Trust Router before calling us. + */ + if (0 == inet_aton("127.0.0.1", &((*resp)->servers->aaa_server_addr))) { + printf("tids_req_handler(): inet_aton() failed.\n"); + return -1; + } + + /* Set the key name */ + (*resp)->servers->key_name = tr_new_name("placeholder.key.name"); + /* Generate the server key */ printf("Generating the server key.\n"); if (NULL == (s_keybuf = malloc(DH_size((*resp)->servers->aaa_server_dh)))) { @@ -120,7 +131,7 @@ int main (int argc, /* Create a TID server instance */ if (NULL == (tids = tids_create())) { - printf("Error in tids_create(). Exiting.\n"); + printf("Unable to create TIDS instance,exiting.\n"); return 1; } diff --git a/tid/tids.c b/tid/tids.c index 1eafe6f..842c983 100644 --- a/tid/tids.c +++ b/tid/tids.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -189,7 +190,7 @@ static void tids_handle_connection (TIDS_INSTANCE *tids, int conn) gss_ctx_id_t gssctx = GSS_C_NO_CONTEXT; if (!tids_auth_connection(conn, &gssctx)) { - fprintf(stderr, "Error authorizing TID Server connection, rc = %d.\n", rc); + fprintf(stderr, "Error authorizing TID Server connection.\n"); close(conn); return; } @@ -239,7 +240,7 @@ static void tids_handle_connection (TIDS_INSTANCE *tids, int conn) TIDS_INSTANCE *tids_create (void) { - TIDS_INSTANCE *tids = 0; + TIDS_INSTANCE *tids = NULL; if (tids = malloc(sizeof(TIDS_INSTANCE))) memset(tids, 0, sizeof(TIDS_INSTANCE)); return tids; -- 2.1.4