Initial Trust Path Query client code, incomplete, not added to build system.
authorMargaret Wasserman <mrw@painless-security.com>
Fri, 30 Nov 2012 17:27:17 +0000 (12:27 -0500)
committerMargaret Wasserman <mrw@painless-security.com>
Fri, 30 Nov 2012 17:27:17 +0000 (12:27 -0500)
include/tpq.h
tpq/example_tpqc/tpqc_main.c [new file with mode: 0644]
tpq/tpqc.c [new file with mode: 0644]

index 16c4a4b..7748ae3 100644 (file)
 
 #define TRUST_PATH_QUERY_PORT  12309
 
+typedef void (*TPQC_RESP_FUNC)(TPQC_INSTANCE *, TPQC_REQ *, TPQC_RESP *, void *);
+
+struct tpqc_req_t {
+  struct tpqc_req_t next_req;
+  char realm[1024];
+  char coi[1024];
+  int conn;
+  TPQC_RESP_FUNC *func
+};
+
+typedef struct tpqc_req_t TPQC_REQ;
+
+struct tpqc_instance_t {
+  TPQC_REQ *req_list
+};
+
+typedef void TPQC_RESP;
+
+typedef struct tpqc_instance_t TPQC_INSTANCE;
+
+TPQC_INSTANCE *tpqc_create (void);
+void tpqc_release (TPQC_INSTANCE *tpqc);
+int tpqc_open_connection (TPQC_INSTANCE *tpqc, char *server);
+TPQC_REQ *tpqc_send_request (TPQC_INSTANCE *tpqc, int conn, char *realm, char *coi, TPQC_RESP_FUNC *resp_handler);
+
 typedef void TPQS_INSTANCE;
 
 TPQS_INSTANCE *tpqs_init ();
 int tpqs_start (TPQS_INSTANCE *tpqs);
 
+
 #endif
diff --git a/tpq/example_tpqc/tpqc_main.c b/tpq/example_tpqc/tpqc_main.c
new file mode 100644 (file)
index 0000000..ec52202
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2012, 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.
+ *
+ */
+
+#include <stdio,h>
+#include <tpq.h>
+
+static int tpqc_response_received = 0;
+
+void tpqc_print_usage (char *name)
+{
+  printf("Usage: %s <server> <realm> <coi>\n", name);
+}
+
+void tpqc_resp_handler (TPQC_INSTANCE * tpqc, 
+                       TPQC_REQ *treq, 
+                       TPQC_RESP *tresp, 
+                       void *cookie) 
+{
+  printf ("Response received!");
+  tpqc_response_received = 1;
+}
+
+int main (int argc, 
+         const char *argv[]) 
+{
+  TPQC_INSTANCE *tpqc;
+  TPQC_REQ *treq;
+  char *server = NULL;
+  char *realm = NULL;
+  char *coi = NULL;
+  void *cookie = NULL;
+  int conn = 0;
+
+  /* Parse command-line arguments */ 
+  if (argc != 4)
+    tpqc_print_usage(argv[0]);
+
+  /* TBD -- validity checking, dealing with quotes, etc. */
+  server = argv[1];
+  realm = argv[2];
+  coi = argv[3];
+
+  /* Create a TPQ client instance */
+  tpqc = tpqc_create();
+
+  /* Set-up TPQ connection */
+  if (0 == (conn = tpqc_open_connection(tpqc, server))) {
+    /* Handle error */
+  };
+
+  /* Build and send a TPQ request */
+  if (NULL == (treq = tpqc_build_request(tpqc, conn, realm, coi))) {
+    /* Handle error */
+  }
+
+  if (tpqc_send_request(tpqc, tpqc_resp_handler)) {
+    /* Handle error */
+  }
+    
+  /* Wait for any response */
+  while (!tpqc_response_received);
+
+  /* Clean-up the TPQ client instance */
+  tpqc_release(tpqc);
+
+  return 0;
+}
+
diff --git a/tpq/tpqc.c b/tpq/tpqc.c
new file mode 100644 (file)
index 0000000..8fbdacd
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2012, 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.
+ *
+ */
+
+#include <gsscon.h>
+#include <tpq.h>
+
+TPQC_INSTANCE *tpqc_create ()
+{
+  TPQC_INSTANCE *tpqc = NULL;
+
+  if (tpqc = malloc(sizeof(TPQC_INSTANCE)))
+    memset(tpqc, 0, sizeof(TPQC_INSTANCE));
+
+  return tpqc;
+}
+
+void tpqc_destroy (TPQC_INSTANCE *tpqc)
+{
+  if (tpqc)
+    free(tpqc);
+}
+
+int tpqc_open_connection (TPQC_INSTANCE *tpqc, char *server)
+{
+
+}
+
+int tpqc_send_request (TPQC_INSTANCE *tpqc, 
+                      int conn, 
+                      char *realm, 
+                      char *coi,
+                      TPQC_RESP_FUNC *resp_handler)
+
+{
+
+}
+
+