Skip to content

Commit c8dcf5b

Browse files
committed
Address feedback copilot x daniele - NOT TESTED YET NEED TO TEST CHANGES
- NATIONS_PSK mode check (tpm2_spdm.c) - Only affects PSK mode which was already broken (raw path instead of VENDOR_DEFINED) - END_SESSION (tpm2_wrap.c) - New behavior but only adds an END_SESSION before the existing cleanup. If it fails, cleanup still proceeds. - Nations auto-connect (tpm2_wrap.c:279) - Only fires when spdmOnlyDetected is true (TPM locked in SPDM-only mode and TPM2_Startup returned TPM_RC_DISABLED). Normal operation never hits this path. - VdCode validation (spdm_tcg.c) - This one could theoretically break something if a response VdCode doesn't match. But all callers like wolfSPDM_TCG_GetPubKey() already validate VdCode independently (line 316-321), so the existing code was already checking this for specific commands. - VCA skip in PSK (spdm_psk.c) - Changes the transcript hash. Needs firmware 0.1.0.16 + NS350 to also skip VCA. Vision confirmed this works. - TPM_CMD_Lx defines / comments - No behavioral change.
1 parent ebedd63 commit c8dcf5b

6 files changed

Lines changed: 28 additions & 14 deletions

File tree

examples/spdm/spdm_ctrl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ int TPM2_SPDM_Ctrl(void* userCtx, int argc, char *argv[])
621621
if (rc != 0) break;
622622
}
623623

624-
wolfTPM2_Cleanup(&dev); /* Shutdown goes through SPDM if session active */
625-
wolfTPM2_SpdmCleanup(&dev);
624+
wolfTPM2_Cleanup(&dev); /* TPM2_Shutdown + END_SESSION via SPDM, then free */
625+
wolfTPM2_SpdmCleanup(&dev); /* no-op safety net (already freed by Cleanup) */
626626
return rc;
627627
}
628628

src/spdm/spdm_psk.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,11 @@ int wolfSPDM_ConnectPsk(WOLFSPDM_CTX* ctx)
349349
SPDM_CONNECT_STEP(ctx, "PSK Step 1: GET_VERSION\n",
350350
wolfSPDM_GetVersion(ctx));
351351

352-
/* Step 2: GET_CAPABILITIES (with PSK_CAP flag) */
353-
SPDM_CONNECT_STEP(ctx, "PSK Step 2: GET_CAPABILITIES\n",
354-
wolfSPDM_TCG_GetCapabilities(ctx, WOLFSPDM_TCG_CAPS_FLAGS_PSK));
352+
/* Steps 2-3: GET_CAPABILITIES + NEGOTIATE_ALGORITHMS
353+
* Not mandatory for PSK mode per TCG PC Client PSK spec.
354+
* NS350 supports direct GET_VERSION -> PSK_EXCHANGE. */
355355

