Make tid types opaque
authorSam Hartman <hartmans@debian.org>
Tue, 15 Jul 2014 14:07:29 +0000 (10:07 -0400)
committerSam Hartman <hartmans@debian.org>
Tue, 15 Jul 2014 14:07:29 +0000 (10:07 -0400)
15 files changed:
Makefile.am
common/t_constraint.c
common/tr_constraint.c
common/tr_dh.c
common/tr_msg.c
include/tid_internal.h [new file with mode: 0644]
include/tr.h
include/trust_router/tid.h
tid/example/tidc_main.c
tid/example/tids_main.c
tid/tid_req.c
tid/tid_resp.c
tid/tidc.c
tid/tids.c
tr/tr_main.c

index 3e18e37..7f9f9cf 100644 (file)
@@ -55,7 +55,8 @@ noinst_HEADERS = include/gsscon.h include/tr_config.h \
        include/tr_msg.h include/tr.h \
        include/tr_idp.h include/tr_rp.h \
        include/tr_comm.h include/tr_apc.h \
-       include/tr_filter.h
+       include/tr_filter.h \
+       include/tid_internal.h
 
 pkgdata_DATA=schema.sql
 systemddir=/lib/systemd/system
index 7f57601..7ba9a14 100644 (file)
@@ -37,7 +37,7 @@
 #include <stdio.h>
 #include <assert.h>
 
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <trust_router/tr_constraint.h>
 #include <tr_debug.h>
 
index c34d6ec..7307bd1 100644 (file)
@@ -40,6 +40,7 @@
 #include <tr_debug.h>
 
 #include <trust_router/tr_constraint.h>
+#include <tid_internal.h>
 
 /* Returns TRUE (1) if the the string (str) matchs the wildcard string (wc_str), FALSE (0) if not.
  */
index 0d11662..f7c6496 100644 (file)
@@ -38,6 +38,7 @@
 #include <openssl/sha.h>
 #include <talloc.h>
 #include <assert.h>
+#include <tid_internal.h>
 
 
 unsigned char tr_2048_dhprime[2048/8] = {
index 99c04a5..28e2920 100644 (file)
@@ -41,7 +41,7 @@
 
 #include <tr_msg.h>
 #include <trust_router/tr_name.h>
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <trust_router/tr_constraint.h>
 #include <tr_debug.h>
 
diff --git a/include/tid_internal.h b/include/tid_internal.h
new file mode 100644 (file)
index 0000000..db8189d
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * 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)
+ * 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.
+ *
+ */
+
+#ifndef TID_INTERNAL_H
+#define TID_INTERNAL_H
+#include <trust_router/tid.h>
+
+#include <jansson.h>
+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;
+
+typedef struct tid_resp {
+  TID_RC result;
+  TR_NAME *err_msg;
+  TR_NAME *rp_realm;
+  TR_NAME *realm;
+  TR_NAME *comm;
+  TR_CONSTRAINT_SET *cons;
+  TR_NAME *orig_coi;
+  TID_SRVR_BLK *servers;               /* Linked list of servers */
+  /* TBD -- Trust Path Used */
+} TID_RESP;
+struct tid_req {
+  struct tid_req *next_req;
+  int resp_sent;
+  int conn;
+  gss_ctx_id_t gssctx;
+  int resp_rcvd;
+  TR_NAME *rp_realm;
+  TR_NAME *realm;
+  TR_NAME *comm;
+  TR_CONSTRAINT_SET *cons;
+  TR_NAME *orig_coi;
+  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*/
+};
+struct tidc_instance {
+  TID_REQ *req_list;
+  // TBD -- Do we still need a separate private key */
+  // char *priv_key;
+  // int priv_len;
+  DH *client_dh;                       /* Client's DH struct with priv and pub keys */
+};
+struct tids_instance {
+  int req_count;
+  char *priv_key;
+  char *ipaddr;
+  const char *hostname;
+  TIDS_REQ_FUNC *req_handler;
+  tids_auth_func *auth_handler;
+  void *cookie;
+};
+
+
+/** Decrement a reference to #json when this tid_req is cleaned up. A
+    new reference is not created; in effect the caller is handing a
+    reference they already hold to the TID_REQ.*/
+void tid_req_cleanup_json(TID_REQ *, json_t *json);
+
+#endif
index dd2b1bf..61adc36 100644 (file)
@@ -35,7 +35,7 @@
 #ifndef TR_H
 #define TR_H
 
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <trust_router/tr_name.h>
 #include <tr_msg.h>
 #include <tr_rp.h>
index a3459ea..bae236b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012-2014, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -42,7 +42,6 @@
 #include <trust_router/tr_versioning.h>
 
 #include <gssapi.h>
-#include <jansson.h>
 
 
 #define TID_PORT       12309
@@ -52,26 +51,12 @@ typedef enum tid_rc {
   TID_ERROR
 } 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;
-  
+typedef struct tid_srvr_blk  TID_SRVR_BLK;
+
+
 typedef struct _tr_constraint_set  TR_CONSTRAINT_SET;
 
-typedef struct tid_resp {
-  TID_RC result;
-  TR_NAME *err_msg;
-  TR_NAME *rp_realm;
-  TR_NAME *realm;
-  TR_NAME *comm;
-  TR_CONSTRAINT_SET *cons;
-  TR_NAME *orig_coi;
-  TID_SRVR_BLK *servers;               /* Linked list of servers */
-  /* TBD -- Trust Path Used */
-} TID_RESP;
+typedef struct tid_resp TID_RESP;
 
 typedef struct tidc_instance TIDC_INSTANCE;
 typedef struct tids_instance TIDS_INSTANCE;
