Skip to content

Commit

Permalink
Fix formatting of cpuid
Browse files Browse the repository at this point in the history
  • Loading branch information
cjen1-msft committed Mar 5, 2025
1 parent f6a03bb commit df38f54
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"configurations": [
{
"name": "Linux",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"includePath": ["${workspaceFolder}/include", "${workspaceFolder}/src"]
}
],
"version": 4
Expand Down
23 changes: 14 additions & 9 deletions include/ccf/pal/attestation_sev_snp.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ QPHfbkH0CyPfhl1jWhJFZasCAwEAAQ==
bool operator==(const CPUID&) const = default;
std::string hex_str() const
{
auto begin = reinterpret_cast<const uint8_t*>(this);
return ccf::ds::to_hex(begin, begin + sizeof(CPUID));
uint8_t buf[sizeof(CPUID)];
memcpy(buf, this, sizeof(CPUID));
std::reverse(buf, buf + sizeof(CPUID)); // fix little endianness of AMD
return ccf::ds::to_hex(buf, buf + sizeof(CPUID));
}
inline uint8_t get_family_id() const
{
Expand All @@ -300,6 +302,15 @@ QPHfbkH0CyPfhl1jWhJFZasCAwEAAQ==
CPUID, stepping, base_model, base_family, extended_model, extended_family);
static_assert(
sizeof(CPUID) == sizeof(uint32_t), "Can't cast CPUID to uint32_t");
static CPUID cpuid_from_hex(const std::string& hex_str)
{
CPUID ret;
auto buf_ptr = reinterpret_cast<uint8_t*>(&ret);
ccf::ds::from_hex(
hex_str, buf_ptr, buf_ptr + sizeof(CPUID));
std::reverse(buf_ptr, buf_ptr + sizeof(CPUID)); //fix little endianness of AMD
return ret;
}

union UnionedCPUID
{
Expand Down Expand Up @@ -331,13 +342,7 @@ namespace ccf::kv::serialisers

static ccf::pal::snp::CPUID from_serialised(const SerialisedEntry& data)
{
ccf::pal::snp::CPUID ret;
auto buf_ptr = reinterpret_cast<uint8_t*>(&ret);
ccf::ds::from_hex(
std::string(data.data(), data.end()),
buf_ptr,
buf_ptr + sizeof(ccf::pal::snp::CPUID));
return ret;
return ccf::pal::snp::cpuid_from_hex(std::string(data.data(), data.end()));
}
};
}
4 changes: 3 additions & 1 deletion samples/constitutions/default/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,9 @@ const actions = new Map([
},
function (args) {
const cpuid = hexStrToBuf(args.cpuid);
ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].delete(cpuid);
if ( ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].has(cpuid)) {
ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].delete(cpuid);
}
},
),
],
Expand Down
2 changes: 0 additions & 2 deletions src/node/rpc/node_frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -1621,8 +1621,6 @@ namespace ccf
ctx.tx, in.measurement, in.quote_info.format);
}

InternalTablesAccess::trust_static_snp_tcb_version(ctx.tx);

switch (in.quote_info.format)
{
case QuoteFormat::insecure_virtual:
Expand Down

0 comments on commit df38f54

Please sign in to comment.