/// Function just to make setting the encryption method simpler from Python WINEXPORT void cryptcurve25519_set_encryption_method(void) { cryptframe_set_encryption_method(cryptcurve25519_new_generic); }
/// Routine to pretend to be the initial CMA void fakecma_startup(AuthListener* auth, FrameSet* ifs, NetAddr* nanoaddr) { FrameSet* pkt; NetGSource* netpkt = auth->baseclass.transport; char * nanostr = nanoaddr->baseclass.toString(nanoaddr); GSList* thisgsf; const char * keyid = NULL; (void)ifs; g_message("CMA received startup message from nanoprobe at address %s/%d." , nanostr, nanoaddr->port(nanoaddr)); g_free(nanostr); nanostr = NULL; check_JSON(ifs); netpkt->_netio->addalias(netpkt->_netio, nanoaddr, destaddr); // Set up our crypto... cryptframe_set_dest_key_id(nanoaddr, cryptframe_get_signing_key_id()); cryptframe_set_dest_key_id(destaddr, cryptframe_get_signing_key_id()); cryptframe_associate_identity(CMA_IDENTITY_NAME, cryptframe_get_signing_key_id()); cryptframe_set_encryption_method(cryptcurve25519_new_generic); for (thisgsf = ifs->framelist; thisgsf; thisgsf=thisgsf->next) { Frame* thisframe = CASTTOCLASS(Frame, thisgsf->data); if (thisframe->type == FRAMETYPE_KEYID) { CstringFrame* csf = CASTTOCLASS(CstringFrame, thisframe); keyid = (const char *)csf->baseclass.value; }else if (keyid && thisframe->type == FRAMETYPE_PUBKEYCURVE25519) { cryptcurve25519_save_public_key(keyid, thisframe->value , thisframe->length); } } // Send the configuration data to our new "client" pkt = create_setconfig(nanoconfig); netpkt->_netio->sendareliablefs(netpkt->_netio, nanoaddr, DEFAULT_FSP_QID, pkt); UNREF(pkt); // Now tell them to send/expect heartbeats to various places pkt = create_sendexpecthb(auth->baseclass.config, FRAMESETTYPE_SENDEXPECTHB, destaddr, 1); netpkt->_netio->sendareliablefs(netpkt->_netio, nanoaddr, DEFAULT_FSP_QID, pkt); UNREF(pkt); { const char * monopjson[] = { START, MONITOR, STOP}; unsigned j; // Create a frameset for a few resource operations pkt = frameset_new(FRAMESETTYPE_DORSCOP); for (j=0; j < DIMOF(monopjson); j++) { CstringFrame* csf = cstringframe_new(FRAMETYPE_RSCJSON,0); csf->baseclass.setvalue(&csf->baseclass, g_strdup(monopjson[j]) , strlen(monopjson[j])+1, g_free); frameset_append_frame(pkt, &csf->baseclass); UNREF2(csf); } netpkt->_netio->sendareliablefs(netpkt->_netio, nanoaddr, DEFAULT_FSP_QID, pkt); UNREF(pkt); } { const char * discoverjson[] = {SWITCHDISCOVER, ARPDISCOVER}; const char * discoverinstnm[] = {SWINSTNM, ARPINSTNM}; unsigned j; // Create a frameset for a few discovery operations pkt = frameset_new(FRAMESETTYPE_DODISCOVER); for (j=0; j < DIMOF(discoverjson); j++) { CstringFrame* csf = cstringframe_new(FRAMETYPE_DISCJSON,0); CstringFrame* inst = cstringframe_new(FRAMETYPE_DISCNAME,0); fprintf(stderr, "Creating discovery frameset: %s: %s\n" , discoverinstnm[j] , discoverjson[j]); inst->baseclass.setvalue(&inst->baseclass, g_strdup(discoverjson[j]) , strlen(discoverjson[j])+1, g_free); frameset_append_frame(pkt, &inst->baseclass); UNREF2(inst); csf->baseclass.setvalue(&csf->baseclass, g_strdup(discoverjson[j]) , strlen(discoverjson[j])+1, g_free); frameset_append_frame(pkt, &csf->baseclass); UNREF2(csf); } netpkt->_netio->sendareliablefs(netpkt->_netio, nanoaddr, DEFAULT_FSP_QID, pkt); UNREF(pkt); } pkt = frameset_new(FRAMESETTYPE_ACKSTARTUP); netpkt->_netio->sendareliablefs(netpkt->_netio, nanoaddr, DEFAULT_FSP_QID, pkt); UNREF(pkt); g_info("ACKSTARTUP packet queued to send"); }