@@ -80,44 +65,12 @@ typedef struct tid_req TID_REQ;
 
 typedef void (TIDC_RESP_FUNC)(TIDC_INSTANCE *, TID_REQ *, TID_RESP *, void *);
 
-struct tid_req {
-  struct tid_req *next_req;
-  int resp_sent;
-  int conn;
-  gss_ctx_id_t gssctx;
-  int resp_rcvd;
-  TR_NAME *rp_realm;
-  TR_NAME *realm;
-  TR_NAME *comm;
-  TR_CONSTRAINT_SET *cons;
-  TR_NAME *orig_coi;
-  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*/
-};
-
-struct tidc_instance {
-  TID_REQ *req_list;
-  // TBD -- Do we still need a separate private key */
-  // 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 *);
 typedef int (tids_auth_func)(gss_name_t client_name, TR_NAME *display_name, void *cookie);
 
 
-struct tids_instance {
-  int req_count;
-  char *priv_key;
-  char *ipaddr;
-  const char *hostname;
-  TIDS_REQ_FUNC *req_handler;
-  tids_auth_func *auth_handler;
-  void *cookie;
-};
 
 /* Utility functions for TID_REQ structures, in tid/tid_req.c */
 TR_EXPORT TID_REQ *tid_req_new(void);
@@ -144,11 +97,6 @@ void tid_req_set_resp_func(TID_REQ *req, TIDC_RESP_FUNC *resp_func);
 TR_EXPORT void *tid_req_get_cookie(TID_REQ *req);
 void tid_req_set_cookie(TID_REQ *req, void *cookie);
 TR_EXPORT TID_REQ *tid_dup_req (TID_REQ *orig_req);
-
-/** Decrement a reference to #json when this tid_req is cleaned up. A
-    new reference is not created; in effect the caller is handing a
-    reference they already hold to the TID_REQ.*/
-void tid_req_cleanup_json(TID_REQ *, json_t *json);
 void TR_EXPORT tid_req_free( TID_REQ *req);
 
 /* Utility functions for TID_RESP structure, in tid/tid_resp.c */
@@ -166,7 +114,15 @@ 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_servers(TID_RESP *resp);
 void tid_resp_set_servers(TID_RESP *resp, TID_SRVR_BLK *servers);
-// TBD -- add function to add/remove items from linked list of servers?
+
+/* Server blocks*/
+TR_EXPORT void tid_srvr_get_address(const TID_SRVR_BLK *,
+const struct sockaddr **out_addr);
+TR_EXPORT DH *tid_srvr_get_dh(TID_SRVR_BLK *);
+TR_EXPORT const TR_NAME *tid_srvr_get_key_name(const TID_SRVR_BLK *);
+
+
+
 
 /* TID Client functions, in tid/tidc.c */
 TR_EXPORT TIDC_INSTANCE *tidc_create (void);
index 751a504..90efd4e 100644 (file)
@@ -36,7 +36,7 @@
 #include <stdio.h>
 
 #include <gsscon.h>
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <trust_router/tr_dh.h>
 
 void static tidc_print_usage (const char *name)
index 79230b7..ef2d070 100644 (file)
@@ -39,7 +39,7 @@
 #include <sqlite3.h>
 
 #include <tr_debug.h>
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <trust_router/tr_constraint.h>
 #include <trust_router/tr_dh.h>
 #include <openssl/rand.h>
index 6f14be9..d8b225c 100644 (file)
@@ -37,7 +37,7 @@
 #include <assert.h>
 #include <talloc.h>
 
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <jansson.h>
 
 static int destroy_tid_req(TID_REQ *req)
@@ -207,3 +207,29 @@ void tid_req_free(TID_REQ *req)
 {
   talloc_free(req);
 }
+
+
+void tid_srvr_get_address(const TID_SRVR_BLK *blk,
+                         const struct sockaddr **out_addr)
+{
+  struct sockaddr_in *sa = NULL;
+    assert(blk);
+    sa = talloc_zero(blk, struct sockaddr_in);
+    sa->sin_family = AF_INET;
+    sa->sin_addr = blk->aaa_server_addr;
+    sa->sin_port = htons(2083);
+    *out_addr = (struct sockaddr *) sa;
+}
+
+DH *tid_srvr_get_dh( TID_SRVR_BLK *blk)
+{
+  assert(blk);
+  return blk->aaa_server_dh;
+}
+
+const TR_NAME *tid_srvr_get_key_name(
+                                   const TID_SRVR_BLK *blk)
+{
+  assert(blk);
+  return blk->key_name;
+}
index 6cfbb87..46ded18 100644 (file)
@@ -35,7 +35,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 
 TR_EXPORT TID_RC tid_resp_get_result(TID_RESP *resp)
 {
index 7f675d3..61eaa91 100644 (file)
@@ -36,7 +36,7 @@
 #include <jansson.h>
 
 #include <trust_router/tr_dh.h>
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <tr_msg.h>
 #include <gsscon.h>
 
index 26e14af..ac236f1 100644 (file)
@@ -42,7 +42,7 @@
 #include <netinet/in.h>
 #include <jansson.h>
 
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <gsscon.h>
 #include <tr_msg.h>
 
index 6830f6d..c39b7dc 100644 (file)
@@ -37,7 +37,7 @@
 
 #include <tr.h>
 #include <tr_filter.h>
-#include <trust_router/tid.h>
+#include <tid_internal.h>
 #include <tr_config.h>
 #include <tr_comm.h>
 #include <tr_idp.h>