@@ -129,7 +129,7 @@ libspdm_return_t libspdm_get_response_set_certificate(libspdm_context_t *spdm_co
129
129
SPDM_SET_CERTIFICATE , response_size , response );
130
130
}
131
131
132
- slot_id = spdm_request -> header .param1 & SPDM_GET_CERTIFICATE_REQUEST_SLOT_ID_MASK ;
132
+ slot_id = spdm_request -> header .param1 & SPDM_SET_CERTIFICATE_REQUEST_SLOT_ID_MASK ;
133
133
if (slot_id >= SPDM_MAX_SLOT_COUNT ) {
134
134
return libspdm_generate_error_response (spdm_context ,
135
135
SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
@@ -147,63 +147,84 @@ libspdm_return_t libspdm_get_response_set_certificate(libspdm_context_t *spdm_co
147
147
root_cert_hash_size = libspdm_get_hash_size (
148
148
spdm_context -> connection_info .algorithm .base_hash_algo );
149
149
150
- if (request_size < sizeof (spdm_set_certificate_request_t ) +
151
- sizeof (spdm_cert_chain_t ) + root_cert_hash_size ) {
152
- return libspdm_generate_error_response (spdm_context ,
153
- SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
154
- response_size , response );
155
- }
150
+ if ((libspdm_get_connection_version (spdm_context ) >= SPDM_MESSAGE_VERSION_13 ) &&
151
+ ((spdm_request -> header .param1 & SPDM_SET_CERTIFICATE_REQUEST_ERASE ) != 0 )) {
152
+ /*the CertChain field shall be absent;the value of SetCertModel shall be zero*/
153
+ if ((request_size != sizeof (spdm_set_certificate_request_t )) ||
154
+ ((spdm_request -> header .param1 & SPDM_SET_CERTIFICATE_REQUEST_SET_CERT_MODEL_MASK ) !=
155
+ 0 )) {
156
+ return libspdm_generate_error_response (spdm_context ,
157
+ SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
158
+ response_size , response );
159
+ }
156
160
157
- /*point to full SPDM certificate chain*/
158
- cert_chain = (const void * )(spdm_request + 1 );
159
- cert_chain_header = cert_chain ;
161
+ /* erase slot_id cert_chain*/
162
+ result = libspdm_write_certificate_to_nvm (slot_id , NULL , 0 , 0 , 0 );
163
+ if (!result ) {
164
+ return libspdm_generate_error_response (spdm_context ,
165
+ SPDM_ERROR_CODE_OPERATION_FAILED , 0 ,
166
+ response_size , response );
167
+ }
168
+ } else {
169
+ if (request_size < sizeof (spdm_set_certificate_request_t ) +
170
+ sizeof (spdm_cert_chain_t ) + root_cert_hash_size ) {
171
+ return libspdm_generate_error_response (spdm_context ,
172
+ SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
173
+ response_size , response );
174
+ }
160
175
161
- if (cert_chain_header -> length < sizeof (spdm_cert_chain_t ) + root_cert_hash_size ) {
162
- return libspdm_generate_error_response (spdm_context ,
163
- SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
164
- response_size , response );
165
- }
166
- if (cert_chain_header -> length > request_size - sizeof (spdm_set_certificate_request_t )) {
167
- return libspdm_generate_error_response (spdm_context ,
168
- SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
169
- response_size , response );
170
- }
176
+ /*point to full SPDM certificate chain*/
177
+ cert_chain = (const void * )(spdm_request + 1 );
178
+ cert_chain_header = cert_chain ;
171
179
172
- /*get actual cert_chain size*/
173
- cert_chain_size = cert_chain_header -> length - sizeof (spdm_cert_chain_t ) - root_cert_hash_size ;
180
+ if (cert_chain_header -> length < sizeof (spdm_cert_chain_t ) + root_cert_hash_size ) {
181
+ return libspdm_generate_error_response (spdm_context ,
182
+ SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
183
+ response_size , response );
184
+ }
185
+ if (cert_chain_header -> length > request_size - sizeof (spdm_set_certificate_request_t )) {
186
+ return libspdm_generate_error_response (spdm_context ,
187
+ SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
188
+ response_size , response );
189
+ }
174
190
175
- /*point to actual cert_chain*/
176
- cert_chain = ( const void * )(( const uint8_t * ) cert_chain
177
- + sizeof ( spdm_cert_chain_t ) + root_cert_hash_size ) ;
191
+ /*get actual cert_chain size */
192
+ cert_chain_size = cert_chain_header -> length - sizeof ( spdm_cert_chain_t ) -
193
+ root_cert_hash_size ;
178
194
179
- is_device_cert_model = false;
180
- if ((spdm_context -> local_context .capability .flags &
181
- SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP ) == 0 ) {
182
- is_device_cert_model = true;
183
- }
195
+ /*point to actual cert_chain*/
196
+ cert_chain = (const void * )((const uint8_t * )cert_chain
197
+ + sizeof (spdm_cert_chain_t ) + root_cert_hash_size );
198
+
199
+ is_device_cert_model = false;
200
+ if ((spdm_context -> local_context .capability .flags &
201
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP ) == 0 ) {
202
+ is_device_cert_model = true;
203
+ }
184
204
185
205
#if LIBSPDM_CERT_PARSE_SUPPORT
186
- /*check the cert_chain*/
187
- result = libspdm_set_cert_verify_certchain (cert_chain , cert_chain_size ,
188
- spdm_context -> connection_info .algorithm .base_asym_algo ,
189
- spdm_context -> connection_info .algorithm .base_hash_algo ,
190
- is_device_cert_model );
191
- if (!result ) {
192
- return libspdm_generate_error_response (spdm_context ,
193
- SPDM_ERROR_CODE_UNSPECIFIED , 0 ,
194
- response_size , response );
195
- }
206
+ /*check the cert_chain*/
207
+ result = libspdm_set_cert_verify_certchain (cert_chain , cert_chain_size ,
208
+ spdm_context -> connection_info .algorithm .base_asym_algo ,
209
+ spdm_context -> connection_info .algorithm .base_hash_algo ,
210
+ is_device_cert_model );
211
+ if (!result ) {
212
+ return libspdm_generate_error_response (spdm_context ,
213
+ SPDM_ERROR_CODE_UNSPECIFIED , 0 ,
214
+ response_size , response );
215
+ }
196
216
#endif /*LIBSPDM_CERT_PARSE_SUPPORT*/
197
217
198
- /* set certificate to NV*/
199
- result = libspdm_write_certificate_to_nvm (slot_id , cert_chain ,
200
- cert_chain_size ,
201
- spdm_context -> connection_info .algorithm .base_hash_algo ,
202
- spdm_context -> connection_info .algorithm .base_asym_algo );
203
- if (!result ) {
204
- return libspdm_generate_error_response (spdm_context ,
205
- SPDM_ERROR_CODE_UNSPECIFIED , 0 ,
206
- response_size , response );
218
+ /* set certificate to NV*/
219
+ result = libspdm_write_certificate_to_nvm (slot_id , cert_chain ,
220
+ cert_chain_size ,
221
+ spdm_context -> connection_info .algorithm .base_hash_algo ,
222
+ spdm_context -> connection_info .algorithm .base_asym_algo );
223
+ if (!result ) {
224
+ return libspdm_generate_error_response (spdm_context ,
225
+ SPDM_ERROR_CODE_UNSPECIFIED , 0 ,
226
+ response_size , response );
227
+ }
207
228
}
208
229
209
230
LIBSPDM_ASSERT (* response_size >= sizeof (spdm_set_certificate_response_t ));
0 commit comments