Skip to content

Commit b24ed56

Browse files
committed
Merge libspdm_get_certificate_ex with libspdm_get_certificate_choose_length_ex
Signed-off-by: Shital Jumbad <[email protected]>
1 parent 6ea62c2 commit b24ed56

File tree

5 files changed

+32
-72
lines changed

5 files changed

+32
-72
lines changed

doc/api/requester_api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ libspdm will perform the following checks over the leaf certificate.
102102
<br/><br/>
103103

104104
---
105-
### libspdm_get_certificate_choose_length_ex
105+
### libspdm_get_certificate_ex
106106
---
107107

108108
### Description
@@ -120,7 +120,7 @@ Indicates if it is a secured message (non-NULL) or an unsecured message (NULL).
120120
The certificate chain slot number.
121121

122122
**length**<br/>
123-
The length of the certificate chain block to be retrieved.
123+
The length of the certificate chain block to be retrieved. If `length` is 0, libspdm uses the default maximum block size.
124124

125125
**cert_chain_size**<br/>
126126
On input, indicates the size, in bytes, of the buffer in which the certificate chain will be stored.

include/library/spdm_requester_lib.h

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2025 DMTF. All rights reserved.
3+
* Copyright 2021-2026 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -108,63 +108,36 @@ libspdm_return_t libspdm_get_certificate(void *spdm_context,
108108
size_t *cert_chain_size,
109109
void *cert_chain);
110110

111-
/**
112-
* This function sends GET_CERTIFICATE to get certificate chain in one slot from device.
113-
*
114-
* This function verify the integrity of the certificate chain.
115-
* root_hash -> Root certificate -> Intermediate certificate -> Leaf certificate.
116-
*
117-
* If the peer root certificate hash is deployed,
118-
* this function also verifies the digest with the root hash in the certificate chain.
119-
*
120-
* @param spdm_context A pointer to the SPDM context.
121-
* @param session_id Indicates if it is a secured message protected via SPDM session.
122-
* If session_id is NULL, it is a normal message.
123-
* @param slot_id The number of slot for the certificate chain.
124-
* @param cert_chain_size On input, indicate the size in bytes of the destination buffer to store the digest buffer.
125-
* On output, indicate the size in bytes of the certificate chain.
126-
* @param cert_chain A pointer to a destination buffer to store the certificate chain.
127-
* @param trust_anchor A buffer to hold the trust_anchor which is used to validate the peer certificate, if not NULL.
128-
* @param trust_anchor_size A buffer to hold the trust_anchor_size, if not NULL.
129-
**/
130-
libspdm_return_t libspdm_get_certificate_ex(void *spdm_context,
131-
const uint32_t *session_id,
132-
uint8_t slot_id,
133-
size_t *cert_chain_size,
134-
void *cert_chain,
135-
const void **trust_anchor,
136-
size_t *trust_anchor_size);
137-
138111
/**
139112
* This function sends GET_CERTIFICATE to get certificate chain in one slot from the device,
140113
* and allows the Integrator to specify the size of the certificate chain blocks.
141114
*
142-
* This function verify the integrity of the certificate chain.
115+
* This function verifies the integrity of the certificate chain:
143116
* root_hash -> Root certificate -> Intermediate certificate -> Leaf certificate.
144117
*
145-
* If the peer root certificate hash is deployed,
146-
* this function also verifies the digest with the root hash in the certificate chain.
118+
* If the peer root certificate hash is deployed, this function also verifies the digest with the
119+
* root hash in the certificate chain.
147120
*
148121
* @param spdm_context A pointer to the SPDM context.
149122
* @param session_id Indicates if it is a secured message protected via SPDM session.
150123
* If session_id is NULL, it is a normal message.
151124
* @param slot_id The number of slot for the certificate chain.
152125
* @param length The length of the certificate chain block to retrieve.
153126
* If length is 0, the default maximum block size will be used.
154-
* @param cert_chain_size On input, indicate the size in bytes of the destination buffer to store the digest buffer.
127+
* @param cert_chain_size On input, indicate the size in bytes of the destination buffer.
155128
* On output, indicate the size in bytes of the certificate chain.
156129
* @param cert_chain A pointer to a destination buffer to store the certificate chain.
157130
* @param trust_anchor A buffer to hold the trust_anchor which is used to validate the peer certificate, if not NULL.
158131
* @param trust_anchor_size A buffer to hold the trust_anchor_size, if not NULL.
159132
**/
160-
libspdm_return_t libspdm_get_certificate_choose_length_ex(void *spdm_context,
161-
const uint32_t *session_id,
162-
uint8_t slot_id,
163-
uint32_t length,
164-
size_t *cert_chain_size,
165-
void *cert_chain,
166-
const void **trust_anchor,
167-
size_t *trust_anchor_size);
133+
libspdm_return_t libspdm_get_certificate_ex(void *spdm_context,
134+
const uint32_t *session_id,
135+
uint8_t slot_id,
136+
uint32_t length,
137+
size_t *cert_chain_size,
138+
void *cert_chain,
139+
const void **trust_anchor,
140+
size_t *trust_anchor_size);
168141
#endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
169142

