Пример #1
0
    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
Пример #2
0
    def __check_incoming_vote(self, config):

        _doc_count = len(self.bdoc.documents)
        if _doc_count == 0:
            raise Exception, "BDoc ei sisalda ühtegi andmefaili"

        sigfiles = self.bdoc.signatures.keys()
        if len(sigfiles) != 1:
            raise Exception, "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_fn = sigfiles[0]
        sig_content = self.bdoc.signatures[sig_fn]
        res = verifier.verifyInHTS(sig_content)
        if res.signature:
            self.bdoc.addTM(sig_fn, res.signature)
        return res
Пример #3
0
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)
Пример #4
0
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
Пример #5
0
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'
for el in os.listdir(certDir):
    print 'Adding certificate:', el
    verifier.addCertToStore(os.path.join(certDir, el))

if method == 'online' or method == 'tm':
    #verifier.addOCSPConf(issuer, url, cert, skew, maxAge)
    pass

for el in bdoc.documents:
    verifier.setDocument(bdoc.documents[el], el)

sig_fn = sigfiles[0]