Merge branch 'milestone/monitoring' into jennifer/request_id
authorJennifer Richards <jennifer@painless-security.com>
Thu, 3 May 2018 20:50:54 +0000 (16:50 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Thu, 3 May 2018 20:50:54 +0000 (16:50 -0400)
# Conflicts:
# include/trust_router/tid.h
# tid/tidc.c
# tr/tr_tid.c

1  2 
Makefile.am
common/tr_msg.c
include/tid_internal.h
include/trust_router/tid.h
tid/tid_req.c
tid/tid_resp.c
tid/tidc.c
tid/tids.c
tr/tr_tid.c

diff --cc Makefile.am
@@@ -84,9 -132,19 +134,20 @@@ $(common_srcs
  tr_trpc_LDADD = gsscon/libgsscon.la $(GLIB_LIBS)
  tr_trpc_LDFLAGS = $(AM_LDFLAGS) -pthread
  
+ tr_trmon_SOURCES = tr/trmon_main.c \
+ common/tr_gss.c \
+ common/tr_gss_client.c \
+ $(tid_srcs) \
+ $(trp_srcs) \
+ $(common_srcs) \
+ mon/monc.c
+ tr_trmon_LDADD = gsscon/libgsscon.la  $(GLIB_LIBS)
+ tr_trmon_LDFLAGS = $(AM_LDFLAGS) -pthread
  trp_msgtst_SOURCES = trp/msgtst.c \
  $(common_srcs) \
 +common/tr_rand_id.c \
  trp/trp_req.c \
  trp/trp_upd.c \
  tid/tid_resp.c \
diff --cc common/tr_msg.c
Simple merge
Simple merge
@@@ -94,9 -95,7 +95,9 @@@ void tid_req_set_realm(TID_REQ *req, TR
  TR_EXPORT TR_NAME *tid_req_get_comm(TID_REQ *req);
  void tid_req_set_comm(TID_REQ *req, TR_NAME *comm);
  TR_EXPORT TR_NAME *tid_req_get_orig_coi(TID_REQ *req);
- void tid_req_set_rp_orig_coi(TID_REQ *req, TR_NAME *orig_coi);
+ void tid_req_set_orig_coi(TID_REQ *req, TR_NAME *orig_coi);
 +TR_EXPORT TR_NAME *tid_req_get_request_id(TID_REQ *req);
 +void tid_req_set_request_id(TID_REQ *req, TR_NAME *request_id);
  TR_EXPORT TIDC_RESP_FUNC *tid_req_get_resp_func(TID_REQ *req);
  void tid_req_set_resp_func(TID_REQ *req, TIDC_RESP_FUNC *resp_func);
  TR_EXPORT void *tid_req_get_cookie(TID_REQ *req);
diff --cc tid/tid_req.c
Simple merge
diff --cc tid/tid_resp.c
Simple merge
diff --cc tid/tidc.c
@@@ -39,9 -40,7 +40,8 @@@
  #include <trust_router/tr_dh.h>
  #include <tid_internal.h>
  #include <tr_msg.h>
- #include <gsscon.h>
  #include <tr_debug.h>
 +#include <tr_rand_id.h>
  
  
  int tmp_len = 32;
@@@ -96,17 -87,31 +88,32 @@@ int tidc_open_connection (TIDC_INSTANC
  }
  
  int tidc_send_request (TIDC_INSTANCE *tidc,
-                      int conn,
-                      gss_ctx_id_t gssctx,
-                      const char *rp_realm,
-                      const char *realm, 
-                      const char *comm,
-                      TIDC_RESP_FUNC *resp_handler,
-                      void *cookie)
+                        int conn,
+                        gss_ctx_id_t gssctx,
+                        const char *rp_realm,
+                        const char *realm,
+                        const char *comm,
+                        TIDC_RESP_FUNC *resp_handler,
+                        void *cookie)
  {
    TID_REQ *tid_req = NULL;
 +  char *request_id = NULL;
    int rc;
+   int orig_conn = 0;
+   gss_ctx_id_t *orig_gss_ctx = NULL;
+   /* For ABI compatibility, replace the generic GSS client parameters
+    * with the arguments we were passed. */
+   orig_conn = tidc->gssc->conn; /* save to restore later */
+   if (conn != tidc->gssc->conn) {
+     tr_warning("tidc_send_request: WARNING: socket connection FD does not match FD opened by tidc_open_connection()");
+     tidc->gssc->conn = conn;
+   }
+   orig_gss_ctx = tidc->gssc->gss_ctx; /* save to restore later */
+   if (gssctx != *(tidc->gssc->gss_ctx)) {
+     tr_warning("tidc_send_request: WARNING: sending request with different GSS context than used for tidc_open_connection()");
+     *tidc->gssc->gss_ctx = gssctx;
+   }
  
    /* Create and populate a TID req structure */
    if (!(tid_req = tid_req_new()))
      goto error;
    }
  
-   tid_req->tidc_dh = tr_dh_dup(tidc->client_dh);
+   tid_req->tidc_dh = tr_dh_dup(tidc->gssc->client_dh);
  
 +  /* generate an ID */
 +  request_id = tr_random_id(NULL);
 +  if (request_id) {
 +    if (tid_req->request_id = tr_new_name(request_id))
 +      tr_debug("tidc_send_request: Created TID request ID: %s", request_id);
 +    else
 +      tr_debug("tidc_send_request: Unable to set request ID, proceeding without one");
 +    talloc_free(request_id);
 +  } else
 +    tr_debug("tidc_send_request: Failed to generate a TID request ID, proceeding without one");
 +
    rc = tidc_fwd_request(tidc, tid_req, resp_handler, cookie);
    goto cleanup;
   error:
@@@ -149,13 -147,9 +160,10 @@@ int tidc_fwd_request(TIDC_INSTANCE *tid
                       TIDC_RESP_FUNC *resp_handler,
                       void *cookie)
  {
-   char *req_buf = NULL;
-   char *resp_buf = NULL;
-   size_t resp_buflen = 0;
+   TALLOC_CTX *tmp_ctx = talloc_new(NULL);
    TR_MSG *msg = NULL;
    TR_MSG *resp_msg = NULL;
-   int err;
 +  TID_RESP *tid_resp = NULL;
    int rc = 0;
  
    /* Create and populate a TID msg structure */
    msg->msg_type = TID_REQUEST;
    tr_msg_set_req(msg, tid_req);
  
-   /* store the response function and cookie */
-   // tid_req->resp_func = resp_handler;
-   // tid_req->cookie = cookie;
  
-   /* Encode the request into a json string */
-   if (!(req_buf = tr_msg_encode(msg))) {
-     tr_err("tidc_fwd_request: Error encoding TID request.\n");
-     goto error;
-   }
-   tr_debug( "tidc_fwd_request: Sending TID request:\n");
-   tr_debug( "%s\n", req_buf);
+   tr_debug( "tidc_fwd_request: Sending TID request\n");
  
    /* Send the request over the connection */
-   if (err = gsscon_write_encrypted_token (tid_req->conn, tid_req->gssctx, req_buf,
-                                         strlen(req_buf))) {
-     tr_err( "tidc_fwd_request: Error sending request over connection.\n");
+   resp_msg = tr_gssc_exchange_msgs(tmp_ctx, tidc->gssc, msg);
+   if (resp_msg == NULL)
      goto error;
-   }
-   /* TBD -- queue request on instance, read resps in separate thread */
-   /* Read the response from the connection */
-   /* TBD -- timeout? */
-   if (err = gsscon_read_encrypted_token(tid_req->conn, tid_req->gssctx, &resp_buf, &resp_buflen)) {
-     if (resp_buf)
-       free(resp_buf);
-     goto error;
-   }
-   tr_debug( "tidc_fwd_request: Response Received (%u bytes).\n", (unsigned) resp_buflen);
-   tr_debug( "%s\n", resp_buf);
-   if (NULL == (resp_msg = tr_msg_decode(resp_buf, resp_buflen))) {
-     tr_err( "tidc_fwd_request: Error decoding response.\n");
-     goto error;
-   }
  
    /* TBD -- Check if this is actually a valid response */
 -  if (TID_RESPONSE != tr_msg_get_msg_type(resp_msg)) {
 +  tid_resp = tr_msg_get_resp(resp_msg);
 +  if (tid_resp == NULL) {
      tr_err( "tidc_fwd_request: Error, no response in the response!\n");
      goto error;
    }
diff --cc tid/tids.c
Simple merge
diff --cc tr/tr_tid.c
@@@ -273,14 -344,8 +344,14 @@@ static int tr_tids_req_handler(TIDS_INS
      goto cleanup;
    }
  
-   tr_debug("tr_tids_req_handler: Request received (conn = %d)! Realm = %s, Comm = %s", orig_req->conn,
+   tr_debug("tr_tids_req_handler: Request received (conn = %d)! Realm = %s, Comm = %s", orig_req->conn, 
             orig_req->realm->buf, orig_req->comm->buf);
 +  if (orig_req->request_id)
 +    tr_debug("tr_tids_req_handler: TID request ID: %.*s", orig_req->request_id->len, orig_req->request_id->buf);
 +  else
 +    tr_debug("tr_tids_req_handler: TID request ID: none");
 +
 +  tids->req_count++;
  
    /* Duplicate the request, so we can modify and forward it */
    if (NULL == (fwd_req=tid_dup_req(orig_req))) {