From 400c4eac86a193945f43db9d502a3b9e537f79f3 Mon Sep 17 00:00:00 2001 From: Fritz Ray Date: Mon, 23 Sep 2024 08:13:25 -0700 Subject: [PATCH] Fixing javascript:S2819 --- src/com/eduworks/ec/crypto/EcAesCtrAsyncWorker.js | 4 ++-- src/com/eduworks/ec/crypto/EcRsaOaepAsyncWorker.js | 12 ++++++------ src/com/eduworks/ec/crypto/forgeAsync.js | 4 +++- src/com/eduworks/ec/crypto/forgeAsyncNode.js | 2 ++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/com/eduworks/ec/crypto/EcAesCtrAsyncWorker.js b/src/com/eduworks/ec/crypto/EcAesCtrAsyncWorker.js index 57aded27..c44ec281 100644 --- a/src/com/eduworks/ec/crypto/EcAesCtrAsyncWorker.js +++ b/src/com/eduworks/ec/crypto/EcAesCtrAsyncWorker.js @@ -44,7 +44,7 @@ module.exports = class EcAesCtrAsyncWorker { o["iv"] = iv; o["text"] = forge.util.encodeUtf8(plaintext); o["cmd"] = "encryptAesCtr"; - return EcRsaOaepAsyncWorker.w[worker].postMessage(o); + return EcRsaOaepAsyncWorker.w[worker].postMessage(o,'cassproject'); } /** * Asynchronous form of {{#crossLink @@ -83,7 +83,7 @@ module.exports = class EcAesCtrAsyncWorker { o["iv"] = iv; o["text"] = ciphertext; o["cmd"] = "decryptAesCtr"; - let p = EcRsaOaepAsyncWorker.w[worker].postMessage(o); + let p = EcRsaOaepAsyncWorker.w[worker].postMessage(o,'cassproject'); p = p.then((decrypted) => { return forge.util.decodeUtf8(decrypted); }); diff --git a/src/com/eduworks/ec/crypto/EcRsaOaepAsyncWorker.js b/src/com/eduworks/ec/crypto/EcRsaOaepAsyncWorker.js index 5168de11..f038cdf3 100644 --- a/src/com/eduworks/ec/crypto/EcRsaOaepAsyncWorker.js +++ b/src/com/eduworks/ec/crypto/EcRsaOaepAsyncWorker.js @@ -106,7 +106,7 @@ module.exports = class EcRsaOaepAsyncWorker { o["text"] = plaintext; o["cmd"] = "encryptRsaOaep"; - let p = this.w[worker].postMessage(o); + let p = this.w[worker].postMessage(o, 'cassproject'); return cassPromisify(p, success, failure); } /** @@ -144,7 +144,7 @@ module.exports = class EcRsaOaepAsyncWorker { o["ppk"] = ppk.toPem(); o["text"] = ciphertext; o["cmd"] = "decryptRsaOaep"; - let p = this.w[worker].postMessage(o); + let p = this.w[worker].postMessage(o, 'cassproject'); p = p.then(function (decrypted) { return forge.util.decodeUtf8(decrypted); }); @@ -184,7 +184,7 @@ module.exports = class EcRsaOaepAsyncWorker { o["ppk"] = ppk.toPem(); o["text"] = forge.util.encodeUtf8(text); o["cmd"] = "signRsaOaep"; - let p = this.w[worker].postMessage(o); + let p = this.w[worker].postMessage(o, 'cassproject'); return cassPromisify(p, success, failure); } /** @@ -215,7 +215,7 @@ module.exports = class EcRsaOaepAsyncWorker { o["ppk"] = ppk.toPem(); o["text"] = forge.util.encodeUtf8(text); o["cmd"] = "signSha256RsaOaep"; - let p = this.w[worker].postMessage(o); + let p = this.w[worker].postMessage(o,'cassproject'); return cassPromisify(p, success, failure); }; /** @@ -247,7 +247,7 @@ module.exports = class EcRsaOaepAsyncWorker { o["text"] = forge.util.encodeUtf8(text); o["signature"] = signature; o["cmd"] = "verifyRsaOaep"; - let p = this.w[worker].postMessage(o); + let p = this.w[worker].postMessage(o, 'cassproject'); return cassPromisify(p, success, failure); } /** @@ -279,7 +279,7 @@ module.exports = class EcRsaOaepAsyncWorker { o["text"] = forge.util.encodeUtf8(text); o["signature"] = signature; o["cmd"] = "verifyRsaOaepSha256"; - let p = this.w[worker].postMessage(o); + let p = this.w[worker].postMessage(o, 'cassproject'); return cassPromisify(p, success, failure); } }; diff --git a/src/com/eduworks/ec/crypto/forgeAsync.js b/src/com/eduworks/ec/crypto/forgeAsync.js index 352ef93c..407884a3 100644 --- a/src/com/eduworks/ec/crypto/forgeAsync.js +++ b/src/com/eduworks/ec/crypto/forgeAsync.js @@ -71,7 +71,9 @@ function registerPromiseWorker (callback) { } } - function onIncomingMessage (e) { + function onIncomingMessage(e) { + if (e.origin != 'cassproject') return; + var payload = e.data if (!Array.isArray(payload) || payload.length !== 2) { // message doens't match communication format; ignore diff --git a/src/com/eduworks/ec/crypto/forgeAsyncNode.js b/src/com/eduworks/ec/crypto/forgeAsyncNode.js index 93b9b0c7..63fa1f1b 100644 --- a/src/com/eduworks/ec/crypto/forgeAsyncNode.js +++ b/src/com/eduworks/ec/crypto/forgeAsyncNode.js @@ -54,6 +54,8 @@ function registerPromiseWorker(callback) { } function onIncomingMessage(e) { + if (e.origin != 'cassproject') return; + var payload = e.data if (!Array.isArray(payload) || payload.length !== 2) { // message doens't match communication format; ignore