Exemple #1
0
def create_signed_task_to_compute(
        task_id,
        subtask_id,
        deadline,
        timestamp=None,
        provider_public_key=None,
        requestor_public_key=None,
        requestor_ethereum_public_key=REQUESTOR_ETHEREUM_PUBLIC_KEY,
        provider_ethereum_public_key=PROVIDER_ETHEREUM_PUBLIC_KEY,
        price=0):
    with freeze_time(timestamp):
        compute_task_def = ComputeTaskDefFactory(
            task_id=task_id,
            subtask_id=subtask_id,
            deadline=deadline,
        )
        task_to_compute = TaskToComputeFactory(
            provider_public_key=provider_public_key if provider_public_key
            is not None else _get_provider_hex_public_key(),
            requestor_public_key=requestor_public_key if requestor_public_key
            is not None else _get_requestor_hex_public_key(),
            compute_task_def=compute_task_def,
            requestor_ethereum_public_key=requestor_ethereum_public_key,
            provider_ethereum_public_key=provider_ethereum_public_key,
            price=price,
            size=1,
        )
        sign_message(task_to_compute, REQUESTOR_PRIVATE_KEY)
        return task_to_compute
Exemple #2
0
    def _create_serialized_subtask_results_verify(
        self,
        reason_of_rejection=message.tasks.SubtaskResultsRejected.REASON.
        VerificationNegative,
        time_offset=settings.ADDITIONAL_VERIFICATION_CALL_TIME / 2,
        key=None,
    ):
        subtask_result_rejected_time_str = "2018-04-01 10:30:00"
        subtask_results_rejected = self._get_deserialized_subtask_results_rejected(
            reason=reason_of_rejection,
            timestamp=subtask_result_rejected_time_str,
            report_computed_task=self.report_computed_task,
        )
        subtask_results_verify_time_str = self._add_time_offset_to_date(
            subtask_result_rejected_time_str, time_offset)
        sign_message(subtask_results_rejected, key
                     or self.REQUESTOR_PRIVATE_KEY)

        subtask_results_verify = self._get_deserialized_subtask_results_verify(
            timestamp=subtask_results_verify_time_str,
            subtask_results_rejected=subtask_results_rejected)

        serialized_subtask_results_verify = self._get_serialized_subtask_results_verify(
            subtask_results_verify=subtask_results_verify)
        return serialized_subtask_results_verify, subtask_results_verify_time_str
Exemple #3
0
def force_report_computed_task(task_to_compute):
    report_computed_task = ReportComputedTaskFactory()
    report_computed_task.task_to_compute = task_to_compute
    sign_message(report_computed_task, PROVIDER_PRIVATE_KEY)

    force_report_computed_task  = ForceReportComputedTask()
    force_report_computed_task.report_computed_task = report_computed_task
    return force_report_computed_task
Exemple #4
0
 def send(self, cluster_url, message):
     for party, message_types in KEY_MAP.items():
         if isinstance(message, message_types):
             priv_key, _ = self.select_keys(party)
             break
     else:
         raise Exception(f'Unsupported Message Type: {type(message)}')
     print_message(message, cluster_url, 'send')
     sign_message(get_field_from_message(message, 'task_to_compute'), self.requestor_private_key)
     serialized_message = dump(message, priv_key, self.concent_pub_key)
     self._exchange_message(priv_key, cluster_url, serialized_message)
Exemple #5
0
    def test_add_signature_with_correct_keys_pair(self):
        ping_message = message.Ping()
        self.assertEqual(ping_message.sig, None)

        ping_message = sign_message(ping_message, CONCENT_PRIVATE_KEY)

        self.assertIsNot(ping_message.sig, None)
        self.assertIsInstance(ping_message.sig, bytes)
def _create_file_transfer_token(
    subtask_id: str,
    result_package_path: str,
    result_size: int,
    result_package_hash: str,
    authorized_client_public_key: bytes,
    operation: FileTransferToken.Operation,
    source_package_path: Optional[str] = None,
    source_size: Optional[int] = None,
    source_package_hash: Optional[str] = None,
    token_expiration_deadline: Optional[int] = None,
) -> FileTransferToken:

    assert (source_size and source_package_hash and source_package_path) or (result_size and result_package_hash and result_package_path)
    assert isinstance(authorized_client_public_key, bytes)
    assert isinstance(token_expiration_deadline, int) and not isinstance(token_expiration_deadline, bool) or token_expiration_deadline is None
    assert operation in [FileTransferToken.Operation.download, FileTransferToken.Operation.upload]

    file_transfer_token = FileTransferToken(
        token_expiration_deadline       = token_expiration_deadline,
        storage_cluster_address         = settings.STORAGE_CLUSTER_ADDRESS,
        authorized_client_public_key    = authorized_client_public_key,
        operation                       = operation,
        subtask_id                      = subtask_id
    )
    files = []
    if result_package_path and result_package_hash and result_size:
        files.append(
            create_file_info(
                file_path=result_package_path,
                package_hash=result_package_hash,
                size=result_size,
                category=FileTransferToken.FileInfo.Category.results,
            )
        )

    if source_package_path and source_package_hash and source_size:
        files.append(
            create_file_info(
                file_path=source_package_path,
                package_hash=source_package_hash,
                size=source_size,
                category=FileTransferToken.FileInfo.Category.resources,
            )
        )

    file_transfer_token.files = files
    file_transfer_token = sign_message(file_transfer_token, settings.CONCENT_PRIVATE_KEY)

    validate_file_transfer_token(file_transfer_token)

    return file_transfer_token
Exemple #7
0
 def _sign_message(self, golem_message, client_private_key = None):
     return sign_message(
         golem_message,
         self.REQUESTOR_PRIVATE_KEY if client_private_key is None else client_private_key,
     )