46 CADynamicCascadeConfigurator::CADynamicCascadeConfigurator(
CASignature *a_pSignature,
CAMix *a_pMix)
48 this->m_pSignature = a_pSignature;
49 this->m_pMix = a_pMix;
58 CADynamicCascadeConfigurator::~CADynamicCascadeConfigurator()
60 if(m_proposals != NULL)
62 PROPOSALENTRY *tmpProposal = NULL;
63 PROPOSERENTRY *tmpProposer = NULL;
64 while( (tmpProposal = m_proposals) != NULL )
66 while( (tmpProposer = tmpProposal->proposers) != NULL)
68 tmpProposal->proposers = tmpProposer->next;
69 delete tmpProposer->ski;
70 tmpProposer->ski = NULL;
74 delete tmpProposal->proposal;
75 tmpProposal->proposal = NULL;
77 m_proposals = tmpProposal->next;
100 SINT32 CADynamicCascadeConfigurator::configure()
106 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::configure - Querying %i infoservices...\n", nrAddresses);
111 pglobalOptions->getMixId( bufMixId, mixIdLen );
112 sprintf((
char*)request,
"/reconfigure/%s",bufMixId );
114 for (
UINT32 i = 0; i < nrAddresses; i++)
118 if( sendInfoserviceGetRequest(pAddr, request, &elem) !=
E_SUCCESS)
121 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::configure - Query %i WAS NOT SUCCESSFULL!\n", i);
128 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::configure - Query %i successful, adding proposal now...\n", i);
141 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::configure - Queried all infoservices, will now vote...\n");
144 DOM_Node *newCascade = NULL;
145 UINT8 proposal[1024];
146 if( getMajorityVote( nrAddresses, newCascade, proposal ) ==
E_SUCCESS )
151 if(pglobalOptions->getLastCascadeProposal(buff,
len) ==
E_SUCCESS)
153 if(strcmp((
char*)proposal, (
char*)buff) == 0)
155 CAMsg::printMsg(LOG_DEBUG,
"New proposal == old proposal: SKIPPING\n");
159 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::configure - Vote successful!\n");
160 if(newCascade != NULL)
162 return reconfigureMix(*newCascade, proposal);
167 CAMsg::printMsg(LOG_DEBUG,
"CADynamicCascadeConfigurator::configure - Vote not successful, no majority found, remaining as I am\n");
180 SINT32 CADynamicCascadeConfigurator::getMajorityVote(
UINT32 a_nrInfoServices, DOM_Node *&r_elemMajority,
UINT8* r_strProposal)
183 r_elemMajority = NULL;
184 PROPOSALENTRY *tmp = m_proposals;
187 if(tmp->count >= MIN_MAJORITY_QUOTE(a_nrInfoServices))
190 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::getMajorityVote - Proposal (%s) has %i votes, thats the majority (%i were needed)!\n", tmp->proposal, tmp->count,
191 MIN_MAJORITY_QUOTE(a_nrInfoServices));
193 r_elemMajority = &tmp->elem;
194 if( r_elemMajority != NULL)
196 strcpy((
char*)r_strProposal, (
char*)tmp->proposal);
203 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::getMajorityVote - Proposal (%s) has %i votes, discarting, majority would be (%i)\n", tmp->proposal, tmp->count,
204 MIN_MAJORITY_QUOTE(a_nrInfoServices));
219 SINT32 CADynamicCascadeConfigurator::reconfigureMix(DOM_Node a_elemNewCascade,
UINT8* a_strProposal)
221 DOM_Element mixesElement;
223 DOM_Node child = mixesElement.getFirstChild();
227 pglobalOptions->getMixId(myMixId,
len);
228 char* prevMixId = NULL;
229 char* myNextMixId = NULL;
230 char* myPrevMixId = NULL;
231 bool bFoundMix =
false;
234 if(child.getNodeName().equals(
"Mix") && child.getNodeType() == DOM_Node::ELEMENT_NODE)
236 mixId =
static_cast<const DOM_Element&
>(child).getAttribute(
"id").transcode();
237 if(strcmp(mixId,(
char*)myMixId) == 0)
240 myPrevMixId = prevMixId;
242 else if(bFoundMix ==
true)
249 child = child.getNextSibling();
254 CAMsg::printMsg(LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - Unable to find my mix ID in the majority cascade info\n");
260 if(myPrevMixId == NULL && myNextMixId == NULL)
263 pglobalOptions->resetPrevMix();
264 pglobalOptions->resetNextMix();
265 pglobalOptions->setCascadeProposal(a_strProposal, strlen((
char*)a_strProposal));
266 m_pMix->dynaReconfigure(
false );
269 m_pMix->setReconfiguring(
true);
272 bool typeChanged =
false;
275 if(myPrevMixId == NULL)
278 if(pglobalOptions->isLastMix())
280 CAMsg::printMsg( LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - I am a LastMix and should be reconfigured as a FirstMix! Won't do that!!\n");
283 else if(pglobalOptions->isMiddleMix())
286 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::reconfigureMix - I am a MiddleMix and should be reconfigured as a FirstMix!\n");
291 else if(pglobalOptions->isFirstMix())
294 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::reconfigureMix - CADynamicCascadeConfigurator::reconfigureMix - I am (and will remain) a first mix!\n");
300 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::reconfigureMix - Ugh! I do not have a current mix type! Trying to become a FirstMix nevertheless, but that might fail\n");
308 if( myNextMixId == NULL )
310 if(!pglobalOptions->isLastMix())
312 CAMsg::printMsg( LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - I am NOT a LastMix and should be reconfigured as a LastMix! Won't do that!!\n");
318 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::reconfigureMix - I am (and will remain) a last mix!\n");
324 if(myPrevMixId != NULL && myNextMixId != NULL)
326 if(pglobalOptions->isLastMix())
328 CAMsg::printMsg( LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - I am a LastMix and should be reconfigured as a MiddleMix! Won't do that!!\n");
331 else if(pglobalOptions->isFirstMix())
334 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::reconfigureMix - I am a FirstMix and should be reconfigured as a MiddleMix!\n");
339 else if(pglobalOptions->isMiddleMix())
341 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::reconfigureMix - I am (and will remain) a middle mix!\n");
346 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::reconfigureMix - Ugh! I do not have a current mix type! Trying to become a MiddleMix nevertheless, but that might fail\n");
354 if(myPrevMixId != NULL)
356 CAMsg::printMsg(LOG_INFO,
"CADynamicCascadeConfigurator::reconfigureMix - Asking InfoService about previous mix ...\n");
358 sprintf(buf,
"/mixinfo/%s", (
char*)myPrevMixId);
361 ret = sendRandomInfoserviceGetRequest( (
UINT8*)buf, &result);
364 CAMsg::printMsg(LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - Error retrieving mix info from InfoService!\n");
367 DOM_Document doc = result.getOwnerDocument();
368 ret = pglobalOptions->setPrevMix( doc );
371 CAMsg::printMsg(LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - Error setting next mix info!\n");
372 pglobalOptions->resetPrevMix();
378 if(pglobalOptions->resetPrevMix() !=
E_SUCCESS)
380 CAMsg::printMsg( LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - Unable to reset prev mix information\n");
386 if(myNextMixId != NULL)
388 CAMsg::printMsg(LOG_INFO,
"CADynamicCascadeConfigurator::reconfigureMix - Asking InfoService about next mix ...\n");
390 sprintf(buf,
"/mixinfo/%s", (
char*)myNextMixId);
392 if( sendRandomInfoserviceGetRequest( (
UINT8*)buf, &result) !=
E_SUCCESS )
394 CAMsg::printMsg(LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - Error retrieving mix info from InfoService!\n");
397 DOM_Document doc = result.getOwnerDocument();
398 if(pglobalOptions->setNextMix( doc ) !=
E_SUCCESS)
400 CAMsg::printMsg(LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - Error setting next mix info!\n");
406 if(pglobalOptions->resetNextMix() !=
E_SUCCESS)
408 CAMsg::printMsg( LOG_ERR,
"CADynamicCascadeConfigurator::reconfigureMix - Unable to reset next mix information\n");
413 pglobalOptions->setCascadeProposal(a_strProposal, strlen((
char*)a_strProposal));
419 CAMsg::printMsg( LOG_DEBUG,
"CADynamicCascadeConfigurator::reconfigureMix - Calling dynaReconfigure on the mix, grab a hold of something!\n");
421 m_pMix->dynaReconfigure( typeChanged );
436 SINT32 CADynamicCascadeConfigurator::addProposal(DOM_Element a_elem)
446 DOM_Element mixesElement;
448 DOM_Node child = mixesElement.getFirstChild();
450 char* tmpProposal = NULL;
453 if(child.getNodeName().equals(
"Mix") && child.getNodeType() == DOM_Node::ELEMENT_NODE)
455 mixId =
static_cast<const DOM_Element&
>(child).getAttribute(
"id").transcode();
456 if(tmpProposal == NULL)
458 tmpProposal =
new char[strlen(mixId)+1];
459 strncpy(tmpProposal, mixId, strlen(mixId)+1);
463 char *tmp =
new char[strlen(tmpProposal)+1];
464 strncpy(tmp, tmpProposal, strlen(tmpProposal)+1);
466 tmpProposal =
new char[ strlen(mixId) + strlen(tmp) + 1];
467 strncpy(tmpProposal, tmp, strlen(tmp) + 1);
470 strcat(tmpProposal, mixId);
473 child = child.getNextSibling();
475 UINT8* proposal = NULL;
477 proposal =
new UINT8[strlen(tmpProposal) + 1];
478 memcpy(proposal, tmpProposal, strlen(tmpProposal) + 1);
479 lenProposal = strlen(tmpProposal);
488 DOM_Element elemSig, elemCert;
495 UINT8 proposerSki[60];
496 UINT32 lenProposerSki = 60;
507 PROPOSALENTRY *tmpEntry;
508 if( m_proposals == NULL )
510 m_proposals = createProposal( proposal, lenProposal, proposerSki, lenProposerSki, &a_elem );
518 tmpEntry=m_proposals;
521 if(memcmp(tmpEntry->proposal, proposal, lenProposal) == 0)
523 PROPOSERENTRY *proposer = tmpEntry->proposers;
527 if(memcmp(proposer->ski, proposerSki, lenProposerSki) == 0)
534 if(proposer->next == NULL)
536 proposer = proposer->next;
540 PROPOSERENTRY *tmpProposer =
new PROPOSERENTRY;
541 tmpProposer->next = NULL;
542 tmpProposer->ski =
new UINT8[lenProposerSki+1];
543 memcpy(tmpProposer->ski, proposerSki, lenProposerSki+1);
544 proposer->next = tmpProposer;
553 if(tmpEntry->next == NULL)
555 tmpEntry = tmpEntry->next;
559 tmpEntry->next = createProposal( proposal, lenProposal, proposerSki, lenProposerSki, &a_elem );
578 PROPOSALENTRY *CADynamicCascadeConfigurator::createProposal(
UINT8* a_strProposal,
UINT32 a_lenProposal,
UINT8 *a_strProposer,
UINT32 a_lenProposer, DOM_Element *a_elem)
580 PROPOSALENTRY *entry =
new PROPOSALENTRY;
581 entry->proposal =
new UINT8[a_lenProposal+1];
582 memcpy(entry->proposal, a_strProposal, a_lenProposal+1);
585 PROPOSERENTRY *proposer =
new PROPOSERENTRY;
586 proposer->next = NULL;
587 proposer->ski =
new UINT8[a_lenProposer+1];
588 memcpy(proposer->ski, a_strProposer, a_lenProposer+1);
589 entry->proposers = proposer;
590 entry->elem = a_elem->cloneNode(
true );
#define CERT_X509CERTIFICATE
SINT32 getDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
SINT32 getSubjectKeyIdentifier(UINT8 *r_ski, UINT32 *r_skiLen)
LERNGRUPPE Accessor method for the subjectKeyIdentifier (SKI) extension stored in this certificate.
static CACertificate * decode(const UINT8 *const buff, UINT32 bufflen, UINT32 type, const char *const passwd=NULL)
Extracts a certificate from an encoded (DER,XML) form.
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
This class represents a socket address for Internet (IP) connections.