Skip to content

Commit c1c1faa

Browse files
committed
Add verify cert callback function for DiceTcbInfo.
Refer the spec https://trustedcomputinggroup.org/resource/dice-attestation-architecture/ add verify cert callback function for Cert extentison DiceTcbInfo check. Signed-off-by: Wenxing Hou <[email protected]>
1 parent 828ef62 commit c1c1faa

File tree

6 files changed

+552
-0
lines changed

6 files changed

+552
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ else()
940940
ADD_SUBDIRECTORY(unit_test/test_spdm_fips)
941941
ADD_SUBDIRECTORY(unit_test/test_spdm_secured_message)
942942
ADD_SUBDIRECTORY(unit_test/test_spdm_vendor_cmds)
943+
ADD_SUBDIRECTORY(unit_test/test_spdm_callback)
943944
endif()
944945

945946
if((NOT TOOLCHAIN STREQUAL "ARM_DS2022") AND (NOT TOOLCHAIN STREQUAL "RISCV_XPACK"))

unit_test/spdm_unit_test_common/spdm_unit_test.h

+35
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,39 @@ typedef enum
161161
void libspdm_force_error (libspdm_error_target_t target);
162162
void libspdm_release_error (libspdm_error_target_t target);
163163

164+
/**
165+
* The callback function for verifying cert_chain DiceTcbInfo extension.
166+
*
167+
* @param spdm_context A pointer to the SPDM context.
168+
* @param slot_id The number of slot for the certificate chain.
169+
* This params is not uesed, just for compatible in this function.
170+
* @param cert_chain_size size in bytes of the certificate chain buffer.
171+
* @param cert_chain Certificate chain buffer including spdm_cert_chain_t header.
172+
* @param trust_anchor A buffer to hold the trust_anchor which is used to validate the peer certificate, if not NULL.
173+
* @param trust_anchor_size A buffer to hold the trust_anchor_size, if not NULL.
174+
*
175+
* @retval true The certificate chain buffer DiceTcbInfo extension verification passed.
176+
* @retval false The certificate chain buffer DiceTcbInfo extension verification failed.
177+
**/
178+
bool libspdm_verify_spdm_cert_chain_with_dice(void *spdm_context, uint8_t slot_id,
179+
size_t cert_chain_size, const void *cert_chain,
180+
const void **trust_anchor,
181+
size_t *trust_anchor_size);
182+
183+
/**
184+
* verify cert DiceTcbInfo extension.
185+
*
186+
* @param[in] cert Pointer to the DER-encoded X509 certificate.
187+
* @param[in] cert_size Size of the X509 certificate in bytes.
188+
* @param[in, out] spdm_get_dice_tcb_info_size DiceTcbInfo Extension bytes size.
189+
*
190+
* @retval true If the returned spdm_get_dice_tcb_info_size == 0, it means that cert is valid, but cert doesn't have DiceTcbInfo extension;
191+
* If the returned spdm_get_dice_tcb_info_size != 0, it means that cert is valid, and the DiceTcbInfo extension is found;
192+
* And the cert DiceTcbInfo extension includes all fields in the reference TcbInfo.
193+
* @retval false If the returned spdm_get_dice_tcb_info_size == 0, it means that cert are invalid;
194+
* If the returned spdm_get_dice_tcb_info_size != 0, it means that cert is valid, and the DiceTcbInfo extension is found;
195+
* But the cert DiceTcbInfo extension doesn't include all fields in the reference TcbInfo.
196+
**/
197+
bool libspdm_verify_cert_dicetcbinfo(const void *cert, size_t cert_size,
198+
size_t *spdm_get_dice_tcb_info_size);
164199
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
cmake_minimum_required(VERSION 2.8.12)
2+
3+
INCLUDE_DIRECTORIES(${LIBSPDM_DIR}/include
4+
${LIBSPDM_DIR}/unit_test/include
5+
${LIBSPDM_DIR}/os_stub/spdm_device_secret_lib_sample
6+
${LIBSPDM_DIR}/unit_test/cmockalib/cmocka/include
7+
${LIBSPDM_DIR}/unit_test/cmockalib/cmocka/include/cmockery
8+
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common
9+
${LIBSPDM_DIR}/os_stub/include
10+
${LIBSPDM_DIR}/os_stub
11+
)
12+
13+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
14+
if((TOOLCHAIN STREQUAL "VS2015") OR (TOOLCHAIN STREQUAL "VS2019") OR (TOOLCHAIN STREQUAL "VS2022"))
15+
ADD_COMPILE_OPTIONS(/wd4819)
16+
endif()
17+
endif()
18+
19+
SET(src_test_spdm_callback
20+
test_spdm_callback.c
21+
spdm_cert_verify_callback.c
22+
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common/support.c
23+
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common/algo.c
24+
)
25+
26+
SET(test_spdm_callback_LIBRARY
27+
memlib
28+
debuglib
29+
spdm_crypt_lib
30+
${CRYPTO_LIB_PATHS}
31+
cryptlib_${CRYPTO}
32+
rnglib
33+
malloclib
34+
cmockalib
35+
spdm_device_secret_lib_sample
36+
spdm_crypt_ext_lib
37+
spdm_common_lib
38+
spdm_secured_message_lib
39+
)
40+
41+
if(TOOLCHAIN STREQUAL "ARM_DS2022")
42+
SET(test_spdm_callback_LIBRARY ${test_spdm_callback_LIBRARY} armbuild_lib)
43+
endif()
44+
45+
if((TOOLCHAIN STREQUAL "KLEE") OR (TOOLCHAIN STREQUAL "CBMC"))
46+
ADD_EXECUTABLE(test_spdm_callback
47+
${src_test_spdm_callback}
48+
$<TARGET_OBJECTS:memlib>
49+
$<TARGET_OBJECTS:debuglib>
50+
$<TARGET_OBJECTS:spdm_crypt_lib>
51+
$<TARGET_OBJECTS:${CRYPTO_LIB_PATHS}>
52+
$<TARGET_OBJECTS:rnglib>
53+
$<TARGET_OBJECTS:cryptlib_${CRYPTO}>
54+
$<TARGET_OBJECTS:malloclib>
55+
)
56+
else()
57+
ADD_EXECUTABLE(test_spdm_callback ${src_test_spdm_callback})
58+
TARGET_LINK_LIBRARIES(test_spdm_callback ${test_spdm_callback_LIBRARY})
59+
endif()
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## This is reference implementation to verify CertChain DiceTcbInfo extension.
2+
3+
### DiceTcbInfo extension Spec
4+
[DICE Attestation Architecture](https://trustedcomputinggroup.org/wp-content/uploads/DICE-Attestation-Architecture-Version-1.1-Revision-18_pub.pdf)
5+
6+
### Implementation Assumption
7+
1) **Reference TcbInfo.**
8+
9+
- Only one reference TcbInfo entry is provided by the integrator. (Multiple reference TcbInfo is NOT supported in this Implementation.)
10+
2) **Reported TcbInfo**
11+
12+
- Reported TcbInfo must be in at least one certificate.
13+
- If none of the certificates includes TcbInfo, the verification must fail.
14+
3) **TcbInfo Matching**
15+
16+
- At least one reported TcbInfo must fully match the reference TcbInfo.
17+
- If none of the reported TcbInfos matches all fields in the reference TcbInfo, the verification must fail.
18+
- Once one of the reported TcbInfo fully matches, the verification must pass and the rests of reported TcbInfo must be ignored.
19+
4) **TcbInfo Field**
20+
21+
- The reported TcbInfo must include all fields in the reference TcbInfo. If a field in the reference TcbInfo does not exist in the reported TcbInfo, the verification must fail.
22+
- The reported TcbInfo could include more fields which do not exist in the reference TcbInfo. The extra fields in the reported TcbInfo must be ignored and NOT validated, and they must not impact the final result.
23+
24+
25+
### Note
26+
1) The implementaion is just for Openssl Crypto Library.
27+
2) To verify the CertChain DiceTcbInfo extension, please use the following command to build.
28+
```
29+
cmake -G"NMake Makefiles" -DARCH=x64 -DTOOLCHAIN=VS2019 -DTARGET=Debug -DCRYPTO=openssl -DX509_IGNORE_CRITICAL=ON ..
30+
```
31+
32+
```
33+
cmake -G"NMake Makefiles" -DARCH=x64 -DTOOLCHAIN=VS2019 -DTARGET=Release -DCRYPTO=openssl -DX509_IGNORE_CRITICAL=ON ..
34+
```

0 commit comments

Comments
 (0)