Exemplo n.º 1
0
def replace_candidates(elid, valik_f):

    """Valikute nimekirja välja vahetamine"""

    def do_replace(cr):
        try:
            cr.elid = elid

            if not cr.prepare('REPLACE CHOICES'):
                return False

            if not cr.check_choices_file(valik_f):
                return False

            if not cr.do_it():
                return False
            return True

        except: # pylint: disable=W0702
            print 'Viga valikute nimekirja välja vahetamisel'
            print exception_msg.trace()
            return False


    bdocpython.initialize()
    try:
        my_cr = ChoicesReplace()
        if do_replace(my_cr):
            my_cr.success()
            return True
        else:
            my_cr.failure()
            return False
    finally:
        bdocpython.terminate()
Exemplo n.º 2
0
def replace_candidates(elid, valik_f):
    """Valikute nimekirja välja vahetamine"""
    def do_replace(cr):
        try:
            cr.elid = elid

            if not cr.prepare('REPLACE CHOICES'):
                return False

            if not cr.check_choices_file(valik_f):
                return False

            if not cr.do_it():
                return False
            return True

        except:  # pylint: disable=W0702
            print 'Viga valikute nimekirja välja vahetamisel'
            print exception_msg.trace()
            return False

    bdocpython.initialize()
    try:
        my_cr = ChoicesReplace()
        if do_replace(my_cr):
            my_cr.success()
            return True
        else:
            my_cr.failure()
            return False
    finally:
        bdocpython.terminate()
Exemplo n.º 3
0
    def tyhista_ennista(self, filename):

        tmp_tyhis_f = None

        try:

            bdocpython.initialize()
            bconf = bdocpythonutils.BDocConfig()
            bconf.load(Election().get_bdoc_conf())

            result = regrights.kontrolli_volitusi(self._elid, filename, "TYHIS", bconf)

            if not result[0]:
                self._errmsg = "Tühistus-/ennistusnimekirja volituste " "kontroll andis negatiivse tulemuse: "
                self._errmsg += result[1]
                raise Exception(self._errmsg)
            _signercode = result[2]

            tmp_tyhis_f = bdocpythonutils.get_doc_content_file(filename)

            rl = revocationlists.RevocationList()
            rl.attach_elid(self._elid)
            rl.attach_logger(evlog.AppLog())
            if not rl.check_format(tmp_tyhis_f, "Kontrollin tühistus-/ennistusnimekirja: "):
                self._errmsg = "Vigase formaadiga tühistus-/ennistusnimekiri"
                raise Exception(self._errmsg)

            g_l = None
            b_l = None
            act = ""

            report = []

            if rl.revoke:
                act = "tühistamine"
                g_l, b_l = self.__tyhista_haaled(rl.rev_list, _signercode)
            else:
                act = "ennistamine"
                g_l, b_l = self.__ennista_haaled(rl.rev_list, _signercode)

            for el in b_l:
                el.append(act + " nurjus")
                report.append(el)

            for el in g_l:
                el.append(act + " õnnestus")
                report.append(el)

            fn = self._reg.path(["hts", "output", evcommon.REVREPORT_FILE])
            self.__save_list(report, fn)
            ksum.store(fn)
            return len(rl.rev_list), len(g_l), len(b_l)

        finally:

            if tmp_tyhis_f != None:
                os.unlink(tmp_tyhis_f)
Exemplo n.º 4
0
    def check_vote(self, mobid):

        try:
            bdocpython.initialize()
            conf = bdocconfig.BDocConfig()
            conf.load(Election().get_bdoc_conf())

            alines = []
            elines = []
            if mobid:
                alines, elines = regrights.analyze_signature_for_log(self._decoded_vote)
            else:
                alines, elines = regrights.analyze_vote_for_log(self._decoded_vote)

            for el in alines:
                evlog.log(el)

            for el in elines:
                evlog.log_error(el)

            res = None
            if mobid:
                res = regrights.check_vote_hes_mobid(self._decoded_vote, conf)
            else:
                res = regrights.check_vote_hes(self._decoded_vote, conf)

            if not res.result:
                self.error.log_msg = res.error
                if self.error.user_msg == "":
                    self.error.user_msg = evmessage.EV_ERRORS.TEHNILINE_VIGA
                self.error.user_code = evcommon.EVOTE_ERROR

                if not res.cert_is_valid:
                    self.error.user_msg = evmessage.EV_ERRORS.SERTIFIKAAT_ON_AEGUNUD
                    self.error.user_code = evcommon.EVOTE_CERT_ERROR

                return False

            ik_ver = regrights.get_personal_code(res.subject)
            if self._ik != ik_ver:
                self.error.log_msg = "Autentija (%s) ja allkirjastaja (%s) erinevad" % (self._ik, ik_ver)
                self.error.user_msg = evmessage.EV_ERRORS.TEHNILINE_VIGA
                self.error.user_code = evcommon.EVOTE_ERROR
                return False

            return True

        except:
            self.error.user_msg = evmessage.EV_ERRORS.TEHNILINE_VIGA
            self.error.user_code = evcommon.EVOTE_ERROR
            self.error.log_msg = exception_msg.trace()

        finally:
            bdocpython.terminate()

        return False
