Skip to content

Commit 15b50cb

Browse files
committed
Fix converters
1 parent f1cc568 commit 15b50cb

File tree

4 files changed

+43
-67
lines changed

4 files changed

+43
-67
lines changed

include/ccf/js/extensions/ccf/converters.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace ccf::js::extensions
1515
* - ccf.bufToJsonCompatible
1616
*
1717
* - ccf.pemToId
18-
* - ccf.jsonToTcbVersion
1918
*
2019
* - ccf.enableUntrustedDateTime
2120
* - ccf.enableMetricsLogging

samples/constitutions/default/actions.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ const actions = new Map([
11011101
new Action(
11021102
function (args) {
11031103
checkType(args.cpuid, "string", "cpuid");
1104-
checkLength(hexStrToBuf(args.cpuid), 4, 4, "cpuid");
1104+
checkLength(ccf.strToBuf(args.cpuid), 8, 8, "cpuid");
11051105

11061106
checkType(args.tcb_version, "object", "tcb_version");
11071107
checkType(
@@ -1120,7 +1120,7 @@ const actions = new Map([
11201120
function (args, proposalId) {
11211121
ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].set(
11221122
ccf.strToBuf(args.cpuid),
1123-
ccf.jsonToSnpTcbVersion(args.tcb_version),
1123+
ccf.jsonCompatibleToBuf(args.tcb_version),
11241124
);
11251125

11261126
invalidateOtherOpenProposals(proposalId);
@@ -1187,12 +1187,14 @@ const actions = new Map([
11871187
new Action(
11881188
function (args) {
11891189
checkType(args.cpuid, "string", "cpuid");
1190-
checkLength(hexStrToBuf(args.cpuid), 4, 4, "cpuid");
1190+
checkLength(ccf.strToBuf(args.cpuid), 8, 8, "cpuid");
11911191
},
11921192
function (args) {
1193-
const cpuid = hexStrToBuf(args.cpuid);
1193+
const cpuid = ccf.strToBuf(args.cpuid);
11941194
if ( ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].has(cpuid)) {
11951195
ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].delete(cpuid);
1196+
} else {
1197+
throw new Error("CPUID not found");
11961198
}
11971199
},
11981200
),

src/js/extensions/ccf/converters.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -193,28 +193,6 @@ namespace ccf::js::extensions
193193
ctx, "Failed to parse PEM: %s", exc.what());
194194
}
195195
}
196-
197-
JSValue js_json_to_tcb_version(
198-
JSContext* ctx, JSValueConst, int argc, JSValueConst* argv)
199-
{
200-
if (argc != 1)
201-
return JS_ThrowTypeError(
202-
ctx, "Passed %d arguments, but expected 1", argc);
203-
204-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
205-
206-
auto str = jsctx.json_stringify(jsctx.wrap(argv[0]));
207-
JS_CHECK_EXC(str);
208-
209-
pal::snp::TcbVersion tcb_version =
210-
nlohmann::json::parse(jsctx.to_str(str).value());
211-
212-
auto buf = jsctx.new_array_buffer_copy(
213-
(uint8_t*)&tcb_version, sizeof(pal::snp::TcbVersion));
214-
JS_CHECK_EXC(buf);
215-
216-
return buf.take();
217-
}
218196
}
219197

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

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

245-
ccf.set(
246-
"jsonToSnpTcbVersion",
247-
ctx.new_c_function(js_json_to_tcb_version, "jsonToSnpTcbVersion", 1));
248223
}
249224
}

tests/code_update.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ def test_tcb_version_tables(network, args):
310310
new_node = network.create_node("local://localhost")
311311
network.join_node(new_node, args.package, args, timeout=3)
312312
network.trust_node(new_node, args)
313-
except Exception as e:
313+
except TimeoutError as e:
314314
thrown_exception = e
315-
assert thrown_exception is None, "New node should not have been able to join"
315+
assert thrown_exception is not None, "New node should not have been able to join"
316316

317317
LOG.info("Adding new cpuid's TCB version")
318318
network.consortium.add_snp_tcb_version(primary, cpuid, tcb_version)
@@ -778,43 +778,43 @@ def run(args):
778778
) as network:
779779
network.start_and_open(args)
780780

781-
# test_verify_quotes(network, args)
782-
#
783-
# # Measurements
784-
# test_measurements_tables(network, args)
785-
# if not snp.IS_SNP:
786-
# test_add_node_with_untrusted_measurement(network, args)
787-
#
788-
# # Host data/security policy
789-
# test_host_data_tables(network, args)
790-
# test_add_node_with_untrusted_host_data(network, args)
791-
#
781+
test_verify_quotes(network, args)
782+
783+
# Measurements
784+
test_measurements_tables(network, args)
785+
if not snp.IS_SNP:
786+
test_add_node_with_untrusted_measurement(network, args)
787+
788+
# Host data/security policy
789+
test_host_data_tables(network, args)
790+
test_add_node_with_untrusted_host_data(network, args)
791+
792792
if snp.IS_SNP:
793-
# # Virtual has no security policy, _only_ host data (unassociated with anything)
794-
# test_add_node_with_stubbed_security_policy(network, args)
795-
# test_start_node_with_mismatched_host_data(network, args)
796-
# test_add_node_without_security_policy(network, args)
793+
# Virtual has no security policy, _only_ host data (unassociated with anything)
794+
test_add_node_with_stubbed_security_policy(network, args)
795+
test_start_node_with_mismatched_host_data(network, args)
796+
test_add_node_without_security_policy(network, args)
797797
test_tcb_version_tables(network, args)
798-
#
799-
# # Endorsements
800-
# test_endorsements_tables(network, args)
801-
# test_add_node_with_no_uvm_endorsements(network, args)
802-
#
803-
# if not snp.IS_SNP:
804-
# # NB: Assumes the current nodes are still using args.package, so must run before test_update_all_nodes
805-
# test_proposal_invalidation(network, args)
806-
#
807-
# # This is in practice equivalent to either "unknown measurement" or "unknown host data", but is explicitly
808-
# # testing that (without artifically removing/corrupting those values) a replacement package differs
809-
# # in one of these values
810-
# test_add_node_with_different_package(network, args)
811-
# test_update_all_nodes(network, args)
812-
#
813-
# # Run again at the end to confirm current nodes are acceptable
814-
# test_verify_quotes(network, args)
815-
#
816-
# if snp.IS_SNP:
817-
# test_add_node_with_no_uvm_endorsements_in_kv(network, args)
798+
799+
# Endorsements
800+
test_endorsements_tables(network, args)
801+
test_add_node_with_no_uvm_endorsements(network, args)
802+
803+
if not snp.IS_SNP:
804+
# NB: Assumes the current nodes are still using args.package, so must run before test_update_all_nodes
805+
test_proposal_invalidation(network, args)
806+
807+
# This is in practice equivalent to either "unknown measurement" or "unknown host data", but is explicitly
808+
# testing that (without artifically removing/corrupting those values) a replacement package differs
809+
# in one of these values
810+
test_add_node_with_different_package(network, args)
811+
test_update_all_nodes(network, args)
812+
813+
# Run again at the end to confirm current nodes are acceptable
814+
test_verify_quotes(network, args)
815+
816+
if snp.IS_SNP:
817+
test_add_node_with_no_uvm_endorsements_in_kv(network, args)
818818

819819

820820
if __name__ == "__main__":

0 commit comments

Comments
 (0)