Skip to content

Commit

Permalink
Origin matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lomilar committed Sep 23, 2024
1 parent 56a7181 commit 3a566b3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/com/eduworks/ec/crypto/EcAesCtrAsyncWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ module.exports = class EcAesCtrAsyncWorker {
o["iv"] = iv;
o["text"] = forge.util.encodeUtf8(plaintext);
o["cmd"] = "encryptAesCtr";
return EcRsaOaepAsyncWorker.w[worker].postMessage(o,'cassproject');
o["origin"] = "cassproject";
return EcRsaOaepAsyncWorker.w[worker].postMessage(o, 'cassproject');
}
/**
* Asynchronous form of {{#crossLink
Expand Down Expand Up @@ -82,6 +83,7 @@ module.exports = class EcAesCtrAsyncWorker {
o["iv"] = iv;
o["text"] = ciphertext;
o["cmd"] = "decryptAesCtr";
o["origin"] = "cassproject";
let p = EcRsaOaepAsyncWorker.w[worker].postMessage(o,'cassproject');
p = p.then((decrypted) => {
return forge.util.decodeUtf8(decrypted);
Expand Down
6 changes: 6 additions & 0 deletions src/com/eduworks/ec/crypto/EcRsaOaepAsyncWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module.exports = class EcRsaOaepAsyncWorker {
o["pk"] = pk.toPem();
o["text"] = plaintext;
o["cmd"] = "encryptRsaOaep";
o["origin"] = "cassproject";

let p = this.w[worker].postMessage(o, 'cassproject');
return cassPromisify(p, success, failure);
Expand Down Expand Up @@ -144,6 +145,7 @@ module.exports = class EcRsaOaepAsyncWorker {
o["ppk"] = ppk.toPem();
o["text"] = ciphertext;
o["cmd"] = "decryptRsaOaep";
o["origin"] = "cassproject";
let p = this.w[worker].postMessage(o, 'cassproject');
p = p.then(function (decrypted) {
return forge.util.decodeUtf8(decrypted);
Expand Down Expand Up @@ -184,6 +186,7 @@ module.exports = class EcRsaOaepAsyncWorker {
o["ppk"] = ppk.toPem();
o["text"] = forge.util.encodeUtf8(text);
o["cmd"] = "signRsaOaep";
o["origin"] = "cassproject";
let p = this.w[worker].postMessage(o, 'cassproject');
return cassPromisify(p, success, failure);
}
Expand Down Expand Up @@ -215,6 +218,7 @@ module.exports = class EcRsaOaepAsyncWorker {
o["ppk"] = ppk.toPem();
o["text"] = forge.util.encodeUtf8(text);
o["cmd"] = "signSha256RsaOaep";
o["origin"] = "cassproject";
let p = this.w[worker].postMessage(o,'cassproject');
return cassPromisify(p, success, failure);
};
Expand Down Expand Up @@ -247,6 +251,7 @@ module.exports = class EcRsaOaepAsyncWorker {
o["text"] = forge.util.encodeUtf8(text);
o["signature"] = signature;
o["cmd"] = "verifyRsaOaep";
o["origin"] = "cassproject";
let p = this.w[worker].postMessage(o, 'cassproject');
return cassPromisify(p, success, failure);
}
Expand Down Expand Up @@ -279,6 +284,7 @@ module.exports = class EcRsaOaepAsyncWorker {
o["text"] = forge.util.encodeUtf8(text);
o["signature"] = signature;
o["cmd"] = "verifyRsaOaepSha256";
o["origin"] = "cassproject";
let p = this.w[worker].postMessage(o, 'cassproject');
return cassPromisify(p, success, failure);
}
Expand Down
7 changes: 2 additions & 5 deletions src/com/eduworks/ec/crypto/forgeAsync.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions src/com/eduworks/ec/crypto/forgeAsyncNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function registerPromiseWorker(callback) {
}

function onIncomingMessage(e) {
if (e.origin != 'cassproject') return;
if (e.origin != 'cassproject' && e.data?.origin != 'cassproject' && e.data?.[1]?.origin != 'cassproject') { console.log("Origin does not match.", e.origin);return;}

var payload = e.data
if (!Array.isArray(payload) || payload.length !== 2) {
Expand Down Expand Up @@ -108,7 +108,4 @@ registerPromiseWorker(function (e) {
error: ex.message
};
}
});

self.addEventListener('message', function (e) {
}, false);
});

0 comments on commit 3a566b3

Please sign in to comment.