[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-57-ge97e6c0

by Maximilian Krambach cvs at cvs.gnupg.org
Mon Jun 11 12:14:11 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  e97e6c06e950cfad424e120f4f3752b594214c94 (commit)
      from  c072675f3f2d734297a348c6de810148fb1424a2 (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 e97e6c06e950cfad424e120f4f3752b594214c94
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date:   Mon Jun 11 12:08:50 2018 +0200

    js: Add key creation to Keyring
    
    --
    
    * src/Keyring.js: Added method generateKey for new Keys
      Still TODO: Key length and some further testing. Automated testing
      does not work in this case, and gpgmejs will not be able to delete
      test keys again.
    * src/permittedOperations.js Added new method's definitions according
      to gpgme-json

diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js
index 7158587..0d4e3c5 100644
--- a/lang/js/src/Keyring.js
+++ b/lang/js/src/Keyring.js
@@ -197,5 +197,63 @@ export class GPGME_Keyring {
         }
     }
 
-    // generateKey
+    /**
+     * Generates a new Key pair directly in gpg, and returns a GPGME_Key
+     * representing that Key. Please note that due to security concerns, secret
+     * Keys can not be _deleted_ from inside gpgmejs.
+     *
+     * @param {String} userId The user Id, e.g. "Foo Bar <foo at bar.baz>"
+     * @param {*} algo (optional) algorithm to be used. See
+     *      {@link supportedKeyAlgos } below for supported values.
+     * @param {Number} keyLength (optional) TODO
+     * @param {Date} expires (optional) Expiration date. If not set, expiration
+     * will be set to 'never'
+     *
+     * @returns{Promise<Key>}
+     */
+    generateKey(userId, algo = 'default', keyLength, expires){
+        if (
+            typeof(userId) !== 'string' ||
+            supportedKeyAlgos.indexOf(algo) < 0 ||
+            (expires && !(expires instanceof Date))
+            // TODO keylength
+            // TODO check for completeness of algos
+        ){
+            return Promise.reject(gpgme_error('PARAM_WRONG'));
+        }
+        let me = this;
+        return new Promise(function(resolve, reject){
+            let msg = createMessage('createkey');
+            msg.setParameter('userid', userId);
+            msg.setParameter('algo', algo);
+            if (expires){
+                msg.setParameter('expires',
+                    Math.floor(expires.valueOf()/1000));
+            }
+            // TODO append keylength to algo
+            msg.post().then(function(response){
+                me.getKeys(response.fingerprint, true).then(
+                    // TODO make prepare_sync (second parameter) optional here.
+                    function(result){
+                        resolve(result);
+                    }, function(error){
+                        reject(error);
+                    });
+            }, function(error) {
+                reject(error);
+            });
+        });
+    }
 }
+
+/**
+ * A list of algorithms supported for key generation.
+ */
+const supportedKeyAlgos = [
+    'default',
+    'rsa',
+    'dsa',
+    'elg',
+    'ed25519',
+    'cv25519'
+];
\ No newline at end of file
diff --git a/lang/js/src/permittedOperations.js b/lang/js/src/permittedOperations.js
index 6ac33af..91612ad 100644
--- a/lang/js/src/permittedOperations.js
+++ b/lang/js/src/permittedOperations.js
@@ -311,12 +311,31 @@ export const permittedOperations = {
                 'info': 'object'
             }
         }
-    }
+    },
 
+    createkey: {
+	pinentry: true,
+        required: {
+            userid: {
+                allowed: ['string']
+            }
+        },
+        optional: {
+            algo: {
+                allowed: ['string']
+            },
+            expires: {
+                allowed: ['number'],
+            }
+        },
+        answer: {
+            type: [''],
+            data: {'fingerprint': 'string'}
+        }
+    }
     /**
      * TBD handling of secrets
      * TBD key modification?
-     * TBD: key generation
      */
 
 };

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

Summary of changes:
 lang/js/src/Keyring.js             | 60 +++++++++++++++++++++++++++++++++++++-
 lang/js/src/permittedOperations.js | 23 +++++++++++++--
 2 files changed, 80 insertions(+), 3 deletions(-)


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




More information about the Gnupg-commits mailing list