356-
/* Step 3: NEGOTIATE_ALGORITHMS */
357-
SPDM_CONNECT_STEP(ctx, "PSK Step 3: NEGOTIATE_ALGORITHMS\n",
358-
wolfSPDM_TCG_NegotiateAlgorithms(ctx));
359-
360-
/* Step 4: PSK_EXCHANGE / PSK_EXCHANGE_RSP */
356+
/* Step 2: PSK_EXCHANGE / PSK_EXCHANGE_RSP */
361357
{
362358
byte txBuf[128];
363359
byte rxBuf[WOLFSPDM_VENDOR_RX_SZ];

src/spdm/spdm_tcg.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ int wolfSPDM_TCG_VendorCmdClear(WOLFSPDM_CTX* ctx, const char* vdCode,
7373
if (rc < 0) {
7474
return rc;
7575
}
76-
/* Verify response vendor code matches expected */
76+
/* Validate response VdCode matches the request */
7777
if (XMEMCMP(rsp->vdCode, vdCode, WOLFSPDM_VDCODE_LEN) != 0) {
78+
wolfSPDM_DebugPrint(ctx, "%s: unexpected VdCode '%.8s'\n",
79+
vdCode, rsp->vdCode);
7880
return WOLFSPDM_E_PEER_ERROR;
7981
}
8082
}

src/tpm2_spdm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ int wolfTPM2_SPDM_SecuredExchange(
211211
* accepts SPDM messages (starting with version byte 0x13), not raw TPM
212212
* commands (starting with tag 0x80 0x01). */
213213
if (wolfSPDM_GetMode(ctx->spdmCtx) == WOLFSPDM_MODE_NUVOTON ||
214-
wolfSPDM_GetMode(ctx->spdmCtx) == WOLFSPDM_MODE_NATIONS) {
214+
wolfSPDM_GetMode(ctx->spdmCtx) == WOLFSPDM_MODE_NATIONS ||
215+
wolfSPDM_GetMode(ctx->spdmCtx) == WOLFSPDM_MODE_NATIONS_PSK) {
215216
byte vdMsg[WOLFSPDM_MAX_MSG_SIZE];
216217
byte vdRsp[WOLFSPDM_MAX_MSG_SIZE];
217218
word32 vdRspSz = sizeof(vdRsp);

src/tpm2_wrap.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int wolfTPM2_Init(WOLFTPM2_DEV* dev, TPM2HalIoCb ioCb, void* userCtx)
317317
}
318318
rc = TPM_RC_SUCCESS;
319319
}
320-
#endif /* WOLFTPM_SPDM && WOLFSPDM_NUVOTON */
320+
#endif /* WOLFTPM_SPDM && WOLFTPM_SPDM_TCG */
321321

322322
return rc;
323323
}
@@ -1953,7 +1953,13 @@ int wolfTPM2_Cleanup_ex(WOLFTPM2_DEV* dev, int doShutdown)
19531953
}
19541954

19551955
#ifdef WOLFTPM_SPDM
1956-
/* Clean up SPDM context if it was auto-established */
1956+
/* Send END_SESSION to gracefully terminate SPDM session
1957+
* (TCG spec 5.5.1.6, Table 2: mandatory) */
1958+
if (dev->spdmCtx != NULL && dev->spdmCtx->spdmCtx != NULL &&
1959+
wolfSPDM_IsConnected(dev->spdmCtx->spdmCtx)) {
1960+
(void)wolfTPM2_SpdmDisconnect(dev);
1961+
}
1962+
/* Clean up SPDM context */
19571963
wolfTPM2_SpdmCleanup(dev);
19581964
#endif
19591965

wolftpm/spdm/spdm_tcg.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ extern "C" {
6060
#define WOLFSPDM_VDCODE_LEN 8
6161

6262
#define WOLFSPDM_VDCODE_TPM2_CMD "TPM2_CMD" /* TPM command over SPDM */
63+
64+
/* Locality-aware TPM command VdCodes (TCG spec Table 11, optional).
65+
* Response to all TPM_CMD_L* is TPM_RSP with VdCode "TPM2_CMD".
66+
* Not currently used -- our code sends TPM2_CMD for all localities. */
67+
#define WOLFSPDM_VDCODE_TPM2CMD0 "TPM2CMD0" /* TPM_CMD_L0: locality 0 */
68+
#define WOLFSPDM_VDCODE_TPM2CMD1 "TPM2CMD1" /* TPM_CMD_L1: locality 1 */
69+
#define WOLFSPDM_VDCODE_TPM2CMD2 "TPM2CMD2" /* TPM_CMD_L2: locality 2 */
70+
#define WOLFSPDM_VDCODE_TPM2CMD3 "TPM2CMD3" /* TPM_CMD_L3: locality 3 */
71+
#define WOLFSPDM_VDCODE_TPM2CMD4 "TPM2CMD4" /* TPM_CMD_L4: locality 4 */
6372
#define WOLFSPDM_VDCODE_GET_PUBK "GET_PUBK" /* Get TPM's identity key */
6473
#define WOLFSPDM_VDCODE_GIVE_PUB "GIVE_PUB" /* Give host's identity key */
6574
#define WOLFSPDM_VDCODE_GET_STS "GET_STS_" /* Get SPDM status */

0 commit comments

Comments
 (0)