aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src
diff options
context:
space:
mode:
Diffstat (limited to 'lang/js/src')
-rw-r--r--lang/js/src/Errors.js5
-rw-r--r--lang/js/src/Key.js8
-rw-r--r--lang/js/src/Keyring.js56
-rw-r--r--lang/js/src/permittedOperations.js54
4 files changed, 121 insertions, 2 deletions
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',
diff --git a/lang/js/src/Key.js b/lang/js/src/Key.js
index 5986254e..3e4f1c78 100644
--- a/lang/js/src/Key.js
+++ b/lang/js/src/Key.js
@@ -192,6 +192,7 @@ export class GPGME_Key {
* Query the armored block of the non- secret parts of the Key directly
* from gpg.
* @returns {Promise<String>}
+ * @async
*/
getArmor(){
let me = this;
@@ -211,6 +212,13 @@ export class GPGME_Key {
});
}
+ /**
+ * Find out if the Key includes a secret part
+ * @returns {Promise<Boolean>}
+ *
+ * @async
+ */
+ // TODO: Does not work yet, result is always false
getHasSecret(){
let me = this;
return new Promise(function(resolve, reject) {
diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js
index 0d4e3c52..e07a5934 100644
--- a/lang/js/src/Keyring.js
+++ b/lang/js/src/Keyring.js
@@ -99,7 +99,61 @@ export class GPGME_Keyring {
});
}
- // getDefaultKey() Big TODO
+ /**
+ * Returns the Key to be used by default for signing operations,
+ * looking up the gpg configuration, or returning the first key that
+ * contains a secret key.
+ * @returns {Promise<GPGME_Key>}
+ *
+ * @async
+ * TODO: getHasSecret always returns false at this moment, so this fucntion
+ * still does not fully work as intended.
+ *
+ */
+ getDefaultKey() {
+ let me = this;
+ return new Promise(function(resolve, reject){
+ let msg = createMessage('config_opt');
+ msg.setParameter('component', 'gpg');
+ msg.setParameter('option', 'default-key');
+ msg.post().then(function(response){
+ if (response.value !== undefined
+ && response.value.hasOwnProperty('string')
+ && typeof(response.value.string) === 'string'
+ ){
+ me.getKeys(response.value.string,true).then(function(keys){
+ if(keys.length === 1){
+ resolve(keys[0]);
+ } else {
+ reject(gpgme_error('KEY_NO_DEFAULT'));
+ }
+ }, function(error){
+ reject(error);
+ });
+ } else {
+ // TODO: this is overly 'expensive' in communication
+ // and probably performance, too
+ me.getKeys(null,true).then(function(keys){
+ for (let i=0; i < keys.length; i++){
+ console.log(keys[i]);
+ console.log(keys[i].get('hasSecret'));
+ if (keys[i].get('hasSecret') === true){
+ resolve(keys[i]);
+ break;
+ }
+ if (i === keys.length -1){
+ reject(gpgme_error('KEY_NO_DEFAULT'));
+ }
+ }
+ }, function(error){
+ reject(error);
+ });
+ }
+ }, function(error){
+ reject(error);
+ });
+ });
+ }
/**
*
diff --git a/lang/js/src/permittedOperations.js b/lang/js/src/permittedOperations.js
index 91612ada..044ae4af 100644
--- a/lang/js/src/permittedOperations.js
+++ b/lang/js/src/permittedOperations.js
@@ -314,7 +314,7 @@ export const permittedOperations = {
},
createkey: {
- pinentry: true,
+ pinentry: true,
required: {
userid: {
allowed: ['string']
@@ -332,7 +332,59 @@ export const permittedOperations = {
type: [''],
data: {'fingerprint': 'string'}
}
+ },
+
+ verify: {
+ required: {
+ data: {
+ allowed: ['string']
+ }
+ },
+ optional: {
+ 'protocol': {
+ allowed: ['string'],
+ allowed_data: ['cms', 'openpgp']
+ },
+ 'signature': {
+ allowed: ['string']
+ },
+ 'base64':{
+ allowed: ['boolean']
+ }
+ },
+ answer: {
+ type: ['plaintext'],
+ data:{
+ data: 'string',
+ base64:'boolean',
+ info: 'object'
+ // file_name: Optional string of the plaintext file name.
+ // is_mime: Boolean if the messages claims it is MIME.
+ // signatures: Array of signatures
+ }
+ }
+ },
+
+ config_opt: {
+ required: {
+ 'component':{
+ allowed: ['string'],
+ // allowed_data: ['gpg'] // TODO check all available
+ },
+ 'option': {
+ allowed: ['string'],
+ // allowed_data: ['default-key'] // TODO check all available
+ }
+ },
+ optional: {},
+ answer: {
+ type: [],
+ data: {
+ option: 'object'
+ }
+ }
}
+
/**
* TBD handling of secrets
* TBD key modification?