diff options
Diffstat (limited to 'tests/tlcl_tests.c')
-rw-r--r-- | tests/tlcl_tests.c | 135 |
1 files changed, 133 insertions, 2 deletions
diff --git a/tests/tlcl_tests.c b/tests/tlcl_tests.c index c2f3681c..135311a4 100644 --- a/tests/tlcl_tests.c +++ b/tests/tlcl_tests.c @@ -98,6 +98,12 @@ VbError_t VbExTpmSendReceive(const uint8_t *request, uint32_t request_length, return c->retval; } +VbError_t VbExTpmGetRandom(uint8_t *buf, uint32_t length) +{ + memset(buf, 0xa5, length); + return VBERROR_SUCCESS; +} + /** * Test assorted tlcl functions */ @@ -519,7 +525,7 @@ static void IFXFieldUpgradeInfoTest(void) calls[0].rsp_size = sizeof(version_response); calls[1].rsp = upgrade_info_response; calls[1].rsp_size = sizeof(upgrade_info_response); - TEST_EQ(TlclIFXFieldUpgradeInfo(&info), TPM_E_IOERROR, + TEST_EQ(TlclIFXFieldUpgradeInfo(&info), TPM_E_INVALID_RESPONSE, "IFXFieldUpgradeInfo - short"); TEST_EQ(calls[1].req_cmd, TPM_ORD_FieldUpgrade, " cmd"); @@ -529,11 +535,135 @@ static void IFXFieldUpgradeInfoTest(void) ResetMocks(); calls[0].rsp = version_response; calls[0].rsp_size = sizeof(version_response); - TEST_EQ(TlclIFXFieldUpgradeInfo(&info), TPM_E_IOERROR, + TEST_EQ(TlclIFXFieldUpgradeInfo(&info), TPM_E_INVALID_RESPONSE, "IFXFieldUpgradeInfo - bad vendor"); TEST_EQ(calls[1].req_cmd, TPM_ORD_FieldUpgrade, " cmd"); } +/** + * Test ReadPubek + */ +void ReadPubekTest(void) { + uint8_t response[] = { + 0x00, 0xc4, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x9c, 0xa8, + 0x8f, 0x15, 0x6d, 0xbf, 0x37, 0x6f, 0x8d, 0xb7, + 0xb2, 0xe2, 0x79, 0x81, 0xf7, 0xc2, 0x3c, 0x84, + 0x64, 0x35, 0x38, 0x59, 0x6a, 0x87, 0x23, 0xe0, + 0x2a, 0xca, 0x40, 0x37, 0x78, 0x75, 0x18, 0xfc, + 0x2d, 0xbe, 0x2b, 0xd9, 0x77, 0x49, 0x4b, 0x8c, + 0xea, 0xe3, 0xcd, 0xa5, 0x27, 0x2b, 0x48, 0x2f, + 0xbe, 0x3b, 0x14, 0xca, 0xe5, 0x22, 0x31, 0xb8, + 0xa1, 0x14, 0xc6, 0x06, 0x8d, 0x14, 0xe8, 0x4a, + 0x36, 0x4d, 0xd3, 0x5f, 0xde, 0x23, 0xd1, 0x7b, + 0xec, 0x3b, 0xdd, 0x84, 0xa4, 0xd4, 0xe9, 0x9a, + 0x89, 0x94, 0x5c, 0xa0, 0x01, 0xfb, 0x95, 0x61, + 0x01, 0xaf, 0x6b, 0x17, 0x39, 0x44, 0x7e, 0x25, + 0x9b, 0x73, 0xfa, 0xde, 0x20, 0xb6, 0x92, 0x95, + 0x7b, 0x76, 0x9f, 0x44, 0xb0, 0xfb, 0x86, 0x9f, + 0xc5, 0xe2, 0x38, 0x9d, 0xcf, 0xce, 0x32, 0x53, + 0x3b, 0x3d, 0x10, 0xb7, 0x89, 0x53, 0x54, 0xc0, + 0x28, 0x52, 0xfc, 0x7a, 0xa9, 0x5b, 0x03, 0xd7, + 0x55, 0x2b, 0x07, 0xa7, 0x22, 0x5b, 0x1e, 0xe5, + 0x4f, 0x43, 0x70, 0x7d, 0x81, 0xbb, 0x3d, 0x56, + 0xfe, 0x5c, 0x47, 0xcc, 0xc0, 0x6e, 0xc8, 0xc7, + 0xd9, 0x96, 0x53, 0x2d, 0xd2, 0x28, 0xc7, 0xdf, + 0x5a, 0x07, 0x50, 0x3b, 0x17, 0x25, 0xe7, 0x51, + 0xed, 0xf7, 0x94, 0x02, 0x2a, 0x4c, 0x31, 0x57, + 0x34, 0x51, 0x05, 0x26, 0x43, 0xd4, 0x40, 0x47, + 0x3e, 0x02, 0xfe, 0xa5, 0x08, 0xc7, 0x94, 0xaa, + 0xd3, 0x14, 0x02, 0x1b, 0x41, 0x4c, 0xcd, 0xd6, + 0x8c, 0xad, 0x8e, 0x72, 0x1a, 0x36, 0xc7, 0x23, + 0xd1, 0x38, 0x83, 0x9f, 0xac, 0x66, 0xc5, 0x25, + 0x82, 0x9d, 0x18, 0x67, 0x78, 0xca, 0x15, 0x63, + 0x15, 0xd8, 0x83, 0xbd, 0xcc, 0xe7, 0xf7, 0xe9, + 0xba, 0xda, 0x23, 0xdf, 0x53, 0x30, 0x51, 0x1a, + 0xf1, 0x0c, 0x02, 0xe7, 0x65, 0x0d, 0x95, 0x52, + 0x76, 0xd1, 0x1b, 0xb0, 0x77, 0xba, 0x31, 0x0b, + 0x17, 0xb5, 0x63, 0x0d, 0x50, 0x7c, 0xbc, 0x63, + 0xbf, 0xc3, + }; + uint32_t exponent = 0; + uint8_t modulus[TPM_RSA_2048_LEN]; + uint32_t modulus_size = TPM_RSA_2048_LEN; + + ResetMocks(); + calls[0].rsp = response; + calls[0].rsp_size = sizeof(response); + TEST_EQ(TlclReadPubek(&exponent, modulus, &modulus_size), TPM_SUCCESS, + "ReadPubek"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, " cmd"); + TEST_EQ(exponent, 0x10001, " exponent"); + TEST_EQ(memcmp(modulus, response + 38, sizeof(modulus)), TPM_SUCCESS, + " modulus"); + TEST_EQ(modulus_size, 0x100, " modulus_size"); + + /* Test that the command returns the full size of the modulus if the + * input buffer is too small. */ + ResetMocks(); + calls[0].rsp = response; + calls[0].rsp_size = sizeof(response); + modulus_size = 0; + TEST_EQ(TlclReadPubek(&exponent, NULL, &modulus_size), + TPM_E_BUFFER_SIZE, "ReadPubek - returns modulus size"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, " cmd"); + TEST_EQ(modulus_size, 0x100, " modulus_size"); + + /* Test that a too large parm_size value gets handled correctly. */ + ResetMocks(); + calls[0].rsp = response; + calls[0].rsp_size = sizeof(response); + ToTpmUint32(response + 18, 1 << 24); + TEST_EQ(TlclReadPubek(&exponent, NULL, &modulus_size), + TPM_E_INVALID_RESPONSE, "ReadPubek - large parm_size"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, " cmd"); + ToTpmUint32(response + 18, 12); + + /* Test that a too small parm_size value gets handled correctly. */ + ResetMocks(); + calls[0].rsp = response; + calls[0].rsp_size = sizeof(response); + ToTpmUint32(response + 18, 11); + TEST_EQ(TlclReadPubek(&exponent, NULL, &modulus_size), + TPM_E_INVALID_RESPONSE, "ReadPubek - small parm_size"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, " cmd"); + ToTpmUint32(response + 18, 12); + + /* Test that an overlong modulus size gets handled correctly. */ + ResetMocks(); + calls[0].rsp = response; + calls[0].rsp_size = sizeof(response); + ToTpmUint32(response + 34, 1 << 24); + modulus_size = sizeof(modulus); + TEST_EQ(TlclReadPubek(&exponent, NULL, &modulus_size), + TPM_E_INVALID_RESPONSE, "ReadPubek - large modulus size"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, " cmd"); + ToTpmUint32(response + 34, TPM_RSA_2048_LEN); + + /* Test that a large exponent size gets handled correctly. */ + ResetMocks(); + calls[0].rsp = response; + calls[0].rsp_size = sizeof(response); + ToTpmUint32(response + 20, 1 << 24); + TEST_EQ(TlclReadPubek(&exponent, NULL, &modulus_size), + TPM_E_INVALID_RESPONSE, "ReadPubek - large exponent size"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, " cmd"); + ToTpmUint32(response + 20, 0); + + /* Test that an incorrect auth tag causes an error. */ + ResetMocks(); + calls[0].rsp = response; + calls[0].rsp_size = sizeof(response); + response[294] = 0; + TEST_EQ(TlclReadPubek(&exponent, NULL, &modulus_size), + TPM_E_INVALID_RESPONSE, "ReadPubek - incorrect auth"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, " cmd"); + response[294] = 0x60; +} + int main(void) { TlclTest(); @@ -544,6 +674,7 @@ int main(void) RandomTest(); GetVersionTest(); IFXFieldUpgradeInfoTest(); + ReadPubekTest(); return gTestSuccess ? 0 : 255; } |