Пример #1
0
def recalc_encrypted_etag(ivs, warebox, cfg):
    """
    Encrypt all the files into the encrypted folder and return a list of etag

    @param ivs: a dictionary with pathname as key and ivs as value
    @param warebox: an instance of warebox class
    @param cfg: an instance of config class
    """
    encrypted_etags = dict()
    enc_dir = CryptoUtils.get_encryption_dir(cfg)
    encrypter = Encrypter(warebox)
    for pathname in ivs:
        pathname_operation = PathnameOperation(None, None, u'UPLOAD', pathname)
        pathname_operation.to_encrypt=True
        try:
            wrapped_task = TaskWrapper(pathname_operation)
            wrapped_task.prepare(cfg, enc_dir)
            wrapped_task.iv = unhexlify(ivs[pathname])
            encrypter._on_new_task(wrapped_task)
            while not encrypter._is_task_completed(wrapped_task):
                encrypter._task_step(wrapped_task)
            encrypter._on_task_complete(wrapped_task)
            encrypted_etags[pathname] = compute_md5_hex(wrapped_task.task.encrypted_pathname)
            clean_env(pathname_operation)
        except Exception:
            clean_env(pathname_operation)
            raise
    return encrypted_etags
Пример #2
0
def recalc_encrypted_etag(ivs, warebox, cfg, interruption=None):
    return recalc_encrypted_etag_in_mem(ivs, warebox, cfg, interruption)
    """
    Encrypt all the files into the encrypted folder and return a list of etag

    @param ivs: a dictionary with pathname as key and ivs as value
    @param warebox: an instance of warebox class
    @param cfg: an instance of config class
    """
    encrypted_etags = dict()
    enc_dir = CryptoUtils.get_encryption_dir(cfg)
    encrypter = Encrypter(warebox)
    for pathname in ivs:
        pathname_operation = PathnameOperation(None, None, u'UPLOAD', pathname)
        pathname_operation.to_encrypt = True
        try:
            wrapped_task = TaskWrapper(pathname_operation)
            wrapped_task.prepare(cfg, enc_dir)
            wrapped_task.iv = unhexlify(ivs[pathname])
            encrypter._on_new_task(wrapped_task)
            while not encrypter._is_task_completed(wrapped_task):
                encrypter._task_step(wrapped_task)
            encrypter._on_task_complete(wrapped_task)
            encrypted_etags[pathname] = compute_md5_hex(
                wrapped_task.task.encrypted_pathname)
            clean_env(pathname_operation)
        except Exception:
            clean_env(pathname_operation)
            raise
    return encrypted_etags
Пример #3
0
 def _create_pathname_operation(self, status, pathname, oldpath=None):
     """
     Factory method for PathnameOperation objects
     """
     status_to_verb = {
         'LN': 'UPLOAD',
         'LD': 'DELETE',
         'LRto': 'REMOTE_COPY',
         'RN': 'DOWNLOAD',
         'RD': 'DELETE_LOCAL'
     }
     event = self._last_event_for_pathname[pathname]
     operation = PathnameOperation(
         self.application, self.access, status_to_verb[status],
         pathname, oldpath, event.etag, event.size, event.lmtime,
         event.conflicted)
     operation.register_abort_handler(self.on_file_operation_abort)
     operation.register_complete_handler(self.on_file_operation_complete)
     return operation
Пример #4
0
 def _create_pathname_operation(self, status, pathname, oldpath=None):
     """
     Factory method for PathnameOperation objects
     """
     status_to_verb = {"LN": "UPLOAD", "LD": "DELETE", "LRto": "REMOTE_COPY", "RN": "DOWNLOAD", "RD": "DELETE_LOCAL"}
     event = self._last_event_for_pathname[pathname]
     operation = PathnameOperation(
         self.application,
         self.access,
         status_to_verb[status],
         pathname,
         oldpath,
         event.etag,
         event.size,
         event.lmtime,
         event.conflicted,
     )
     operation.register_abort_handler(self.on_file_operation_abort)
     operation.register_complete_handler(self.on_file_operation_complete)
     return operation
Пример #5
0
 def _create_pathname_operation(self, status, pathname, oldpath=None):
     """
     Factory method for PathnameOperation objects
     """
     status_to_verb = {
         'LN': 'UPLOAD',
         'LD': 'DELETE',
         'LRto': 'REMOTE_COPY',
         'RN': 'DOWNLOAD',
         'RD': 'DELETE_LOCAL'
     }
     event = self._last_event_for_pathname[pathname]
     operation = PathnameOperation(self.application, self.access,
                                   status_to_verb[status], pathname,
                                   oldpath, event.etag, event.size,
                                   event.lmtime, event.conflicted)
     operation.register_abort_handler(self.on_file_operation_abort)
     operation.register_complete_handler(self.on_file_operation_complete)
     return operation
Пример #6
0
def test_integrity_error_storage_is_candidate_but_different_basis(
        adapter_mock, workerpool_mock, connection_lifekeeper,
        disconnectedstate_cls_mock, downloadstate_cls_mock):

    from FileRockSharedLibraries.Communication.Messages import SYNC_FILES_LIST
    from filerockclient.pathname_operation import PathnameOperation

    components = setup_fixtures(adapter_mock, workerpool_mock,
                                connection_lifekeeper,
                                disconnectedstate_cls_mock,
                                downloadstate_cls_mock)

    # There is nothing in the warebox
    components['mock']['warebox'].get_content.return_value = []

    # There is nothing in the storage cache...
    assert_equal(components['real']['storage_cache'].get_all_records(), [])

    # ... but one file pending from last commit
    operation = PathnameOperation(application=None,
                                  lock=None,
                                  verb='UPLOAD',
                                  pathname=u'File.txt',
                                  etag=u'd41d8cd98f00b204e9800998ecf8427e',
                                  size=1,
                                  lmtime=datetime.datetime.now())
    transaction_cache = components['real']['server_session'].transaction_cache
    transaction_cache.update_record(1, operation, datetime.datetime.now())

    components['real']['metadata'].set('trusted_basis', 'TRUSTEDBASIS')
    components['real']['metadata'].set('candidate_basis', 'CANDIDATEBASIS')

    # On the storage there is the same file as in the candidate storage cache
    storage_content = [{
        u'key': u'File.txt',
        u'etag': u'"d41d8cd98f00b204e9800998ecf8427e"',
        u'lmtime': u'1970-01-01T10:00:00.000Z',
        u'size': u'1'
    }]

    # Server basis is different from the candidate basis
    msg = SYNC_FILES_LIST(
        'SYNC_FILES_LIST', {
            'basis': 'MALICIOUSBASIS',
            'dataset': storage_content,
            'last_commit_client_id': '0',
            'last_commit_client_hostname': 'myhostname',
            'last_commit_client_platform': 'myplatform',
            'last_commit_timestamp': 'mytimestamp',
            'user_quota': '0',
            'used_space': '100'
        })
    components['real']['input_queue'].put(msg, 'servermessage')

    # Let's start!
    components['real']['server_session'].start()
    components['real']['server_session'].join()

    # The storage content is equal to our candidate storage cache,
    # but the basis is different from the candidate one: it's an attack.
    # We expect the application to have alerted the user about the integrity
    # error and to have gone into BasisMismatchState.
    ui = components['mock']['ui_controller']
    int_f = components['mock']['internal_facade']
    fail_state = components['mock']['integrity_failure_state']

    ui.notify_user.assert_called_with('hash_mismatch')
    int_f.set_global_status.assert_called_with(
        GStatuses.C_HASHMISMATCHONCONNECT)
    assert_true(fail_state.do_execute.called)