Packet Signing & Key Verification Stage: Start
diff --git a/Makefile b/Makefile
index f9d826c..8eaca94 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
PROGRAMS = nlsrc nlsr
INSTALL_PATH=/usr/local/bin/
-NLSR_SRCS=nlsr.c nlsr_ndn.c nlsr_npl.c nlsr_adl.c nlsr_lsdb.c nlsr_route.c nlsr_npt.c nlsr_fib.c nlsr_sync.c nlsr_face.c utility.c
+NLSR_SRCS=nlsr.c nlsr_ndn.c nlsr_npl.c nlsr_adl.c nlsr_lsdb.c nlsr_route.c nlsr_npt.c nlsr_fib.c nlsr_sync.c nlsr_face.c nlsr_km.c nlsr_km_util.c utility.c
NLSRC_SRCS=nlsrc.c
all: $(PROGRAMS)
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index 64caae8..e4b1378 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -23,27 +23,10 @@
#include "nlsr_adl.h"
#include "nlsr_lsdb.h"
#include "utility.h"
+#include "nlsr_km.h"
+#include "nlsr_km_util.h"
-/**
-* add lifetime in second to a interest template
-*/
-int
-appendLifetime(struct ccn_charbuf *cb, int lifetime)
-{
- unsigned char buf[sizeof(int32_t)];
- int32_t dreck = lifetime << 12;
- int pos = sizeof(int32_t);
- int res = 0;
- while (dreck > 0 && pos > 0)
- {
- pos--;
- buf[pos] = dreck & 255;
- dreck = dreck >> 8;
- }
- res |= ccnb_append_tagged_blob(cb, CCN_DTAG_InterestLifetime, buf+pos,
- sizeof(buf)-pos);
- return res;
-}
+
/**
* get neighbor name prefix from interest/content name and put into nbr
@@ -307,20 +290,6 @@
struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
sp.template_ccnb=ccn_charbuf_create();
- /*ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_SignedInfo, CCN_DTAG);
- ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyLocator, CCN_DTAG);
- ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyName, CCN_DTAG);
- ccn_charbuf_append_charbuf(sp.template_ccnb, name);
- ccn_charbuf_append_closer(sp.template_ccnb);
- ccn_charbuf_append_closer(sp.template_ccnb);
- ccn_charbuf_append_closer(sp.template_ccnb);
-
- sp.sp_flags |= CCN_SP_TEMPL_KEY_LOCATOR;
- sp.sp_flags |= CCN_SP_FINAL_BLOCK;
- sp.type = CCN_CONTENT_KEY;
- sp.freshness = 10;
- */
-
ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
@@ -418,33 +387,41 @@
break;
case CCN_UPCALL_INTEREST_TIMED_OUT:
- //printf("Interest Timed Out Received for Name: ");
- if ( nlsr->debugging )
- printf("Interest Timed Out Received for Name: ");
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Receiv"
+ //printf("Interest Timed Out Received for Name: ");
+ if ( nlsr->debugging )
+ printf("Interest Timed Out Received for Name: ");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Receiv"
"ed for Name: ");
- struct ccn_charbuf*ito;
- ito=ccn_charbuf_create();
- ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
- if ( nlsr->debugging )
- printf("%s\n",ccn_charbuf_as_string(ito));
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito));
- ccn_charbuf_destroy(&ito);
+ struct ccn_charbuf*ito;
+ ito=ccn_charbuf_create();
+ ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
+ if ( nlsr->debugging )
+ printf("%s\n",ccn_charbuf_as_string(ito));
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito));
+ ccn_charbuf_destroy(&ito);
-
-
- process_incoming_timed_out_interest(selfp,info);
+ process_incoming_timed_out_interest(selfp,info);
break;
+
+ case CCN_UPCALL_CONTENT_UNVERIFIED:
+ if ( nlsr->debugging )
+ printf("Unverified Content Received ..Waiting for verification\n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unverified Content"
+ " Received ..Waiting for verification\n");
+ return CCN_UPCALL_RESULT_VERIFY;
+ break;
+
default:
fprintf(stderr, "Unexpected response of kind %d\n", kind);
- if ( nlsr->debugging )
- printf("Unexpected response of kind %d\n", kind);
- if ( nlsr->detailed_logging )
- writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of "
+ if ( nlsr->debugging )
+ printf("Unexpected response of kind %d\n", kind);
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of "
"kind %d\n", kind);
break;
}
@@ -518,20 +495,6 @@
"ghbor: %s Length:%d\n",nbr->name,nbr->length);
- if ( contain_key_name(info->content_ccnb, info->pco) == 1)
- {
- struct ccn_charbuf *key_name=get_key_name(info->content_ccnb, info->pco);
- struct ccn_charbuf *key_uri = ccn_charbuf_create();
- ccn_uri_append(key_uri, key_name->buf, key_name->length, 1);
-
- if(nlsr->debugging)
- printf("Key Name: %s\n",ccn_charbuf_as_string(key_uri));
-
- ccn_charbuf_destroy(&key_uri);
- ccn_charbuf_destroy(&key_name);
-
-
- }
update_adjacent_timed_out_zero_to_adl(nbr);
update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
@@ -801,40 +764,3 @@
ccn_charbuf_destroy(&name);
free(int_name);
}
-
-/**
-* Check whether content name contains a key name. Return 1 for containing
-*/
-
-int
-contain_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco)
-{
- if (pco->offset[CCN_PCO_B_KeyLocator] == pco->offset[CCN_PCO_E_KeyLocator])
- return -1;
-
- struct ccn_buf_decoder decoder;
- struct ccn_buf_decoder *d;
- d = ccn_buf_decoder_start(&decoder, ccnb +
- pco->offset[CCN_PCO_B_Key_Certificate_KeyName],
- pco->offset[CCN_PCO_E_Key_Certificate_KeyName] -
- pco->offset[CCN_PCO_B_Key_Certificate_KeyName]);
- if (ccn_buf_match_dtag(d, CCN_DTAG_KeyName))
- return 1;
-
- return -1;
-}
-
-/**
-* Extract Key Name from Content Name and return the Key Name
-*
-*/
-
-struct ccn_charbuf *
-get_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco)
-{
- struct ccn_charbuf *key_name = ccn_charbuf_create();
- ccn_charbuf_append(key_name, ccnb + pco->offset[CCN_PCO_B_KeyName_Name],
- pco->offset[CCN_PCO_E_KeyName_Name] - pco->offset[CCN_PCO_B_KeyName_Name]);
-
- return key_name;
-}
diff --git a/nlsr_ndn.h b/nlsr_ndn.h
index b7b7725..c254793 100644
--- a/nlsr_ndn.h
+++ b/nlsr_ndn.h
@@ -21,8 +21,5 @@
int send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags);
void send_info_interest_to_neighbor(struct name_prefix *nbr);
-struct ccn_charbuf * get_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco);
-int contain_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco);
-
#endif
diff --git a/nlsr_sync.c b/nlsr_sync.c
index f2d390b..53652b5 100644
--- a/nlsr_sync.c
+++ b/nlsr_sync.c
@@ -29,9 +29,10 @@
#include "nlsr_sync.h"
#include "nlsr_lsdb.h"
#include "utility.h"
+#include "nlsr_km.h"
- char *
+char *
hex_string(unsigned char *s, size_t l)
{
const char *hex_digits = "0123456789abcdef";
@@ -45,7 +46,7 @@
return(r);
}
- int
+int
sync_cb(struct ccns_name_closure *nc,
struct ccn_charbuf *lhash,
struct ccn_charbuf *rhash,
@@ -116,16 +117,12 @@
- void
+void
get_name_part(struct name_prefix *name_part,struct ccn_charbuf * interest_ccnb,
struct ccn_indexbuf *interest_comps, int offset)
{
- //int i;
int lsa_position=0;
- //int len=0;
-
- //struct ccn_indexbuf cid={0};
- //struct ccn_indexbuf *components=&cid;
+
struct ccn_indexbuf *components=ccn_indexbuf_create();
struct ccn_charbuf *name=ccn_charbuf_create();
ccn_name_from_uri(name,nlsr->slice_prefix);
@@ -153,40 +150,6 @@
if ( nlsr->debugging )
printf("Name Part: %s \n",name_part->name);
-
- /*
- const unsigned char *comp_ptr1;
- size_t comp_size;
- for(i=lsa_position+1+offset;i<interest_comps->n-1;i++)
- {
- ccn_name_comp_get(interest_ccnb->buf, interest_comps,i,&comp_ptr1,
- &comp_size);
- len+=1;
- len+=(int)comp_size;
- }
- len++;
-
- char *neighbor=(char *)malloc(len);
- memset(neighbor,0,len);
-
- for(i=lsa_position+1+offset; i<interest_comps->n-1;i++)
- {
- ccn_name_comp_get(interest_ccnb->buf, interest_comps,i,&comp_ptr1,
- &comp_size);
- memcpy(neighbor+strlen(neighbor),"/",1);
- memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,
- strlen((char *)comp_ptr1));
-
- }
-
- name_part->name=(char *)malloc(strlen(neighbor)+1);
- memset(name_part->name,0,strlen(neighbor)+1);
- memcpy(name_part->name,neighbor,strlen(neighbor)+1);
- name_part->length=strlen(neighbor)+1;
-
- // Add 01/31/2013
- free(neighbor);
- */
}
@@ -272,7 +235,7 @@
ccn_charbuf_destroy(&name);
}
- void
+void
process_incoming_sync_content_lsa( unsigned char *content_data)
{
diff --git a/utility.c b/utility.c
index 6a7cb0c..ece8dea 100644
--- a/utility.c
+++ b/utility.c
@@ -297,4 +297,27 @@
}
+int
+add_ccn_uri_name(struct ccn_charbuf *res_name, struct ccn_charbuf *add){
+
+ int i, res;
+ struct ccn_indexbuf *idx=ccn_indexbuf_create();
+ res=ccn_name_split(add,idx);
+ if ( res < 0 ){
+ ccn_indexbuf_destroy(&idx);
+ return -1;
+ }
+
+ const unsigned char *comp_ptr1;
+ size_t comp_size;
+ for(i=0;i<idx->n-1;i++){
+ ccn_name_comp_get(add->buf,idx,i,&comp_ptr1, &comp_size);
+ ccn_name_append_str(res_name,(char *)comp_ptr1);
+ }
+ ccn_indexbuf_destroy(&idx);
+
+ return 0;
+
+}
+
diff --git a/utility.h b/utility.h
index bbca9f6..e681a0e 100644
--- a/utility.h
+++ b/utility.h
@@ -12,4 +12,7 @@
struct sockaddr_in * get_ip_from_hostname(char *hostname);
int get_ip_from_hostname_02(char * hostname , char* ip);
char * get_current_timestamp_micro_v2();
+
+int add_ccn_uri_name(struct ccn_charbuf *res_name, struct ccn_charbuf *add);
+
#endif