Skip to content

Commit ad1fd32

Browse files
committed
Service messages
1 parent b201f45 commit ad1fd32

7 files changed

Lines changed: 799 additions & 16 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ set(LIBNAT20_TEST_SOURCES
108108
set(LIBNAT20_SERVICE_SOURCES
109109
# Add service source files here.
110110
src/service/gnostic.c
111+
src/service/messages.c
111112
src/service/proxy.c
112113
src/service/service.c
113114
)
114115

115116
set(LIBNAT20_SERVICE_PUB_HEADERS
116117
# Add service public headers here.
117118
include/nat20/service/gnostic.h
119+
include/nat20/service/messages.h
118120
include/nat20/service/proxy.h
119121
include/nat20/service/service.h
120122
)

include/nat20/error.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ enum n20_error_s {
6464
n20_error_missing_callback_function_or_context_e = 9,
6565
n20_error_parent_path_size_exceeds_max_e = 10,
6666
n20_error_missing_parent_service_e = 11,
67+
n20_error_unexpected_message_structure_e = 12,
68+
n20_error_unrecognized_request_type_e = 13,
69+
n20_error_write_position_overflow_e = 14,
6770
/**
6871
* @brief The crypto context given to an interface was invalid.
6972
*

include/nat20/functionality.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ enum n20_open_dice_mode_s {
6060
* @brief Device is in a debug or maintenance mode.
6161
*/
6262
n20_open_dice_mode_recovery_e = 3,
63+
/**
64+
* @brief Maximum value for the mode enumeration.
65+
*/
66+
n20_open_dice_mode_max_e = 4
6367
};
6468

6569
typedef enum n20_open_dice_mode_s n20_open_dice_mode_t;

include/nat20/service/messages.h

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
* Copyright 2025 Aurora Operations, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <nat20/crypto.h>
20+
#include <nat20/functionality.h>
21+
#include <nat20/service/service.h>
22+
#include <nat20/types.h>
23+
#include <stddef.h>
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
enum n20_msg_request_type_s {
30+
n20_msg_request_type_none_e = 0,
31+
/**
32+
* @brief Request to promote the caller's CDI to the next level.
33+
*/
34+
n20_msg_request_type_promote_e = 1,
35+
36+
/**
37+
* @brief Request to issue a CDI certificate.
38+
*/
39+
n20_msg_request_type_issue_cdi_cert_e = 2,
40+
41+
n20_msg_request_type_count_e = 3,
42+
};
43+
44+
typedef enum n20_msg_request_type_s n20_msg_request_type_t;
45+
46+
struct n20_msg_promote_request_s {
47+
n20_slice_t compressed_context;
48+
};
49+
50+
typedef struct n20_msg_promote_request_s n20_msg_promote_request_t;
51+
52+
struct n20_msg_issue_cdi_cert_request_s {
53+
/**
54+
* @brief The type of the parent key.
55+
*
56+
* This is used to determine how to derive the new CDI.
57+
*/
58+
n20_crypto_key_type_t parent_key_type;
59+
60+
/**
61+
* @brief The type of the new key to be issued.
62+
*
63+
* This is the type of the CDI that is being requested.
64+
*/
65+
n20_crypto_key_type_t key_type;
66+
67+
/**
68+
* @brief The length of the parent path.
69+
*
70+
* This is used to determine how many elements are in the parent path.
71+
*/
72+
73+
n20_open_dice_input_t next_context;
74+
75+
/**
76+
* @brief The length of the parent path.
77+
*
78+
* This is used to determine how many elements are in the parent path.
79+
*/
80+
size_t parent_path_length;
81+
/**
82+
* @brief The compressed path to the parent CDI.
83+
*
84+
* This is used to derive the new CDI from the parent CDI.
85+
*/
86+
n20_slice_t parent_path[N20_STATELESS_MAX_PATH_LENGTH];
87+
/**
88+
* @brief The format of the certificate to be issued.
89+
*
90+
* This is used to determine how the certificate should be formatted.
91+
*/
92+
n20_certificate_format_t certificate_format;
93+
};
94+
95+
typedef struct n20_msg_issue_cdi_cert_request_s n20_msg_issue_cdi_cert_request_t;
96+
97+
union n20_msg_request_payload_u {
98+
n20_msg_promote_request_t promote;
99+
n20_msg_issue_cdi_cert_request_t issue_cdi_cert;
100+
};
101+
102+
typedef union n20_msg_request_payload_u n20_msg_request_payload_t;
103+
104+
struct n20_msg_request_s {
105+
/**
106+
* @brief The request type.
107+
*
108+
* This is a unique identifier for the request.
109+
*/
110+
n20_msg_request_type_t request_type;
111+
112+
/**
113+
* @brief The payload of the request.
114+
*
115+
* This is the data that is being sent with the request.
116+
*/
117+
n20_msg_request_payload_t payload;
118+
};
119+
120+
struct n20_msg_error_response_s {
121+
/**
122+
* @brief The error code of the response.
123+
*
124+
* This is used to indicate success or failure of the request.
125+
*/
126+
n20_error_t error_code;
127+
};
128+
129+
typedef struct n20_msg_error_response_s n20_msg_error_response_t;
130+
131+
typedef struct n20_msg_request_s n20_msg_request_t;
132+
133+
struct n20_msg_issue_cdi_cert_response_s {
134+
/**
135+
* @brief The error code of the response.
136+
*
137+
* This is used to indicate success or failure of the request.
138+
*/
139+
n20_error_t error_code;
140+
/**
141+
* @brief The payload of the response.
142+
*
143+
* This is the data that is being sent with the response.
144+
*/
145+
n20_slice_t certificate;
146+
};
147+
148+
typedef struct n20_msg_issue_cdi_cert_response_s n20_msg_issue_cdi_cert_response_t;
149+
150+
extern n20_error_t n20_msg_request_read(n20_msg_request_t *request, n20_slice_t msg_buffer);
151+
152+
extern n20_error_t n20_msg_request_write(n20_msg_request_t const *request,
153+
uint8_t *buffer,
154+
size_t *buffer_size);
155+
156+
extern n20_error_t n20_msg_issue_cdi_cert_response_read(n20_msg_issue_cdi_cert_response_t *response,
157+
n20_slice_t buffer);
158+
159+
extern n20_error_t n20_msg_issue_cdi_cert_response_write(
160+
n20_msg_issue_cdi_cert_response_t const *response,
161+
uint8_t *buffer,
162+
size_t *const buffer_size_in_out);
163+
164+
extern n20_error_t n20_msg_error_response_read(n20_msg_error_response_t *response,
165+
n20_slice_t buffer);
166+
extern n20_error_t n20_msg_error_response_write(n20_msg_error_response_t const *response,
167+
uint8_t *buffer,
168+
size_t *const buffer_size_in_out);
169+
170+
#ifdef __cplusplus
171+
}
172+
#endif

include/nat20/service/service.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
extern "C" {
2121
#endif
2222

23+
#define N20_STATELESS_MAX_PATH_LENGTH 8
24+
2325
#ifdef __cplusplus
2426
}
2527
#endif

0 commit comments

Comments
 (0)