@@ -147,63 +147,83 @@ 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_MASK ) != 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_SETCERTMODEL_MASK ) != 0 )) {
155
+ return libspdm_generate_error_response (spdm_context ,
156
+ SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
157
+ response_size , response );
158
+ }
156
159
157
- /*point to full SPDM certificate chain*/
158
- cert_chain = (const void * )(spdm_request + 1 );
159
- cert_chain_header = cert_chain ;
160
+ /* erase slot_id cert_chain*/
161
+ result = libspdm_erase_nvm_certificate (slot_id );
162
+ if (!result ) {
163
+ return libspdm_generate_error_response (spdm_context ,
164
+ SPDM_ERROR_CODE_OPERATION_FAILED , 0 ,
165
+ response_size , response );
166
+ }
167
+ } else {
168
+ if (request_size < sizeof (spdm_set_certificate_request_t ) +
169
+ sizeof (spdm_cert_chain_t ) + root_cert_hash_size ) {
170
+ return libspdm_generate_error_response (spdm_context ,
171
+ SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
172
+ response_size , response );
173
+ }
160
174
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
- }
175
+ /*point to full SPDM certificate chain*/
176
+ cert_chain = (const void * )(spdm_request + 1 );
177
+ cert_chain_header = cert_chain ;
171
178
172
- /*get actual cert_chain size*/
173
- cert_chain_size = cert_chain_header -> length - sizeof (spdm_cert_chain_t ) - root_cert_hash_size ;
179
+ if (cert_chain_header -> length < sizeof (spdm_cert_chain_t ) + root_cert_hash_size ) {
180
+ return libspdm_generate_error_response (spdm_context ,
181
+ SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
182
+ response_size , response );
183
+ }
184
+ if (cert_chain_header -> length > request_size - sizeof (spdm_set_certificate_request_t )) {
185
+ return libspdm_generate_error_response (spdm_context ,
186
+ SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
187
+ response_size , response );
188
+ }
174
189
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 ) ;
190
+ /*get actual cert_chain size */
191
+ cert_chain_size = cert_chain_header -> length - sizeof ( spdm_cert_chain_t ) -
192
+ root_cert_hash_size ;
178
193
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
- }
194
+ /*point to actual cert_chain*/
195
+ cert_chain = (const void * )((const uint8_t * )cert_chain
196
+ + sizeof (spdm_cert_chain_t ) + root_cert_hash_size );
197
+
198
+ is_device_cert_model = false;
199
+ if ((spdm_context -> local_context .capability .flags &
200
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP ) == 0 ) {
201
+ is_device_cert_model = true;
202
+ }
184
203
185
204
#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
- }
205
+ /*check the cert_chain*/
206
+ result = libspdm_set_cert_verify_certchain (cert_chain , cert_chain_size ,
207
+ spdm_context -> connection_info .algorithm .base_asym_algo ,
208
+ spdm_context -> connection_info .algorithm .base_hash_algo ,
209
+ is_device_cert_model );
210
+ if (!result ) {
211
+ return libspdm_generate_error_response (spdm_context ,
212
+ SPDM_ERROR_CODE_UNSPECIFIED , 0 ,
213
+ response_size , response );
214
+ }
196
215
#endif /*LIBSPDM_CERT_PARSE_SUPPORT*/
197
216
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 );
217
+ /* set certificate to NV*/
218
+ result = libspdm_write_certificate_to_nvm (slot_id , cert_chain ,
219
+ cert_chain_size ,
220
+ spdm_context -> connection_info .algorithm .base_hash_algo ,
221
+ spdm_context -> connection_info .algorithm .base_asym_algo );
222
+ if (!result ) {
223
+ return libspdm_generate_error_response (spdm_context ,
224
+ SPDM_ERROR_CODE_UNSPECIFIED , 0 ,
225
+ response_size , response );
226
+ }
207
227
}
208
228
209
229
LIBSPDM_ASSERT (* response_size >= sizeof (spdm_set_certificate_response_t ));
0 commit comments