コード例 #1
0
def contribute(base_url: str, key_file: str, challenge_file: str,
               contribute_cb: Callable[[], str], wait_interval: int,
               server_certificate: Optional[str], insecure: bool) -> None:
    """
    Given a callback that creates a response from a challenge, download a
    challenge, create the response via the callback, and sign and upload it.
    """
    # Check key upfront
    with open(key_file, "rb") as key_f:
        sk = import_signing_key(key_f.read())
    print("Got key")

    client = Client(base_url, server_certificate, insecure)

    if wait_interval:
        verification_key = get_verification_key(sk)
        wait_for_turn(client, wait_interval, verification_key)

    # Get challenge
    client.get_challenge(challenge_file)
    print("Got challenge")

    # Perform the contribution
    response_file = contribute_cb()

    # Sign and upload
    _upload_response(client, response_file, sk)
コード例 #2
0
def upload_response(client: Client, response_file: str, key_file: str) -> None:
    """
    Given some response file and a key, sign the response and upload the
    coordinator connected to by client.
    """
    with open(key_file, "rb") as key_f:
        sk = import_signing_key(key_f.read())
    _upload_response(client, response_file, sk)