int add_signature(unsigned char *out, char *private_key_path, unsigned char *file, unsigned int fsize) { int len; unsigned char sig[2048]; unsigned int sig_len; len = ccnl_ccnb_mkHeader(out, CCN_DTAG_SIGNATURE, CCN_TT_DTAG); len += ccnl_ccnb_mkStrBlob(out + len, CCN_DTAG_NAME, CCN_TT_DTAG, "SHA256"); len += ccnl_ccnb_mkStrBlob(out + len, CCN_DTAG_WITNESS, CCN_TT_DTAG, ""); if(!sign(private_key_path, (unsigned char*)file, fsize, (unsigned char*)sig, &sig_len)) return 0; //printf("SIGLEN: %d\n",sig_len); sig[sig_len]=0; //add signaturebits bits... len += ccnl_ccnb_mkHeader(out + len, CCN_DTAG_SIGNATUREBITS, CCN_TT_DTAG); len += ccnl_ccnb_addBlob(out + len, (char*)sig, sig_len); out[len++] = 0; // end signaturebits out[len++] = 0; // end signature /*char *publickey = "/home/blacksheeep/.ssh/publickey.pem"; int verified = verify(publickey, file, fsize, sig, sig_len); printf("Verified: %d\n", verified);*/ return len; }
int mkEchoserverRequest(unsigned char *out, char *path, int suite, char *private_key_path) { int len = 0, len1 = 0, len2 = 0, len3 = 0; unsigned char out1[CCNL_MAX_PACKET_SIZE]; unsigned char contentobj[2000]; unsigned char fwdentry[2000]; char suite_s[1]; char *cp; DEBUGMSG(DEBUG, "mkEchoserverRequest uri=%s suite=%d\n", path, suite); len = ccnl_ccnb_mkHeader(out, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest len += ccnl_ccnb_mkHeader(out+len, CCN_DTAG_NAME, CCN_TT_DTAG); // name len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx"); len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, ""); len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "echoserver"); // prepare FWDENTRY len3 = ccnl_ccnb_mkHeader(fwdentry, CCN_DTAG_FWDINGENTRY, CCN_TT_DTAG); len3 += ccnl_ccnb_mkStrBlob(fwdentry+len3, CCN_DTAG_ACTION, CCN_TT_DTAG, "echoserver"); len3 += ccnl_ccnb_mkHeader(fwdentry+len3, CCN_DTAG_NAME, CCN_TT_DTAG); // prefix cp = strtok(path, "/"); while (cp) { unsigned short cmplen = strlen(cp); #ifdef USE_SUITE_CCNTLV if (suite == CCNL_SUITE_CCNTLV) { char* oldcp = cp; cp = malloc( (cmplen + 4) * (sizeof(char)) ); cp[0] = CCNX_TLV_N_NameSegment >> 8; cp[1] = CCNX_TLV_N_NameSegment; cp[2] = cmplen >> 8; cp[3] = cmplen; memcpy(cp + 4, oldcp, cmplen); cmplen += 4; } #endif #ifdef USE_SUITE_CISTLV if (suite == CCNL_SUITE_CISTLV) { char* oldcp = cp; cp = malloc( (cmplen + 4) * (sizeof(char)) ); cp[0] = CISCO_TLV_NameComponent >> 8; cp[1] = CISCO_TLV_NameComponent; cp[2] = cmplen >> 8; cp[3] = cmplen; memcpy(cp + 4, oldcp, cmplen); cmplen += 4; }
static int ccnl_crypto_create_ccnl_sign_verify_msg(char *typ, int txid, char *content, int content_len, char *sig, int sig_len, char *msg, char *callback) { int len = 0, len2 = 0, len3 = 0; char *component_buf, *contentobj_buf; char h[100]; component_buf = ccnl_malloc(sizeof(char)*(content_len)+2000); contentobj_buf = ccnl_malloc(sizeof(char)*(content_len)+1000); len = ccnl_ccnb_mkHeader(msg, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest len += ccnl_ccnb_mkHeader(msg+len, CCN_DTAG_NAME, CCN_TT_DTAG); // name len += ccnl_ccnb_mkStrBlob(msg+len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx"); len += ccnl_ccnb_mkStrBlob(msg+len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "crypto"); // prepare FACEINSTANCE len3 += ccnl_ccnb_mkStrBlob(component_buf+len3, CCNL_DTAG_CALLBACK, CCN_TT_DTAG, callback); len3 += ccnl_ccnb_mkStrBlob(component_buf+len3, CCN_DTAG_TYPE, CCN_TT_DTAG, typ); memset(h, 0, 100); sprintf(h, "%d", txid); len3 += ccnl_ccnb_mkStrBlob(component_buf+len3, CCN_DTAG_SEQNO, CCN_TT_DTAG, h); if(!strcmp(typ, "verify")) len3 += ccnl_ccnb_mkBlob(component_buf+len3, CCN_DTAG_SIGNATURE, CCN_TT_DTAG, // content (char*) sig, sig_len); len3 += ccnl_ccnb_mkBlob(component_buf+len3, CCN_DTAG_CONTENTDIGEST, CCN_TT_DTAG, // content (char*) content, content_len); // prepare CONTENTOBJ with CONTENT len2 = ccnl_ccnb_mkHeader(contentobj_buf, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // contentobj len2 += ccnl_ccnb_mkBlob(contentobj_buf+len2, CCN_DTAG_CONTENT, CCN_TT_DTAG, // content (char*) component_buf, len3); contentobj_buf[len2++] = 0; // end-of-contentobj // add CONTENTOBJ as the final name component len += ccnl_ccnb_mkBlob(msg+len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, // comp (char*) contentobj_buf, len2); msg[len++] = 0; // end-of-name msg[len++] = 0; // end-o ccnl_free(component_buf); ccnl_free(contentobj_buf); return len; }
static int ccnl_crypto_add_signature(unsigned char *out, char *sig, int siglen) { int len; len = ccnl_ccnb_mkHeader(out, CCN_DTAG_SIGNATURE, CCN_TT_DTAG); len += ccnl_ccnb_mkStrBlob(out + len, CCN_DTAG_NAME, CCN_TT_DTAG, "SHA256"); len += ccnl_ccnb_mkStrBlob(out + len, CCN_DTAG_WITNESS, CCN_TT_DTAG, ""); //add signaturebits bits... len += ccnl_ccnb_mkHeader(out + len, CCN_DTAG_SIGNATUREBITS, CCN_TT_DTAG); len += ccnl_ccnb_addBlob(out + len, sig, siglen); out[len++] = 0; // end signaturebits out[len++] = 0; // end signature return len; }
int mkDebugRequest(unsigned char *out, char *dbg, char *private_key_path) { int len = 0, len1 = 0, len2 = 0, len3 = 0; unsigned char out1[CCNL_MAX_PACKET_SIZE]; unsigned char contentobj[2000]; unsigned char stmt[1000]; len = ccnl_ccnb_mkHeader(out, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest len += ccnl_ccnb_mkHeader(out+len, CCN_DTAG_NAME, CCN_TT_DTAG); // name len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx"); len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, ""); len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "debug"); // prepare debug statement len3 = ccnl_ccnb_mkHeader(stmt, CCNL_DTAG_DEBUGREQUEST, CCN_TT_DTAG); len3 += ccnl_ccnb_mkStrBlob(stmt+len3, CCN_DTAG_ACTION, CCN_TT_DTAG, "debug"); len3 += ccnl_ccnb_mkStrBlob(stmt+len3, CCNL_DTAG_DEBUGACTION, CCN_TT_DTAG, dbg); stmt[len3++] = 0; // end-of-debugstmt // prepare CONTENTOBJ with CONTENT len2 = ccnl_ccnb_mkHeader(contentobj, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // contentobj len2 += ccnl_ccnb_mkBlob(contentobj+len2, CCN_DTAG_CONTENT, CCN_TT_DTAG, // content (char*) stmt, len3); contentobj[len2++] = 0; // end-of-contentobj // add CONTENTOBJ as the final name component len1 += ccnl_ccnb_mkBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, // comp (char*) contentobj, len2); #ifdef USE_SIGNATURES if(private_key_path) len += add_signature(out+len, private_key_path, out1, len1); #endif /*USE_SIGNATURES*/ memcpy(out+len, out1, len1); len += len1; out[len++] = 0; // end-of-name out[len++] = 0; // end-of-interest // ccnl_prefix_free(p); return len; }
int mkNewEthDevRequest(unsigned char *out, char *devname, char *ethtype, char *frag, char *flags, char *private_key_path) { int len = 0, len1 = 0, len2 = 0, len3 = 0; unsigned char out1[CCNL_MAX_PACKET_SIZE]; unsigned char contentobj[2000]; unsigned char faceinst[2000]; len = ccnl_ccnb_mkHeader(out, CCN_DTAG_INTEREST, CCN_TT_DTAG); // interest len += ccnl_ccnb_mkHeader(out+len, CCN_DTAG_NAME, CCN_TT_DTAG); // name len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "ccnx"); len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, ""); len1 += ccnl_ccnb_mkStrBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, "newdev"); // prepare DEVINSTANCE len3 = ccnl_ccnb_mkHeader(faceinst, CCNL_DTAG_DEVINSTANCE, CCN_TT_DTAG); len3 += ccnl_ccnb_mkStrBlob(faceinst+len3, CCN_DTAG_ACTION, CCN_TT_DTAG, "newdev"); if (devname) len3 += ccnl_ccnb_mkStrBlob(faceinst+len3, CCNL_DTAG_DEVNAME, CCN_TT_DTAG, devname); if (ethtype) len3 += ccnl_ccnb_mkStrBlob(faceinst+len3, CCN_DTAG_PORT, CCN_TT_DTAG, ethtype); if (frag) len3 += ccnl_ccnb_mkStrBlob(faceinst+len3, CCNL_DTAG_FRAG, CCN_TT_DTAG, frag); if (flags) len3 += ccnl_ccnb_mkStrBlob(faceinst+len3, CCNL_DTAG_DEVFLAGS, CCN_TT_DTAG, flags); faceinst[len3++] = 0; // end-of-faceinst // prepare CONTENTOBJ with CONTENT len2 = ccnl_ccnb_mkHeader(contentobj, CCN_DTAG_CONTENTOBJ, CCN_TT_DTAG); // contentobj len2 += ccnl_ccnb_mkBlob(contentobj+len2, CCN_DTAG_CONTENT, CCN_TT_DTAG, // content (char*) faceinst, len3); contentobj[len2++] = 0; // end-of-contentobj // add CONTENTOBJ as the final name component len1 += ccnl_ccnb_mkBlob(out1+len1, CCN_DTAG_COMPONENT, CCN_TT_DTAG, // comp (char*) contentobj, len2); #ifdef USE_SIGNATURES if(private_key_path) len += add_signature(out+len, private_key_path, out1, len1); #endif /*USE_SIGNATURES*/ memcpy(out+len, out1, len1); len += len1; out[len++] = 0; // end-of-name out[len++] = 0; // end-of-interest return len; }
int add_ccnl_name(unsigned char *out, char *ccn_path) { char comp[256]; int len = 0, len2 = 0; int h; memset(comp, 0 , 256); len += ccnl_ccnb_mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG); while( (h = split_string(ccn_path + len2, '/', comp)) ) { len2 += h; len += ccnl_ccnb_mkStrBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, comp); memset(comp, 0 , 256); } out[len++] = 0; return len; }