Skip to content

Commit

Permalink
fix(security): address CVE-2021-23358
Browse files Browse the repository at this point in the history
Fixes hyperledger-cacti#1775

Signed-off-by: zondervancalvez <[email protected]>
  • Loading branch information
zondervancalvez committed Mar 25, 2022
1 parent 8c32ea2 commit ed07b17
Showing 1 changed file with 44 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test, { Test } from "tape-promise/tape";
import HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json";
import Web3 from "web3";
import Web3EEAClient, { IPrivateTransactionReceipt } from "web3-eea";
import Web3JsQuorum, { IPrivateTransactionReceipt } from "web3js-quorum";
import { BesuMpTestLedger } from "@hyperledger/cactus-test-tooling";
import { AbiItem } from "web3-utils";
import { LogLevelDesc } from "@hyperledger/cactus-common";
Expand Down Expand Up @@ -83,31 +83,32 @@ test(testCase, async (t: Test) => {
const chainIdMember3 = await web3Member3.eth.getChainId();
t.comment(`chainIdMember3=${chainIdMember3}`);

const web3EeaMember1 = Web3EEAClient(web3Member1, chainIdMember1);
t.ok(web3EeaMember1, "web3EeaMember1 truthy OK");
const web3QuorumMember1 = Web3JsQuorum(web3Member1);
t.ok(web3QuorumMember1, "web3QuorumMember1 truthy OK");

const web3EeaMember2 = Web3EEAClient(web3Member2, chainIdMember2);
t.ok(web3EeaMember2, "web3EeaMember2 truthy OK");
const web3QuorumMember2 = Web3JsQuorum(web3Member2);
t.ok(web3QuorumMember2, "web3QuorumMember2 truthy OK");

const web3EeaMember3 = Web3EEAClient(web3Member3, chainIdMember3);
t.ok(web3EeaMember3, "web3EeaMember3 truthy OK");
const web3QuorumMember3 = Web3JsQuorum(web3Member3);
t.ok(web3QuorumMember3, "web3QuorumMember3 truthy OK");

const commitmentHash = await web3EeaMember1.eea.sendRawTransaction({
data: "0x" + HelloWorldContractJson.bytecode,
privateFrom: keys.tessera.member1.publicKey,
privateFor: [
keys.tessera.member1.publicKey,
keys.tessera.member2.publicKey,
],
privateKey: keys.besu.member1.privateKey,
gasLimit: 3000000,
});
const commitmentHash = await web3QuorumMember1.priv.generateAndSendRawTransaction(
{
data: "0x" + HelloWorldContractJson.bytecode,
privateFrom: keys.tessera.member1.publicKey,
privateFor: [
keys.tessera.member1.publicKey,
keys.tessera.member2.publicKey,
],
privateKey: keys.besu.member1.privateKey,
gasLimit: "3000000",
},
);

t.ok(commitmentHash, "commitmentHash truthy OK");

const contractDeployReceipt = (await web3EeaMember1.priv.getTransactionReceipt(
const contractDeployReceipt = (await web3QuorumMember1.priv.waitForTransactionReceipt(
commitmentHash,
keys.tessera.member1.publicKey,
)) as IPrivateTransactionReceipt;

t.ok(contractDeployReceipt, "contractDeployReceipt truthy OK");
Expand All @@ -119,29 +120,26 @@ test(testCase, async (t: Test) => {

// Check that the third node does not see the transaction of the contract
// deployment that was sent to node 1 and 2 only, not 3.
const txReceiptNever = await web3EeaMember3.priv.getTransactionReceipt(
const txReceiptNever = await web3QuorumMember3.priv.waitForTransactionReceipt(
commitmentHash,
keys.tessera.member3.publicKey,
);
t.notok(txReceiptNever, "txReceiptNever falsy OK");

// Check that node 1 and 2 can indeed see the transaction for the contract
// deployment that was sent to them and them only (node 3 was left out)

// Note that changing this to use web3EeaMember3 breaks it and I'm suspecting
// Note that changing this to use web3QuorumMember3 breaks it and I'm suspecting
// that this is what's plaguing the tests that are based on the connector
// which is instantiated with a single web3+web3 EEA client.
// What I will try next is to have 3 connectors each with a web3 EEA client
// which is instantiated with a single web3+web3 Quorum client.
// What I will try next is to have 3 connectors each with a web3 Quorum client
// that points to one of the 3 nodes and see if that makes it work.
const txReceiptAlways1 = await web3EeaMember1.priv.getTransactionReceipt(
const txReceiptAlways1 = await web3QuorumMember1.priv.waitForTransactionReceipt(
commitmentHash,
keys.tessera.member1.publicKey,
);
t.ok(txReceiptAlways1, "txReceiptAlways1 truthy OK");

const txReceiptAlways2 = await web3EeaMember2.priv.getTransactionReceipt(
const txReceiptAlways2 = await web3QuorumMember2.priv.waitForTransactionReceipt(
commitmentHash,
keys.tessera.member2.publicKey,
);
t.ok(txReceiptAlways2, "txReceiptAlways2 truthy OK");

Expand Down Expand Up @@ -174,15 +172,14 @@ test(testCase, async (t: Test) => {
privateFor: [keys.tessera.member2.publicKey],
privateKey: keys.besu.member1.privateKey,
};
const transactionHash = await web3EeaMember1.eea.sendRawTransaction(
const transactionHash = await web3QuorumMember1.priv.generateAndSendRawTransaction(
functionParams,
);
t.comment(`Transaction hash: ${transactionHash}`);
t.ok(transactionHash, "transactionHash truthy OK");

const result = await web3EeaMember1.priv.getTransactionReceipt(
const result = await web3QuorumMember1.priv.waitForTransactionReceipt(
transactionHash,
keys.tessera.member1.publicKey,
);
t.comment(`Transaction receipt for set() call: ${JSON.stringify(result)}`);
t.ok(result, "set() result member 1 truthy OK");
Expand All @@ -202,16 +199,19 @@ test(testCase, async (t: Test) => {
privateKey: keys.besu.member1.privateKey,
};

const privacyGroupId = web3EeaMember1.priv.generatePrivacyGroup(fnParams);
const callOutput = await web3EeaMember1.priv.call({
privacyGroupId,
const privacyGroupId = web3QuorumMember1.utils.generatePrivacyGroup(
fnParams,
);
const callOutput = await web3QuorumMember1.priv.call(privacyGroupId, {
to: contractDeployReceipt.contractAddress,
data: contract.methods.getName().encodeABI(),
from: "LieutenantCactus",
});
t.comment(`getName Call output: ${JSON.stringify(callOutput)}`);
t.ok(callOutput, "callOutput truthy OK");
const name = web3EeaMember1.eth.abi.decodeParameter("string", callOutput);
const name = web3QuorumMember1.eth.abi.decodeParameter(
"string",
callOutput,
);
t.equal(name, "ProfessorCactus - #1", "getName() member 1 equals #1");
}

Expand All @@ -227,12 +227,12 @@ test(testCase, async (t: Test) => {
privateKey: keys.besu.member3.privateKey,
};

const privacyGroupId = web3EeaMember3.priv.generatePrivacyGroup(fnParams);
const callOutput = await web3EeaMember3.priv.call({
privacyGroupId,
const privacyGroupId = web3QuorumMember3.utils.generatePrivacyGroup(
fnParams,
);
const callOutput = await web3QuorumMember3.priv.call(privacyGroupId, {
to: contractDeployReceipt.contractAddress,
data: getNameAbi.signature,
from: "LieutenantCactus",
});
t.comment(`getName member3 output: ${JSON.stringify(callOutput)}`);
t.equal(callOutput, "0x", "member3 getName callOutput === 0x OK");
Expand All @@ -250,15 +250,14 @@ test(testCase, async (t: Test) => {
privateFor: [keys.tessera.member2.publicKey],
privateKey: keys.besu.member2.privateKey,
};
const transactionHash = await web3EeaMember2.eea.sendRawTransaction(
const transactionHash = await web3QuorumMember2.priv.generateAndSendRawTransaction(
functionParams,
);
t.comment(`Transaction hash: ${transactionHash}`);
t.ok(transactionHash, "transactionHash truthy OK");

const result = await web3EeaMember2.priv.getTransactionReceipt(
const result = await web3QuorumMember2.priv.waitForTransactionReceipt(
transactionHash,
keys.tessera.member1.publicKey,
);
t.comment(`Transaction receipt for set() call: ${JSON.stringify(result)}`);
t.ok(result, "set() result member 2 truthy OK");
Expand All @@ -276,15 +275,14 @@ test(testCase, async (t: Test) => {
privateKey: keys.besu.member3.privateKey,
privateFor: [keys.tessera.member2.publicKey],
};
const transactionHash = await web3EeaMember3.eea.sendRawTransaction(
const transactionHash = await web3QuorumMember3.priv.generateAndSendRawTransaction(
functionParams,
);
t.comment(`setName tx hash for member 3: ${transactionHash}`);
t.ok(transactionHash, "setName tx hash for member 3 truthy OK");

const result = await web3EeaMember3.priv.getTransactionReceipt(
const result = await web3QuorumMember3.priv.waitForTransactionReceipt(
transactionHash,
keys.tessera.member1.publicKey,
);
t.comment(`Transaction receipt for set() call: ${JSON.stringify(result)}`);
t.ok(result, "set() result for member 3 truthy OK");
Expand Down

0 comments on commit ed07b17

Please sign in to comment.