# Author: Eduardo Robles Elvira <edulix@wadobo.com>
+I2N_XXX_ENCRYPTION_VERSION = 0
+
import logging
import datetime
import binascii
return path[len(prefix):]
return path
- def open_index(self, path, mode='r'):
+ def open_index(self, path, mode='r', kind="index"):
'''
Given the specified configuration, opens the index for reading or
writing. It transparently handles if the index is encrypted and/or
- compressed, returning a file object reading to use.
+ compressed, returning a file object ready to use.
+
+ :param kind: Role of file. The only special value is “info”
+ which sets the appropriate counter in the crypto
+ layer.
+ :type kind: str
'''
filemode = None
encver = None
if 'aes' in self.index_mode:
- encver = 1
+ encver = I2N_XXX_ENCRYPTION_VERSION
+ counter = None
+ if kind == "info": # fixed counter
+ counter = crypto.AES_GCM_IV_CNT_INFOFILE
return tarfile._Stream(name=path, mode=mode, comptype=comptype,
- bufsize=tarfile.RECORDSIZE, fileobj=None,
- encver=encver, password=self.password)
+ bufsize=tarfile.RECORDSIZE, fileobj=None,
+ encver=encver, enccounter=counter,
+ password=self.password)
def create_full_backup(self, source_path, backup_path,
max_volume_size=None, extra_data=dict()):
remainder = -1 # track size in encrypted entries
def __init__(self, name, mode, comptype, fileobj, bufsize,
- concat_stream=False, encver=None, password=None,
+ concat_stream=False,
+ encver=None, enccounter=None, password=None,
nacl=None, compresslevel=9):
"""Construct a _Stream object.
"""
self.encryption = None
self.lasthdr = None
+ enccounter = enccounter or crypto.AES_GCM_IV_CNT_DATA
+
try:
if comptype == "gz":
try:
try:
enc = crypto.Encrypt (password,
I2N_XXX_ENCRYPTION_VERSION, nacl,
- counter=crypto.AES_GCM_IV_CNT_DATA)
+ counter=enccounter)
except ValueError as exn:
raise InvalidEncryptionError \
("ctor failed crypto.Encrypt(<PASSWORD>, “%s”, %r)"
try:
enc = crypto.Encrypt (password,
I2N_XXX_ENCRYPTION_VERSION, nacl,
- counter=crypto.AES_GCM_IV_CNT_DATA)
+ counter=enccounter)
except ValueError as exn:
raise InvalidEncryptionError \
("ctor failed crypto.Encrypt(<PASSWORD>, “%s”, %r)"