Skip to content

Commit 02dddb6

Browse files
committed
copilot review feedback
1 parent 5ee1a25 commit 02dddb6

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

docs/draft/wrapped-certs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This documents the "wrapped certificate" use case, showing how to leverage the
66
certificate manager to use trusted root certificates that live in the server's
7-
**keystore cache** (RAM) after being unwrapped via keywrap funcitonality,
7+
**keystore cache** (RAM) after being unwrapped via keywrap functionality,
88
rather than exclusively in **NVM** (flash). A root certificate is wrapped
99
(AES-GCM encrypted) by the server, handed back to the client as an opaque blob,
1010
and later unwrapped into the server's key cache on demand. Once cached, it can
@@ -196,7 +196,7 @@ updated with the same pattern:
196196
197197
1. **Translate the client ID**: If the incoming `req.id` (or
198198
`req.trustedRootNvmId`) has `WH_KEYID_CLIENT_WRAPPED_FLAG` set, call
199-
`wh_KeyId_TranslateFromClient(WH_KEYTYPE_NVM, server->comm->client_id, req.id)`
199+
`wh_KeyId_TranslateFromClient(WH_KEYTYPE_WRAPPED, server->comm->client_id, req.id)`
200200
to produce a full server-internal key ID with `TYPE=WH_KEYTYPE_WRAPPED`,
201201
`USER=client_id`, and the bare key `ID` in the low byte.
202202

src/wh_client_cert.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@ int wh_Client_CertUnwrapAndExportResponse(whClientContext* ctx,
10351035
uint8_t* certOut,
10361036
uint16_t* inout_certSz)
10371037
{
1038-
if ((ctx == NULL) || (certOut == NULL) || (inout_certSz == NULL)) {
1038+
if ((ctx == NULL) || (metadataOut == NULL) || (certOut == NULL) ||
1039+
(inout_certSz == NULL)) {
10391040
return WH_ERROR_BADARGS;
10401041
}
10411042

@@ -1051,7 +1052,7 @@ int wh_Client_CertUnwrapAndExport(
10511052
int rc;
10521053

10531054
if ((ctx == NULL) || (wrappedCert == NULL) || (wrappedCertSz == 0) ||
1054-
(certOut == NULL) || (inout_certSz == NULL)) {
1055+
(metadataOut == NULL) || (certOut == NULL) || (inout_certSz == NULL)) {
10551056
return WH_ERROR_BADARGS;
10561057
}
10571058

src/wh_server_cert.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ int wh_Server_CertReadTrusted(whServerContext* server, whKeyId id,
245245
if (rc == WH_ERROR_OK) {
246246
*inout_cert_len = sz;
247247
}
248+
else if (rc == WH_ERROR_NOSPACE) {
249+
/* Map keystore error to cert API's documented error and report the
250+
* required size so the caller can retry with a larger buffer */
251+
*inout_cert_len = meta.len;
252+
rc = WH_ERROR_BUFFER_SIZE;
253+
}
248254
return rc;
249255
}
250256

@@ -256,11 +262,11 @@ int wh_Server_CertReadTrusted(whServerContext* server, whKeyId id,
256262

257263
/* Check if the provided buffer is large enough */
258264
if (meta.len > *inout_cert_len) {
265+
*inout_cert_len = meta.len;
259266
return WH_ERROR_BUFFER_SIZE;
260267
}
261268

262-
/* Clamp the input length to the actual length of the certificate. This will
263-
* be reflected back to the user on length mismatch failure */
269+
/* Clamp the input length to the actual length of the certificate */
264270
*inout_cert_len = meta.len;
265271

266272
return wh_Nvm_Read(server->nvm, id, 0, meta.len, cert);

0 commit comments

Comments
 (0)