Packet Signing & Key Verification Stage: Middle
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 ){