js: implement import/delete Key, some fixes
-- * Keyring.js - implemented importKey: importing one or more armored public key blocks. - implemented deleteKey: deleting a public Key from gpg. * Key.js renamed property Key.armor to Key.armored * Helpers.js: toKeyIDArray does not complain anymore if there are no keys. Not having Keys in e.g. signing keys in encrypt is legitimate and common, the complaints were getting spammy * Errors.js: gpgme_errors now always pass an optional additional message, for easier debugging in minified code * Connection.js: Fix in gpgme-json responses containing objects * eslintrc.json: Start using eslint. A cleanup to conform to it is not done yet * Added further tests for the new functionality
This commit is contained in:
parent
332b4adbcc
commit
0356a667c5
29
lang/js/.eslintrc.json
Normal file
29
lang/js/.eslintrc.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"indent": [
|
||||
"warn",
|
||||
4
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"max-len": 1
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
<script src="tests/encryptTest.js"></script>
|
||||
<script src="tests/encryptDecryptTest.js"></script>
|
||||
<script src="tests/signTest.js"></script>
|
||||
<script src="tests/KeyImportExport.js"></script>
|
||||
<!-- run tests -->
|
||||
<script src="runbrowsertest.js"></script>
|
||||
</body>
|
||||
|
83
lang/js/BrowserTestExtension/tests/KeyImportExport.js
Normal file
83
lang/js/BrowserTestExtension/tests/KeyImportExport.js
Normal file
@ -0,0 +1,83 @@
|
||||
/* 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 <http://www.gnu.org/licenses/>.
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
/* global describe, it, expect, Gpgmejs, ImportablePublicKey */
|
||||
|
||||
describe('Key importing', function () {
|
||||
it('Prepare test Key (deleting it from gnupg, if present)', function(done){
|
||||
let prm = Gpgmejs.init();
|
||||
prm.then(function (context) {
|
||||
expect(context.Keyring.getKeys).to.be.a('function');
|
||||
context.Keyring.getKeys(ImportablePublicKey.fingerprint).then(
|
||||
function(result){
|
||||
if (result.length === 1) {
|
||||
result[0].delete().then(function(result){
|
||||
expect(result).to.be.true;
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('importing, updating, then deleting public Key', function (done) {
|
||||
//This test runs in one large step, to ensure the proper state of the
|
||||
// key in all stages.
|
||||
let prm = Gpgmejs.init();
|
||||
prm.then(function (context) {
|
||||
context.Keyring.getKeys(ImportablePublicKey.fingerprint).then(
|
||||
function(result){
|
||||
expect(result).to.be.an('array');
|
||||
expect(result.length).to.equal(0);
|
||||
context.Keyring.importKey(ImportablePublicKey.key, true)
|
||||
.then(function(result){
|
||||
expect(result[0]).to.not.be.undefined;
|
||||
expect(result[0].key).to.be.an('object');
|
||||
expect(result[0].key.fingerprint).to.equal(
|
||||
ImportablePublicKey.fingerprint);
|
||||
expect(result[0].status).to.equal('newkey');
|
||||
context.Keyring.importKey(
|
||||
ImportablePublicKey.keyChangedUserId,true)
|
||||
.then(function(res){
|
||||
expect(res[0]).to.not.be.undefined;
|
||||
expect(res[0].key).to.be.an('object');
|
||||
expect(res[0].key.fingerprint).to.equal(
|
||||
ImportablePublicKey.fingerprint);
|
||||
expect(res[0].status).to.equal(
|
||||
'change');
|
||||
expect(
|
||||
res[0].changes.userId).to.be.true;
|
||||
expect(
|
||||
res[0].changes.subkey).to.be.false;
|
||||
expect(
|
||||
res[0].changes.signature).to.be.true;
|
||||
res[0].key.delete().then(function(result){
|
||||
expect(result).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -163,7 +163,6 @@ describe('Encryption and Decryption', function () {
|
||||
}).timeout(3000);
|
||||
|
||||
it('Random data, input as base64', function (done) {
|
||||
//TODO fails. The result is
|
||||
let data = bigBoringString(0.001);
|
||||
let b64data = btoa(data);
|
||||
let prm = Gpgmejs.init();
|
||||
@ -177,11 +176,11 @@ describe('Encryption and Decryption', function () {
|
||||
'BEGIN PGP MESSAGE');
|
||||
expect(answer.data).to.include(
|
||||
'END PGP MESSAGE');
|
||||
context.decrypt(answer.data).then(
|
||||
context.decrypt(answer.data, true).then(
|
||||
function (result) {
|
||||
expect(result).to.not.be.empty;
|
||||
expect(result.data).to.be.a('string');
|
||||
expect(result.data).to.equal(data);
|
||||
expect(result.data).to.equal(b64data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -18,11 +18,12 @@
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
var inputvalues = {
|
||||
var inputvalues = {// eslint-disable-line no-unused-vars
|
||||
encrypt: {
|
||||
good:{
|
||||
data : 'Hello World.',
|
||||
// Fingerprint of a key that has been imported to gnupg (i.e. see testkey.pub; testkey.sec)
|
||||
// Fingerprint of a key that has been imported to gnupg
|
||||
// (i.e. see testkey.pub; testkey.sec)
|
||||
fingerprint : 'D41735B91236FDB882048C5A2301635EEFF0CB05',
|
||||
data_nonascii: '¡Äußerste µ€ før ñoquis@hóme! Добрый день',
|
||||
|
||||
@ -45,7 +46,8 @@ var inputvalues = {
|
||||
]
|
||||
},
|
||||
bad: {
|
||||
// valid Hex value, but not usable (not imported to gnupg, or bogus fingerprint)
|
||||
// valid Hex value, but not usable (not imported to gnupg, or
|
||||
// bogus fingerprint)
|
||||
fingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A'
|
||||
}
|
||||
},
|
||||
@ -54,14 +56,13 @@ var inputvalues = {
|
||||
invalid_startups: [
|
||||
{all_passwords: true},
|
||||
'openpgpmode',
|
||||
{api_style:"frankenstein"}
|
||||
{api_style:'frankenstein'}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
// (Pseudo-)Random String covering all of utf8.
|
||||
function bigString(length){
|
||||
var uint = '';
|
||||
function bigString(length){// eslint-disable-line no-unused-vars
|
||||
let arr = [];
|
||||
for (let i= 0; i < length; i++){
|
||||
arr.push(String.fromCharCode(
|
||||
@ -71,7 +72,7 @@ function bigString(length){
|
||||
return arr.join('');
|
||||
}
|
||||
|
||||
function fixedLengthString(megabytes){
|
||||
function fixedLengthString(megabytes){// eslint-disable-line no-unused-vars
|
||||
let maxlength = 1024 * 1024 * megabytes / 2;
|
||||
let uint = new Uint8Array(maxlength);
|
||||
for (let i = 0; i < maxlength; i++){
|
||||
@ -83,7 +84,7 @@ function fixedLengthString(megabytes){
|
||||
}
|
||||
|
||||
// (Pseudo-)Random Uint8Array, given size in Megabytes
|
||||
function bigUint8(megabytes){
|
||||
function bigUint8(megabytes){// eslint-disable-line no-unused-vars
|
||||
let maxlength = 1024 * 1024 * megabytes;
|
||||
let uint = new Uint8Array(maxlength);
|
||||
for (let i= 0; i < maxlength; i++){
|
||||
@ -92,11 +93,13 @@ function bigUint8(megabytes){
|
||||
return uint;
|
||||
}
|
||||
|
||||
// (Pseudo-)Random string with very limited charset (ascii only, no control chars)
|
||||
function bigBoringString(megabytes){
|
||||
// (Pseudo-)Random string with very limited charset
|
||||
// (ascii only, no control chars)
|
||||
function bigBoringString(megabytes){// eslint-disable-line no-unused-vars
|
||||
let maxlength = 1024 * 1024 * megabytes;
|
||||
let string = [];
|
||||
let chars = ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let chars =
|
||||
' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
for (let i= 0; i < maxlength; i++){
|
||||
string.push(chars[Math.floor(Math.random() * chars.length)]);
|
||||
}
|
||||
@ -105,12 +108,13 @@ function bigBoringString(megabytes){
|
||||
|
||||
// Some String with simple chars, with different characteristics, but still
|
||||
// expected to occur in an averag message
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function slightlyLessBoringString(megabytes, set){
|
||||
let maxlength = 1024 * 1024 * megabytes;
|
||||
let string = [];
|
||||
let chars = '';
|
||||
if (set ===1 ) {
|
||||
chars = '\n\"\r \'';
|
||||
chars = '\n"\r \'';
|
||||
} else if (set === 2 ) {
|
||||
chars = '()=?`#+-{}[]';
|
||||
} else if (set === 3){
|
||||
@ -118,7 +122,7 @@ function slightlyLessBoringString(megabytes, set){
|
||||
} else if (set ===4) {
|
||||
chars = 'äüßµüþÖ~ɁÑ||@';
|
||||
} else {
|
||||
chars = '*<>\n\"\r§$%&/()=?`#+-{}[] \'';
|
||||
chars = '*<>\n"\r§$%&/()=?`#+-{}[] \'';
|
||||
}
|
||||
for (let i= 0; i < maxlength; i++){
|
||||
string.push(chars[Math.floor(Math.random() * chars.length)]);
|
||||
@ -127,7 +131,7 @@ function slightlyLessBoringString(megabytes, set){
|
||||
}
|
||||
|
||||
// Data encrypted with testKey
|
||||
var encryptedData =
|
||||
var encryptedData =// eslint-disable-line no-unused-vars
|
||||
'-----BEGIN PGP MESSAGE-----\n' +
|
||||
'\n' +
|
||||
'hQEMA6B8jfIUScGEAQgAlANd3uyhmhYLzVcfz4LEqA8tgUC3n719YH0iuKEzG/dv\n' +
|
||||
@ -141,3 +145,76 @@ var encryptedData =
|
||||
'kSAQYOHplfA7YJWkrlRm\n' +
|
||||
'=zap6\n' +
|
||||
'-----END PGP MESSAGE-----\n';
|
||||
|
||||
var ImportablePublicKey = {// eslint-disable-line no-unused-vars
|
||||
fingerprint: '78034948BA7F5D0E9BDB67E4F63790C11E60278A',
|
||||
key:'-----BEGIN PGP PUBLIC KEY BLOCK-----\n' +
|
||||
'\n' +
|
||||
'mQENBFsPvK0BCACaIgoIN+3g05mrTITULK/YDTrfg4W7RdzIZBxch5CM0zdu/dby\n' +
|
||||
'esFwaJbVQIqu54CRz5xKAiWmRrQCaRvhvjY0na5r5UUIpbeQiOVrl65JtNbRmlik\n' +
|
||||
'd9Prn1kZDUOZiCPIKn+/M2ecJ92YedM7I4/BbpiaFB11cVrPFg4thepn0LB3+Whp\n' +
|
||||
'9HDm4orH9rjy6IUr6yjWNIr+LYRY6/Ip2vWcMVjleEpTFznXrm83hrJ0n0INtyox\n' +
|
||||
'Nass4eDWkgo6ItxDFFLOORSmpfrToxZymSosWqgux/qG6sxHvLqlqy6Xe3ZYRFbG\n' +
|
||||
'+JcA1oGdwOg/c0ndr6BYYiXTh8+uUJfEoZvzABEBAAG0HEJsYSBCbGEgPGJsYWJs\n' +
|
||||
'YUBleGFtcGxlLm9yZz6JAVQEEwEIAD4WIQR4A0lIun9dDpvbZ+T2N5DBHmAnigUC\n' +
|
||||
'Ww+8rQIbAwUJA8JnAAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRD2N5DBHmAn\n' +
|
||||
'igwIB/9K3E3Yev9taZP4KnXPhk1oMQRW1MWAsFGUr+70N85VwedpUawymW4vXi1+\n' +
|
||||
'hMeTc39QjmZ0+VqHkJttkqEN6bLcEvgmU/mOlOgKdzy6eUcasYAzgoAKUqSX1SPs\n' +
|
||||
'0Imo7Tj04wnfnVwvKxaeadi0VmdqIYaW75UlrzIaltsBctyeYH8sBrvaTLscb4ON\n' +
|
||||
'46OM3Yw2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tF4TgDlfSsdxHxVOmnZkY3\n' +
|
||||
'=qP6s\n' +
|
||||
'-----END PGP PUBLIC KEY BLOCK-----\n',
|
||||
|
||||
keyChangedUserId: '-----BEGIN PGP PUBLIC KEY BLOCK-----\n' +
|
||||
'\n' +
|
||||
'mQENBFsPvK0BCACaIgoIN+3g05mrTITULK/YDTrfg4W7RdzIZBxch5CM0zdu/dby\n' +
|
||||
'esFwaJbVQIqu54CRz5xKAiWmRrQCaRvhvjY0na5r5UUIpbeQiOVrl65JtNbRmlik\n' +
|
||||
'd9Prn1kZDUOZiCPIKn+/M2ecJ92YedM7I4/BbpiaFB11cVrPFg4thepn0LB3+Whp\n' +
|
||||
'9HDm4orH9rjy6IUr6yjWNIr+LYRY6/Ip2vWcMVjleEpTFznXrm83hrJ0n0INtyox\n' +
|
||||
'Nass4eDWkgo6ItxDFFLOORSmpfrToxZymSosWqgux/qG6sxHvLqlqy6Xe3ZYRFbG\n' +
|
||||
'+JcA1oGdwOg/c0ndr6BYYiXTh8+uUJfEoZvzABEBAAG0HEJsYSBCbGEgPGJsYWJs\n' +
|
||||
'YUBleGFtcGxlLm9yZz6JAVQEEwEIAD4WIQR4A0lIun9dDpvbZ+T2N5DBHmAnigUC\n' +
|
||||
'Ww+8rQIbAwUJA8JnAAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRD2N5DBHmAn\n' +
|
||||
'igwIB/9K3E3Yev9taZP4KnXPhk1oMQRW1MWAsFGUr+70N85VwedpUawymW4vXi1+\n' +
|
||||
'hMeTc39QjmZ0+VqHkJttkqEN6bLcEvgmU/mOlOgKdzy6eUcasYAzgoAKUqSX1SPs\n' +
|
||||
'0Imo7Tj04wnfnVwvKxaeadi0VmdqIYaW75UlrzIaltsBctyeYH8sBrvaTLscb4ON\n' +
|
||||
'46OM3Yw2G9+dBF0P+4UYFHP3EYZMlzNxfwF+i2HsYcNDHlcLfjENr9GwKn5FJqpY\n' +
|
||||
'Iq3qmI37w1hVasHDxXdz1X06dp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of1o7nCBeksB0m+60I4vkA\n' +
|
||||
'EQEAAYkBPAQYAQgAJhYhBHgDSUi6f10Om9tn5PY3kMEeYCeKBQJbD7ytAhsMBQkD\n' +
|
||||
'wmcAAAoJEPY3kMEeYCeKAxUH/jzgbb7dHRwBqPdX/PiBbcxFIyFxioQzIn8AJ2jv\n' +
|
||||
'Lx6it5hbzjclZZUNFjr9hxhga4EE/jtY7gm4/bAiVWfXtc4JKCc2OaaOwhiIDOSi\n' +
|
||||
'nvvZMHbujRV6IVfmJZxrDLQQjskJvbfGkj5A/fWSwvbLJFgVcK1dJR9w6sukJjxo\n' +
|
||||
'RAxBsAa2RqDXAdOj9N/9WKnyrRkRDjE4pNHb+WXr6Kc/yTMbLNp0SVScfVDU5Rd3\n' +
|
||||
'YuP/sGkEcTb76ECMFBGCfJo40XualQ0S7DriIE2zQJ7oqLhFXb4QEucW5ucU1HF8\n' +
|
||||
'UlxhdyKOG5/dgJ1bOpiY+lT8K0XhOAOV9Kx3EfFU6admRjc=\n' +
|
||||
'=9WZ7\n' +
|
||||
'-----END PGP PUBLIC KEY BLOCK-----\n'
|
||||
};
|
||||
|
@ -103,7 +103,7 @@ export class Connection{
|
||||
}
|
||||
if (!message || !message instanceof GPGME_Message){
|
||||
this.disconnect();
|
||||
return Promise.reject(gpgme_error('PARAM_WRONG'), message);
|
||||
return Promise.reject(gpgme_error('PARAM_WRONG', 'Connection.post'));
|
||||
}
|
||||
if (message.isComplete !== true){
|
||||
this.disconnect();
|
||||
@ -221,12 +221,13 @@ class Answer{
|
||||
if (!this._response.hasOwnProperty(key)){
|
||||
this._response[key] = [];
|
||||
}
|
||||
|
||||
if (Array.isArray(msg[key])) {
|
||||
for (let i=0; i< msg[key].length; i++) {
|
||||
this._response[key].push(msg[key][i]);
|
||||
}
|
||||
} else {
|
||||
this._response[key].push(msg[key][i]);
|
||||
this._response[key].push(msg[key]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -74,7 +74,7 @@ const err_list = {
|
||||
'KEY_NO_INIT': {
|
||||
msg:'This property has not been retrieved yet from GPG',
|
||||
type: 'error'
|
||||
}
|
||||
},
|
||||
// generic
|
||||
'PARAM_WRONG':{
|
||||
msg: 'Invalid parameter was found',
|
||||
@ -118,7 +118,11 @@ class GPGME_Error extends Error{
|
||||
if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){
|
||||
super(msg);
|
||||
} else if (err_list.hasOwnProperty(code)){
|
||||
if (msg){
|
||||
super(err_list[code].msg + "--" + msg);
|
||||
} else {
|
||||
super(err_list[code].msg);
|
||||
}
|
||||
} else {
|
||||
super(err_list['GENERIC_ERROR'].msg);
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import { GPGME_Key } from "./Key";
|
||||
|
||||
export function toKeyIdArray(input){
|
||||
if (!input){
|
||||
gpgme_error('MSG_NO_KEYS');
|
||||
return [];
|
||||
}
|
||||
if (!Array.isArray(input)){
|
||||
@ -61,7 +60,6 @@ export function toKeyIdArray(input){
|
||||
}
|
||||
}
|
||||
if (result.length === 0){
|
||||
gpgme_error('MSG_NO_KEYS');
|
||||
return [];
|
||||
} else {
|
||||
return result;
|
||||
|
@ -207,7 +207,7 @@ export class GPGME_Key {
|
||||
msg.setParameter('armor', true);
|
||||
msg.setParameter('keys', me._data.fingerprint);
|
||||
msg.post().then(function(result){
|
||||
me._data.armor = result.data;
|
||||
me._data.armored = result.data;
|
||||
resolve(result.data);
|
||||
}, function(error){
|
||||
reject(error);
|
||||
@ -280,7 +280,7 @@ export class GPGME_Key {
|
||||
/**
|
||||
* Deletes the public Key from the GPG Keyring. Note that a deletion of a
|
||||
* secret key is not supported by the native backend.
|
||||
* @returns {Boolean} Success if key was deleted, rejects with a GPG error
|
||||
* @returns {Promise<Boolean>} Success if key was deleted, rejects with a GPG error
|
||||
* otherwise
|
||||
*/
|
||||
delete(){
|
||||
|
@ -18,9 +18,9 @@
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
import {createMessage} from './Message'
|
||||
import {GPGME_Key, createKey} from './Key'
|
||||
import { isFingerprint, toKeyIdArray } from './Helpers';
|
||||
import {createMessage} from './Message';
|
||||
import {createKey} from './Key';
|
||||
import { isFingerprint } from './Helpers';
|
||||
import { gpgme_error } from './Errors';
|
||||
|
||||
export class GPGME_Keyring {
|
||||
@ -39,10 +39,8 @@ export class GPGME_Keyring {
|
||||
*
|
||||
*/
|
||||
getKeys(pattern, prepare_sync){
|
||||
let me = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
let msg;
|
||||
msg = createMessage('keylist');
|
||||
let msg = createMessage('keylist');
|
||||
if (pattern !== undefined){
|
||||
msg.setParameter('keys', pattern);
|
||||
}
|
||||
@ -50,9 +48,11 @@ export class GPGME_Keyring {
|
||||
msg.post().then(function(result){
|
||||
let resultset = [];
|
||||
let promises = [];
|
||||
// TODO check if result.key is not empty
|
||||
if (result.keys.length === 0){
|
||||
resolve([]);
|
||||
} else {
|
||||
for (let i=0; i< result.keys.length; i++){
|
||||
let k = createKey(result.keys[i].fingerprint, me);
|
||||
let k = createKey(result.keys[i].fingerprint);
|
||||
k.setKeyData(result.keys[i]);
|
||||
if (prepare_sync === true){
|
||||
promises.push(k.getArmor());
|
||||
@ -61,14 +61,15 @@ export class GPGME_Keyring {
|
||||
resultset.push(k);
|
||||
}
|
||||
if (promises.length > 0) {
|
||||
Promise.all(promises).then(function (res){
|
||||
Promise.all(promises).then(function() {
|
||||
resolve(resultset);
|
||||
}, function(error){
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
resolve(resultset);
|
||||
}
|
||||
}
|
||||
}, function(error){
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -80,7 +81,6 @@ export class GPGME_Keyring {
|
||||
* @returns {Promise<String>} Armored Key blocks
|
||||
*/
|
||||
getKeysArmored(pattern) {
|
||||
if (pattern)
|
||||
return new Promise(function(resolve, reject) {
|
||||
let msg = createMessage('export');
|
||||
msg.setParameter('armor', true);
|
||||
@ -92,10 +92,102 @@ export class GPGME_Keyring {
|
||||
}, function(error){
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// getDefaultKey() Big TODO
|
||||
// importKeys(armoredKeys)
|
||||
// generateKey --> TODO (Andre noch anfragen!)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} armored Armored Key block of the Kex(s) to be imported into gnupg
|
||||
* @param {Boolean} prepare_sync prepare the keys for synched use (see getKeys()).
|
||||
* @returns {Promise<Array<Object>>} An array of objects for the Keys considered.
|
||||
* Key.key The key itself as a GPGME_Key
|
||||
* Key.status String:
|
||||
* 'nochange' if the Key was not changed,
|
||||
* 'newkey' if the Key was imported in gpg, and did not exist previously,
|
||||
* 'change' if the key existed, but details were updated. For details,
|
||||
* Key.changes is available.
|
||||
* Key.changes.userId: Boolean userIds changed
|
||||
* Key.changes.signature: Boolean signatures changed
|
||||
* Key.changes.subkey: Boolean subkeys changed
|
||||
* // TODO: not yet implemented: Information about Keys that failed
|
||||
* (e.g. malformed Keys, secretKeys are not accepted)
|
||||
*/
|
||||
importKey(armored, prepare_sync) {
|
||||
if (!armored || typeof(armored) !== 'string'){
|
||||
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
||||
}
|
||||
let me = this;
|
||||
return new Promise(function(resolve, reject){
|
||||
let msg = createMessage('import');
|
||||
msg.setParameter('data', armored);
|
||||
msg.post().then(function(response){
|
||||
let infos = {};
|
||||
let fprs = [];
|
||||
for (var res=0; res < response.result[0].imports.length; res++) {
|
||||
let result = response.result[0].imports[res];
|
||||
let status = '';
|
||||
if (result.status === 0){
|
||||
status = 'nochange';
|
||||
} else if ((result.status & 1) === 1){
|
||||
status = 'newkey';
|
||||
} else {
|
||||
status = 'change';
|
||||
}
|
||||
let changes = {};
|
||||
changes.userId = (result.status & 2) === 2;
|
||||
changes.signature = (result.status & 4) === 4;
|
||||
changes.subkey = (result.status & 8) === 8;
|
||||
//16 new secret key: not implemented
|
||||
|
||||
fprs.push(result.fingerprint);
|
||||
infos[result.fingerprint] = {
|
||||
changes: changes,
|
||||
status: status
|
||||
};
|
||||
}
|
||||
let resultset = [];
|
||||
if (prepare_sync === true){
|
||||
me.getKeys(fprs, true).then(function(result){
|
||||
for (let i=0; i < result.length; i++) {
|
||||
resultset.push({
|
||||
key: result[i],
|
||||
changes: infos[result[i].fingerprint].changes,
|
||||
status: infos[result[i].fingerprint].status
|
||||
});
|
||||
}
|
||||
resolve(resultset);
|
||||
}, function(error){
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
for (let i=0; i < fprs.length; i++) {
|
||||
resultset.push({
|
||||
key: createKey(fprs[i]),
|
||||
changes: infos[fprs[i]].changes,
|
||||
status: infos[fprs[i]].status
|
||||
});
|
||||
}
|
||||
resolve(resultset);
|
||||
}
|
||||
|
||||
}, function(error){
|
||||
reject(error);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
deleteKey(fingerprint){
|
||||
if (isFingerprint(fingerprint) === true) {
|
||||
let key = createKey(fingerprint);
|
||||
key.delete();
|
||||
}
|
||||
}
|
||||
|
||||
// generateKey
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {Connection} from "./src/Connection";
|
||||
import {createKey} from "./src/Key";
|
||||
import {Connection} from './src/Connection';
|
||||
import {createKey} from './src/Key';
|
||||
|
||||
let conn = new Connection;
|
||||
|
||||
@ -25,12 +25,12 @@ export const helper_params = {
|
||||
return '85DE2A8BA5A5AB3A8A7BE2000B8AED24D7534BC2';}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const message_params = {
|
||||
invalid_op_action : 'dance',
|
||||
invalid_op_type : [234, 34, '<>'],
|
||||
valid_encrypt_data: "مرحبا بالعالم",
|
||||
valid_encrypt_data: 'مرحبا بالعالم',
|
||||
invalid_param_test: {
|
||||
valid_op: 'encrypt',
|
||||
invalid_param_names: [22,'dance', {}],
|
||||
@ -38,11 +38,11 @@ export const message_params = {
|
||||
invalid_values_0: [2134, 'All your passwords',
|
||||
createKey('12AE9F3E41B33BF77DF52B6BE8EE1992D7909B08', conn), null]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const whatever_params = {
|
||||
four_invalid_params: ['<(((-<', '>°;==;~~', '^^', '{{{{o}}}}'],
|
||||
}
|
||||
};
|
||||
export const key_params = {
|
||||
// A Key you own (= having a secret Key) in GPG. See testkey.pub/testkey.sec
|
||||
validKeyFingerprint: 'D41735B91236FDB882048C5A2301635EEFF0CB05',
|
||||
@ -52,4 +52,75 @@ export const key_params = {
|
||||
invalidKeyFingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A',
|
||||
validKeyProperties: ['expired', 'disabled','invalid','can_encrypt',
|
||||
'can_sign','can_certify','can_authenticate','secret','is_qualified']
|
||||
}
|
||||
};
|
||||
export const armoredKey = {
|
||||
fingerprint: '78034948BA7F5D0E9BDB67E4F63790C11E60278A',
|
||||
key:'-----BEGIN PGP PUBLIC KEY BLOCK-----\n' +
|
||||
'\n' +
|
||||
'mQENBFsPvK0BCACaIgoIN+3g05mrTITULK/YDTrfg4W7RdzIZBxch5CM0zdu/dby\n' +
|
||||
'esFwaJbVQIqu54CRz5xKAiWmRrQCaRvhvjY0na5r5UUIpbeQiOVrl65JtNbRmlik\n' +
|
||||
'd9Prn1kZDUOZiCPIKn+/M2ecJ92YedM7I4/BbpiaFB11cVrPFg4thepn0LB3+Whp\n' +
|
||||
'9HDm4orH9rjy6IUr6yjWNIr+LYRY6/Ip2vWcMVjleEpTFznXrm83hrJ0n0INtyox\n' +
|
||||
'Nass4eDWkgo6ItxDFFLOORSmpfrToxZymSosWqgux/qG6sxHvLqlqy6Xe3ZYRFbG\n' +
|
||||
'+JcA1oGdwOg/c0ndr6BYYiXTh8+uUJfEoZvzABEBAAG0HEJsYSBCbGEgPGJsYWJs\n' +
|
||||
'YUBleGFtcGxlLm9yZz6JAVQEEwEIAD4WIQR4A0lIun9dDpvbZ+T2N5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'7y8eoreYW843JWWVDRY6/YcYYGuBBP47WO4JuP2wIlVn17XOCSgnNjmmjsIYiAzk\n' +
|
||||
'op772TB27o0VeiFX5iWcawy0EI7JCb23xpI+QP31ksL2yyRYFXCtXSUfcOrLpCY8\n' +
|
||||
'aEQMQbAGtkag1wHTo/Tf/Vip8q0ZEQ4xOKTR2/ll6+inP8kzGyzadElUnH1Q1OUX\n' +
|
||||
'd2Lj/7BpBHE2++hAjBQRgnyaONF7mpUNEuw64iBNs0Ce6Ki4RV2+EBLnFubnFNRx\n' +
|
||||
'fFJcYXcijhuf3YCdWzqYmPpU/CtF4TgDlfSsdxHxVOmnZkY3\n' +
|
||||
'=qP6s\n' +
|
||||
'-----END PGP PUBLIC KEY BLOCK-----\n',
|
||||
keyChangedUserId: '-----BEGIN PGP PUBLIC KEY BLOCK-----\n' +
|
||||
'\n' +
|
||||
'mQENBFsPvK0BCACaIgoIN+3g05mrTITULK/YDTrfg4W7RdzIZBxch5CM0zdu/dby\n' +
|
||||
'esFwaJbVQIqu54CRz5xKAiWmRrQCaRvhvjY0na5r5UUIpbeQiOVrl65JtNbRmlik\n' +
|
||||
'd9Prn1kZDUOZiCPIKn+/M2ecJ92YedM7I4/BbpiaFB11cVrPFg4thepn0LB3+Whp\n' +
|
||||
'9HDm4orH9rjy6IUr6yjWNIr+LYRY6/Ip2vWcMVjleEpTFznXrm83hrJ0n0INtyox\n' +
|
||||
'Nass4eDWkgo6ItxDFFLOORSmpfrToxZymSosWqgux/qG6sxHvLqlqy6Xe3ZYRFbG\n' +
|
||||
'+JcA1oGdwOg/c0ndr6BYYiXTh8+uUJfEoZvzABEBAAG0HEJsYSBCbGEgPGJsYWJs\n' +
|
||||
'YUBleGFtcGxlLm9yZz6JAVQEEwEIAD4WIQR4A0lIun9dDpvbZ+T2N5DBHmAnigUC\n' +
|
||||
'Ww+8rQIbAwUJA8JnAAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRD2N5DBHmAn\n' +
|
||||
'ig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AC4Ye6AMu/r+OWLPPPmO2PdIAdW0kHyUlbwjRw1IQhfxt\n' +
|
||||
'FgfgLuU/YNNv0KAxwYStAjIrjzT4cixuxmElI0d2NRSXog8QRV9JDNZq5+a6zB57\n' +
|
||||
'6CKoeJOxqJbbTK1eKXBUamOUcFrGf9umyRnRhFqyCc+oqAkPd3mS6c2pajIKkxwV\n' +
|
||||
'iAMRG89uGFx4Vu8UT0b+7eBty5XXmbHnd0NfQia89y8mcM7IlL3KvsCl05XfXakD\n' +
|
||||
'UwtvF8+dudW750ZefsP9UIN3loFhU+b7kA2uTrP2Vgof1o7nCBeksB0m+60I4vkA\n' +
|
||||
'EQEAAYkBPAQYAQgAJhYhBHgDSUi6f10Om9tn5PY3kMEeYCeKBQJbD7ytAhsMBQkD\n' +
|
||||
'wmcAAAoJEPY3kMEeYCeKAxUH/jzgbb7dHRwBqPdX/PiBbcxFIyFxioQzIn8AJ2jv\n' +
|
||||
'Lx6it5hbzjclZZUNFjr9hxhga4EE/jtY7gm4/bAiVWfXtc4JKCc2OaaOwhiIDOSi\n' +
|
||||
'nvvZMHbujRV6IVfmJZxrDLQQjskJvbfGkj5A/fWSwvbLJFgVcK1dJR9w6sukJjxo\n' +
|
||||
'RAxBsAa2RqDXAdOj9N/9WKnyrRkRDjE4pNHb+WXr6Kc/yTMbLNp0SVScfVDU5Rd3\n' +
|
||||
'YuP/sGkEcTb76ECMFBGCfJo40XualQ0S7DriIE2zQJ7oqLhFXb4QEucW5ucU1HF8\n' +
|
||||
'UlxhdyKOG5/dgJ1bOpiY+lT8K0XhOAOV9Kx3EfFU6admRjc=\n' +
|
||||
'=9WZ7\n' +
|
||||
'-----END PGP PUBLIC KEY BLOCK-----\n'
|
||||
};
|
@ -17,19 +17,19 @@
|
||||
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
import "./node_modules/mocha/mocha";
|
||||
import "./node_modules/chai/chai";
|
||||
import { helper_params as hp } from "./unittest_inputvalues";
|
||||
import { message_params as mp } from "./unittest_inputvalues";
|
||||
import { whatever_params as wp } from "./unittest_inputvalues";
|
||||
import { key_params as kp } from "./unittest_inputvalues";
|
||||
import { Connection } from "./src/Connection";
|
||||
import { gpgme_error } from "./src/Errors";
|
||||
import { toKeyIdArray , isFingerprint } from "./src/Helpers";
|
||||
import { GPGME_Key , createKey } from "./src/Key";
|
||||
import { GPGME_Keyring } from "./src/Keyring";
|
||||
import {GPGME_Message, createMessage} from "./src/Message";
|
||||
import { setTimeout } from "timers";
|
||||
|
||||
import './node_modules/mocha/mocha'; /*global mocha, it, describe*/
|
||||
import './node_modules/chai/chai';/*global chai*/
|
||||
import { helper_params as hp } from './unittest_inputvalues';
|
||||
import { message_params as mp } from './unittest_inputvalues';
|
||||
import { whatever_params as wp } from './unittest_inputvalues';
|
||||
import { key_params as kp } from './unittest_inputvalues';
|
||||
import { Connection } from './src/Connection';
|
||||
import { gpgme_error } from './src/Errors';
|
||||
import { toKeyIdArray , isFingerprint } from './src/Helpers';
|
||||
import { GPGME_Key , createKey } from './src/Key';
|
||||
import { GPGME_Keyring } from './src/Keyring';
|
||||
import {GPGME_Message, createMessage} from './src/Message';
|
||||
|
||||
mocha.setup('bdd');
|
||||
var expect = chai.expect;
|
||||
@ -74,12 +74,14 @@ function unittests (){
|
||||
expect(test0.code).to.equal('CONN_TIMEOUT');
|
||||
});
|
||||
|
||||
it('Error Object returns generic code if code is not listed', function(){
|
||||
it('Error Object returns generic code if code is not listed',
|
||||
function(){
|
||||
let test0 = gpgme_error(hp.invalidErrorCode);
|
||||
|
||||
expect(test0).to.be.an.instanceof(Error);
|
||||
expect(test0.code).to.equal('GENERIC_ERROR');
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
it('Warnings like PARAM_IGNORED should not return errors', function(){
|
||||
let test0 = gpgme_error('PARAM_IGNORED');
|
||||
@ -201,7 +203,7 @@ function unittests (){
|
||||
|
||||
it('Non-cached key async armored Key', function (done){
|
||||
let key = createKey(kp.validKeyFingerprint);
|
||||
key.get('armor', false).then(function(result){
|
||||
key.get('armored', false).then(function(result){
|
||||
expect(result).to.be.a('string');
|
||||
expect(result).to.include('KEY BLOCK-----');
|
||||
done();
|
||||
@ -269,13 +271,73 @@ function unittests (){
|
||||
keyring.getKeys(null, true).then(function(result){
|
||||
expect(result).to.be.an('array');
|
||||
expect(result[0]).to.be.an.instanceof(GPGME_Key);
|
||||
expect(result[0].get('armor')).to.be.a('string');
|
||||
expect(result[0].get('armor')).to.include(
|
||||
expect(result[0].get('armored')).to.be.a('string');
|
||||
expect(result[0].get('armored')).to.include(
|
||||
'-----END PGP PUBLIC KEY BLOCK-----');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Loading specific Key from Keyring, to be used synchronously', function(done){
|
||||
let keyring = new GPGME_Keyring;
|
||||
keyring.getKeys(kp.validKeyFingerprint, true).then(function(result){
|
||||
expect(result).to.be.an('array');
|
||||
expect(result[0]).to.be.an.instanceof(GPGME_Key);
|
||||
expect(result[0].get('armored')).to.be.a('string');
|
||||
expect(result[0].get('armored')).to.include(
|
||||
'-----END PGP PUBLIC KEY BLOCK-----');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Querying non-existing Key from Keyring', function(done){
|
||||
let keyring = new GPGME_Keyring;
|
||||
keyring.getKeys(kp.invalidKeyFingerprint, true).then(function(result){
|
||||
expect(result).to.be.an('array');
|
||||
expect(result.length).to.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// describe('Keyring import/export', function(){
|
||||
// before(function(done) {
|
||||
// let keyring = new GPGME_Keyring;
|
||||
|
||||
// keyring.getKeys(ak.fingerprint, false).then(function(result){
|
||||
// if (result.length === 1){
|
||||
// result[0].delete().then(function(delete_result){
|
||||
// if (delete_result === true){
|
||||
// done();
|
||||
// }
|
||||
// });
|
||||
// } else {
|
||||
// done();
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// it('Import Public Key', function(done){
|
||||
// keyring.importKey(ak.key).then(function(result){
|
||||
// expect(result).to.be.an('array');
|
||||
// expect(result[0].key).to.be.an.instanceof(GPGME_Key);
|
||||
// expect(result[0].changed).to.equal('newkey');
|
||||
// expect(result[0].key.keyring).to.equal(ak.fingerprint);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('Update Public Key', function(done){
|
||||
// keyring.importKey(ak.key).then(function(result){
|
||||
// expect(result).to.be.an('array');
|
||||
// expect(result[0].key).to.be.an.instanceof(GPGME_Key);
|
||||
// expect(result[0].changed).to.equal('change');
|
||||
// expect(result[0].changes.userId).to.be.true;
|
||||
// expect(result[0].changes.subkeys).to.be.false;
|
||||
// expect(result[0].key.keyring).to.equal(ak.fingerprint);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('GPGME_Message', function(){
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user