added tests for entropy checks and key generation, added base64 experiment, showing we could replace Base64.js v2.1.9 with other options, but still need to find a way to handle v1.7 format and UTF16 to UTF8 conversion (btou / utob functions)
This commit is contained in:
parent
3cf005c8ae
commit
2d4c75be85
62
js/test.js
62
js/test.js
@ -2,9 +2,6 @@
|
|||||||
var jsc = require('jsverify'),
|
var jsc = require('jsverify'),
|
||||||
jsdom = require('jsdom-global'),
|
jsdom = require('jsdom-global'),
|
||||||
cleanup = jsdom(),
|
cleanup = jsdom(),
|
||||||
base64lib = require('./base64-2.1.9'),
|
|
||||||
rawdeflatelib = require('./rawdeflate-0.5'),
|
|
||||||
rawinflatelib = require('./rawinflate-0.3'),
|
|
||||||
|
|
||||||
a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
|
a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
|
||||||
'n','o','p','q','r','s','t','u','v','w','x','y','z'],
|
'n','o','p','q','r','s','t','u','v','w','x','y','z'],
|
||||||
@ -22,9 +19,9 @@ var jsc = require('jsverify'),
|
|||||||
|
|
||||||
global.$ = global.jQuery = require('./jquery-3.1.1');
|
global.$ = global.jQuery = require('./jquery-3.1.1');
|
||||||
global.sjcl = require('./sjcl-1.0.6');
|
global.sjcl = require('./sjcl-1.0.6');
|
||||||
global.Base64 = base64lib.Base64;
|
global.Base64 = require('./base64-2.1.9').Base64;
|
||||||
global.RawDeflate = rawdeflatelib.RawDeflate;
|
global.RawDeflate = require('./rawdeflate-0.5').RawDeflate;
|
||||||
global.RawDeflate.inflate = rawinflatelib.RawDeflate.inflate;
|
global.RawDeflate.inflate = require('./rawinflate-0.3').RawDeflate.inflate;
|
||||||
require('./privatebin');
|
require('./privatebin');
|
||||||
|
|
||||||
// redirect console messages to log file
|
// redirect console messages to log file
|
||||||
@ -441,7 +438,7 @@ describe('I18n', function () {
|
|||||||
|
|
||||||
describe('CryptTool', function () {
|
describe('CryptTool', function () {
|
||||||
describe('cipher & decipher', function () {
|
describe('cipher & decipher', function () {
|
||||||
this.timeout(20000);
|
this.timeout(30000);
|
||||||
it('can en- and decrypt any message', function () {
|
it('can en- and decrypt any message', function () {
|
||||||
jsc.check(jsc.forall(
|
jsc.check(jsc.forall(
|
||||||
'string',
|
'string',
|
||||||
@ -461,7 +458,9 @@ describe('CryptTool', function () {
|
|||||||
|
|
||||||
// The below static unit test is included to ensure deciphering of "classic"
|
// The below static unit test is included to ensure deciphering of "classic"
|
||||||
// SJCL based pastes still works
|
// SJCL based pastes still works
|
||||||
it('supports v1 ciphertext (SJCL)', function () {
|
it(
|
||||||
|
'supports v1 ciphertext (SJCL)',
|
||||||
|
function () {
|
||||||
// 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.
|
||||||
var paste1 = $.PrivateBin.CryptTool.decipher(
|
var paste1 = $.PrivateBin.CryptTool.decipher(
|
||||||
@ -478,7 +477,54 @@ describe('CryptTool', function () {
|
|||||||
if (!paste1.includes('securely packed in iron') || !paste2.includes('Sol is right')) {
|
if (!paste1.includes('securely packed in iron') || !paste2.includes('Sol is right')) {
|
||||||
throw Error('v1 (SJCL based) pastes could not be deciphered');
|
throw Error('v1 (SJCL based) pastes could not be deciphered');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isEntropyReady & addEntropySeedListener', function () {
|
||||||
|
it(
|
||||||
|
'lets us know that enough entropy is collected or make us wait for it',
|
||||||
|
function(done) {
|
||||||
|
if ($.PrivateBin.CryptTool.isEntropyReady()) {
|
||||||
|
done();
|
||||||
|
} else {
|
||||||
|
$.PrivateBin.CryptTool.addEntropySeedListener(function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getSymmetricKey', function () {
|
||||||
|
var keys = [];
|
||||||
|
|
||||||
|
// the parameter is used to ensure the test is run more then one time
|
||||||
|
jsc.property(
|
||||||
|
'returns random, non-empty keys',
|
||||||
|
'nat',
|
||||||
|
function(n) {
|
||||||
|
var key = $.PrivateBin.CryptTool.getSymmetricKey(),
|
||||||
|
result = (key !== '' && keys.indexOf(key) === -1);
|
||||||
|
keys.push(key);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Base64.js vs SJCL.js vs abab.js', function () {
|
||||||
|
var btoa = require('abab').btoa;
|
||||||
|
|
||||||
|
jsc.property(
|
||||||
|
'these all return the same base64 string',
|
||||||
|
'string',
|
||||||
|
function(string) {
|
||||||
|
var base64 = Base64.toBase64(string),
|
||||||
|
sjcl = global.sjcl.codec.base64.fromBits(global.sjcl.codec.utf8String.toBits(string)),
|
||||||
|
abab = btoa(Base64.utob(string));
|
||||||
|
return base64 === sjcl && sjcl === abab;
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user