Skip to content

Commit

Permalink
Change format of the crypto packets to match ccn-content-object
Browse files Browse the repository at this point in the history
conventions
  • Loading branch information
blacksheeep committed Nov 27, 2013
1 parent 55b26f3 commit 7bc2b4a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 131 deletions.
4 changes: 2 additions & 2 deletions ccnl-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,8 @@ ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
ccnl_print_stats(relay, STAT_RCV_C); //log count recv_content

#ifdef CCNL_USE_MGMT_SIGNATUES
if (p->compcnt == 3 && !memcmp(p->comp[0], "ccnx", 4)
/*&& !memcmp(p->comp[1], "crypto", 6)*/) {
if (p->compcnt == 2 && !memcmp(p->comp[0], "ccnx", 4)
&& !memcmp(p->comp[1], "crypto", 6)) {
rc = ccnl_crypto(relay, buf, p, from); goto Done;
}
#endif /*CCNL_USE_MGMT_SIGNATUES*/
Expand Down
79 changes: 31 additions & 48 deletions ccnl-ext-crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,17 @@ ccnl_crypto_ux_open(char *path, struct sockaddr_un *ux)
#endif

static int
ccnl_crypto_get_tag_content(unsigned char **buf, int *len, char *content, int contentlen){
ccnl_crypto_get_tag_content(unsigned char **buf, int *len, int numletters, char *content, int contentlen){
int num = 0;
int end = numletters < contentlen ? numletters : contentlen;
memset(content,0,contentlen);
while((**buf) != 0 && num < contentlen)
for(num = 0; num < end; ++num)
{
content[num] = **buf;
++(*buf); --(*len);
++num;
}
++(*buf); --(*len);
++num;
return num;
}

Expand Down Expand Up @@ -168,10 +169,10 @@ ccnl_crypto_create_ccnl_sign_verify_msg(char *typ, int txid, char *content, int

len += mkStrBlob(msg+len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx");
len += mkStrBlob(msg+len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "crypto");
len += mkStrBlob(msg+len, CCNL_DTAG_CALLBACK, CCN_TT_DTAG, callback);

// prepare FACEINSTANCE

len3 += mkStrBlob(component_buf+len3, CCNL_DTAG_CALLBACK, CCN_TT_DTAG, callback);
len3 += mkStrBlob(component_buf+len3, CCN_DTAG_TYPE, CCN_TT_DTAG, typ);
memset(h, 0, 100);
sprintf(h, "%d", txid);
len3 += mkStrBlob(component_buf+len3, CCN_DTAG_SEQNO, CCN_TT_DTAG, h);
Expand All @@ -183,7 +184,6 @@ ccnl_crypto_create_ccnl_sign_verify_msg(char *typ, int txid, char *content, int

// prepare CONTENTOBJ with CONTENT
len2 = mkHeader(contentobj_buf, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // contentobj
len2 += mkStrBlob(contentobj_buf+len2, CCN_DTAG_TYPE, CCN_TT_DTAG, typ);
len2 += mkBlob(contentobj_buf+len2, CCN_DTAG_CONTENT, CCN_TT_DTAG, // content
(char*) component_buf, len3);
contentobj_buf[len2++] = 0; // end-of-contentobj
Expand Down Expand Up @@ -217,34 +217,33 @@ ccnl_crypto_extract_type_callback(unsigned char **buf, int *buflen, char *type,
if (typ != CCN_TT_DTAG || num != CCN_DTAG_COMPONENT) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf,buflen, comp1, sizeof(comp1));
ccnl_crypto_get_tag_content(buf, buflen, num, comp1, sizeof(comp1));

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_COMPONENT) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf,buflen, comp1, sizeof(comp1));
ccnl_crypto_get_tag_content(buf, buflen, num, comp1, sizeof(comp1));

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCNL_DTAG_CALLBACK) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf,buflen, callback, max_callback_length);

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_COMPONENT) goto Bail;

if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENT) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENTOBJ) goto Bail;

if (typ != CCN_TT_DTAG || num != CCNL_DTAG_CALLBACK) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf, buflen, num, callback, max_callback_length);

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_TYPE) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf,buflen, type, max_type_length);
ccnl_crypto_get_tag_content(buf, buflen, num, type, max_type_length);

return 1;
Bail:
return 0;
Expand All @@ -256,13 +255,13 @@ ccnl_crypto_extract_msg(unsigned char **buf, int *buflen, char **msg){
int len = 0;
int num, typ;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENT) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENTDIGEST) goto Bail;

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;

*msg = *buf;
len = (*buflen) - 6;
len = num;

return len;
Bail:
Expand Down Expand Up @@ -291,37 +290,25 @@ ccnl_crypto_extract_sign_reply(unsigned char **buf, int *buflen, char *sig, int
char type[100];
int num, typ;
char seqnumber_s[100];
char siglen_s[100];
int seqnubmer;
int siglen = 0;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENT) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;


if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_SEQNO) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf, buflen, seqnumber_s, sizeof(seqnumber_s));
ccnl_crypto_get_tag_content(buf, buflen, num, seqnumber_s, sizeof(seqnumber_s));
seqnubmer = ccnl_crypto_strtoint(seqnumber_s);
*seqnum = seqnubmer;

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_SIGNEDINFO) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf, buflen, siglen_s, sizeof(siglen_s));
siglen = ccnl_crypto_strtoint(siglen_s);
*sig_len = siglen;

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_SIGNATURE) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_signature(buf, buflen, sig, siglen);
++(*buf);
--(*buflen);
siglen = num;
ccnl_crypto_get_tag_content(buf, buflen, siglen, sig, CCNL_MAX_PACKET_SIZE);
//ccnl_crypto_get_signature(buf, buflen, sig, siglen);

