Skip to content

Commit 5851029

Browse files
committed
copilot feedback
1 parent dd35e14 commit 5851029

3 files changed

Lines changed: 35 additions & 24 deletions

File tree

docs/draft/wrapped-certs.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ cache, not in NVM."
123123

124124
The same pattern works for:
125125
- `wh_Client_CertVerifyDma` (DMA path)
126-
- `wh_Client_CertReadTrusted` / `wh_Client_CertReadTrustedDma` (read-back)
126+
- `wh_Client_CertReadTrusted` / `wh_Client_CertReadTrustedDma` (read-back a
127+
cached cert by passing `WH_CLIENT_KEYID_MAKE_WRAPPED(cachedCertId)` as the
128+
`id` parameter)
127129
- `wh_Client_CertVerifyAcert` / `wh_Client_CertVerifyAcertDma` (attribute certs)
128130

129131
### 5. Cleanup

src/wh_client_cert.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ int wh_Client_CertEraseTrusted(whClientContext* c, whNvmId id, int32_t* out_rc)
276276
}
277277

278278
/* Get a trusted certificate */
279-
int wh_Client_CertReadTrustedRequest(whClientContext* c, whNvmId id,
279+
int wh_Client_CertReadTrustedRequest(whClientContext* c, whKeyId id,
280280
uint32_t cert_len)
281281
{
282282
(void)cert_len;
@@ -339,7 +339,7 @@ int wh_Client_CertReadTrustedResponse(whClientContext* c, uint8_t* cert,
339339
return rc;
340340
}
341341

342-
int wh_Client_CertReadTrusted(whClientContext* c, whNvmId id, uint8_t* cert,
342+
int wh_Client_CertReadTrusted(whClientContext* c, whKeyId id, uint8_t* cert,
343343
uint32_t* cert_len, int32_t* out_rc)
344344
{
345345
int rc = 0;
@@ -593,7 +593,7 @@ int wh_Client_CertAddTrustedDma(whClientContext* c, whNvmId id,
593593
return rc;
594594
}
595595

596-
int wh_Client_CertReadTrustedDmaRequest(whClientContext* c, whNvmId id,
596+
int wh_Client_CertReadTrustedDmaRequest(whClientContext* c, whKeyId id,
597597
void* cert, uint32_t cert_len)
598598
{
599599
whMessageCert_ReadTrustedDmaRequest req = {0};
@@ -641,7 +641,7 @@ int wh_Client_CertReadTrustedDmaResponse(whClientContext* c, int32_t* out_rc)
641641
return rc;
642642
}
643643

644-
int wh_Client_CertReadTrustedDma(whClientContext* c, whNvmId id, void* cert,
644+
int wh_Client_CertReadTrustedDma(whClientContext* c, whKeyId id, void* cert,
645645
uint32_t cert_len, int32_t* out_rc)
646646
{
647647
int rc = 0;

wolfhsm/wh_client.h

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,18 +1993,20 @@ int wh_Client_CertEraseTrustedResponse(whClientContext* c, int32_t* out_rc);
19931993
int wh_Client_CertEraseTrusted(whClientContext* c, whNvmId id, int32_t* out_rc);
19941994

19951995
/**
1996-
* @brief Sends a request to read a trusted certificate from NVM storage.
1996+
* @brief Sends a request to read a trusted certificate.
19971997
*
1998-
* This function prepares and sends a request to read a trusted certificate
1999-
* from NVM storage. This function does not block; it returns immediately after
2000-
* sending the request.
1998+
* This function prepares and sends a request to read a trusted certificate.
1999+
* The id parameter accepts either an NVM ID for certificates stored in NVM,
2000+
* or a wrapped/cached key ID (via WH_CLIENT_KEYID_MAKE_WRAPPED()) for
2001+
* certificates cached through wh_Client_CertUnwrapAndCache(). This function
2002+
* does not block; it returns immediately after sending the request.
20012003
*
20022004
* @param[in] c Pointer to the client context.
2003-
* @param[in] id The NVM ID of the certificate to retrieve.
2005+
* @param[in] id The key ID of the certificate to retrieve (NVM or wrapped).
20042006
* @param[in] cert_len Maximum length of the certificate buffer.
20052007
* @return int Returns 0 on success, or a negative error code on failure.
20062008
*/
2007-
int wh_Client_CertReadTrustedRequest(whClientContext* c, whNvmId id,
2009+
int wh_Client_CertReadTrustedRequest(whClientContext* c, whKeyId id,
20082010
uint32_t cert_len);
20092011

20102012
/**
@@ -2031,17 +2033,20 @@ int wh_Client_CertReadTrustedResponse(whClientContext* c, uint8_t* cert,
20312033
*
20322034
* This function handles the complete process of sending a request to read a
20332035
* trusted certificate and receiving the response. It blocks until the entire
2034-
* operation is complete or an error occurs.
2036+
* operation is complete or an error occurs. The id parameter accepts either an
2037+
* NVM ID for certificates stored in NVM, or a wrapped/cached key ID (via
2038+
* WH_CLIENT_KEYID_MAKE_WRAPPED()) for certificates cached through
2039+
* wh_Client_CertUnwrapAndCache().
20352040
*
20362041
* @param[in] c Pointer to the client context.
2037-
* @param[in] id The NVM ID of the certificate to retrieve.
2042+
* @param[in] id The key ID of the certificate to retrieve (NVM or wrapped).
20382043
* @param[out] cert Pointer to store the certificate data.
20392044
* @param[in,out] cert_len Pointer to the maximum length of the certificate
20402045
* buffer. On output, contains the actual length of the certificate.
20412046
* @param[out] out_rc Pointer to store the response code from the server.
20422047
* @return int Returns 0 on success, or a negative error code on failure.
20432048
*/
2044-
int wh_Client_CertReadTrusted(whClientContext* c, whNvmId id, uint8_t* cert,
2049+
int wh_Client_CertReadTrusted(whClientContext* c, whKeyId id, uint8_t* cert,
20452050
uint32_t* cert_len, int32_t* out_rc);
20462051

20472052
/**
@@ -2219,20 +2224,21 @@ int wh_Client_CertAddTrustedDma(whClientContext* c, whNvmId id,
22192224
int32_t* out_rc);
22202225

22212226
/**
2222-
* @brief Sends a request to read a trusted certificate from NVM storage using
2223-
* DMA.
2227+
* @brief Sends a request to read a trusted certificate using DMA.
22242228
*
2225-
* This function prepares and sends a request to read a trusted certificate from
2226-
* NVM storage using DMA. This function does not block; it returns immediately
2227-
* after sending the request.
2229+
* This function prepares and sends a request to read a trusted certificate
2230+
* using DMA. The id parameter accepts either an NVM ID for certificates stored
2231+
* in NVM, or a wrapped/cached key ID (via WH_CLIENT_KEYID_MAKE_WRAPPED()) for
2232+
* certificates cached through wh_Client_CertUnwrapAndCache(). This function
2233+
* does not block; it returns immediately after sending the request.
22282234
*
22292235
* @param[in] c Pointer to the client context.
2230-
* @param[in] id NVM ID of the trusted certificate to get.
2236+
* @param[in] id The key ID of the trusted certificate to get (NVM or wrapped).
22312237
* @param[in] cert Pointer to buffer to store the certificate data.
22322238
* @param[in] cert_len Length of the certificate buffer.
22332239
* @return int Returns 0 on success, or a negative error code on failure.
22342240
*/
2235-
int wh_Client_CertReadTrustedDmaRequest(whClientContext* c, whNvmId id,
2241+
int wh_Client_CertReadTrustedDmaRequest(whClientContext* c, whKeyId id,
22362242
void* cert, uint32_t cert_len);
22372243

22382244
/**
@@ -2256,16 +2262,19 @@ int wh_Client_CertReadTrustedDmaResponse(whClientContext* c, int32_t* out_rc);
22562262
*
22572263
* This function handles the complete process of sending a request to read a
22582264
* trusted certificate using DMA and receiving the response. It blocks until the
2259-
* entire operation is complete or an error occurs.
2265+
* entire operation is complete or an error occurs. The id parameter accepts
2266+
* either an NVM ID for certificates stored in NVM, or a wrapped/cached key ID
2267+
* (via WH_CLIENT_KEYID_MAKE_WRAPPED()) for certificates cached through
2268+
* wh_Client_CertUnwrapAndCache().
22602269
*
22612270
* @param[in] c Pointer to the client context.
2262-
* @param[in] id NVM ID of the trusted certificate to get.
2271+
* @param[in] id The key ID of the trusted certificate to get (NVM or wrapped).
22632272
* @param[in] cert Pointer to buffer to store the certificate data.
22642273
* @param[in] cert_len Length of the certificate buffer.
22652274
* @param[out] out_rc Pointer to store the response code from the server.
22662275
* @return int Returns 0 on success, or a negative error code on failure.
22672276
*/
2268-
int wh_Client_CertReadTrustedDma(whClientContext* c, whNvmId id, void* cert,
2277+
int wh_Client_CertReadTrustedDma(whClientContext* c, whKeyId id, void* cert,
22692278
uint32_t cert_len, int32_t* out_rc);
22702279

22712280
/**

0 commit comments

Comments
 (0)