Configuration of key expiration for APC
authorSam Hartman <hartmans@debian.org>
Tue, 10 Mar 2015 00:34:57 +0000 (20:34 -0400)
committerSam Hartman <hartmans@debian.org>
Tue, 10 Mar 2015 00:34:57 +0000 (20:34 -0400)
Add support for configuring the key expiration in the config and pass this allong as requests are forwarded.

common/tr_config.c
include/tr_comm.h
tr/tr_main.c

index ccc8a9d..e221363 100644 (file)
@@ -689,13 +689,12 @@ static TR_COMM *tr_cfg_parse_one_comm (TR_CFG *trc, json_t *jcomm, TR_CFG_RC *rc
     return NULL;
   }
 
-  if (NULL == (comm = talloc(trc, TR_COMM))) {
+  if (NULL == (comm = talloc_zero(trc, TR_COMM))) {
     fprintf(stderr, "tr_cfg_parse_one_comm: Out of memory.\n");
     *rc = TR_CFG_NOMEM;
     return NULL;
   }
 
-  memset(comm, 0, sizeof(TR_COMM));
 
   if ((NULL == (jid = json_object_get(jcomm, "community_id"))) ||
       (!json_is_string(jid)) ||
@@ -745,10 +744,25 @@ static TR_COMM *tr_cfg_parse_one_comm (TR_CFG *trc, json_t *jcomm, TR_CFG_RC *rc
   if (TR_CFG_SUCCESS != *rc) {
     fprintf(stderr, "tr_cfg_parse_comm: Can't parse RP realms for comm %s .\n", comm->id->buf);
     tr_free_name(comm->id);
-    /* TBD -- free idps? */;
     return NULL;
   }
 
+  if (TR_COMM_APC == comm->type) {
+    json_t *jexpire  = json_object_get(jcomm, "expiration_interval");
+    comm->expiration_interval = 43200; /*30 days*/
+    if (jexpire) {
+       if (!json_is_integer(jexpire)) {
+         fprintf(stderr, "tr_parse_comm: expirae_interval is not an integer\n");
+         return NULL;
+       }
+       comm->expiration_interval = json_integer_value(jexpire);
+       if (comm->expiration_interval <= 10)
+         comm->expiration_interval = 11; /* Freeradius waits 10 minutes between successful TR queries*/
+       if (comm->expiration_interval > 129600) /* 90 days*/
+       comm->expiration_interval = 129600;
+    }
+  }
+  
   return comm;
 }
 
index 717aafd..374227b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2015, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -52,6 +52,7 @@ typedef struct tr_comm {
   TR_APC *apcs;
   TR_IDP_REALM *idp_realms;
   TR_RP_REALM *rp_realms;
+  time_t expiration_interval; /*Minutes to key expiration; only valid for an APC*/
 } TR_COMM;
 
 TR_COMM *tr_comm_lookup(TR_INSTANCE *tr, TR_NAME *comm);
index d160231..241b496 100644 (file)
@@ -184,6 +184,9 @@ static int tr_tids_req_handler (TIDS_INSTANCE *tids,
   /* send a TID request to the AAA server(s), and get the answer(s) */
   /* TBD -- Handle multiple servers */
 
+  if (cfg_apc)
+    fwd_req->expiration_interval = cfg_apc->expiration_interval;
+  else fwd_req->expiration_interval = cfg_comm->expiration_interval;
   /* Create a TID client instance */
   if (NULL == (tidc = tidc_create())) {
     fprintf(stderr, "tr_tids_req_hander: Unable to allocate TIDC instance.\n");