-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to encrypt media files before uploading #821
Conversation
import files from master implement encryption options move GenerateKeys out of encrypt.py, add key_path to settings add memlimit option to generateKeys, use motioneye conf_path for key retrieval generateKeys.py: backup existing key files make generateKeys.py non-interactive, introduce option to upload unencrypted files to cloud in case encryption fails more logging add --directory option to generateKeys remove whitespace add decryption tool add option to remove unencrypted source file fix removeSourceFile function store memlimit in keyfile simplify write operations, add shebang to decrypt.py add shebang to generateKeys.py simplify file operations move encryption options to file storage options, add --file parameter to decrypt.py remove -d parameter from decrypt.py, add --directory and --file instead don't throw traceback if decryption of a file fails move decryption script to motioneye folder modify code to fit rest of motionEye, add entry point for key generation tool to setup.py pass mem to write_private_key use current version of main.js from dev branch add pynacl to Dockerfile add python-dev to Dockerfile.armv7-armhf add gcc6 and libffi-dev to Dockerfile.armv7-armhf use gcc-arm-linux-gnueabihf instead of gcc6 use build-essential instead of gcc-arm-linux-gnueabihf in Dockerfile.armv7-armhf add new .travis.yml from dev add new main.js from dev dont remove obsolete whitespace in main.js
Do you already have some feedback on this PR, @ccrisan ? |
The reasons why I don't like this PR are:
Long story short, there's a lot of new code that brings relatively little functionality for a limited number of users, potentially affecting performance. Otherwise, the code is well written and follows the various conventions used in motionEye. It appears to be doing the job correctly, as expected. I am not closing this PR right away. Let's wait for more feedback from the community on this matter and, if a significant number of users express their needs for this feature, we'll reconsider merging it, after a few small changes. |
I understand your concerns and appreciate the feedback. Performance:
UI:
Additional dependency:
Use case/general:
Since I see your points regarding your reluctance to include this feature, I'd propose to proceed as follows. Firstly, I'd like to wait for feedback from the community as well. Who knows what it might bring. Then, I'd write a little article for the Wiki on using that together with motioneye in case any users want to implement this in the future. Of course, it's still up to you whether to include the article then. ;-) |
Sounds like a plan! The idea of having a separate piece of code that works well with motionEye and that is documented in a Wiki article sounds even greater. |
A separate piece of code that integrates well with Motioneye would be my preference. I'm curious for your stated use case : do courts care about authentication and time? So, if you were to integrate trusted time stamping, a court would know with certainty exactly when video was filmed. Seems pretty useful, but does it matter to the court? Also, it's clear that keeping a private key on the pi would be bad if it gets ripped off, but using a public key to encrypt takes authentication off the table. Again, would a court care? I imagine it's not an issue, given that footage of your house is pretty compelling evidence that you are in fact filming your house, but I know very little about the law, which can be surprising and strange at times :-\ Anyway, I appreciate you working on something to help the ecosystem and will definitely be following! |
personally, I think this should be a optional thing but my advise would be to alert/warn the user before doing so...Something on the lines of:
Anyway good work @va1entin |
Thanks for the feedback everyone! As suggested I took the code and made a python module called "plasm" from it. I've been using it for about two weeks now with motionEye on Raspbian. To install plasm, create a key pair and patch motionEye to use it, you can use the following commands: Download and installation $ wget https://github.com/va1entin/plasm/archive/refs/heads/master.zip -O plasm-master.zip $ unzip plasm-master.zip $ cd plasm-master $ pip install . Key pair creation $ python >>> from plasm import gen_keys >>> gen_keys.generate_key_pair('/path/to/private.key', '/path/to/public.key', 'password') Customizing the patch 26a27 > from plasm import encrypt 875a877 > filename = encrypt.encrypt_file(filename, '/etc/plasm/public.key') You can customize the patch to use a public key file from another path or remove unencrypted input files after successful encryption. By default input files are kept. The patch would look likes this then: 26a27 > from plasm import encrypt 875a877 > filename = encrypt.encrypt_file(filename, '/different/path/to/public.key', remove_input_file=True) Applying the patch systemctl stop motioneye.service patch /usr/local/lib/python2.7/dist-packages/motioneye/uploadservices.py motioneye-uploadservices.patch rm /usr/local/lib/python2.7/dist-packages/motioneye/uploadservices.pyc systemctl start motioneye.service |
I added an encryption module, which allows users to automatically encrypt their videos and photos before uploading them to an external file storage such as Google Drive.
It requires PyNaCl version 1.2.0 or greater and works as follows:
Execute
meyeGenerateKeys --directory /etc/motioneye
to generate a key pair. The private key is encrypted with a password and used to decrypt the files, the public key is used to encrypt the files.meyeGenerateKeys uses over 500mb of RAM to encrypt the key by default. With the option
--memlimit
a smaller value can be specified for computers such as the Raspberry Pi 1, which has only 512 mb of RAM in total.Once the keys have been created and the public key has been placed in the motionEye config directory, three options below file storage can be used. They're all set to False by default.
The private key can be removed from the device completely and stored in a safe location because it is not needed for encryption. This way a device can be stolen and nobody will be able to decrypt the media files on it, if the user has set both "Encrypt files before cloud upload" and "Remove unencrypted files after encryption" to True.
To decrypt files
meyeDecrypt
can be used. It works as follows:meyeDecrypt -k /path/to/private.key --file /path/to/file.mp4.crypt
or to decrypt all files ending with .crypt in a directory:
meyeDecrypt -k /path/to/private.key --directory /path/to/dir
If there are any questions feel free to ask!