def verify_certificate(certificate_model, options=None):
    if options is None:
        options = {}
    try:
        is_issued_on_smartcontract = certificate_model.certificate_json[
            "signature"]["anchors"][0]["type"] == "ETHSmartContract"
    except (TypeError, KeyError):
        is_issued_on_smartcontract = False
    messages = []
    if is_issued_on_smartcontract:
        verification_steps = create_verification_steps(
            certificate_model,
            is_issued_on_smartcontract=is_issued_on_smartcontract)
        verification_steps.execute()
        verification_steps.add_detailed_status(messages)
    else:
        # lookup issuer-hosted information
        issuer_info = connectors.get_issuer_info(certificate_model)

        # lookup transaction information
        connector = connectors.createTransactionLookupConnector(
            certificate_model.chain, options)
        transaction_info = connector.lookup_tx(certificate_model.txid)

        # create verification plan
        verification_steps = create_verification_steps(certificate_model,
                                                       transaction_info,
                                                       issuer_info,
                                                       certificate_model.chain)

        verification_steps.execute()
        verification_steps.add_detailed_status(messages)
    printer.print_issuer_information(certificate_model.certificate_json)
    printer.print_verification_information(messages)
    return messages
Exemple #2
0
def verify_v1_2(certificate_json):
    # removing this check until we have caching for the schemas
    #try:
    #    schema_validator.validate_v1_2(certificate_json)
    #    logging.debug('The schema validates against v1.2 schema')
    #except Exception as e:
    #    logging.error('The certificate did not comply with the Blockchain Certificate schema', e)
    #    raise InvalidCertificateError('The certificate did not comply with the Blockchain Certificate schema', e)

    state = ProcessingStateV2(certificate_json['document'],
                              certificate_json['receipt'])

    chain = parse_chain_from_address(
        certificate_json['document']['recipient']['publicKey'])
    connector = createTransactionLookupConnector(chain)
    bitcoin.SelectParams(chain.name)

    validate_receipt = ValidationGroup(steps=[ValidateReceipt()],
                                       name='Validate receipt')
    compute_hash = ValidationGroup(
        steps=[ComputeHashV2()],
        name='Computing SHA256 digest of local certificate',
        success_status=StepStatus.done)
    fetch_transaction = ValidationGroup(
        steps=[LookupTransactionId(),
               FetchTransaction(connector)],
        name='Fetch Bitcoin Transaction',
        success_status=StepStatus.done)
    compare_certificate_hash = ValidationGroup(
        steps=[CompareHashesV2()], name='Comparing local and merkle hashes')
    check_signature = ValidationGroup(
        steps=[FetchIssuerKeys(), CheckIssuerSignature()],
        name='Checking issuer signature')
    check_not_revoked = ValidationGroup(
        steps=[CheckNotRevoked(),
               CheckRecipientNotRevoked()],
        name='Checking not revoked by issuer')
    check_not_expired = ValidationGroup(
        steps=[CheckNotExpired()], name='Checking certificate has not expired')

    steps = [
        validate_receipt, compute_hash, fetch_transaction,
        compare_certificate_hash, check_signature, check_not_revoked,
        check_not_expired
    ]
    all_steps = ValidationGroup(steps=steps, name='Validation')

    all_steps.execute(state)
    messages = []
    all_steps.add_detailed_status(messages)
    for message in messages:
        print(message['name'] + ',' + str(message['status']))

    return messages
Exemple #3
0
def verify_certificate(certificate_model):
    # lookup issuer-hosted information
    issuer_info = connectors.get_issuer_info(certificate_model)

    # lookup transaction information
    chain = parse_chain_from_address(issuer_info.issuer_keys[0].public_key)
    connector = connectors.createTransactionLookupConnector(chain)
    transaction_info = connector.lookup_tx(certificate_model.txid)

    # create verification plan
    verification_steps = create_verification_steps(certificate_model, transaction_info, issuer_info, chain)

    verification_steps.execute()
    messages = []
    verification_steps.add_detailed_status(messages)
    for message in messages:
        print(message['name'] + ',' + str(message['status']))

    return messages
Exemple #4
0
def verify_certificate(certificate_model, options={}):
    # lookup issuer-hosted information
    issuer_info = connectors.get_issuer_info(certificate_model)

    # lookup transaction information
    connector = connectors.createTransactionLookupConnector(
        certificate_model.chain, options)
    transaction_info = connector.lookup_tx(certificate_model.txid)
    # create verification plan
    verification_steps = create_verification_steps(certificate_model,
                                                   transaction_info,
                                                   issuer_info,
                                                   certificate_model.chain)
    verification_steps.execute()
    messages = []
    verification_steps.add_detailed_status(messages)
    for message in messages:
        print(message['name'] + ',' + str(message['status']))

    return messages