From d62f66b1fb47f2075770d896f672748a4136e70b Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 23 Apr 2018 17:18:46 +0200 Subject: js: Key handling stubs, Error handling, refactoring -- * Error handling: introduced GPGMEJS_Error class that handles errors at a more centralized and consistent position * src/Connection.js: The nativeMessaging port now opens per session instead of per message. Some methods were added that reflect this change - added methods disconnect() and reconnect() - added connection status query * src/gpgmejs.js - stub for key deletion - error handling - high level API for changing connection status * src/gpgmejs_openpgpjs.js - added stubs for Key/Keyring handling according to current state of discussion. It is still subject to change * src/Helpers.js - toKeyIdArray creates an array of KeyIds, now accepting fingerprints, GPGMEJS_Key objects and openpgp Key objects. * Key objects (src/Key.js) Querying information about a key directly from gnupg. Currently a stub, only the Key.fingerprint is functional. * Keyring queries (src/Keyring.js): Listing and searching keys. Currently a stub. --- lang/js/src/Errors.js | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 lang/js/src/Errors.js (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js new file mode 100644 index 00000000..c2356f7c --- /dev/null +++ b/lang/js/src/Errors.js @@ -0,0 +1,148 @@ +/* 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+ + */ + +// This is a preliminary collection of erors and warnings to be thrown and implemented. + +// general idea: if throw , throw the NAME +// return false || 'return' property + +//TODO: Connection.NOCONNECT promise +//connection.timeout: Be aware of pinentry + +export class GPGMEJS_Error { + + constructor(code = 'GENERIC_ERROR', details){ + let config = { //TODO TEMP + debug: 'console', // |'alert' + throw: 'default' // | 'always' | 'never' + }; + let errors = { //TODO: someplace else + //Connection errors + 'ALREADY_CONNECTED':{ + msg: 'The connection was already established. The action would overwrite the context', + throw: true + }, + 'NO_CONNECT': { + msg:'Connection with the nativeMessaging host could not be established.', + throw: true + }, + 'EMPTY_GPG_ANSWER':{ + msg: 'The nativeMesaging answer was empty', + throw: true + }, + 'TIMEOUT': { + msg: 'A timeout was exceeded.', + throw: false + }, + + 'UNEXPECTED_ANSWER': { + msg: 'The answer from gnupg was not as expected', + throw: true + }, + + // Message/Data Errors + + 'NO_KEYS' : { + msg: 'There were no valid keys provided.', + throw: true + }, + 'NOT_A_FPR': { + msg: 'The String is not an accepted fingerprint', + throw: false + }, + 'MSG_INCOMPLETE': { + msg: 'The Message did not match the minimum requirements for the interaction', + throw: true + }, + 'EMPTY_MSG' : { + msg: 'The Message has no data.', + throw: true + }, + 'MSG_NODATA':{ + msg: 'The data sent is empty. This may be unintentional.', + throw: false + }, + 'MSG_OP_PENDING': { + msg: 'There is no operation specified yet. The parameter cannot be set', + throw: false + }, + 'WRONG_OP': { + msg: "The operation requested could not be found", + throw: true + }, + + //generic errors + + 'WRONGPARAM':{ + msg: 'invalid parameter was found', + throw: true + }, + 'WRONGTYPE':{ + msg: 'invalid parameter type was found', + throw: true + }, + 'NOT_IMPLEMENTED': { + msg: 'A openpgpjs parameter was submitted that is not implemented', + throw: true + }, + 'GENERIC_ERROR': { + msg: 'Unspecified error', + throw: true + }, + + // hopefully temporary errors + + 'NOT_YET_IMPLEMENTED': { + msg: 'Support of this is probable, but it is not implemented yet', + throw: false + } + } + if (!errors.hasOwnProperty(code)){ + throw('GENERIC_ERROR'); + } + let msg = code; + if (errors[code].msg !== undefined){ + msg = msg + ': ' + errors[code].msg; + } + if (details){ + msg = msg + ' ' + details; + } + if (config.debug === 'console'){ + console.log(msg); + } else if (config.debug === 'alert'){ + alert(msg); + } + switch (config.throw) { + case 'default': + if (errors[code].throw === true){ + throw(code); + } + break; + case 'always': + throw(code); + break; + + case 'never': + break; + default: + throw('GENERIC_ERROR'); + } + } +} -- cgit v1.2.3 From c72adc00965fe4fcedd9d18609211021a091b28b Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 25 Apr 2018 10:54:24 +0200 Subject: js: change in Error behaviour -- * Error objects will now return the error code if defined as error type in src/Errors.js, or do a console.log if it is a warning. Errors from the native gpgme-json will be marked as GNUPG_ERROR. --- lang/js/src/Errors.js | 170 ++++++++++++++++++++------------------------------ 1 file changed, 69 insertions(+), 101 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index c2356f7c..c49bfe21 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -18,131 +18,99 @@ * SPDX-License-Identifier: LGPL-2.1+ */ -// This is a preliminary collection of erors and warnings to be thrown and implemented. - -// general idea: if throw , throw the NAME -// return false || 'return' property - -//TODO: Connection.NOCONNECT promise -//connection.timeout: Be aware of pinentry - -export class GPGMEJS_Error { - - constructor(code = 'GENERIC_ERROR', details){ - let config = { //TODO TEMP - debug: 'console', // |'alert' - throw: 'default' // | 'always' | 'never' - }; +/** + * Checks the given error code and returns some information about it's meaning + * @param {String} code The error code + * @returns {Object} An object containing string properties code and msg + * TODO: error-like objects with the code 'GNUPG_ERROR' are errors sent + * directly by gnupg as answer in Connection.post() + */ +export function GPGMEJS_Error(code = 'GENERIC_ERROR'){ + if (!typeof(code) === 'string'){ + code = 'GENERIC_ERROR'; + } let errors = { //TODO: someplace else - //Connection errors - 'ALREADY_CONNECTED':{ - msg: 'The connection was already established. The action would overwrite the context', - throw: true + // Connection + 'CONN_NO_CONNECT': { + msg:'Connection with the nativeMessaging host could not be' + + ' established.', + type: 'error' }, - 'NO_CONNECT': { - msg:'Connection with the nativeMessaging host could not be established.', - throw: true + 'CONN_EMPTY_GPG_ANSWER':{ + msg: 'The nativeMessaging answer was empty.', + type: 'error' }, - 'EMPTY_GPG_ANSWER':{ - msg: 'The nativeMesaging answer was empty', - throw: true + 'CONN_TIMEOUT': { + msg: 'A connection timeout was exceeded.', + type: 'error' }, - 'TIMEOUT': { - msg: 'A timeout was exceeded.', - throw: false + 'CONN_UNEXPECTED_ANSWER': { + msg: 'The answer from gnupg was not as expected.', + type: 'error' }, - - 'UNEXPECTED_ANSWER': { - msg: 'The answer from gnupg was not as expected', - throw: true - }, - - // Message/Data Errors - - 'NO_KEYS' : { - msg: 'There were no valid keys provided.', - throw: true - }, - 'NOT_A_FPR': { - msg: 'The String is not an accepted fingerprint', - throw: false + 'CONN_ALREADY_CONNECTED':{ + msg: 'A connection was already established.', + type: 'warn' }, + // Message/Data 'MSG_INCOMPLETE': { - msg: 'The Message did not match the minimum requirements for the interaction', - throw: true - }, - 'EMPTY_MSG' : { - msg: 'The Message has no data.', - throw: true + msg: 'The Message did not match the minimum requirements for' + + ' the interaction.', + type: 'error' }, - 'MSG_NODATA':{ - msg: 'The data sent is empty. This may be unintentional.', - throw: false + 'MSG_EMPTY' : { + msg: 'The Message is empty.', + type: 'error' }, 'MSG_OP_PENDING': { - msg: 'There is no operation specified yet. The parameter cannot be set', - throw: false + msg: 'There is no operation specified yet. The parameter cannot' + + ' be set', + type: 'warning' }, - 'WRONG_OP': { - msg: "The operation requested could not be found", - throw: true + 'MSG_WRONG_OP': { + msg: 'The operation requested could not be found', + type: 'warning' + }, + 'MSG_NO_KEYS' : { + msg: 'There were no valid keys provided.', + type: 'warn' + }, + 'MSG_NOT_A_FPR': { + msg: 'The String is not an accepted fingerprint', + type: 'warn' }, - //generic errors - - 'WRONGPARAM':{ + // generic + 'PARAM_WRONG':{ msg: 'invalid parameter was found', - throw: true - }, - 'WRONGTYPE':{ - msg: 'invalid parameter type was found', - throw: true + type: 'error' }, 'NOT_IMPLEMENTED': { msg: 'A openpgpjs parameter was submitted that is not implemented', - throw: true + type: 'error' + }, + 'NOT_YET_IMPLEMENTED': { + msg: 'Support of this is probable, but it is not implemented yet', + type: 'error' }, 'GENERIC_ERROR': { msg: 'Unspecified error', - throw: true + type: 'error' }, - - // hopefully temporary errors - - 'NOT_YET_IMPLEMENTED': { - msg: 'Support of this is probable, but it is not implemented yet', - throw: false - } - } - if (!errors.hasOwnProperty(code)){ - throw('GENERIC_ERROR'); } - let msg = code; - if (errors[code].msg !== undefined){ - msg = msg + ': ' + errors[code].msg; + if (code === 'TODO'){ + alert('TODO_Error!'); } - if (details){ - msg = msg + ' ' + details; + if (errors.hasOwnProperty(code)){ + code = 'GENERIC_ERROR'; } - if (config.debug === 'console'){ - console.log(msg); - } else if (config.debug === 'alert'){ - alert(msg); + if (error.type === 'error'){ + return {code: 'code', + msg: errors[code].msg + }; } - switch (config.throw) { - case 'default': - if (errors[code].throw === true){ - throw(code); - } - break; - case 'always': - throw(code); - break; - - case 'never': - break; - default: - throw('GENERIC_ERROR'); + if (error.type === 'warning'){ + console.log(code + ': ' + error[code].msg); } - } + return undefined; } -- cgit v1.2.3 From 5befa1c9751fe54b5ae87906d7f09772ce9de6ea Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 25 Apr 2018 11:32:21 +0200 Subject: js: reactivate timeout on connection -- * A timeout of 5 seconds is activated for functions that do not require a pinentry. This definition is written to src/permittedOperations.js * testapplication.js now alerts the proper error codes and messages. * src/Errors.js fixed two typos in error handling --- lang/js/src/Errors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index c49bfe21..04b13e10 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -104,12 +104,12 @@ export function GPGMEJS_Error(code = 'GENERIC_ERROR'){ if (errors.hasOwnProperty(code)){ code = 'GENERIC_ERROR'; } - if (error.type === 'error'){ + if (errors.type === 'error'){ return {code: 'code', msg: errors[code].msg }; } - if (error.type === 'warning'){ + if (errors.type === 'warning'){ console.log(code + ': ' + error[code].msg); } return undefined; -- cgit v1.2.3 From 1fb310cabe578625f96fce5d84ff6f0092c08d24 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 25 Apr 2018 15:59:36 +0200 Subject: js: Configuration and Error handling -- * gpgmejs_openpgpjs - unsuported values with no negative consequences can now reject, warn or be ignored, according to config.unconsidered_params - cleanup of unsupported/supported parameters and TODOS * A src/index.js init() now accepts a configuration object * Errors will now be derived from Error, offering more info and a stacktrace. * Fixed Connection.post() timeout triggering on wrong cases * Added comments in permittedOperations.js, which gpgme interactions are still unimplemented and should be added next --- lang/js/src/Errors.js | 208 ++++++++++++++++++++++++++++---------------------- 1 file changed, 117 insertions(+), 91 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 04b13e10..2f53aa89 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -18,99 +18,125 @@ * SPDX-License-Identifier: LGPL-2.1+ */ +const err_list = { + // Connection + 'CONN_NO_CONNECT': { + msg:'Connection with the nativeMessaging host could not be' + + ' established.', + type: 'error' + }, + 'CONN_DISCONNECTED': { + msg:'Connection with the nativeMessaging host was lost.', + type: 'error' + }, + 'CONN_EMPTY_GPG_ANSWER':{ + msg: 'The nativeMessaging answer was empty.', + type: 'error' + }, + 'CONN_TIMEOUT': { + msg: 'A connection timeout was exceeded.', + type: 'error' + }, + 'CONN_UNEXPECTED_ANSWER': { + msg: 'The answer from gnupg was not as expected.', + type: 'error' + }, + 'CONN_ALREADY_CONNECTED':{ + msg: 'A connection was already established.', + type: 'warning' + }, + // Message/Data + 'MSG_INCOMPLETE': { + msg: 'The Message did not match the minimum requirements for' + + ' the interaction.', + type: 'error' + }, + 'MSG_EMPTY' : { + msg: 'The Message is empty.', + type: 'error' + }, + 'MSG_OP_PENDING': { + msg: 'There is no operation specified yet. The parameter cannot' + + ' be set', + type: 'warning' + }, + 'MSG_WRONG_OP': { + msg: 'The operation requested could not be found', + type: 'warning' + }, + 'MSG_NO_KEYS' : { + msg: 'There were no valid keys provided.', + type: 'warning' + }, + 'MSG_NOT_A_FPR': { + msg: 'The String is not an accepted fingerprint', + type: 'warning' + }, + 'KEY_INVALID': { + msg:'Key object is invalid', + type: 'error' + }, + // generic + 'PARAM_WRONG':{ + msg: 'invalid parameter was found', + type: 'error' + }, + 'PARAM_IGNORED': { + msg: 'An parameter was set that has no effect in gpgmejs', + type: 'warning' + }, + 'NOT_IMPLEMENTED': { + msg: 'A openpgpjs parameter was submitted that is not implemented', + type: 'error' + }, + 'NOT_YET_IMPLEMENTED': { + msg: 'Support of this is probable, but it is not implemented yet', + type: 'error' + }, + 'GENERIC_ERROR': { + msg: 'Unspecified error', + type: 'error' + } +}; + /** - * Checks the given error code and returns some information about it's meaning - * @param {String} code The error code - * @returns {Object} An object containing string properties code and msg - * TODO: error-like objects with the code 'GNUPG_ERROR' are errors sent - * directly by gnupg as answer in Connection.post() + * Checks the given error code and returns an error object with some + * information about meaning and origin + * @param {*} code Error code. Should be in err_list or 'GNUPG_ERROR' + * @param {*} info Error message passed through if code is 'GNUPG_ERROR' */ -export function GPGMEJS_Error(code = 'GENERIC_ERROR'){ - if (!typeof(code) === 'string'){ - code = 'GENERIC_ERROR'; - } - let errors = { //TODO: someplace else - // Connection - 'CONN_NO_CONNECT': { - msg:'Connection with the nativeMessaging host could not be' - + ' established.', - type: 'error' - }, - 'CONN_EMPTY_GPG_ANSWER':{ - msg: 'The nativeMessaging answer was empty.', - type: 'error' - }, - 'CONN_TIMEOUT': { - msg: 'A connection timeout was exceeded.', - type: 'error' - }, - 'CONN_UNEXPECTED_ANSWER': { - msg: 'The answer from gnupg was not as expected.', - type: 'error' - }, - 'CONN_ALREADY_CONNECTED':{ - msg: 'A connection was already established.', - type: 'warn' - }, - // Message/Data - 'MSG_INCOMPLETE': { - msg: 'The Message did not match the minimum requirements for' - + ' the interaction.', - type: 'error' - }, - 'MSG_EMPTY' : { - msg: 'The Message is empty.', - type: 'error' - }, - 'MSG_OP_PENDING': { - msg: 'There is no operation specified yet. The parameter cannot' - + ' be set', - type: 'warning' - }, - 'MSG_WRONG_OP': { - msg: 'The operation requested could not be found', - type: 'warning' - }, - 'MSG_NO_KEYS' : { - msg: 'There were no valid keys provided.', - type: 'warn' - }, - 'MSG_NOT_A_FPR': { - msg: 'The String is not an accepted fingerprint', - type: 'warn' - }, - - // generic - 'PARAM_WRONG':{ - msg: 'invalid parameter was found', - type: 'error' - }, - 'NOT_IMPLEMENTED': { - msg: 'A openpgpjs parameter was submitted that is not implemented', - type: 'error' - }, - 'NOT_YET_IMPLEMENTED': { - msg: 'Support of this is probable, but it is not implemented yet', - type: 'error' - }, - 'GENERIC_ERROR': { - msg: 'Unspecified error', - type: 'error' - }, - } - if (code === 'TODO'){ - alert('TODO_Error!'); +export function gpgme_error(code = 'GENERIC_ERROR', info){ + if (err_list.hasOwnProperty(code)){ + if (err_list[code].type === 'error'){ + return new GPGME_Error(code); } - if (errors.hasOwnProperty(code)){ - code = 'GENERIC_ERROR'; + if (err_list[code].type === 'warning'){ + console.log(new GPGME_Error(code)); } - if (errors.type === 'error'){ - return {code: 'code', - msg: errors[code].msg - }; - } - if (errors.type === 'warning'){ - console.log(code + ': ' + error[code].msg); - } - return undefined; + return null; + } else if (code === 'GNUPG_ERROR'){ + return new GPGME_Error(code, info.msg); + } + else { + return new GPGME_Error('GENERIC_ERROR'); + } } + +class GPGME_Error extends Error{ + constructor(code, msg=''){ + if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){ + super(msg); + } else if (err_list.hasOwnProperty(code)){ + super(err_list[code].msg); + } else { + super(err_list['GENERIC_ERROR'].msg); + } + this.code = code || 'GENERIC_ERROR'; + } + set code(value){ + this._code = value; + } + get code(){ + return this._code; + } +} \ No newline at end of file -- cgit v1.2.3 From 3685913bf510a14b8cb324d980217d90489e6453 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 25 Apr 2018 19:45:39 +0200 Subject: js: First testing and improvements -- * Introduced Mocha/chai as testsuite. After development build 'npm test' should run the unit tests. Functionality exclusive to Browsers/WebExtensions cannot be run this way, so some other testing is still needed. - package.json: Added required development packages - .babelrc indirect configuration for mocha. ES6 transpiling needs some babel configuration, but mocha has no setting for it. - test/mocha.opts Vonfiguration for mocha runs * Fixed errors: - Helpers.js toKeyIdArray; isLongId is now exported - Key.js Key constructor failed - Message.js will not throw an Error during construction, a new message is now created with createMessage, which can return an Error or a GPGME_Message object * Tests: - test/Helpers: exports from Helpers.js, GPGME_Error handling - test/Message: first init test with bad parameters --- lang/js/src/Errors.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 2f53aa89..d26aab18 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -55,14 +55,9 @@ const err_list = { msg: 'The Message is empty.', type: 'error' }, - 'MSG_OP_PENDING': { - msg: 'There is no operation specified yet. The parameter cannot' - + ' be set', - type: 'warning' - }, 'MSG_WRONG_OP': { msg: 'The operation requested could not be found', - type: 'warning' + type: 'error' }, 'MSG_NO_KEYS' : { msg: 'There were no valid keys provided.', @@ -78,7 +73,7 @@ const err_list = { }, // generic 'PARAM_WRONG':{ - msg: 'invalid parameter was found', + msg: 'Invalid parameter was found', type: 'error' }, 'PARAM_IGNORED': { @@ -111,7 +106,7 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ return new GPGME_Error(code); } if (err_list[code].type === 'warning'){ - console.log(new GPGME_Error(code)); + console.warn(code + ': ' + err_list[code].msg); } return null; } else if (code === 'GNUPG_ERROR'){ -- cgit v1.2.3 From cca40627b0afa2efc85ef7f5f1a1060a221ff2a2 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Tue, 8 May 2018 18:33:41 +0200 Subject: js: more testing -- * Tests: Under certain circumstances, some data change during encrypt-decrypt. Committing the current state so the problem can be discussed. * Fixes: - disconnecting the test ports after tests are complete - fixed passing of the error message from gpgme-json --- lang/js/src/Errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index d26aab18..b71004a5 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -110,7 +110,7 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ } return null; } else if (code === 'GNUPG_ERROR'){ - return new GPGME_Error(code, info.msg); + return new GPGME_Error(code, info); } else { return new GPGME_Error('GENERIC_ERROR'); -- cgit v1.2.3 From f7ed80ff6a66f2c5ee6f1c3daebd597f4592733d Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 23 May 2018 12:56:23 +0200 Subject: js: remove openpgp mode -- * After discussion, that mode is not required, and can result in being quite misleading and a maintenance hassle later on. --- lang/js/src/Errors.js | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index b71004a5..bfe3a2f4 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -80,14 +80,6 @@ const err_list = { msg: 'An parameter was set that has no effect in gpgmejs', type: 'warning' }, - 'NOT_IMPLEMENTED': { - msg: 'A openpgpjs parameter was submitted that is not implemented', - type: 'error' - }, - 'NOT_YET_IMPLEMENTED': { - msg: 'Support of this is probable, but it is not implemented yet', - type: 'error' - }, 'GENERIC_ERROR': { msg: 'Unspecified error', type: 'error' -- cgit v1.2.3 From eff27d6387b1cad2ef9901fa03dbee2ea86c786a Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Fri, 25 May 2018 11:53:24 +0200 Subject: js: use version operation for connection checks -- * src/Connection.js: isConnected was renamed to checkConnection, that returns a promise with either version information or Boolean * Connection checks have been adapted to reflect that checkConnection returns a Promise * BrowsertestExtension: tests/signTest.js was missing from my last commit --- lang/js/src/Errors.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index bfe3a2f4..7e98f319 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -25,10 +25,6 @@ const err_list = { + ' established.', type: 'error' }, - 'CONN_DISCONNECTED': { - msg:'Connection with the nativeMessaging host was lost.', - type: 'error' - }, 'CONN_EMPTY_GPG_ANSWER':{ msg: 'The nativeMessaging answer was empty.', type: 'error' -- cgit v1.2.3 From 7a73d88aba106d571f121dc3230864c81a76e5db Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Fri, 25 May 2018 19:02:18 +0200 Subject: js: implement Key handling (1) -- * Keys can now be queried for information. Onne version queries gnug directly (asynchronous Promise in javascript terms), the cached version refreshes on demand. * Small fixes: src/Connection.js joins answers that stay json properly now --- lang/js/src/Errors.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 7e98f319..fa8a4efe 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -67,6 +67,10 @@ const err_list = { msg:'Key object is invalid', type: 'error' }, + 'KEY_NOKEY': { + msg:'This key does not exist in GPG', + type: 'error' + }, // generic 'PARAM_WRONG':{ msg: 'Invalid parameter was found', -- cgit v1.2.3 From 332b4adbcc52ccf337cbc1943d5abef500769e10 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 30 May 2018 17:05:54 +0200 Subject: js: more Keyring/Key handling -- * src/Keys.js - made setKeyData more consistent with other methods - added convenience methods (Key.armored, Key.hasSecret) - Added a Key delete function * src/Keyring.js: - added a getkeysArmored which allows for bulk export of public Keys gpgmejs: - removed deleteKey. It is now a method of the Key itself - Encrypt: Added some common options as parameter, and the possibility to set all allowed flags via an additional Object --- lang/js/src/Errors.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index fa8a4efe..3b53eeb4 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -71,6 +71,10 @@ const err_list = { msg:'This key does not exist in GPG', type: 'error' }, + 'KEY_NO_INIT': { + msg:'This property has not been retrieved yet from GPG', + type: 'error' + } // generic 'PARAM_WRONG':{ msg: 'Invalid parameter was found', -- cgit v1.2.3 From 0356a667c5a8b4fdb4404cebb57475ed3f39ade9 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 6 Jun 2018 11:57:41 +0200 Subject: 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 --- lang/js/src/Errors.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 3b53eeb4..2f2bfd5c 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -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)){ - super(err_list[code].msg); + if (msg){ + super(err_list[code].msg + "--" + msg); + } else { + super(err_list[code].msg); + } } else { super(err_list['GENERIC_ERROR'].msg); } -- cgit v1.2.3 From bfd3799d39df265882deedeee083fd5246a2f35d Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 6 Jun 2018 13:05:53 +0200 Subject: js: code cleanup (eslint) -- * trying to stick to eslint from now on for readability * As some attribution was lost in previous git confusions, I added my name into some of the licence headers --- lang/js/src/Errors.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 2f2bfd5c..dabf6a5c 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -16,6 +16,9 @@ * 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 */ const err_list = { @@ -102,6 +105,7 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ return new GPGME_Error(code); } if (err_list[code].type === 'warning'){ + // eslint-disable-next-line no-console console.warn(code + ': ' + err_list[code].msg); } return null; @@ -119,7 +123,7 @@ class GPGME_Error extends Error{ super(msg); } else if (err_list.hasOwnProperty(code)){ if (msg){ - super(err_list[code].msg + "--" + msg); + super(err_list[code].msg + '--' + msg); } else { super(err_list[code].msg); } -- cgit v1.2.3 From aed402c5d572b60246f1f8e57ae269f8c91b0b7c Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 13 Jun 2018 15:22:03 +0200 Subject: js: getDefaultKey and verify fix -- * DemoExtension/maindemo.js - added a Demo for retrieving the default signing key * src/Errors.js - add a new Error if no default key can be determined * src/Key.js added documentation and a TODO marker for hasSecret. * src/Keyring.js implemented getDefaultKey * src/permittedOperations.js: Added missing entry for verify, added config_opt --- lang/js/src/Errors.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index dabf6a5c..73e74382 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -78,6 +78,11 @@ const err_list = { msg:'This property has not been retrieved yet from GPG', type: 'error' }, + 'KEY_NO_DEFAULT': { + msg:'A default key could not be established. Please check yout gpg ' + + 'configuration', + type: 'error' + }, // generic 'PARAM_WRONG':{ msg: 'Invalid parameter was found', -- cgit v1.2.3 From 3c783bd09ce54b0d50dc3bea201e70e4fcbbf6a3 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Thu, 14 Jun 2018 12:15:51 +0200 Subject: js: add verify and signature parsing -- * src/gpgmejs.js: - Added verify method - Added verification results in decrypt (if signatures are present in the message) - Added a base64 option to decrypt * src/Signature.js: Convenience class for verification results. Used for e.g. converting timestamps to javascript time, quick overall validity checks * src/Keyring.js: removed debug code * src/Errors.js add two new Signature errors --- lang/js/src/Errors.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 73e74382..a8cd8b56 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -83,6 +83,14 @@ const err_list = { 'configuration', type: 'error' }, + 'SIG_WRONG': { + msg:'A malformed signature was created', + type: 'error' + }, + 'SIG_NO_SIGS': { + msg:'There were no signatures found', + type: 'error' + }, // generic 'PARAM_WRONG':{ msg: 'Invalid parameter was found', -- cgit v1.2.3 From 4015f5b4983c8a4590aa71776880d8bc42c7918d Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Tue, 10 Jul 2018 14:32:26 +0200 Subject: js: documentation -- * Fixed errors: - src/Message.js post(): Set chunksize to defined default value instead of hardcoded - src/Keys.js: added getHasSecret() to refreshKey operation. * Reviewed and updated the documentation * non-documentation changes which do not affect functionality: - src/Errors: disabled a console.warn that is only useful for debugging - helpers.js: renamed "string" to "value" in isFingerprint and isLongId to avoid confusion - src/Keyring: prepare_sync, search are both explicitly set to false by default --- lang/js/src/Errors.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index a8cd8b56..cb5c94c2 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -21,6 +21,9 @@ * Maximilian Krambach */ +/** + * Listing of all possible error codes and messages of a {@link GPGME_Error}. + */ const err_list = { // Connection 'CONN_NO_CONNECT': { @@ -107,10 +110,11 @@ const err_list = { }; /** - * Checks the given error code and returns an error object with some - * information about meaning and origin + * Checks the given error code and returns an {@link GPGME_Error} error object + * with some information about meaning and origin * @param {*} code Error code. Should be in err_list or 'GNUPG_ERROR' * @param {*} info Error message passed through if code is 'GNUPG_ERROR' + * @returns {GPGME_Error} */ export function gpgme_error(code = 'GENERIC_ERROR', info){ if (err_list.hasOwnProperty(code)){ @@ -119,7 +123,7 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ } if (err_list[code].type === 'warning'){ // eslint-disable-next-line no-console - console.warn(code + ': ' + err_list[code].msg); + // console.warn(code + ': ' + err_list[code].msg); } return null; } else if (code === 'GNUPG_ERROR'){ @@ -130,6 +134,14 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ } } +/** + * An error class with additional info about the origin of the error, as string + * @property {String} code Short description of origin and type of the error + * @property {String} msg Additional info + * @class + * @protected + * @extends Error + */ class GPGME_Error extends Error{ constructor(code, msg=''){ if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){ -- cgit v1.2.3 From 94ee0988d4eaac27785de6efb7c19ca9976e1e9c Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Fri, 27 Jul 2018 20:36:21 +0200 Subject: js: change the write access for js class methods -- * src/ [Connection, Error, Key, Keyring, MEssage, Signature, gpgmejs]: Functions and values that are not meant to be overwritten are now moved into their constructors, thus eliminating the possibility of overwrites after initialization. * Key: The mode of use (synchronous cached, or async promises) ivs now determined at initialization of that Key. The property Key.isAsync reflects this state. * unittests: fixed old Key syntax for testing. * Message.js isComplete is now a method and not a getter anymore. * Added some startup tests. --- lang/js/src/Errors.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index cb5c94c2..0cf1af19 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -143,7 +143,7 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ * @extends Error */ class GPGME_Error extends Error{ - constructor(code, msg=''){ + constructor(code = 'GENERIC_ERROR', msg=''){ if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){ super(msg); } else if (err_list.hasOwnProperty(code)){ @@ -155,12 +155,12 @@ class GPGME_Error extends Error{ } else { super(err_list['GENERIC_ERROR'].msg); } - this.code = code || 'GENERIC_ERROR'; - } - set code(value){ - this._code = value; + this.getCode = function(){ + return code; + }; } + get code(){ - return this._code; + return this.getCode(); } } \ No newline at end of file -- cgit v1.2.3 From e16a87e83910ebb6bfdc4148369165f121f0997e Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 30 Jul 2018 12:31:27 +0200 Subject: js: Making objects inmutable -- * An Object.freeze should stop any malicious third party from changing objects' methods once the objects are instantiated (see unittest for an approach that would have worked before) - An initialized gpgmejs- object doesn't have a '_Keyring' property anymore (it still has its 'Keyring') - The internal expect='base64' needed to be turned into a method. --- lang/js/src/Errors.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 0cf1af19..39e3a74a 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -119,7 +119,7 @@ const err_list = { export function gpgme_error(code = 'GENERIC_ERROR', info){ if (err_list.hasOwnProperty(code)){ if (err_list[code].type === 'error'){ - return new GPGME_Error(code); + return Object.freeze(new GPGME_Error(code)); } if (err_list[code].type === 'warning'){ // eslint-disable-next-line no-console @@ -127,10 +127,10 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ } return null; } else if (code === 'GNUPG_ERROR'){ - return new GPGME_Error(code, info); + return Object.freeze(new GPGME_Error(code, info)); } else { - return new GPGME_Error('GENERIC_ERROR'); + return Object.freeze(new GPGME_Error('GENERIC_ERROR')); } } -- cgit v1.2.3 From ad39d54d192864b54a155bf5f94d5b6bb3e8612a Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Fri, 17 Aug 2018 16:57:41 +0200 Subject: js: removed Key.armor property in synchronous use -- * src/Key.js The synchronous mode for a Key does not offer an armor/ armored property anymore. This frees up a lot of performance issues, also the armored expoort is expected to change quite often, so a cached version is not advisable. * hasSecret/getHasSecret is now refactored, to reflect their uses. With get('hasSecret') there is a method that fetches the result. * src/Key.js also some refactoring --- lang/js/src/Errors.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 39e3a74a..b22eca73 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -81,6 +81,10 @@ const err_list = { msg:'This property has not been retrieved yet from GPG', type: 'error' }, + 'KEY_ASYNC_ONLY': { + msg: 'This property cannot be used in synchronous calls', + type: 'error' + }, 'KEY_NO_DEFAULT': { msg:'A default key could not be established. Please check yout gpg ' + 'configuration', -- cgit v1.2.3 From 1954d27be86b8e4eb801ca6ddcb670f8cfb149f5 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 20 Aug 2018 12:12:43 +0200 Subject: js: revert changes to class read/write restriction -- * undoes 94ee0988d4eaac27785de6efb7c19ca9976e1e9c and e16a87e83910ebb6bfdc4148369165f121f0997e. I do not fully understand why my approach was bad, but I am not in a position to argue. This revert was requested to me after a review, and I'm doing it in the assumption that more experienced people know better than me. * unittests: Also changed some outdated tests that stopped working since 754e799d35fd62d7a979452f44342934659908c7 (as GPGME_Key is not exported, one cannot check for instanceof in the tests anymore) --- lang/js/src/Errors.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index b22eca73..2a35bc5e 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -123,7 +123,7 @@ const err_list = { export function gpgme_error(code = 'GENERIC_ERROR', info){ if (err_list.hasOwnProperty(code)){ if (err_list[code].type === 'error'){ - return Object.freeze(new GPGME_Error(code)); + return new GPGME_Error(code); } if (err_list[code].type === 'warning'){ // eslint-disable-next-line no-console @@ -131,10 +131,10 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ } return null; } else if (code === 'GNUPG_ERROR'){ - return Object.freeze(new GPGME_Error(code, info)); + return new GPGME_Error(code, info); } else { - return Object.freeze(new GPGME_Error('GENERIC_ERROR')); + return new GPGME_Error('GENERIC_ERROR'); } } @@ -148,6 +148,7 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ */ class GPGME_Error extends Error{ constructor(code = 'GENERIC_ERROR', msg=''){ + if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){ super(msg); } else if (err_list.hasOwnProperty(code)){ @@ -159,12 +160,10 @@ class GPGME_Error extends Error{ } else { super(err_list['GENERIC_ERROR'].msg); } - this.getCode = function(){ - return code; - }; + this._code = code; } get code(){ - return this.getCode(); + return this._code; } } \ No newline at end of file -- cgit v1.2.3 From dd32daad0bb21e3d5567326d0b2e548ff8510431 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 20 Aug 2018 15:12:01 +0200 Subject: js: add and apply eslint rules -- * mainly spacing, see .eslintrc.json for details --- lang/js/src/Errors.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 2a35bc5e..53e7bcd7 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -120,7 +120,7 @@ const err_list = { * @param {*} info Error message passed through if code is 'GNUPG_ERROR' * @returns {GPGME_Error} */ -export function gpgme_error(code = 'GENERIC_ERROR', info){ +export function gpgme_error (code = 'GENERIC_ERROR', info){ if (err_list.hasOwnProperty(code)){ if (err_list[code].type === 'error'){ return new GPGME_Error(code); @@ -147,9 +147,9 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ * @extends Error */ class GPGME_Error extends Error{ - constructor(code = 'GENERIC_ERROR', msg=''){ + constructor (code = 'GENERIC_ERROR', msg=''){ - if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){ + if (code === 'GNUPG_ERROR' && typeof (msg) === 'string'){ super(msg); } else if (err_list.hasOwnProperty(code)){ if (msg){ @@ -163,7 +163,7 @@ class GPGME_Error extends Error{ this._code = code; } - get code(){ + get code (){ return this._code; } } \ No newline at end of file -- cgit v1.2.3 From 93f674d33d4dacb115398196a7218c28323fd708 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 22 Aug 2018 12:18:55 +0200 Subject: js: throw errors in sync functions -- * synchronous functions should throw errors if something goes wrong, Promises should reject. This commit changes some error cases that returned Error objects instead of throwing them - src/Key.js: createKey() and sync Key.get() throw errors - src/Error.js: Exporting the list of errors to be able to test and compare against these strings - src/Keyring.js: Setting a null value in pattern is not useful, and now caused an error with the new changes. - src/Message.js: createMessage and Message.setParameter now throw errors --- lang/js/src/Errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index 53e7bcd7..73418028 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -24,7 +24,7 @@ /** * Listing of all possible error codes and messages of a {@link GPGME_Error}. */ -const err_list = { +export const err_list = { // Connection 'CONN_NO_CONNECT': { msg:'Connection with the nativeMessaging host could not be' -- cgit v1.2.3