Packet Signing & Key Verification Stage: Middle
diff --git a/macbook.conf b/macbook.conf
index 7310e35..efe4f59 100644
--- a/macbook.conf
+++ b/macbook.conf
@@ -1,9 +1,9 @@
#----configuration file for macbook----------
#
-router-name /ndn/memphis.edu/netlab/macbook
+router-name /ndn/memphis.edu/cs/pollux
ccnneighbor /ndn/memphis.edu/cs/gemeni
ccnneighbor /ndn/memphis.edu/cs/altair
-ccnneighbor /ndn/memphis.edu/cs/pollux 141.225.11.132
+#ccnneighbor /ndn/memphis.edu/cs/pollux 141.225.11.132
ccnname /ndn/memphis.edu/macbook/patterson
ccnname /ndn/memphis.edu/macbook/houston/
#------lsdb-synch-interval-----
@@ -12,12 +12,16 @@
interest-resend-time 5
lsa-refresh-time 600
router-dead-interval 900
-max_faces_per_prefix 1
+max-faces-per-prefix 1
debug on
#hyperbolic-routing on
hyperbolic-cordinate 1234.0 0.875
tunnel-type udp
+keystore-path /Users/akmhoque/CCN_KEY/nlsr_key_store/.ccnx/.ccnx_keystore
+root-key-prefix /ndn/keys
+site-name memphis.edu
+
topo-prefix /ndn/routing/nlsr/
slice-prefix /ndn/routing/nlsr/LSA
diff --git a/nlsr.c b/nlsr.c
index b3c2f64..6ca3c40 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -563,7 +563,7 @@
//free(nlsr->topo_prefix);
nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1,sizeof(char));
memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1);
- printf ("Topo prefix is: %s", nlsr->topo_prefix);;
+ printf ("Topo prefix is: %s\n", nlsr->topo_prefix);
}
}
@@ -596,6 +596,38 @@
//free(nlsr->slice_prefix);
nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char));
memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1);
+ printf("Slice prefix: %s \n",nlsr->slice_prefix);
+ }
+}
+
+
+ void
+process_command_root_key_prefix(char *command)
+{
+ if(command==NULL)
+ {
+ printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
+ return;
+ }
+ char *rem;
+ const char *sep=" \t\n";
+ char *root_key_prefix;
+
+ root_key_prefix=strtok_r(command,sep,&rem);
+ if(root_key_prefix==NULL)
+ {
+ printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
+ return;
+ }
+ else
+ {
+ if ( nlsr->root_key_prefix != NULL)
+ free(nlsr->root_key_prefix);
+ if ( root_key_prefix[strlen(root_key_prefix)-1] == '/' )
+ root_key_prefix[strlen(root_key_prefix)-1]='\0';
+ nlsr->root_key_prefix=(char *)calloc(strlen(root_key_prefix)+1,sizeof(char));
+ memcpy(nlsr->root_key_prefix,root_key_prefix,strlen(root_key_prefix)+1);
+ printf("Root key prefix: %s \n",nlsr->root_key_prefix);
}
}
@@ -686,6 +718,94 @@
}
}
+void
+process_command_keystore_passphrase(char *command)
+{
+ if(command==NULL)
+ {
+ printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
+ return;
+ }
+ char *rem;
+ const char *sep=" \t\n";
+ char *passphrase;
+
+ passphrase=strtok_r(command,sep,&rem);
+ if(passphrase==NULL)
+ {
+ printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
+ return;
+ }
+
+ if( nlsr->keystore_passphrase)
+ free(nlsr->keystore_passphrase);
+ nlsr->keystore_passphrase=(char *)calloc(strlen(passphrase)+1,sizeof(char));
+ memcpy(nlsr->keystore_passphrase,passphrase,strlen(passphrase));
+
+
+}
+
+
+void
+process_command_keystore_path(char *command)
+{
+ if(command==NULL)
+ {
+ printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
+ return;
+ }
+ char *rem;
+ const char *sep=" \t\n";
+ char *path;
+
+ path=strtok_r(command,sep,&rem);
+ if(path==NULL)
+ {
+ printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
+ return;
+ }
+
+ if( nlsr->keystore_path)
+ free(nlsr->keystore_path);
+ nlsr->keystore_path=(char *)calloc(strlen(path)+1,sizeof(char));
+ memcpy(nlsr->keystore_path,path,strlen(path));
+
+}
+
+
+
+void
+process_command_site_name(char *command)
+{
+ if(command==NULL)
+ {
+ printf(" Wrong Command Format ( site-name site/name/prefix )\n");
+ return;
+ }
+ char *rem;
+ const char *sep=" \t\n";
+ char *site_name;
+
+ site_name=strtok_r(command,sep,&rem);
+ if(site_name==NULL)
+ {
+ printf(" Wrong Command Format ( site-name site/name/prefix )\n");
+ return;
+ }
+
+ if( nlsr->site_name)
+ free(nlsr->site_name);
+
+ if ( site_name[strlen(site_name)-1] == '/' )
+ site_name[strlen(site_name)-1]='\0';
+
+ nlsr->site_name=(char *)calloc(strlen(site_name)+1,sizeof(char));
+ memcpy(nlsr->site_name,site_name,strlen(site_name));
+ printf("Site Name prefix: %s \n",nlsr->site_name);
+
+}
+
+
void
process_conf_command(char *command)
{
@@ -762,6 +882,22 @@
{
process_command_tunnel_type(remainder);
}
+ else if(!strcmp(cmd_type,"site-name") )
+ {
+ process_command_site_name(remainder);
+ }
+ else if(!strcmp(cmd_type,"keystore-path") )
+ {
+ process_command_keystore_path(remainder);
+ }
+ else if(!strcmp(cmd_type,"keystore-passphrase") )
+ {
+ process_command_keystore_passphrase(remainder);
+ }
+ else if(!strcmp(cmd_type,"root-key-prefix") )
+ {
+ process_command_root_key_prefix(remainder);
+ }
else
{
printf("Wrong configuration Command %s \n",cmd_type);
@@ -1070,6 +1206,11 @@
fprintf(stderr,"Hyperbolic codinate has not been defined :(\n");
return -1;
}
+ if (nlsr->site_name == NULL )
+ {
+ fprintf(stderr,"Site name has not been configured :(\n");
+ return -1;
+ }
return 0;
}
@@ -1101,6 +1242,13 @@
close(nlsr->nlsr_api_server_sock_fd);
ccn_destroy(&nlsr->ccn);
+
+ free(nlsr->root_key_prefix);
+ free(nlsr->keystore_path);
+ free(nlsr->keystore_passphrase);
+ if( nlsr->site_name )
+ free(nlsr->site_name);
+
free(nlsr->router_name);
if ( nlsr->debugging )
{
@@ -1176,13 +1324,7 @@
nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL);
nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL);
- /*
- char *time_stamp=(char *) calloc (20,sizeof(char));
- get_current_timestamp_micro(time_stamp);
- nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
- memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp));
- free(time_stamp);
- */
+
nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
@@ -1221,6 +1363,14 @@
nlsr->tunnel_type=IPPROTO_UDP;
+ nlsr->root_key_prefix=(char *)calloc(strlen("/ndn/keys")+1,sizeof(char));
+ memcpy(nlsr->root_key_prefix,"/ndn/keys",strlen("/ndn/keys"));
+ nlsr->keystore_path=get_current_user_default_keystore();
+ nlsr->keystore_passphrase=(char *)calloc(strlen("Th1s1sn0t8g00dp8ssw0rd.")+1
+ ,sizeof(char));
+ memcpy(nlsr->keystore_passphrase,"Th1s1sn0t8g00dp8ssw0rd.",
+ strlen("Th1s1sn0t8g00dp8ssw0rd."));
+
return 0;
}
diff --git a/nlsr.h b/nlsr.h
index 2e33371..cb7a1c3 100644
--- a/nlsr.h
+++ b/nlsr.h
@@ -47,21 +47,17 @@
struct ccn_closure in_content;
struct ccns_name_closure *closure;
-
struct ccns_slice *slice;
struct ccns_handle *ccns;
struct ccn_schedule *sched;
struct ccn_scheduled_event *event;
- struct ccn_scheduled_event *event_send_lsdb_interest;
struct ccn_scheduled_event *event_send_info_interest;
- struct ccn_scheduled_event *event_build_name_lsa;
struct ccn_scheduled_event *event_build_adj_lsa;
struct ccn_scheduled_event *event_calculate_route;
struct hashtb *adl;
struct hashtb *npl;
- //struct hashtb *pit_alsa;
struct hashtb *map;
struct hashtb *rev_map;
struct hashtb *npt;
@@ -83,12 +79,11 @@
int is_send_lsdb_interest_scheduled;
int is_route_calculation_scheduled;
- //long int lsdb_synch_interval;
int interest_retry;
long int interest_resend_time;
long int lsa_refresh_time;
long int router_dead_interval;
- //long int multi_path_face_num;
+
long int max_faces_per_prefix;
char *logDir;
int detailed_logging;
@@ -103,6 +98,11 @@
char *topo_prefix;
char *slice_prefix;
+ char *root_key_prefix;
+ char *keystore_path;
+ char *keystore_passphrase;
+ char *site_name;
+
int is_hyperbolic_calc;
double cor_r;
double cor_theta;
diff --git a/nlsr_km.c b/nlsr_km.c
index 2bfa8fa..995db18 100644
--- a/nlsr_km.c
+++ b/nlsr_km.c
@@ -29,7 +29,8 @@
char *site_name,
char *router_name){
- printf("sign_content_with_user_defined_keystore called\n");
+ if ( nlsr->debugging )
+ printf("sign_content_with_user_defined_keystore called\n");
int res;
@@ -43,7 +44,8 @@
keystore=ccn_keystore_create();
res=ccn_keystore_init(keystore, keystore_path,keystore_passphrase );
if ( res < 0 ){
- printf("Error in initiating keystore :(\n");
+ if ( nlsr->debugging )
+ printf("Error in initiating keystore :(\n");
ccn_keystore_destroy(&keystore);
return -1;
}
@@ -51,11 +53,12 @@
res=ccn_load_private_key (nlsr->ccn,
keystore_path,
- "Th1s1sn0t8g00dp8ssw0rd.",
+ keystore_passphrase,
pubid_out);
if(res < 0 ){
- printf("Error in loading keystore :( \n");
+ if ( nlsr->debugging )
+ printf("Error in loading keystore :( \n");
ccn_charbuf_destroy(&pubid_out);
return -1;
}
@@ -63,7 +66,8 @@
char *baseuri=(char *)calloc(strlen(key_repo_name)+strlen(site_name)+
strlen(router_name)+strlen("/%C1.R.N.Start")+5,sizeof(char));
memcpy(baseuri,key_repo_name,strlen(key_repo_name)+1);
- memcpy(baseuri+strlen(baseuri),"/",1);
+ if ( site_name[0] != '/')
+ memcpy(baseuri+strlen(baseuri),"/",1);
memcpy(baseuri+strlen(baseuri),site_name,strlen(site_name)+1);
memcpy(baseuri+strlen(baseuri),"/%C1.R.N.Start",strlen("/%C1.R.N.Start"));
memcpy(baseuri+strlen(baseuri),router_name,strlen(router_name)+1);
@@ -78,7 +82,8 @@
}
ccn_name_from_uri(keyname,baseuri);
if ( res < 0 ){
- printf("Bad URI format: %s\n",baseuri);
+ if ( nlsr->debugging )
+ printf("Bad URI format: %s\n",baseuri);
ccn_charbuf_destroy(&pubid_out);
ccn_charbuf_destroy(&keyname);
free(baseuri);
@@ -97,7 +102,8 @@
struct ccn_charbuf *uri = ccn_charbuf_create();
ccn_uri_append(uri, keyname->buf, keyname->length, 0);
- printf("Key Name Included when processing content: %s\n", ccn_charbuf_as_string(uri));
+ if ( nlsr->debugging )
+ printf("Key Name Included when processing content: %s\n", ccn_charbuf_as_string(uri));
ccn_charbuf_destroy(&uri);
struct ccn_signing_params sp = CCN_SIGNING_PARAMS_INIT;
@@ -117,7 +123,8 @@
if (pubid_out->length != sizeof(sp.pubid)){
- printf("Size of pubid and sp.pubid is not equal");
+ if ( nlsr->debugging )
+ printf("Size of pubid and sp.pubid is not equal");
ccn_charbuf_destroy(&keyname);
ccn_charbuf_destroy(&pubid_out);
free(baseuri);
@@ -130,7 +137,8 @@
res=ccn_sign_content(nlsr->ccn,resultbuf,content_name,&sp,data,data_size);
if( res < 0 ){
- printf("Content signing error \n");
+ if ( nlsr->debugging )
+ printf("Content signing error \n");
ccn_charbuf_destroy(&sp.template_ccnb);
ccn_charbuf_destroy(&keyid);
ccn_charbuf_destroy(&keyname);
@@ -170,8 +178,8 @@
int
verify_key(const unsigned char *ccnb,size_t size,
struct ccn_parsed_ContentObject *pco){
-
- printf("verify key called\n");
+ if ( nlsr->debugging )
+ printf("verify key called\n");
int ret=-1;
if ( contain_key_name(ccnb, pco) == 1){
@@ -179,9 +187,11 @@
struct ccn_charbuf *key_name=get_key_name(ccnb, pco);
struct ccn_charbuf *key_uri = ccn_charbuf_create();
ccn_uri_append(key_uri, key_name->buf, key_name->length, 0);
- printf("Key Name from Incoming Content: %s\n",ccn_charbuf_as_string(key_uri));
- int res=get_key_type_from_key_name(key_name);
- printf("Key Type: %d \n",res);
+ if ( nlsr->debugging )
+ printf("Key Name from Incoming Content: %s\n",ccn_charbuf_as_string(key_uri));
+ int res=get_key_type_from_key_name(key_name);
+ if ( nlsr->debugging )
+ printf("Key Type: %d \n",res);
struct ccn_charbuf *result = ccn_charbuf_create();
struct ccn_parsed_ContentObject temp_pco = {0};
@@ -194,10 +204,12 @@
int chk_verify=ccn_verify_content(nlsr->ccn,ccnb,pco);
if ( chk_verify == 0 ){
- printf("Verification Successful :)\n");
+ if ( nlsr->debugging )
+ printf("Verification Successful :)\n");
if ( counter == 3){
- printf("Could not retrieve key by name !!!\n");
+ if ( nlsr->debugging )
+ printf("Could not retrieve key by name !!!\n");
}
else{
if ( res == ROOT_KEY ){
diff --git a/nlsr_km_util.c b/nlsr_km_util.c
index ee55252..6750c67 100644
--- a/nlsr_km_util.c
+++ b/nlsr_km_util.c
@@ -65,6 +65,44 @@
return key_name;
}
+
+int
+get_orig_router_from_key_name(struct ccn_charbuf *orig_router ,struct ccn_charbuf *name)
+{
+ int res;
+ struct ccn_indexbuf *name_comps;
+
+ name_comps = ccn_indexbuf_create();
+ res = ccn_name_split(name, name_comps);
+ if ( res < 0 ){
+ ccn_indexbuf_destroy(&name_comps);
+ return res;
+ }
+ else{
+ res=ccn_name_chop(name, name_comps, -2);
+ if ( res < 0 ){
+ ccn_indexbuf_destroy(&name_comps);
+ return res;
+ }
+ else{
+ res=check_for_tag_component_in_name(name,name_comps,"R.N.Start");
+ if ( res > 0 ){
+ ccn_name_init(orig_router);
+ ccn_name_append_components(orig_router,name->buf,
+ name_comps->buf[res+1],
+ name_comps->buf[name_comps->n - 1]);
+ }
+ else{
+ ccn_indexbuf_destroy(&name_comps);
+ return -1;
+ }
+ }
+ }
+
+ ccn_indexbuf_destroy(&name_comps);
+ return 0;
+}
+
int
check_for_name_component_in_name(const struct ccn_charbuf *name,
const struct ccn_indexbuf *indx,
diff --git a/nlsr_km_util.h b/nlsr_km_util.h
index 8ad001f..204a592 100644
--- a/nlsr_km_util.h
+++ b/nlsr_km_util.h
@@ -20,6 +20,10 @@
enum key_type
get_key_type_from_key_name(struct ccn_charbuf *keyname);
+int
+get_orig_router_from_key_name(struct ccn_charbuf *orig_router,
+ struct ccn_charbuf *name);
+
int
appendLifetime(struct ccn_charbuf *cb, int lifetime);
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index e4b1378..b907570 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -761,6 +761,7 @@
}
ccn_charbuf_destroy(&templ);
}
+
ccn_charbuf_destroy(&name);
free(int_name);
}
diff --git a/nlsr_sync.c b/nlsr_sync.c
index 53652b5..fd884cb 100644
--- a/nlsr_sync.c
+++ b/nlsr_sync.c
@@ -30,6 +30,7 @@
#include "nlsr_lsdb.h"
#include "utility.h"
#include "nlsr_km.h"
+#include "nlsr_km_util.h"
char *
@@ -133,13 +134,16 @@
struct ccn_charbuf *temp=ccn_charbuf_create();
ccn_name_init(temp);
ccn_name_append_components( temp, interest_ccnb->buf,
- interest_comps->buf[lsa_position+1], interest_comps->buf[interest_comps->n - 1]);
+ interest_comps->buf[lsa_position+1],
+ interest_comps->buf[interest_comps->n - 1]);
struct ccn_charbuf *temp1=ccn_charbuf_create();
ccn_uri_append(temp1, temp->buf, temp->length, 0);
- name_part->name=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1,sizeof(char));
- memcpy(name_part->name,ccn_charbuf_as_string(temp1),strlen(ccn_charbuf_as_string(temp1)));
+ name_part->name=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1,
+ sizeof(char));
+ memcpy(name_part->name,ccn_charbuf_as_string(temp1),
+ strlen(ccn_charbuf_as_string(temp1)));
name_part->name[strlen(ccn_charbuf_as_string(temp1))]='\0';
name_part->length=strlen(ccn_charbuf_as_string(temp1))+1;
@@ -156,20 +160,22 @@
- void
-get_content_by_content_name(char *content_name, unsigned char **content_data)
+int
+get_content_by_content_name(char *content_name, unsigned char **content_data,
+ char *orig_router)
{
-
+
+ int ret=-1;
struct ccn_charbuf *name = NULL;
struct ccn_charbuf *templ = NULL;
struct ccn_charbuf *resultbuf = NULL;
struct ccn_parsed_ContentObject pcobuf = { 0 };
int res;
- int allow_stale = 0;
+ int allow_stale = 1;
int content_only = 1;
int scope = -1;
- const unsigned char *ptr;
- size_t length;
+ const unsigned char *ptr,*ptr_in;
+ size_t length,length_in;
int resolve_version = CCN_V_HIGHEST;
int timeout_ms = 3000;
const unsigned lifetime_default = CCN_INTEREST_LIFETIME_SEC << 12;
@@ -180,7 +186,8 @@
res = ccn_name_from_uri(name,content_name);
if (res < 0) {
fprintf(stderr, "Bad ccn URI: %s\n", content_name);
- exit(1);
+ ccn_charbuf_destroy(&name);
+ return ret;
}
if (allow_stale || lifetime_l12 != lifetime_default || scope != -1) {
@@ -226,13 +233,53 @@
length = resultbuf->length;
if (content_only){
ccn_content_get_value(ptr, length, &pcobuf, &ptr, &length);
- *content_data = (unsigned char *) calloc(length, sizeof(char *));
- memcpy (*content_data, ptr, length);
+ struct ccn_parsed_ContentObject pcobuf1 = { 0 };
+ int chk_cont=ccn_parse_ContentObject(ptr,length,&pcobuf1,NULL);
+ printf("Content Parsing result: %d\n",chk_cont);
+ if ( contain_key_name(ptr, &pcobuf1) == 1){
+ struct ccn_charbuf *key_name=get_key_name(ptr, &pcobuf1);
+ struct ccn_charbuf *orig_router_kn=ccn_charbuf_create();
+ res=get_orig_router_from_key_name(orig_router_kn,key_name);
+ if( res == 0){
+ struct ccn_charbuf *rtr_uri = ccn_charbuf_create();
+ ccn_uri_append(rtr_uri, orig_router_kn->buf,
+ orig_router_kn->length, 0);
+ printf("Orig Router from Key name: %s\n",
+ ccn_charbuf_as_string(rtr_uri));
+
+ if( strcmp(orig_router,ccn_charbuf_as_string(rtr_uri)) == 0){
+
+ int res_verify=verify_key(ptr,pcobuf1.offset[CCN_PCO_E],
+ &pcobuf1);
+
+ if ( res_verify != 0 ){
+ printf("Error in verfiying keys !! :( \n");
+ }
+ else{
+ printf("Key verification is successful :)\n");
+ ptr_in=ptr;
+ length_in=length;
+ ccn_content_get_value(ptr_in, length_in, &pcobuf1,
+ &ptr_in, &length_in);
+ *content_data = (unsigned char *) calloc(length_in,
+ sizeof(char *));
+ memcpy (*content_data, ptr_in, length_in);
+ ret=0;
+ }
+ }
+ ccn_charbuf_destroy(&rtr_uri);
+ }
+ ccn_charbuf_destroy(&key_name);
+ ccn_charbuf_destroy(&orig_router_kn);
+ }
}
}
+
ccn_charbuf_destroy(&resultbuf);
ccn_charbuf_destroy(&templ);
- ccn_charbuf_destroy(&name);
+ ccn_charbuf_destroy(&name);
+
+ return ret;
}
void
@@ -304,7 +351,8 @@
printf(" Name Prefix length: %d\n",name_length);
}
- build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np);
+ build_and_install_others_name_lsa(orig_router,ls_type,ls_id,
+ orig_time,isValid,np);
print_name_lsdb();
@@ -322,7 +370,8 @@
printf(" No Link : %d\n",no_link);
printf(" Data : %s\n",data);
}
- build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data);
+ build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,
+ no_link,data);
}
else if ( ls_type == LS_TYPE_COR )
{
@@ -340,13 +389,14 @@
printf(" Cor R : %f\n",r);
printf(" Cor Theta : %f\n",theta);
}
- build_and_install_others_cor_lsa(orig_router,ls_type,orig_time, (double)r, (double)theta);
+ build_and_install_others_cor_lsa(orig_router,ls_type,orig_time,
+ (double)r, (double)theta);
}
}
}
- void
+void
process_content_from_sync (struct ccn_charbuf *content_name,
struct ccn_indexbuf *components)
{
@@ -393,42 +443,63 @@
{
lsid=rem;
ls_id=atoi(rem);
- ccn_name_comp_get(content_name->buf, components,components->n-2-2,&third_last_comp, &comp_size);
+ ccn_name_comp_get(content_name->buf, components,components->n-2-2,
+ &third_last_comp, &comp_size);
lst=strtok_r((char *)third_last_comp,sep,&rem);
lst=rem;
ls_type=atoi(lst);
- ccn_name_comp_get(content_name->buf, components,components->n-2,&origtime, &comp_size);
+ ccn_name_comp_get(content_name->buf, components,components->n-2,
+ &origtime, &comp_size);
ccn_name_chop(content_name,components,-3);
get_name_part(orig_router,content_name,components,0);
if ( nlsr->debugging )
- printf("Orig Router: %s Ls Type: %d Ls id: %ld Orig Time: %s\n",orig_router->name,ls_type,ls_id,origtime);
+ printf("Orig Router: %s Ls Type: %d Ls id: %ld Orig Time: %s\n",
+ orig_router->name,ls_type,ls_id,origtime);
int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
if ( nlsr->debugging )
printf("LSA Life time: %d\n",lsa_life_time);
- if ( (strcmp(orig_router->name,nlsr->router_name) == 0 && lsa_life_time < nlsr->lsa_refresh_time)
- || (strcmp(orig_router->name,nlsr->router_name) != 0 && lsa_life_time < nlsr->router_dead_interval) )
+ if ( (strcmp(orig_router->name,nlsr->router_name) == 0 &&
+ lsa_life_time < nlsr->lsa_refresh_time)
+ || (strcmp(orig_router->name,nlsr->router_name) != 0
+ && lsa_life_time < nlsr->router_dead_interval) )
{
- int is_new_name_lsa=check_is_new_name_lsa(orig_router->name,(char *)lst,(char *)lsid,(char *)origtime);
+ int is_new_name_lsa=check_is_new_name_lsa(orig_router->name,
+ (char *)lst,(char *)lsid,(char *)origtime);
if ( is_new_name_lsa == 1 )
{
if ( nlsr->debugging )
printf("New NAME LSA.....\n");
- get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
- if ( nlsr->debugging )
- printf("Content Data: %s \n",content_data);
- process_incoming_sync_content_lsa(content_data);
+ int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
+ &content_data,orig_router->name);
+ if ( chk_con == 0 ){
+ if ( nlsr->debugging )
+ printf("Content Data: %s \n",content_data);
+ process_incoming_sync_content_lsa(content_data);
+ }
+ else{
+ if ( nlsr->debugging )
+ printf("Verification failed. No content given back\n");
+ }
}
else
{
if ( nlsr->debugging )
printf("Name LSA / Newer Name LSA already xists in LSDB\n");
- get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
+ int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri)
+ , &content_data,orig_router->name);
- if ( nlsr->debugging )
- printf("Content Data: %s \n",content_data);
+ if ( chk_con == 0 ){
+ if ( nlsr->debugging )
+ printf("Content Data: %s \n",content_data);
+ process_incoming_sync_content_lsa(content_data);
+ }
+ else{
+ if ( nlsr->debugging )
+ printf("Verification failed. No content given back\n");
+ }
}
}
else
@@ -467,19 +538,34 @@
{
if ( nlsr->debugging )
printf("New Adj LSA.....\n");
- get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
+ int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
+ &content_data,orig_router->name);
- if ( nlsr->debugging )
- printf("Content Data: %s \n",content_data);
- process_incoming_sync_content_lsa(content_data);
+ if ( chk_con == 0 ){
+ if ( nlsr->debugging )
+ printf("Content Data: %s \n",content_data);
+ process_incoming_sync_content_lsa(content_data);
+ }
+ else{
+ if ( nlsr->debugging )
+ printf("Verification failed. No content given back\n");
+ }
}
else
{
if ( nlsr->debugging )
printf("Adj LSA / Newer Adj LSA already exists in LSDB\n");
- get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
- if ( nlsr->debugging )
- printf("Content Data: %s \n",content_data);
+ int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
+ &content_data,orig_router->name);
+ if ( chk_con == 0 ){
+ if ( nlsr->debugging )
+ printf("Content Data: %s \n",content_data);
+ process_incoming_sync_content_lsa(content_data);
+ }
+ else{
+ if ( nlsr->debugging )
+ printf("Verification failed. No content given back\n");
+ }
}
}
else
@@ -514,20 +600,35 @@
{
if ( nlsr->debugging )
printf("New Cor LSA.....\n");
- get_content_by_content_name(ccn_charbuf_as_string(uri),
- &content_data);
+ int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
+ &content_data,
+ orig_router->name);
- if ( nlsr->debugging )
- printf("Content Data: %s \n",content_data);
- process_incoming_sync_content_lsa(content_data);
+ if ( chk_con == 0 ){
+ if ( nlsr->debugging )
+ printf("Content Data: %s \n",content_data);
+ process_incoming_sync_content_lsa(content_data);
+ }
+ else{
+ if ( nlsr->debugging )
+ printf("Verification failed. No content given back\n");
+ }
}
else
{
if ( nlsr->debugging )
printf("Cor LSA / Newer Cor LSA already exists in LSDB\n");
- get_content_by_content_name(ccn_charbuf_as_string(uri), &content_data);
- if ( nlsr->debugging )
- printf("Content Data: %s \n",content_data);
+ int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri),
+ &content_data,orig_router->name);
+ if ( chk_con == 0 ){
+ if ( nlsr->debugging )
+ printf("Content Data: %s \n",content_data);
+ process_incoming_sync_content_lsa(content_data);
+ }
+ else{
+ if ( nlsr->debugging )
+ printf("Verification failed. No content given back\n");
+ }
}
}
else
@@ -648,15 +749,30 @@
return -1;
}
- blockread = 0;
+ struct ccn_charbuf *resultbuf=ccn_charbuf_create();
- blockread=strlen(data)+1;
+ sign_content_with_user_defined_keystore(name,
+ resultbuf,
+ data,
+ strlen(data),
+ nlsr->keystore_path,
+ nlsr->keystore_passphrase,
+ nlsr->root_key_prefix,
+ nlsr->site_name,
+ nlsr->router_name);
+
+
+ //blockread = 0;
+ //blockread=strlen(data)+1;
+ blockread=resultbuf->length;
if (blockread > 0) {
- res = ccn_seqw_write(w, data, blockread);
+ //res = ccn_seqw_write(w, data, blockread);
+ res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length);
while (res == -1) {
ccn_run(temp_ccn,100);
- res = ccn_seqw_write(w, data, blockread);
+ //res = ccn_seqw_write(w, data, blockread);
+ res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length);
}
}
@@ -671,7 +787,7 @@
create_sync_slice(char *topo_prefix, char *slice_prefix)
{
int res;
- struct ccn *handle; //obaid: probably we don't need it use the same handle i.e. nlsr->ccn
+ struct ccn *handle;
struct ccns_slice *slice;
struct ccn_charbuf *prefix = ccn_charbuf_create();
struct ccn_charbuf *topo = ccn_charbuf_create();
@@ -702,7 +818,6 @@
res = ccns_write_slice(handle, slice, slice_name);
- //res = ccns_write_slice(nlsr->ccn, slice, slice_name);
//01/31/2013
ccns_slice_destroy(&slice);
diff --git a/utility.c b/utility.c
index ece8dea..51afa86 100644
--- a/utility.c
+++ b/utility.c
@@ -92,7 +92,7 @@
}
char *
-get_current_timestamp_micro_v2()
+get_current_timestamp_micro_v2(void)
{
struct timeval now;
gettimeofday(&now, NULL);
@@ -144,21 +144,15 @@
char *ret;
char *logExt;
char *defaultLogDir;
- //int status;
struct stat st;
int isLogDirExists=0;
char *time=getLocalTimeStamp();
- pwdbuffer=(char *)malloc(sizeof(char)*200);
- memset(pwdbuffer,0,200);
- logDir=(char *)malloc(sizeof(char)*200);
- memset(logDir,0,200);
- logFileName=(char *)malloc(sizeof(char)*200);
- memset(logFileName,0,200);
- logExt=(char *)malloc(sizeof(char)*5);
- memset(logExt,0,5);
- defaultLogDir=(char *)malloc(sizeof(char)*10);
- memset(defaultLogDir,0,10);
+ pwdbuffer=(char *)calloc(200,sizeof(char));
+ logDir=(char *)calloc(200,sizeof(char));
+ logFileName=(char *)calloc(200,sizeof(char));
+ logExt=(char *)calloc(5,sizeof(char));
+ defaultLogDir=(char *)calloc(10,sizeof(char));
memcpy(logExt,".log",4);
logExt[4]='\0';
@@ -192,8 +186,7 @@
memcpy(logDir,pd.pw_dir,strlen(pd.pw_dir)+1);
memcpy(logDir+strlen(logDir),defaultLogDir,strlen(defaultLogDir)+1);
if(stat(logDir,&st) != 0)
- mkdir(logDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
- //printf("Status: %d\n",status);
+ mkdir(logDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
}
}
memcpy(logFileName,logDir,strlen(logDir)+1);
@@ -220,6 +213,39 @@
}
+char *
+get_current_user_home(void){
+
+ const char *homeDir = getenv("HOME");
+
+ if (!homeDir ) {
+ struct passwd* pwd = getpwuid(getuid());
+ if (pwd)
+ homeDir = pwd->pw_dir;
+ }
+
+ char *home=(char *)calloc(strlen(homeDir)+1,sizeof(char));
+ memcpy(home,homeDir,strlen(homeDir)+1);
+
+ return home;
+}
+
+
+char *
+get_current_user_default_keystore(void){
+
+ char *home=get_current_user_home();
+ char *def_keystore=(char *)calloc(strlen(home)+strlen("/.ccnx") +
+ strlen("/.ccnx_keystore")+1,sizeof(char));
+ memcpy(def_keystore,home,strlen(home));
+ memcpy(def_keystore+strlen(def_keystore),"/.ccnx/.ccnx_keystore",
+ strlen("/.ccnx/.ccnx_keystore"));
+ def_keystore[strlen(def_keystore)]='\0';
+ free(home);
+
+ return def_keystore;
+}
+
void
writeLogg(const char *source_file, const char *function, const int line, const char *format, ...)
{
diff --git a/utility.h b/utility.h
index e681a0e..dc935da 100644
--- a/utility.h
+++ b/utility.h
@@ -11,7 +11,9 @@
void writeLogg(const char *source_file, const char *function, const int line, const char *format, ...);
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();
+char * get_current_timestamp_micro_v2(void);
+char * get_current_user_home(void);
+char * get_current_user_default_keystore(void);
int add_ccn_uri_name(struct ccn_charbuf *res_name, struct ccn_charbuf *add);