From: Eduardo Robles Elvira Date: Wed, 9 Oct 2013 09:56:09 +0000 (+0200) Subject: start working on AES-only delta tar mode, with no encryption. some tests still fail X-Git-Tag: v2.2~86 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=ac5e418402e99c71e5037384633da2f154603597;p=python-delta-tar start working on AES-only delta tar mode, with no encryption. some tests still fail --- diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index bab22f4..872f9cf 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -94,7 +94,9 @@ class DeltaTar(object): '|bz2': '.bz2', '#gz': '.gz', '#gz.aes128': '.gz.aes128', - '#gz.aes256': '.gz.aes256' + '#gz.aes256': '.gz.aes256', + '#aes128': '.aes128', + '#aes256': '.aes256', } # valid index modes and their corresponding default file extension @@ -103,7 +105,9 @@ class DeltaTar(object): 'gz': '.gz', 'bz2': '.bz2', 'gz.aes128': '.gz.aes128', - 'gz.aes256': '.gz.aes256' + 'gz.aes256': '.gz.aes256', + 'aes128': '.aes128', + 'aes256': '.aes256' } # valid path prefixes @@ -149,6 +153,8 @@ class DeltaTar(object): '#gz' open a stream of gzip compressed tar blocks '#gz.aes128' open an aes128 encrypted stream of gzip compressed tar blocks '#gz.aes256' open an aes256 encrypted stream of gzip compressed tar blocks + '#aes128' open an aes128 encrypted stream of tar blocks + '#aes256' open an aes256 encrypted stream of tar blocks - password: used together with aes modes to encrypt and decrypt backups. @@ -166,6 +172,8 @@ class DeltaTar(object): 'bz2' open with bzip2 compression 'gz.aes128' open an aes128 encrypted stream of gzip compressed tar blocks 'gz.aes256' open an aes256 encrypted stream of gzip compressed tar blocks + 'aes128' open an aes128 encrypted stream of tar blocks + 'aes256' open an aes256 encrypted stream of tar blocks - index_name_func: function that sets a custom name for the index file. This function receives the backup_path and if it's a full backup as @@ -199,6 +207,8 @@ class DeltaTar(object): index_mode = "gz" elif 'bz2' in mode: index_mode = "bz2" + elif 'aes' in mode: + index_mode = mode[1:] elif mode not in self.__index_extensions_dict: raise Exception('Unrecognized extension') diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index f9c8e79..1832199 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -456,7 +456,7 @@ class _Stream: self._init_write_gz() self.crc = zlib.crc32("") & 0xffffffffL - if comptype == "bz2": + elif comptype == "bz2": try: import bz2 except ImportError: @@ -467,6 +467,13 @@ class _Stream: else: self.cmp = bz2.BZ2Compressor() + elif self.enctype == 'aes': + self.encryption = aescrypto.AESCrypt(self.password, + key_length=self.key_length) + if mode != "r": + self.encryption.init() + self.__write_to_file(self.encryption.salt_str) + def __del__(self): if hasattr(self, "closed") and not self.closed: self.close() @@ -504,6 +511,8 @@ class _Stream: raise CompressionError("new compression blocks can only be added in mode 'w'") if self.comptype == "gz": self._new_gz_block(True) + elif self.enctype == 'aes': + self._new_aes_block(True) else: raise CompressionError("Concat compression only available for comptype 'gz'") @@ -522,19 +531,23 @@ class _Stream: # if aes, we encrypt after compression if self.enctype == 'aes': - self.__write_to_file(self.encryption.close_enc()) - if set_last_block_offset: - self.last_block_offset = self.fileobj.tell() - self.encryption = aescrypto.AESCrypt(self.password, - key_length=self.key_length) - self.encryption.init() - self.__write_to_file(self.encryption.salt_str) + self._new_aes_block(set_last_block_offset) elif set_last_block_offset: self.last_block_offset = self.fileobj.tell() timestamp = struct.pack("