*sig_len = siglen;
ret = 1;
Expand All @@ -338,27 +325,24 @@ ccnl_crypto_extract_verify_reply(unsigned char **buf, int *buflen, int *seqnum)
char seqnumber_s[100], verified_s[100];
int seqnubmer, h;

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_CONTENT) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCN_DTAG_SEQNO) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf, buflen, seqnumber_s, sizeof(seqnumber_s));
ccnl_crypto_get_tag_content(buf, buflen, num, seqnumber_s, sizeof(seqnumber_s));
seqnubmer = ccnl_crypto_strtoint(seqnumber_s);
*seqnum = seqnubmer;

if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_DTAG || num != CCNL_DTAG_VERIFIED) goto Bail;
if(dehead(buf, buflen, &num, &typ)) goto Bail;
if (typ != CCN_TT_BLOB) goto Bail;
ccnl_crypto_get_tag_content(buf, buflen, verified_s, sizeof(verified_s));
ccnl_crypto_get_tag_content(buf, buflen, num, verified_s, sizeof(verified_s));
h = ccnl_crypto_strtoint(verified_s);
if(h == 1) verified = 1;

if(h == 1) {
verified = 1;
DEBUGMSG(99,"VERIFIED\n");
}
Bail:
return verified;
}
Expand Down Expand Up @@ -508,6 +492,7 @@ ccnl_mgmt_crypto(struct ccnl_relay_s *ccnl, char *type, char *buf, int buflen)
char *msg;
int siglen, seqnum, len, len1;
struct ccnl_buf_s *retbuf;

ccnl_crypto_extract_sign_reply(&buf, &buflen, sig, &siglen, &seqnum);

len = ccnl_crypto_extract_msg(&buf, &buflen, &msg);
Expand All @@ -522,7 +507,6 @@ ccnl_mgmt_crypto(struct ccnl_relay_s *ccnl, char *type, char *buf, int buflen)

out[len1++] = 0; // end-of-name
out[len1++] = 0; // end-of-interest
DEBUGMSG(99, "LEN1: %d", len1);
from = ccnl->faces;
while(from){
if(from->faceid == seqnum)
Expand Down Expand Up @@ -581,7 +565,6 @@ ccnl_crypto(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig,
char type[100];
char callback[100];


if(!ccnl_crypto_extract_type_callback(&buf, &buflen, type, sizeof(type), callback,
sizeof(callback))) goto Bail;

Expand Down
47 changes: 19 additions & 28 deletions doc/ccnl_crypto_system.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ The format of the sign request is the following:
<name>
<component>ccnx</component>
<component>crypto</component>
<callback>"name of the function called when the relay receives the answer"</callback>
<component>
<contentobj>
<type>sign</type>
<content>
<content>
<callback>"name of the function called when the relay receives the answer"</callback>
<type>sign</type>
<sequnumber>"sequence-number"</sequnumber>
<contentdigest> "content to sign" </contentdigest>
</content>
Expand All @@ -88,19 +88,14 @@ The sign reply msg is the following:
<name>
<component>ccnx</component>
<component>crypto</component>
<callback>"name of the function called when the relay receives the answer"</callback>
<component>
<contentobj>
<type>sign</type>
<content>
<sequnumber>"sequence-number"</sequnumber>
<siglen>"size of the signature"</siglen>
<signature>"the signature"</signature>
<contentdigest> "content to sign" </contentdigest>
</content>
</contentobj>
</component>
</name>
<content>
<callback>"name of the function called when the relay receives the answer"</callback>
<type>sign</type>
<sequnumber>"sequence-number"</sequnumber>
<signature>"the signature"</signature>
<contentdigest> "content to sign" </contentdigest>
</content>
</contentobj>

//----------------------------------------------------------------------------
Expand All @@ -111,11 +106,11 @@ Format of the verify request is the following:
<name>
<component>ccnx</component>
<component>crypto</component>
<callback>"name of the function called when the relay receives the answer"</callback>
<component>
<contentobj>
<type>verify</type>
<content>
<callback>"name of the function called when the relay receives the answer"</callback>
<type>verify</type>
<sequnumber>"sequence-number"</sequnumber>
<signature>"the signature"</signature>
<contentdigest> "content to verify" </contentdigest>
Expand All @@ -131,18 +126,14 @@ The verify reply msg is the following:
<name>
<component>ccnx</component>
<component>crypto</component>
<callback>"name of the function called when the relay receives the answer"</callback>
<component>
<contentobj>
<type>sign</type>
<content>
<sequnumber>"sequence-number"</sequnumber>
<verified>"1 if verified, else 0"</verified>
<contentdigest> "content to verify" </contentdigest>
</content>
</contentobj>
</component>
</name>
<content>
<callback>"name of the function called when the relay receives the answer"</callback>
<type>sign</type>
<sequnumber>"sequence-number"</sequnumber>
<verified>"1 if verified, else 0"</verified>
<contentdigest> "content to verify" </contentdigest>
</content>
</contentobj>

//----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 7bc2b4a

Please sign in to comment.