Ejemplo n.º 1
0
 def test_certificate_to_award(self):
     with open('data/1.2/sample-cert.json') as cert_file:
         certificate_json = json.load(cert_file)
         certificate_model = to_certificate_model(certificate_json)
         award = certificate_formatter.certificate_to_award(certificate_model)
         self.assertEquals(award['title'], 'Game of Thrones Character')
         self.assertEquals(award['issuedOn'], '2016-09-29')
         self.assertEquals(award['name'], 'Arya Stark')
Ejemplo n.º 2
0
def verify_cert(cert_json):
    """Run verification on the given cert, return a tuple with (overall_result, individual_results)"""
    config = get_config()
    certificate_model = to_certificate_model(certificate_json=cert_json)
    result = verify_certificate(
        certificate_model,
        dict(etherscan_api_token=config.get('ETHERSCAN_API_TOKEN', '')))
    all_steps_passed = all(d.get('status') == 'passed' for d in result)
    return all_steps_passed, result
Ejemplo n.º 3
0
 def test_certificate_to_award_eth(self):
     with open('data/1.2/eth-ropsten-cert.json') as cert_file:
         certificate_json = json.load(cert_file)
         certificate_model = to_certificate_model(certificate_json)
         award = certificate_formatter.certificate_to_award(
             certificate_model)
         self.assertEqual(award['title'], 'Certificate of Accomplishment')
         self.assertEqual(award['issuedOn'], '2017-10-25')
         self.assertEqual(award['name'], 'Mcallister Greenborough')
         self.assertEqual(award['chain'], 'Ethereum')
Ejemplo n.º 4
0
def verify_certificate_file(certificate_file_name, transaction_id=None):
    with open(certificate_file_name, 'rb') as cert_fp:
        certificate_bytes = cert_fp.read()
        certificate_json = json.loads(certificate_bytes.decode('utf-8'))
        certificate_model = to_certificate_model(
            certificate_json=certificate_json,
            txid=transaction_id,
            certificate_bytes=certificate_bytes)
        result = verify_certificate(certificate_model)
    return result
Ejemplo n.º 5
0
def verify_certificate_file(certificate_file_name,
                            transaction_id=None,
                            options={}):
    with open(certificate_file_name, 'rb') as cert_fp:
        certificate_bytes = cert_fp.read()
        certificate_json = json.loads(certificate_bytes.decode('utf-8'))
        certificate_json["signature"]["merkleRoot"] = get_merklehash_from_ipfs(
            certificate_json["signature"]["merkleRoot"])
        certificate_model = to_certificate_model(
            certificate_json=certificate_json,
            txid=transaction_id,
            certificate_bytes=certificate_bytes)
        print(certificate_json)
        result = verify_certificate(certificate_model, options)
    return result
Ejemplo n.º 6
0
def verify_certificate_file(certificate_file_name,
                            transaction_id=None,
                            options={}):
    config.init_cwd(os.path.dirname(os.path.abspath(__file__)))
    printer.print_certfile_information(certificate_file_name)
    with open(certificate_file_name, 'rb') as cert_fp:
        certificate_bytes = cert_fp.read()
        certificate_json = json.loads(certificate_bytes.decode('utf-8'))
        certificate_model = to_certificate_model(
            certificate_json=certificate_json,
            txid=transaction_id,
            certificate_bytes=certificate_bytes)
        result = verify_certificate(certificate_model, options)

    return result
Ejemplo n.º 7
0
def verify_certificate_file(certificate_file_name,
                            transaction_id=None,
                            options={}):
    with open(certificate_file_name, 'rb') as cert_fp:
        certificate_bytes = cert_fp.read()
        certificate_json = json.loads(certificate_bytes.decode('utf-8'))
        certificate_model = to_certificate_model(
            certificate_json=certificate_json,
            txid=transaction_id,
            certificate_bytes=certificate_bytes)
        result = verify_certificate(certificate_model, options)
        new_res = [
            'has not been tampered with', 'has not expired',
            'has not been revoked', 'issuer authenticity'
        ]
        res = dict()
        for i in range(0, len(result)):
            x = result[i]
            if x['name'] != 'Validation':
                res[new_res[i]] = (x['status'] == 'passed')
    return res
Ejemplo n.º 8
0
def verify_certificate_file(certificate_file_name,
                            transaction_id=None,
                            options={},
                            hideInfo=False):
    with open(certificate_file_name, 'rb') as cert_fp:
        certificate_bytes = cert_fp.read()
        certificate_json = json.loads(certificate_bytes.decode('utf-8'))

        if not hideInfo:
            print("[*] Issuer data:")
            print("\tName:\t\t" + certificate_json["badge"]["issuer"]["name"])
            print("\tEmail:\t\t" +
                  certificate_json["badge"]["issuer"]["email"])
            print("\tPublic key:\t" +
                  certificate_json["verification"]["publicKey"])

            print("[*] Recipient data:")
            print("\tName:\t\t" + certificate_json["recipientProfile"]["name"])
            print("\tEmail:\t\t" + certificate_json["recipient"]["identity"])
            print("\tPublic key:\t" +
                  certificate_json["recipientProfile"]["publicKey"])

            print("[*] Certificate data:")
            print("\tName:\t\t" + certificate_json["badge"]["name"])
            print("\tDescription:\t" +
                  certificate_json["badge"]["description"])
            print("\tCriteria:\t" +
                  certificate_json["badge"]["criteria"]["narrative"])
            print("\tIssued on:\t" + certificate_json["issuedOn"])

        certificate_model = to_certificate_model(
            certificate_json=certificate_json,
            txid=transaction_id,
            certificate_bytes=certificate_bytes)
        result = verify_certificate(certificate_model, options)
    return result
Ejemplo n.º 9
0
def verify_certificate_json(certificate_json, transaction_id=None, options={}):
    certificate_model = to_certificate_model(certificate_json=certificate_json,
                                             txid=transaction_id)
    result = verify_certificate(certificate_model, options)
    return result