Esempio n. 1
0
def verify_signature(uid, signed_certificate_file_name, issuing_address):
    """
    Verify the certificate signature matches the expected. Double-check the uid field in the certificate and use
    VerifyMessage to confirm that the signature in the certificate matches the issuing_address.

    Raises error is verification fails.

    :param uid:
    :param signed_certificate_file_name:
    :param issuing_address:
    :return:
    """

    # Throws an error if invalid
    logging.info('verifying signature for certificate with uid=%s:', uid)
    with open(signed_certificate_file_name) as in_file:
        signed_cert = in_file.read()
        signed_cert_json = json.loads(signed_cert)

        to_verify = signed_cert_json['assertion']['uid']
        signature = signed_cert_json['signature']
        message = BitcoinMessage(to_verify)
        verified = VerifyMessage(issuing_address, message, signature)
        if not verified:
            error_message = 'There was a problem with the signature for certificate uid={}'.format(
                signed_cert_json['assertion']['uid'])
            raise UnverifiedSignatureError(error_message)

        logging.info('verified signature')
def do_verify_signature(address, signed_cert):
    signed_cert_json = json.loads(signed_cert)
    to_verify = signed_cert_json['assertion']['uid']
    message = BitcoinMessage(to_verify)
    signature = signed_cert_json['signature']
    verified = VerifyMessage(address, message, signature)
    if not verified:
        error_message = 'There was a problem with the signature for certificate uid={}'.format(
            signed_cert_json['assertion']['uid'])
        raise UnverifiedSignatureError(error_message)