170143
#if LIBSPDM_SEND_CHALLENGE_SUPPORT

library/spdm_requester_lib/libspdm_req_get_certificate.c

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2025 DMTF. All rights reserved.
3+
* Copyright 2021-2026 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -500,36 +500,13 @@ static libspdm_return_t libspdm_try_get_large_certificate(libspdm_context_t *spd
500500
return status;
501501
}
502502

503-
libspdm_return_t libspdm_get_certificate(void *spdm_context, const uint32_t *session_id,
504-
uint8_t slot_id,
505-
size_t *cert_chain_size,
506-
void *cert_chain)
507-
{
508-
return libspdm_get_certificate_choose_length_ex(spdm_context, session_id, slot_id,
509-
0, cert_chain_size, cert_chain,
510-
NULL, NULL);
511-
}
512-
513503
libspdm_return_t libspdm_get_certificate_ex(void *spdm_context, const uint32_t *session_id,
514504
uint8_t slot_id,
505+
uint32_t length,
515506
size_t *cert_chain_size,
516507
void *cert_chain,
517508
const void **trust_anchor,
518509
size_t *trust_anchor_size)
519-
{
520-
return libspdm_get_certificate_choose_length_ex(spdm_context, session_id, slot_id,
521-
0, cert_chain_size, cert_chain,
522-
trust_anchor, trust_anchor_size);
523-
}
524-
525-
libspdm_return_t libspdm_get_certificate_choose_length_ex(void *spdm_context,
526-
const uint32_t *session_id,
527-
uint8_t slot_id,
528-
uint32_t length,
529-
size_t *cert_chain_size,
530-
void *cert_chain,
531-
const void **trust_anchor,
532-
size_t *trust_anchor_size)
533510
{
534511
libspdm_context_t *context;
535512
size_t retry;
@@ -554,4 +531,14 @@ libspdm_return_t libspdm_get_certificate_choose_length_ex(void *spdm_context,
554531
return status;
555532
}
556533

534+
libspdm_return_t libspdm_get_certificate(void *spdm_context, const uint32_t *session_id,
535+
uint8_t slot_id,
536+
size_t *cert_chain_size,
537+
void *cert_chain)
538+
{
539+
return libspdm_get_certificate_ex(spdm_context, session_id, slot_id, 0,
540+
cert_chain_size, cert_chain,
541+
NULL, NULL);
542+
}
543+
557544
#endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */

unit_test/fuzzing/test_requester/test_spdm_requester_get_certificate/get_certificate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void libspdm_test_requester_get_certificate_ex_case1(void **State)
300300

301301
cert_chain_size = sizeof(cert_chain);
302302
libspdm_zero_mem(cert_chain, sizeof(cert_chain));
303-
libspdm_get_certificate_ex(spdm_context, NULL, 0, &cert_chain_size, cert_chain,NULL,NULL);
303+
libspdm_get_certificate_ex(spdm_context, NULL, 0, 0, &cert_chain_size, cert_chain, NULL, NULL);
304304

305305
free(data);
306306
libspdm_reset_message_b(spdm_context);
@@ -394,7 +394,7 @@ void libspdm_test_requester_get_certificate_in_session_case1(void **State)
394394
#endif
395395
cert_chain_size = sizeof(cert_chain);
396396
libspdm_zero_mem(cert_chain, sizeof(cert_chain));
397-
libspdm_get_certificate_ex(spdm_context, &session_id, 0, &cert_chain_size, cert_chain,
397+
libspdm_get_certificate_ex(spdm_context, &session_id, 0, 0, &cert_chain_size, cert_chain,
398398
NULL, NULL);
399399

400400
free(data);

unit_test/test_spdm_requester/get_certificate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2025 DMTF. All rights reserved.
3+
* Copyright 2021-2026 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -3250,7 +3250,7 @@ static void req_get_certificate_case14(void **state)
32503250

32513251
cert_chain_size = sizeof(cert_chain);
32523252
libspdm_zero_mem(cert_chain, sizeof(cert_chain));
3253-
status = libspdm_get_certificate_choose_length_ex(
3253+
status = libspdm_get_certificate_ex(
32543254
spdm_context, NULL, 0, get_cert_length,
32553255
&cert_chain_size, cert_chain, NULL, NULL);
32563256
/* It may fail because the spdm does not support too many messages.
@@ -4126,7 +4126,7 @@ static void req_get_certificate_case26(void **state)
41264126
cert_chain_size = sizeof(cert_chain);
41274127
libspdm_zero_mem(cert_chain, sizeof(cert_chain));
41284128
status = libspdm_get_certificate_ex(spdm_context, &session_id,
4129-
0, &cert_chain_size,
4129+
0, 0, &cert_chain_size,
41304130
cert_chain, NULL, 0);
41314131
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
41324132
#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT

0 commit comments

Comments
 (0)