Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed Oct 19, 2023
1 parent c9689b7 commit bf4942a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/js/openenclave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace ccf::js
JS_CHECK_SET(r.set("claims", std::move(js_claims)));
JS_CHECK_SET(r.set("customClaims", std::move(js_custom_claims)));

return r;
return r.take();
}

static JSValue create_openenclave_obj(JSContext* ctx)
Expand Down
57 changes: 26 additions & 31 deletions src/js/snp_attestation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ namespace ccf::js
{
#pragma clang diagnostic push

static JSValue make_js_tcb_version(JSContext* ctx, pal::snp::TcbVersion tcb)
static JSValue make_js_tcb_version(js::Context& jsctx, pal::snp::TcbVersion tcb)
{
auto js_tcb = JS_NewObject(ctx);
JS_SetPropertyStr(
ctx, js_tcb, "boot_loader", JS_NewUint32(ctx, tcb.boot_loader));
JS_SetPropertyStr(ctx, js_tcb, "tee", JS_NewUint32(ctx, tcb.tee));
JS_SetPropertyStr(ctx, js_tcb, "snp", JS_NewUint32(ctx, tcb.snp));
JS_SetPropertyStr(
ctx, js_tcb, "microcode", JS_NewUint32(ctx, tcb.microcode));
return js_tcb;
auto js_tcb = jsctx.new_obj();
JS_CHECK_EXC(js_tcb);

JS_CHECK_SET(js_tcb.set_uint32("boot_loader", tcb.boot_loader));
JS_CHECK_SET(js_tcb.set_uint32("tee", tcb.tee));
JS_CHECK_SET(js_tcb.set_uint32("snp", tcb.snp));
JS_CHECK_SET(js_tcb.set_uint32("microcode", tcb.microcode));
return js_tcb.take();
}

static JSValue JS_NewArrayBuffer2(
Expand Down Expand Up @@ -112,6 +112,7 @@ namespace ccf::js
auto attestation =
*reinterpret_cast<const pal::snp::Attestation*>(quote_info.quote.data());


auto r = jsctx.new_obj();
JS_CHECK_EXC(r);

Expand Down Expand Up @@ -146,24 +147,18 @@ namespace ccf::js
JS_CHECK_SET(a.set_uint32("vmpl", attestation.vmpl));
JS_CHECK_SET(a.set_uint32("signature_algo", static_cast<uint32_t>(attestation.signature_algo)));

JS_SetProperty(
ctx,
a,
JS_NewAtom(ctx, "platform_version"),
make_js_tcb_version(ctx, attestation.platform_version));
auto platform_version = JSWrappedValue(ctx, make_js_tcb_version(jsctx, attestation.platform_version));
JS_CHECK_EXC(platform_version);
JS_CHECK_SET(a.set("platform_version", std::move(platform_version)));

auto platform_info = JS_NewObject(ctx);
JS_SetPropertyStr(
ctx,
platform_info,
"smt_en",
JS_NewUint32(ctx, attestation.platform_info.smt_en));
JS_SetPropertyStr(
ctx,
platform_info,
"tsme_en",
JS_NewUint32(ctx, attestation.platform_info.tsme_en));
JS_SetProperty(ctx, a, JS_NewAtom(ctx, "platform_info"), platform_info);
auto platform_info = jsctx.new_obj();
JS_CHECK_EXC(platform_info);
JS_CHECK_SET(platform_info.set_uint32("smt_en", attestation.platform_info.smt_en));
JS_CHECK_SET(platform_info.set_uint32("tsme_en", attestation.platform_info.tsme_en));

auto platform_info_atom = JSWrappedAtom(ctx, "platform_info");
JS_CHECK_NULL(platform_info_atom);
JS_CHECK_SET(a.set(std::move(platform_info_atom), std::move(platform_info)));

auto flags = JS_NewObject(ctx);
JS_SetPropertyStr(
Expand Down Expand Up @@ -211,14 +206,14 @@ namespace ccf::js
ctx,
a,
JS_NewAtom(ctx, "reported_tcb"),
make_js_tcb_version(ctx, attestation.reported_tcb));
make_js_tcb_version(jsctx, attestation.reported_tcb));
JS_SetPropertyStr(
ctx, a, "chip_id", JS_NewArrayBuffer2(ctx, attestation.chip_id));
JS_SetProperty(
ctx,
a,
JS_NewAtom(ctx, "committed_tcb"),
make_js_tcb_version(ctx, attestation.committed_tcb));
make_js_tcb_version(jsctx, attestation.committed_tcb));
JS_SetPropertyStr(
ctx, a, "current_minor", JS_NewUint32(ctx, attestation.current_minor));
JS_SetPropertyStr(
Expand All @@ -244,7 +239,7 @@ namespace ccf::js
ctx,
a,
JS_NewAtom(ctx, "launch_tcb"),
make_js_tcb_version(ctx, attestation.launch_tcb));
make_js_tcb_version(jsctx, attestation.launch_tcb));

auto signature = JS_NewObject(ctx);
JS_SetProperty(
Expand All @@ -258,7 +253,7 @@ namespace ccf::js
JS_NewAtom(ctx, "s"),
JS_NewArrayBuffer2(ctx, attestation.signature.s));
JS_SetProperty(ctx, a, JS_NewAtom(ctx, "signature"), signature);
JS_SetProperty(ctx, r, JS_NewAtom(ctx, "attestation"), a);
JS_CHECK_SET(r.set("attestation", std::move(a)));

if (parsed_uvm_endorsements.has_value())
{
Expand All @@ -281,7 +276,7 @@ namespace ccf::js
JS_SetProperty(ctx, r, JS_NewAtom(ctx, "uvm_endorsements"), u);
}

return r;
return r.take();
}

#pragma clang diagnostic pop
Expand Down
1 change: 1 addition & 0 deletions src/js/wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ namespace ccf::js
{
va_list ap;
va_start(ap, fmt);
// TODO: that does not seem right, it will attempt to free a JS_EXCEPTION
auto r = W(JS_ThrowTypeError(ctx, fmt, ap));
va_end(ap);
return r;
Expand Down
16 changes: 8 additions & 8 deletions tests/js-modules/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,15 +1372,15 @@ def run(args):
args.nodes, args.binary_dir, args.debug_nodes, args.perf_nodes, pdb=args.pdb
) as network:
network.start_and_open(args)
network = test_module_import(network, args)
network = test_bytecode_cache(network, args)
network = test_app_bundle(network, args)
network = test_dynamic_endpoints(network, args)
network = test_set_js_runtime(network, args)
# network = test_module_import(network, args)
# network = test_bytecode_cache(network, args)
# network = test_app_bundle(network, args)
# network = test_dynamic_endpoints(network, args)
# network = test_set_js_runtime(network, args)
network = test_npm_app(network, args)
network = test_js_execution_time(network, args)
network = test_js_exception_output(network, args)
network = test_user_cose_authentication(network, args)
# network = test_js_execution_time(network, args)
# network = test_js_exception_output(network, args)
# network = test_user_cose_authentication(network, args)


if __name__ == "__main__":
Expand Down

0 comments on commit bf4942a

Please sign in to comment.