js: adding sign method
authorMaximilian Krambach <maximilian.krambach@intevation.de>
Thu, 24 May 2018 13:16:18 +0000 (15:16 +0200)
committerMaximilian Krambach <maximilian.krambach@intevation.de>
Thu, 24 May 2018 13:16:18 +0000 (15:16 +0200)
--

  * src/gpgmejs.js: method, update in src/permittedOperations
  * basic testing in BrowsertestExtension

lang/js/BrowserTestExtension/browsertest.html
lang/js/src/gpgmejs.js
lang/js/src/permittedOperations.js

index c379ef5..3d81a9e 100644 (file)
@@ -17,6 +17,7 @@
     <script src="tests/startup.js"></script>
     <script src="tests/encryptTest.js"></script>
     <script src="tests/encryptDecryptTest.js"></script>
+    <script src="tests/signTest.js"></script>
 <!-- run tests -->
     <script src="runbrowsertest.js"></script>
     </body>
index 3aa5957..1e76655 100644 (file)
@@ -120,6 +120,44 @@ export class GpgME {
 
     }
 
+    sign(data, keys, mode='clearsign', base64=false) { //sender
+        if (data === undefined){
+            return Promise.reject(gpgme_error('MSG_EMPTY'));
+        }
+        let key_arr = toKeyIdArray(keys);
+        if (key_arr.length === 0){
+            return Promise.reject(gpgme_error('MSG_NO_KEYS'));
+        }
+        let msg = createMessage('sign');
+
+        msg.setParameter('keys', key_arr);
+        if (base64 === true){
+            msg.setParameter('base64', true);
+        }
+        msg.setParameter('mode', mode);
+        putData(msg, data);
+        if (mode === 'detached') {
+            msg.expected = 'base64';
+        }
+        let me = this;
+        return new Promise(function(resolve,reject) {
+            me.connection.post(msg).then( function(message) {
+                if (mode === 'clearsign'){
+                    resolve({
+                        data: message.data}
+                    );
+                } else if (mode === 'detached') {
+                    resolve({
+                        data: data,
+                        signature: message.data
+                    });
+                }
+            }, function(error){
+                reject(error);
+            })
+        });
+    }
+
     deleteKey(key, delete_secret = false, no_confirm = false){
         return Promise.reject(gpgme_error('NOT_YET_IMPLEMENTED'));
         let msg = createMessage('deletekey');
index da46a1f..aa02a8b 100644 (file)
@@ -130,6 +130,49 @@ export const permittedOperations = {
                         // }]
         }
     },
+
+    sign: {
+        pinentry: true,
+        required: {
+            'data': {
+                allowed: ['string']},
+            'keys': {
+                allowed: ['string'],
+                array_allowed: true
+            }
+        },
+        optional: {
+            'protocol': {
+                allowed: ['string'],
+                allowed_data: ['cms', 'openpgp']
+            },
+            'chunksize': {
+                allowed: ['number'],
+            },
+            'sender': {
+                allowed: ['string'],
+            },
+            'mode': {
+                allowed: ['string'],
+                allowed_data: ['detached', 'clearsign'] // TODO 'opaque' not used
+            },
+            'base64': {
+                allowed: ['boolean']
+            },
+            'armor': {
+                allowed: ['boolean']
+            },
+        },
+        answer: {
+            type: ['signature', 'ciphertext'],
+            data: ['data'], // Unless armor mode is used a Base64 encoded binary
+                            // signature.  In armor mode a string with an armored
+                            // OpenPGP or a PEM message.
+            params: ['base64']
+        }
+    },
+
+
     /** TBD: querying the Key's information (keyinfo)
     TBD name: {
         required: {
@@ -212,6 +255,5 @@ export const permittedOperations = {
      *TBD get armored secret different treatment from keyinfo!
      * TBD key modification?
      * encryptsign: TBD
-     * verify: TBD
      */
 }