Skip to content

Conversation

werwurm
Copy link
Contributor

@werwurm werwurm commented Sep 3, 2025

Implements marshalling and unmarshalling for DICE service messages using
CBOR encoding.

@werwurm werwurm requested a review from Copilot September 3, 2025 05:16
Copilot

This comment was marked as outdated.

@werwurm werwurm requested review from Copilot and seidelrj September 3, 2025 05:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements CBOR marshalling and unmarshalling for DICE service messages, establishing the message format and serialization layer for NAT20 service communication. The implementation adds support for various DICE operations including CDI promotion, certificate issuance, and cryptographic signing through a well-defined API.

  • Defines comprehensive message structures for all supported DICE operations
  • Implements CBOR encoding/decoding with proper error handling and validation
  • Provides extensive test coverage for round-trip serialization scenarios

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
include/nat20/service/messages.h Defines message structures and API for DICE service operations
src/service/messages.c Implements CBOR marshalling/unmarshalling with validation logic
src/service/messages.cddl CDDL specification documenting the CBOR message format
src/service/test/messages.cpp Comprehensive test suite covering serialization round-trips and edge cases
src/service/test/test.cpp Basic test runner for the service module
include/nat20/error.h Adds new error codes for message parsing and validation
CMakeLists.txt Integrates service library and tests into build system
.github/license-check/license-config.json Adds license checking for CDDL files
.github/license-check/header-apache2-semicolon.txt License header template for CDDL files

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


int main(int argc, char *argv[]) {
::testing::InitGoogleTest(&argc, argv);
std::cout << "Testing libnat20 service..." << std::endl;
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string 'libnat20' should be 'Libnat20' to match the project naming convention seen elsewhere in the codebase.

Suggested change
std::cout << "Testing libnat20 service..." << std::endl;
std::cout << "Testing Libnat20 service..." << std::endl;

Copilot uses AI. Check for mistakes.

Comment on lines 203 to 231
n20_msg_read_map_with_int_key(istream, n20_msg_open_dice_input_read_cb, input);

Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of n20_msg_read_map_with_int_key is ignored. This function can return errors that should be propagated up to the caller.

Suggested change
n20_msg_read_map_with_int_key(istream, n20_msg_open_dice_input_read_cb, input);
n20_error_t error = n20_msg_read_map_with_int_key(istream, n20_msg_open_dice_input_read_cb, input);
if (error != n20_error_ok_e) {
return error;
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with copilot here. why not just return n20_msg_read_map_with_int_key like n20_msg_promote_request_read does above?

break;
default:
// Skip unknown keys.
n20_cbor_read_skip_item(istream);
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of n20_cbor_read_skip_item is ignored, but other similar cases check this return value and return an error if it fails. This should be consistent with the error handling pattern used elsewhere.

Suggested change
n20_cbor_read_skip_item(istream);
if (!n20_cbor_read_skip_item(istream)) {
return n20_error_unexpected_message_structure_e;
}

Copilot uses AI. Check for mistakes.

/**
* @brief Parent path size exceeds maximum allowed.
*
* When deriving the effective CDI on behalf of a proxy DCIE service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* When deriving the effective CDI on behalf of a proxy DCIE service
* When deriving the effective CDI on behalf of a proxy DICE service

* The implementation does not recognize the request type
* as a valid request type.
*/
n20_error_request_type_unknown_e = 18,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for skipping error numbers?

uint64_t cbor_value;

switch (key) {
case 1: // compressed_context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we want to add #defines or enums for the cbor map keys?

Comment on lines 203 to 231
n20_msg_read_map_with_int_key(istream, n20_msg_open_dice_input_read_cb, input);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with copilot here. why not just return n20_msg_read_map_with_int_key like n20_msg_promote_request_read does above?

EXPECT_EQ(0, memcmp("testkey", read_request.payload.issue_eca_ee_cert.name.buffer, 7));
EXPECT_EQ(2, read_request.payload.issue_eca_ee_cert.key_usage.size);
EXPECT_EQ(0x01, read_request.payload.issue_eca_ee_cert.key_usage.buffer[0]);
EXPECT_EQ(0x02, read_request.payload.issue_eca_ee_cert.key_usage.buffer[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing check for challenge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

n20_msg_request_type_issue_cdi_cert_e,
n20_msg_request_type_issue_eca_cert_e,
n20_msg_request_type_issue_eca_ee_cert_e,
n20_msg_request_type_eca_ee_sign_e));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing newline at end of file.

@@ -0,0 +1,32 @@
/*
* Copyright 2024 Aurora Operations, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright 2024 Aurora Operations, Inc.
* Copyright 2025 Aurora Operations, Inc.

@werwurm werwurm force-pushed the werwurm/cbor_parser branch from 96ca001 to 088e415 Compare September 10, 2025 18:13
@werwurm werwurm force-pushed the werwurm/service_messages branch from fb866a7 to eeb91ba Compare September 10, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants