From 7de782f23bc14d748e92b4c1f3530e654d206b99 Mon Sep 17 00:00:00 2001 From: Arnaud Brousseau Date: Thu, 9 May 2024 12:28:15 -0500 Subject: [PATCH] Patch import/index and import/standalone --- import/index.template.html | 11 ++++++++++- import/standalone.template.html | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/import/index.template.html b/import/index.template.html index 5d5f5c7..ea42c25 100644 --- a/import/index.template.html +++ b/import/index.template.html @@ -546,7 +546,16 @@ if (!TKHQ.verifyEnclaveSignature) { throw new Error("method not loaded"); } - verified = await TKHQ.verifyEnclaveSignature(bundleObj.enclaveQuorumPublic, bundleObj.dataSignature, bundleObj.data); + + // Temporary solution to get the bytes signed by the enclave + var signedData = /"data":({[^}]+)/.exec(bundle); + if (signedData === null || signedData.length !== 2) { + throw new Error(`unable to find signed data in bundle: ${bundle}`); + } + const signedDataBytes = new TextEncoder().encode(signedData[1] + "}"); + const signedDataHexString = TKHQ.uint8arrayToHexString(signedDataBytes); + + verified = await TKHQ.verifyEnclaveSignature(bundleObj.enclaveQuorumPublic, bundleObj.dataSignature, signedDataHexString); if (!verified) { throw new Error(`failed to verify enclave signature: ${bundle}`); } diff --git a/import/standalone.template.html b/import/standalone.template.html index 203ef76..78d1ed1 100644 --- a/import/standalone.template.html +++ b/import/standalone.template.html @@ -543,7 +543,17 @@

Message log

if (!TKHQ.verifyEnclaveSignature) { throw new Error("method not loaded"); } - verified = await TKHQ.verifyEnclaveSignature(bundleObj.enclaveQuorumPublic, bundleObj.dataSignature, bundleObj.data); + + // Temporary solution to get the bytes signed by the enclave + var signedData = /"data":({[^}]+)/.exec(bundle); + if (signedData === null || signedData.length !== 2) { + throw new Error(`unable to find signed data in bundle: ${bundle}`); + } + const signedDataBytes = new TextEncoder().encode(signedData[1] + "}"); + const signedDataHexString = TKHQ.uint8arrayToHexString(signedDataBytes); + + verified = await TKHQ.verifyEnclaveSignature(bundleObj.enclaveQuorumPublic, bundleObj.dataSignature, signedDataHexString); + if (!verified) { throw new Error(`failed to verify enclave signature: ${bundle}`); }