diff --git a/lang/js/BrowserTestExtension/tests/KeyImportExport.js b/lang/js/BrowserTestExtension/tests/KeyImportExport.js
index f57877f4..b3d95bbc 100644
--- a/lang/js/BrowserTestExtension/tests/KeyImportExport.js
+++ b/lang/js/BrowserTestExtension/tests/KeyImportExport.js
@@ -1,152 +1,152 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
* Raimund Renkert
*/
/* global describe, it, expect, before, afterEach, Gpgmejs*/
/* global ImportablePublicKey, inputvalues */
describe('Key importing', function () {
const fpr = ImportablePublicKey.fingerprint;
const pubKey = ImportablePublicKey.key;
const changedKey = ImportablePublicKey.keyChangedUserId;
let context = null;
before(function (done){
- const prm = Gpgmejs.init();
+ const prm = Gpgmejs.init({ timeout: 2000 });
prm.then(function (gpgmejs){
context = gpgmejs;
context.Keyring.getKeys({ pattern: fpr }).then(
function (result){
if (result.length === 1) {
result[0].delete().then(function (){
done();
},function (){
done();
});
} else {
done();
}
});
});
});
afterEach(function (done){
// delete the test key if still present
context.Keyring.getKeys({ pattern: fpr }).then(
function (result){
if (result.length === 1) {
result[0].delete().then(function (){
done();
},function (){
done();
});
} else {
done();
}
});
});
it('Importing Key', function (done) {
context.Keyring.getKeys({ pattern: fpr }).then(function (result){
expect(result).to.be.an('array');
expect(result.length).to.equal(0);
context.Keyring.importKey(pubKey).then(function (result){
expect(result.Keys).to.be.an('array');
expect(result.Keys[0]).to.not.be.undefined;
expect(result.Keys[0].key).to.be.an('object');
expect(result.Keys[0].key.fingerprint).to.equal(fpr);
expect(result.Keys[0].status).to.equal('newkey');
expect(result.summary.considered).to.equal(1);
expect(result.summary.imported).to.equal(1);
done();
});
});
});
it('Updating Key', function (done){
context.Keyring.importKey(pubKey)
.then(function (result){
expect(result.Keys[0].key).to.not.be.undefined;
expect(result.Keys[0].status).to.equal('newkey');
context.Keyring.importKey(changedKey).then(function (res){
expect(res.Keys[0].key).to.be.an('object');
expect(res.Keys[0].key.fingerprint).to.equal(fpr);
expect(res.Keys[0].status).to.equal('change');
expect(res.Keys[0].changes.userId).to.be.true;
expect(res.Keys[0].changes.subkey).to.be.false;
expect(res.Keys[0].changes.signature).to.be.true;
expect(res.summary.considered).to.equal(1);
done();
});
});
});
it('Deleting Key', function (done) {
context.Keyring.importKey(pubKey).then(function (result){
expect(result.Keys[0].key).to.be.an('object');
expect(result.Keys[0].key.fingerprint).to.equal(fpr);
result.Keys[0].key.delete().then(function (result){
expect(result).to.be.true;
done();
});
});
});
it('Import result feedback', function (done){
context.Keyring.importKey(pubKey, true).then(function (result){
expect(result).to.be.an('object');
expect(result.Keys[0]).to.be.an('object');
expect(result.Keys[0].key.fingerprint).to.equal(fpr);
expect(result.Keys[0].status).to.equal('newkey');
result.Keys[0].key.getArmor().then(function (armor){
expect(armor).to.be.a('string');
done();
});
});
});
it('exporting armored Key with getKeysArmored', function (done) {
context.Keyring.importKey(pubKey).then(function (){
context.Keyring.getKeysArmored({ pattern: fpr })
.then(function (result){
expect(result).to.be.an('object');
expect(result.armored).to.be.a('string');
expect(result.secret_fprs).to.be.undefined;
done();
});
});
});
it('Exporting Key (including secret fingerprints)', function (done) {
const key_secret = inputvalues.encrypt.good.fingerprint;
context.Keyring.getKeysArmored({
pattern: key_secret, with_secret_fpr: true })
.then(function (result){
expect(result).to.be.an('object');
expect(result.armored).to.be.a('string');
expect(result.secret_fprs).to.be.an('array');
expect(result.secret_fprs[0]).to.equal(key_secret);
done();
});
});
});
\ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/tests/KeyInfos.js b/lang/js/BrowserTestExtension/tests/KeyInfos.js
index 553aedb9..d1229584 100644
--- a/lang/js/BrowserTestExtension/tests/KeyInfos.js
+++ b/lang/js/BrowserTestExtension/tests/KeyInfos.js
@@ -1,59 +1,59 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global describe, it, expect, before, Gpgmejs */
/* global inputvalues*/
describe('Key information', function () {
let context = null;
before(function (done){
- const prm = Gpgmejs.init();
+ const prm = Gpgmejs.init({ timeout: 2000 });
prm.then(function (gpgmejs){
context = gpgmejs;
done();
});
});
it('A fingerprint is consistently returned upper case hex', function (done){
const mixedCase = inputvalues.encrypt.good.fingerprint_mixedcase;
context.Keyring.getKeys({ pattern: mixedCase }).then(function (result){
expect(result).to.be.an('array');
expect(result.length).to.equal(1);
expect(result[0].fingerprint).to.equal(mixedCase.toUpperCase());
done();
});
});
it('A userId keeps their encoding', function (done){
context.Keyring.importKey(inputvalues.publicKeyNonAscii.key, true)
.then(function (result){
expect(result.Keys[0]).to.be.an('object');
const user = result.Keys[0].key.get('userids')[0];
expect(user.get('name')).to.equal(
inputvalues.publicKeyNonAscii.userid);
result.Keys[0].key.delete().then(function (){
done();
});
});
});
});
diff --git a/lang/js/BrowserTestExtension/tests/decryptTest.js b/lang/js/BrowserTestExtension/tests/decryptTest.js
index 61a3fab9..5817eb49 100644
--- a/lang/js/BrowserTestExtension/tests/decryptTest.js
+++ b/lang/js/BrowserTestExtension/tests/decryptTest.js
@@ -1,114 +1,114 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global describe, it, before, expect, Gpgmejs */
/* global bigString, inputvalues, sabotageMsg, binaryData, filename_files */
describe('Decryption', function () {
let context = null;
const good_fpr = inputvalues.encrypt.good.fingerprint;
before(function (done){
- const prm = Gpgmejs.init();
+ const prm = Gpgmejs.init({ timeout:2000 });
prm.then(function (gpgmejs){
context = gpgmejs;
done();
});
});
it('Decryption of random string fails', function (done) {
let data = bigString(20 * 1024);
context.decrypt({ data: data }).then(
function (){},
function (error){
expect(error).to.be.an('error');
expect(error.code).to.equal('GNUPG_ERROR');
done();
});
});
it('Decryption of slightly corrupted message fails', function (done) {
const data = bigString(10000);
context.encrypt({ data: data, publicKeys:good_fpr }).then(
function (enc){
context.decrypt({ data: sabotageMsg(enc.data) }).then(
function (){},
function (error){
expect(error).to.be.an('error');
expect(error.code).to.equal('GNUPG_ERROR');
done();
});
});
}).timeout(5000);
it('decrypt/verify operations return proper information', function (done){
const data = inputvalues.encryptSignedMessage;
context.decrypt({ data: data }).then(function (result){
expect(result).to.be.an('object');
expect(result.signatures).to.be.an('object');
expect(result.signatures.all_valid).to.be.true;
expect(result.signatures.count).to.equal(1);
expect(result.signatures.signatures.good).to.be.an('array');
expect(
result.signatures.signatures.good[0].fingerprint).to.equal(
good_fpr);
done();
});
});
it('decrypt of a png, result as base64', function (done){
const data = binaryData.encryptedArmored;
context.decrypt({ data: data, expect: 'base64' })
.then(function (result){
expect(result.data).to.be.a('String');
expect(result.data).to.equal(binaryData.base64);
expect(result.format).to.equal('base64');
done();
});
});
it('decrypt of a png, result as Uint8Array', function (done){
const data = binaryData.encryptedArmored;
context.decrypt({ data: data, expect: 'uint8' })
.then(function (result){
expect(result.data).to.be.an('Uint8Array');
expect(result.format).to.equal('uint8');
done();
});
});
for (let i=0; i < filename_files.length; i++) {
it (
'decrypted file_names keep correct encoding (' + i + ')',
function (done){
context.decrypt({ data:filename_files[i].data })
.then(function (answer){
expect(answer.file_name).to.equal(
filename_files[i].name);
done();
});
});
}
});
\ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
index c10c5d06..b4e4f3fb 100644
--- a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
+++ b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
@@ -1,200 +1,200 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global describe, it, expect, before, Gpgmejs */
/* global inputvalues, encryptedData, bigString, bigBoringString */
describe('Encryption and Decryption', function (){
let context = null;
let good_fpr = inputvalues.encrypt.good.fingerprint;
before(function (done){
- const prm = Gpgmejs.init();
+ const prm = Gpgmejs.init({ timeout: 2000 });
prm.then(function (gpgmejs){
context = gpgmejs;
done();
});
});
it('Successful encrypt and decrypt simple string', function (done) {
let data = inputvalues.encrypt.good.data;
context.encrypt({ data: data, publicKeys: good_fpr }).then(
function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
context.decrypt({ data: answer.data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(
inputvalues.encrypt.good.data);
done();
});
});
});
it('Decrypt simple non-ascii', function (done) {
let data = encryptedData;
context.decrypt({ data: data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(
'¡Äußerste µ€ før ñoquis@hóme! Добрый день\n');
done();
});
}).timeout(3000);
it('Trailing whitespace and different line endings', function (done) {
const data = 'Keks. \rKeks \n Keks \r\n';
context.encrypt({ data: data, publicKeys: good_fpr }).then(
function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
context.decrypt({ data: answer.data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
}).timeout(5000);
it('Random data, as string', function (done) {
let data = bigString(1000);
context.encrypt({ data:data, publicKeys: good_fpr }).then(
function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({ data: answer.data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
}).timeout(3000);
it('Data, input as base64', function (done) {
let data = inputvalues.encrypt.good.data;
let b64data = btoa(data);
context.encrypt({ data: b64data, publicKeys: good_fpr, base64: true })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({ data: answer.data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
}).timeout(3000);
it('Random data, input as base64', function (done) {
let data = bigBoringString(0.001);
let b64data = btoa(data);
context.encrypt(
{ data: b64data, publicKeys: good_fpr, base64: true })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({ data:answer.data }).then(
function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
}).timeout(3000);
it('Random data, original data is and should stay base64 encoded',
function (done) {
let data = bigBoringString(0.001);
let b64data = btoa(data);
context.encrypt(
{ data: b64data, publicKeys: good_fpr })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({
data:answer.data, expect: 'base64' })
.then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(b64data);
done();
});
});
}).timeout(3000);
for (let j = 0; j < inputvalues.encrypt.good.data_nonascii_32.length; j++){
it('Roundtrip with >1MB non-ascii input meeting default chunksize (' +
(j + 1) + '/'
+ inputvalues.encrypt.good.data_nonascii_32.length + ')',
function (done) {
let input = inputvalues.encrypt.good.data_nonascii_32[j];
expect(input).to.have.length(32);
let data = '';
for (let i=0; i < 34 * 1024; i++){
data += input;
}
context.encrypt({ data: data, publicKeys: good_fpr })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({ data: answer.data })
.then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
}).timeout(5000);
}
});
diff --git a/lang/js/BrowserTestExtension/tests/encryptTest.js b/lang/js/BrowserTestExtension/tests/encryptTest.js
index d97b458d..1017d714 100644
--- a/lang/js/BrowserTestExtension/tests/encryptTest.js
+++ b/lang/js/BrowserTestExtension/tests/encryptTest.js
@@ -1,159 +1,159 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global describe, it, expect, before, Gpgmejs */
/* global inputvalues, fixedLengthString, bigString */
describe('Encryption', function () {
let context = null;
const good_fpr = inputvalues.encrypt.good.fingerprint;
before(function (done){
- const prm = Gpgmejs.init();
+ const prm = Gpgmejs.init({ timeout: 2000 });
prm.then(function (gpgmejs){
context = gpgmejs;
done();
});
});
it('Successful encrypt', function (done) {
const data = inputvalues.encrypt.good.data;
context.encrypt({ data: data, publicKeys: good_fpr })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
done();
});
});
it( 'encrypt with \'armor\': true should returned an armored block',
function (done){
const data = bigString(1000);
context.encrypt({ data: data, publicKeys: good_fpr, armor: true })
.then(function (answer){
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
expect(answer.format).to.equal('ascii');
done();
});
});
it( 'encrypt with \'armor\': false and \'expected\': \'uint8\' returns ' +
'an Uint8Array', function (done) {
const data = bigString(1000);
context.encrypt({
data: data, publicKeys: good_fpr, armor: false, expect: 'uint8'
}).then(function (answer){
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('Uint8Array');
expect(answer.format).to.equal('uint8');
done();
});
});
it( 'encrypt with \'armor\': false and \'expected\': \'base64\' returns ' +
'a base64 string', function (done) {
const data = bigString(1000);
context.encrypt({
data: data, publicKeys: good_fpr, armor: false, expect: 'base64'
}).then(function (answer){
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.format).to.equal('base64');
done();
});
});
const sizes = [5,20,50];
for (let i=0; i < sizes.length; i++) {
it('Successful encrypt a ' + sizes[i] + 'MB message', function (done) {
const data = fixedLengthString(sizes[i]);
context.encrypt({ data: data, publicKeys: good_fpr })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
done();
});
}).timeout(20000);
}
it('Sending encryption without keys fails', function (done) {
const data = inputvalues.encrypt.good.data;
context.encrypt({ data: data }).then(function (answer) {
expect(answer).to.be.undefined;
}, function (error){
expect(error).to.be.an('Error');
expect(error.code).to.equal('MSG_INCOMPLETE');
done();
});
});
it('Sending encryption without data fails', function (done) {
context.encrypt({ data: null, publicKeys: good_fpr })
.then(function (answer) {
expect(answer).to.be.undefined;
}, function (error) {
expect(error).to.be.an.instanceof(Error);
expect(error.code).to.equal('MSG_INCOMPLETE');
done();
});
});
it('Sending encryption with non existing keys fails', function (done) {
const data = inputvalues.encrypt.good.data;
const bad_fpr = inputvalues.encrypt.bad.fingerprint;
context.encrypt({ data:data, publicKeys: bad_fpr })
.then(function (answer) {
expect(answer).to.be.undefined;
}, function (error){
expect(error).to.be.an('Error');
expect(error.code).to.not.be.undefined;
expect(error.code).to.equal('GNUPG_ERROR');
done();
});
}).timeout(5000);
it('Overly large message ( > 64MB) is rejected', function (done) {
const data = fixedLengthString(65);
context.encrypt({ data: data, publicKeys: good_fpr })
.then(function (answer) {
expect(answer).to.be.undefined;
}, function (error){
expect(error).to.be.an.instanceof(Error);
// TODO: there is a 64 MB hard limit at least in chrome at:
// chromium//extensions/renderer/messaging_util.cc:
// kMaxMessageLength
// The error will be a browser error, not from gnupg or from
// this library
done();
});
}).timeout(8000);
});
diff --git a/lang/js/BrowserTestExtension/tests/longRunningTests.js b/lang/js/BrowserTestExtension/tests/longRunningTests.js
index f28a6e78..534a95aa 100644
--- a/lang/js/BrowserTestExtension/tests/longRunningTests.js
+++ b/lang/js/BrowserTestExtension/tests/longRunningTests.js
@@ -1,58 +1,58 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global describe, it, before, expect, Gpgmejs */
/* global bigString, inputvalues */
describe('Long running Encryption/Decryption', function () {
let context = null;
const good_fpr = inputvalues.encrypt.good.fingerprint;
before(function (done){
- const prm = Gpgmejs.init();
+ const prm = Gpgmejs.init({ timeout: 2000 });
prm.then(function (gpgmejs){
context = gpgmejs;
done();
});
});
for (let i=1; i < 101; i++) {
it('Successful encrypt/decrypt completely random data '
+ (i) + '/100', function (done) {
const data = bigString(2*1024*1024);
context.encrypt({ data: data, publicKeys: good_fpr })
.then(function (answer){
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
context.decrypt({ data: answer.data })
.then(function (result){
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
}).timeout(15000);
}
});
diff --git a/lang/js/BrowserTestExtension/tests/signTest.js b/lang/js/BrowserTestExtension/tests/signTest.js
index bd8db807..1e269e6a 100644
--- a/lang/js/BrowserTestExtension/tests/signTest.js
+++ b/lang/js/BrowserTestExtension/tests/signTest.js
@@ -1,64 +1,64 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global describe, it, expect, before, Gpgmejs */
/* global bigString, inputvalues */
describe('Signing', function () {
let context = null;
const good_fpr = inputvalues.encrypt.good.fingerprint;
before(function (done){
- const prm = Gpgmejs.init();
+ const prm = Gpgmejs.init({ timeout: 2000 });
prm.then(function (gpgmejs){
context = gpgmejs;
done();
});
});
it('Sign a message', function (done) {
const data = bigString(100);
context.sign({ data: data, keys: good_fpr }).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP SIGNATURE');
expect(answer.data).to.include('END PGP SIGNATURE');
expect(answer.data).to.include(data);
done();
});
});
it('Detached sign a message', function (done) {
const data = bigString(100);
context.sign({ data: data, keys: good_fpr, mode: 'detached' })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(data);
expect(answer.signature).to.be.a('string');
expect(answer.signature).to.be.a('string');
done();
});
});
});
diff --git a/lang/js/BrowserTestExtension/tests/startup.js b/lang/js/BrowserTestExtension/tests/startup.js
index cf5b0999..e7c74782 100644
--- a/lang/js/BrowserTestExtension/tests/startup.js
+++ b/lang/js/BrowserTestExtension/tests/startup.js
@@ -1,47 +1,47 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global describe, it, expect, Gpgmejs, inputvalues */
describe('GPGME context', function (){
it('Starting a GpgME instance', function (done){
- let prm = Gpgmejs.init();
+ let prm = Gpgmejs.init({ timeout: 2000 });
const input = inputvalues.someInputParameter;
prm.then(
function (context){
expect(context).to.be.an('object');
expect(context.encrypt).to.be.a('function');
expect(context.decrypt).to.be.a('function');
expect(context.sign).to.be.a('function');
expect(context.verify).to.be.a('function');
context.Keyring = input;
expect(context.Keyring).to.be.an('object');
expect(context.Keyring).to.not.equal(input);
expect(context.Keyring.getKeys).to.be.a('function');
expect(context.Keyring.getDefaultKey).to.be.a('function');
expect(context.Keyring.importKey).to.be.a('function');
expect(context.Keyring.generateKey).to.be.a('function');
done();
});
});
});
\ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/tests/verifyTest.js b/lang/js/BrowserTestExtension/tests/verifyTest.js
index 04c7a77a..c63f6849 100644
--- a/lang/js/BrowserTestExtension/tests/verifyTest.js
+++ b/lang/js/BrowserTestExtension/tests/verifyTest.js
@@ -1,90 +1,90 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global describe, it, expect, before, bigString, inputvalues, Gpgmejs */
describe('Verifying data', function () {
let context = null;
before(function (done){
- const prm = Gpgmejs.init();
+ const prm = Gpgmejs.init({ timeout: 2000 });
prm.then(function (gpgmejs){
context = gpgmejs;
done();
});
});
it('Successful verify message', function (done) {
const message = inputvalues.signedMessage.good;
context.verify({ data: message }).then(function (result){
expect(result.data).to.be.a('string');
expect(result.signatures.all_valid).to.be.true;
expect(result.signatures.count).to.equal(1);
expect(result.signatures.signatures.good).to.be.an('array');
expect(result.signatures.signatures.good.length).to.equal(1);
expect(result.signatures.signatures.good[0].fingerprint).to.be.a('string');
expect(result.signatures.signatures.good[0].valid).to.be.true;
done();
});
});
it('Successfully recognize changed cleartext', function (done) {
const message = inputvalues.signedMessage.bad;
context.verify({ data: message }).then(function (result){
expect(result.data).to.be.a('string');
expect(result.signatures.all_valid).to.be.false;
expect(result.signatures.count).to.equal(1);
expect(result.signatures.signatures.bad).to.be.an('array');
expect(result.signatures.signatures.bad.length).to.equal(1);
expect(result.signatures.signatures.bad[0].fingerprint)
.to.be.a('string');
expect(result.signatures.signatures.bad[0].valid)
.to.be.false;
done();
});
});
it('Encrypt-Sign-Verify random message', function (done) {
const message = bigString(2000);
let fpr = inputvalues.encrypt.good.fingerprint;
context.encrypt({ data: message, publicKeys: fpr })
.then(function (message_enc){
context.sign({ data: message_enc.data, keys: fpr })
.then(function (message_encsign){
context.verify({ data: message_encsign.data })
.then(function (result){
expect(result.data).to.equal(message_enc.data);
expect(result.data).to.be.a('string');
expect(result.signatures.all_valid).to.be.true;
expect(result.signatures.count).to.equal(1);
const arr = result.signatures.signatures.good;
expect(arr).to.be.an('array');
expect(arr.length).to.equal(1);
expect(arr[0].fingerprint).to.equal(fpr);
expect(arr[0].valid).to.be.true;
done();
});
});
});
});
});
\ No newline at end of file
diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js
index 4055da6a..d43d55f1 100644
--- a/lang/js/src/Connection.js
+++ b/lang/js/src/Connection.js
@@ -1,316 +1,320 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see .
* SPDX-License-Identifier: LGPL-2.1+
*
* Author(s):
* Maximilian Krambach
*/
/* global chrome */
import { permittedOperations } from './permittedOperations';
import { gpgme_error } from './Errors';
import { GPGME_Message, createMessage } from './Message';
import { decode, atobArray, Utf8ArrayToStr } from './Helpers';
/**
* A Connection handles the nativeMessaging interaction via a port. As the
* protocol only allows up to 1MB of message sent from the nativeApp to the
* browser, the connection will stay open until all parts of a communication
* are finished. For a new request, a new port will open, to avoid mixing
* contexts.
* @class
* @private
*/
export class Connection{
constructor (){
this._connection = chrome.runtime.connectNative('gpgmejson');
}
/**
* Immediately closes an open port.
*/
disconnect () {
if (this._connection){
this._connection.disconnect();
this._connection = null;
}
}
/**
* @typedef {Object} backEndDetails
* @property {String} gpgme Version number of gpgme
* @property {Array