hsh, nacl, params = scrypt_hashsource (pw, ins)
import json
- out = json.dumps ({ "salt" : str (binascii.hexlify (nacl))
- , "hash" : str (binascii.hexlify (hsh))
+ out = json.dumps ({ "salt" : binascii.hexlify (nacl).decode ()
+ , "hash" : binascii.hexlify (hsh).decode ()
, "scrypt_params" : { "N" : params ["N"]
, "r" : params ["r"]
, "p" : params ["p"]
import binascii
import hashlib
+import json
import os
+import subprocess
from deltatar import crypto
from deltatar.tarfile import TarFile, GNU_FORMAT
assert hash == self.md5sum("big")
+ def test_cli_scrypt (self):
+ """
+ Create an encrypted archive, then have crypto.py extract the
+ scrypt hash from it.
+ """
+ pw = "It goes baah, it is a sheep."
+ nacl = hashlib.md5 ("Stráðu á mig salti".encode ()).digest ()
+
+ # create the content of the file to compress and hash it
+ _void = self.create_file("big", 50000)
+
+ # create the encryption handler
+ encryptor = crypto.Encrypt (password=pw, nacl=nacl,
+ version=DELTATAR_HEADER_VERSION,
+ paramversion=DELTATAR_PARAMETER_VERSION)
+
+ # create the tar file with volumes
+ tarobj = TarFile.open("sample.tar.gz.pdtcrypt",
+ mode="w#gz",
+ format=GNU_FORMAT,
+ encryption=encryptor)
+ tarobj.add("big")
+ tarobj.close()
+ os.unlink("big")
+
+ # decrypt outer archive layer with crypto.py
+ assert os.path.exists("sample.tar.gz.pdtcrypt")
+ with subprocess.Popen ( [ "python3", "./deltatar/crypto.py"
+ , "scrypt", "-i", "sample.tar.gz.pdtcrypt" ]
+ , env={ "PDTCRYPT_PASSWORD" : pw }
+ , stdout=subprocess.PIPE
+ ) as p:
+ raw = p.stdout.read ().strip ().decode ()
+
+ info = json.loads (raw)
+ assert nacl == binascii.unhexlify (info ["salt"])
+ key = binascii.unhexlify (info ["hash"])
+ kdf = crypto.kdf_by_version (1)
+ assert key, nacl == kdf (pw.encode (), nacl)
+
+
def test_cli_multiple_files_decrypt_pw_argv (self):
"""
Create a tar file with multiple files inside, using concat