mrworf / iceshelf

A simple tool to allow storage of signed, encrypted, incremental backups using Amazon's Glacier storage
GNU General Public License v2.0
32 stars 8 forks source link

Encrypt failed #1

Closed Jonny007-MKD closed 8 years ago

Jonny007-MKD commented 8 years ago

Hi,

I'm trying to set up iceshelf and get the following exception:

Encrypting archive
Traceback (most recent call last):
File "/home/osmc/build/iceshelf/iceshelf", line 426
files = gatherData()
File "/home/osmc/build/iceshelf/iceshelf", line 217
gpg.encrypt_file(
AttributeError: 'GPG' object has no attribute 'encrypt_file'

I'm running Jessie and python 2.7. pip says I've got gnupg version 2.0.2

Can you help me?

mrworf commented 8 years ago

Did you install the gnupg python module using with apt-get or with pip? Because apt-get will unfortunately get you an older version (even if it says 2.0.2) which lacks this function. (see https://pythonhosted.org/python-gnupg/#encryption )

Jonny007-MKD commented 8 years ago

I (thought I) used pip as you said in the README. How can I reinstall it?

mrworf commented 8 years ago

Hmm... you're also running on jessie, let me do a clean install tonight on jessie and see if anything has changed since I last set it up. It's a bit unfortunate that there are various versions of the gnupg which differ so much :(

Sorry, I'll update tomorrow once I've tested it.

If you want to uninstall the gnupg version, try "sudo pip uninstall gnupg" ... maybe you got both the apt version and the pip and the pip version was overwritten by apt's version? (speculating)

Jonny007-MKD commented 8 years ago

Hi,

thanks for your quick response! In pip I installed python-gnupg and uninstalled gnupg. Now encrypting did work =)

Perhaps this is something for a trubleshooting section?

Jonny007-MKD commented 8 years ago

Now I got another error and it seems to be related as it works without encryption

Encrypting archive
Signing archive
Traceback (most recent call last):
File "build/iceshelf/iceshelf", line 426, in <module>
    files = gatherData()
File "build/iceshelf/iceshelf", line 229, in gatherData
    with open(file_archive, 'rb') as fp:
IOError: [Errno 2] No such file or directory: '/raid/Temp/iceshelf/20160311-231300-be819.tar.bz2.gpg'

The temp dir only contains a JSON file, nothing ekse

mrworf commented 8 years ago

Thanks for finding this one, my testsuite was not using encryption (to save time) so I completely missed that if the archive generator doesn't find any changes to save, it will start failing with encryption enabled. This is of course not OK, so now it runs two times, with or without encryption and soon also with or without signature.

I've also updated the README.md with CORRECT instructions (sorry, it was pip install python-gnupg not pip install gnupg, why there are two versions with the same python name, I don't know). Also added to the faq so people making this mistake have some insight into how to fix it.

Please pull latest and let me know if you still have issues.

Jonny007-MKD commented 8 years ago

I still had the same error (file not found). Then I found this note for encrypt_file:

Any public key provided for encryption should be trusted, otherwise encryption fails but without any warning.

Trusting the key solved this error. So I suggest you check after encrypting whether the file exists and raise an error with the trust as possible cause.

Now I'm at the next step :) I've got PAR enabled and get this error:

Encrypting archive
Signing archive
Output:
Error : You must specify a list of files when creating.

Code  : 3
Unable to create PAR2 file for this archive
Failed to gather all data and compress it.
mrworf commented 8 years ago

I really apologize for all the issues you're running in to and I appreciate the patience. All too easy to miss things when you have a running setup. I think the PAR error is the same issue as the encrypt. I'll check that in about 20min. As for the key, yes, you're right, I need to deal with non-existing keys properly (what? doesn't everyone have it running before running it?? ;))

mrworf commented 8 years ago

I've added a bit more debugging to this, including the filename leading up to it. Would you mind pull:ing again and running it?

mrworf commented 8 years ago

Just out of curiousity, how are you providing the key to the encryption/signing settings? I've been using the email and the gpg vault of the linux account and after creating the pair with gpg --gen-key I never had the trust issue you mention, so I just want to understand when this happens :)

Jonny007-MKD commented 8 years ago

This is absolutely no problem :) I don't want to complain about errors, I want to assist you in finding them ;) After all this is issue #1!

I created my keypair on my desktop and imported only the public key on the backup machine. I had the same trust issues with gpgit for mails, so I should have thought about this :D

I'll try again in a few hours, thank you very much!

Jonny007-MKD commented 8 years ago

Again it was my fault. As I said I only imported the public key, not the private key on the backup machine. So gpg --sign failed:

$:~/build/iceshelf$ gpg -u test@somewhere.bla --sign
    gpg: skipped "test@somewhere.bla": secret key not available
    gpg: signing failed: secret key not available
$:~/build/iceshelf$ echo $?
    2

This exit/error code should be tested after signing. Now it's working :+1: Thank you!

Jonny007-MKD commented 8 years ago

My next problem (I had to fix my Glacier permissions first) :) I will append it here even if it isn't related:

Creating vault "Music-Backup"
Vault created
Uploading 6 files (62K) to glacier, this may take a while
Traceback (most recent call last):
File "/home/osmc/build/iceshelf/iceshelf", line 478, in <module>
    backup = glacier.uploadFiles(config, files, totalbytes)
File "/home/osmc/build/iceshelf/glacier.py", line 19, in uploadFiles
    cmd.append(os.path.join(config["prepdir"], f))
NameError: global name 'os' is not defined
Jonny007-MKD commented 8 years ago

Solution: Import os.path and time in glacier.py

import os.path
import time
mrworf commented 8 years ago

Yeah, the sign test was a copy'n'paste error :( ... fixed that one and the missing imports. The sign test will make sure you don't have an issue with missing key. The api for gnupg doesn't seem to return a documented object, which is why I don't test the result, which is bad. I could (like you said) test that the call produced a new file, which is what I'll do.

mrworf commented 8 years ago

I now test the keys provided as well as do better handling of gnupg vs pythin-gnupg (it actually is supposed to detect the wrong module now, yay!). Are you ok with closing this issue?

Jonny007-MKD commented 8 years ago

Yep, that's fine :)