Exemplo n.º 5
0
    def check_vote(self, mobid):

        try:
            bdocpython.initialize()
            conf = bdocpythonutils.BDocConfig()
            conf.load(Election().get_bdoc_conf())

            res = None
            if mobid:
                res = regrights.check_vote_hes_mobid(self._decoded_vote, conf)
            else:
                res = regrights.check_vote_hes(self._decoded_vote, conf)

            if not res.result:
                self.error.log_msg = res.error
                if self.error.user_msg == '':
                    self.error.user_msg = evmessage.EvMessage().\
                        get_str("TEHNILINE_VIGA_HAALE_VERIFITSEERIMISEL", \
                            evstrings.TEHNILINE_VIGA_HAALE_VERIFITSEERIMISEL)
                self.error.user_code = evcommon.EVOTE_ERROR

                if not res.cert_is_valid:
                    self.error.user_msg = evmessage.EvMessage().\
                        get_str("SERTIFIKAAT_ON_AEGUNUD", \
                            evstrings.SERTIFIKAAT_ON_AEGUNUD)
                    self.error.user_code = evcommon.EVOTE_CERT_ERROR

                return False

            ik_ver = regrights.get_personal_code(res.subject)
            if self._ik != ik_ver:
                self.error.log_msg = \
                    'Autentija (%s) ja allkirjastaja (%s) erinevad' % \
                        (self._ik, ik_ver)
                self.error.user_msg = \
                    evmessage.EvMessage().get_str("ERINEV_KASUTAJA", \
                        evstrings.ERINEV_KASUTAJA)
                self.error.user_code = evcommon.EVOTE_ERROR
                return False

            return True

        except:
            self.error.user_msg = evmessage.EvMessage().\
                get_str("TEHNILINE_VIGA_HAALE_VERIFITSEERIMISEL", \
                    evstrings.TEHNILINE_VIGA_HAALE_VERIFITSEERIMISEL)
            self.error.user_code = evcommon.EVOTE_ERROR
            self.error.log_msg = exception_msg.trace()

        finally:
            bdocpython.terminate()

        return False
Exemplo n.º 6
0
    def check_vote(self, mobid):

        try:
            bdocpython.initialize()
            conf = bdocpythonutils.BDocConfig()
            conf.load(Election().get_bdoc_conf())

            res = None
            if mobid:
                res = regrights.check_vote_hes_mobid(self._decoded_vote, conf)
            else:
                res = regrights.check_vote_hes(self._decoded_vote, conf)

            if not res.result:
                self.error.log_msg = res.error
                if self.error.user_msg == '':
                    self.error.user_msg = evmessage.EvMessage().\
                        get_str("TEHNILINE_VIGA_HAALE_VERIFITSEERIMISEL", \
                            evstrings.TEHNILINE_VIGA_HAALE_VERIFITSEERIMISEL)
                self.error.user_code = evcommon.EVOTE_ERROR

                if not res.cert_is_valid:
                    self.error.user_msg = evmessage.EvMessage().\
                        get_str("SERTIFIKAAT_ON_AEGUNUD", \
                            evstrings.SERTIFIKAAT_ON_AEGUNUD)
                    self.error.user_code = evcommon.EVOTE_CERT_ERROR

                return False

            ik_ver = regrights.get_personal_code(res.subject)
            if self._ik != ik_ver:
                self.error.log_msg = \
                    'Autentija (%s) ja allkirjastaja (%s) erinevad' % \
                        (self._ik, ik_ver)
                self.error.user_msg = \
                    evmessage.EvMessage().get_str("ERINEV_KASUTAJA", \
                        evstrings.ERINEV_KASUTAJA)
                self.error.user_code = evcommon.EVOTE_ERROR
                return False

            return True

        except:
            self.error.user_msg = evmessage.EvMessage().\
                get_str("TEHNILINE_VIGA_HAALE_VERIFITSEERIMISEL", \
                    evstrings.TEHNILINE_VIGA_HAALE_VERIFITSEERIMISEL)
            self.error.user_code = evcommon.EVOTE_ERROR
            self.error.log_msg = exception_msg.trace()

        finally:
            bdocpython.terminate()

        return False
