Strict Hierarchical Check of Trust Chain Final
diff --git a/nlsr_km.c b/nlsr_km.c
index 81c4a80..e3fa463 100644
--- a/nlsr_km.c
+++ b/nlsr_km.c
@@ -156,25 +156,6 @@
}
-/*
-int
-process_incoming_content(struct ccn_closure* selfp,
- struct ccn_upcall_info* info){
-
- printf("process_incoming_content called\n");
-
- int res=verify_key(info->content_ccnb,info->pco->offset[CCN_PCO_E],info->pco);
-
- if ( res != 0 ){
- printf("Error in verfiying keys !! :( \n");
- }
- else{
- printf("Key verification is successful :)\n");
- }
- return 0;
-}
-*/
-
char *
get_orig_router_from_lsa_name(struct ccn_charbuf * content_name)
{
@@ -188,7 +169,7 @@
struct ccn_indexbuf *components=ccn_indexbuf_create();
struct ccn_charbuf *name=ccn_charbuf_create();
- ccn_name_from_uri(name,"/ndn/routing/nlsr/LSA");
+ ccn_name_from_uri(name,nlsr->slice_prefix);
ccn_name_split (name, components);
start=components->n-2;
ccn_charbuf_destroy(&name);
@@ -232,11 +213,47 @@
}
+char *
+get_orig_router_from_info_content_name(struct ccn_charbuf * content_name)
+{
+ int start,end;
+
+ start=0;
+
+ struct ccn_indexbuf *comps=ccn_indexbuf_create();
+ ccn_name_split (content_name, comps);
+
+ end=check_for_name_component_in_name(content_name,comps,"nlsr");
+
+
+ struct ccn_charbuf *temp=ccn_charbuf_create();
+ ccn_name_init(temp);
+ ccn_name_append_components( temp, content_name->buf,
+ comps->buf[start],
+ comps->buf[end]);
+
+ struct ccn_charbuf *temp1=ccn_charbuf_create();
+ ccn_uri_append(temp1, temp->buf, temp->length, 0);
+
+ char *orig_router=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1,
+ sizeof(char));
+ memcpy(orig_router,ccn_charbuf_as_string(temp1),
+ strlen(ccn_charbuf_as_string(temp1)));
+ orig_router[strlen(orig_router)]='\0';
+
+ ccn_charbuf_destroy(&temp);
+ ccn_charbuf_destroy(&temp1);
+ ccn_indexbuf_destroy(&comps);
+ return orig_router;
+
+
+}
+
int
check_key_name_hierarchy(const unsigned char *ccnb,
struct ccn_parsed_ContentObject *pco,
- int key_type){
+ int key_type, int content_type){
printf("check_key_name_hierarchy called\n");
if (key_type == UNKNOWN_KEY ){
return 1;
@@ -260,7 +277,13 @@
if ( key_type == NLSR_KEY){
char *orig_router_key_name=get_orig_router_from_key_name(key_name,0,0);
- char *orig_router_content_name=get_orig_router_from_lsa_name(content_name);
+ char *orig_router_content_name;
+ if ( content_type == 1 ){
+ orig_router_content_name=get_orig_router_from_lsa_name(content_name);
+ }
+ else if ( content_type == 0 ){
+ orig_router_content_name=get_orig_router_from_info_content_name(content_name);
+ }
printf("Orig Router (Key Name):%s\n",orig_router_key_name);
printf("Orig Router (Content Name):%s\n",orig_router_content_name);
@@ -354,7 +377,8 @@
int
verify_key(const unsigned char *ccnb,
- struct ccn_parsed_ContentObject *pco){
+ struct ccn_parsed_ContentObject *pco,
+ int content_type){
if ( nlsr->debugging )
printf("verify key called\n");
int ret=-1;
@@ -383,7 +407,7 @@
if ( chk_verify == 0 ){
if ( nlsr->debugging )
- printf("Verification Successful :)\n");
+ printf("Content verification Successful :)\n");
if ( counter == 3){
if ( nlsr->debugging )
@@ -394,15 +418,17 @@
ret=0;
}
else{
- //ret=verify_key(result->buf,&temp_pco);
if ( nlsr->isStrictHierchicalKeyCheck ){
- int key_name_test=check_key_name_hierarchy(ccnb,pco,key_type);
+ int key_name_test=check_key_name_hierarchy(ccnb,
+ pco,
+ key_type,
+ content_type);
if ( key_name_test == 1){
- ret=verify_key(result->buf,&temp_pco);
+ ret=verify_key(result->buf,&temp_pco,content_type);
}
}
else{
- ret=verify_key(result->buf,&temp_pco);
+ ret=verify_key(result->buf,&temp_pco,content_type);
}
}
}