예제 #1
0
파일: init.py 프로젝트: wenwkich/cert-web
def init_certificate_template(config):
    template = create_certificate_template(config)
    col = DAO().get_collection("certificate_template")
    if col.find_one():
        _id = col.find_one()["_id"]
        selector = {"_id": _id}
        col.replace_one(selector, template)
    else:
        col.insert_one(template)
    print(template)
예제 #2
0
파일: init.py 프로젝트: wenwkich/cert-web
def init_issuer_id(config):
    issuer_id = generate_issuer_file(config)
    col = DAO().get_collection("issuer_id")
    if col.find_one():
        _id = col.find_one()["_id"]
        selector = {"_id": _id}
        col.replace_one(selector, issuer_id)
    if not col.find_one():
        col.insert_one(issuer_id)
    print(issuer_id)
예제 #3
0
파일: apis.py 프로젝트: wenwkich/cert-web
 def get(self, id):
     '''
     verify a certificate according to id
     '''
     cert_col = DAO().get_collection("certificates")
     cert = cert_col.find_one({'id': URN_UUID_PREFIX + id}, {'_id': 0})
     return verify_certificate_json(cert)
예제 #4
0
파일: init.py 프로젝트: wenwkich/cert-web
def init_revocation_list(config):
    revocation_list = {}
    revocation_list["@context"] = "https://w3id.org/openbadges/v2"
    revocation_list[
        "id"] = config.domain_name_prefix + config.revocation_list_path
    revocation_list["type"] = "RevocationList"
    revocation_list[
        "issuer"] = config.domain_name_prefix + config.issuer_id_path

    col = DAO().get_collection("revocation_list")
    if col.find_one():
        _id = col.find_one()["_id"]
        selector = {"_id": _id}
        col.update_one(selector, {"$set": revocation_list})
    else:
        revocation_list["revokedAssertions"] = []
        col.insert_one(revocation_list)
    print(revocation_list)
예제 #5
0
파일: apis.py 프로젝트: wenwkich/cert-web
    def post(self):
        json_data = request.get_json(force=True)
        # get recipient from the json_data
        fields = {}
        fields["identity"] = json_data['email']
        fields["name"] = json_data['name']
        recipient = Recipient(fields)

        # get the template from db
        template_col = DAO().get_collection('certificate_template')
        template = template_col.find_one({}, {"_id": 0})

        # get deep copy of the template as cert
        cert = deepcopy(template)

        # get the config
        config = Config().get()

        # call instantiate_assertion and instantiate_recipient
        uid = str(uuid.uuid4())
        issued_on = helpers.create_iso8601_tz()
        instantiate_assertion(cert, uid, issued_on)
        instantiate_recipient(cert, recipient,
                              config.additional_per_recipient_fields,
                              config.hash_emails)

        # get the config
        config = Config().get()

        # post it to blockchain
        # first instantiate handlers
        chain = config.chain
        if chain == Chain.ethereum_mainnet or chain == Chain.ethereum_ropsten:
            from cert_issuer.blockchain_handlers import ethereum
            certificate_batch_handler, transaction_handler, connector = ethereum.instantiate_blockchain_handlers(
                config, False)
        else:
            from cert_issuer.blockchain_handlers import bitcoin
            certificate_batch_handler, transaction_handler, connector = bitcoin.instantiate_blockchain_handlers(
                config, False)

        certificate_batch_handler.certificates_to_issue = [cert]
        issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                        transaction_handler=transaction_handler,
                        max_retry=config.max_retry)
        tx_id = issuer.issue(config.chain)

        issued_cert = certificate_batch_handler.certificates_to_issue[0]
        issued_cert_to_insert = deepcopy(issued_cert)
        cert_col = DAO().get_collection("certificates")
        cert_col.insert_one(issued_cert_to_insert)
        return issued_cert
예제 #6
0
파일: apis.py 프로젝트: wenwkich/cert-web
 def get(self, id):
     '''
     gets a certificate
     '''
     cert_col = DAO().get_collection("certificates")
     return cert_col.find_one({'id': URN_UUID_PREFIX + id}, {'_id': 0})
예제 #7
0
파일: apis.py 프로젝트: wenwkich/cert-web
 def get(self):
     revocation_list_col = DAO().get_collection("revocation_list")
     return revocation_list_col.find_one({}, {"_id": 0})
예제 #8
0
파일: apis.py 프로젝트: wenwkich/cert-web
 def get(self):
     issuer_id_col = DAO().get_collection("issuer_id")
     return issuer_id_col.find_one({}, {"_id": 0})