Пример #1
0
    def from_public_keys(cls,
                         powers_and_material: Dict,
                         federated_only=True,
                         *args,
                         **kwargs) -> 'Character':
        # TODO: Need to be federated only until we figure out the best way to get the checksum_address in here.
        """
        Sometimes we discover a Character and, at the same moment,
        learn the public parts of more of their powers. Here, we take a Dict
        (powers_and_key_bytes) in the following format:
        {CryptoPowerUp class: public_material_bytes}

        Each item in the collection will have the CryptoPowerUp instantiated
        with the public_material_bytes, and the resulting CryptoPowerUp instance
        consumed by the Character.
        """
        crypto_power = CryptoPower()

        for power_up, public_key in powers_and_material.items():
            try:
                umbral_key = UmbralPublicKey(public_key)
            except TypeError:
                umbral_key = public_key

            crypto_power.consume_power_up(power_up(pubkey=umbral_key))

        return cls(is_me=False,
                   federated_only=federated_only,
                   crypto_power=crypto_power,
                   *args,
                   **kwargs)
Пример #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.
        """
        crypto_power = CryptoPower(power_ups=target_ursula._default_crypto_powerups)

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

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

        vladimir = cls(is_me=True,
                       crypto_power=crypto_power,
                       db_filepath=cls.db_filepath,
                       rest_host=target_ursula.rest_information()[0].host,
                       rest_port=target_ursula.rest_information()[0].port,
                       certificate=target_ursula.rest_server_certificate(),
                       network_middleware=cls.network_middleware,
                       checksum_address = cls.fraud_address,
                       ######### Asshole.
                       timestamp=target_ursula._timestamp,
                       interface_signature=target_ursula._interface_signature,
                       ######### 
                       )

        cls.attach_transacting_key(blockchain=target_ursula.blockchain)

        return vladimir
Пример #3
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
Пример #4
0
    def from_public_keys(cls,
                         powers_and_material: Dict = None,
                         verifying_key: Union[bytes, UmbralPublicKey] = None,
                         encrypting_key: Union[bytes, UmbralPublicKey] = None,
                         federated_only: bool = True,
                         *args,
                         **kwargs) -> 'Character':
        """
        Sometimes we discover a Character and, at the same moment,
        learn the public parts of more of their powers. Here, we take a Dict
        (powers_and_material) in the format {CryptoPowerUp class: material},
        where material can be bytes or UmbralPublicKey.

        Each item in the collection will have the CryptoPowerUp instantiated
        with the given material, and the resulting CryptoPowerUp instance
        consumed by the Character.

        Alternatively, you can pass directly a verifying public key
        (for SigningPower) and/or an encrypting public key (for DecryptionPower).

        # TODO: Need to be federated only until we figure out the best way to get the checksum_address in here.
        """

        crypto_power = CryptoPower()

        if powers_and_material is None:
            powers_and_material = dict()

        if verifying_key:
            powers_and_material[SigningPower] = verifying_key
        if encrypting_key:
            powers_and_material[DecryptingPower] = encrypting_key

        for power_up, public_key in powers_and_material.items():
            try:
                umbral_key = UmbralPublicKey.from_bytes(public_key)
            except TypeError:
                umbral_key = public_key

            crypto_power.consume_power_up(power_up(public_key=umbral_key))

        return cls(is_me=False,
                   federated_only=federated_only,
                   crypto_power=crypto_power,
                   *args,
                   **kwargs)
Пример #5
0
    def from_public_keys(cls, powers_and_keys: Dict, *args, **kwargs):
        """
        Sometimes we discover a Character and, at the same moment, learn one or
        more of their public keys. Here, we take a Dict
        (powers_and_key_bytes) in the following format:
        {CryptoPowerUp class: public_key_bytes}

        Each item in the collection will have the CryptoPowerUp instantiated
        with the public_key_bytes, and the resulting CryptoPowerUp instance
        consumed by the Character.
        """
        crypto_power = CryptoPower()

        for power_up, public_key in powers_and_keys.items():
            try:
                umbral_key = UmbralPublicKey(public_key)
            except TypeError:
                umbral_key = public_key

            crypto_power.consume_power_up(power_up(pubkey=umbral_key))

        return cls(is_me=False, crypto_power=crypto_power, *args, **kwargs)
Пример #6
0
    def from_target_ursula(cls, target_ursula, claim_signing_key=False):
        """
        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.
        """
        crypto_power = CryptoPower(power_ups=Ursula._default_crypto_powerups)

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

        vladimir = cls(crypto_power=crypto_power,
                       rest_host=target_ursula.rest_information()[0].host,
                       rest_port=target_ursula.rest_information()[0].port,
                       checksum_address=cls.fraud_address,
                       certificate=target_ursula.rest_server_certificate(),
                       is_me=False)

        vladimir._interface_signature_object = target_ursula._interface_signature_object  # Asshole.

        cls.attach_transacting_key(blockchain=target_ursula.blockchain)

        return vladimir