address decryptOrPromptPassword(), decryptPaste() and decryptAttachment() async compatibility
This commit is contained in:
parent
c0d3b9062b
commit
ff8ec5a1a0
@ -4133,6 +4133,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
*
|
*
|
||||||
* @name PasteDecrypter.decryptOrPromptPassword
|
* @name PasteDecrypter.decryptOrPromptPassword
|
||||||
* @private
|
* @private
|
||||||
|
* @async
|
||||||
* @function
|
* @function
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
* @param {string} password - optional, may be an empty string
|
* @param {string} password - optional, may be an empty string
|
||||||
@ -4140,10 +4141,10 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
* @throws {string}
|
* @throws {string}
|
||||||
* @return {false|string} false, when unsuccessful or string (decrypted data)
|
* @return {false|string} false, when unsuccessful or string (decrypted data)
|
||||||
*/
|
*/
|
||||||
function decryptOrPromptPassword(key, password, cipherdata)
|
async function decryptOrPromptPassword(key, password, cipherdata)
|
||||||
{
|
{
|
||||||
// try decryption without password
|
// try decryption without password
|
||||||
var plaindata = CryptTool.decipher(key, password, cipherdata);
|
var plaindata = await CryptTool.decipher(key, password, cipherdata);
|
||||||
|
|
||||||
// if it fails, request password
|
// if it fails, request password
|
||||||
if (plaindata.length === 0 && password.length === 0) {
|
if (plaindata.length === 0 && password.length === 0) {
|
||||||
@ -4168,6 +4169,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
*
|
*
|
||||||
* @name PasteDecrypter.decryptPaste
|
* @name PasteDecrypter.decryptPaste
|
||||||
* @private
|
* @private
|
||||||
|
* @async
|
||||||
* @function
|
* @function
|
||||||
* @param {object} paste - paste data in object form
|
* @param {object} paste - paste data in object form
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
@ -4176,21 +4178,19 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
* @return {bool} whether action was successful
|
* @return {bool} whether action was successful
|
||||||
* @throws {string}
|
* @throws {string}
|
||||||
*/
|
*/
|
||||||
function decryptPaste(paste, key, password, ignoreError)
|
async function decryptPaste(paste, key, password, ignoreError)
|
||||||
{
|
{
|
||||||
var plaintext;
|
let decyptionPromise;
|
||||||
if (ignoreError === true) {
|
if (ignoreError === true) {
|
||||||
plaintext = CryptTool.decipher(key, password, paste.data);
|
decyptionPromise = CryptTool.decipher(key, password, paste.data);
|
||||||
} else {
|
} else {
|
||||||
try {
|
decyptionPromise = decryptOrPromptPassword(key, password, paste.data);
|
||||||
plaintext = decryptOrPromptPassword(key, password, paste.data);
|
|
||||||
} catch (err) {
|
|
||||||
throw 'failed to decipher paste text: ' + err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return decyptionPromise.then((plaintext) => {
|
||||||
if (plaintext === false) {
|
if (plaintext === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// on success show paste
|
// on success show paste
|
||||||
PasteViewer.setFormat(paste.meta.formatter);
|
PasteViewer.setFormat(paste.meta.formatter);
|
||||||
@ -4199,6 +4199,9 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
PasteViewer.run();
|
PasteViewer.run();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}).catch((err) => {
|
||||||
|
throw 'failed to decipher paste text: ' + err;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4206,6 +4209,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
*
|
*
|
||||||
* @name PasteDecrypter.decryptAttachment
|
* @name PasteDecrypter.decryptAttachment
|
||||||
* @private
|
* @private
|
||||||
|
* @async
|
||||||
* @function
|
* @function
|
||||||
* @param {object} paste - paste data in object form
|
* @param {object} paste - paste data in object form
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
@ -4213,36 +4217,26 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
* @return {bool} whether action was successful
|
* @return {bool} whether action was successful
|
||||||
* @throws {string}
|
* @throws {string}
|
||||||
*/
|
*/
|
||||||
function decryptAttachment(paste, key, password)
|
async function decryptAttachment(paste, key, password)
|
||||||
{
|
{
|
||||||
var attachment, attachmentName;
|
let attachmentPromise = decryptOrPromptPassword(key, password, paste.attachment);
|
||||||
|
let attachmentNamePromise = decryptOrPromptPassword(key, password, paste.attachmentname);
|
||||||
// decrypt attachment
|
attachmentPromise.catch((err) => {
|
||||||
try {
|
|
||||||
attachment = decryptOrPromptPassword(key, password, paste.attachment);
|
|
||||||
} catch (err) {
|
|
||||||
throw 'failed to decipher attachment: ' + err;
|
throw 'failed to decipher attachment: ' + err;
|
||||||
}
|
})
|
||||||
if (attachment === false) {
|
attachmentNamePromise.catch((err) => {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// decrypt attachment name
|
|
||||||
if (paste.attachmentname) {
|
|
||||||
try {
|
|
||||||
attachmentName = decryptOrPromptPassword(key, password, paste.attachmentname);
|
|
||||||
} catch (err) {
|
|
||||||
throw 'failed to decipher attachment name: ' + err;
|
throw 'failed to decipher attachment name: ' + err;
|
||||||
}
|
})
|
||||||
if (attachmentName === false) {
|
Promise.all([attachmentPromise, attachmentNamePromise]).then((results) => {
|
||||||
|
if (results.some((result) => {
|
||||||
|
return result === false;
|
||||||
|
})) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
AttachmentViewer.setAttachment(results[0], results[1]);
|
||||||
|
|
||||||
AttachmentViewer.setAttachment(attachment, attachmentName);
|
|
||||||
AttachmentViewer.showAttachment();
|
AttachmentViewer.showAttachment();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4300,20 +4294,17 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
// try to decrypt the paste
|
// try to decrypt the paste
|
||||||
try {
|
try {
|
||||||
// decrypt attachments
|
// decrypt attachments
|
||||||
if (paste.attachment) {
|
if (paste.attachment && AttachmentViewer.hasAttachmentData()) {
|
||||||
if (AttachmentViewer.hasAttachmentData()) {
|
|
||||||
// try to decrypt paste and if it fails (because the password is
|
// try to decrypt paste and if it fails (because the password is
|
||||||
// missing) return to let JS continue and wait for user
|
// missing) return to let JS continue and wait for user
|
||||||
if (!decryptAttachment(paste, key, password)) {
|
decryptAttachment(paste, key, password).then((attachementIsDecrypted) => {
|
||||||
return;
|
if (attachementIsDecrypted) {
|
||||||
}
|
|
||||||
}
|
|
||||||
// ignore empty paste, as this is allowed when pasting attachments
|
// ignore empty paste, as this is allowed when pasting attachments
|
||||||
decryptPaste(paste, key, password, true);
|
decryptPaste(paste, key, password, true);
|
||||||
} else {
|
|
||||||
if (decryptPaste(paste, key, password) === false) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
decryptPaste(paste, key, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
// shows the remaining time (until) deletion
|
// shows the remaining time (until) deletion
|
||||||
@ -4472,8 +4463,6 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
// restore position
|
// restore position
|
||||||
window.scrollTo(0, orgPosition);
|
window.scrollTo(0, orgPosition);
|
||||||
|
|
||||||
PasteDecrypter.run(data);
|
|
||||||
|
|
||||||
// NOTE: could create problems as callback may be called
|
// NOTE: could create problems as callback may be called
|
||||||
// asyncronously if PasteDecrypter e.g. needs to wait for a
|
// asyncronously if PasteDecrypter e.g. needs to wait for a
|
||||||
// password being entered
|
// password being entered
|
||||||
|
@ -71,7 +71,7 @@ if ($MARKDOWN):
|
|||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.7.js" integrity="sha512-VnKJHLosO8z2ojNvWk9BEKYqnhZyWK9rM90FgZUUEp/PRnUqR5OLLKE0a3BkVmn7YgB7LXRrjHgFHQYKd6DAIA==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.7.js" integrity="sha512-VnKJHLosO8z2ojNvWk9BEKYqnhZyWK9rM90FgZUUEp/PRnUqR5OLLKE0a3BkVmn7YgB7LXRrjHgFHQYKd6DAIA==" crossorigin="anonymous"></script>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-TueCJSPy2oHZv94r1sC8F7u/4KJGyI7D7qSRW9oOdyE0UnMeAvAgiAGgspAkiDkhi31QmDZ0J8GcORF2IojR5g==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-koPew9AjZ8OBU64pQG50jLX+yTDw/i4smvV618aGUG1NX+LpEvAVhjQ7K7/Iprxr2ZHksz5BToLYf54G5IewHA==" crossorigin="anonymous"></script>
|
||||||
<!--[if lt IE 10]>
|
<!--[if lt IE 10]>
|
||||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
@ -49,7 +49,7 @@ if ($MARKDOWN):
|
|||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.7.js" integrity="sha512-VnKJHLosO8z2ojNvWk9BEKYqnhZyWK9rM90FgZUUEp/PRnUqR5OLLKE0a3BkVmn7YgB7LXRrjHgFHQYKd6DAIA==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.7.js" integrity="sha512-VnKJHLosO8z2ojNvWk9BEKYqnhZyWK9rM90FgZUUEp/PRnUqR5OLLKE0a3BkVmn7YgB7LXRrjHgFHQYKd6DAIA==" crossorigin="anonymous"></script>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-TueCJSPy2oHZv94r1sC8F7u/4KJGyI7D7qSRW9oOdyE0UnMeAvAgiAGgspAkiDkhi31QmDZ0J8GcORF2IojR5g==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-koPew9AjZ8OBU64pQG50jLX+yTDw/i4smvV618aGUG1NX+LpEvAVhjQ7K7/Iprxr2ZHksz5BToLYf54G5IewHA==" crossorigin="anonymous"></script>
|
||||||
<!--[if lt IE 10]>
|
<!--[if lt IE 10]>
|
||||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
Loading…
Reference in New Issue
Block a user