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; }
*/ if (isset($HTTP_RAW_POST_DATA)) { $electionconfigStr = $HTTP_RAW_POST_DATA; } if (isset($electionconfigStr)) { $newconfig = array(); try { $electionconfig = json_decode($electionconfigStr, true); // TODO verify auth if (isset($electionconfig) && isset($electionconfig['electionId']) && is_string($electionconfig['electionId']) && isset($electionconfig['auth']) && is_string($electionconfig['auth']) && isset($electionconfig['authData'])) { $electionId = $electionconfig['electionId']; } else { WrongRequestException::throwException(2100, 'Missing election Id or authorisation module name or it is not a string or auth data ist missing', "complete request received:\n" . $electionconfigStr); } $db = new DbElections($dbInfos); $alreadyGiven = $db->loadElectionConfigFromElectionId($electionId); if (count($alreadyGiven) > 0) { WrongRequestException::throwException(2120, 'This election id is already used', $electionId); } // create public election config and secret election config $newconfig['electionId'] = $electionId; if (isset($electionconfig['electionTitle'])) { $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'];