vtpmmgr: Support GetRandom passthrough on TPM 2.0
authorJason Andryuk <jandryuk@gmail.com>
Thu, 6 May 2021 13:59:19 +0000 (09:59 -0400)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 10 May 2021 13:50:27 +0000 (14:50 +0100)
commit64d00dd126b3dfa4370805f1dc3d7c1ddb6a130d
tree4bdcada6f8b22116c4279f4399efabad5b9b6321
parent1b4bfa0b8f6a47c2b80bdc203bb0487fe1bd4366
vtpmmgr: Support GetRandom passthrough on TPM 2.0

GetRandom passthrough currently fails when using vtpmmgr with a hardware
TPM 2.0.
vtpmmgr (8): INFO[VTPM]: Passthrough: TPM_GetRandom
vtpm (12): vtpm_cmd.c:120: Error: TPM_GetRandom() failed with error code (30)

When running on TPM 2.0 hardware, vtpmmgr needs to convert the TPM 1.2
TPM_ORD_GetRandom into a TPM2 TPM_CC_GetRandom command.  Besides the
differing ordinal, the TPM 1.2 uses 32bit sizes for the request and
response (vs. 16bit for TPM2).

Place the random output directly into the tpmcmd->resp and build the
packet around it.  This avoids bouncing through an extra buffer, but the
header has to be written after grabbing the random bytes so we have the
number of bytes to include in the size.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed by: Daniel P. Smith <dpsmith@apertussolutions.com>
stubdom/vtpmmgr/marshal.h
stubdom/vtpmmgr/vtpm_cmd_handler.c