Skip to content

Instantly share code, notes, and snippets.

@jpopesculian
Last active December 23, 2019 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpopesculian/44ba0914c590d9e3367e7aa0ec2901d9 to your computer and use it in GitHub Desktop.
Save jpopesculian/44ba0914c590d9e3367e7aa0ec2901d9 to your computer and use it in GitHub Desktop.
Javascript SGX remote attestation samples
node_modules
.env
require("dotenv").config();
const fetch = require("node-fetch");
const HOST_API = "http://localhost:8000/api/attestation/remote";
const INTEL_API =
"https://api.trustedservices.intel.com/sgx/dev/attestation/v3";
const SPID = "E6CCD942923D1341950E00BA9CAC5D2E";
const buildChallenge = (session, spid) => {
return {
session,
spid
};
};
const parseResponse = async res => {
let text = await res.text();
try {
return JSON.parse(text);
} catch {
return { status: res.status, message: text };
}
};
const getSession = async () => fetch(`${HOST_API}/session`).then(parseResponse);
const postChallenge = async challenge =>
fetch(`${HOST_API}/challenge`, {
method: "post",
body: JSON.stringify({ challenge }),
headers: { "Content-Type": "application/json" }
}).then(parseResponse);
const postVerification = async quote =>
await fetch(`${INTEL_API}/report`, {
method: "post",
body: JSON.stringify({ isvEnclaveQuote: quote, nonce: "0" }),
headers: {
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": process.env.OCP_APIM_SUBSCRIPTION_KEY
}
}).then(parseResponse);
const main = async () => {
console.log("getting session from service...");
let { session } = await getSession();
console.log("received session!");
console.log(session);
let challenge = buildChallenge(session, SPID);
console.log("posting challenge to service...");
let { response } = await postChallenge(challenge);
console.log("received response!");
console.log(response);
console.log("posting verification to Intel...");
let verification = await postVerification(response.result.quote);
console.log("received verification!");
console.log(verification);
};
main();
{
"dependencies": {
"dotenv": "^8.2.0",
"node-fetch": "^2.6.0"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
node-fetch@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment