js: add Key lookup

--

* src/Keyring.js: getKeys() now has the option "search", which will
  trigger a remote lookup (as configured in gpg) for the string given
  as pattern.
* src/permittedOperations: make use of the new 'locate' option in
  keylist
* DemoExtension: Add a button for lookup, to demonstrate the
  functionality
This commit is contained in:
Maximilian Krambach 2018-07-04 12:11:35 +02:00
parent a52ec87d40
commit 1105fc87a3
4 changed files with 33 additions and 4 deletions

View File

@ -98,5 +98,22 @@ document.addEventListener('DOMContentLoaded', function() {
alert( errormsg.message); alert( errormsg.message);
}); });
}); });
document.getElementById('searchkey').addEventListener('click',
function(){
let data = document.getElementById('inputtext').value;
gpgmejs.Keyring.getKeys(data, true, true).then(function(keys){
if (keys.length === 1){
document.getElementById(
'pubkey').value = keys[0].fingerprint;
} else if (keys.length > 1) {
alert('The pattern was not unambigious enough for a Key. '
+ keys.length + ' Keys were found');
} else {
alert('No keys found');
}
}, function(errormsg){
alert( errormsg.message);
});
});
}); });
}); });

View File

@ -17,9 +17,13 @@
</li> </li>
<li> <li>
<span class="label">Fingerprint of Key to use: </span> <span class="label">Fingerprint of Key to use: </span>
</li> <input type="text" id="pubkey" value="" />
<input type="text" id="pubkey" value="" /> <br> <button id="getdefaultkey">
<button id="getdefaultkey">Set to default signing key</button> Set to default signing key
</button>&nbsp;
<button id="searchkey">
Look up Key
</button>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -39,16 +39,21 @@ export class GPGME_Keyring {
* inmediately. This allows for full synchronous use. If set to false, * inmediately. This allows for full synchronous use. If set to false,
* these will initially only be available as Promises in getArmor() and * these will initially only be available as Promises in getArmor() and
* getHasSecret() * getHasSecret()
* @param {Boolean} search (optional) retrieve the Keys from servers with
* the method(s) defined in gnupg (e.g. WKD/HKP lookup)
* @returns {Promise.<Array<GPGME_Key>>} * @returns {Promise.<Array<GPGME_Key>>}
* *
*/ */
getKeys(pattern, prepare_sync){ getKeys(pattern, prepare_sync, search){
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
let msg = createMessage('keylist'); let msg = createMessage('keylist');
if (pattern !== undefined){ if (pattern !== undefined){
msg.setParameter('keys', pattern); msg.setParameter('keys', pattern);
} }
msg.setParameter('sigs', true); msg.setParameter('sigs', true);
if (search === true){
msg.setParameter('locate', true);
}
msg.post().then(function(result){ msg.post().then(function(result){
let resultset = []; let resultset = [];
let promises = []; let promises = [];

View File

@ -188,6 +188,9 @@ export const permittedOperations = {
'local':{ 'local':{
allowed: ['boolean'] allowed: ['boolean']
}, },
'locate': {
allowed: ['boolean']
},
'sigs':{ 'sigs':{
allowed: ['boolean'] allowed: ['boolean']
}, },