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
Plugin encrypt #385
Plugin encrypt #385
Conversation
Demo: https://dbw9580.github.io/sigal-encrypt-demo/ |
Looks cool, thanks! |
Do you think you could add some tests, building the gallery with the example settings and checking that images are indeed encrypted? |
Definitely a good idea. I'll work on that.
So I was trying to create some tests, but not sure about how fine granularity it is suitable for such a plugin. So basically what the test should look like is first build the sample gallery, encrypt several pictures and decrypt them in-place to see if decryption works out with no error, right? As for the javascript parts of code, I am not sure how to test them properly. |
Yes, something like this. Testing that some images are indeed encrypted, and maybe that they can be descrypted with the Python decrypt code that you included ? Lines 9 to 19 in 0d8a3c8
Yeah that's doable but it's a lot of work so I never went into this. |
Codecov Report
@@ Coverage Diff @@
## master #385 +/- ##
==========================================
- Coverage 87.49% 86.28% -1.21%
==========================================
Files 19 22 +3
Lines 1503 1750 +247
==========================================
+ Hits 1315 1510 +195
- Misses 188 240 +52
Continue to review full report at Codecov.
|
I rewrote most of the frontend code with Service Worker. The decryption process is now (almost) transparent to the gallery app and the user. Image Speaking of original images, I find that they are handled differently than the resized ones and the thumbnails, in terms of how they end up where they belong in the output directory. They are copied here: Line 120 in 0d8a3c8
while the resized and thumbnails are directly saved from PIL here: Line 144 in 0d8a3c8
and here: Line 163 in 0d8a3c8
This means if I were to use signals to handle the encryption, I would need one signal for the original files, and another for the resized and thumbnails. Which seems a little overkill to me. Your thoughts? |
@saimn I've added the test. I think this PR is ready for review. |
… setup until window load
Looks very good, thanks for the hard work in this !
I will try to review more carefully in the coming days.
sigal/plugins/encrypt/encrypt.py
Outdated
``kdf_iters`` defaults to 10000. Do not specify them in the config file unless | ||
you have good reasons to do so. | ||
- ``encrypt_symlinked_originals``: Force encrypting original images even if they | ||
are symlinked. If you don't know what it means, leave it to ``False``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be True by default, and we could maybe even remove this setting (and send a warning that orig_link should not be used in this case). When using this plugin clearly the goal is to protect privacy by encrypting all images including the original ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but we need to also make sure people don't get their original pictures overwritten if they accidentally have both keep_orig
and orig_link
set to True
, and have not made a backup. I think it's better we abort the encryption and send a warning, to make sure the user understands the situation, then it's up to them to decide. It's trivial to restart an aborted gallery build, while to recover the originals by decrypting them is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! So I think you can remove this setting ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove it from the doc or the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove from the code, as you said above we should abort if keep_orig
and orig_link
are True, so I don't think we should keep this setting to force encryption. People should just choose between orig_link
and using this plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Changed in a3b0876.
More comments, mostly minor ones but I think the error handling in the Python code could be improved. The Abort exception used everywhere makes it a bit difficult to follow the error cases. You should use standard exceptions when possible (e.g. missing or invalid parameter), and reserve use of an exception specific to the plugin for problems with the encryption. And in particular I think the plugin should always fail the build if something could prevent encyption of the files.
It occurs to me that the |
Remove from the doc?
2020年4月18日 10:23, 10:23,在 Simon Conseil <notifications@github.com> 已写:
@saimn commented on this pull request.
…________________________________
In sigal/plugins/encrypt/encrypt.py<http://encrypt.py>:
+ 'kdf_iters': 10000, + 'encrypt_symlinked_originals': False + } + +-
``password``: The password used to encrypt the images on gallery build,
+ and decrypt them when viewers access the gallery. No default value.
You must + specify a password. +- ``ask_password``: Whether or not
viewers are asked for the password to view + the gallery. If set to
``False``, the password will be present in the HTML files + so the
images are decrypted automatically. Defaults to ``False``. +-
``gcm_tag``, ``kdf_salt``, ``kdf_iters``: Cryptographic parameters used
when + encrypting the files. ``gcm_tag``, ``kdf_salt`` are meant to be
randomly generated, + ``kdf_iters`` defaults to 10000. Do not specify
them in the config file unless + you have good reasons to do so. +-
``encrypt_symlinked_originals``: Force encrypting original images even
if they + are symlinked. If you don't know what it means, leave it to
``False``.
Agreed! So I think you can remove this setting ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
theme_path = os.path.join(settings["destination"], 'static') | ||
copy(os.path.join(ASSETS_PATH, "decrypt.js"), theme_path, symlink=False, rellink=False) | ||
copy(os.path.join(ASSETS_PATH, "keycheck.txt"), theme_path, symlink=False, rellink=False) | ||
copy(os.path.join(ASSETS_PATH, "sw.js"), settings["destination"], symlink=False, rellink=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why sw.js
is not in the static directory with the other static files ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per Service Worker specification, the worker script has no access to resources outside its directory tree. So putting sw.js
in static
will break it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the info!
Great job, thanks @dbw9580 ! |
This plugin adds support for password-protected galleries. Images are encrypted using a password during the build, and then decrypted in browser when they are accessed by viewers if they can provide the correct password.
Summaries:
decrypt.js
is tested to work with all 3 themes bundled with Sigal, on Chrome and Firefox;