forked from ComputerTech/bastebin
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'),
|
'default_expiry': _pastes.get('default_expiry', 'never'),
|
||||||
'allow_expiry_options': _pastes.get('allow_expiry_options', []),
|
'allow_expiry_options': _pastes.get('allow_expiry_options', []),
|
||||||
'expiry_labels': _pastes.get('expiry_labels', {}),
|
'expiry_labels': _pastes.get('expiry_labels', {}),
|
||||||
|
'encryption_key_bits': _pastes.get('encryption_key_bits', 128),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
"pastes": {
|
"pastes": {
|
||||||
"max_size_bytes": 2097152,
|
"max_size_bytes": 2097152,
|
||||||
"id_length": 8,
|
"id_length": 8,
|
||||||
|
"encryption_key_bits": 128,
|
||||||
"recent_limit": 50,
|
"recent_limit": 50,
|
||||||
"default_language": "text",
|
"default_language": "text",
|
||||||
"default_expiry": "1year",
|
"default_expiry": "1year",
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ const PasteCrypto = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/** Generate a new, random AES-GCM 256-bit key. */
|
/** Generate a new, random AES-GCM key. Default to 128-bit if not specified. */
|
||||||
async generateKey() {
|
async generateKey(length = 128) {
|
||||||
return window.crypto.subtle.generateKey(
|
return window.crypto.subtle.generateKey(
|
||||||
{ name: 'AES-GCM', length: 128 },
|
{ name: 'AES-GCM', length: length },
|
||||||
true,
|
true,
|
||||||
['encrypt', 'decrypt']
|
['encrypt', 'decrypt']
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
try {
|
try {
|
||||||
let postBody, keyBase64 = null;
|
let postBody, keyBase64 = null;
|
||||||
if (E2E) {
|
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);
|
keyBase64 = await PasteCrypto.exportKey(key);
|
||||||
const plain = JSON.stringify({ title, content, language });
|
const plain = JSON.stringify({ title, content, language });
|
||||||
postBody = { encrypted_data: await PasteCrypto.encrypt(plain, key), expires_in };
|
postBody = { encrypted_data: await PasteCrypto.encrypt(plain, key), expires_in };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue