2018-04-23 15:18:46 +00:00
|
|
|
/* 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+
|
|
|
|
*/
|
|
|
|
|
2018-04-25 17:45:39 +00:00
|
|
|
import {createMessage} from './Message'
|
2018-05-28 15:26:56 +00:00
|
|
|
import {GPGME_Key, createKey} from './Key'
|
2018-05-03 16:03:22 +00:00
|
|
|
import { isFingerprint } from './Helpers';
|
2018-04-25 13:59:36 +00:00
|
|
|
import { gpgme_error } from './Errors';
|
2018-04-23 15:18:46 +00:00
|
|
|
|
|
|
|
export class GPGME_Keyring {
|
2018-05-28 14:52:50 +00:00
|
|
|
constructor(){
|
2018-04-23 15:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-28 15:26:56 +00:00
|
|
|
* @param {String} pattern (optional) pattern A pattern to search for,
|
|
|
|
* in userIds or KeyIds
|
|
|
|
* @param {Boolean} prepare_sync (optional, default true) if set to true,
|
|
|
|
* Key.armor and Key.hasSecret will be called, so they can be used
|
|
|
|
* inmediately. This allows for full synchronous use. If set to false,
|
|
|
|
* these will initially only be available as Promises in getArmor() and
|
|
|
|
* getHasSecret()
|
2018-04-23 15:18:46 +00:00
|
|
|
* @returns {Promise.<Array<GPGME_Key>>}
|
|
|
|
*
|
|
|
|
*/
|
2018-05-28 15:26:56 +00:00
|
|
|
getKeys(pattern, prepare_sync){
|
2018-05-03 12:12:10 +00:00
|
|
|
let me = this;
|
2018-05-25 09:53:24 +00:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
let msg;
|
2018-05-28 15:26:56 +00:00
|
|
|
msg = createMessage('keylist');
|
2018-05-25 09:53:24 +00:00
|
|
|
if (pattern && typeof(pattern) === 'string'){
|
2018-05-28 15:26:56 +00:00
|
|
|
msg.setParameter('keys', pattern);
|
2018-04-23 15:18:46 +00:00
|
|
|
}
|
2018-05-28 15:26:56 +00:00
|
|
|
msg.setParameter('sigs', true); //TODO do we need this?
|
2018-05-28 14:52:50 +00:00
|
|
|
msg.post().then(function(result){
|
2018-05-25 09:53:24 +00:00
|
|
|
let resultset = [];
|
2018-05-28 15:26:56 +00:00
|
|
|
let promises = [];
|
|
|
|
// TODO check if result.key is not empty
|
|
|
|
for (let i=0; i< result.keys.length; i++){
|
|
|
|
let k = createKey(result.keys[i].fingerprint, me);
|
|
|
|
k.setKeyData(result.keys[i]);
|
|
|
|
if (prepare_sync === true){
|
|
|
|
promises.push(k.getArmor());
|
|
|
|
promises.push(k.getHasSecret());
|
2018-05-25 09:53:24 +00:00
|
|
|
}
|
2018-05-28 15:26:56 +00:00
|
|
|
resultset.push(k);
|
|
|
|
}
|
|
|
|
if (promises.length > 0) {
|
|
|
|
Promise.all(promises).then(function (res){
|
|
|
|
resolve(resultset);
|
|
|
|
}, function(error){
|
|
|
|
reject(error);
|
|
|
|
});
|
2018-05-25 09:53:24 +00:00
|
|
|
}
|
|
|
|
}, function(error){
|
|
|
|
reject(error);
|
|
|
|
});
|
2018-04-23 15:18:46 +00:00
|
|
|
});
|
|
|
|
}
|
2018-05-28 15:26:56 +00:00
|
|
|
// TODO:
|
|
|
|
// deleteKey(key, include_secret=false)
|
|
|
|
// getKeysArmored(pattern) //just dump all armored keys
|
|
|
|
// getDefaultKey() Big TODO
|
|
|
|
// importKeys(armoredKeys)
|
2018-04-23 15:18:46 +00:00
|
|
|
|
|
|
|
};
|