From 9bd560a05a3bbd7db62133580e55725fa8065a2a Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 11 Jan 2020 20:22:55 +0100 Subject: [PATCH] Use JS cryptocore Signed-off-by: Knut Ahlers --- .eslintrc.js | 3 +++ package-lock.json | 10 ++++++++++ package.json | 2 ++ src/js_cryptocore.js | 18 ++++++++++++++++++ src/main.js | 9 ++++++--- 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/js_cryptocore.js diff --git a/.eslintrc.js b/.eslintrc.js index a3e227d..d3e4016 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,7 +21,10 @@ module.exports = { plugins: ['vue'], globals: { Go: true, + opensslDecrypt: true, + opensslEncrypt: true, process: true, + sha256sum: true, }, // add your custom rules here rules: { diff --git a/package-lock.json b/package-lock.json index aa91035..355d4e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6992,6 +6992,11 @@ "assert-plus": "^1.0.0" } }, + "gibberish-aes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/gibberish-aes/-/gibberish-aes-1.0.0.tgz", + "integrity": "sha1-9kHEWPuCLgrWHDwN6hWOC5Q+n8U=" + }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", @@ -11905,6 +11910,11 @@ "safe-buffer": "^5.0.1" } }, + "sha2": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/sha2/-/sha2-1.0.2.tgz", + "integrity": "sha512-sQ1sFn+WN2weGkwwt25bllwocaJLyYeDrn/T221Bovc6XEHRf7NSn0KPoPQMV2+NT+RhJoStkdm4TrEGCXkKHA==" + }, "shallow-clone": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", diff --git a/package.json b/package.json index 40821e1..1b74b16 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,8 @@ "axios": "^0.18.1", "bootstrap-vue": "^2.2.0", "bootswatch": "^4.4.1", + "gibberish-aes": "^1.0.0", + "sha2": "^1.0.2", "uuid": "^3.3.3", "vue": "^2.6.11", "vue-clipboard2": "^0.2.1", diff --git a/src/js_cryptocore.js b/src/js_cryptocore.js new file mode 100644 index 0000000..339a177 --- /dev/null +++ b/src/js_cryptocore.js @@ -0,0 +1,18 @@ +import GibberishAES from 'gibberish-aes/src/gibberish-aes.js' +import { SHA256 } from 'sha2' + +const opensslDecrypt = (plaintext, password, callback) => { + callback(GibberishAES.enc(plaintext, password), null) +} + +const opensslEncrypt = (ciphertext, password, callback) => { + callback(GibberishAES.dec(ciphertext, password), null) +} + +const sha256sum = (plaintext, callback) => { + callback(SHA256(plaintext).toString('hex')) +} + +window.opensslDecrypt = opensslDecrypt +window.opensslEncrypt = opensslEncrypt +window.sha256sum = sha256sum diff --git a/src/main.js b/src/main.js index c5ade18..d2a6afc 100644 --- a/src/main.js +++ b/src/main.js @@ -35,9 +35,12 @@ Vue.component('fa-icon', FontAwesomeIcon) axios.defaults.baseURL = 'v2' -const go = new Go() -WebAssembly.instantiateStreaming(fetch('cryptocore.wasm'), go.importObject) - .then(async obj => await go.run(obj.instance)) +/* + * const go = new Go() + * WebAssembly.instantiateStreaming(fetch('cryptocore.wasm'), go.importObject) + * .then(async obj => await go.run(obj.instance)) + */ +import './js_cryptocore.js' // JS alternative window.instance = new Vue({ mounted: () => store.dispatch('reload_users'),