Compare commits

...

4 Commits

Author SHA1 Message Date
CPlusSharp ffa03b0e0c
Merge 9f7a75536e into bbebba6481 2024-04-25 19:25:43 +01:00
n1474335 bbebba6481
Added pause after setting complex input to avoid race conditions 2024-04-25 18:10:59 +01:00
n1474335 f0a49fefa4
Extended time for autoBake to trigger in a test 2024-04-25 17:51:31 +01:00
CPlusSharp 9f7a75536e Output generated RSA keys as JSON Web Key 2024-04-14 18:48:19 +02:00
3 changed files with 42 additions and 10 deletions

View File

@ -7,6 +7,8 @@
import Operation from "../Operation.mjs";
import forge from "node-forge";
import { toBase64 } from "../lib/Base64.mjs";
import { fromHex } from "../lib/Hex.mjs";
import { cryptNotice } from "../lib/Crypt.mjs";
/**
@ -41,6 +43,7 @@ class GenerateRSAKeyPair extends Operation {
type: "option",
value: [
"PEM",
"JWK",
"JSON",
"DER"
]
@ -70,6 +73,38 @@ class GenerateRSAKeyPair extends Operation {
case "PEM":
result = forge.pki.publicKeyToPem(keypair.publicKey) + "\n" + forge.pki.privateKeyToPem(keypair.privateKey);
break;
case "JWK": {
const base64urlUInt = function (bigInt) {
let hex = bigInt.toString(16);
// prepend 0 if not even
if (hex.length % 2 === 1) {
hex = "0" + hex;
}
return toBase64(fromHex(hex), "A-Za-z0-9-_");
};
const pubKey = {
kty: "RSA",
kid: "PublicKey",
key_ops: ["verify", "encrypt"], // eslint-disable-line camelcase
n: base64urlUInt(keypair.publicKey.n),
e: base64urlUInt(keypair.publicKey.e)
};
const privKey = {
kty: "RSA",
kid: "PrivateKey",
key_ops: ["sign", "decrypt"], // eslint-disable-line camelcase
n: base64urlUInt(keypair.privateKey.n),
e: base64urlUInt(keypair.privateKey.e),
d: base64urlUInt(keypair.privateKey.d),
p: base64urlUInt(keypair.privateKey.p),
q: base64urlUInt(keypair.privateKey.q),
dp: base64urlUInt(keypair.privateKey.dP),
dq: base64urlUInt(keypair.privateKey.dQ),
qi: base64urlUInt(keypair.privateKey.qInv)
};
result = JSON.stringify({keys: [privKey, pubKey]}, null, 4);
break;
}
case "JSON":
result = JSON.stringify(keypair);
break;

View File

@ -173,25 +173,20 @@ module.exports = {
browser.waitForElementVisible("#stale-indicator");
browser.expect.element("#auto-bake").to.not.be.selected;
// Enable previously disabled autobake
browser.expect.element("#auto-bake").to.not.be.selected;
browser.click("#auto-bake-label");
browser.expect.element("#auto-bake").to.be.selected.before(1000);
browser.waitUntil(() => {
return browser.expect.element("#auto-bake").to.be.selected;
}, 1000);
// Add content to the input
browser.pause(100);
browser.sendKeys("#input-text .cm-content", "1");
browser.waitForElementVisible("#output-loader");
browser.pause(500);
// Make another change while the previous input is being baked
browser.sendKeys("#input-text .cm-content", "2");
browser
.sendKeys("#input-text .cm-content", "2")
.waitForElementNotVisible("#stale-indicator")
.waitForElementNotVisible("#output-loader");
@ -200,6 +195,7 @@ module.exports = {
// Turn autobake off again
browser.click("#auto-bake-label");
browser.expect.element("#auto-bake").to.not.be.selected.before(1000);
},
"Special content": browser => {

View File

@ -39,6 +39,7 @@ function setInput(browser, input, type=true) {
browser.execute(text => {
window.app.setInput(text);
}, [input]);
browser.pause(100);
}
}