Ejemplo n.º 1
0
def test_huge_treasure_maps_are_rejected(federated_alice, federated_ursulas):
    federated_alice.network_middleware = EvilMiddleWare()

    firstula = list(federated_ursulas)[0]

    ok_amount = 10 * 1024  # 10k
    ok_data = os.urandom(ok_amount)

    with pytest.raises(BytestringSplittingError):
        federated_alice.network_middleware.upload_arbitrary_data(
            firstula, 'consider_arrangement', ok_data)
    """
Ejemplo n.º 2
0
    def from_target_ursula(cls,
                           target_ursula: Ursula,
                           claim_signing_key: bool = False,
                           attach_transacting_key: bool = True) -> 'Vladimir':
        """
        Sometimes Vladimir seeks to attack or imitate a *specific* target Ursula.

        TODO: This is probably a more instructive method if it takes a bytes representation instead of the entire Ursula.
        """
        try:
            from tests.utils.middleware import EvilMiddleWare
        except ImportError:
            raise DevelopmentInstallationRequired(
                importable_name='tests.utils.middleware.EvilMiddleWare')
        cls.network_middleware = EvilMiddleWare()

        crypto_power = CryptoPower(
            power_ups=target_ursula._default_crypto_powerups)

        if claim_signing_key:
            crypto_power.consume_power_up(
                SigningPower(
                    public_key=target_ursula.stamp.as_umbral_pubkey()))

        if attach_transacting_key:
            cls.attach_transacting_key(
                blockchain=target_ursula.policy_agent.blockchain)

        db_filepath = tempfile.mkdtemp(prefix='Vladimir')

        vladimir = cls(
            is_me=True,
            crypto_power=crypto_power,
            db_filepath=db_filepath,
            domain=TEMPORARY_DOMAIN,
            block_until_ready=False,
            start_working_now=False,
            rest_host=target_ursula.rest_interface.host,
            rest_port=target_ursula.rest_interface.port,
            certificate=target_ursula.rest_server_certificate(),
            network_middleware=cls.network_middleware,
            checksum_address=cls.fraud_address,
            worker_address=cls.fraud_address,
            ######### Asshole.
            timestamp=target_ursula._timestamp,
            interface_signature=target_ursula._interface_signature,
            #########
        )
        return vladimir
Ejemplo n.º 3
0
    def from_target_ursula(
        cls,
        target_ursula: Ursula,
        substitute_verifying_key: bool = False,
        sign_metadata: bool = False,
    ) -> 'Vladimir':
        """
        Sometimes Vladimir seeks to attack or imitate a *specific* target Ursula.

        TODO: This is probably a more instructive method if it takes a bytes representation instead of the entire Ursula.
        """
        try:
            from tests.utils.middleware import EvilMiddleWare
        except ImportError:
            raise DevelopmentInstallationRequired(
                importable_name='tests.utils.middleware.EvilMiddleWare')
        cls.network_middleware = EvilMiddleWare()

        crypto_power = CryptoPower(
            power_ups=target_ursula._default_crypto_powerups)

        blockchain = target_ursula.policy_agent.blockchain
        cls.attach_transacting_key(blockchain=blockchain)

        db_filepath = tempfile.mkdtemp(prefix='Vladimir')

        vladimir = cls(
            is_me=True,
            crypto_power=crypto_power,
            db_filepath=db_filepath,
            domain=TEMPORARY_DOMAIN,
            rest_host=target_ursula.rest_interface.host,
            rest_port=target_ursula.rest_interface.port,
            certificate=target_ursula.certificate,
            network_middleware=cls.network_middleware,
            checksum_address=cls.fraud_address,
            worker_address=cls.fraud_address,
            signer=Web3Signer(blockchain.client),
            provider_uri=blockchain.provider_uri,
        )

        # Let's use the target's public info, and try to make some changes.

        metadata = target_ursula.metadata()
        metadata_bytes = bytes(metadata)

        # Since it is an object from a Rust extension, we cannot directly modify it,
        # so we have to replace stuff in the byte representation and then deserialize.
        # We are replacinig objects with constant size,
        # so it should work regardless of the binary format.

        # Our basic replacement. We want to impersonate the target Ursula.
        metadata_bytes = metadata_bytes.replace(
            metadata.payload.canonical_address, vladimir.canonical_address)

        # Use our own verifying key
        if substitute_verifying_key:
            metadata_bytes = metadata_bytes.replace(
                bytes(metadata.payload.verifying_key),
                bytes(vladimir.stamp.as_umbral_pubkey()))

        fake_metadata = NodeMetadata.from_bytes(metadata_bytes)

        # Re-generate metadata signature using our signing key
        if sign_metadata:
            fake_metadata = NodeMetadata(vladimir.stamp.as_umbral_signer(),
                                         fake_metadata.payload)

        # Put metadata back
        vladimir._metadata = fake_metadata

        return vladimir