From 6e99d23a0a8c4d7dc644d2d9bf4e961d410c68f2 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 21 Apr 2017 09:16:49 +0200 Subject: [PATCH] =?utf8?q?eliminate=20the=20last=20traces=20of=20encryption=20=E2=80=9Cmodes=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Since encryption handling has been moved outside of tarfile.py these no longer apply. Thus remove all references so they don’t obscure problems in the unit tests. --- deltatar/deltatar.py | 30 +++++++++++------------------- deltatar/tarfile.py | 19 ++++++++----------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index 697a3df..b9eae99 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -124,8 +124,8 @@ class DeltaTar(object): '|gz': '.gz', '|bz2': '.bz2', '#gz': '.gz', - '#gz.aes128': '.gz', - '#aes128': '', + '#gz.pdtcrypt': '.gz', + '#pdtcrypt': '', } # valid index modes and their corresponding default file extension @@ -133,8 +133,8 @@ class DeltaTar(object): '': '', 'gz': '.gz', 'bz2': '.bz2', - 'gz.aes128': '.gz', - 'aes128': '', + 'gz.pdtcrypt': '.gz', + 'pdtcrypt': '', } # valid path prefixes @@ -178,25 +178,21 @@ class DeltaTar(object): '|gz' open a gzip compressed stream of tar blocks '|bz2' open a bzip2 compressed stream of tar blocks '#gz' open a stream of gzip compressed tar blocks - '#gz.aes128' open an aes128 encrypted stream of gzip compressed tar blocks - '#aes128' open an aes128 encrypted stream of tar blocks - - password: used together with aes modes to encrypt and decrypt backups. + - password: used to encrypt and decrypt backups. Encryption will be + enabled automatically if a password is supplied. - logger: python logger object. Optional. - index_mode: specifies the index mode in the same format as @param - mode, but without the ':', '|' or '#' at the begining. It doesn't - make sense to specify that the index is encrypted if no no password - is given in the constructor. This is an optional parameter that will - automatically mimic @param mode by default if not provided. Valid - modes are: + mode, but without the ':', '|' or '#' at the begining. If encryption + is requested it will extend to the auxiliary (index, info) files as + well. This is an optional parameter that will automatically mimic + @param mode by default if not provided. Valid modes are: '' open uncompressed 'gz' open with gzip compression 'bz2' open with bzip2 compression - 'gz.aes128' open an aes128 encrypted stream of gzip compressed tar blocks - 'aes128' open an aes128 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 @@ -227,14 +223,10 @@ class DeltaTar(object): # generate index_mode if index_mode is None: index_mode = '' - if 'gz.aes' in mode: - index_mode = mode[1:] - elif 'gz' in mode: + if 'gz' in mode: 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 mode=[%s] requested for index' % str(mode)) diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index aef4faf..6056d55 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -388,8 +388,8 @@ def gz_header (name=None): flags |= GZ_FLAG_ORIG_NAME if type(name) is str: name = name.encode("iso-8859-1", "replace") - if name.endswith(b".aes128"): - name = name[:-7] + if name.endswith(b".pdtcrypt"): + name = name[:-9] if name.endswith(b".gz"): name = name[:-3] # RFC1952 says we must use ISO-8859-1 for the FNAME field. @@ -499,7 +499,7 @@ class _Stream: else: self.cmp = lzma.LZMACompressor() - elif comptype not in [ "tar", "aes128" ]: + elif comptype not in [ "tar" ]: if self.encryption is not None: raise InvalidEncryptionError("encryption not available for " "compression %s" % comptype) @@ -758,15 +758,17 @@ class _Stream: """Initialize encryption for next entry in archive. Read a header and notify the crypto context.""" if self.encryption is not None: - self.lasthdr = self.fileobj.tell () + lasthdr = self.fileobj.tell () try: hdr = crypto.hdr_read_stream (self.fileobj) except crypto.EndOfFile: return False - except crypto.InvalidHeader: + except crypto.InvalidHeader as exn: raise DecryptionError ("Crypto.hdr_read_stream(): error “%s” " - "processing %r" % (hdr, self.fileobj)) \ + "processing %r at pos %d" + % (exn, self.fileobj, lasthdr)) \ from exn + self.lasthdr = lasthdr self.remainder = hdr ["ctsize"] # distance to next header self.encryption.next (hdr) @@ -1978,11 +1980,6 @@ class TarFile(object): 'r#gz' open a stream of gzip compressed tar blocks for reading 'w#gz' open a stream of gzip compressed tar blocks for writing - - 'r#gz.aes128' open an aes128 encrypted stream of gzip compressed tar blocks for reading - 'w#gz.aes128' open an aes128 encrypted stream of gzip compressed tar blocks for writing - 'r#aes128' open an aes128 encrypted stream of tar blocks for reading - 'w#aes128' open an aes128 encrypted stream of tar blocks for writing """ if not name and not fileobj: -- 1.7.1