|
Packit Service |
30b792 |
/* gpgme.js - Javascript integration for gpgme
|
|
Packit Service |
30b792 |
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* This file is part of GPGME.
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* GPGME is free software; you can redistribute it and/or modify it
|
|
Packit Service |
30b792 |
* under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
30b792 |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
30b792 |
* the License, or (at your option) any later version.
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* GPGME is distributed in the hope that it will be useful, but
|
|
Packit Service |
30b792 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
30b792 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
30b792 |
* Lesser General Public License for more details.
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
30b792 |
* License along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
Packit Service |
30b792 |
* SPDX-License-Identifier: LGPL-2.1+
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* Author(s):
|
|
Packit Service |
30b792 |
* Maximilian Krambach <mkrambach@intevation.de>
|
|
Packit Service |
30b792 |
*/
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
/* global describe, it, expect, before, Gpgmejs */
|
|
Packit Service |
30b792 |
/* global inputvalues, fixedLengthString, bigString */
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
describe('Encryption', function () {
|
|
Packit Service |
30b792 |
let context = null;
|
|
Packit Service |
30b792 |
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
|
Packit Service |
30b792 |
before(function (done){
|
|
Packit Service |
30b792 |
const prm = Gpgmejs.init({ timeout: 2000 });
|
|
Packit Service |
30b792 |
prm.then(function (gpgmejs){
|
|
Packit Service |
30b792 |
context = gpgmejs;
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
it('Successful encrypt', function (done) {
|
|
Packit Service |
30b792 |
const data = inputvalues.encrypt.good.data;
|
|
Packit Service |
30b792 |
context.encrypt({ data: data, publicKeys: good_fpr })
|
|
Packit Service |
30b792 |
.then(function (answer) {
|
|
Packit Service |
30b792 |
expect(answer).to.not.be.empty;
|
|
Packit Service |
30b792 |
expect(answer.data).to.be.a('string');
|
|
Packit Service |
30b792 |
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
|
Packit Service |
30b792 |
expect(answer.data).to.include('END PGP MESSAGE');
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
it( 'encrypt with \'armor\': true should returned an armored block',
|
|
Packit Service |
30b792 |
function (done){
|
|
Packit Service |
30b792 |
const data = bigString(1000);
|
|
Packit Service |
30b792 |
context.encrypt({ data: data, publicKeys: good_fpr, armor: true })
|
|
Packit Service |
30b792 |
.then(function (answer){
|
|
Packit Service |
30b792 |
expect(answer).to.not.be.empty;
|
|
Packit Service |
30b792 |
expect(answer.data).to.be.a('string');
|
|
Packit Service |
30b792 |
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
|
Packit Service |
30b792 |
expect(answer.data).to.include('END PGP MESSAGE');
|
|
Packit Service |
30b792 |
expect(answer.format).to.equal('ascii');
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
it( 'encrypt with \'armor\': false and \'expected\': \'uint8\' returns ' +
|
|
Packit Service |
30b792 |
'an Uint8Array', function (done) {
|
|
Packit Service |
30b792 |
const data = bigString(1000);
|
|
Packit Service |
30b792 |
context.encrypt({
|
|
Packit Service |
30b792 |
data: data, publicKeys: good_fpr, armor: false, expect: 'uint8'
|
|
Packit Service |
30b792 |
}).then(function (answer){
|
|
Packit Service |
30b792 |
expect(answer).to.not.be.empty;
|
|
Packit Service |
30b792 |
expect(answer.data).to.be.a('Uint8Array');
|
|
Packit Service |
30b792 |
expect(answer.format).to.equal('uint8');
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
it( 'encrypt with \'armor\': false and \'expected\': \'base64\' returns ' +
|
|
Packit Service |
30b792 |
'a base64 string', function (done) {
|
|
Packit Service |
30b792 |
const data = bigString(1000);
|
|
Packit Service |
30b792 |
context.encrypt({
|
|
Packit Service |
30b792 |
data: data, publicKeys: good_fpr, armor: false, expect: 'base64'
|
|
Packit Service |
30b792 |
}).then(function (answer){
|
|
Packit Service |
30b792 |
expect(answer).to.not.be.empty;
|
|
Packit Service |
30b792 |
expect(answer.data).to.be.a('string');
|
|
Packit Service |
30b792 |
expect(answer.format).to.equal('base64');
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
const sizes = [5,20,50];
|
|
Packit Service |
30b792 |
for (let i=0; i < sizes.length; i++) {
|
|
Packit Service |
30b792 |
it('Successful encrypt a ' + sizes[i] + 'MB message', function (done) {
|
|
Packit Service |
30b792 |
const data = fixedLengthString(sizes[i]);
|
|
Packit Service |
30b792 |
context.encrypt({ data: data, publicKeys: good_fpr })
|
|
Packit Service |
30b792 |
.then(function (answer) {
|
|
Packit Service |
30b792 |
expect(answer).to.not.be.empty;
|
|
Packit Service |
30b792 |
expect(answer.data).to.be.a('string');
|
|
Packit Service |
30b792 |
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
|
Packit Service |
30b792 |
expect(answer.data).to.include('END PGP MESSAGE');
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
}).timeout(20000);
|
|
Packit Service |
30b792 |
}
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
it('Sending encryption without keys fails', function (done) {
|
|
Packit Service |
30b792 |
const data = inputvalues.encrypt.good.data;
|
|
Packit Service |
30b792 |
context.encrypt({ data: data }).then(function (answer) {
|
|
Packit Service |
30b792 |
expect(answer).to.be.undefined;
|
|
Packit Service |
30b792 |
}, function (error){
|
|
Packit Service |
30b792 |
expect(error).to.be.an('Error');
|
|
Packit Service |
30b792 |
expect(error.code).to.equal('MSG_INCOMPLETE');
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
it('Sending encryption without data fails', function (done) {
|
|
Packit Service |
30b792 |
context.encrypt({ data: null, publicKeys: good_fpr })
|
|
Packit Service |
30b792 |
.then(function (answer) {
|
|
Packit Service |
30b792 |
expect(answer).to.be.undefined;
|
|
Packit Service |
30b792 |
}, function (error) {
|
|
Packit Service |
30b792 |
expect(error).to.be.an.instanceof(Error);
|
|
Packit Service |
30b792 |
expect(error.code).to.equal('MSG_INCOMPLETE');
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
it('Sending encryption with non existing keys fails', function (done) {
|
|
Packit Service |
30b792 |
const data = inputvalues.encrypt.good.data;
|
|
Packit Service |
30b792 |
const bad_fpr = inputvalues.encrypt.bad.fingerprint;
|
|
Packit Service |
30b792 |
context.encrypt({ data:data, publicKeys: bad_fpr })
|
|
Packit Service |
30b792 |
.then(function (answer) {
|
|
Packit Service |
30b792 |
expect(answer).to.be.undefined;
|
|
Packit Service |
30b792 |
}, function (error){
|
|
Packit Service |
30b792 |
expect(error).to.be.an('Error');
|
|
Packit Service |
30b792 |
expect(error.code).to.not.be.undefined;
|
|
Packit Service |
30b792 |
expect(error.code).to.equal('GNUPG_ERROR');
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
}).timeout(5000);
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
it('Overly large message ( > 64MB) is rejected', function (done) {
|
|
Packit Service |
30b792 |
const data = fixedLengthString(65);
|
|
Packit Service |
30b792 |
context.encrypt({ data: data, publicKeys: good_fpr })
|
|
Packit Service |
30b792 |
.then(function (answer) {
|
|
Packit Service |
30b792 |
expect(answer).to.be.undefined;
|
|
Packit Service |
30b792 |
}, function (error){
|
|
Packit Service |
30b792 |
expect(error).to.be.an.instanceof(Error);
|
|
Packit Service |
30b792 |
// TODO: there is a 64 MB hard limit at least in chrome at:
|
|
Packit Service |
30b792 |
// chromium//extensions/renderer/messaging_util.cc:
|
|
Packit Service |
30b792 |
// kMaxMessageLength
|
|
Packit Service |
30b792 |
// The error will be a browser error, not from gnupg or from
|
|
Packit Service |
30b792 |
// this library
|
|
Packit Service |
30b792 |
done();
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
}).timeout(8000);
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
});
|