From 88e7f8ec2ef3d90ca014b0bdb246f4d99f82abc8 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 20 Jun 2018 13:42:19 +0200 Subject: [PATCH] js: Demoextension update -- * src/Signature: typo * src/gpgmejs.js: fixed wrong scope in verification * right now verify does not succeed in the DemoExtension. This is probably a problem in conversion or line ending. --- lang/js/DemoExtension/maindemo.js | 41 ++++++++++++++++++-- lang/js/DemoExtension/mainui.html | 63 +++++++++++++++---------------- lang/js/DemoExtension/ui.css | 23 +++++++++++ lang/js/src/Signature.js | 6 ++- lang/js/src/gpgmejs.js | 6 +-- 5 files changed, 99 insertions(+), 40 deletions(-) diff --git a/lang/js/DemoExtension/maindemo.js b/lang/js/DemoExtension/maindemo.js index 6230c3f0..d0127c73 100644 --- a/lang/js/DemoExtension/maindemo.js +++ b/lang/js/DemoExtension/maindemo.js @@ -27,7 +27,7 @@ document.addEventListener('DOMContentLoaded', function() { Gpgmejs.init().then(function(gpgmejs){ document.getElementById('buttonencrypt').addEventListener('click', function(){ - let data = document.getElementById('cleartext').value; + let data = document.getElementById('inputtext').value; let keyId = document.getElementById('pubkey').value; gpgmejs.encrypt(data, keyId).then( function(answer){ @@ -42,7 +42,7 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('buttondecrypt').addEventListener('click', function(){ - let data = document.getElementById('ciphertext').value; + let data = document.getElementById('inputtext').value; gpgmejs.decrypt(data).then( function(answer){ if (answer.data){ @@ -57,11 +57,46 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('getdefaultkey').addEventListener('click', function(){ gpgmejs.Keyring.getDefaultKey().then(function(answer){ - document.getElementById('defaultkey').textContent = + document.getElementById('pubkey').value = answer.fingerprint; }, function(errormsg){ alert(errormsg.message); }); }); + + document.getElementById('signtext').addEventListener('click', + function(){ + let data = document.getElementById('inputtext').value; + let keyId = document.getElementById('pubkey').value; + gpgmejs.sign(data, keyId).then( + function(answer){ + if (answer.data){ + document.getElementById( + 'answer').value = answer.data; + } + }, function(errormsg){ + alert( errormsg.message); + }); + }); + + document.getElementById('verifytext').addEventListener('click', + function(){ + let data = document.getElementById('inputtext').value; + gpgmejs.verify(data).then( + function(answer){ + let vals = ''; + if (answer.all_valid === true){ + vals = 'Success! '; + } else { + vals = 'Failure! '; + } + vals = vals + (answer.count - answer.failures) + 'of ' + + answer.count + ' signature(s) were successfully ' + + 'verified.\n\n' + answer.data; + document.getElementById('answer').value = vals; + }, function(errormsg){ + alert( errormsg.message); + }); + }); }); }); diff --git a/lang/js/DemoExtension/mainui.html b/lang/js/DemoExtension/mainui.html index 91be7bbc..b6390363 100644 --- a/lang/js/DemoExtension/mainui.html +++ b/lang/js/DemoExtension/mainui.html @@ -7,38 +7,37 @@ - -
-
- -
-
-

Result data:

- +
-
-
+
+
+
+
+
- - - +
+ diff --git a/lang/js/DemoExtension/ui.css b/lang/js/DemoExtension/ui.css index 9c88698b..16dfb5ae 100644 --- a/lang/js/DemoExtension/ui.css +++ b/lang/js/DemoExtension/ui.css @@ -8,3 +8,26 @@ ul li span { width: 120px; margin-top: 6px; } + +div .left { + float: left; + align-items: stretch; + width: 40%; +} +div .center { + width: 50%; + align-content: space-between; +} + +div .center button { + align-self: stretch; +} +div .right { + float: right; + align-items: stretch; + width: 40%; +} + +div .bottom { + clear:both; +} \ No newline at end of file diff --git a/lang/js/src/Signature.js b/lang/js/src/Signature.js index d7d05983..a07fc4d1 100644 --- a/lang/js/src/Signature.js +++ b/lang/js/src/Signature.js @@ -35,7 +35,7 @@ export function createSignature(sigObject){ if ( typeof(sigObject) !=='object' || !sigObject.hasOwnProperty('summary') || - !sigObject.hasOwnProperty('fingerpprint') || + !sigObject.hasOwnProperty('fingerprint') || !sigObject.hasOwnProperty('timestamp') //TODO check if timestamp is mandatory in specification ){ @@ -67,6 +67,7 @@ export function createSignature(sigObject){ } } } + console.log('sig created'); return new GPGME_Signature(sigObject); } @@ -178,7 +179,8 @@ const expSum = { 'crl-missing': 'boolean', 'crl-too-old': 'boolean', 'bad-policy': 'boolean', - 'sys-error': 'boolean' + 'sys-error': 'boolean', + 'sigsum': 'object' }; /** diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js index a0f7e968..c2a6b8b6 100644 --- a/lang/js/src/gpgmejs.js +++ b/lang/js/src/gpgmejs.js @@ -168,7 +168,7 @@ export class GpgME { /** * Sign a Message - * @param {String|Object} data text/data to be decrypted. Accepts Strings + * @param {String|Object} data text/data to be signed. Accepts Strings * and Objects with a gettext methos * @param {GPGME_Key|String|Array|Array} keys The * key/keys to use for signing @@ -238,7 +238,7 @@ export class GpgME { */ verify(data, signature, base64 = false){ let msg = createMessage('verify'); - let dt = this.putData(msg, data); + let dt = putData(msg, data); if (dt instanceof Error){ return Promise.reject(dt); } @@ -317,7 +317,7 @@ function collectSignatures(sigs){ for (let i=0; i< sigs.length; i++){ let sigObj = createSignature(sigs[i]); if (sigObj instanceof Error){ - return gpgme_error('SIG_WRONG'); + return gpgme_error(sigObj); } if (sigObj.valid !== true){ summary.failures += 1;