Skip to content

Commit

Permalink
Deploying to gh-pages from @ d0c8a01 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jan 27, 2025
1 parent 976b9ef commit 954ca49
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 140 deletions.
19 changes: 2 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body class="min-h-screen">
<script src="wasm_exec.js"></script>
<script src="verifier.js"></script>
<script src="main.js"></script>

<div class="container mx-auto px-4 py-6">
<div class="bg-white rounded-lg shadow-sm p-4 md:p-8">
Expand Down Expand Up @@ -46,23 +46,8 @@ <h1 class="text-2xl md:text-3xl font-bold text-gray-800 mb-4">Tinfoil Verifier</
</button>
</div>
</div>
<div class="flex flex-col gap-4 mb-6">
<div>
<div class="text-sm font-medium text-gray-600 mb-2">Bundle URL:</div>
<div class="bg-gray-100 p-3 rounded-md">
<a id="bundleLink" href="#" class="text-blue-600 hover:text-blue-800 break-all text-sm block" target="_blank" rel="noopener noreferrer"></a>
</div>
</div>
<div>
<div class="text-sm font-medium text-gray-600 mb-2">Attestation URL:</div>
<div class="bg-gray-100 p-3 rounded-md">
<a id="attestationLink" href="#" class="text-blue-600 hover:text-blue-800 break-all text-sm block" target="_blank" rel="noopener noreferrer"></a>
</div>
</div>
</div>

<div
id="log"
id="logs"
class="bg-white rounded-md p-4 border border-gray-200 min-h-[200px] font-mono text-sm"
></div>
</div>
Expand Down
85 changes: 85 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
function verify() {
let repo = document.getElementById("repo").value;
let hostname = document.getElementById("domain").value;

document.getElementById("logs").innerHTML = "";

function addLog(...messages) {
const date = new Date();
const timestamp = `${date.getFullYear()}/${String(date.getMonth() + 1).padStart(2, '0')}/${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}:${String(date.getSeconds()).padStart(2, '0')}`;
console.log(`${timestamp}`, ...messages, '\n');
}

const go = new Go();
WebAssembly.instantiateStreaming(fetch("tinfoil-verifier.wasm"), go.importObject).then((result) => {
go.run(result.instance);

let enclavePromise = verifyEnclave(hostname).then(result => {
addLog("Enclave attested certificate fingerprint:", result.certificate);
return result.measurement;
}).catch(error => {
addLog("Error verifying enclave:", error);
});

addLog(`Fetching latest release for ${repo}`);
let sigstorePromise = fetch("https://api.github.com/repos/" + repo + "/releases/latest")
.then(response => response.json())
.then(data => {
let latestTag = data.tag_name;

const regex = /EIF hash: ([a-f0-9]{64})/i;
const match = data.body.match(regex);
if (match) {
let digest = match[1];
addLog(`Found latest release ${latestTag}`);
return digest;
} else {
addLog("Failed to find EIF hash");
}
})
.then(digest => {
return verifyCode(repo, digest)
})
.catch(error => {
addLog("Failed to fetch latest release: " + error);
throw error;
})

Promise.all([sigstorePromise, enclavePromise])
.then(([sigstoreMeasurement, enclaveMeasurement]) => {
addLog("Source:", sigstoreMeasurement);
addLog("Enclave:", enclaveMeasurement);
if (sigstoreMeasurement === enclaveMeasurement) {
addLog("Verification successful! ✅");
} else {
throw new Error("Verification failed: measurements do not match");
}
})
.catch(error => {
addLog("Verification failed: " + error);
});
});
}

document.addEventListener("DOMContentLoaded", function () {
let url = new URL(window.location.href);
let urlRepo = url.searchParams.get("repo");
let urlDomain = url.searchParams.get("domain");

if (urlRepo) {
document.getElementById("repo").value = urlRepo;
}
if (urlDomain) {
document.getElementById("domain").value = urlDomain;
}

let logsElement = document.getElementById("logs");

console.stdlog = console.log.bind(console);
console.log = function () {
console.stdlog.apply(console, arguments);
logsElement.innerHTML = logsElement.innerHTML + Array.from(arguments).join(" ") + "<br>";
}

verify();
});
Binary file modified tinfoil-verifier.wasm
Binary file not shown.
123 changes: 0 additions & 123 deletions verifier.js

This file was deleted.

0 comments on commit 954ca49

Please sign in to comment.