Skip to content

Commit 44bd5c6

Browse files
committed
speed up decryption: only add relevant keystore entries to encrypted pages.
username/password pairs are added in total, because relevant entry can be found.
1 parent 1154b43 commit 44bd5c6

File tree

9 files changed

+18
-30
lines changed

9 files changed

+18
-30
lines changed

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ plugins:
338338
# - 'logo.svg'
339339
```
340340

341-
title: Features
342-
343341
# Features
344342

345343
### Override default templates
@@ -486,8 +484,6 @@ However if `sharelinks: True` is enabled in the plugin configuration you can gen
486484
> Then another condition applies: If non-aphanumeric characters are used in user/password,
487485
> they need to be URLencoded (f.ex. %20 = space character). Some browsers may do that automatically (Do a copy/paste from the browsers address bar then).
488486

489-
title: Modify pages
490-
491487
## Modify generated pages
492488

493489
### Encrypt something
@@ -662,8 +658,6 @@ It ends with `///`. The meta tag `inject_id` defines which div id we would like
662658
(it also injects the decryption form here). And the div id found at `delete_id` will be deleted
663659
on successful decryption.
664660

665-
title: Search encryption
666-
667661
## Search encryption
668662

669663
### Search index encryption
@@ -733,8 +727,6 @@ pip install --force-reinstall .
733727

734728
> Note: this currently doesn't work with mkdocs-material-9.x.x
735729

736-
title: Javascript extensions
737-
738730
## Javascript extensions
739731

740732
### Reload user-defined scripts
@@ -855,8 +847,6 @@ graph LR
855847
````
856848

857849

858-
title: Security
859-
860850
## Security
861851

862852
### Crypto-js or webcrypto?

documentation/decrypt-form.tpl.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h1>{{ summary }}</h1>
2525
<p id="mkdocs-decrypt-msg"></p>
2626
</form>
2727
</div>
28-
28+
<div id="encryptcontent-info"></div>
2929
<script type="text/javascript">
3030
var encryptcontent_id = "{{ encryptcontent_id }}";
3131
var encryptcontent_path = "{{ encryptcontent_path }}";
@@ -39,3 +39,7 @@ <h1>{{ summary }}</h1>
3939
<script type="text/javascript" src="{{ library }}"></script>
4040
{%- endfor %}
4141
<script type="text/javascript" src="{{ base_path }}assets/javascripts/decrypt-contents.js" defer></script>
42+
<script>
43+
var encryptcontent_info = document.getElementById('encryptcontent-info');
44+
encryptcontent_info.innerHTML = '<b>keystore length:</b> '+ encryptcontent_keystore.length + '<br>encryptcontent id:<b>:</b> ' + encryptcontent_id;
45+
</script>

documentation/docs/features/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
title: Features
2-
31
# Features
42

53
### Override default templates

documentation/docs/features/jsext.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
title: Javascript extensions
2-
31
## Javascript extensions
42

53
### Reload user-defined scripts

documentation/docs/features/modifypages.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
title: Modify pages
2-
31
## Modify generated pages
42

53
### Encrypt something

documentation/docs/features/search.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
title: Search encryption
2-
31
## Search encryption
42

53
### Search index encryption

documentation/docs/features/security.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
title: Security
2-
31
## Security
42

53
### Crypto-js or webcrypto?

documentation/mkdocs.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ nav:
2424
- 'usage.md'
2525
- Features:
2626
- 'features/index.md'
27-
- 'features/modifypages.md'
28-
- 'features/search.md'
29-
- 'features/jsext.md'
30-
- 'features/security.md'
27+
- Modify pages: 'features/modifypages.md'
28+
- Search encryption: 'features/search.md'
29+
- Javascript extensions: 'features/jsext.md'
30+
- Security: 'features/security.md'
3131
- How does it work?: 'explanations.md'
3232
- Test bench:
3333
- 'testbench/index.md'

encryptcontent/plugin.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,34 +254,38 @@ def __encrypt_content__(self, content, base_path, encryptcontent_path, encryptco
254254
obfuscate_password = None
255255
encryptcontent_id = ''
256256

257+
encryptcontent_keystore = []
258+
257259
if encryptcontent['type'] == 'password':
258260
# get 32-bit AES-256 key from password_keys
259261
key = encryptcontent['key']
260262
keystore = self.setup['password_keys'][encryptcontent['password']]
261263
encryptcontent_id = keystore['id']
262-
encrypted_keystore = self.setup['keystore_password']
264+
encryptcontent_keystore.append(self.setup['keystore_password'][(KS_PASSWORD, encryptcontent['password'])])
263265
elif encryptcontent['type'] == 'level':
264266
# get 32-bit AES-256 key from level_keys
265267
key = encryptcontent['key']
266268
keystore = self.setup['level_keys'][encryptcontent['level']]
267269
encryptcontent_id = keystore['id']
268270
if keystore.get('uname'):
269271
encrypted_keystore = self.setup['keystore_userpass']
272+
for entry in encrypted_keystore: # might as well add all credentials as keystore can be found by user name
273+
encryptcontent_keystore.append(encrypted_keystore[entry])
270274
uname = 1
271275
else:
272276
encrypted_keystore = self.setup['keystore_password']
277+
for entry in encrypted_keystore:
278+
if entry[1] in self.setup['password_inventory'][encryptcontent['level']]:
279+
encryptcontent_keystore.append(encrypted_keystore[entry])
273280
elif encryptcontent['type'] == 'obfuscate':
274281
# get 32-bit AES-256 key from obfuscate_keys
275282
key = encryptcontent['key']
276283
keystore = self.setup['obfuscate_keys'][encryptcontent['obfuscate']]
277284
encryptcontent_id = keystore['id']
278-
encrypted_keystore = self.setup['keystore_obfuscate']
285+
encryptcontent_keystore.append(self.setup['keystore_obfuscate'][(KS_OBFUSCATE, encryptcontent['obfuscate'])])
279286
obfuscate = 1
280287
obfuscate_password = encryptcontent['obfuscate']
281288

282-
encryptcontent_keystore = []
283-
for entry in encrypted_keystore:
284-
encryptcontent_keystore.append(encrypted_keystore[entry])
285289

286290
inject_something = encryptcontent['inject'] if 'inject' in encryptcontent else None
287291
delete_something = encryptcontent['delete_id'] if 'delete_id' in encryptcontent else None

0 commit comments

Comments
 (0)