void SecurityManager::onRepositoryData(Event *e) { RepositoryEntryRef re; if (!e->getData()) { signalIsReadyForStartup(); return; } HAGGLE_DBG("Got repository callback\n"); DataStoreQueryResult *qr = static_cast < DataStoreQueryResult * >(e->getData()); if (qr->countRepositoryEntries() == 0) { HAGGLE_DBG("No repository entries, generating new certificate and keypair\n"); helper->addTask(new SecurityTask(SECURITY_TASK_GENERATE_CERTIFICATE)); // Delay signalling that we are ready for startup until we get the // task result indicating our certificate is ready. delete qr; return; } while ((re = qr->detachFirstRepositoryEntry())) { if (strcmp(re->getKey(), "privkey") == 0) { // Just to make sure if (privKey) RSA_free(privKey); privKey = stringToRSAKey(re->getValueStr(), KEY_TYPE_PRIVATE); HAGGLE_DBG("Read my own private key from repository\n"); } else { CertificateRef c = Certificate::fromPEM(re->getValueStr()); if (c) { if (c->getSubject() == kernel->getThisNode()->getIdStr()) myCert = c; storeCertificate(c); HAGGLE_DBG("Read certificate for subject '%s' from repository\n", c->getSubject().c_str()); } else { HAGGLE_ERR("Could not read certificate from repository\n"); } } } delete qr; signalIsReadyForStartup(); }
void DebugManager::onFindRepositoryKey(Event *e) { if (!e || !e->hasData()) return; DataStoreQueryResult *qr = static_cast < DataStoreQueryResult * >(e->getData()); RepositoryEntryRef re = qr->detachFirstRepositoryEntry(); if (!re) { // No repository entry: no data object. DataObjectRef dObj; // Name the log so that the files are more easily readable on the // machine that receives them: char filename[128]; sprintf(filename, "log-%s.txt", kernel->getThisNode()->getIdStr()); // Create data object: // Empty at first: dObj = DataObject::create(LogTrace::ltrace.getFile(), filename); if (!dObj) { HAGGLE_ERR("Could not create data object\n"); return; } // Add log file attribute: Attribute a("Log file","Trace"); dObj->addAttribute(a); // Add node id of local node, to make sure that two logs from different // nodes don't clash: Attribute b("Node id", kernel->getThisNode()->getIdStr()); dObj->addAttribute(b); // Insert data object: kernel->getDataStore()->insertDataObject(dObj); // Insert a repository entry to show the data object exists: kernel->getDataStore()->insertRepository(new RepositoryEntry("DebugManager", "has saved log file data object", "yes")); } delete qr; }
void DataManager::onGetLocalBF(Event *e) { if (!e || !e->hasData()) return; DataStoreQueryResult *qr = static_cast < DataStoreQueryResult * >(e->getData()); HAGGLE_DBG("Got repository callback\n"); // Are there any repository entries? if (qr->countRepositoryEntries() != 0) { RepositoryEntryRef re; // Then this is most likely the local bloomfilter: re = qr->detachFirstRepositoryEntry(); // Was there a repository entry? => was this really what we expected? if (re) { HAGGLE_DBG("Retrieved bloomfilter from data store\n"); // Yes: Bloomfilter *tmpBF = Bloomfilter::create(re->getValueBlob(), re->getValueLen()); if (tmpBF) { if (localBF) delete localBF; localBF = tmpBF; kernel->getThisNode()->setBloomfilter(*localBF, setCreateTimeOnBloomfilterUpdate); } } RepositoryEntryRef lbf = new RepositoryEntry("DataManager", "Local Bloomfilter"); kernel->getDataStore()->deleteRepository(lbf); } else { // Don't do anything... for now. } delete qr; }