|
| 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 |
0 commit comments