Exemplo n.º 7
0
def do_configure(apptype,
                 elid,
                 jaosk_f=None,
                 voter_f=None,
                 valik_f=None,
                 voter_public_key_f=None):

    def do_conf(cc):
        # pylint: disable-msg=W0702
        try:
            cc.elid = elid
            cc.jaosk_f = jaosk_f
            cc.voter_f = voter_f
            cc.valik_f = valik_f
            cc.voter_public_key_f = voter_public_key_f

            if not cc.prepare('CONFIGURATOR', apptype):
                return False

            if jaosk_f:
                if not cc.check_districts_file():
                    return False

            if valik_f:
                if not cc.check_choices_file():
                    return False

            if voter_f and voter_public_key_f:
                if not cc.check_voters_file():
                    return False

            if not cc.do_it():
                return False
            return True

        except:
            print 'Viga valimiste failide laadimisel'
            print exception_msg.trace()
            return False

    bdocpython.initialize()

    try:
        my_cc = ConfCreator()
        if do_conf(my_cc):
            my_cc.success()
            return True
        else:
            my_cc.failure()
            return False
    finally:
        bdocpython.terminate()
Exemplo n.º 8
0
def do_configure(apptype,
                 elid,
                 jaosk_f=None,
                 voter_f=None,
                 valik_f=None,
                 voter_public_key_f=None):
    def do_conf(cc):
        # pylint: disable-msg=W0702
        try:
            cc.elid = elid
            cc.jaosk_f = jaosk_f
            cc.voter_f = voter_f
            cc.valik_f = valik_f
            cc.voter_public_key_f = voter_public_key_f

            if not cc.prepare('CONFIGURATOR', apptype):
                return False

            if jaosk_f:
                if not cc.check_districts_file():
                    return False

            if valik_f:
                if not cc.check_choices_file():
                    return False

            if voter_f and voter_public_key_f:
                if not cc.check_voters_file():
                    return False

            if not cc.do_it():
                return False
            return True

        except:
            print 'Viga valimiste failide laadimisel'
            print exception_msg.trace()
            return False

    bdocpython.initialize()

    try:
        my_cc = ConfCreator()
        if do_conf(my_cc):
            my_cc.success()
            return True
        else:
            my_cc.failure()
            return False
    finally:
        bdocpython.terminate()
Exemplo n.º 9
0
    def check_vote(self, mobid):

        try:
            bdocpython.initialize()
            conf = bdocconfig.BDocConfig()
            conf.load(Election().get_bdoc_conf())

            alines = []
            elines = []
            if mobid:
                alines, elines = \
                    regrights.analyze_signature_for_log(self._decoded_vote)
            else:
                alines, elines = \
                    regrights.analyze_vote_for_log(self._decoded_vote)

            for el in alines:
                evlog.log(el)

            for el in elines:
                evlog.log_error(el)

            res = None
            if mobid:
                res = regrights.check_vote_hes_mobid(self._decoded_vote, conf)
            else:
                res = regrights.check_vote_hes(self._decoded_vote, conf)

            if not res.result:
                self.error.log_msg = res.error
                if self.error.user_msg == '':
                    self.error.user_msg = evmessage.EV_ERRORS.TEHNILINE_VIGA
                self.error.user_code = evcommon.EVOTE_ERROR

                if not res.cert_is_valid:
                    self.error.user_msg =\
                        evmessage.EV_ERRORS.SERTIFIKAAT_ON_AEGUNUD
                    self.error.user_code = evcommon.EVOTE_CERT_ERROR

                return False

            ik_ver = regrights.get_personal_code(res.subject)
            if self._ik != ik_ver:
                self.error.log_msg = \
                    'Autentija (%s) ja allkirjastaja (%s) erinevad' % \
                    (self._ik, ik_ver)
                self.error.user_msg = \
                    evmessage.EV_ERRORS.TEHNILINE_VIGA
                self.error.user_code = evcommon.EVOTE_ERROR
                return False

            return True

        except:
            self.error.user_msg = evmessage.EV_ERRORS.TEHNILINE_VIGA
            self.error.user_code = evcommon.EVOTE_ERROR
            self.error.log_msg = exception_msg.trace()

        finally:
            bdocpython.terminate()

        return False
