Tss2_Sys_NV_ReadPublic returns 0x98b "The handle is not correct for the use"
AndyPearceBCN opened this issue · 6 comments
This function call fails and returns 0x98b "The handle is not correct for the use"
rc = Tss2_Sys_NV_ReadPublic(sysContext, nvIndex, cmdAuth, &nvPublic, nullptr, nullptr);
This function call, a few lines below with the same values works as expected and returns data.
rc = Tss2_Sys_NV_Read(sysContext, TPM2_RH_OWNER, nvIndex, cmdAuth, bytesToRead, offset, &nvData, NULL);
The NV Index is 0x1150001.
This command returns ...
tpm2_nvreadpublic 0x1150001
0x1150001:
name: 000b0ac1061da5139b464318b7d468261a8d062403816bf1f0795318f733d341d12d
hash algorithm:
friendly: sha256
value: 0xB
attributes:
friendly: ownerwrite|ownerread|written
value: 0x2000220
size: 1460
Is there a problem with the way I am using Tss2_Sys_NV_ReadPublic?
Thank you!
Try it with:
rc = Tss2_Sys_NV_ReadPublic(sysContext, nvIndex, nullptr, &nvPublic, nullptr, nullptr);
No auth value is needed here.
I tried your suggestion. Now I get ...
2024-03-30 09:37:33,488 INFO Cert App - Called getObjectSize with handle 0x1150001
WARNING:marshal:src/tss2-mu/tpm2b-types.c:355:Tss2_MU_TPM2B_NV_PUBLIC_Unmarshal() Size not zero
2024-03-30 09:37:33,492 ERROR Cert App - Failed to read Object size for NV index: 0x1150001 rc 0x8000b
tpm2_rc_decode 0x8000b
sys:A parameter has a bad value
Here's the complete method:
// Function to read the size of the NV object
size_t getObjectSize(TSS2_SYS_CONTEXT *sysContext, TPMI_RH_NV_INDEX nvIndex) {
TSS2_RC rc;
TPM2B_NV_PUBLIC nvPublic;
LOG4CXX_INFO(LSPAppLogger, "Called getObjectSize with handle 0x" << std::hex << nvIndex << std::dec);
// Query the size of the data in the NV index
rc = Tss2_Sys_NV_ReadPublic(sysContext, nvIndex, nullptr, &nvPublic, nullptr, nullptr);
if (rc != TSS2_RC_SUCCESS) {
LOG4CXX_ERROR(LSPAppLogger, "Failed to read Object size for NV index: 0x" << std::hex << nvIndex << " rc " << rc << std::dec);
return 0;
}
LOG4CXX_INFO(LSPAppLogger, "getObjectSize returned object size: " << nvPublic.nvPublic.dataSize);
return nvPublic.nvPublic.dataSize;
}
debug:tcti:src/tss2-tcti/tcti-device.c:449:Tss2_Tcti_Device_Init() Trying to open specified TCTI device file /dev/tpmrm0
debug:tcti:src/tss2-tcti/tcti-device.c:461:Tss2_Tcti_Device_Init() Probe device for partial response read support
debug:tcti:src/util/io.c:94:write_all() writing 12 bytes starting at 0x7ffe4c4ec094 to fd 3
debug:tcti:src/util/io.c:108:write_all() wrote 12 bytes to fd 3
debug:tcti:src/tss2-tcti/tcti-device.c:473:Tss2_Tcti_Device_Init() Command sent, reading header
debug:tcti:src/tss2-tcti/tcti-device.c:492:Tss2_Tcti_Device_Init() Header read, reading rest of response
debug:tcti:src/tss2-tcti/tcti-device.c:523:Tss2_Tcti_Device_Init() Read the rest - partial read supported
2024-03-30 09:53:14,067 INFO Cert App - TPM Abstraction is initialized
2024-03-30 09:53:14,068 INFO Cert App - Called getObjectSize with handle 0x1150001
trace:marshal:src/tss2-mu/base-types.c:179:Tss2_MU_TPM2_ST_Marshal() offset non-NULL, initial value: 0
debug:marshal:src/tss2-mu/base-types.c:179:Tss2_MU_TPM2_ST_Marshal() Marshalling TPM2_ST from 0x7ffe4c4eb74c to buffer 0x563915376040 at index 0x0
debug:marshal:src/tss2-mu/base-types.c:179:Tss2_MU_TPM2_ST_Marshal() offset parameter non-NULL, updated to 2
trace:marshal:src/tss2-mu/base-types.c:173:Tss2_MU_UINT32_Marshal() offset non-NULL, initial value: 10
debug:marshal:src/tss2-mu/base-types.c:173:Tss2_MU_UINT32_Marshal() Marshalling UINT32 from 0x7ffe4c4eb78c to buffer 0x563915376040 at index 0xa
debug:marshal:src/tss2-mu/base-types.c:173:Tss2_MU_UINT32_Marshal() offset parameter non-NULL, updated to 14
debug:tcti:src/tss2-tcti/tcti-device.c:114:tcti_device_transmit() sending 14 byte command buffer: (size=14):
0000: 80010000000e0000016901150001 .........i....
debug:tcti:src/util/io.c:94:write_all() writing 14 bytes starting at 0x563915376040 to fd 3
debug:tcti:src/util/io.c:108:write_all() wrote 14 bytes to fd 3
debug:tcti:src/tss2-tcti/tcti-device.c:183:tcti_device_receive() Partial read - reading response size
debug:tcti:src/tss2-tcti/tcti-device.c:203:tcti_device_receive() Partial read - received header
trace:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset non-NULL, initial value: 2
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() Unmarshaling UINT32 from 0x7ffe4c4eb73e to buffer 0x7ffe4c4eb724 at index 0x2
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset parameter non-NULL, updated to 6
debug:tcti:src/tss2-tcti/tcti-device.c:216:tcti_device_receive() Partial read - received response size 62.
debug:tcti:src/tss2-tcti/tcti-device.c:274:tcti_device_receive() Response Received (size=62):
0000: 80010000003e00000000000e01150001 .....>..........
0010: 000b20020002000005b40022000b0ac1 ..........."....
0020: 061da5139b464318b7d468261a8d0624 .....FC...h&...$
0030: 03816bf1f0795318f733d341d12d ..k..yS..3.A.-
trace:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() offset non-NULL, initial value: 0
debug:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() Unmarshaling TPM2_ST from 0x563915376040 to buffer 0x56391537389c at index 0x0
debug:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() offset parameter non-NULL, updated to 2
trace:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset non-NULL, initial value: 2
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() Unmarshaling UINT32 from 0x563915376040 to buffer 0x5639153738a0 at index 0x2
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset parameter non-NULL, updated to 6
trace:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset non-NULL, initial value: 6
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() Unmarshaling UINT32 from 0x563915376040 to buffer 0x5639153738a4 at index 0x6
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset parameter non-NULL, updated to 10
debug:tcti:src/tss2-tcti/tcti-device.c:288:tcti_device_receive() Size from header 62 bytes read 62
trace:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() offset non-NULL, initial value: 0
debug:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() Unmarshaling TPM2_ST from 0x563915376040 to buffer 0x56391537600e at index 0x0
debug:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() offset parameter non-NULL, updated to 2
trace:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset non-NULL, initial value: 2
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() Unmarshaling UINT32 from 0x563915376040 to buffer 0x563915376010 at index 0x2
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset parameter non-NULL, updated to 6
trace:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset non-NULL, initial value: 6
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() Unmarshaling UINT32 from 0x563915376040 to buffer 0x563915376014 at index 0x6
debug:marshal:src/tss2-mu/base-types.c:174:Tss2_MU_UINT32_Unmarshal() offset parameter non-NULL, updated to 10
trace:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() offset non-NULL, initial value: 0
debug:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() Unmarshaling TPM2_ST from 0x563915376040 to buffer 0x7ffe4c4eb7ce at index 0x0
debug:marshal:src/tss2-mu/base-types.c:180:Tss2_MU_TPM2_ST_Unmarshal() offset parameter non-NULL, updated to 2
debug:marshal:src/tss2-mu/tpm2b-types.c:355:Tss2_MU_TPM2B_NV_PUBLIC_Unmarshal() offset non-NULL, initial value: 10
WARNING:marshal:src/tss2-mu/tpm2b-types.c:355:Tss2_MU_TPM2B_NV_PUBLIC_Unmarshal() Size not zero
2024-03-30 09:53:14,074 ERROR Cert App - Failed to read Object size for NV index: 0x1150001 rc 524299
terminate called after throwing an instance of 'std::runtime_error'
what(): Failed to read object size
Aborted (core dumped)
Please try:
TPM2B_NV_PUBLIC nvPublic = {0};
Yes that worked. Thank you!
Yes that worked?
This unnecessary check will be removed in future versions.