Allow configuring paste ID and encryption key lengths in config.json
This commit is contained in:
parent
f8cc163ba9
commit
cdbd700c2e
1
app.py
1
app.py
|
|
@ -390,6 +390,7 @@ def get_client_config():
|
|||
'default_expiry': _pastes.get('default_expiry', 'never'),
|
||||
'allow_expiry_options': _pastes.get('allow_expiry_options', []),
|
||||
'expiry_labels': _pastes.get('expiry_labels', {}),
|
||||
'encryption_key_bits': _pastes.get('encryption_key_bits', 128),
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
"pastes": {
|
||||
"max_size_bytes": 2097152,
|
||||
"id_length": 8,
|
||||
"encryption_key_bits": 128,
|
||||
"recent_limit": 50,
|
||||
"default_language": "text",
|
||||
"default_expiry": "1year",
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ const PasteCrypto = (function () {
|
|||
}
|
||||
|
||||
return {
|
||||
/** Generate a new, random AES-GCM 256-bit key. */
|
||||
async generateKey() {
|
||||
/** Generate a new, random AES-GCM key. Default to 128-bit if not specified. */
|
||||
async generateKey(length = 128) {
|
||||
return window.crypto.subtle.generateKey(
|
||||
{ name: 'AES-GCM', length: 128 },
|
||||
{ name: 'AES-GCM', length: length },
|
||||
true,
|
||||
['encrypt', 'decrypt']
|
||||
);
|
||||
|
|
|
|||
|
|
@ -89,7 +89,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
try {
|
||||
let postBody, keyBase64 = null;
|
||||
if (E2E) {
|
||||
const key = await PasteCrypto.generateKey();
|
||||
const keyLen = window.PBCFG?.pastes?.encryption_key_bits ?? 128;
|
||||
const key = await PasteCrypto.generateKey(keyLen);
|
||||
keyBase64 = await PasteCrypto.exportKey(key);
|
||||
const plain = JSON.stringify({ title, content, language });
|
||||
postBody = { encrypted_data: await PasteCrypto.encrypt(plain, key), expires_in };
|
||||
|
|
|
|||
Loading…
Reference in New Issue