Exemplo n.º 10
0
 def __init__(self):
     bdocpython.initialize()
Exemplo n.º 11
0
                manage_rights(el, e_config[el])
                config_common.config_hlr(el, \
                        "%s/%s" % (self.__dir, e_config[el]['districts']), \
                        "%s/%s" % (self.__dir, e_config[el]['choices']))


def usage():
    print "Invalid arguments"
    print "%s verify <bdoc>" % sys.argv[0]
    print "%s install <bdoc>" % sys.argv[0]
    sys.exit(1)


if __name__ == "__main__":

    bdocpython.initialize()
    if len(sys.argv) != 3:
        usage()

    typ = sys.argv[1]
    if not typ in ['install', 'verify']:
        usage()

    inst = ElectionInstaller()
    ret = 1

    if typ == 'verify':
        res, name = inst.process_bdoc(sys.argv[2])
        if res:
            ret = 0
            print 'Allkiri korrektne'
Exemplo n.º 12
0
        usage()

    elid = sys.argv[1]
    infile = sys.argv[2]

    p_time = "00:00:00"
    evlog.AppLog().set_app('HTS', elid)

    tmp_f = None
    try:
        try:
            s_time = time.time()
            evlog.AppLog().log(
                'Tühistus-/ennistusnimekirja laadimine: ALGUS')

            bdocpython.initialize()
            bconf = bdocconfig.BDocConfig()
            bconf.load(election.Election().get_bdoc_conf())
            result = regrights.kontrolli_volitusi(elid, infile, 'TYHIS', bconf)
            if not result[0]:
                errmsg = 'Tühistus-/ennistusnimekirja volituste ' \
                               'kontroll andis negatiivse tulemuse: '
                errmsg += result[1]
                raise Exception(errmsg)
            _signercode = result[2]

            tmp_f = bdocpythonutils.get_doc_content_file(infile)

            all_, res_a, res_u = restore_revoke(elid, tmp_f, _signercode)
            p_time = time.strftime("%H:%M:%S",
                    time.gmtime(long(time.time() - s_time)))
Exemplo n.º 13
0
    def tyhista_ennista(self, filename):

        tmp_tyhis_f = None

        try:

            bdocpython.initialize()
            bconf = bdocpythonutils.BDocConfig()
            bconf.load(Election().get_bdoc_conf())

            result = regrights.kontrolli_volitusi(\
                self._elid, filename, 'TYHIS', bconf)

            if not result[0]:
                self._errmsg = \
                    'Tühistus-/ennistusnimekirja volituste ' \
                    'kontroll andis negatiivse tulemuse: '
                self._errmsg += result[1]
                raise Exception(self._errmsg)
            _signercode = result[2]

            tmp_tyhis_f = bdocpythonutils.get_doc_content_file(filename)

            rl = revocationlists.RevocationList()
            rl.attach_elid(self._elid)
            rl.attach_logger(evlog.AppLog())
            if not rl.check_format(tmp_tyhis_f, \
                'Kontrollin tühistus-/ennistusnimekirja: '):
                self._errmsg = 'Vigase formaadiga tühistus-/ennistusnimekiri'
                raise Exception(self._errmsg)

            g_l = None
            b_l = None
            act = ''

            report = []

            if rl.revoke:
                act = 'tühistamine'
                g_l, b_l = self.__tyhista_haaled(rl.rev_list, _signercode)
            else:
                act = 'ennistamine'
                g_l, b_l = self.__ennista_haaled(rl.rev_list, _signercode)

            for el in b_l:
                el.append(act + ' nurjus')
                report.append(el)

            for el in g_l:
                el.append(act + ' õnnestus')
                report.append(el)

            fn = self._reg.path(['hts', 'output', evcommon.REVREPORT_FILE])
            self.__save_list(report, fn)
            ksum.store(fn)
            return len(rl.rev_list), len(g_l), len(b_l)

        finally:

            if tmp_tyhis_f != None:
                os.unlink(tmp_tyhis_f)