Пример #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 decrypt(pathname_operation, warebox, cfg, logger=None):
    """
    Decrypts a file

    @param pathname_operation: an instance of pathname_operation class
    @param warebox: an instance of warebox class
    @cfg an instance of cfg class
    @logger optional logger object
    """
    try:
        tw = TaskWrapper(pathname_operation)
        enc_dir = CryptoUtils.get_encryption_dir(cfg)
        tw.prepare(cfg, enc_dir)
        if logger:
            logger.debug(u'Decrypting file %s to %s' %
                         (tw.task.encrypted_pathname, tw.task.temp_pathname))
        decrypter = Decrypter(warebox)
        decrypter._on_new_task(tw)
        while not decrypter._is_task_completed(tw):
            decrypter._task_step(tw)
        decrypter._on_task_complete(tw)
    except Exception as e:
        if logger:
            logger.exception(u'Decryption task fail on %s' %
                             pathname_operation.pathname)
        on_decrypt_fail(pathname_operation, e, logger)
        raise
Пример #3
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
Пример #4
0
 def __init__(self, operationQueue, resultsQueue, maxWorker, cfg, warebox):
     """
     @param operationQueue: the input queue, cryptoFilter reads the new tasks from it
     @param resultsQueue: the output queue, the managed tasks will be sent back through it
     @param maxWorker: the maximum number of workers running at the same time
     @param cfg: an instance of ConfigurationManager
     @param warebox: an instance of Warebox class
     """
     AbstractFilter.__init__(self, operationQueue, resultsQueue, maxWorker, name=self.__class__.__name__)
     self.logger = logging.getLogger('FR.%s' % self.getName())
     self.cfg=cfg
     self.enc_dir=CryptoUtils.get_encryption_dir(cfg)
     self.warebox = warebox
Пример #5
0
 def __init__(self, operationQueue, resultsQueue, maxWorker, cfg, warebox, lockfile_fd):
     """
     @param operationQueue: the input queue, cryptoFilter reads the new tasks from it
     @param resultsQueue: the output queue, the managed tasks will be sent back through it
     @param maxWorker: the maximum number of workers running at the same time
     @param cfg: an instance of ConfigurationManager
     @param warebox: an instance of Warebox class
     @param lockfile_fd:
                 File descriptor of the lock file which ensures there
                 is only one instance of FileRock Client running.
                 Child processes have to close it to avoid stale locks.
     """
     AbstractFilter.__init__(self, operationQueue, resultsQueue, maxWorker, name=self.__class__.__name__)
     self.logger = logging.getLogger('FR.%s' % self.getName())
     self.cfg=cfg
     self.enc_dir=CryptoUtils.get_encryption_dir(cfg)
     self.warebox = warebox
     self.lockfile_fd = lockfile_fd
Пример #6
0
 def __init__(self, operationQueue, resultsQueue, maxWorker, cfg, warebox,
              lockfile_fd):
     """
     @param operationQueue: the input queue, cryptoFilter reads the new tasks from it
     @param resultsQueue: the output queue, the managed tasks will be sent back through it
     @param maxWorker: the maximum number of workers running at the same time
     @param cfg: an instance of ConfigurationManager
     @param warebox: an instance of Warebox class
     @param lockfile_fd:
                 File descriptor of the lock file which ensures there
                 is only one instance of FileRock Client running.
                 Child processes have to close it to avoid stale locks.
     """
     AbstractFilter.__init__(self,
                             operationQueue,
                             resultsQueue,
                             maxWorker,
                             name=self.__class__.__name__)
     self.logger = logging.getLogger('FR.%s' % self.getName())
     self.cfg = cfg
     self.enc_dir = CryptoUtils.get_encryption_dir(cfg)
     self.warebox = warebox
     self.lockfile_fd = lockfile_fd
Пример #7
0
def decrypt(pathname_operation, warebox, cfg, logger=None):
    """
    Decrypts a file

    @param pathname_operation: an instance of pathname_operation class
    @param warebox: an instance of warebox class
    @cfg an instance of cfg class
    @logger optional logger object
    """
    try:
        tw = TaskWrapper(pathname_operation)
        enc_dir = CryptoUtils.get_encryption_dir(cfg)
        tw.prepare(cfg, enc_dir)
        if logger:
            logger.debug(u'Decrypting file %s to %s' % (tw.task.encrypted_pathname, tw.task.temp_pathname))
        decrypter = Decrypter(warebox)
        decrypter._on_new_task(tw)
        while not decrypter._is_task_completed(tw):
            decrypter._task_step(tw)
        decrypter._on_task_complete(tw)
    except Exception as e:
        if logger: logger.exception(u'Decryption task fail on %s' % pathname_operation.pathname)
        on_decrypt_fail(pathname_operation, e, logger)
        raise