improving tests, correcting cipher
This commit is contained in:
parent
0dbbb61d11
commit
b97ac08003
|
@ -764,7 +764,8 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
||||||
derivedKey,
|
derivedKey,
|
||||||
StrToArr(compress(message)) // compressed plain text to encrypt
|
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)
|
me.decipher = async function(key, password, data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (password.length > 0) {
|
if ((password || '').trim().length > 0) {
|
||||||
key += sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(password));
|
key += sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(password));
|
||||||
}
|
}
|
||||||
var object = JSON.parse(data),
|
var object = JSON.parse(data),
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
require('../common');
|
||||||
|
jsdom();
|
||||||
|
window.crypto = new WebCrypto();
|
||||||
|
|
||||||
describe('CryptTool', function () {
|
describe('CryptTool', function () {
|
||||||
describe('cipher & decipher', function () {
|
describe('cipher & decipher', function () {
|
||||||
|
@ -9,18 +11,14 @@ describe('CryptTool', function () {
|
||||||
'string',
|
'string',
|
||||||
'string',
|
'string',
|
||||||
'string',
|
'string',
|
||||||
function (key, password, message) {
|
async function (key, password, message) {
|
||||||
jsdom();
|
return message.trim() === await $.PrivateBin.CryptTool.decipher(
|
||||||
window.crypto = new WebCrypto();
|
|
||||||
return message === $.PrivateBin.CryptTool.decipher(
|
|
||||||
key,
|
key,
|
||||||
password,
|
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"
|
// The below static unit tests are included to ensure deciphering of "classic"
|
||||||
|
@ -30,9 +28,7 @@ describe('CryptTool', function () {
|
||||||
async function () {
|
async function () {
|
||||||
delete global.Base64;
|
delete global.Base64;
|
||||||
// make btoa available
|
// make btoa available
|
||||||
jsdom();
|
|
||||||
global.btoa = window.btoa;
|
global.btoa = window.btoa;
|
||||||
window.crypto = new WebCrypto();
|
|
||||||
|
|
||||||
// Of course you can easily decipher the following texts, if you like.
|
// Of course you can easily decipher the following texts, if you like.
|
||||||
// Bonus points for finding their sources and hidden meanings.
|
// Bonus points for finding their sources and hidden meanings.
|
||||||
|
@ -106,8 +102,6 @@ describe('CryptTool', function () {
|
||||||
'supports ZeroBin ciphertext (SJCL & Base64 1.7)',
|
'supports ZeroBin ciphertext (SJCL & Base64 1.7)',
|
||||||
async function () {
|
async function () {
|
||||||
global.Base64 = require('../base64-1.7').Base64;
|
global.Base64 = require('../base64-1.7').Base64;
|
||||||
jsdom();
|
|
||||||
window.crypto = new WebCrypto();
|
|
||||||
|
|
||||||
// Of course you can easily decipher the following texts, if you like.
|
// Of course you can easily decipher the following texts, if you like.
|
||||||
// Bonus points for finding their sources and hidden meanings.
|
// Bonus points for finding their sources and hidden meanings.
|
||||||
|
@ -172,8 +166,6 @@ describe('CryptTool', function () {
|
||||||
'returns random, non-empty keys',
|
'returns random, non-empty keys',
|
||||||
'integer',
|
'integer',
|
||||||
function(counter) {
|
function(counter) {
|
||||||
jsdom();
|
|
||||||
window.crypto = new WebCrypto();
|
|
||||||
var key = $.PrivateBin.CryptTool.getSymmetricKey(),
|
var key = $.PrivateBin.CryptTool.getSymmetricKey(),
|
||||||
result = (key !== '' && keys.indexOf(key) === -1);
|
result = (key !== '' && keys.indexOf(key) === -1);
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
|
@ -187,8 +179,6 @@ describe('CryptTool', function () {
|
||||||
'these all return the same base64 string',
|
'these all return the same base64 string',
|
||||||
'string',
|
'string',
|
||||||
function(string) {
|
function(string) {
|
||||||
// make btoa/atob available
|
|
||||||
jsdom();
|
|
||||||
// not comparing Base64.js v1.7 encode/decode, that has known issues
|
// not comparing Base64.js v1.7 encode/decode, that has known issues
|
||||||
var Base64 = require('../base64-1.7').Base64,
|
var Base64 = require('../base64-1.7').Base64,
|
||||||
sjcl = global.sjcl.codec.base64.fromBits(global.sjcl.codec.utf8String.toBits(string)),
|
sjcl = global.sjcl.codec.base64.fromBits(global.sjcl.codec.utf8String.toBits(string)),
|
||||||
|
|
|
@ -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-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]>
|
<!--[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-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]>
|
<!--[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