Skip to content

Commit

Permalink
Fix converters
Browse files Browse the repository at this point in the history
  • Loading branch information
cjen1-msft committed Mar 7, 2025
1 parent f1cc568 commit 15b50cb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 67 deletions.
1 change: 0 additions & 1 deletion include/ccf/js/extensions/ccf/converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace ccf::js::extensions
* - ccf.bufToJsonCompatible
*
* - ccf.pemToId
* - ccf.jsonToTcbVersion
*
* - ccf.enableUntrustedDateTime
* - ccf.enableMetricsLogging
Expand Down
10 changes: 6 additions & 4 deletions samples/constitutions/default/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ const actions = new Map([
new Action(
function (args) {
checkType(args.cpuid, "string", "cpuid");
checkLength(hexStrToBuf(args.cpuid), 4, 4, "cpuid");
checkLength(ccf.strToBuf(args.cpuid), 8, 8, "cpuid");

checkType(args.tcb_version, "object", "tcb_version");
checkType(
Expand All @@ -1120,7 +1120,7 @@ const actions = new Map([
function (args, proposalId) {
ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].set(
ccf.strToBuf(args.cpuid),
ccf.jsonToSnpTcbVersion(args.tcb_version),
ccf.jsonCompatibleToBuf(args.tcb_version),
);

invalidateOtherOpenProposals(proposalId);
Expand Down Expand Up @@ -1187,12 +1187,14 @@ const actions = new Map([
new Action(
function (args) {
checkType(args.cpuid, "string", "cpuid");
checkLength(hexStrToBuf(args.cpuid), 4, 4, "cpuid");
checkLength(ccf.strToBuf(args.cpuid), 8, 8, "cpuid");
},
function (args) {
const cpuid = hexStrToBuf(args.cpuid);
const cpuid = ccf.strToBuf(args.cpuid);
if ( ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].has(cpuid)) {
ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].delete(cpuid);
} else {
throw new Error("CPUID not found");
}
},
),
Expand Down
25 changes: 0 additions & 25 deletions src/js/extensions/ccf/converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,28 +193,6 @@ namespace ccf::js::extensions
ctx, "Failed to parse PEM: %s", exc.what());
}
}

JSValue js_json_to_tcb_version(
JSContext* ctx, JSValueConst, int argc, JSValueConst* argv)
{
if (argc != 1)
return JS_ThrowTypeError(
ctx, "Passed %d arguments, but expected 1", argc);

js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);

auto str = jsctx.json_stringify(jsctx.wrap(argv[0]));
JS_CHECK_EXC(str);

pal::snp::TcbVersion tcb_version =
nlohmann::json::parse(jsctx.to_str(str).value());

auto buf = jsctx.new_array_buffer_copy(
(uint8_t*)&tcb_version, sizeof(pal::snp::TcbVersion));
JS_CHECK_EXC(buf);

return buf.take();
}
}

void ConvertersExtension::install(js::core::Context& ctx)
Expand Down Expand Up @@ -242,8 +220,5 @@ namespace ccf::js::extensions

ccf.set("pemToId", ctx.new_c_function(js_pem_to_id, "pemToId", 1));

ccf.set(
"jsonToSnpTcbVersion",
ctx.new_c_function(js_json_to_tcb_version, "jsonToSnpTcbVersion", 1));
}
}
74 changes: 37 additions & 37 deletions tests/code_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ def test_tcb_version_tables(network, args):
new_node = network.create_node("local://localhost")
network.join_node(new_node, args.package, args, timeout=3)
network.trust_node(new_node, args)
except Exception as e:
except TimeoutError as e:
thrown_exception = e
assert thrown_exception is None, "New node should not have been able to join"
assert thrown_exception is not None, "New node should not have been able to join"

LOG.info("Adding new cpuid's TCB version")
network.consortium.add_snp_tcb_version(primary, cpuid, tcb_version)
Expand Down Expand Up @@ -778,43 +778,43 @@ def run(args):
) as network:
network.start_and_open(args)

# test_verify_quotes(network, args)
#
# # Measurements
# test_measurements_tables(network, args)
# if not snp.IS_SNP:
# test_add_node_with_untrusted_measurement(network, args)
#
# # Host data/security policy
# test_host_data_tables(network, args)
# test_add_node_with_untrusted_host_data(network, args)
#
test_verify_quotes(network, args)

# Measurements
test_measurements_tables(network, args)
if not snp.IS_SNP:
test_add_node_with_untrusted_measurement(network, args)

# Host data/security policy
test_host_data_tables(network, args)
test_add_node_with_untrusted_host_data(network, args)

if snp.IS_SNP:
# # Virtual has no security policy, _only_ host data (unassociated with anything)
# test_add_node_with_stubbed_security_policy(network, args)
# test_start_node_with_mismatched_host_data(network, args)
# test_add_node_without_security_policy(network, args)
# Virtual has no security policy, _only_ host data (unassociated with anything)
test_add_node_with_stubbed_security_policy(network, args)
test_start_node_with_mismatched_host_data(network, args)
test_add_node_without_security_policy(network, args)
test_tcb_version_tables(network, args)
#
# # Endorsements
# test_endorsements_tables(network, args)
# test_add_node_with_no_uvm_endorsements(network, args)
#
# if not snp.IS_SNP:
# # NB: Assumes the current nodes are still using args.package, so must run before test_update_all_nodes
# test_proposal_invalidation(network, args)
#
# # This is in practice equivalent to either "unknown measurement" or "unknown host data", but is explicitly
# # testing that (without artifically removing/corrupting those values) a replacement package differs
# # in one of these values
# test_add_node_with_different_package(network, args)
# test_update_all_nodes(network, args)
#
# # Run again at the end to confirm current nodes are acceptable
# test_verify_quotes(network, args)
#
# if snp.IS_SNP:
# test_add_node_with_no_uvm_endorsements_in_kv(network, args)

# Endorsements
test_endorsements_tables(network, args)
test_add_node_with_no_uvm_endorsements(network, args)

if not snp.IS_SNP:
# NB: Assumes the current nodes are still using args.package, so must run before test_update_all_nodes
test_proposal_invalidation(network, args)

# This is in practice equivalent to either "unknown measurement" or "unknown host data", but is explicitly
# testing that (without artifically removing/corrupting those values) a replacement package differs
# in one of these values
test_add_node_with_different_package(network, args)
test_update_all_nodes(network, args)

# Run again at the end to confirm current nodes are acceptable
test_verify_quotes(network, args)

if snp.IS_SNP:
test_add_node_with_no_uvm_endorsements_in_kv(network, args)


if __name__ == "__main__":
Expand Down

0 comments on commit 15b50cb

Please sign in to comment.