Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
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;
}