hexo-blog-encrypt 4.0.0 → 4.0.2
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/ReadMe.md +20 -2
- package/ReadMe.zh.md +15 -1
- package/lib/hbe.blink.html +1 -1
- package/lib/hbe.bundle.js +1 -1
- package/lib/hbe.bundle.js.map +3 -3
- package/lib/hbe.default.html +1 -1
- package/lib/hbe.flip.html +1 -1
- package/lib/hbe.shrink.html +1 -1
- package/lib/hbe.style.css +39 -16
- package/lib/hbe.surge.html +1 -1
- package/lib/hbe.up.html +1 -1
- package/lib/hbe.wave.html +1 -1
- package/lib/hbe.xray.html +1 -1
- package/package.json +1 -1
- package/src/server/config.js +2 -0
- package/src/server/crypto.js +9 -1
- package/src/server/index.js +16 -1
- package/src/server/template.js +1 -0
package/ReadMe.md
CHANGED
|
@@ -185,12 +185,24 @@ encrypt: # hexo-blog-encrypt
|
|
|
185
185
|
show: true
|
|
186
186
|
text: Decrypt
|
|
187
187
|
|
|
188
|
-
# Cache the
|
|
189
|
-
#
|
|
188
|
+
# Cache the derived AES key in localStorage so reloads skip the password
|
|
189
|
+
# prompt. OFF by default — opt in per post via front-matter
|
|
190
190
|
# `autoSave: true`, or globally here. Cache key is namespaced under
|
|
191
191
|
# `hbe.v4.<post-permalink-hash>`.
|
|
192
192
|
autoSave: false
|
|
193
193
|
|
|
194
|
+
# Keep the PBKDF2 salt stable across clean static builds for the same
|
|
195
|
+
# post permalink. Default: false. This is useful with autoSave on
|
|
196
|
+
# Cloudflare Pages, Vercel, Netlify, GitHub Actions, and similar
|
|
197
|
+
# platforms that rebuild generated HTML from a clean environment on
|
|
198
|
+
# every deploy.
|
|
199
|
+
#
|
|
200
|
+
# Only the salt is stable. The AES-GCM nonce remains random for every
|
|
201
|
+
# encryption to avoid nonce reuse. If the post permalink changes, the
|
|
202
|
+
# stable salt changes too, and existing localStorage cache for that page
|
|
203
|
+
# is invalidated.
|
|
204
|
+
stableSalt: false
|
|
205
|
+
|
|
194
206
|
# PBKDF2 iteration count. Floor: 100_000. Recommended ≥ 600_000
|
|
195
207
|
# (OWASP 2023 for PBKDF2-SHA256). Lower-than-recommended values log a
|
|
196
208
|
# warning at build time. Default: 250_000.
|
|
@@ -199,6 +211,12 @@ encrypt: # hexo-blog-encrypt
|
|
|
199
211
|
|
|
200
212
|
```
|
|
201
213
|
|
|
214
|
+
When `autoSave` reads a cached key, it compares the cached salt with the
|
|
215
|
+
current page salt. A nonce change alone does not delete the cache up
|
|
216
|
+
front; the browser tries the cached key with the current page nonce and
|
|
217
|
+
ciphertext. If AES-GCM authentication fails, the cache entry is cleared
|
|
218
|
+
and the visitor is asked for the password again.
|
|
219
|
+
|
|
202
220
|
#### To disable tag encryption
|
|
203
221
|
|
|
204
222
|
Just set the `password` property in front matter to `""`.
|
package/ReadMe.zh.md
CHANGED
|
@@ -179,11 +179,21 @@ encrypt: # hexo-blog-encrypt
|
|
|
179
179
|
show: true
|
|
180
180
|
text: 解密
|
|
181
181
|
|
|
182
|
-
#
|
|
182
|
+
# 是否将派生出的 AES 密钥缓存到 localStorage, 让刷新页面跳过密码输入.
|
|
183
183
|
# 默认 OFF — 可在文章 front-matter 中通过 `autoSave: true` 单独开启,
|
|
184
184
|
# 也可以在这里全局开启. 缓存键命名空间为 `hbe.v4.<post-permalink-hash>`.
|
|
185
185
|
autoSave: false
|
|
186
186
|
|
|
187
|
+
# 让同一篇文章的 PBKDF2 salt 在 clean build 间保持稳定, 文章身份来自
|
|
188
|
+
# 当前实现中的 post permalink. 默认: false. 配合 autoSave 时, 适用于
|
|
189
|
+
# Cloudflare Pages、Vercel、Netlify、GitHub Actions 等每次部署都会从
|
|
190
|
+
# 干净环境重新生成 HTML 的静态部署平台.
|
|
191
|
+
#
|
|
192
|
+
# 只稳定 salt; AES-GCM nonce 每次加密仍然随机, 避免 nonce reuse.
|
|
193
|
+
# 如果文章 permalink 改变, stable salt 也会改变, 该页面已有的
|
|
194
|
+
# localStorage 缓存会失效.
|
|
195
|
+
stableSalt: false
|
|
196
|
+
|
|
187
197
|
# PBKDF2 迭代次数. 下限: 100_000. 推荐 ≥ 600_000
|
|
188
198
|
# (OWASP 2023 关于 PBKDF2-SHA256 的推荐). 低于推荐值时构建会打印 warning.
|
|
189
199
|
# 默认: 250_000.
|
|
@@ -192,6 +202,10 @@ encrypt: # hexo-blog-encrypt
|
|
|
192
202
|
|
|
193
203
|
```
|
|
194
204
|
|
|
205
|
+
`autoSave` 读取缓存密钥时会比较缓存中的 salt 与当前页面 salt. 仅 nonce
|
|
206
|
+
变化不会提前删除缓存; 浏览器会使用缓存密钥配合当前页面的 nonce 与密文尝试
|
|
207
|
+
解密. 如果 AES-GCM 认证失败, 该缓存条目会被清除, 访客需要重新输入密码.
|
|
208
|
+
|
|
195
209
|
#### 对博文禁用 Tag 加密
|
|
196
210
|
|
|
197
211
|
只需要将博文头部的 `password` 设置为 `""` 即可取消 Tag 加密.
|
package/lib/hbe.blink.html
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-blink" data-content="{{hbeMessage}}">{{hbeMessage}}</span>
|
|
18
18
|
</label>
|
|
19
19
|
</div>
|
|
20
|
-
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
20
|
+
<button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
|
|
21
21
|
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
22
22
|
</form>
|
|
23
23
|
</div>
|
package/lib/hbe.bundle.js
CHANGED
|
@@ -1,2 +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,
|
|
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,H)=>{"use strict";var _="hbe.v4.";function u(e){return _+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}){let r;try{let n=localStorage.getItem(u(e));if(!n)return null;r=JSON.parse(n)}catch(n){return null}if(!r||r.version!==4||typeof r.dk!="string"||typeof r.salt!="string"||typeof r.nonce!="string"||"hmk"in r||"hmacDigest"in r){try{localStorage.removeItem(u(e))}catch(n){}return null}if(r.salt!==t){try{localStorage.removeItem(u(e))}catch(n){}return null}try{let n=F(r.dk);return await crypto.subtle.importKey("raw",n,{name:"AES-GCM"},!0,["decrypt"])}catch(n){try{localStorage.removeItem(u(e))}catch(o){}return null}}function Y(e){try{localStorage.removeItem(u(e))}catch(t){}}H.exports={save:W,load:L,clear:Y,STORAGE_KEY_PREFIX:_,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});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
2
|
//# sourceMappingURL=hbe.bundle.js.map
|
package/lib/hbe.bundle.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/browser/ui.js", "../src/browser/crypto.js", "../src/browser/dom.js", "../src/browser/storage.js", "../src/browser/main.js"],
|
|
4
|
-
"sourcesContent": ["'use strict';\n\n// Wires the encrypted-post UI: form submit (Enter + click both fire),\n// `aria-busy` during async derivation, and an inline `[role=\"alert\"]` for\n// errors (NO `alert()` calls \u2014 feature-crew critique blocked dialog UX).\n\nfunction setBusy(form, busy) {\n if (!form) return;\n form.setAttribute('aria-busy', busy ? 'true' : 'false');\n const button = form.querySelector('.hbe-button');\n if (button) {\n button.disabled = !!busy;\n }\n const input = form.querySelector('#hbePass');\n if (input) {\n input.disabled = !!busy;\n }\n}\n\nfunction showError(mainElement, message) {\n let alert = mainElement.querySelector('[role=\"alert\"]');\n if (!alert) {\n alert = document.createElement('div');\n alert.setAttribute('role', 'alert');\n alert.className = 'hbe hbe-error';\n const form = mainElement.querySelector('#hbeForm');\n if (form) form.parentNode.insertBefore(alert, form.nextSibling);\n else mainElement.appendChild(alert);\n }\n alert.textContent = message;\n}\n\nfunction clearError(mainElement) {\n const alert = mainElement.querySelector('[role=\"alert\"]');\n if (alert) alert.textContent = '';\n}\n\nfunction readPassword(form) {\n const input = form.querySelector('#hbePass');\n return input ? input.value : '';\n}\n\nfunction attachSubmit(form, handler) {\n if (!form) return;\n form.addEventListener('submit', (event) => {\n event.preventDefault();\n handler();\n });\n}\n\nmodule.exports = {\n setBusy,\n showError,\n clearError,\n readPassword,\n attachSubmit,\n};\n", "'use strict';\n\n// Browser-side AES-256-GCM decryption with PBKDF2-SHA256 key derivation.\n// Mirrors the server-side parameters in `src/server/crypto.js`:\n// - PBKDF2: SHA-256, configurable iterations (read from data-kdf-iterations)\n// - AES: 256-bit key, GCM mode, 12-byte nonce, 16-byte auth tag\n//\n// Unified failure path: ANY thrown value (DOMException OperationError,\n// TypeError, etc.) collapses to {ok: false}. Wrong-password and\n// tampered-ciphertext are indistinguishable under GCM by design.\n\nconst KEY_BITS = 256;\nconst TAG_BITS = 128;\nconst TAG_BYTES = TAG_BITS / 8;\nconst TEXT_DECODER = new TextDecoder('utf-8', { fatal: true });\nconst TEXT_ENCODER = new TextEncoder();\n\nfunction hexToBytes(hex) {\n const len = hex.length;\n if (len % 2 !== 0) {\n throw new Error('hexo-blog-encrypt: hex string has odd length');\n }\n const out = new Uint8Array(len / 2);\n for (let i = 0; i < out.length; i++) {\n out[i] = parseInt(hex.substr(i * 2, 2), 16);\n }\n return out;\n}\n\nasync function deriveKey(password, salt, iterations) {\n const baseKey = await crypto.subtle.importKey(\n 'raw',\n TEXT_ENCODER.encode(password),\n { name: 'PBKDF2' },\n false,\n ['deriveKey']\n );\n return crypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt,\n iterations,\n hash: 'SHA-256',\n },\n baseKey,\n { name: 'AES-GCM', length: KEY_BITS },\n true, // extractable=true so storage.js can persist the raw key bytes when autoSave is on\n ['decrypt']\n );\n}\n\nasync function decryptWithKey(key, nonce, ciphertextWithTag) {\n // Web Crypto AES-GCM expects ciphertext||tag as a single buffer (same as Node's\n // `decipher.update + setAuthTag(tag); decipher.final()` flow when concatenated).\n const plainBuf = await crypto.subtle.decrypt(\n { name: 'AES-GCM', iv: nonce, tagLength: TAG_BITS },\n key,\n ciphertextWithTag\n );\n return TEXT_DECODER.decode(plainBuf);\n}\n\n// High-level: derive a key from the password + decrypt in one shot.\n// Returns {ok: true, plaintext, key} or {ok: false}.\nasync function tryDecryptWithPassword({ password, saltHex, nonceHex, ciphertextHex, iterations }) {\n try {\n const salt = hexToBytes(saltHex);\n const nonce = hexToBytes(nonceHex);\n const ciphertext = hexToBytes(ciphertextHex);\n if (ciphertext.length < TAG_BYTES) return { ok: false };\n const key = await deriveKey(password, salt, iterations);\n const plaintext = await decryptWithKey(key, nonce, ciphertext);\n return { ok: true, plaintext, key };\n } catch (_e) {\n return { ok: false };\n }\n}\n\n// Same shape, but reuses an already-derived key (autosave fast path).\nasync function tryDecryptWithKey({ key, nonceHex, ciphertextHex }) {\n try {\n const nonce = hexToBytes(nonceHex);\n const ciphertext = hexToBytes(ciphertextHex);\n if (ciphertext.length < TAG_BYTES) return { ok: false };\n const plaintext = await decryptWithKey(key, nonce, ciphertext);\n return { ok: true, plaintext };\n } catch (_e) {\n return { ok: false };\n }\n}\n\nmodule.exports = {\n tryDecryptWithPassword,\n tryDecryptWithKey,\n deriveKey,\n decryptWithKey,\n hexToBytes,\n};\n", "'use strict';\n\n// DOM helpers preserved from v3 (`getExecutableScript` + `convertHTMLToElement`):\n// when ciphertext decrypts to HTML containing `<script>` tags, the browser does\n// NOT execute scripts inserted via `innerHTML`. We re-create them as live <script>\n// elements so the decrypted post behaves like a normal Hexo-rendered post.\n\nfunction getExecutableScript(oldScriptElement) {\n const newScript = document.createElement('script');\n for (const attr of oldScriptElement.attributes) {\n newScript.setAttribute(attr.name, attr.value);\n }\n newScript.text = oldScriptElement.text;\n return newScript;\n}\n\nfunction convertHTMLToElement(htmlString) {\n const wrapper = document.createElement('div');\n wrapper.innerHTML = htmlString;\n // Replace each <script> with a live, executable element.\n for (const oldScript of wrapper.querySelectorAll('script')) {\n oldScript.parentNode.replaceChild(getExecutableScript(oldScript), oldScript);\n }\n return wrapper;\n}\n\n// Replace the encrypted wrapper with the decrypted DOM. Returns the new container\n// so callers can inspect / dispatch events on it.\nfunction swapInDecryptedDOM(mainElement, plaintextHTML) {\n const decrypted = convertHTMLToElement(plaintextHTML);\n decrypted.id = 'hexo-blog-encrypt';\n decrypted.classList.add('hbe', 'hbe-decrypted-content');\n mainElement.parentNode.replaceChild(decrypted, mainElement);\n return decrypted;\n}\n\nmodule.exports = {\n getExecutableScript,\n convertHTMLToElement,\n swapInDecryptedDOM,\n};\n", "'use strict';\n\n// Per-post localStorage entry storing the derived AES key + the salt/nonce that\n// produced the corresponding ciphertext. On reload we re-import the key and\n// attempt decryption silently; the user is never re-prompted.\n//\n// Schema (v4):\n// {\n// version: 4,\n// dk: base64(rawKeyBytes), // 32 bytes\n// salt: <hex64>, // matches data-salt\n// nonce: <hex24>, // matches data-nonce\n// }\n//\n// IMPORTANT: when `autoSave` is false, save() is a no-op. When reading, any\n// entry with a non-4 version (or v3 leftovers like `hmk`/`hmacDigest`) is\n// purged + ignored.\n\nconst STORAGE_KEY_PREFIX = 'hbe.v4.';\nconst SCHEMA_VERSION = 4;\n\nfunction storageKey(pageKey) {\n return STORAGE_KEY_PREFIX + pageKey;\n}\n\nfunction bytesToBase64(bytes) {\n let bin = '';\n for (let i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);\n return btoa(bin);\n}\n\nfunction base64ToBytes(b64) {\n const bin = atob(b64);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n\nasync function save({ pageKey, key, saltHex, nonceHex, autoSave }) {\n if (!autoSave) return;\n try {\n const raw = await crypto.subtle.exportKey('raw', key);\n const entry = {\n version: SCHEMA_VERSION,\n dk: bytesToBase64(new Uint8Array(raw)),\n salt: saltHex,\n nonce: nonceHex,\n };\n localStorage.setItem(storageKey(pageKey), JSON.stringify(entry));\n } catch (_e) {\n // localStorage.setItem can throw QuotaExceededError or SecurityError\n // (private mode, disabled storage). Silently ignore \u2014 autoSave is\n // best-effort UX.\n }\n}\n\nasync function load({ pageKey, expectedSaltHex, expectedNonceHex }) {\n let entry;\n try {\n const raw = localStorage.getItem(storageKey(pageKey));\n if (!raw) return null;\n entry = JSON.parse(raw);\n } catch (_e) {\n return null;\n }\n\n // Purge stale or v3 entries.\n if (\n !entry\n || entry.version !== SCHEMA_VERSION\n || typeof entry.dk !== 'string'\n || typeof entry.salt !== 'string'\n || typeof entry.nonce !== 'string'\n || 'hmk' in entry\n || 'hmacDigest' in entry\n ) {\n try { localStorage.removeItem(storageKey(pageKey)); } catch (_e) { /* ignore */ }\n return null;\n }\n\n // If the encrypted page's salt/nonce changed (rebuild minted fresh ones),\n // the cached key is stale. Drop it.\n if (entry.salt !== expectedSaltHex || entry.nonce !== expectedNonceHex) {\n try { localStorage.removeItem(storageKey(pageKey)); } catch (_e) { /* ignore */ }\n return null;\n }\n\n try {\n const rawBytes = base64ToBytes(entry.dk);\n const key = await crypto.subtle.importKey(\n 'raw',\n rawBytes,\n { name: 'AES-GCM' },\n true,\n ['decrypt']\n );\n return key;\n } catch (_e) {\n try { localStorage.removeItem(storageKey(pageKey)); } catch (_e2) { /* ignore */ }\n return null;\n }\n}\n\nfunction clear(pageKey) {\n try { localStorage.removeItem(storageKey(pageKey)); } catch (_e) { /* ignore */ }\n}\n\nmodule.exports = {\n save,\n load,\n clear,\n STORAGE_KEY_PREFIX,\n SCHEMA_VERSION,\n};\n", "'use strict';\n\n// Browser entry point. Reads the wire-format from the encrypted-post wrapper,\n// drives the UI via `ui.js`, derives & decrypts via `crypto.js`, and persists\n// the derived key (when autoSave is on) via `storage.js`.\n\nconst ui = require('./ui');\nconst cryptoMod = require('./crypto');\nconst dom = require('./dom');\nconst storage = require('./storage');\n\nconst SUPPORTED_FORMAT = '4';\n\nfunction readWireFormat(mainElement) {\n const ds = mainElement.dataset;\n const ciphertextNode = mainElement.querySelector('script#hbeData');\n return {\n format: ds.hbeFormat,\n wpm: ds.wpm || 'Wrong password.',\n whm: ds.whm || ds.wpm || 'Wrong password.',\n saltHex: ds.salt,\n nonceHex: ds.nonce,\n iterations: parseInt(ds.kdfIterations, 10) || 250000,\n autoSave: ds.autoSave === 'true',\n ciphertextHex: ciphertextNode ? ciphertextNode.textContent.trim() : '',\n };\n}\n\nfunction dispatchDecryptEvent(mode) {\n // Fire on `window` for v3 back-compat \u2014 both READMEs document\n // `window.addEventListener('hexo-blog-decrypt', fn)` as the public API.\n // Old listeners that only access `e.type` continue to work; new listeners\n // can additionally read `e.detail.mode` ('manual' | 'cached').\n try {\n window.dispatchEvent(new CustomEvent('hexo-blog-decrypt', { detail: { mode } }));\n } catch (_e) {\n // CustomEvent constructor unavailable on very old browsers \u2014 fall back\n // to plain Event (no detail).\n try {\n window.dispatchEvent(new Event('hexo-blog-decrypt'));\n } catch (_e2) { /* ignore \u2014 no event API at all */ }\n }\n}\n\nfunction pageKey() {\n // Per-URL bucket so different encrypted posts don't collide in localStorage.\n return location.pathname + location.search;\n}\n\nasync function reveal(mainElement, plaintext, mode) {\n dom.swapInDecryptedDOM(mainElement, plaintext);\n dispatchDecryptEvent(mode);\n}\n\nasync function tryAutoDecrypt(mainElement, wire, guardedReveal) {\n if (!wire.autoSave) return false;\n const cachedKey = await storage.load({\n pageKey: pageKey(),\n expectedSaltHex: wire.saltHex,\n expectedNonceHex: wire.nonceHex,\n });\n if (!cachedKey) return false;\n const result = await cryptoMod.tryDecryptWithKey({\n key: cachedKey,\n nonceHex: wire.nonceHex,\n ciphertextHex: wire.ciphertextHex,\n });\n if (!result.ok) {\n storage.clear(pageKey());\n return false;\n }\n await guardedReveal(result.plaintext, 'cached');\n return true;\n}\n\nasync function handleSubmit(mainElement, wire, form, guardedReveal) {\n ui.clearError(mainElement);\n ui.setBusy(form, true);\n const password = ui.readPassword(form);\n if (!password) {\n ui.setBusy(form, false);\n ui.showError(mainElement, wire.wpm);\n return;\n }\n let result;\n try {\n result = await cryptoMod.tryDecryptWithPassword({\n password,\n saltHex: wire.saltHex,\n nonceHex: wire.nonceHex,\n ciphertextHex: wire.ciphertextHex,\n iterations: wire.iterations,\n });\n } finally {\n ui.setBusy(form, false);\n }\n if (!result.ok) {\n ui.showError(mainElement, wire.wpm);\n return;\n }\n if (wire.autoSave) {\n await storage.save({\n pageKey: pageKey(),\n key: result.key,\n saltHex: wire.saltHex,\n nonceHex: wire.nonceHex,\n autoSave: true,\n });\n }\n await guardedReveal(result.plaintext, 'manual');\n}\n\nasync function bootstrap() {\n const mainElement = document.getElementById('hexo-blog-encrypt');\n if (!mainElement) return;\n const wire = readWireFormat(mainElement);\n\n if (wire.format !== SUPPORTED_FORMAT) {\n ui.showError(\n mainElement,\n 'hexo-blog-encrypt: this page was built with an incompatible plugin version. ' +\n 'Rebuild the site after upgrading the plugin.'\n );\n return;\n }\n\n // Single-shot reveal guard: with autoSave on, `tryAutoDecrypt` runs in\n // parallel with the form submit handler. If the user types fast enough\n // to submit BEFORE auto-decrypt resolves, both paths can call `reveal`\n // on the same `mainElement` \u2014 the second `replaceChild` would throw\n // because the wrapper is already detached. The guard makes whoever\n // wins the race the sole DOM-mutator.\n let revealed = false;\n const guardedReveal = async (plaintext, mode) => {\n if (revealed) return;\n revealed = true;\n await reveal(mainElement, plaintext, mode);\n };\n\n const form = mainElement.querySelector('#hbeForm');\n ui.attachSubmit(form, () => handleSubmit(mainElement, wire, form, guardedReveal));\n\n const auto = await tryAutoDecrypt(mainElement, wire, guardedReveal);\n if (!auto && !revealed) {\n const input = mainElement.querySelector('#hbePass');\n if (input) input.focus();\n }\n}\n\nif (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', bootstrap);\n} else {\n bootstrap();\n}\n"],
|
|
5
|
-
"mappings": "iFAAA,IAAAA,EAAAC,EAAA,CAAAC,GAAAC,IAAA,cAMA,SAASC,EAAQC,EAAMC,EAAM,CAC3B,GAAI,CAACD,EAAM,OACXA,EAAK,aAAa,YAAaC,EAAO,OAAS,OAAO,EACtD,IAAMC,EAASF,EAAK,cAAc,aAAa,EAC3CE,IACFA,EAAO,SAAW,CAAC,CAACD,GAEtB,IAAME,EAAQH,EAAK,cAAc,UAAU,EACvCG,IACFA,EAAM,SAAW,CAAC,CAACF,EAEvB,CAEA,SAASG,EAAUC,EAAaC,EAAS,CACvC,IAAIC,EAAQF,EAAY,cAAc,gBAAgB,EACtD,GAAI,CAACE,EAAO,CACVA,EAAQ,SAAS,cAAc,KAAK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SAAAC,EAAU,SAAAC,CAAS,EAAG,CACjE,GAAKA,EACL,GAAI,CACF,IAAMC,EAAM,MAAM,OAAO,OAAO,UAAU,MAAOJ,CAAG,EAC9CK,EAAQ,CACZ,QAAS,EACT,GAAIb,EAAc,IAAI,WAAWY,CAAG,CAAC,EACrC,KAAMH,EACN,MAAOC,CACT,EACA,aAAa,QAAQZ,EAAWC,CAAO,EAAG,KAAK,UAAUc,CAAK,CAAC,CACjE,OAASC,EAAI,CAIb,CACF,CAEA,eAAeC,EAAK,CAAE,QAAAhB,EAAS,gBAAAiB,
|
|
6
|
-
"names": ["require_ui", "__commonJSMin", "exports", "module", "setBusy", "form", "busy", "button", "input", "showError", "mainElement", "message", "alert", "clearError", "readPassword", "attachSubmit", "handler", "event", "require_crypto", "__commonJSMin", "exports", "module", "TEXT_DECODER", "TEXT_ENCODER", "hexToBytes", "hex", "len", "out", "i", "deriveKey", "password", "salt", "iterations", "baseKey", "decryptWithKey", "key", "nonce", "ciphertextWithTag", "plainBuf", "tryDecryptWithPassword", "saltHex", "nonceHex", "ciphertextHex", "ciphertext", "_e", "tryDecryptWithKey", "require_dom", "__commonJSMin", "exports", "module", "getExecutableScript", "oldScriptElement", "newScript", "attr", "convertHTMLToElement", "htmlString", "wrapper", "oldScript", "swapInDecryptedDOM", "mainElement", "plaintextHTML", "decrypted", "require_storage", "__commonJSMin", "exports", "module", "STORAGE_KEY_PREFIX", "storageKey", "pageKey", "bytesToBase64", "bytes", "bin", "i", "base64ToBytes", "b64", "out", "save", "key", "saltHex", "nonceHex", "autoSave", "raw", "entry", "_e", "load", "expectedSaltHex", "
|
|
4
|
+
"sourcesContent": ["'use strict';\n\n// Wires the encrypted-post UI: form submit (Enter + click both fire),\n// `aria-busy` during async derivation, and an inline `[role=\"alert\"]` for\n// errors (NO `alert()` calls \u2014 feature-crew critique blocked dialog UX).\n\nfunction setBusy(form, busy) {\n if (!form) return;\n form.setAttribute('aria-busy', busy ? 'true' : 'false');\n const button = form.querySelector('.hbe-button');\n if (button) {\n button.disabled = !!busy;\n }\n const input = form.querySelector('#hbePass');\n if (input) {\n input.disabled = !!busy;\n }\n}\n\nfunction showError(mainElement, message) {\n let alert = mainElement.querySelector('[role=\"alert\"]');\n if (!alert) {\n alert = document.createElement('div');\n alert.setAttribute('role', 'alert');\n alert.className = 'hbe hbe-error';\n const form = mainElement.querySelector('#hbeForm');\n if (form) form.parentNode.insertBefore(alert, form.nextSibling);\n else mainElement.appendChild(alert);\n }\n alert.textContent = message;\n}\n\nfunction clearError(mainElement) {\n const alert = mainElement.querySelector('[role=\"alert\"]');\n if (alert) alert.textContent = '';\n}\n\nfunction readPassword(form) {\n const input = form.querySelector('#hbePass');\n return input ? input.value : '';\n}\n\nfunction attachSubmit(form, handler) {\n if (!form) return;\n form.addEventListener('submit', (event) => {\n event.preventDefault();\n handler();\n });\n}\n\nmodule.exports = {\n setBusy,\n showError,\n clearError,\n readPassword,\n attachSubmit,\n};\n", "'use strict';\n\n// Browser-side AES-256-GCM decryption with PBKDF2-SHA256 key derivation.\n// Mirrors the server-side parameters in `src/server/crypto.js`:\n// - PBKDF2: SHA-256, configurable iterations (read from data-kdf-iterations)\n// - AES: 256-bit key, GCM mode, 12-byte nonce, 16-byte auth tag\n//\n// Unified failure path: ANY thrown value (DOMException OperationError,\n// TypeError, etc.) collapses to {ok: false}. Wrong-password and\n// tampered-ciphertext are indistinguishable under GCM by design.\n\nconst KEY_BITS = 256;\nconst TAG_BITS = 128;\nconst TAG_BYTES = TAG_BITS / 8;\nconst TEXT_DECODER = new TextDecoder('utf-8', { fatal: true });\nconst TEXT_ENCODER = new TextEncoder();\n\nfunction hexToBytes(hex) {\n const len = hex.length;\n if (len % 2 !== 0) {\n throw new Error('hexo-blog-encrypt: hex string has odd length');\n }\n const out = new Uint8Array(len / 2);\n for (let i = 0; i < out.length; i++) {\n out[i] = parseInt(hex.substr(i * 2, 2), 16);\n }\n return out;\n}\n\nasync function deriveKey(password, salt, iterations) {\n const baseKey = await crypto.subtle.importKey(\n 'raw',\n TEXT_ENCODER.encode(password),\n { name: 'PBKDF2' },\n false,\n ['deriveKey']\n );\n return crypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt,\n iterations,\n hash: 'SHA-256',\n },\n baseKey,\n { name: 'AES-GCM', length: KEY_BITS },\n true, // extractable=true so storage.js can persist the raw key bytes when autoSave is on\n ['decrypt']\n );\n}\n\nasync function decryptWithKey(key, nonce, ciphertextWithTag) {\n // Web Crypto AES-GCM expects ciphertext||tag as a single buffer (same as Node's\n // `decipher.update + setAuthTag(tag); decipher.final()` flow when concatenated).\n const plainBuf = await crypto.subtle.decrypt(\n { name: 'AES-GCM', iv: nonce, tagLength: TAG_BITS },\n key,\n ciphertextWithTag\n );\n return TEXT_DECODER.decode(plainBuf);\n}\n\n// High-level: derive a key from the password + decrypt in one shot.\n// Returns {ok: true, plaintext, key} or {ok: false}.\nasync function tryDecryptWithPassword({ password, saltHex, nonceHex, ciphertextHex, iterations }) {\n try {\n const salt = hexToBytes(saltHex);\n const nonce = hexToBytes(nonceHex);\n const ciphertext = hexToBytes(ciphertextHex);\n if (ciphertext.length < TAG_BYTES) return { ok: false };\n const key = await deriveKey(password, salt, iterations);\n const plaintext = await decryptWithKey(key, nonce, ciphertext);\n return { ok: true, plaintext, key };\n } catch (_e) {\n return { ok: false };\n }\n}\n\n// Same shape, but reuses an already-derived key (autosave fast path).\nasync function tryDecryptWithKey({ key, nonceHex, ciphertextHex }) {\n try {\n const nonce = hexToBytes(nonceHex);\n const ciphertext = hexToBytes(ciphertextHex);\n if (ciphertext.length < TAG_BYTES) return { ok: false };\n const plaintext = await decryptWithKey(key, nonce, ciphertext);\n return { ok: true, plaintext };\n } catch (_e) {\n return { ok: false };\n }\n}\n\nmodule.exports = {\n tryDecryptWithPassword,\n tryDecryptWithKey,\n deriveKey,\n decryptWithKey,\n hexToBytes,\n};\n", "'use strict';\n\n// DOM helpers preserved from v3 (`getExecutableScript` + `convertHTMLToElement`):\n// when ciphertext decrypts to HTML containing `<script>` tags, the browser does\n// NOT execute scripts inserted via `innerHTML`. We re-create them as live <script>\n// elements so the decrypted post behaves like a normal Hexo-rendered post.\n\nfunction getExecutableScript(oldScriptElement) {\n const newScript = document.createElement('script');\n for (const attr of oldScriptElement.attributes) {\n newScript.setAttribute(attr.name, attr.value);\n }\n newScript.text = oldScriptElement.text;\n return newScript;\n}\n\nfunction convertHTMLToElement(htmlString) {\n const wrapper = document.createElement('div');\n wrapper.innerHTML = htmlString;\n // Replace each <script> with a live, executable element.\n for (const oldScript of wrapper.querySelectorAll('script')) {\n oldScript.parentNode.replaceChild(getExecutableScript(oldScript), oldScript);\n }\n return wrapper;\n}\n\n// Replace the encrypted wrapper with the decrypted DOM. Returns the new container\n// so callers can inspect / dispatch events on it.\nfunction swapInDecryptedDOM(mainElement, plaintextHTML) {\n const decrypted = convertHTMLToElement(plaintextHTML);\n decrypted.id = 'hexo-blog-encrypt';\n decrypted.classList.add('hbe', 'hbe-decrypted-content');\n mainElement.parentNode.replaceChild(decrypted, mainElement);\n return decrypted;\n}\n\nmodule.exports = {\n getExecutableScript,\n convertHTMLToElement,\n swapInDecryptedDOM,\n};\n", "'use strict';\n\n// Per-post localStorage entry storing the derived AES key + the salt/nonce that\n// produced the corresponding ciphertext. On reload we re-import the key and\n// attempt decryption silently; the user is never re-prompted.\n//\n// Schema (v4):\n// {\n// version: 4,\n// dk: base64(rawKeyBytes), // 32 bytes\n// salt: <hex64>, // matches data-salt\n// nonce: <hex24>, // retained for v4 schema compatibility\n// }\n//\n// IMPORTANT: when `autoSave` is false, save() is a no-op. When reading, any\n// entry with a non-4 version (or v3 leftovers like `hmk`/`hmacDigest`) is\n// purged + ignored.\n\nconst STORAGE_KEY_PREFIX = 'hbe.v4.';\nconst SCHEMA_VERSION = 4;\n\nfunction storageKey(pageKey) {\n return STORAGE_KEY_PREFIX + pageKey;\n}\n\nfunction bytesToBase64(bytes) {\n let bin = '';\n for (let i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);\n return btoa(bin);\n}\n\nfunction base64ToBytes(b64) {\n const bin = atob(b64);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n\nasync function save({ pageKey, key, saltHex, nonceHex, autoSave }) {\n if (!autoSave) return;\n try {\n const raw = await crypto.subtle.exportKey('raw', key);\n const entry = {\n version: SCHEMA_VERSION,\n dk: bytesToBase64(new Uint8Array(raw)),\n salt: saltHex,\n nonce: nonceHex,\n };\n localStorage.setItem(storageKey(pageKey), JSON.stringify(entry));\n } catch (_e) {\n // localStorage.setItem can throw QuotaExceededError or SecurityError\n // (private mode, disabled storage). Silently ignore \u2014 autoSave is\n // best-effort UX.\n }\n}\n\nasync function load({ pageKey, expectedSaltHex }) {\n let entry;\n try {\n const raw = localStorage.getItem(storageKey(pageKey));\n if (!raw) return null;\n entry = JSON.parse(raw);\n } catch (_e) {\n return null;\n }\n\n // Purge stale or v3 entries.\n if (\n !entry\n || entry.version !== SCHEMA_VERSION\n || typeof entry.dk !== 'string'\n || typeof entry.salt !== 'string'\n || typeof entry.nonce !== 'string'\n || 'hmk' in entry\n || 'hmacDigest' in entry\n ) {\n try { localStorage.removeItem(storageKey(pageKey)); } catch (_e) { /* ignore */ }\n return null;\n }\n\n // If the encrypted page's salt changed, the cached key is stale. Nonce is\n // not part of PBKDF2 key derivation; decrypt still uses the current page's\n // nonce and ciphertext, and failure clears the cache in main.js.\n if (entry.salt !== expectedSaltHex) {\n try { localStorage.removeItem(storageKey(pageKey)); } catch (_e) { /* ignore */ }\n return null;\n }\n\n try {\n const rawBytes = base64ToBytes(entry.dk);\n const key = await crypto.subtle.importKey(\n 'raw',\n rawBytes,\n { name: 'AES-GCM' },\n true,\n ['decrypt']\n );\n return key;\n } catch (_e) {\n try { localStorage.removeItem(storageKey(pageKey)); } catch (_e2) { /* ignore */ }\n return null;\n }\n}\n\nfunction clear(pageKey) {\n try { localStorage.removeItem(storageKey(pageKey)); } catch (_e) { /* ignore */ }\n}\n\nmodule.exports = {\n save,\n load,\n clear,\n STORAGE_KEY_PREFIX,\n SCHEMA_VERSION,\n};\n", "'use strict';\n\n// Browser entry point. Reads the wire-format from the encrypted-post wrapper,\n// drives the UI via `ui.js`, derives & decrypts via `crypto.js`, and persists\n// the derived key (when autoSave is on) via `storage.js`.\n\nconst ui = require('./ui');\nconst cryptoMod = require('./crypto');\nconst dom = require('./dom');\nconst storage = require('./storage');\n\nconst SUPPORTED_FORMAT = '4';\n\nfunction readWireFormat(mainElement) {\n const ds = mainElement.dataset;\n const ciphertextNode = mainElement.querySelector('script#hbeData');\n return {\n format: ds.hbeFormat,\n wpm: ds.wpm || 'Wrong password.',\n whm: ds.whm || ds.wpm || 'Wrong password.',\n saltHex: ds.salt,\n nonceHex: ds.nonce,\n iterations: parseInt(ds.kdfIterations, 10) || 250000,\n autoSave: ds.autoSave === 'true',\n ciphertextHex: ciphertextNode ? ciphertextNode.textContent.trim() : '',\n };\n}\n\nfunction dispatchDecryptEvent(mode) {\n // Fire on `window` for v3 back-compat \u2014 both READMEs document\n // `window.addEventListener('hexo-blog-decrypt', fn)` as the public API.\n // Old listeners that only access `e.type` continue to work; new listeners\n // can additionally read `e.detail.mode` ('manual' | 'cached').\n try {\n window.dispatchEvent(new CustomEvent('hexo-blog-decrypt', { detail: { mode } }));\n } catch (_e) {\n // CustomEvent constructor unavailable on very old browsers \u2014 fall back\n // to plain Event (no detail).\n try {\n window.dispatchEvent(new Event('hexo-blog-decrypt'));\n } catch (_e2) { /* ignore \u2014 no event API at all */ }\n }\n}\n\nfunction pageKey() {\n // Per-URL bucket so different encrypted posts don't collide in localStorage.\n return location.pathname + location.search;\n}\n\nasync function reveal(mainElement, plaintext, mode) {\n dom.swapInDecryptedDOM(mainElement, plaintext);\n dispatchDecryptEvent(mode);\n}\n\nasync function tryAutoDecrypt(mainElement, wire, guardedReveal) {\n if (!wire.autoSave) return false;\n const cachedKey = await storage.load({\n pageKey: pageKey(),\n expectedSaltHex: wire.saltHex,\n });\n if (!cachedKey) return false;\n const result = await cryptoMod.tryDecryptWithKey({\n key: cachedKey,\n nonceHex: wire.nonceHex,\n ciphertextHex: wire.ciphertextHex,\n });\n if (!result.ok) {\n storage.clear(pageKey());\n return false;\n }\n await guardedReveal(result.plaintext, 'cached');\n return true;\n}\n\nasync function handleSubmit(mainElement, wire, form, guardedReveal) {\n ui.clearError(mainElement);\n ui.setBusy(form, true);\n const password = ui.readPassword(form);\n if (!password) {\n ui.setBusy(form, false);\n ui.showError(mainElement, wire.wpm);\n return;\n }\n let result;\n try {\n result = await cryptoMod.tryDecryptWithPassword({\n password,\n saltHex: wire.saltHex,\n nonceHex: wire.nonceHex,\n ciphertextHex: wire.ciphertextHex,\n iterations: wire.iterations,\n });\n } finally {\n ui.setBusy(form, false);\n }\n if (!result.ok) {\n ui.showError(mainElement, wire.wpm);\n return;\n }\n if (wire.autoSave) {\n await storage.save({\n pageKey: pageKey(),\n key: result.key,\n saltHex: wire.saltHex,\n nonceHex: wire.nonceHex,\n autoSave: true,\n });\n }\n await guardedReveal(result.plaintext, 'manual');\n}\n\nasync function bootstrap() {\n const mainElement = document.getElementById('hexo-blog-encrypt');\n if (!mainElement) return;\n const wire = readWireFormat(mainElement);\n\n if (wire.format !== SUPPORTED_FORMAT) {\n ui.showError(\n mainElement,\n 'hexo-blog-encrypt: this page was built with an incompatible plugin version. ' +\n 'Rebuild the site after upgrading the plugin.'\n );\n return;\n }\n\n // Single-shot reveal guard: with autoSave on, `tryAutoDecrypt` runs in\n // parallel with the form submit handler. If the user types fast enough\n // to submit BEFORE auto-decrypt resolves, both paths can call `reveal`\n // on the same `mainElement` \u2014 the second `replaceChild` would throw\n // because the wrapper is already detached. The guard makes whoever\n // wins the race the sole DOM-mutator.\n let revealed = false;\n const guardedReveal = async (plaintext, mode) => {\n if (revealed) return;\n revealed = true;\n await reveal(mainElement, plaintext, mode);\n };\n\n const form = mainElement.querySelector('#hbeForm');\n ui.attachSubmit(form, () => handleSubmit(mainElement, wire, form, guardedReveal));\n\n const auto = await tryAutoDecrypt(mainElement, wire, guardedReveal);\n if (!auto && !revealed) {\n const input = mainElement.querySelector('#hbePass');\n if (input) input.focus();\n }\n}\n\nif (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', bootstrap);\n} else {\n bootstrap();\n}\n"],
|
|
5
|
+
"mappings": "iFAAA,IAAAA,EAAAC,EAAA,CAAAC,GAAAC,IAAA,cAMA,SAASC,EAAQC,EAAMC,EAAM,CAC3B,GAAI,CAACD,EAAM,OACXA,EAAK,aAAa,YAAaC,EAAO,OAAS,OAAO,EACtD,IAAMC,EAASF,EAAK,cAAc,aAAa,EAC3CE,IACFA,EAAO,SAAW,CAAC,CAACD,GAEtB,IAAME,EAAQH,EAAK,cAAc,UAAU,EACvCG,IACFA,EAAM,SAAW,CAAC,CAACF,EAEvB,CAEA,SAASG,EAAUC,EAAaC,EAAS,CACvC,IAAIC,EAAQF,EAAY,cAAc,gBAAgB,EACtD,GAAI,CAACE,EAAO,CACVA,EAAQ,SAAS,cAAc,KAAK,EACpCA,EAAM,aAAa,OAAQ,OAAO,EAClCA,EAAM,UAAY,gBAClB,IAAMP,EAAOK,EAAY,cAAc,UAAU,EAC7CL,EAAMA,EAAK,WAAW,aAAaO,EAAOP,EAAK,WAAW,EACzDK,EAAY,YAAYE,CAAK,CACpC,CACAA,EAAM,YAAcD,CACtB,CAEA,SAASE,EAAWH,EAAa,CAC/B,IAAME,EAAQF,EAAY,cAAc,gBAAgB,EACpDE,IAAOA,EAAM,YAAc,GACjC,CAEA,SAASE,EAAaT,EAAM,CAC1B,IAAMG,EAAQH,EAAK,cAAc,UAAU,EAC3C,OAAOG,EAAQA,EAAM,MAAQ,EAC/B,CAEA,SAASO,EAAaV,EAAMW,EAAS,CAC9BX,GACLA,EAAK,iBAAiB,SAAWY,GAAU,CACzCA,EAAM,eAAe,EACrBD,EAAQ,CACV,CAAC,CACH,CAEAb,EAAO,Q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QAAE,CACAjB,EAAG,QAAQsB,EAAM,EAAK,CACxB,CACA,GAAI,CAACF,EAAO,GAAI,CACdpB,EAAG,UAAUM,EAAaW,EAAK,GAAG,EAClC,MACF,CACIA,EAAK,UACP,MAAMd,EAAQ,KAAK,CACjB,QAASU,EAAQ,EACjB,IAAKO,EAAO,IACZ,QAASH,EAAK,QACd,SAAUA,EAAK,SACf,SAAU,EACZ,CAAC,EAEH,MAAMC,EAAcE,EAAO,UAAW,QAAQ,CAChD,CAEA,eAAeI,GAAY,CACzB,IAAMlB,EAAc,SAAS,eAAe,mBAAmB,EAC/D,GAAI,CAACA,EAAa,OAClB,IAAMW,EAAOZ,EAAeC,CAAW,EAEvC,GAAIW,EAAK,SAAWb,EAAkB,CACpCJ,EAAG,UACDM,EACA,0HAEF,EACA,MACF,CAQA,IAAImB,EAAW,GACTP,EAAgB,MAAOH,EAAWL,IAAS,CAC3Ce,IACJA,EAAW,GACX,MAAMX,EAAOR,EAAaS,EAAWL,CAAI,EAC3C,EAEMY,EAAOhB,EAAY,cAAc,UAAU,EAIjD,GAHAN,EAAG,aAAasB,EAAM,IAAMD,EAAaf,EAAaW,EAAMK,EAAMJ,CAAa,CAAC,EAG5E,CADS,MAAMF,EAAeV,EAAaW,EAAMC,CAAa,GACrD,CAACO,EAAU,CACtB,IAAMC,EAAQpB,EAAY,cAAc,UAAU,EAC9CoB,GAAOA,EAAM,MAAM,CACzB,CACF,CAEI,SAAS,aAAe,UAC1B,SAAS,iBAAiB,mBAAoBF,CAAS,EAEvDA,EAAU",
|
|
6
|
+
"names": ["require_ui", "__commonJSMin", "exports", "module", "setBusy", "form", "busy", "button", "input", "showError", "mainElement", "message", "alert", "clearError", "readPassword", "attachSubmit", "handler", "event", "require_crypto", "__commonJSMin", "exports", "module", "TEXT_DECODER", "TEXT_ENCODER", "hexToBytes", "hex", "len", "out", "i", "deriveKey", "password", "salt", "iterations", "baseKey", "decryptWithKey", "key", "nonce", "ciphertextWithTag", "plainBuf", "tryDecryptWithPassword", "saltHex", "nonceHex", "ciphertextHex", "ciphertext", "_e", "tryDecryptWithKey", "require_dom", "__commonJSMin", "exports", "module", "getExecutableScript", "oldScriptElement", "newScript", "attr", "convertHTMLToElement", "htmlString", "wrapper", "oldScript", "swapInDecryptedDOM", "mainElement", "plaintextHTML", "decrypted", "require_storage", "__commonJSMin", "exports", "module", "STORAGE_KEY_PREFIX", "storageKey", "pageKey", "bytesToBase64", "bytes", "bin", "i", "base64ToBytes", "b64", "out", "save", "key", "saltHex", "nonceHex", "autoSave", "raw", "entry", "_e", "load", "expectedSaltHex", "rawBytes", "_e2", "clear", "ui", "cryptoMod", "dom", "storage", "SUPPORTED_FORMAT", "readWireFormat", "mainElement", "ds", "ciphertextNode", "dispatchDecryptEvent", "mode", "_e", "_e2", "pageKey", "reveal", "plaintext", "tryAutoDecrypt", "wire", "guardedReveal", "cachedKey", "result", "handleSubmit", "form", "password", "bootstrap", "revealed", "input"]
|
|
7
7
|
}
|
package/lib/hbe.default.html
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-default">{{hbeMessage}}</span>
|
|
18
18
|
</label>
|
|
19
19
|
</div>
|
|
20
|
-
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
20
|
+
<button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
|
|
21
21
|
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
22
22
|
</form>
|
|
23
23
|
</div>
|
package/lib/hbe.flip.html
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-flip" data-content="{{hbeMessage}}">{{hbeMessage}}</span>
|
|
18
18
|
</label>
|
|
19
19
|
</div>
|
|
20
|
-
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
20
|
+
<button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
|
|
21
21
|
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
22
22
|
</form>
|
|
23
23
|
</div>
|
package/lib/hbe.shrink.html
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-shrink">{{hbeMessage}}</span>
|
|
18
18
|
</label>
|
|
19
19
|
</div>
|
|
20
|
-
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
20
|
+
<button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
|
|
21
21
|
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
22
22
|
</form>
|
|
23
23
|
</div>
|
package/lib/hbe.style.css
CHANGED
|
@@ -762,25 +762,39 @@
|
|
|
762
762
|
* ============================================================ */
|
|
763
763
|
|
|
764
764
|
.hbe-form {
|
|
765
|
-
margin: 0;
|
|
766
|
-
padding: 0;
|
|
767
|
-
|
|
765
|
+
margin: 0;
|
|
766
|
+
padding: 0;
|
|
767
|
+
width: 100%;
|
|
768
|
+
display: flex;
|
|
769
|
+
flex-direction: column;
|
|
770
|
+
align-items: center;
|
|
768
771
|
}
|
|
769
772
|
|
|
770
773
|
.hbe-button {
|
|
771
|
-
display:
|
|
772
|
-
margin: 0
|
|
773
|
-
padding: 0.7em 1.6em;
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
774
|
+
display: block;
|
|
775
|
+
margin: 0 auto 1em;
|
|
776
|
+
padding: 0.7em 1.6em;
|
|
777
|
+
width: auto;
|
|
778
|
+
max-width: 100%;
|
|
779
|
+
min-width: 8em;
|
|
780
|
+
height: auto;
|
|
781
|
+
line-height: 1.2;
|
|
782
|
+
font-size: 1rem;
|
|
783
|
+
font-family: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
784
|
+
font-weight: 600;
|
|
785
|
+
color: #fff;
|
|
786
|
+
text-align: center;
|
|
787
|
+
text-indent: 0;
|
|
788
|
+
text-shadow: none;
|
|
789
|
+
white-space: normal;
|
|
790
|
+
overflow-wrap: anywhere;
|
|
791
|
+
background: #2a7ae2;
|
|
792
|
+
border: none;
|
|
793
|
+
border-radius: 4px;
|
|
794
|
+
box-shadow: none;
|
|
795
|
+
cursor: pointer;
|
|
796
|
+
-webkit-appearance: none;
|
|
797
|
+
transition: background 0.15s ease, box-shadow 0.15s ease;
|
|
784
798
|
}
|
|
785
799
|
|
|
786
800
|
.hbe-button:hover,
|
|
@@ -809,6 +823,15 @@ border-radius: 50%;
|
|
|
809
823
|
animation: hbe-spin 0.7s linear infinite;
|
|
810
824
|
}
|
|
811
825
|
|
|
826
|
+
.hbe-button::after {
|
|
827
|
+
content: none;
|
|
828
|
+
display: none;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
.hbe-button-hidden {
|
|
832
|
+
display: none;
|
|
833
|
+
}
|
|
834
|
+
|
|
812
835
|
@keyframes hbe-spin {
|
|
813
836
|
to { transform: rotate(360deg); }
|
|
814
837
|
}
|
package/lib/hbe.surge.html
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<path d="M1200,9c0,0-305.005,0-401.001,0C733,9,675.327,4.969,598,4.969C514.994,4.969,449.336,9,400.333,9C299.666,9,0,9,0,9v43c0,0,299.666,0,400.333,0c49.002,0,114.66,3.484,197.667,3.484c77.327,0,135-3.484,200.999-3.484C894.995,52,1200,52,1200,52V9z"></path>
|
|
21
21
|
</svg>
|
|
22
22
|
</div>
|
|
23
|
-
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
23
|
+
<button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
|
|
24
24
|
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
25
25
|
</form>
|
|
26
26
|
</div>
|
package/lib/hbe.up.html
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-up">{{hbeMessage}}</span>
|
|
18
18
|
</label>
|
|
19
19
|
</div>
|
|
20
|
-
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
20
|
+
<button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
|
|
21
21
|
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
22
22
|
</form>
|
|
23
23
|
</div>
|
package/lib/hbe.wave.html
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"></path>
|
|
21
21
|
</svg>
|
|
22
22
|
</div>
|
|
23
|
-
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
23
|
+
<button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
|
|
24
24
|
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
25
25
|
</form>
|
|
26
26
|
</div>
|
package/lib/hbe.xray.html
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
<path d="M0,2.5c0,0,298.666,0,399.333,0C448.336,2.5,513.994,13,597,13c77.327,0,135-10.5,200.999-10.5c95.996,0,402.001,0,402.001,0"></path>
|
|
22
22
|
</svg>
|
|
23
23
|
</div>
|
|
24
|
-
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
24
|
+
<button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
|
|
25
25
|
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
26
26
|
</form>
|
|
27
27
|
</div>
|
package/package.json
CHANGED
package/src/server/config.js
CHANGED
|
@@ -13,6 +13,7 @@ const DEFAULTS = Object.freeze({
|
|
|
13
13
|
// unified GCM failure handling).
|
|
14
14
|
silent: false,
|
|
15
15
|
autoSave: false,
|
|
16
|
+
stableSalt: false,
|
|
16
17
|
decryptButton: Object.freeze({
|
|
17
18
|
show: true,
|
|
18
19
|
text: 'Decrypt',
|
|
@@ -70,6 +71,7 @@ const POST_KNOWN_KEYS = [
|
|
|
70
71
|
'wrong_hash_message',
|
|
71
72
|
'silent',
|
|
72
73
|
'autoSave',
|
|
74
|
+
'stableSalt',
|
|
73
75
|
'decryptButton',
|
|
74
76
|
'kdf',
|
|
75
77
|
];
|
package/src/server/crypto.js
CHANGED
|
@@ -21,7 +21,15 @@ function encrypt(plaintext, password, opts) {
|
|
|
21
21
|
const iterations = (opts && Number.isInteger(opts.iterations) && opts.iterations > 0)
|
|
22
22
|
? opts.iterations
|
|
23
23
|
: DEFAULT_ITERATIONS;
|
|
24
|
-
|
|
24
|
+
let salt;
|
|
25
|
+
if (opts && opts.salt !== undefined) {
|
|
26
|
+
if (!Buffer.isBuffer(opts.salt) || opts.salt.length !== SALT_BYTES) {
|
|
27
|
+
throw new Error('salt must be a 32-byte Buffer');
|
|
28
|
+
}
|
|
29
|
+
salt = Buffer.from(opts.salt);
|
|
30
|
+
} else {
|
|
31
|
+
salt = crypto.randomBytes(SALT_BYTES);
|
|
32
|
+
}
|
|
25
33
|
const nonce = crypto.randomBytes(NONCE_BYTES);
|
|
26
34
|
const dk = deriveKey(password, salt, iterations);
|
|
27
35
|
const cipher = crypto.createCipheriv(CIPHER, dk, nonce);
|
package/src/server/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const crypto = require('node:crypto');
|
|
3
4
|
const path = require('node:path');
|
|
4
5
|
|
|
5
6
|
const { resolve } = require('./config');
|
|
@@ -15,6 +16,7 @@ const BUNDLE_PATH = path.join(REPO_ROOT, 'lib', 'hbe.bundle.js');
|
|
|
15
16
|
const BUNDLE_SOURCEMAP_PATH = path.join(REPO_ROOT, 'lib', 'hbe.bundle.js.map');
|
|
16
17
|
|
|
17
18
|
const FORMAT_VERSION = '4';
|
|
19
|
+
const STABLE_SALT_NAMESPACE = 'hexo-blog-encrypt:v4:stableSalt:';
|
|
18
20
|
|
|
19
21
|
// Per-instance Symbol so user front-matter keys can never collide with our
|
|
20
22
|
// idempotence marker. We deliberately do NOT use Symbol.for(...) (a global
|
|
@@ -47,6 +49,14 @@ function normalizePostTags(postTags) {
|
|
|
47
49
|
return [];
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
function stableSaltFromPermalink(permalink) {
|
|
53
|
+
return crypto.createHash('sha256')
|
|
54
|
+
.update(STABLE_SALT_NAMESPACE)
|
|
55
|
+
.update('\0')
|
|
56
|
+
.update(permalink)
|
|
57
|
+
.digest();
|
|
58
|
+
}
|
|
59
|
+
|
|
50
60
|
function resolveTagPassword(hexoEncrypt, postTags) {
|
|
51
61
|
if (!hexoEncrypt || !Array.isArray(hexoEncrypt.tags)) return null;
|
|
52
62
|
const tags = normalizePostTags(postTags);
|
|
@@ -133,8 +143,12 @@ function register(hexo) {
|
|
|
133
143
|
data.origin = data.content;
|
|
134
144
|
|
|
135
145
|
const plaintext = String(data.content == null ? '' : data.content);
|
|
146
|
+
const stableSaltEnabled = cfg.stableSalt === true
|
|
147
|
+
&& typeof data.permalink === 'string'
|
|
148
|
+
&& data.permalink.length > 0;
|
|
136
149
|
const { salt, nonce, ciphertext } = encrypt(plaintext, cfg.password, {
|
|
137
150
|
iterations: cfg.kdf.iterations,
|
|
151
|
+
salt: stableSaltEnabled ? stableSaltFromPermalink(data.permalink) : undefined,
|
|
138
152
|
});
|
|
139
153
|
|
|
140
154
|
const buttonShow = !cfg.decryptButton || cfg.decryptButton.show !== false;
|
|
@@ -152,7 +166,8 @@ function register(hexo) {
|
|
|
152
166
|
message: cfg.message,
|
|
153
167
|
wpm: cfg.wrong_pass_message,
|
|
154
168
|
whm: cfg.wrong_hash_message,
|
|
155
|
-
|
|
169
|
+
buttonClass: buttonShow ? '' : ' hbe-button-hidden',
|
|
170
|
+
buttonText,
|
|
156
171
|
kdfIterations: cfg.kdf.iterations,
|
|
157
172
|
autoSave: !!cfg.autoSave,
|
|
158
173
|
});
|
package/src/server/template.js
CHANGED
|
@@ -38,6 +38,7 @@ const PLACEHOLDERS = [
|
|
|
38
38
|
{ token: '{{hbeKdfIterations}}', field: 'kdfIterations', mode: 'attr' },
|
|
39
39
|
{ token: '{{hbeAutoSave}}', field: 'autoSave', mode: 'attr' },
|
|
40
40
|
{ token: '{{hbeMessage}}', field: 'message', mode: 'text' },
|
|
41
|
+
{ token: '{{hbeButtonClass}}', field: 'buttonClass', mode: 'attr' },
|
|
41
42
|
{ token: '{{hbeButtonText}}', field: 'buttonText', mode: 'text' },
|
|
42
43
|
{ token: '{{hbeSalt}}', field: 'salt', mode: 'hex' },
|
|
43
44
|
{ token: '{{hbeNonce}}', field: 'nonce', mode: 'hex' },
|