hexo-blog-encrypt 3.1.9 → 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 +105 -0
- 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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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,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,QAAU,CACf,QAAAC,EACA,UAAAK,EACA,WAAAI,EACA,aAAAC,EACA,aAAAC,CACF,ICxDA,IAAAG,EAAAC,EAAA,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AK,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", "expectedNonceHex", "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
|
+
}
|
package/lib/hbe.default.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-default">
|
|
5
15
|
<input class="hbe hbe-input-field hbe-input-field-default" type="password" id="hbePass">
|
|
6
16
|
<label class="hbe hbe-input-label hbe-input-label-default" for="hbePass">
|
|
7
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-default">{{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>
|
package/lib/hbe.flip.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-flip">
|
|
5
15
|
<input class="hbe hbe-input-field hbe-input-field-flip" type="password" id="hbePass">
|
|
6
16
|
<label class="hbe hbe-input-label hbe-input-label-flip" for="hbePass">
|
|
7
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-flip" 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>
|
package/lib/hbe.shrink.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-shrink">
|
|
5
15
|
<input class="hbe hbe-input-field hbe-input-field-shrink" type="password" id="hbePass">
|
|
6
16
|
<label class="hbe hbe-input-label hbe-input-label-shrink" for="hbePass">
|
|
7
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-shrink">{{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>
|
package/lib/hbe.style.css
CHANGED
|
@@ -747,3 +747,108 @@
|
|
|
747
747
|
transform: translate3d(0, 2em, 0) scale3d(0.655, 0.655, 1);
|
|
748
748
|
}
|
|
749
749
|
/* shrink theme }}} */
|
|
750
|
+
|
|
751
|
+
/* ============================================================
|
|
752
|
+
* v4 SHELL: form, button, error, loading, dark mode.
|
|
753
|
+
*
|
|
754
|
+
* Themes wrap the input + button in <form id="hbeForm"> so Enter
|
|
755
|
+
* and click both fire 'submit'. The button is opt-in via the
|
|
756
|
+
* `decryptButton.show` config — themes always emit the slot, the
|
|
757
|
+
* server decides whether to render it.
|
|
758
|
+
*
|
|
759
|
+
* NEW in v4 (additive — pre-v4 themes that lack these slots
|
|
760
|
+
* remain visually identical to v3 except for the .hbe-error
|
|
761
|
+
* region appearing only when populated).
|
|
762
|
+
* ============================================================ */
|
|
763
|
+
|
|
764
|
+
.hbe-form {
|
|
765
|
+
margin: 0;
|
|
766
|
+
padding: 0;
|
|
767
|
+
display: contents;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
.hbe-button {
|
|
771
|
+
display: inline-block;
|
|
772
|
+
margin: 0.5em 1em;
|
|
773
|
+
padding: 0.7em 1.6em;
|
|
774
|
+
font-size: 1rem;
|
|
775
|
+
font-family: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
776
|
+
font-weight: 600;
|
|
777
|
+
color: #fff;
|
|
778
|
+
background: #2a7ae2;
|
|
779
|
+
border: none;
|
|
780
|
+
border-radius: 4px;
|
|
781
|
+
cursor: pointer;
|
|
782
|
+
-webkit-appearance: none;
|
|
783
|
+
transition: background 0.15s ease, box-shadow 0.15s ease;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
.hbe-button:hover,
|
|
787
|
+
.hbe-button:focus {
|
|
788
|
+
background: #1c5db8;
|
|
789
|
+
outline: none;
|
|
790
|
+
box-shadow: 0 0 0 3px rgba(42, 122, 226, 0.35);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
.hbe-button:disabled,
|
|
794
|
+
.hbe-button[aria-busy="true"] {
|
|
795
|
+
cursor: progress;
|
|
796
|
+
opacity: 0.7;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
.hbe-button[aria-busy="true"]::after {
|
|
800
|
+
content: "";
|
|
801
|
+
display: inline-block;
|
|
802
|
+
margin-left: 0.5em;
|
|
803
|
+
width: 0.9em;
|
|
804
|
+
height: 0.9em;
|
|
805
|
+
vertical-align: -0.15em;
|
|
806
|
+
border: 2px solid currentColor;
|
|
807
|
+
border-right-color: transparent;
|
|
808
|
+
border-radius: 50%;
|
|
809
|
+
animation: hbe-spin 0.7s linear infinite;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
@keyframes hbe-spin {
|
|
813
|
+
to { transform: rotate(360deg); }
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
.hbe-error {
|
|
817
|
+
min-height: 1.4em;
|
|
818
|
+
margin: 0.5em 1em;
|
|
819
|
+
padding: 0.5em 1em;
|
|
820
|
+
color: #b00020;
|
|
821
|
+
font-size: 0.95rem;
|
|
822
|
+
font-family: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
823
|
+
background: transparent;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
.hbe-error:not(:empty) {
|
|
827
|
+
background: rgba(176, 0, 32, 0.08);
|
|
828
|
+
border-radius: 4px;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
@media (prefers-color-scheme: dark) {
|
|
832
|
+
.hbe-input-field {
|
|
833
|
+
background: #2a2f36;
|
|
834
|
+
color: #e6e6e6;
|
|
835
|
+
}
|
|
836
|
+
.hbe-input-label {
|
|
837
|
+
color: #cfd6e4;
|
|
838
|
+
}
|
|
839
|
+
.hbe-button {
|
|
840
|
+
background: #4d8df0;
|
|
841
|
+
color: #fff;
|
|
842
|
+
}
|
|
843
|
+
.hbe-button:hover,
|
|
844
|
+
.hbe-button:focus {
|
|
845
|
+
background: #6ba1f5;
|
|
846
|
+
box-shadow: 0 0 0 3px rgba(77, 141, 240, 0.35);
|
|
847
|
+
}
|
|
848
|
+
.hbe-error {
|
|
849
|
+
color: #ff7a7a;
|
|
850
|
+
}
|
|
851
|
+
.hbe-error:not(:empty) {
|
|
852
|
+
background: rgba(255, 122, 122, 0.12);
|
|
853
|
+
}
|
|
854
|
+
}
|
package/lib/hbe.surge.html
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
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-surge">
|
|
5
15
|
<input class="hbe hbe-input-field hbe-input-field-surge" type="password" id="hbePass">
|
|
6
16
|
<label class="hbe hbe-input-label hbe-input-label-surge" for="hbePass">
|
|
7
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-surge" data-content="{{hbeMessage}}">{{hbeMessage}}</span>
|
|
@@ -10,5 +20,8 @@
|
|
|
10
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>
|
|
11
21
|
</svg>
|
|
12
22
|
</div>
|
|
23
|
+
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
24
|
+
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
25
|
+
</form>
|
|
13
26
|
</div>
|
|
14
27
|
</div>
|
package/lib/hbe.up.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-up">
|
|
5
15
|
<input class="hbe hbe-input-field hbe-input-field-up" type="password" id="hbePass">
|
|
6
16
|
<label class="hbe hbe-input-label hbe-input-label-up" for="hbePass">
|
|
7
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-up">{{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>
|
package/lib/hbe.wave.html
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
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-wave">
|
|
5
15
|
<input class="hbe hbe-input-field hbe-input-field-wave" type="password" id="hbePass">
|
|
6
16
|
<label class="hbe hbe-input-label hbe-input-label-wave" for="hbePass">
|
|
7
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-wave">{{hbeMessage}}</span>
|
|
@@ -10,5 +20,8 @@
|
|
|
10
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>
|
|
11
21
|
</svg>
|
|
12
22
|
</div>
|
|
23
|
+
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
24
|
+
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
25
|
+
</form>
|
|
13
26
|
</div>
|
|
14
27
|
</div>
|
package/lib/hbe.xray.html
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
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-xray">
|
|
5
15
|
<input class="hbe hbe-input-field hbe-input-field-xray" type="password" id="hbePass">
|
|
6
16
|
<label class="hbe hbe-input-label hbe-input-label-xray" for="hbePass">
|
|
7
17
|
<span class="hbe hbe-input-label-content hbe-input-label-content-xray">{{hbeMessage}}</span>
|
|
@@ -11,5 +21,8 @@
|
|
|
11
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>
|
|
12
22
|
</svg>
|
|
13
23
|
</div>
|
|
24
|
+
<button class="hbe hbe-button" type="submit">{{hbeButtonText}}</button>
|
|
25
|
+
<div class="hbe hbe-error" role="alert" aria-live="polite"></div>
|
|
26
|
+
</form>
|
|
14
27
|
</div>
|
|
15
28
|
</div>
|
package/package.json
CHANGED
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"main": "index.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"src/server/",
|
|
20
|
+
"lib/"
|
|
21
|
+
],
|
|
17
22
|
"maintainers": [
|
|
18
23
|
{
|
|
19
24
|
"email": "D0n9X1n@outlook.com",
|
|
@@ -23,14 +28,32 @@
|
|
|
23
28
|
"name": "hexo-blog-encrypt",
|
|
24
29
|
"repository": {
|
|
25
30
|
"type": "git",
|
|
26
|
-
"url": "git+
|
|
31
|
+
"url": "git+https://github.com/D0n9X1n/hexo-blog-encrypt.git"
|
|
27
32
|
},
|
|
28
33
|
"scripts": {
|
|
29
|
-
"
|
|
34
|
+
"build": "node build/build.js",
|
|
35
|
+
"prepack": "npm run build",
|
|
36
|
+
"prepare": "node build/prepare.js",
|
|
37
|
+
"pretest:server": "npm run build",
|
|
38
|
+
"test": "npm run lint && npm run test:server && npm run test:e2e",
|
|
39
|
+
"test:server": "node tests/helpers/install-fixture.js && c8 --reporter=text --reporter=lcov --include=index.js --include=src/server/**/*.js --check-coverage --lines=100 --functions=100 --branches=100 --statements=100 node --test tests/server/*.test.js tests/docs.test.js",
|
|
40
|
+
"test:e2e": "cd tests/fixtures/hexo-site && (test -d node_modules || npm install --no-audit --no-fund) && cd ../../.. && playwright install --with-deps chromium && playwright test --config tests/e2e/playwright.config.js",
|
|
41
|
+
"test:docs": "node --test tests/docs.test.js",
|
|
30
42
|
"lint": "eslint --ext .js ./"
|
|
31
43
|
},
|
|
32
|
-
"version": "
|
|
44
|
+
"version": "4.0.0",
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"hexo": ">=5"
|
|
50
|
+
},
|
|
33
51
|
"devDependencies": {
|
|
34
|
-
"
|
|
52
|
+
"@playwright/test": "^1.45",
|
|
53
|
+
"c8": "^10",
|
|
54
|
+
"esbuild": "^0.25.12",
|
|
55
|
+
"eslint": "^6.2.2",
|
|
56
|
+
"hexo": "^7",
|
|
57
|
+
"hexo-renderer-marked": "^7"
|
|
35
58
|
}
|
|
36
59
|
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const FLOOR = 100000;
|
|
4
|
+
const RECOMMENDED = 600000;
|
|
5
|
+
|
|
6
|
+
const DEFAULTS = Object.freeze({
|
|
7
|
+
abstract: 'Here\'s something encrypted, password is required to continue reading.',
|
|
8
|
+
message: 'Hey, password is required here.',
|
|
9
|
+
theme: 'default',
|
|
10
|
+
wrong_pass_message: 'Oh, this is an invalid password. Check and try again, please.',
|
|
11
|
+
// wrong_hash_message intentionally omitted from DEFAULTS — it defaults to the
|
|
12
|
+
// resolved wrong_pass_message in resolve() below (single source of truth under
|
|
13
|
+
// unified GCM failure handling).
|
|
14
|
+
silent: false,
|
|
15
|
+
autoSave: false,
|
|
16
|
+
decryptButton: Object.freeze({
|
|
17
|
+
show: true,
|
|
18
|
+
text: 'Decrypt',
|
|
19
|
+
}),
|
|
20
|
+
kdf: Object.freeze({
|
|
21
|
+
iterations: 250000,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function clone(value) {
|
|
26
|
+
if (value === null || typeof value !== 'object') return value;
|
|
27
|
+
if (typeof structuredClone === 'function') return structuredClone(value);
|
|
28
|
+
/* c8 ignore next 2 — Node ≥18 always has structuredClone; fallback is for non-Node hosts. */
|
|
29
|
+
return JSON.parse(JSON.stringify(value));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function deepMerge(base, overlay) {
|
|
33
|
+
if (overlay === null || overlay === undefined) return clone(base);
|
|
34
|
+
if (typeof base !== 'object' || base === null || Array.isArray(base)) return clone(overlay);
|
|
35
|
+
if (typeof overlay !== 'object' || Array.isArray(overlay)) return clone(overlay);
|
|
36
|
+
const out = {};
|
|
37
|
+
const keys = new Set([...Object.keys(base), ...Object.keys(overlay)]);
|
|
38
|
+
for (const key of keys) {
|
|
39
|
+
if (key in overlay) {
|
|
40
|
+
out[key] = deepMerge(base[key], overlay[key]);
|
|
41
|
+
} else {
|
|
42
|
+
out[key] = clone(base[key]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function shallowPickKnown(source, knownKeys) {
|
|
49
|
+
const out = {};
|
|
50
|
+
for (const key of knownKeys) {
|
|
51
|
+
if (key in source) out[key] = source[key];
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Keys allowed to flow from the front-matter `post` object into `resolve()`'s
|
|
57
|
+
// deep merge. Deliberately EXCLUDES `tags`: Hexo materializes `post.tags` as a
|
|
58
|
+
// Warehouse Query containing functions/methods, which `structuredClone` cannot
|
|
59
|
+
// clone (DataCloneError). The post's tag list is read directly by
|
|
60
|
+
// `resolveTagPassword(hexoConfig.encrypt, data.tags)` over in `index.js`; the
|
|
61
|
+
// `tags` field on `hexoConfig.encrypt` (the {name, password} registry) is
|
|
62
|
+
// allowed and lives in `KNOWN_KEYS`.
|
|
63
|
+
const POST_KNOWN_KEYS = [
|
|
64
|
+
'password',
|
|
65
|
+
'abstract',
|
|
66
|
+
'message',
|
|
67
|
+
'theme',
|
|
68
|
+
'template',
|
|
69
|
+
'wrong_pass_message',
|
|
70
|
+
'wrong_hash_message',
|
|
71
|
+
'silent',
|
|
72
|
+
'autoSave',
|
|
73
|
+
'decryptButton',
|
|
74
|
+
'kdf',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const KNOWN_KEYS = [
|
|
78
|
+
...POST_KNOWN_KEYS,
|
|
79
|
+
'tags',
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
function resolve(hexoConfig, postData, logger) {
|
|
83
|
+
// Only `warn` is ever called from this module; keep the no-op default minimal.
|
|
84
|
+
const log = logger || { warn: () => {} };
|
|
85
|
+
|
|
86
|
+
// hexo.config.encrypt may legitimately be missing OR a non-object truthy
|
|
87
|
+
// value (e.g. `encrypt: true` in _config.yml, which YAML parses as boolean).
|
|
88
|
+
// Treat any non-plain-object as "no encrypt block configured".
|
|
89
|
+
const hexoEncrypt = (
|
|
90
|
+
hexoConfig
|
|
91
|
+
&& typeof hexoConfig.encrypt === 'object'
|
|
92
|
+
&& hexoConfig.encrypt !== null
|
|
93
|
+
&& !Array.isArray(hexoConfig.encrypt)
|
|
94
|
+
) ? hexoConfig.encrypt : {};
|
|
95
|
+
const post = postData || {};
|
|
96
|
+
|
|
97
|
+
// Layer 1: defaults → hexo encrypt block (for top-level shared keys, NOT password/theme overrides per-post).
|
|
98
|
+
let merged = deepMerge(DEFAULTS, shallowPickKnown(hexoEncrypt, KNOWN_KEYS));
|
|
99
|
+
|
|
100
|
+
// Layer 2: post front-matter wins. Use POST_KNOWN_KEYS (which excludes
|
|
101
|
+
// `tags`) to avoid pulling Hexo's Warehouse Query for `post.tags` into
|
|
102
|
+
// the deep-merge — `structuredClone` would throw DataCloneError on the
|
|
103
|
+
// function-bearing internals.
|
|
104
|
+
merged = deepMerge(merged, shallowPickKnown(post, POST_KNOWN_KEYS));
|
|
105
|
+
|
|
106
|
+
// Deprecation: template → theme.
|
|
107
|
+
if (merged.template !== undefined && merged.template !== null) {
|
|
108
|
+
log.warn(
|
|
109
|
+
'hexo-blog-encrypt: "template" is deprecated, use "theme" instead. ' +
|
|
110
|
+
'See https://github.com/D0n9X1n/hexo-blog-encrypt#encrypt-theme'
|
|
111
|
+
);
|
|
112
|
+
if (merged.theme === DEFAULTS.theme) {
|
|
113
|
+
merged.theme = merged.template;
|
|
114
|
+
}
|
|
115
|
+
delete merged.template;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Password: undefined or empty-string disables encryption (caller short-circuits).
|
|
119
|
+
if (merged.password === undefined || merged.password === null) return null;
|
|
120
|
+
merged.password = String(merged.password);
|
|
121
|
+
if (merged.password === '') return null;
|
|
122
|
+
|
|
123
|
+
// KDF iteration floor + warn band. (deepMerge always populates merged.kdf
|
|
124
|
+
// from DEFAULTS.kdf when the user does not set it, so we only need to
|
|
125
|
+
// validate the resolved value here.)
|
|
126
|
+
if (!Number.isInteger(merged.kdf.iterations) || merged.kdf.iterations < FLOOR) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`hexo-blog-encrypt: kdf.iterations must be an integer ≥ ${FLOOR.toLocaleString('en-US').replace(/,/g, '_')} ` +
|
|
129
|
+
`(got ${merged.kdf.iterations}). 100_000 is the absolute floor; ${RECOMMENDED.toLocaleString('en-US').replace(/,/g, '_')}+ is recommended (OWASP 2023).`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (merged.kdf.iterations < RECOMMENDED) {
|
|
133
|
+
log.warn(
|
|
134
|
+
`hexo-blog-encrypt: kdf.iterations=${merged.kdf.iterations} is below the OWASP-recommended 600_000. ` +
|
|
135
|
+
'Consider raising it for stronger brute-force resistance.'
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// wrong_hash_message handling under GCM:
|
|
140
|
+
// - User explicitly set it → keep it but warn (deprecated alias).
|
|
141
|
+
// - User did NOT set it → default to the resolved wrong_pass_message.
|
|
142
|
+
const userSetWhm =
|
|
143
|
+
(post.wrong_hash_message !== undefined) || (hexoEncrypt.wrong_hash_message !== undefined);
|
|
144
|
+
if (userSetWhm) {
|
|
145
|
+
log.warn(
|
|
146
|
+
'hexo-blog-encrypt: "wrong_hash_message" is deprecated under v4 (AES-GCM unifies wrong-password ' +
|
|
147
|
+
'and tampered-ciphertext failures). The value is now an alias of "wrong_pass_message". ' +
|
|
148
|
+
'Set "wrong_pass_message" instead.'
|
|
149
|
+
);
|
|
150
|
+
} else {
|
|
151
|
+
merged.wrong_hash_message = merged.wrong_pass_message;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return merged;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module.exports = {
|
|
158
|
+
resolve,
|
|
159
|
+
DEFAULTS,
|
|
160
|
+
FLOOR,
|
|
161
|
+
RECOMMENDED,
|
|
162
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crypto = require('node:crypto');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_ITERATIONS = 250000;
|
|
6
|
+
const SALT_BYTES = 32;
|
|
7
|
+
const NONCE_BYTES = 12;
|
|
8
|
+
const KEY_BYTES = 32;
|
|
9
|
+
const TAG_BYTES = 16;
|
|
10
|
+
const HASH = 'sha256';
|
|
11
|
+
const CIPHER = 'aes-256-gcm';
|
|
12
|
+
|
|
13
|
+
function deriveKey(password, salt, iterations) {
|
|
14
|
+
const passwordBuf = typeof password === 'string'
|
|
15
|
+
? Buffer.from(password, 'utf8')
|
|
16
|
+
: Buffer.from(String(password), 'utf8');
|
|
17
|
+
return crypto.pbkdf2Sync(passwordBuf, salt, iterations, KEY_BYTES, HASH);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function encrypt(plaintext, password, opts) {
|
|
21
|
+
const iterations = (opts && Number.isInteger(opts.iterations) && opts.iterations > 0)
|
|
22
|
+
? opts.iterations
|
|
23
|
+
: DEFAULT_ITERATIONS;
|
|
24
|
+
const salt = crypto.randomBytes(SALT_BYTES);
|
|
25
|
+
const nonce = crypto.randomBytes(NONCE_BYTES);
|
|
26
|
+
const dk = deriveKey(password, salt, iterations);
|
|
27
|
+
const cipher = crypto.createCipheriv(CIPHER, dk, nonce);
|
|
28
|
+
const enc = Buffer.concat([
|
|
29
|
+
cipher.update(Buffer.from(String(plaintext), 'utf8')),
|
|
30
|
+
cipher.final(),
|
|
31
|
+
]);
|
|
32
|
+
const tag = cipher.getAuthTag();
|
|
33
|
+
const ciphertext = Buffer.concat([enc, tag]);
|
|
34
|
+
return { salt, nonce, ciphertext };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function decrypt(salt, nonce, ciphertext, password, opts) {
|
|
38
|
+
const iterations = (opts && Number.isInteger(opts.iterations) && opts.iterations > 0)
|
|
39
|
+
? opts.iterations
|
|
40
|
+
: DEFAULT_ITERATIONS;
|
|
41
|
+
if (!Buffer.isBuffer(salt) || salt.length !== SALT_BYTES) {
|
|
42
|
+
throw new Error('salt must be a 32-byte Buffer');
|
|
43
|
+
}
|
|
44
|
+
if (!Buffer.isBuffer(nonce) || nonce.length !== NONCE_BYTES) {
|
|
45
|
+
throw new Error('nonce must be a 12-byte Buffer');
|
|
46
|
+
}
|
|
47
|
+
if (!Buffer.isBuffer(ciphertext) || ciphertext.length < TAG_BYTES) {
|
|
48
|
+
throw new Error('ciphertext must be a Buffer of length ≥ 16');
|
|
49
|
+
}
|
|
50
|
+
const dk = deriveKey(password, salt, iterations);
|
|
51
|
+
const enc = ciphertext.slice(0, ciphertext.length - TAG_BYTES);
|
|
52
|
+
const tag = ciphertext.slice(ciphertext.length - TAG_BYTES);
|
|
53
|
+
const decipher = crypto.createDecipheriv(CIPHER, dk, nonce);
|
|
54
|
+
decipher.setAuthTag(tag);
|
|
55
|
+
const out = Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
56
|
+
return out.toString('utf8');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
encrypt,
|
|
61
|
+
decrypt,
|
|
62
|
+
DEFAULT_ITERATIONS,
|
|
63
|
+
SALT_BYTES,
|
|
64
|
+
NONCE_BYTES,
|
|
65
|
+
KEY_BYTES,
|
|
66
|
+
TAG_BYTES,
|
|
67
|
+
};
|