hexo-blog-encrypt 3.1.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/ReadMe.md +117 -16
- package/ReadMe.zh.md +103 -15
- package/index.js +2 -169
- package/lib/hbe.blink.html +16 -3
- package/lib/hbe.bundle.js +2 -0
- package/lib/hbe.bundle.js.map +7 -0
- package/lib/hbe.default.html +16 -3
- package/lib/hbe.flip.html +16 -3
- package/lib/hbe.shrink.html +16 -3
- package/lib/hbe.style.css +106 -1
- package/lib/hbe.surge.html +16 -3
- package/lib/hbe.up.html +16 -3
- package/lib/hbe.wave.html +16 -3
- package/lib/hbe.xray.html +16 -3
- package/package.json +27 -4
- package/src/server/config.js +162 -0
- package/src/server/crypto.js +67 -0
- package/src/server/generator.js +97 -0
- package/src/server/index.js +180 -0
- package/src/server/logger.js +60 -0
- package/src/server/template.js +135 -0
- package/.editorconfig +0 -14
- package/.eslintrc.js +0 -11
- package/.github/CONTRIBUTING.md +0 -22
- package/.github/ISSUE_TEMPLATE.md +0 -15
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -10
- package/lib/hbe.js +0 -297
package/LICENSE
CHANGED
package/ReadMe.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# hexo-blog-encrypt
|
|
2
2
|
|
|
3
|
-
](https://github.com/D0n9X1n/hexo-blog-encrypt/releases)
|
|
4
|
+
[](https://www.npmjs.com/package/hexo-blog-encrypt)
|
|
5
|
+
[](https://www.npmjs.com/package/hexo-blog-encrypt)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](https://github.com/D0n9X1n/hexo-blog-encrypt/actions/workflows/test.yml)
|
|
8
|
+
[](https://d0n9x1n.github.io/hexo-blog-encrypt/)
|
|
6
9
|
|
|
7
10
|
[中文说明](./ReadMe.zh.md)
|
|
8
11
|
|
|
@@ -18,23 +21,96 @@
|
|
|
18
21
|
|
|
19
22
|
## Features
|
|
20
23
|
|
|
21
|
-
- Once you enter the correct password,
|
|
24
|
+
- Once you enter the correct password, the encrypted post is decrypted client-side. By default the password is **not** persisted; opt in with `autoSave: true` (per-post or in `_config.yml`) to have a derived key cached in `localStorage` so a subsequent reload of the same page auto-decrypts. If there are scripts in the post, they will be executed once the post is decrypted.
|
|
22
25
|
|
|
23
26
|
- Support preset tag-specified password.
|
|
24
27
|
|
|
25
28
|
- All functions are provided by the native APIs. We use [Crypto](https://nodejs.org/dist/latest-v12.x/docs/api/crypto.html) in Node.js, and use [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) in Browsers.
|
|
26
29
|
|
|
27
|
-
- [PBKDF2](https://tools.ietf.org/html/rfc2898)
|
|
30
|
+
- [PBKDF2](https://tools.ietf.org/html/rfc2898) with [SHA-256](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) is used to derive keys, and we use [AES-256-GCM](https://csrc.nist.gov/publications/detail/sp/800-38d/final) for both encryption and authenticated decryption — the GCM auth tag detects any modification of the ciphertext (replacing the v3 separate HMAC step).
|
|
28
31
|
|
|
29
32
|
- Promise is widely used to make sure our main procedures are asynchronous, so that there is little chance for the process to be blocked, and the experience will be more fluent.
|
|
30
33
|
|
|
31
|
-
- Template theme supported, you can use [`default`, `blink`, `flip`, `shrink`, `surge`, `up`, `wave`, `xray`] to set up your template theme, and [CHECK ONLINE](https://
|
|
34
|
+
- Template theme supported, you can use [`default`, `blink`, `flip`, `shrink`, `surge`, `up`, `wave`, `xray`] to set up your template theme, and [CHECK ONLINE](https://d0n9x1n.github.io/hexo-blog-encrypt/tags/theme-demo/).
|
|
32
35
|
|
|
33
36
|
- Outdated browsers may not work well. In such case, please upgrade your browser.
|
|
34
37
|
|
|
35
38
|
## Online demo
|
|
36
39
|
|
|
37
|
-
- See [Demo Page](https://
|
|
40
|
+
- See [Demo Page](https://d0n9x1n.github.io/hexo-blog-encrypt/), **all passwords are `hello`**.
|
|
41
|
+
|
|
42
|
+
## Browser support
|
|
43
|
+
|
|
44
|
+
The runtime uses Web Crypto (`crypto.subtle`), which requires a **secure
|
|
45
|
+
context** (HTTPS or `http://localhost`). Verified:
|
|
46
|
+
|
|
47
|
+
| Browser | Minimum | Notes |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| Chromium / Edge | 92+ | Tested in CI via Playwright |
|
|
50
|
+
| Firefox | 90+ | |
|
|
51
|
+
| Safari (macOS / iOS) | 14+ | Manual smoke at release time |
|
|
52
|
+
|
|
53
|
+
If your site is served over plain HTTP from a non-localhost host,
|
|
54
|
+
decryption will silently fail (`crypto.subtle` is `undefined`). Always
|
|
55
|
+
use HTTPS in production.
|
|
56
|
+
|
|
57
|
+
## Why upgrade from v3?
|
|
58
|
+
|
|
59
|
+
v4 isn't a cosmetic refresh — it closes real security gaps and fixes UX
|
|
60
|
+
problems v3 had. The headline reasons:
|
|
61
|
+
|
|
62
|
+
- **Stronger crypto.** **AES-256-GCM** with a built-in authentication
|
|
63
|
+
tag replaces v3's AES-CBC + separate HMAC. One primitive, one auth
|
|
64
|
+
path, hardware-accelerated, and immune to a class of CBC
|
|
65
|
+
padding-oracle and HMAC-comparison bugs.
|
|
66
|
+
- **Per-post salt + nonce.** v3 used the same salt for every post, so
|
|
67
|
+
the same password derived the same key everywhere. v4 derives an
|
|
68
|
+
independent key per post — an attacker can't amortize one password's
|
|
69
|
+
PBKDF2 work across other posts that share the password.
|
|
70
|
+
- **Stronger KDF defaults.** v3 used **1,024** PBKDF2-SHA256 iterations
|
|
71
|
+
— far below current recommendations and easily amortized across many
|
|
72
|
+
guesses on modern hardware. v4 defaults to **250,000** (≈ 240× more
|
|
73
|
+
work per guess) and recommends 600,000+ (OWASP 2023). Tunable per
|
|
74
|
+
post via `kdf.iterations`.
|
|
75
|
+
- **Privacy by default.** v3 always cached decrypted posts in
|
|
76
|
+
`localStorage`, so anyone with subsequent device access could
|
|
77
|
+
re-read them. v4 defaults to `autoSave: false`; you opt in per post
|
|
78
|
+
or globally.
|
|
79
|
+
- **Inline error messages.** v3 fired a `window.alert()` dialog on a
|
|
80
|
+
wrong password — disruptive, especially on mobile. v4 shows the
|
|
81
|
+
error inline next to the password field (`role="alert"`).
|
|
82
|
+
- **Optional click-to-decrypt button.** Discoverable for visitors who
|
|
83
|
+
don't realise Enter submits the form. Label is configurable.
|
|
84
|
+
- **Smaller bundle.** Drops the bundled CryptoJS dependency in
|
|
85
|
+
favour of the browser's native Web Crypto API. The shipped browser
|
|
86
|
+
bundle is ≈ 6 KB minified.
|
|
87
|
+
- **Tested.** Server suite at 100 % line / branch / function coverage
|
|
88
|
+
+ Playwright e2e across all 8 themes. v3 had effectively zero
|
|
89
|
+
automated tests; v4 is regression-guarded on every push.
|
|
90
|
+
|
|
91
|
+
If you care about offline password guessing against your generated
|
|
92
|
+
HTML, or about shared-device exposure of cached keys — upgrade.
|
|
93
|
+
|
|
94
|
+
The deeper rationale per change lives on the wiki:
|
|
95
|
+
[Migration v3 → v4](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Migration-v3-to-v4).
|
|
96
|
+
|
|
97
|
+
## Upgrading from v3
|
|
98
|
+
|
|
99
|
+
v4 changed the wire format (AES-GCM, per-post salt + nonce). Existing
|
|
100
|
+
encrypted output cannot be read by v4 and vice versa, so:
|
|
101
|
+
|
|
102
|
+
1. Upgrade the plugin: `npm install --save hexo-blog-encrypt@^4`.
|
|
103
|
+
2. Rebuild from source: `hexo clean && hexo generate`.
|
|
104
|
+
3. Purge your CDN if you use one (the post HTML changes byte-for-byte
|
|
105
|
+
on every build by design — fresh nonce per encryption — but the
|
|
106
|
+
runtime asset URL `lib/hbe.<hash>.js` is content-hashed and only
|
|
107
|
+
changes when the bundle changes).
|
|
108
|
+
4. Optional: drop `wrong_hash_message` from your config and front-matter
|
|
109
|
+
(deprecated in v4, removed in v5).
|
|
110
|
+
|
|
111
|
+
No source `.md` files are touched. See [CHANGELOG.md](./CHANGELOG.md)
|
|
112
|
+
for the full breaking-changes list and the new `decryptButton` /
|
|
113
|
+
`autoSave` / `kdf.iterations` options.
|
|
38
114
|
|
|
39
115
|
## Install
|
|
40
116
|
|
|
@@ -77,6 +153,9 @@ password: mikemessi
|
|
|
77
153
|
abstract: Here's something encrypted, password is required to continue reading.
|
|
78
154
|
message: Hey, password is required here.
|
|
79
155
|
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
|
|
156
|
+
# Deprecated under v4 — AES-GCM unifies wrong-password and tampered-ciphertext
|
|
157
|
+
# failures, so this option is now an alias of `wrong_pass_message`. Set
|
|
158
|
+
# `wrong_pass_message` instead.
|
|
80
159
|
wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.
|
|
81
160
|
---
|
|
82
161
|
|
|
@@ -95,8 +174,29 @@ encrypt: # hexo-blog-encrypt
|
|
|
95
174
|
- {name: encryptAsDiary, password: passwordA}
|
|
96
175
|
- {name: encryptAsTips, password: passwordB}
|
|
97
176
|
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
|
|
177
|
+
# Deprecated under v4 (alias of `wrong_pass_message`). See note above.
|
|
98
178
|
wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.
|
|
99
179
|
|
|
180
|
+
# ── v4 keys (all optional, safe defaults) ────────────────────────────
|
|
181
|
+
# Render a visible "Decrypt" button next to the password field.
|
|
182
|
+
# Themes that already include a button via `<%- decrypt_button %>`
|
|
183
|
+
# ignore this option. Default: true.
|
|
184
|
+
decryptButton:
|
|
185
|
+
show: true
|
|
186
|
+
text: Decrypt
|
|
187
|
+
|
|
188
|
+
# Cache the decrypted plaintext in localStorage so reloads skip the
|
|
189
|
+
# password prompt. OFF by default — opt in per post via front-matter
|
|
190
|
+
# `autoSave: true`, or globally here. Cache key is namespaced under
|
|
191
|
+
# `hbe.v4.<post-permalink-hash>`.
|
|
192
|
+
autoSave: false
|
|
193
|
+
|
|
194
|
+
# PBKDF2 iteration count. Floor: 100_000. Recommended ≥ 600_000
|
|
195
|
+
# (OWASP 2023 for PBKDF2-SHA256). Lower-than-recommended values log a
|
|
196
|
+
# warning at build time. Default: 250_000.
|
|
197
|
+
kdf:
|
|
198
|
+
iterations: 250000
|
|
199
|
+
|
|
100
200
|
```
|
|
101
201
|
|
|
102
202
|
#### To disable tag encryption
|
|
@@ -143,7 +243,7 @@ It will be called after the blog is decrypted.
|
|
|
143
243
|
</script>
|
|
144
244
|
```
|
|
145
245
|
|
|
146
|
-
Demo: [Callback Example](https://
|
|
246
|
+
Demo: [Callback Example](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/callback/).
|
|
147
247
|
|
|
148
248
|
### After Decrypt Event
|
|
149
249
|
Thanks to @[f-dong](https://github.com/f-dong), we now will trigger a event named `hexo-blog-decrypt`, so you can add a call back to listen to that event.
|
|
@@ -219,20 +319,21 @@ encrypt: # hexo-blog-encrypt
|
|
|
219
319
|
- {name: encryptAsTips, password: passwordB}
|
|
220
320
|
theme: xray
|
|
221
321
|
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
|
|
322
|
+
# Deprecated under v4 (alias of `wrong_pass_message`); see "Advanced settings".
|
|
222
323
|
wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.
|
|
223
324
|
|
|
224
325
|
```
|
|
225
326
|
|
|
226
327
|
Check them online, and PICK one:
|
|
227
328
|
|
|
228
|
-
+ [default](https://
|
|
229
|
-
+ [blink](https://
|
|
230
|
-
+ [shrink](https://
|
|
231
|
-
+ [flip](https://
|
|
232
|
-
+ [up](https://
|
|
233
|
-
+ [surge](https://
|
|
234
|
-
+ [wave](https://
|
|
235
|
-
+ [xray](https://
|
|
329
|
+
+ [default](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/default/)
|
|
330
|
+
+ [blink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/blink/)
|
|
331
|
+
+ [shrink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/shrink/)
|
|
332
|
+
+ [flip](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/flip/)
|
|
333
|
+
+ [up](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/up/)
|
|
334
|
+
+ [surge](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/surge/)
|
|
335
|
+
+ [wave](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/)
|
|
336
|
+
+ [xray](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/xray/)
|
|
236
337
|
|
|
237
338
|
|
|
238
339
|
## License
|
package/ReadMe.zh.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# hexo-blog-encrypt
|
|
2
2
|
|
|
3
|
-
](https://github.com/D0n9X1n/hexo-blog-encrypt/releases)
|
|
4
|
+
[](https://www.npmjs.com/package/hexo-blog-encrypt)
|
|
5
|
+
[](https://www.npmjs.com/package/hexo-blog-encrypt)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](https://github.com/D0n9X1n/hexo-blog-encrypt/actions/workflows/test.yml)
|
|
8
|
+
[](https://d0n9x1n.github.io/hexo-blog-encrypt/)
|
|
6
9
|
|
|
7
10
|
#### 提 issue 之前,请务必提供复现方式,log,配置信息等必要信息。良好的 issue 可以节省双方的时间。
|
|
8
11
|
*请严格按照模版要求,不明确的 issue 将直接关闭。*
|
|
@@ -24,13 +27,13 @@
|
|
|
24
27
|
|
|
25
28
|
## 特性
|
|
26
29
|
|
|
27
|
-
- 一旦你输入了正确的密码,
|
|
30
|
+
- 一旦你输入了正确的密码, 加密的文章会在浏览器端解密. 默认情况下密码 **不会** 被持久化; 在文章信息头或 `_config.yml` 中设置 `autoSave: true` 之后, 派生出的密钥才会被缓存到 `localStorage`, 这样下次刷新同一页面时就能自动解密. 若文章中含有脚本, 它将会在解密后被正确执行.
|
|
28
31
|
|
|
29
32
|
- 支持按标签加密.
|
|
30
33
|
|
|
31
34
|
- 所有的核心功能都是由原生的 API 所提供的. 在 Node.js中, 我们使用 [Crypto](https://nodejs.org/dist/latest-v12.x/docs/api/crypto.html). 在浏览器中, 我们使用 [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API).
|
|
32
35
|
|
|
33
|
-
- [PBKDF2](https://tools.ietf.org/html/rfc2898)
|
|
36
|
+
- [PBKDF2](https://tools.ietf.org/html/rfc2898) 与 [SHA-256](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) 被用于派生密钥, 我们使用 [AES-256-GCM](https://csrc.nist.gov/publications/detail/sp/800-38d/final) 进行带认证的加解密 — GCM 自带的 auth tag 即可检测密文被篡改 (取代了 v3 中独立的 HMAC 步骤).
|
|
34
37
|
|
|
35
38
|
- 我们广泛地使用 Promise 来进行异步操作, 以此确保线程不被阻塞.
|
|
36
39
|
|
|
@@ -40,7 +43,68 @@
|
|
|
40
43
|
|
|
41
44
|
## 在线演示
|
|
42
45
|
|
|
43
|
-
- 点击 [Demo Page](https://
|
|
46
|
+
- 点击 [Demo Page](https://d0n9x1n.github.io/hexo-blog-encrypt/), **所有的密码都是 `hello`**.
|
|
47
|
+
|
|
48
|
+
## 浏览器支持
|
|
49
|
+
|
|
50
|
+
运行时使用 Web Crypto (`crypto.subtle`), 因此需要 **安全上下文**
|
|
51
|
+
(HTTPS 或 `http://localhost`). 已验证:
|
|
52
|
+
|
|
53
|
+
| 浏览器 | 最低版本 | 备注 |
|
|
54
|
+
| --- | --- | --- |
|
|
55
|
+
| Chromium / Edge | 92+ | CI 中通过 Playwright 自动测试 |
|
|
56
|
+
| Firefox | 90+ | |
|
|
57
|
+
| Safari (macOS / iOS) | 14+ | 发版前手动冒烟 |
|
|
58
|
+
|
|
59
|
+
如果站点是通过非 localhost 的纯 HTTP 提供, 解密会静默失败
|
|
60
|
+
(`crypto.subtle` 为 `undefined`). 生产环境请始终使用 HTTPS.
|
|
61
|
+
|
|
62
|
+
## 为什么要从 v3 升级
|
|
63
|
+
|
|
64
|
+
v4 不是表面的刷新, 而是真正修复了 v3 的安全短板与 UX 痛点. 主要原因:
|
|
65
|
+
|
|
66
|
+
- **更强的密码学.** **AES-256-GCM** 自带的 auth tag 取代了 v3 的
|
|
67
|
+
AES-CBC + 独立 HMAC. 单一原语、单一鉴权路径、硬件加速, 并且免疫一类
|
|
68
|
+
CBC padding-oracle 与 HMAC 比较 bug.
|
|
69
|
+
- **每篇独立 salt + nonce.** v3 所有文章共用同一个 salt — 同样的密码
|
|
70
|
+
到处派生出同样的密钥. v4 每篇独立派生密钥 — 攻击者无法把对一个密码
|
|
71
|
+
的 PBKDF2 计算结果, 复用到其它使用相同密码的文章上.
|
|
72
|
+
- **更强的 KDF 默认值.** v3 默认仅 **1,024** 轮 PBKDF2-SHA256 — 远低于
|
|
73
|
+
现代推荐值, 在现代硬件上很容易被批量爆破均摊. v4 默认 **250,000**
|
|
74
|
+
轮 (≈ 240× 单次工作量), 推荐 ≥ 600,000 (OWASP 2023). 可通过
|
|
75
|
+
`kdf.iterations` 按文章覆盖.
|
|
76
|
+
- **隐私默认关闭.** v3 总是把解密后的密钥缓存到 `localStorage`, 共享
|
|
77
|
+
设备的下一个用户可以直接重看. v4 默认 `autoSave: false`, 你按需开启
|
|
78
|
+
(按文章或全局).
|
|
79
|
+
- **行内错误提示.** v3 用 `window.alert()` 弹窗提示密码错 — 移动端
|
|
80
|
+
尤其打断流程. v4 直接把错误显示在密码框旁边 (`role="alert"`).
|
|
81
|
+
- **可选的"解密"按钮.** 让不知道按 Enter 的访客也能用. 文案可配置.
|
|
82
|
+
- **更小.** 抛弃了打包的 CryptoJS 依赖, 改用浏览器原生 Web Crypto
|
|
83
|
+
API. 浏览器端 bundle ≈ 6 KB (minified).
|
|
84
|
+
- **有测试.** 服务端套件 100% 行 / 分支 / 函数覆盖 + Playwright e2e
|
|
85
|
+
覆盖全部 8 个主题. v3 几乎没有自动化测试; v4 每次推送都跑回归.
|
|
86
|
+
|
|
87
|
+
如果你在意有人能拉到你生成的 HTML 后做离线密码爆破, 或者在意共用
|
|
88
|
+
设备上缓存密钥被偷看 — 请升级.
|
|
89
|
+
|
|
90
|
+
每条变化更深入的"为什么", 见 wiki:
|
|
91
|
+
[Migration v3 → v4](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Migration-v3-to-v4).
|
|
92
|
+
|
|
93
|
+
## 从 v3 升级
|
|
94
|
+
|
|
95
|
+
v4 修改了密文格式 (AES-GCM, 每篇文章独立 salt + 每次加密独立 nonce).
|
|
96
|
+
v3 加密的产物在 v4 下无法解密, 反之亦然. 升级步骤:
|
|
97
|
+
|
|
98
|
+
1. 升级插件: `npm install --save hexo-blog-encrypt@^4`.
|
|
99
|
+
2. 重新生成: `hexo clean && hexo generate`.
|
|
100
|
+
3. 如果使用 CDN, 请清空缓存 (按设计, 每次构建文章 HTML 都会变化 —
|
|
101
|
+
每次加密都使用新的 nonce — 但运行时资源 `lib/hbe.<hash>.js`
|
|
102
|
+
是按内容 hash 命名的, 只有 bundle 改变时 URL 才会变).
|
|
103
|
+
4. 可选: 从 `_config.yml` 与 front-matter 中删除 `wrong_hash_message`
|
|
104
|
+
(v4 起废弃, v5 中删除).
|
|
105
|
+
|
|
106
|
+
不会触碰任何源 `.md` 文件. 完整的 break 列表与新增的 `decryptButton` /
|
|
107
|
+
`autoSave` / `kdf.iterations` 等配置请见 [CHANGELOG.md](./CHANGELOG.md).
|
|
44
108
|
|
|
45
109
|
## 安装
|
|
46
110
|
|
|
@@ -83,6 +147,8 @@ password: mikemessi
|
|
|
83
147
|
abstract: 有东西被加密了, 请输入密码查看.
|
|
84
148
|
message: 您好, 这里需要密码.
|
|
85
149
|
wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
|
|
150
|
+
# v4 起已废弃 — AES-GCM 已经将 “密码错误” 与 “密文被篡改” 这两类失败统一处理,
|
|
151
|
+
# 该字段现在等同于 `wrong_pass_message`. 请改设 `wrong_pass_message`.
|
|
86
152
|
wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
|
|
87
153
|
---
|
|
88
154
|
|
|
@@ -102,8 +168,28 @@ encrypt: # hexo-blog-encrypt
|
|
|
102
168
|
- {name: tagName, password: 密码A}
|
|
103
169
|
- {name: tagName, password: 密码B}
|
|
104
170
|
wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
|
|
171
|
+
# v4 起已废弃 (等同于 `wrong_pass_message`), 详见上方说明.
|
|
105
172
|
wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
|
|
106
173
|
|
|
174
|
+
# ── v4 新配置 (全部可选, 均有安全的默认值) ────────────────────────────
|
|
175
|
+
# 在密码框旁渲染一个可见的 “解密” 按钮.
|
|
176
|
+
# 主题模板若已经通过 `<%- decrypt_button %>` 自带按钮则会忽略本配置.
|
|
177
|
+
# 默认: true.
|
|
178
|
+
decryptButton:
|
|
179
|
+
show: true
|
|
180
|
+
text: 解密
|
|
181
|
+
|
|
182
|
+
# 解密后是否将明文缓存到 localStorage, 让刷新页面跳过密码输入.
|
|
183
|
+
# 默认 OFF — 可在文章 front-matter 中通过 `autoSave: true` 单独开启,
|
|
184
|
+
# 也可以在这里全局开启. 缓存键命名空间为 `hbe.v4.<post-permalink-hash>`.
|
|
185
|
+
autoSave: false
|
|
186
|
+
|
|
187
|
+
# PBKDF2 迭代次数. 下限: 100_000. 推荐 ≥ 600_000
|
|
188
|
+
# (OWASP 2023 关于 PBKDF2-SHA256 的推荐). 低于推荐值时构建会打印 warning.
|
|
189
|
+
# 默认: 250_000.
|
|
190
|
+
kdf:
|
|
191
|
+
iterations: 250000
|
|
192
|
+
|
|
107
193
|
```
|
|
108
194
|
|
|
109
195
|
#### 对博文禁用 Tag 加密
|
|
@@ -149,7 +235,7 @@ It will be called after the blog decrypted.
|
|
|
149
235
|
</script>
|
|
150
236
|
```
|
|
151
237
|
|
|
152
|
-
例子在: [Callback 例子](https://
|
|
238
|
+
例子在: [Callback 例子](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/callback/).
|
|
153
239
|
|
|
154
240
|
### 解密后的触发事件
|
|
155
241
|
感谢 @[f-dong](https://github.com/f-dong), 我们现在会在解密完成后触发一个 `hexo-blog-decrypt` 事件, 你们可以编写 callback 来监听该事件.
|
|
@@ -214,6 +300,7 @@ abstract: 有东西被加密了, 请输入密码查看.
|
|
|
214
300
|
message: 您好, 这里需要密码.
|
|
215
301
|
theme: xray
|
|
216
302
|
wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
|
|
303
|
+
# v4 起已废弃 (等同于 `wrong_pass_message`), 详见 “高级设置”.
|
|
217
304
|
wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
|
|
218
305
|
---
|
|
219
306
|
|
|
@@ -234,20 +321,21 @@ encrypt: # hexo-blog-encrypt
|
|
|
234
321
|
- {name: tagName, password: 密码B}
|
|
235
322
|
theme: xray
|
|
236
323
|
wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
|
|
324
|
+
# v4 起已废弃 (等同于 `wrong_pass_message`), 详见 “高级设置”.
|
|
237
325
|
wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
|
|
238
326
|
|
|
239
327
|
```
|
|
240
328
|
|
|
241
329
|
你可以在线挑选你喜欢的主题,并应用到你的博客中:
|
|
242
330
|
|
|
243
|
-
+ [default](https://
|
|
244
|
-
+ [blink](https://
|
|
245
|
-
+ [shrink](https://
|
|
246
|
-
+ [flip](https://
|
|
247
|
-
+ [up](https://
|
|
248
|
-
+ [surge](https://
|
|
249
|
-
+ [wave](https://
|
|
250
|
-
+ [xray](https://
|
|
331
|
+
+ [default](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/default/)
|
|
332
|
+
+ [blink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/blink/)
|
|
333
|
+
+ [shrink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/shrink/)
|
|
334
|
+
+ [flip](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/flip/)
|
|
335
|
+
+ [up](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/up/)
|
|
336
|
+
+ [surge](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/surge/)
|
|
337
|
+
+ [wave](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/)
|
|
338
|
+
+ [xray](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/xray/)
|
|
251
339
|
|
|
252
340
|
|
|
253
341
|
## 许可
|
package/index.js
CHANGED
|
@@ -1,172 +1,5 @@
|
|
|
1
|
-
/* global hexo
|
|
1
|
+
/* global hexo */
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const log = hexo.log;
|
|
9
|
-
|
|
10
|
-
const defaultConfig = {
|
|
11
|
-
'abstract': 'Here\'s something encrypted, password is required to continue reading.',
|
|
12
|
-
'message': 'Hey, password is required here.',
|
|
13
|
-
'theme': 'default',
|
|
14
|
-
'wrong_pass_message': 'Oh, this is an invalid password. Check and try again, please.',
|
|
15
|
-
'wrong_hash_message': 'OOPS, these decrypted content may changed, but you can still have a look.',
|
|
16
|
-
'silent': false,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const keySalt = textToArray('hexo-blog-encrypt的作者们都是大帅比!');
|
|
20
|
-
const ivSalt = textToArray('hexo-blog-encrypt是地表最强Hexo加密插件!');
|
|
21
|
-
|
|
22
|
-
// As we can't detect the wrong password with AES-CBC,
|
|
23
|
-
// so adding an empty tag and check it when decrption.
|
|
24
|
-
const knownPrefix = "<hbe-prefix></hbe-prefix>";
|
|
25
|
-
|
|
26
|
-
// disable log
|
|
27
|
-
var silent = false;
|
|
28
|
-
// use default theme
|
|
29
|
-
var theme = 'default';
|
|
30
|
-
|
|
31
|
-
hexo.extend.filter.register('after_post_render', (data) => {
|
|
32
|
-
const tagEncryptPairs = [];
|
|
33
|
-
|
|
34
|
-
let password = data.password;
|
|
35
|
-
let tagUsed = false;
|
|
36
|
-
|
|
37
|
-
// use a empty password to disable category encryption
|
|
38
|
-
if (password === "") {
|
|
39
|
-
return data;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (hexo.config.encrypt === undefined) {
|
|
43
|
-
hexo.config.encrypt = [];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if(('encrypt' in hexo.config) && ('tags' in hexo.config.encrypt)){
|
|
47
|
-
hexo.config.encrypt.tags.forEach((tagObj) => {
|
|
48
|
-
tagEncryptPairs[tagObj.name] = tagObj.password;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (data.tags) {
|
|
53
|
-
data.tags.forEach((cTag) => {
|
|
54
|
-
if (tagEncryptPairs.hasOwnProperty(cTag.name)) {
|
|
55
|
-
tagUsed = password ? tagUsed : cTag.name;
|
|
56
|
-
password = password || tagEncryptPairs[cTag.name];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if(password == undefined){
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
password = password.toString();
|
|
66
|
-
|
|
67
|
-
// make sure toc can work.
|
|
68
|
-
data.origin = data.content;
|
|
69
|
-
|
|
70
|
-
// Let's rock n roll
|
|
71
|
-
const config = Object.assign(defaultConfig, hexo.config.encrypt, data);
|
|
72
|
-
silent = config.silent;
|
|
73
|
-
theme = config.theme.trim().toLowerCase();
|
|
74
|
-
|
|
75
|
-
// deprecate the template keyword
|
|
76
|
-
if (config.template) {
|
|
77
|
-
dlog('warn', 'Looks like you use a deprecated property "template" to set up template, consider to use "theme"? See https://github.com/D0n9X1n/hexo-blog-encrypt#encrypt-theme');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// read theme from file
|
|
81
|
-
let template = fs.readFileSync(path.resolve(__dirname, `./lib/hbe.${theme}.html`)).toString();
|
|
82
|
-
|
|
83
|
-
if (tagUsed === false) {
|
|
84
|
-
dlog('info', `hexo-blog-encrypt: encrypting "${data.title.trim()}" based on the password configured in Front-matter with theme: ${theme}.`);
|
|
85
|
-
} else {
|
|
86
|
-
dlog('info', `hexo-blog-encrypt: encrypting "${data.title.trim()}" based on Tag: "${tagUsed}" with theme ${theme}.`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
data.content = knownPrefix + data.content.trim();
|
|
90
|
-
data.encrypt = true;
|
|
91
|
-
|
|
92
|
-
const key = crypto.pbkdf2Sync(password, keySalt, 1024, 32, 'sha256');
|
|
93
|
-
const iv = crypto.pbkdf2Sync(password, ivSalt, 512, 16, 'sha256');
|
|
94
|
-
|
|
95
|
-
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
|
|
96
|
-
const hmac = crypto.createHmac('sha256', key);
|
|
97
|
-
|
|
98
|
-
let encryptedData = cipher.update(data.content, 'utf8', 'hex');
|
|
99
|
-
hmac.update(data.content, 'utf8');
|
|
100
|
-
encryptedData += cipher.final('hex');
|
|
101
|
-
const hmacDigest = hmac.digest('hex');
|
|
102
|
-
|
|
103
|
-
data.content = template.replace(/{{hbeEncryptedData}}/g, encryptedData)
|
|
104
|
-
.replace(/{{hbeHmacDigest}}/g, hmacDigest)
|
|
105
|
-
.replace(/{{hbeWrongPassMessage}}/g, config.wrong_pass_message)
|
|
106
|
-
.replace(/{{hbeWrongHashMessage}}/g, config.wrong_hash_message)
|
|
107
|
-
.replace(/{{hbeMessage}}/g, config.message);
|
|
108
|
-
data.content += `<script data-pjax src="${hexo.config.root}lib/hbe.js"></script><link href="${hexo.config.root}css/hbe.style.css" rel="stylesheet" type="text/css">`;
|
|
109
|
-
data.excerpt = data.more = config.abstract;
|
|
110
|
-
|
|
111
|
-
return data;
|
|
112
|
-
}, 1000);
|
|
113
|
-
|
|
114
|
-
hexo.extend.generator.register('hexo-blog-encrypt', () => [
|
|
115
|
-
{
|
|
116
|
-
'data': () => fs.createReadStream(path.resolve(__dirname, `./lib/hbe.style.css`)),
|
|
117
|
-
'path': `css/hbe.style.css`,
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
'data': () => fs.createReadStream(path.resolve(__dirname, './lib/hbe.js')),
|
|
121
|
-
'path': 'lib/hbe.js',
|
|
122
|
-
},
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
// log function
|
|
126
|
-
function dlog(level, x) {
|
|
127
|
-
switch (level) {
|
|
128
|
-
case 'warn':
|
|
129
|
-
log.warn(x);
|
|
130
|
-
break;
|
|
131
|
-
|
|
132
|
-
case 'info':
|
|
133
|
-
default:
|
|
134
|
-
if (silent) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
log.info(x);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Utils functions
|
|
143
|
-
function textToArray(s) {
|
|
144
|
-
var i = s.length;
|
|
145
|
-
var n = 0;
|
|
146
|
-
var ba = new Array()
|
|
147
|
-
|
|
148
|
-
for (var j = 0; j < i;) {
|
|
149
|
-
var c = s.codePointAt(j);
|
|
150
|
-
if (c < 128) {
|
|
151
|
-
ba[n++] = c;
|
|
152
|
-
j++;
|
|
153
|
-
} else if ((c > 127) && (c < 2048)) {
|
|
154
|
-
ba[n++] = (c >> 6) | 192;
|
|
155
|
-
ba[n++] = (c & 63) | 128;
|
|
156
|
-
j++;
|
|
157
|
-
} else if ((c > 2047) && (c < 65536)) {
|
|
158
|
-
ba[n++] = (c >> 12) | 224;
|
|
159
|
-
ba[n++] = ((c >> 6) & 63) | 128;
|
|
160
|
-
ba[n++] = (c & 63) | 128;
|
|
161
|
-
j++;
|
|
162
|
-
} else {
|
|
163
|
-
ba[n++] = (c >> 18) | 240;
|
|
164
|
-
ba[n++] = ((c >> 12) & 63) | 128;
|
|
165
|
-
ba[n++] = ((c >> 6) & 63) | 128;
|
|
166
|
-
ba[n++] = (c & 63) | 128;
|
|
167
|
-
j += 2;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return new Uint8Array(ba);
|
|
172
|
-
}
|
|
5
|
+
require('./src/server').register(hexo);
|
package/lib/hbe.blink.html
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
<div class="hbe hbe-container" id="hexo-blog-encrypt"
|
|
2
|
-
|
|
1
|
+
<div class="hbe hbe-container" id="hexo-blog-encrypt"
|
|
2
|
+
data-hbe-format="{{hbeFormat}}"
|
|
3
|
+
data-wpm="{{hbeWrongPassMessage}}"
|
|
4
|
+
data-whm="{{hbeWrongHashMessage}}"
|
|
5
|
+
data-salt="{{hbeSalt}}"
|
|
6
|
+
data-nonce="{{hbeNonce}}"
|
|
7
|
+
data-kdf-iterations="{{hbeKdfIterations}}"
|
|
8
|
+
data-auto-save="{{hbeAutoSave}}">
|
|
9
|
+
<script id="hbeData" type="hbeData">
|
|
10
|
+
{{hbeEncryptedData}}
|
|
11
|
+
</script>
|
|
3
12
|
<div class="hbe hbe-content">
|
|
4
|
-
<
|
|
13
|
+
<form id="hbeForm" class="hbe hbe-form" onsubmit="return false">
|
|
14
|
+
<div class="hbe hbe-input hbe-input-blink">
|
|
5
15
|
<input class="hbe hbe-input-field hbe-input-field-blink" type="password" id="hbePass">
|
|
6
16
|
<label class="hbe hbe-input-label hbe-input-label-blink" for="hbePass">
|
|
7
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-blink" data-content="{{hbeMessage}}">{{hbeMessage}}</span>
|
|
8
18
|
</label>
|
|
9
19
|
</div>
|
|
20
|
+
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
21
|
+
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
22
|
+
</form>
|
|
10
23
|
</div>
|
|
11
24
|
</div>
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";(()=>{var y=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var S=y((tt,x)=>{"use strict";function D(e,t){if(!e)return;e.setAttribute("aria-busy",t?"true":"false");let r=e.querySelector(".hbe-button");r&&(r.disabled=!!t);let n=e.querySelector("#hbePass");n&&(n.disabled=!!t)}function C(e,t){let r=e.querySelector('[role="alert"]');if(!r){r=document.createElement("div"),r.setAttribute("role","alert"),r.className="hbe hbe-error";let n=e.querySelector("#hbeForm");n?n.parentNode.insertBefore(r,n.nextSibling):e.appendChild(r)}r.textContent=t}function k(e){let t=e.querySelector('[role="alert"]');t&&(t.textContent="")}function K(e){let t=e.querySelector("#hbePass");return t?t.value:""}function q(e,t){e&&e.addEventListener("submit",r=>{r.preventDefault(),t()})}x.exports={setBusy:D,showError:C,clearError:k,readPassword:K,attachSubmit:q}});var g=y((et,w)=>{"use strict";var M=new TextDecoder("utf-8",{fatal:!0}),O=new TextEncoder;function i(e){let t=e.length;if(t%2!==0)throw new Error("hexo-blog-encrypt: hex string has odd length");let r=new Uint8Array(t/2);for(let n=0;n<r.length;n++)r[n]=parseInt(e.substr(n*2,2),16);return r}async function b(e,t,r){let n=await crypto.subtle.importKey("raw",O.encode(e),{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:t,iterations:r,hash:"SHA-256"},n,{name:"AES-GCM",length:256},!0,["decrypt"])}async function p(e,t,r){let n=await crypto.subtle.decrypt({name:"AES-GCM",iv:t,tagLength:128},e,r);return M.decode(n)}async function N({password:e,saltHex:t,nonceHex:r,ciphertextHex:n,iterations:o}){try{let a=i(t),s=i(r),l=i(n);if(l.length<16)return{ok:!1};let f=await b(e,a,o);return{ok:!0,plaintext:await p(f,s,l),key:f}}catch(a){return{ok:!1}}}async function P({key:e,nonceHex:t,ciphertextHex:r}){try{let n=i(t),o=i(r);return o.length<16?{ok:!1}:{ok:!0,plaintext:await p(e,n,o)}}catch(n){return{ok:!1}}}w.exports={tryDecryptWithPassword:N,tryDecryptWithKey:P,deriveKey:b,decryptWithKey:p,hexToBytes:i}});var T=y((rt,v)=>{"use strict";function m(e){let t=document.createElement("script");for(let r of e.attributes)t.setAttribute(r.name,r.value);return t.text=e.text,t}function E(e){let t=document.createElement("div");t.innerHTML=e;for(let r of t.querySelectorAll("script"))r.parentNode.replaceChild(m(r),r);return t}function R(e,t){let r=E(t);return r.id="hexo-blog-encrypt",r.classList.add("hbe","hbe-decrypted-content"),e.parentNode.replaceChild(r,e),r}v.exports={getExecutableScript:m,convertHTMLToElement:E,swapInDecryptedDOM:R}});var A=y((nt,_)=>{"use strict";var H="hbe.v4.";function u(e){return H+e}function G(e){let t="";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return btoa(t)}function F(e){let t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}async function W({pageKey:e,key:t,saltHex:r,nonceHex:n,autoSave:o}){if(o)try{let a=await crypto.subtle.exportKey("raw",t),s={version:4,dk:G(new Uint8Array(a)),salt:r,nonce:n};localStorage.setItem(u(e),JSON.stringify(s))}catch(a){}}async function L({pageKey:e,expectedSaltHex:t,expectedNonceHex:r}){let n;try{let o=localStorage.getItem(u(e));if(!o)return null;n=JSON.parse(o)}catch(o){return null}if(!n||n.version!==4||typeof n.dk!="string"||typeof n.salt!="string"||typeof n.nonce!="string"||"hmk"in n||"hmacDigest"in n){try{localStorage.removeItem(u(e))}catch(o){}return null}if(n.salt!==t||n.nonce!==r){try{localStorage.removeItem(u(e))}catch(o){}return null}try{let o=F(n.dk);return await crypto.subtle.importKey("raw",o,{name:"AES-GCM"},!0,["decrypt"])}catch(o){try{localStorage.removeItem(u(e))}catch(a){}return null}}function Y(e){try{localStorage.removeItem(u(e))}catch(t){}}_.exports={save:W,load:L,clear:Y,STORAGE_KEY_PREFIX:H,SCHEMA_VERSION:4}});var c=S(),B=g(),U=T(),d=A(),V="4";function X(e){let t=e.dataset,r=e.querySelector("script#hbeData");return{format:t.hbeFormat,wpm:t.wpm||"Wrong password.",whm:t.whm||t.wpm||"Wrong password.",saltHex:t.salt,nonceHex:t.nonce,iterations:parseInt(t.kdfIterations,10)||25e4,autoSave:t.autoSave==="true",ciphertextHex:r?r.textContent.trim():""}}function J(e){try{window.dispatchEvent(new CustomEvent("hexo-blog-decrypt",{detail:{mode:e}}))}catch(t){try{window.dispatchEvent(new Event("hexo-blog-decrypt"))}catch(r){}}}function h(){return location.pathname+location.search}async function j(e,t,r){U.swapInDecryptedDOM(e,t),J(r)}async function z(e,t,r){if(!t.autoSave)return!1;let n=await d.load({pageKey:h(),expectedSaltHex:t.saltHex,expectedNonceHex:t.nonceHex});if(!n)return!1;let o=await B.tryDecryptWithKey({key:n,nonceHex:t.nonceHex,ciphertextHex:t.ciphertextHex});return o.ok?(await r(o.plaintext,"cached"),!0):(d.clear(h()),!1)}async function Q(e,t,r,n){c.clearError(e),c.setBusy(r,!0);let o=c.readPassword(r);if(!o){c.setBusy(r,!1),c.showError(e,t.wpm);return}let a;try{a=await B.tryDecryptWithPassword({password:o,saltHex:t.saltHex,nonceHex:t.nonceHex,ciphertextHex:t.ciphertextHex,iterations:t.iterations})}finally{c.setBusy(r,!1)}if(!a.ok){c.showError(e,t.wpm);return}t.autoSave&&await d.save({pageKey:h(),key:a.key,saltHex:t.saltHex,nonceHex:t.nonceHex,autoSave:!0}),await n(a.plaintext,"manual")}async function I(){let e=document.getElementById("hexo-blog-encrypt");if(!e)return;let t=X(e);if(t.format!==V){c.showError(e,"hexo-blog-encrypt: this page was built with an incompatible plugin version. Rebuild the site after upgrading the plugin.");return}let r=!1,n=async(s,l)=>{r||(r=!0,await j(e,s,l))},o=e.querySelector("#hbeForm");if(c.attachSubmit(o,()=>Q(e,t,o,n)),!await z(e,t,n)&&!r){let s=e.querySelector("#hbePass");s&&s.focus()}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",I):I();})();
|
|
2
|
+
//# sourceMappingURL=hbe.bundle.js.map
|