def test_vladimir_cannot_verify_interface_with_ursulas_signing_key(
        mining_ursulas):
    his_target = list(mining_ursulas)[4]

    # Vladimir has his own ether address; he hopes to publish it along with Ursula's details
    # so that Alice (or whomever) pays him instead of Ursula, even though Ursula is providing the service.
    vladimir_ether_address = '0xE57bFE9F44b819898F47BF37E5AF72a0783e1141'

    # Vladimir imitates Ursula - copying her public keys and interface info, but inserting his ether address.
    vladimir = Ursula(crypto_power=his_target._crypto_power,
                      rest_host=his_target.rest_interface.host,
                      rest_port=his_target.rest_interface.port,
                      checksum_address=vladimir_ether_address,
                      interface_signature=his_target._interface_signature,
                      is_me=False)

    # Vladimir can substantiate the stamp using his own ether address...
    vladimir.substantiate_stamp()
    vladimir.stamp_is_valid()

    # ...however, the signature for the interface info isn't valid.
    with pytest.raises(vladimir.InvalidNode):
        vladimir.interface_is_valid()

    # Consequently, the metadata isn't valid.
    with pytest.raises(vladimir.InvalidNode):
        vladimir.validate_metadata()
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)
Esempio n. 3
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)