def test_vladimir_uses_his_own_signing_key(alice, mining_ursulas):
    """
    Similar to the attack above, but this time Vladimir makes his own interface signature
    using his own signing key, which he claims is Ursula's.
    """
    his_target = list(mining_ursulas)[4]
    vladimir_ether_address = '0xE57bFE9F44b819898F47BF37E5AF72a0783e1141'

    fraduluent_keys = CryptoPower(power_ups=Ursula._default_crypto_powerups)

    vladimir = Ursula(crypto_power=fraduluent_keys,
                      rest_host=his_target.rest_interface.host,
                      rest_port=his_target.rest_interface.port,
                      checksum_address=vladimir_ether_address,
                      is_me=False)
    message = vladimir._signable_interface_info_message()
    signature = vladimir._crypto_power.power_ups(SigningPower).sign(message)
    vladimir._interface_signature_object = signature

    vladimir.substantiate_stamp()

    # With this slightly more sophisticated attack, his metadata does appear valid.
    vladimir.validate_metadata()

    # However, the actual handshake proves him wrong.
    with pytest.raises(vladimir.InvalidNode):
        vladimir.verify_node(alice.network_middleware)
コード例 #2
0
def test_alice_refuses_to_make_arrangement_unless_ursula_is_valid(
        blockchain_alice, idle_blockchain_policy, mining_ursulas):
    target = list(mining_ursulas)[2]
    # First, let's imagine that Alice has sampled a Vladimir while making this policy.
    vladimir = Ursula(
        crypto_power=CryptoPower(power_ups=Ursula._default_crypto_powerups),
        rest_host=target.rest_interface.host,
        rest_port=target.rest_interface.port,
        checksum_address=
        '0xE57bFE9F44b819898F47BF37E5AF72a0783e1141',  # Fradulent address
        is_me=False)
    message = vladimir._signable_interface_info_message()
    signature = vladimir._crypto_power.power_ups(SigningPower).sign(message)
    vladimir.substantiate_stamp()
    vladimir._interface_signature_object = signature

    class FakeArrangement:
        federated = False

    with pytest.raises(vladimir.InvalidNode):
        idle_blockchain_policy.consider_arrangement(
            network_middleware=blockchain_alice.network_middleware,
            arrangement=FakeArrangement(),
            ursula=vladimir)