sabeechen / decrypt-ha-backup

Decrypts password protected Home Assistant Backups
The Unlicense
23 stars 4 forks source link

Permission denied issue #3

Closed RY00 closed 10 months ago

RY00 commented 10 months ago

Hi,

I ran into a permission denied issue while trying to decrypt an HA backup by using your module: d:>python -m decrypt-ha-backup Partial_2023_10_17_00_00_14.tar --password XXXXXXXXXXXX --output_file test.tar Extracting 'File editor' 100.0% Decrypting 'File editor'Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\decrypt-ha-backup__main.py", line 247, in main() File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\decrypt-ha-backup__main__.py", line 232, in main archive.addTo(output, _key) File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\decrypt-ha-backup__main__.py", line 175, in addTo with securetar.SecureTarFile(Path(extracted.name), "r", key=key, gzip=self._backup.compressed) as decrypted: File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\securetar\init.py", line 73, in enter__ self._file = os.open(self._name, file_mode, 0o666) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied: 'C:\Users\XXXXX\AppData\Local\Temp\tmppdomf_kn'

I'm on Windows, using python 3.12 from an admin cmd.

Regard,

sabeechen commented 10 months ago

This looks like a bug on windows specifically, with how the script handles its temp files. I'll need to make a fix, but in the meantime if you're able to run it on linux its doesn't seem to be a problem there.

sabeechen commented 10 months ago

I've sorted this exception,but something more is wrong with decryption on windows. With the same version of all its dependent libraries installed, it produces garbage data. This is proving rather difficult to figure out.

sabeechen commented 10 months ago

I sorted it out, an underlying library was reading files wrong in windows, something about newlines I think. That was unpleasant to debug.

You shouldbe able to use it on windows now if you update with pip or install the new version explicitly, eg:

pip install decrypt-ha-backup==2023.10.28.1

Let me know if you run into problems with it.

RY00 commented 10 months ago

Hi,

Sorry for the late reply. I try to use the new 2023.10.28.1 and now I got: d:>python -m decrypt-ha-backup Partial_2023_10_17_00_00_14.tar --password XXXXXXXXXXXX b'H\xbf\xdb\xee\x01\xbe\x96\xc0z\xfe)\xaa\xc5\xf4]\xca' Extracting 'File editor' 100.0% Decrypting 'File editor'The file could not be read as a gzip file. Please ensure your password is correct.

By the way I sucessfull decrypt a backup with the previous version by using wsl2. Regard,

sabeechen commented 10 months ago

Well shit, I'm pretty sure thats the same newlines problem again if you were able to run it successfully on linux. I'll need to post a warning about windows until I can sort it out.