Move DH parameter generation outside of TIDC Instance creation.
authorMargaret Wasserman <margaret@moonshot-proxy.(none)>
Mon, 15 Apr 2013 13:21:50 +0000 (09:21 -0400)
committerMargaret Wasserman <margaret@moonshot-proxy.(none)>
Mon, 15 Apr 2013 13:21:50 +0000 (09:21 -0400)
include/trust_router/tid.h
tid/example/tidc_main.c
tid/tidc.c
tr/tr_main.c

index 819a111..428eaca 100644 (file)
@@ -91,9 +91,9 @@ struct tid_req {
 struct tidc_instance {
   TID_REQ *req_list;
   // TBD -- Do we still need a separate private key */
-  char *priv_key;
-  int priv_len;
-  DH *priv_dh;                 /* Client's DH struct with priv and pub keys */
+  // char *priv_key;
+  // int priv_len;
+  DH *client_dh;                       /* Client's DH struct with priv and pub keys */
 };
 
 typedef int (TIDS_REQ_FUNC)(TIDS_INSTANCE *, TID_REQ *, TID_RESP **, void *);
index 260108c..480dde5 100644 (file)
@@ -39,8 +39,6 @@
 #include <trust_router/tid.h>
 #include <trust_router/tr_dh.h>
 
-static int tidc_response_received = 0;
-
 void static tidc_print_usage (const char *name)
 {
   printf("Usage: %s <server> <RP-realm> <target-realm> <community>\n", name);
@@ -56,7 +54,6 @@ static void tidc_resp_handler (TIDC_INSTANCE * tidc,
   int i;
 
   printf ("Response received! Realm = %s, Community = %s.\n", resp->realm->buf, resp->comm->buf);
-  tidc_response_received = 1;
 
   /* Generate the client key -- TBD, handle more than one server */
   if (TID_SUCCESS != resp->result) {
@@ -80,7 +77,7 @@ static void tidc_resp_handler (TIDC_INSTANCE * tidc,
   /* Print out the client key. */
   printf("Client Key Generated (len = %d):\n", c_keylen);
   for (i = 0; i < c_keylen; i++) {
-    printf("%x", c_keybuf[i]); 
+    printf("%.2x", c_keybuf[i]); 
   }
   printf("\n");
 
@@ -113,8 +110,12 @@ int main (int argc,
 
   printf("TIDC Client:\nServer = %s, rp_realm = %s, target_realm = %s, community = %s\n", server, rp_realm, realm, coi);
  
-  /* Create a TID client instance */
+  /* Create a TID client instance & the client DH */
   tidc = tidc_create();
+  if (NULL == (tidc->client_dh = tr_create_dh_params(NULL, 0))) {
+    printf("Error creating client DH params.\n");
+    return 1;
+  }
 
   /* Set-up TID connection */
   if (-1 == (conn = tidc_open_connection(tidc, server, &gssctx))) {
@@ -131,9 +132,6 @@ int main (int argc,
     return 1;
   }
     
-  /* Wait for a response */
-  while (!tidc_response_received);
-
   /* Clean-up the TID client instance, and exit */
   tidc_destroy(tidc);
 
index 345c1b3..764990f 100644 (file)
 #include <tr_msg.h>
 #include <gsscon.h>
 
-/* char tmp_key[32] = 
-  {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
-   0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
-   0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
-   0x19, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
-*/
-
 int tmp_len = 32;
 
 TIDC_INSTANCE *tidc_create ()
@@ -60,16 +53,6 @@ TIDC_INSTANCE *tidc_create ()
   else
     return NULL;
 
- // TBD -- Add a flag, so we don't do this for the trust router */
-  if (NULL == (tidc->priv_dh = tr_create_dh_params(NULL, 0))) {
-    free (tidc);
-    return NULL;
-  }
-
-  fprintf(stderr, "TIDC DH Parameters:\n");
-  DHparams_print_fp(stdout, tidc->priv_dh);
-  fprintf(stderr, "\n");
-
   return tidc;
 }
 
@@ -134,8 +117,8 @@ int tidc_send_request (TIDC_INSTANCE *tidc,
   tid_req->realm = tr_new_name(realm);
   tid_req->comm = tr_new_name(comm);
 
-  tid_req->tidc_dh = tidc->priv_dh;
-  
+  tid_req->tidc_dh = tidc->client_dh;
+
   tid_req->resp_func = resp_handler;
   tid_req->cookie = cookie;
 
index 8d49f90..ce1cc49 100644 (file)
@@ -92,6 +92,9 @@ static int tr_tids_req_handler (TIDS_INSTANCE * tids,
     return -1;
   }
 
+  /* Use the DH parameters from the original request */
+  tidc->client_dh = req->tidc_dh;
+
   /* Set-up TID connection */
   /* TBD -- version of open_connection that takes an inaddr */
   if (-1 == (conn = tidc_open_connection(tidc, inet_ntoa(aaa_servers->aaa_server_addr), &gssctx))) {
@@ -103,7 +106,7 @@ static int tr_tids_req_handler (TIDS_INSTANCE * tids,
   resp_cookie.tr = tr;
   resp_cookie.orig_req = req;
 
-  /* TBD -- version of send request that takes TR_NAMES */
+  /* TBD -- version of send request that takes TR_NAMES? */
   if (0 > (rc = tidc_send_request(tidc, conn, gssctx, req->rp_realm->buf, req->realm->buf, req->comm->buf, &tr_tidc_resp_handler, (void *)&resp_cookie))) {
     printf("Error in tidc_send_request, rc = %d.\n", rc);
     return -1;
@@ -120,7 +123,7 @@ int main (int argc, const char *argv[])
   TR_CFG_RC rc = TR_CFG_SUCCESS;       /* presume success */
   int err = 0, n = 0;;
 
-  /* parse command-line arguments -- TBD */
+  /* parse command-line arguments? -- TBD */
 
   /* create a Trust Router instance */
   if (NULL == (tr = tr_create())) {
@@ -156,9 +159,9 @@ int main (int argc, const char *argv[])
     exit(1);
   }
 
-  /* start the trust path query server, won't return unless error. */
+  /* start the trust path query server, won't return unless fatal error. */
   if (0 != (err = tids_start(tr->tids, &tr_tids_req_handler, (void *)tr))) {
-    printf ("Error starting Trust Path Query Server, err = %d.\n", err);
+    printf ("Error from Trust Path Query Server, err = %d.\n", err);
     exit(err);
   }