示例#1
0
function loadElectionModules($httpRawPostData, $electionIdPlace)
{
    // getpermission: $reqdecoded['electionId']
    global $dbInfos, $numVerifyBallots, $numSignBallots, $pServerKeys, $serverkey, $numAllBallots, $numPSigsRequiered;
    $dbElections = new DbElections($dbInfos);
    $reqdecoded = json_decode($httpRawPostData, true);
    if ($reqdecoded == null) {
        WrongRequestException::throwException(7040, 'Data in JSON format expected', 'got: ' . $HTTP_RAW_POST_DATA);
    }
    //	if (! isset($electionIdPlace($reqdecoded))) 	WrongRequestException::throwException(7010, 'Election id missing in client request'	, $httpRawPostData);
    if (!is_string($electionIdPlace($reqdecoded))) {
        WrongRequestException::throwException(7050, 'Election id must be a string', 'got: ' . print_r($reqdecoded['electionId'], true));
    }
    // load election config from database by election id
    $completeElectionId = $electionIdPlace($reqdecoded);
    $splittedElectionId = json_decode($completeElectionId);
    if ($splittedElectionId == null) {
        $mainElectionId = $completeElectionId;
    } else {
        $mainElectionId = $splittedElectionId->mainElectionId;
    }
    $elconfig = $dbElections->loadElectionConfigFromElectionId($mainElectionId);
    if (count($elconfig) < 1) {
        WrongRequestException::throwException(7000, 'Election id not found in server database', "ElectionId you sent: " . $reqdecoded['electionId']);
    }
    if (!isset($elconfig['auth'])) {
        WrongRequestException::throwException(7020, 'element auth not found in election config', "ElectionId you sent: " . $reqdecoded['electionId']);
    }
    $auth = LoadModules::laodAuthModule($elconfig['auth']);
    if (isset($elconfig['authConfig'])) {
        $auth->setup($elconfig["electionId"], $elconfig['authConfig']);
    }
    // TODO think about: should Election be any Election or just the blinding module?
    $blinder = LoadModules::loadBlinder($elconfig['blinding'], $elconfig, $auth);
    $blinder->tally = LoadModules::loadTally($elconfig['tally'], $blinder);
    // TODO use a different private key for tallying server
    $blinder->tally->setup($elconfig);
    return $blinder;
}
示例#2
0
     $newconfig["electionTitle"] = $electionconfig['electionTitle'];
 } else {
     $newconfig["electionTitle"] = $electionId;
 }
 //		$authm = LoadModules::laodAuthModule($electionconfig['auth']);
 global $dbInfos;
 $authm = new SharedAuth($dbInfos);
 $authTmp = $authm->handleNewElectionReq($electionId, $electionconfig);
 $newconfig['authConfig'] = $authTmp['authConfig'];
 $newconfig["auth"] = $authTmp['auth'];
 // blinder
 $newconfig['blinding'] = 'blindedVoter';
 global $numVerifyBallots, $numSignBallots, $pServerKeys, $serverkey, $numAllBallots, $numPSigsRequiered;
 $blinder = new BlindedVoter($electionId, $numVerifyBallots, $numSignBallots, $pServerKeys, $serverkey, $numAllBallots, $numPSigsRequiered, $dbInfos, $authm);
 // tally
 $tallym = LoadModules::loadTally($electionconfig['tally'], $blinder);
 $newconfig['tally'] = constant(get_class($tallym) . '::name');
 //		$newconfig['tallyData'] = $tallym->handleNewElectionReq($electionId, $authm, $blinder, $electionconfig['tallyData']);
 // $this->subTally->handleNewElectionReq($req['subTallyData']);
 if (!isset($electionconfig["questions"]) || !is_array($electionconfig["questions"])) {
     WrongRequestException::throwException(2146, 'Request must contain an array of questions', print_r($electionconfig, true));
 }
 foreach ($electionconfig['questions'] as $i => $question) {
     $completeElectionId = json_encode(array('mainElectionId' => $electionId, 'subElectionId' => $question['questionID']));
     //			$subAuthConf = $authm->newSubElection($completeElectionId);
     $subBlinderConf = $blinder->handleNewElectionReq($completeElectionId);
     $subTallyConf = $tallym->handleNewElectionReq($completeElectionId, $authm, $blinder, $question);
     $ret[$i] = array('questionID' => $question['questionID'], 'questionWording' => $question['questionWording'], 'blinderData' => $subBlinderConf, 'tallyData' => $subTallyConf);
     if (isset($question['options'])) {
         $ret[$i]['options'] = $question['options'];
     }