diff options
Diffstat (limited to 'lang/js/DemoExtension')
-rw-r--r-- | lang/js/DemoExtension/Makefile.am | 27 | ||||
-rw-r--r-- | lang/js/DemoExtension/entry.js | 30 | ||||
-rw-r--r-- | lang/js/DemoExtension/maindemo.js | 119 | ||||
-rw-r--r-- | lang/js/DemoExtension/mainui.html | 47 | ||||
-rw-r--r-- | lang/js/DemoExtension/manifest.json | 14 | ||||
-rw-r--r-- | lang/js/DemoExtension/popup.html | 9 | ||||
-rw-r--r-- | lang/js/DemoExtension/testicon.png | bin | 0 -> 2670 bytes | |||
-rw-r--r-- | lang/js/DemoExtension/ui.css | 33 |
8 files changed, 279 insertions, 0 deletions
diff --git a/lang/js/DemoExtension/Makefile.am b/lang/js/DemoExtension/Makefile.am new file mode 100644 index 00000000..d6e87fde --- /dev/null +++ b/lang/js/DemoExtension/Makefile.am @@ -0,0 +1,27 @@ +# Makefile.am for gpgme.js. +# Copyright (C) 2018 Intevation GmbH +# +# This file is part of gpgme.js. +# +# gpgme.js is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# gpgme.js is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA + +EXTRA_DIST = manifest.json \ + popup.html \ + entry.js \ + maindemo.js \ + mainui.html \ + testicon.png \ + ui.css diff --git a/lang/js/DemoExtension/entry.js b/lang/js/DemoExtension/entry.js new file mode 100644 index 00000000..fd261a0b --- /dev/null +++ b/lang/js/DemoExtension/entry.js @@ -0,0 +1,30 @@ +/* gpgme.js - Javascript integration for gpgme + * Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see <http://www.gnu.org/licenses/>. + * SPDX-License-Identifier: LGPL-2.1+ + * + * Author(s): + * Maximilian Krambach <[email protected]> + */ + +/* global chrome */ + +document.addEventListener('DOMContentLoaded', function () { + chrome.tabs.create({ + url: './mainui.html' + }); +}); diff --git a/lang/js/DemoExtension/maindemo.js b/lang/js/DemoExtension/maindemo.js new file mode 100644 index 00000000..8d190852 --- /dev/null +++ b/lang/js/DemoExtension/maindemo.js @@ -0,0 +1,119 @@ +/* gpgme.js - Javascript integration for gpgme + * Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik + * + * This file is part of GPGME. + * + * GPGME is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * GPGME is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see <http://www.gnu.org/licenses/>. + * SPDX-License-Identifier: LGPL-2.1+ + * + * Author(s): + * Maximilian Krambach <[email protected]> + */ + +/* global document, Gpgmejs */ + +document.addEventListener('DOMContentLoaded', function () { + Gpgmejs.init().then(function (gpgmejs){ + document.getElementById('buttonencrypt').addEventListener('click', + function (){ + let data = document.getElementById('inputtext').value; + let keyId = document.getElementById('pubkey').value; + gpgmejs.encrypt(data, keyId).then( + function (answer){ + if (answer.data){ + document.getElementById( + 'answer').value = answer.data; + } + }, function (errormsg){ + alert( errormsg.message); + }); + }); + + document.getElementById('buttondecrypt').addEventListener('click', + function (){ + let data = document.getElementById('inputtext').value; + gpgmejs.decrypt(data).then( + function (answer){ + if (answer.data){ + document.getElementById( + 'answer').value = answer.data; + } + }, function (errormsg){ + alert(errormsg.message); + }); + }); + + document.getElementById('getdefaultkey').addEventListener('click', + function (){ + gpgmejs.Keyring.getDefaultKey().then(function (answer){ + 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); + }); + }); + document.getElementById('searchkey').addEventListener('click', + function (){ + let data = document.getElementById('inputtext').value; + gpgmejs.Keyring.getKeys(data, true, true).then(function (keys){ + if (keys.length === 1){ + document.getElementById( + 'pubkey').value = keys[0].fingerprint; + } else if (keys.length > 1) { + alert('The pattern was not unambigious enough for a Key. ' + + keys.length + ' Keys were found'); + } else { + alert('No keys found'); + } + }, function (errormsg){ + alert( errormsg.message); + }); + }); + }); +}); diff --git a/lang/js/DemoExtension/mainui.html b/lang/js/DemoExtension/mainui.html new file mode 100644 index 00000000..c773c9b9 --- /dev/null +++ b/lang/js/DemoExtension/mainui.html @@ -0,0 +1,47 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <link rel="stylesheet" href="ui.css"/> + <script src="libs/gpgmejs.bundle.js"></script> + <script src="maindemo.js"></script> + </head> + <body> + <div> + + <div class="left"> + <ul> + <li> + <span class="label">Input</span> + <textarea rows="5" cols="65" id="inputtext" wrap="hard"></textarea> + </li> + <li> + <span class="label">Fingerprint of Key to use: </span> + <input type="text" id="pubkey" value="" /> + <button id="getdefaultkey"> + Set to default signing key + </button> + <button id="searchkey"> + Look up Key + </button> + </li> + </ul> + </div> + <div class="right"> + <ul> + <li> + <span class="label">Result</span> + <textarea id="answer" rows="5" cols="65" wrap="hard"></textarea> + </li> + </ul> + </div> + </div> + <div class="center"> + <button id="buttonencrypt">Encrypt input text</button><br> + <button id="buttondecrypt">Decrypt input text</button><br> + <button id="signtext">Sign input text</button> <br> + <button id="verifytext">Verify input text</button><br> + + </div> +</body> +</html> diff --git a/lang/js/DemoExtension/manifest.json b/lang/js/DemoExtension/manifest.json new file mode 100644 index 00000000..9e057b35 --- /dev/null +++ b/lang/js/DemoExtension/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + + "name": "gpgme-json with native Messaging", + "description": "A simple demo application", + "version": "0.1", + "content_security_policy": "default-src 'self' filesystem:", + "browser_action": { + "default_icon": "testicon.png", + "default_title": "gpgme.js", + "default_popup": "popup.html" + }, + "permissions": ["nativeMessaging", "activeTab"] +} diff --git a/lang/js/DemoExtension/popup.html b/lang/js/DemoExtension/popup.html new file mode 100644 index 00000000..50070311 --- /dev/null +++ b/lang/js/DemoExtension/popup.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <script src="entry.js"></script> + </head> + <body> + </body> +</html>
\ No newline at end of file diff --git a/lang/js/DemoExtension/testicon.png b/lang/js/DemoExtension/testicon.png Binary files differnew file mode 100644 index 00000000..84284e0b --- /dev/null +++ b/lang/js/DemoExtension/testicon.png diff --git a/lang/js/DemoExtension/ui.css b/lang/js/DemoExtension/ui.css new file mode 100644 index 00000000..16dfb5ae --- /dev/null +++ b/lang/js/DemoExtension/ui.css @@ -0,0 +1,33 @@ +ul { + list-style-type: none; + padding-left: 0px; +} + +ul li span { + float: left; + 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 |