def __handle_valid(self, root, vote_file): code = root.split('/').pop() user_key = htscommon.get_user_key(code) fn = self._reg.path(user_key + [vote_file]) bdoc = bdocpythonutils.BDocContainer() bdoc.load(fn) profile = bdocpythonutils.ManifestProfile('TM') bdoc.validate(profile) haal = bdoc.documents["%s.evote" % self._elid] voter = htscommon.get_votefile_voter(vote_file) b64haal = base64.b64encode(haal).strip() self._log3.log_info(tyyp=3, haal_rasi=ksum.votehash(haal), jaoskond=voter['jaoskond'], jaoskond_omavalitsus=voter['jaoskond_omavalitsus'], ringkond=voter['ringkond'], ringkond_omavalitsus=voter['ringkond_omavalitsus'], isikukood=code) return [ voter['jaoskond_omavalitsus'], voter['jaoskond'], voter['ringkond_omavalitsus'], voter['ringkond'], b64haal ]
def process_bdoc(self, bdocfile): config = bdocconfig.BDocConfig() config.load(Election().get_bdoc_conf()) self.__bdoc = bdocpythonutils.BDocContainer() self.__bdoc.load(bdocfile) profile = bdocpythonutils.ManifestProfile('TM', \ 'application/octet-stream') self.__bdoc.validate(profile) if len(self.__bdoc.signatures) != 1: return False, "BDoc sisaldab rohkem kui ühte allkirja" verifier = bdocpython.BDocVerifier() config.populate(verifier) for el in self.__bdoc.documents: verifier.setDocument(self.__bdoc.documents[el], el) _, sig_content = self.__bdoc.signatures.popitem() res = verifier.verifyTMOffline(sig_content) if res.result: return True, res.subject return False, res.error
def __load_bdoc(self, elid): voter_key = htscommon.get_user_key(self._voter_code) sreg = Election().get_sub_reg(elid) for votefile in sreg.list_keys(voter_key): if htscommon.VALID_VOTE_PATTERN.match(votefile): bdoc = bdocpythonutils.BDocContainer() bdoc.load(sreg.path(voter_key + [votefile])) bdoc.validate(bdocpythonutils.ManifestProfile("TM")) self._voter = htscommon.get_votefile_voter(votefile) break if not bdoc: evlog.log_error("No valid BDOC found for voter %s using vote ID %s" % \ (self._voter, self._vote_id)) raise HTSVerifyException, evcommon.VERIFY_ERROR return bdoc
def get_vote(zipfn): bdoc = None inzip = None try: try: inzip = zipfile.ZipFile(zipfn, 'r') bdocdata = inzip.read(htscommon.ZIP_BDOCFILE) bdoc = bdocpythonutils.BDocContainer() bdoc.load_bytes(bdocdata) profile = bdocpythonutils.ManifestProfile('TM') bdoc.validate(profile) except: bdoc = None evlog.log_exception() finally: if inzip: inzip.close() return bdoc
def __tyhista_korduv_haal(self, code, haale_rasi): user_key = htscommon.get_user_key(code) if not self._reg.check(user_key): return flist = self._reg.list_keys(user_key) for elem in flist: if htscommon.VALID_VOTE_PATTERN.match(elem): rev_name = htscommon.change_votefile_name(\ elem, htscommon.BAUTOREVOKED) old_name = self._reg.path(user_key + [elem]) new_name = self._reg.path(user_key + [rev_name]) bdoc = bdocpythonutils.BDocContainer() bdoc.load(old_name) profile = bdocpythonutils.ManifestProfile('TM') bdoc.validate(profile) vote = bdoc.documents["%s.evote" % self._elid] voter = htscommon.get_votefile_voter(elem) vote_time = htscommon.get_votefile_time(elem) # logimine self._log2.log_info( tyyp=2, haal_rasi=ksum.votehash(vote), jaoskond=voter['jaoskond'], jaoskond_omavalitsus=voter['jaoskond_omavalitsus'], ringkond=voter['ringkond'], ringkond_omavalitsus=voter['ringkond_omavalitsus'], isikukood=code, pohjus='korduv e-hääl: ' + haale_rasi) self._revlog.log_info(tegevus='korduv e-hääl', isikukood=code, nimi=voter['nimi'], timestamp=vote_time, operaator='', pohjus=haale_rasi) os.rename(old_name, new_name)
def analyze_vote(bdocdata, config): bdoc = bdocpythonutils.BDocContainer() bdoc.load_bytes(bdocdata) profile = bdocpythonutils.ManifestProfile('TM') bdoc.validate(profile) _doc_count = len(bdoc.documents) if _doc_count == 0: raise Exception("BDoc ei sisalda ühtegi andmefaili") if len(bdoc.signatures) != 1: raise Exception("BDoc sisaldab rohkem kui ühte allkirja") verifier = bdocpython.BDocVerifier() config.populate(verifier) for el in bdoc.documents: verifier.setDocument(bdoc.documents[el], el) _, sig_content = bdoc.signatures.popitem() return verifier.verifyTMOffline(sig_content)
def kontrolli_volitusi(elid, bdocfile, volitus, config): bdoc = bdocpythonutils.BDocContainer() bdoc.load(bdocfile) profile = bdocpythonutils.ManifestProfile('TM', 'application/octet-stream') bdoc.validate(profile) _doc_count = len(bdoc.documents) if _doc_count == 0: raise Exception, "BDoc ei sisalda ühtegi andmefaili" if _doc_count != 1: raise Exception, "BDoc sisaldab %d andmefaili" % _doc_count if len(bdoc.signatures) != 1: raise Exception, "BDoc sisaldab rohkem kui ühte allkirja" verifier = bdocpython.BDocVerifier() config.populate(verifier) doc_fn, doc_content = bdoc.documents.popitem() verifier.setDocument(doc_content, doc_fn) _signercode = None _, sig_content = bdoc.signatures.popitem() res = verifier.verifyTMOffline(sig_content) if res.result: _signercode = get_personal_code(res.subject) else: raise Exception, "Invalid signature %s" % res.error _rights = Rights(elid) if _rights.has(_signercode, volitus): return True, '', _signercode return False, \ "Isikul koodiga %s puuduvad volitused " \ "antud operatsiooni sooritamiseks" \ % _signercode, _signercode
def __handle_userrevoked(self, root, vote_file): code = root.split('/').pop() user_key = htscommon.get_user_key(code) fn = self._reg.path(user_key + [vote_file]) bdoc = bdocpythonutils.BDocContainer() bdoc.load(fn) profile = bdocpythonutils.ManifestProfile('TM') bdoc.validate(profile) haal = bdoc.documents["%s.evote" % self._elid] voter = htscommon.get_votefile_voter(vote_file) pohjus = self._reg.read_string_value(user_key, 'reason').value self._log2.log_info(tyyp=2, haal_rasi=ksum.votehash(haal), jaoskond=voter['jaoskond'], jaoskond_omavalitsus=voter['jaoskond_omavalitsus'], ringkond=voter['ringkond'], ringkond_omavalitsus=voter['ringkond_omavalitsus'], isikukood=code, pohjus=pohjus)
exit(1) print 'Expecting content type:', contentType with file(sys.argv[2]) as f: zipbytes = f.read() bdocpython.initialize() config = bdocconfig.BDocConfig() bdoc = bdocpythonutils.BDocContainer() bdoc.load_bytes(zipbytes) profile_type = 'TM' if method == 'tm' else 'BES' bdoc.validate( bdocpythonutils.ManifestProfile(profile_type, datatype=contentType)) sigfiles = bdoc.signatures.keys() if len(sigfiles) == 0: raise Exception, "BDoc ei sisalda ühtegi allkirja" sigfiles = bdoc.signatures.keys() if len(sigfiles) != 1: raise Exception, "BDoc sisaldab rohkem kui ühte allkirja" config.load(conf_dir) verifier = bdocpython.BDocVerifier() config.populate(verifier) verifier.setSchemaDir(etc + '/schema') certDir = etc + '/certs'