aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-05-23 10:56:23 +0000
committerMaximilian Krambach <[email protected]>2018-05-23 10:56:23 +0000
commitf7ed80ff6a66f2c5ee6f1c3daebd597f4592733d (patch)
tree3dc2b4dde55c14825b9dfa9db7ed225db77ab9d0 /lang/js/src
parentjs: transfer encoding changes (diff)
downloadgpgme-f7ed80ff6a66f2c5ee6f1c3daebd597f4592733d.tar.gz
gpgme-f7ed80ff6a66f2c5ee6f1c3daebd597f4592733d.zip
js: remove openpgp mode
-- * After discussion, that mode is not required, and can result in being quite misleading and a maintenance hassle later on.
Diffstat (limited to 'lang/js/src')
-rw-r--r--lang/js/src/Config.js8
-rw-r--r--lang/js/src/Errors.js8
-rw-r--r--lang/js/src/gpgmejs.js4
-rw-r--r--lang/js/src/gpgmejs_openpgpjs.js301
-rw-r--r--lang/js/src/index.js7
5 files changed, 7 insertions, 321 deletions
diff --git a/lang/js/src/Config.js b/lang/js/src/Config.js
index e18728de..e85bbb82 100644
--- a/lang/js/src/Config.js
+++ b/lang/js/src/Config.js
@@ -19,13 +19,13 @@
*/
export const availableConf = {
- api_style: ['gpgme', 'gpgme_openpgpjs'],
null_expire_is_never: [true, false],
- unconsidered_params: ['warn','reject', 'ignore'],
+ // cachedKeys: Some Key info will not be queried on each invocation,
+ // manual refresh by Key.refresh()
+ cachedKeys: [true, false]
};
export const defaultConf = {
- api_style: 'gpgme',
null_expire_is_never: false,
- unconsidered_params: 'reject',
+ cachedKeys: false
}; \ No newline at end of file
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'
diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js
index 01cb92c3..3aa5957a 100644
--- a/lang/js/src/gpgmejs.js
+++ b/lang/js/src/gpgmejs.js
@@ -54,8 +54,8 @@ export class GpgME {
}
set Keyring(keyring){
- if (ring && ring instanceof GPGME_Keyring){
- this._Keyring = ring;
+ if (keyring && keyring instanceof GPGME_Keyring){
+ this._Keyring = keyring;
}
}
diff --git a/lang/js/src/gpgmejs_openpgpjs.js b/lang/js/src/gpgmejs_openpgpjs.js
deleted file mode 100644
index 9c8cd2cc..00000000
--- a/lang/js/src/gpgmejs_openpgpjs.js
+++ /dev/null
@@ -1,301 +0,0 @@
-/* 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+
- */
-
-/**
- * This is a compatibility API to be used as openpgpjs syntax.
- * Non-implemented options will throw an error if set (not null or undefined)
- * TODO Some info about differences
- */
-
- import { GpgME } from "./gpgmejs";
- import {GPGME_Keyring} from "./Keyring";
- import { GPGME_Key, createKey } from "./Key";
- import { isFingerprint } from "./Helpers";
- import { gpgme_error } from "./Errors";
-import { Connection } from "./Connection";
-
-
- export class GpgME_openpgpmode {
-
- constructor(connection, config = {}){
- this.initGpgME(connection, config);
- }
-
- get Keyring(){
- if (this._keyring){
- return this._keyring;
- }
- return undefined;
- }
-
- initGpgME(connection, config = {}){
- if (connection && typeof(config) ==='object'){
- this._config = config;
- if (!this._GpgME){
- this._GpgME = new GpgME(connection, config);
- }
- if (!this._keyring){
- this._keyring = new GPGME_Keyring_openpgpmode(connection);
- }
- }
- }
-
- /**
- * Encrypt Message
- * Supported:
- * @param {String|Message} data
- * an openpgp Message is accepted here.
- * @param {Key|Array<Key>} publicKeys
- * //Strings of Fingerprints
- * @param {Boolean} wildcard
- * TODO:
- * @param {Key|Array<Key>} privateKeys // -> encryptsign
- * @param {module:enums.compression} compression //TODO accepts integer, if 0 (no compression) it won't compress
- * @param {Boolean} armor // TODO base64 switch
- * @param {Boolean} detached // --> encryptsign
- * unsupported:
- * @param {String|Array<String>} passwords
- * @param {Object} sessionKey
- * @param {Signature} signature
- * @param {Boolean} returnSessionKey
- * @param {String} filename
- *
- * Can be set, but will be ignored:
- *
- * @returns {Promise<Object>}
- * {data: ASCII armored message,
- * signature: detached signature if 'detached' is true
- * }
- * @async
- * @static
- */
- encrypt(options) {
- if (!options || typeof(options) !== 'object'){
- return Promise.reject(gpgme_error('PARAM_WRONG'));
- }
- if (options.passwords
- || options.sessionKey
- || options.signature
- || options.returnSessionKey
- || (options.hasOwnProperty('date') && options.date !== null)
- ){
- return Promise.reject(gpgme_error('NOT_IMPLEMENTED'));
- }
- if ( options.privateKeys
- || options.compression
- || (options.hasOwnProperty('armor') && options.armor === false)
- || (options.hasOwnProperty('detached') && options.detached == true)
- ){
- return Promise.reject(gpgme_error('NOT_YET_IMPLEMENTED'));
- }
- if (options.filename){
- if (this._config.unconsidered_params === 'warn'){
- gpgme_error('PARAM_IGNORED');
- } else if (this._config.unconsidered_params === 'error'){
- return Promise.reject(gpgme_error('NOT_IMPLEMENTED'));
- }
- }
- return this._GpgME.encrypt(
- options.data, options.publicKeys, options.wildcard);
- }
-
- /** Decrypt Message
- * supported openpgpjs parameters:
- * @param {Message|String} message Message object from openpgpjs
- * Unsupported:
- * @param {String|Array<String>} passwords
- * @param {Key|Array<Key>} privateKeys
- * @param {Object|Array<Object>} sessionKeys
- * Not yet supported, but planned
- * @param {String} format (optional) return data format either as 'utf8' or 'binary'
- * @param {Signature} signature (optional) detached signature for verification
- * Ignored values: can be safely set, but have no effect
- * @param {Date} date
- * @param {Key|Array<Key>} publicKeys
- *
- * @returns {Promise<Object>} decrypted and verified message in the form:
- * { data:String, filename:String, signatures:[{ keyid:String, valid:Boolean }] }
- * @async
- * @static
- */
- decrypt(options) {
- if (options.passwords
- || options.sessionKeys
- || options.privateKeys
- ){
- return Promise.reject(gpgme_error('NOT_IMPLEMENTED'));
- }
- if ((options.hasOwnProperty('format') && options.format !== 'utf8')
- || options.signature
- ){
- return Promise.reject(gpgme_error('NOT_YET_IMPLEMENTED'));
- }
- if ((options.hasOwnProperty('date') && options.date !== null)
- || options.publicKeys
- ){
- if (this._config.unconsidered_params === 'warn'){
- GPMGEJS_Error('PARAM_IGNORED');
- } else if (this._config.unconsidered_params === 'reject'){
- return Promise.reject(GPMGEJS_Error('NOT_IMPLEMENTED'));
- }
- }
- return this._GpgME.decrypt(options.message);
-
- // TODO: translate between:
- // openpgp:
- // { data:Uint8Array|String,
- // filename:String,
- // signatures:[{ keyid:String, valid:Boolean }] }
- // and gnupg:
- // data: The decrypted data. This may be base64 encoded.
- // base64: Boolean indicating whether data is base64 encoded.
- // mime: A Boolean indicating whether the data is a MIME object.
- // info: An optional object with extra information.
- }
-}
-
-/**
- * Translation layer offering basic Keyring API to be used in Mailvelope.
- * It may still be changed/expanded/merged with GPGME_Keyring
- */
-class GPGME_Keyring_openpgpmode {
- constructor(connection){
- this._gpgme_keyring = new GPGME_Keyring(connection);
- }
-
- /**
- * Returns a GPGME_Key Object for each Key in the gnupg Keyring. This
- * includes keys openpgpjs considers 'private' (usable for signing), with
- * the difference that Key.armored will NOT contain any secret information.
- * Please also note that a GPGME_Key does not offer full openpgpjs- Key
- * compatibility.
- * @returns {Array<GPGME_Key_openpgpmode>}
- * //TODO: Check if IsDefault is also always hasSecret
- * TODO Check if async is required
- */
- getPublicKeys(){
- return translateKeys(
- this._gpgme_keyring.getKeys(null, true));
- }
-
- /**
- * Returns the Default Key used for crypto operation in gnupg.
- * Please note that the armored property does not contained secret key blocks,
- * despite secret blocks being part of the key itself.
- * @returns {Promise <GPGME_Key>}
- */
- getDefaultKey(){
- this._gpgme_keyring.getSubset({defaultKey: true}).then(function(result){
- if (result.length === 1){
- return Promise.resolve(
- translateKeys(result)[0]);
- }
- else {
- // TODO: Can there be "no default key"?
- // TODO: Can there be several default keys?
- return gpgme_error('TODO');
- }
- }, function(error){
- //TODO
- });
- }
-
- /**
- * Deletes a Key
- * @param {Object} Object identifying key
- * @param {String} key.fingerprint - fingerprint of the to be deleted key
- * @param {Boolean} key.secret - indicator if private key should be deleted as well
-
- * @returns {Promise.<Array.<undefined>, Error>} TBD: Not sure what is wanted
- TODO @throws {Error} error.code = ‘KEY_NOT_EXIST’ - there is no key for the given fingerprint
- TODO @throws {Error} error.code = ‘NO_SECRET_KEY’ - secret indicator set, but no secret key exists
- */
- deleteKey(key){
- if (typeof(key) !== "object"){
- return Promise.reject(gpgme_error('PARAM_WRONG'));
- }
- if ( !key.fingerprint || ! isFingerprint(key.fingerprint)){
- return Promise.reject(gpgme_error('PARAM_WRONG'));
- }
- let key_to_delete = createKey(key.fingerprint, this._gpgme_keyring_GpgME);
- return key_to_delete.deleteKey(key.secret);
- }
-}
-
-/**
- * TODO error handling.
- * Offers the Key information as the openpgpmode wants
- */
-class GPGME_Key_openpgpmode {
- constructor(value, connection){
- this.init(value, connection);
- }
-
- /**
- * Can be either constructed using an existing GPGME_Key, or a fingerprint
- * and a connection
- * @param {String|GPGME_Key} value
- * @param {Connection} connection
- */
- init (value, connection){
- if (!this._GPGME_Key && value instanceof GPGME_Key){
- this._GPGME_Key = value;
- } else if (!this._GPGME_Key && isFingerprint(value) &&
- connection instanceof Connection){
- this._GPGME_Key = createKey(value, connection);
- }
- }
-
- get fingerprint(){
- return this._GPGME_Key.fingerprint;
- }
-
- get armor(){
- return this._GPGME_Key.armored;
- }
-
- get secret(){
- return this._GPGME_Key.hasSecret;
- }
-
- get default(){
- return this._GPGME_Key.isDefault;
- }
-}
-
-/**
- * creates GPGME_Key_openpgpmode from GPGME_Keys
- * @param {GPGME_Key|Array<GPGME_Key>} input keys
- * @returns {Array<GPGME_Key_openpgpmode>}
- */
-function translateKeys(input){
- //TODO: does not check if inpout is okay!
- if (!input){
- return null;
- }
- if (!Array.isArray(input)){
- input = [input];
- }
- let resultset = [];
- for (let i=0; i< input.length; i++) {
- resultset.push(new GPGME_Key_openpgpmode(input[i]));
- }
- return resultset;
-} \ No newline at end of file
diff --git a/lang/js/src/index.js b/lang/js/src/index.js
index fc406c66..8527b3f3 100644
--- a/lang/js/src/index.js
+++ b/lang/js/src/index.js
@@ -20,7 +20,6 @@
import { GpgME } from "./gpgmejs";
import { gpgme_error } from "./Errors";
-import { GpgME_openpgpmode } from "./gpgmejs_openpgpjs";
import { Connection } from "./Connection";
import { defaultConf, availableConf } from "./Config";
@@ -43,11 +42,7 @@ function init(config){
reject(gpgme_error('CONN_NO_CONNECT'));
}
if (connection.isConnected === true){
- if (_conf.api_style && _conf.api_style === 'gpgme_openpgpjs'){
- resolve(new GpgME_openpgpmode(connection, _conf));
- } else {
- resolve(new GpgME(connection));
- }
+ resolve(new GpgME(connection, _conf));
} else {
reject(gpgme_error('CONN_NO_CONNECT'));
}