[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-60-gaed402c

by Maximilian Krambach cvs at cvs.gnupg.org
Wed Jun 13 15:21:12 CEST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, javascript-binding has been updated
       via  aed402c5d572b60246f1f8e57ae269f8c91b0b7c (commit)
       via  d0fc4ded58f4a6a86c5ee0a36a3d3c669e244d0d (commit)
      from  e154554e9a48a08219649a58be0b641c561e1748 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit aed402c5d572b60246f1f8e57ae269f8c91b0b7c
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date:   Wed Jun 13 15:22:03 2018 +0200

    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

diff --git a/lang/js/CHECKLIST b/lang/js/CHECKLIST
index fe26018..2e70dff 100644
--- a/lang/js/CHECKLIST
+++ b/lang/js/CHECKLIST
@@ -13,10 +13,11 @@ receiving an answer
     [*] Key handling (import/export, modifying, status queries)
         [x] Import (not importing secret)
         [x] Export (not exporting secret)
-        [x] status queries
+        [*] status queries
+            [ ] getHasSecret
         [ ] key generation
         [ ] modification
-    [*] Configuration handling
+    [x] Configuration handling
     [ ] check for completeness
 
 Communication with other implementations
diff --git a/lang/js/DemoExtension/maindemo.js b/lang/js/DemoExtension/maindemo.js
index 5cde1ce..67b811f 100644
--- a/lang/js/DemoExtension/maindemo.js
+++ b/lang/js/DemoExtension/maindemo.js
@@ -36,7 +36,7 @@ document.addEventListener('DOMContentLoaded', function() {
                                 'answer').value = answer.data;
                         }
                     }, function(errormsg){
-                        alert( errormsg.code + ' ' + errormsg.msg);
+                        alert( errormsg.message);
                     });
             });
 
@@ -50,8 +50,18 @@ document.addEventListener('DOMContentLoaded', function() {
                                 'answer').value = answer.data;
                         }
                     }, function(errormsg){
-                        alert( errormsg.code + ' ' + errormsg.msg);
+                        alert(errormsg.message);
                     });
             });
+
+        document.getElementById('getdefaultkey').addEventListener('click',
+            function(){
+                gpgmejs.Keyring.getDefaultKey().then(function(answer){
+                    document.getElementById('defaultkey').innerHtml =
+                        answer.fingerprint;
+                }, function(errormsg){
+                    alert(errormsg.message);
+                });
+            });
     });
 });
diff --git a/lang/js/DemoExtension/mainui.html b/lang/js/DemoExtension/mainui.html
index 76b8a22..91be7bb 100644
--- a/lang/js/DemoExtension/mainui.html
+++ b/lang/js/DemoExtension/mainui.html
@@ -29,5 +29,16 @@
     <hr>
     <h3>Result data:</h3>
     <textarea id="answer" rows="5" cols="65" wrap="hard"></textarea>
+
+    <hr>
+    <ul>
+        <li>
+            <span class="label">Default Key:</span>
+            <button id="getdefaultkey">Get</button><br>
+            <span id="defaultkey"></span>
+        </li>
+
+
+    </ul>
     </body>
 </html>
diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js
index dabf6a5..73e7438 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 5986254..3e4f1c7 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 0d4e3c5..e07a593 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 91612ad..044ae4a 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?

commit d0fc4ded58f4a6a86c5ee0a36a3d3c669e244d0d
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date:   Wed Jun 13 11:49:37 2018 +0200

    js: less confusing icons for test/Demo extension
    
    --
    * The current test icon was just a generic pin. Changed that by the
      gnupg lock symbol with 'Demo'/'Tests' written on it. Original taken
      from gnupg artwork/icons/lock-wing.svg.

diff --git a/lang/js/BrowserTestExtension/testicon.png b/lang/js/BrowserTestExtension/testicon.png
index 12c3f5d..a98463d 100644
Binary files a/lang/js/BrowserTestExtension/testicon.png and b/lang/js/BrowserTestExtension/testicon.png differ
diff --git a/lang/js/DemoExtension/testicon.png b/lang/js/DemoExtension/testicon.png
index 12c3f5d..84284e0 100644
Binary files a/lang/js/DemoExtension/testicon.png and b/lang/js/DemoExtension/testicon.png differ

-----------------------------------------------------------------------

Summary of changes:
 lang/js/BrowserTestExtension/testicon.png | Bin 16192 -> 2697 bytes
 lang/js/CHECKLIST                         |   5 +--
 lang/js/DemoExtension/maindemo.js         |  14 ++++++--
 lang/js/DemoExtension/mainui.html         |  11 ++++++
 lang/js/DemoExtension/testicon.png        | Bin 16192 -> 2670 bytes
 lang/js/src/Errors.js                     |   5 +++
 lang/js/src/Key.js                        |   8 +++++
 lang/js/src/Keyring.js                    |  56 +++++++++++++++++++++++++++++-
 lang/js/src/permittedOperations.js        |  54 +++++++++++++++++++++++++++-
 9 files changed, 147 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list