mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-12-29 13:15:44 +01:00
improving tests, correcting cipher
This commit is contained in:
parent
0dbbb61d11
commit
b97ac08003
4 changed files with 11 additions and 20 deletions
|
@ -764,7 +764,8 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||
derivedKey,
|
||||
StrToArr(compress(message)) // compressed plain text to encrypt
|
||||
)
|
||||
return btoa(ArrToStr(encrypted));
|
||||
object.ct = btoa(ArrToStr(encrypted));
|
||||
return JSON.stringify(object);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -780,7 +781,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||
me.decipher = async function(key, password, data)
|
||||
{
|
||||
try {
|
||||
if (password.length > 0) {
|
||||
if ((password || '').trim().length > 0) {
|
||||
key += sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(password));
|
||||
}
|
||||
var object = JSON.parse(data),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
require('../common');
|
||||
jsdom();
|
||||
window.crypto = new WebCrypto();
|
||||
|
||||
describe('CryptTool', function () {
|
||||
describe('cipher & decipher', function () {
|
||||
|
@ -9,18 +11,14 @@ describe('CryptTool', function () {
|
|||
'string',
|
||||
'string',
|
||||
'string',
|
||||
function (key, password, message) {
|
||||
jsdom();
|
||||
window.crypto = new WebCrypto();
|
||||
return message === $.PrivateBin.CryptTool.decipher(
|
||||
async function (key, password, message) {
|
||||
return message.trim() === await $.PrivateBin.CryptTool.decipher(
|
||||
key,
|
||||
password,
|
||||
$.PrivateBin.CryptTool.cipher(key, password, message.trim())
|
||||
await $.PrivateBin.CryptTool.cipher(key, password, message.trim())
|
||||
);
|
||||
}
|
||||
),
|
||||
// reducing amount of checks as running 100 takes about 5 minutes
|
||||
{tests: 5, quiet: true});
|
||||
));
|
||||
});
|
||||
|
||||
// The below static unit tests are included to ensure deciphering of "classic"
|
||||
|
@ -30,9 +28,7 @@ describe('CryptTool', function () {
|
|||
async function () {
|
||||
delete global.Base64;
|
||||
// make btoa available
|
||||
jsdom();
|
||||
global.btoa = window.btoa;
|
||||
window.crypto = new WebCrypto();
|
||||
|
||||
// Of course you can easily decipher the following texts, if you like.
|
||||
// Bonus points for finding their sources and hidden meanings.
|
||||
|
@ -106,8 +102,6 @@ describe('CryptTool', function () {
|
|||
'supports ZeroBin ciphertext (SJCL & Base64 1.7)',
|
||||
async function () {
|
||||
global.Base64 = require('../base64-1.7').Base64;
|
||||
jsdom();
|
||||
window.crypto = new WebCrypto();
|
||||
|
||||
// Of course you can easily decipher the following texts, if you like.
|
||||
// Bonus points for finding their sources and hidden meanings.
|
||||
|
@ -172,8 +166,6 @@ describe('CryptTool', function () {
|
|||
'returns random, non-empty keys',
|
||||
'integer',
|
||||
function(counter) {
|
||||
jsdom();
|
||||
window.crypto = new WebCrypto();
|
||||
var key = $.PrivateBin.CryptTool.getSymmetricKey(),
|
||||
result = (key !== '' && keys.indexOf(key) === -1);
|
||||
keys.push(key);
|
||||
|
@ -187,8 +179,6 @@ describe('CryptTool', function () {
|
|||
'these all return the same base64 string',
|
||||
'string',
|
||||
function(string) {
|
||||
// make btoa/atob available
|
||||
jsdom();
|
||||
// not comparing Base64.js v1.7 encode/decode, that has known issues
|
||||
var Base64 = require('../base64-1.7').Base64,
|
||||
sjcl = global.sjcl.codec.base64.fromBits(global.sjcl.codec.utf8String.toBits(string)),
|
||||
|
|
|
@ -71,7 +71,7 @@ if ($MARKDOWN):
|
|||
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/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-O3MbgA0NDp6Lklnj0GfSs7l5UkuuF/C+/rqjhVwr/Qw/b3jNEyBsl0ufQ3ruweBH10M189aquTnrmSifu1hDlA==" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-EDc6J8fTVdA2igeEPWA+o0eJtt0C1Jc5MAWVwByI/ATpnkqaOGQd/699yb0kwFXpC4dG75/M/1wsZYCkGec1nA==" crossorigin="anonymous"></script>
|
||||
<!--[if lt IE 10]>
|
||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
||||
<![endif]-->
|
||||
|
|
|
@ -49,7 +49,7 @@ if ($MARKDOWN):
|
|||
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/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-O3MbgA0NDp6Lklnj0GfSs7l5UkuuF/C+/rqjhVwr/Qw/b3jNEyBsl0ufQ3ruweBH10M189aquTnrmSifu1hDlA==" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-EDc6J8fTVdA2igeEPWA+o0eJtt0C1Jc5MAWVwByI/ATpnkqaOGQd/699yb0kwFXpC4dG75/M/1wsZYCkGec1nA==" crossorigin="anonymous"></script>
|
||||
<!--[if lt IE 10]>
|
||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
||||
<![endif]-->
|
||||
|
|
Loading…
Reference in a new issue