2017-12-14 14:23:38 +08:00
|
|
|
'use strict';
|
2018-01-06 20:32:07 +08:00
|
|
|
require('../common');
|
2017-12-14 14:23:38 +08:00
|
|
|
|
|
|
|
describe('CryptTool', function () {
|
|
|
|
describe('cipher & decipher', function () {
|
2018-12-28 04:32:13 +08:00
|
|
|
afterEach(async function () {
|
|
|
|
// pause to let async functions conclude
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1900));
|
|
|
|
});
|
|
|
|
|
2017-12-14 14:23:38 +08:00
|
|
|
this.timeout(30000);
|
|
|
|
it('can en- and decrypt any message', function () {
|
2019-06-22 21:44:54 +08:00
|
|
|
jsc.assert(jsc.forall(
|
2017-12-14 14:23:38 +08:00
|
|
|
'string',
|
|
|
|
'string',
|
|
|
|
'string',
|
2018-12-26 00:34:39 +08:00
|
|
|
async function (key, password, message) {
|
|
|
|
// pause to let async functions conclude
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 300));
|
|
|
|
let clean = jsdom();
|
making webassembly optional, ensuring retry button works when wrong password is provided
Tested configurations:
- browser with WASM support (Firefox 68.0.2)
- creates paste with zlib compression, no password
- creates paste with zlib compression, with password
- reads paste with zlib compression, no password
- reads paste with zlib compression, with password + retry button works
- reads paste without compression, no password
- reads paste without compression, with password + retry button works
- browser without WASM support (Chromium 76.0.3809.100, started via `chromium-browser --js-flags=--noexpose_wasm`)
- creates paste without compression, no password, but shows WASM warning
- creates paste without compression, with password, but shows WASM warning
- fails to read paste with zlib compression, no password + shows WASM error
- fails to read paste with zlib compression, with password + shows WASM error
- reads paste without compression, no password
- reads paste without compression, with password + retry button works
2019-09-08 14:21:54 +08:00
|
|
|
// ensure zlib is getting loaded
|
|
|
|
$.PrivateBin.InitialCheck.init();
|
2018-09-02 17:33:27 +08:00
|
|
|
window.crypto = new WebCrypto();
|
2018-09-02 04:55:52 +08:00
|
|
|
message = message.trim();
|
2018-12-26 00:34:39 +08:00
|
|
|
let cipherMessage = await $.PrivateBin.CryptTool.cipher(
|
|
|
|
key, password, message, []
|
|
|
|
),
|
|
|
|
plaintext = await $.PrivateBin.CryptTool.decipher(
|
making webassembly optional, ensuring retry button works when wrong password is provided
Tested configurations:
- browser with WASM support (Firefox 68.0.2)
- creates paste with zlib compression, no password
- creates paste with zlib compression, with password
- reads paste with zlib compression, no password
- reads paste with zlib compression, with password + retry button works
- reads paste without compression, no password
- reads paste without compression, with password + retry button works
- browser without WASM support (Chromium 76.0.3809.100, started via `chromium-browser --js-flags=--noexpose_wasm`)
- creates paste without compression, no password, but shows WASM warning
- creates paste without compression, with password, but shows WASM warning
- fails to read paste with zlib compression, no password + shows WASM error
- fails to read paste with zlib compression, with password + shows WASM error
- reads paste without compression, no password
- reads paste without compression, with password + retry button works
2019-09-08 14:21:54 +08:00
|
|
|
key, password, cipherMessage
|
2018-12-26 00:34:39 +08:00
|
|
|
);
|
|
|
|
clean();
|
|
|
|
return message === plaintext;
|
2017-12-14 14:23:38 +08:00
|
|
|
}
|
2018-12-28 04:32:13 +08:00
|
|
|
),
|
|
|
|
{tests: 3});
|
2017-12-14 14:23:38 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// The below static unit tests are included to ensure deciphering of "classic"
|
|
|
|
// SJCL based pastes still works
|
|
|
|
it(
|
2018-08-05 14:56:03 +08:00
|
|
|
'supports PrivateBin v1 ciphertext (SJCL & browser atob)',
|
2018-09-02 18:12:55 +08:00
|
|
|
function () {
|
2018-08-05 14:56:03 +08:00
|
|
|
delete global.Base64;
|
2018-12-26 00:34:39 +08:00
|
|
|
let clean = jsdom();
|
2018-09-02 17:33:27 +08:00
|
|
|
window.crypto = new WebCrypto();
|
2018-08-05 14:56:03 +08:00
|
|
|
|
2017-12-14 14:23:38 +08:00
|
|
|
// Of course you can easily decipher the following texts, if you like.
|
|
|
|
// Bonus points for finding their sources and hidden meanings.
|
2018-09-02 18:12:55 +08:00
|
|
|
return $.PrivateBin.CryptTool.decipher(
|
2017-12-14 14:23:38 +08:00
|
|
|
'6t2qsmLyfXIokNCL+3/yl15rfTUBQvm5SOnFPvNE7Q8=',
|
|
|
|
// -- "That's amazing. I've got the same combination on my luggage."
|
2018-12-26 00:34:39 +08:00
|
|
|
Array.apply(0, Array(6)).map((_,b) => b + 1).join(''),
|
2018-01-06 16:26:10 +08:00
|
|
|
'{"iv":"4HNFIl7eYbCh6HuShctTIA==","v":1,"iter":10000,"ks"' +
|
|
|
|
':256,"ts":128,"mode":"gcm","adata":"","cipher":"aes","sa' +
|
|
|
|
'lt":"u0lQvePq6L0=","ct":"fGPUVrDyaVr1ZDGb+kqQ3CPEW8x4YKG' +
|
|
|
|
'fzHDmA0Vjkh250aWNe7Cnigkps9aaFVMX9AaerrTp3yZbojJtNqVGMfL' +
|
|
|
|
'dUTu+53xmZHqRKxCCqSfDNSNoW4Oxk5OVgAtRyuG4bXHDsWTXDNz2xce' +
|
|
|
|
'qzVFqhkwTwlUchrV7uuFK/XUKTNjPFM744moivIcBbfM2FOeKlIFs8RY' +
|
|
|
|
'PYuvqQhp2rMLlNGwwKh//4kykQsHMQDeSDuJl8stMQzgWR/btUBZuwNZ' +
|
|
|
|
'EydkMH6IPpTdf5WTSrZ+wC2OK0GutCm4UaEe6txzaTMfu+WRVu4PN6q+' +
|
|
|
|
'N+2zljWJ1XdpVcN/i0Sv4QVMym0Xa6y0eccEhj/69o47PmExmMMeEwEx' +
|
|
|
|
'ImPalMNT9JUSiZdOZJ/GdzwrwoIuq1mdQR6vSH+XJ/8jXJQ7bjjJVJYX' +
|
|
|
|
'TcT0Di5jixArI2Kpp1GGlGVFbLgPugwU1wczg+byqeDOAECXRRnQcoge' +
|
|
|
|
'aJtVcRwXwfy4j3ORFcblYMilxyHqKBewcYPRVBGtBs50cVjSIkAfR84r' +
|
|
|
|
'nc1nfvnxK/Gmm+4VBNHI6ODWNpRolVMCzXjbKYnV3Are5AgSpsTqaGl4' +
|
|
|
|
'1VJGpcco6cAwi4K0Bys1seKR+bLSdUgqRrkEqSRSdu3/VTu9HhEk8an0' +
|
|
|
|
'rjTE4CBB5/LMn16p0TGLoOb32odKFIEtpanVvLjeyiVMvSxcgYLNnTi/' +
|
|
|
|
'5FiaAC4pJxRD+AZHedU1FICUeEXxIcac/4E5qjkHjX9SpQtLl80QLIVn' +
|
|
|
|
'jNliZm7QLB/nKu7W8Jb0+/CiTdV3Q9LhxlH4ciprnX+W0B00BKYFHnL9' +
|
|
|
|
'jRVzKdXhf1EHydbXMAfpCjHAXIVCkFakJinQBDIIw/SC6Yig0u0ddEID' +
|
|
|
|
'2B7LYAP1iE4RZwzTrxCB+ke2jQr8c20Jj6u6ShFOPC9DCw9XupZ4HAal' +
|
|
|
|
'VG00kSgjus+b8zrVji3/LKEhb4EBzp1ctBJCFTeXwej8ZETLoXTylev5' +
|
|
|
|
'dlwZSYAbuBPPcbFR/xAIPx3uDabd1E1gTqUc68ICIGhd197Mb2eRWiSv' +
|
|
|
|
'Hr5SPsASerMxId6XA6+iQlRiI+NDR+TGVNmCnfxSlyPFMOHGTmslXOGI' +
|
|
|
|
'qGfBR8l4ft8YVZ70lCwmwTuViGc75ULSf9mM57/LmRzQFMYQtvI8IFK9' +
|
|
|
|
'JaQEMY5xz0HLtR4iyQUUdwR9e0ytBNdWF2a2WPDEnJuY/QJo4GzTlgv4' +
|
|
|
|
'QUxMXI5htsn2rf0HxCFu7Po8DNYLxTS+67hYjDIYWYaEIc8LXWMLyDm9' +
|
|
|
|
'C5fARPJ4F2BIWgzgzkNj+dVjusft2XnziamWdbS5u3kuRlVuz5LQj+R5' +
|
|
|
|
'imnqQAincdZTkTT1nYx+DatlOLllCYIHffpI="}'
|
2018-12-26 00:34:39 +08:00
|
|
|
).then(function (paste1) {
|
2018-09-02 17:52:57 +08:00
|
|
|
$.PrivateBin.CryptTool.decipher(
|
2018-09-02 17:49:55 +08:00
|
|
|
's9pmKZKOBN7EVvHpTA8jjLFH3Xlz/0l8lB4+ONPACrM=',
|
|
|
|
'', // no password
|
|
|
|
'{"iv":"WA42mdxIVXUwBqZu7JYNiw==","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hEknERyvt45og2kORJO' +
|
|
|
|
'EJayHW+jZgR0Y0jM3Nk17ubpij2gHxNx9kiLDOiCGSV5mn9mV7qd3HHc' +
|
|
|
|
'OMSykiBgbyzjobi96LT2dIGLeDXTIdPOog8wyobO4jWq0GGs0vBB8oSY' +
|
|
|
|
'XhHvixZLcSjX2KQuHmEoWzmJcr3DavdoXZmAurGWLKjzEdJc5dSD/eNr' +
|
|
|
|
'99gjHX7wphJ6umKMM+fn6PcbYJkhDh2GlJL5COXjXfm/5aj/vuyaRRWZ' +
|
|
|
|
'MZtmnYpGAtAPg7AUG"}'
|
2018-12-26 00:34:39 +08:00
|
|
|
).then(function (paste2) {
|
2018-09-02 17:49:55 +08:00
|
|
|
clean();
|
|
|
|
assert.ok(
|
|
|
|
paste1.includes('securely packed in iron') &&
|
|
|
|
paste2.includes('Sol is right')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2017-12-14 14:23:38 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
'supports ZeroBin ciphertext (SJCL & Base64 1.7)',
|
2018-09-02 18:12:55 +08:00
|
|
|
function () {
|
2017-12-14 14:23:38 +08:00
|
|
|
global.Base64 = require('../base64-1.7').Base64;
|
2018-09-02 17:33:27 +08:00
|
|
|
var clean = jsdom();
|
|
|
|
window.crypto = new WebCrypto();
|
2017-12-14 14:23:38 +08:00
|
|
|
|
|
|
|
// Of course you can easily decipher the following texts, if you like.
|
|
|
|
// Bonus points for finding their sources and hidden meanings.
|
2018-09-02 18:12:55 +08:00
|
|
|
return $.PrivateBin.CryptTool.decipher(
|
2017-12-14 14:23:38 +08:00
|
|
|
'6t2qsmLyfXIokNCL+3/yl15rfTUBQvm5SOnFPvNE7Q8=',
|
|
|
|
// -- "That's amazing. I've got the same combination on my luggage."
|
2018-12-26 00:34:39 +08:00
|
|
|
Array.apply(0, Array(6)).map((_,b) => b + 1).join(''),
|
2018-01-06 16:26:10 +08:00
|
|
|
'{"iv":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2pX1WNWE7dLS2wfroMAS3kh8P22DA' +
|
|
|
|
'V37AeiNoD2PcI6ZcHbRdPa+XRrRcJhSPPW7UQ0z4OvBfjdu/w390QxAx' +
|
|
|
|
'SxvZewoh49fKKB6hTsRnZb4tpHkjlww=="}'
|
2018-12-26 00:34:39 +08:00
|
|
|
).then(function (paste1) {
|
2018-09-02 17:52:57 +08:00
|
|
|
$.PrivateBin.CryptTool.decipher(
|
2018-09-02 17:49:55 +08:00
|
|
|
's9pmKZKOBN7EVvHpTA8jjLFH3Xlz/0l8lB4+ONPACrM=',
|
|
|
|
'', // no password
|
|
|
|
'{"iv":"Z7lAZQbkrqGMvruxoSm6Pw==","v":1,"iter":10000,"ks"' +
|
|
|
|
':256,"ts":128,"mode":"gcm","adata":"","cipher":"aes","sa' +
|
|
|
|
'lt":"jN6CjbQMJCM=","ct":"PuOPWB3i2FPcreSrLYeQf84LdE8RHjs' +
|
|
|
|
'c+MGtiOr4b7doNyWKYtkNorbRadxaPnEee2/Utrp1MIIfY5juJSy8RGw' +
|
|
|
|
'EPX5ciWcYe6EzsXWznsnvhmpKNj9B7eIIrfSbxfy8E2e/g7xav1nive+' +
|
|
|
|
'ljToka3WT1DZ8ILQd/NbnJeHWaoSEOfvz8+d8QJPb1tNZvs7zEY95Dum' +
|
|
|
|
'QwbyOsIMKAvcZHJ9OJNpujXzdMyt6DpcFcqlldWBZ/8q5rAUTw0HNx/r' +
|
|
|
|
'CgbhAxRYfNoTLIcMM4L0cXbPSgCjwf5FuO3EdE13mgEDhcClW79m0Qvc' +
|
|
|
|
'nIh8xgzYoxLbp0+AwvC/MbZM8savN/0ieWr2EKkZ04ggiOIEyvfCUuNp' +
|
|
|
|
'rQBYO+y8kKduNEN6by0Yf4LRCPfmwN+GezDLuzTnZIMhPbGqUAdgV6Ex' +
|
|
|
|
'qK2ULEEIrQEMoOuQIxfoMhqLlzG79vXGt2O+BY+4IiYfvmuRLks4UXfy' +
|
|
|
|
'HqxPXTJg48IYbGs0j4TtJPUgp3523EyYLwEGyVTAuWhYAmVIwd/hoV7d' +
|
|
|
|
'7tmfcF73w9dufDFI3LNca2KxzBnWNPYvIZKBwWbq8ncxkb191dP6mjEi' +
|
|
|
|
'7NnhqVk5A6vIBbu4AC5PZf76l6yep4xsoy/QtdDxCMocCXeAML9MQ9uP' +
|
|
|
|
'QbuspOKrBvMfN5igA1kBqasnxI472KBNXsdZnaDddSVUuvhTcETM="}'
|
2018-12-26 00:34:39 +08:00
|
|
|
).then(function (paste2) {
|
2018-09-02 17:49:55 +08:00
|
|
|
clean();
|
|
|
|
delete global.Base64;
|
|
|
|
assert.ok(
|
|
|
|
paste1.includes('securely packed in iron') &&
|
|
|
|
paste2.includes('Sol is right')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2017-12-14 14:23:38 +08:00
|
|
|
}
|
|
|
|
);
|
2019-05-16 00:56:42 +08:00
|
|
|
|
|
|
|
it('does not truncate messages', async function () {
|
|
|
|
let message = fs.readFileSync('test/compression-sample.txt', 'utf8'),
|
|
|
|
clean = jsdom();
|
|
|
|
window.crypto = new WebCrypto();
|
making webassembly optional, ensuring retry button works when wrong password is provided
Tested configurations:
- browser with WASM support (Firefox 68.0.2)
- creates paste with zlib compression, no password
- creates paste with zlib compression, with password
- reads paste with zlib compression, no password
- reads paste with zlib compression, with password + retry button works
- reads paste without compression, no password
- reads paste without compression, with password + retry button works
- browser without WASM support (Chromium 76.0.3809.100, started via `chromium-browser --js-flags=--noexpose_wasm`)
- creates paste without compression, no password, but shows WASM warning
- creates paste without compression, with password, but shows WASM warning
- fails to read paste with zlib compression, no password + shows WASM error
- fails to read paste with zlib compression, with password + shows WASM error
- reads paste without compression, no password
- reads paste without compression, with password + retry button works
2019-09-08 14:21:54 +08:00
|
|
|
// ensure zlib is getting loaded
|
|
|
|
$.PrivateBin.InitialCheck.init();
|
2019-05-16 00:56:42 +08:00
|
|
|
let cipherMessage = await $.PrivateBin.CryptTool.cipher(
|
|
|
|
'foo', 'bar', message, []
|
|
|
|
),
|
|
|
|
plaintext = await $.PrivateBin.CryptTool.decipher(
|
|
|
|
'foo', 'bar', cipherMessage
|
|
|
|
);
|
|
|
|
clean();
|
|
|
|
assert.strictEqual(
|
|
|
|
message,
|
|
|
|
plaintext
|
|
|
|
);
|
|
|
|
});
|
2019-05-19 14:25:34 +08:00
|
|
|
|
|
|
|
it('can en- and decrypt a particular message (#260)', function () {
|
2019-06-22 21:44:54 +08:00
|
|
|
jsc.assert(jsc.forall(
|
2019-05-19 14:25:34 +08:00
|
|
|
'string',
|
|
|
|
'string',
|
|
|
|
async function (key, password) {
|
|
|
|
// pause to let async functions conclude
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 300));
|
|
|
|
const message = `
|
2019-05-19 14:43:07 +08:00
|
|
|
1 subgoal
|
2019-05-19 14:25:34 +08:00
|
|
|
|
2019-05-19 14:43:07 +08:00
|
|
|
inv : Assert
|
|
|
|
expr : Expr
|
|
|
|
sBody : Instr
|
|
|
|
deduction : (|- [|inv /\ assertOfExpr expr|] sBody [|inv|])%assert
|
|
|
|
IHdeduction : (|= [|inv /\ assertOfExpr expr |] sBody [|inv|])%assert
|
|
|
|
mem : Mem
|
|
|
|
preInMem : inv mem
|
|
|
|
m : Mem
|
|
|
|
n : nat
|
|
|
|
interpRel : interp (nth_iterate sBody n) (MemElem mem) = CpoElem Mem m
|
|
|
|
lastIter : interp (nth_iterate sBody n) (MemElem mem) |=e expr_neg expr
|
|
|
|
notLastIter : forall p : nat,
|
|
|
|
p < n -> interp (nth_iterate sBody p) (MemElem mem) |=e expr
|
|
|
|
isWhile : interp (while expr sBody) (MemElem mem) =
|
|
|
|
interp (nth_iterate sBody n) (MemElem mem)
|
2019-05-19 14:25:34 +08:00
|
|
|
|
2019-05-19 14:43:07 +08:00
|
|
|
======================== ( 1 / 1 )
|
|
|
|
conseq_or_bottom inv (interp (nth_iterate sBody n) (MemElem mem))
|
2019-05-19 14:25:34 +08:00
|
|
|
`;
|
|
|
|
let clean = jsdom();
|
making webassembly optional, ensuring retry button works when wrong password is provided
Tested configurations:
- browser with WASM support (Firefox 68.0.2)
- creates paste with zlib compression, no password
- creates paste with zlib compression, with password
- reads paste with zlib compression, no password
- reads paste with zlib compression, with password + retry button works
- reads paste without compression, no password
- reads paste without compression, with password + retry button works
- browser without WASM support (Chromium 76.0.3809.100, started via `chromium-browser --js-flags=--noexpose_wasm`)
- creates paste without compression, no password, but shows WASM warning
- creates paste without compression, with password, but shows WASM warning
- fails to read paste with zlib compression, no password + shows WASM error
- fails to read paste with zlib compression, with password + shows WASM error
- reads paste without compression, no password
- reads paste without compression, with password + retry button works
2019-09-08 14:21:54 +08:00
|
|
|
// ensure zlib is getting loaded
|
|
|
|
$.PrivateBin.InitialCheck.init();
|
2019-05-19 14:25:34 +08:00
|
|
|
window.crypto = new WebCrypto();
|
|
|
|
let cipherMessage = await $.PrivateBin.CryptTool.cipher(
|
|
|
|
key, password, message, []
|
|
|
|
),
|
|
|
|
plaintext = await $.PrivateBin.CryptTool.decipher(
|
|
|
|
key, password, cipherMessage
|
|
|
|
);
|
|
|
|
clean();
|
|
|
|
return message === plaintext;
|
|
|
|
}
|
|
|
|
),
|
|
|
|
{tests: 3});
|
|
|
|
});
|
2017-12-14 14:23:38 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('getSymmetricKey', function () {
|
2018-09-02 17:33:27 +08:00
|
|
|
this.timeout(30000);
|
2017-12-14 14:23:38 +08:00
|
|
|
var keys = [];
|
|
|
|
|
|
|
|
// the parameter is used to ensure the test is run more then one time
|
|
|
|
jsc.property(
|
|
|
|
'returns random, non-empty keys',
|
2018-08-05 04:30:01 +08:00
|
|
|
'integer',
|
|
|
|
function(counter) {
|
2018-09-02 17:33:27 +08:00
|
|
|
var clean = jsdom();
|
|
|
|
window.crypto = new WebCrypto();
|
2017-12-14 14:23:38 +08:00
|
|
|
var key = $.PrivateBin.CryptTool.getSymmetricKey(),
|
|
|
|
result = (key !== '' && keys.indexOf(key) === -1);
|
|
|
|
keys.push(key);
|
2018-09-02 17:33:27 +08:00
|
|
|
clean();
|
2017-12-14 14:23:38 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|