Skip to content

Commit f64f30e

Browse files
committed
Fix to add userWithAuth enforcement
1 parent f6900d5 commit f64f30e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/fwtpm/fwtpm_command.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12788,6 +12788,33 @@ int FWTPM_ProcessCommand(FWTPM_CTX* ctx,
1278812788
}
1278912789
#endif
1279012790

12791+
/* userWithAuth enforcement: per TPM 2.0 spec Part 1, Section 19.7.1,
12792+
* if an object has authPolicy set and userWithAuth is CLEAR, only a
12793+
* policy session can authorize the object. Reject password and HMAC
12794+
* sessions for such objects. */
12795+
for (pj = 0; pj < cmdAuthCnt && pj < (int)entry->authHandleCnt; pj++) {
12796+
if (cmdAuths[pj].handle == TPM_RS_PW ||
12797+
(cmdAuths[pj].sess != NULL &&
12798+
cmdAuths[pj].sess->sessionType == TPM_SE_HMAC)) {
12799+
TPM_HANDLE entityH = cmdHandles[pj];
12800+
FWTPM_Object* uwObj = NULL;
12801+
if ((entityH & 0xFF000000) == (TRANSIENT_FIRST & 0xFF000000) ||
12802+
(entityH & 0xFF000000) == (PERSISTENT_FIRST & 0xFF000000)) {
12803+
uwObj = FwFindObject(ctx, entityH);
12804+
}
12805+
if (uwObj != NULL && uwObj->pub.authPolicy.size > 0 &&
12806+
!(uwObj->pub.objectAttributes & TPMA_OBJECT_userWithAuth)) {
12807+
#ifdef DEBUG_WOLFTPM
12808+
printf("fwTPM: Password/HMAC auth rejected for handle "
12809+
"0x%x — policy required (userWithAuth clear)\n", entityH);
12810+
#endif
12811+
*rspSize = FwBuildErrorResponse(rspBuf,
12812+
TPM_ST_NO_SESSIONS, TPM_RC_AUTH_UNAVAILABLE);
12813+
return TPM_RC_SUCCESS;
12814+
}
12815+
}
12816+
}
12817+
1279112818
/* Password auth validation: for password sessions (TPM_RS_PW),
1279212819
* verify the password matches the entity's authValue.
1279312820
* Per TPM 2.0 spec Part 1, Section 19.8.4: password authorization

0 commit comments

Comments
 (0)