summaryrefslogtreecommitdiff
path: root/tests/tlcl_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tlcl_tests.c')
-rw-r--r--tests/tlcl_tests.c83
1 files changed, 78 insertions, 5 deletions
diff --git a/tests/tlcl_tests.c b/tests/tlcl_tests.c
index b7f288a3..55e897cb 100644
--- a/tests/tlcl_tests.c
+++ b/tests/tlcl_tests.c
@@ -466,6 +466,83 @@ static void PcrTest(void)
}
/**
+ * Test TlclGetSpaceInfo.
+ */
+static void GetSpaceInfoTest(void)
+{
+ uint8_t response[] = {
+ 0x00, 0xc4, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x18,
+ 0x20, 0x00, 0x00, 0x04, 0x00, 0x03, 0x01, 0x00,
+ 0x00, 0x01, 0xb3, 0x2b, 0x96, 0x30, 0xd3, 0x21,
+ 0x1e, 0x99, 0x78, 0x9e, 0xd3, 0x1f, 0x11, 0x8e,
+ 0x96, 0xbc, 0xf7, 0x7e, 0x7b, 0x06, 0x00, 0x03,
+ 0x20, 0x00, 0x00, 0x10, 0x3b, 0xb2, 0x69, 0x03,
+ 0x3d, 0x12, 0xe1, 0x99, 0x87, 0xe9, 0x3d, 0xf1,
+ 0x11, 0xe8, 0x69, 0xcb, 0x7f, 0xe7, 0xb7, 0x60,
+ 0x00, 0x17, 0x00, 0x00, 0x20, 0x00, 0x00, 0x01,
+ 0x01, 0x00, 0x00, 0x00, 0x45,
+ };
+
+ uint32_t attributes = 0;
+ uint32_t size = 0;
+ TPM_NV_AUTH_POLICY policy;
+ uint32_t policy_size = sizeof(policy);
+
+ /* Test successful parsing. */
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ TEST_EQ(TlclGetSpaceInfo(0x20000004, &attributes, &size, &policy,
+ &policy_size),
+ TPM_SUCCESS, "GetSpaceInfo");
+ TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
+ TEST_EQ(policy_size, sizeof(policy), " policy_size");
+ TEST_EQ(attributes, TPM_NV_PER_WRITEDEFINE, " attributes");
+ TEST_EQ(size, 0x45, " size");
+ TEST_EQ(memcmp(&policy, response + 20, sizeof(policy)), 0, " policy");
+
+ /* Test that GetPermissions returns the attributes as well. */
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ TEST_EQ(TlclGetPermissions(0x20000004, &attributes),
+ TPM_SUCCESS, "GetPermissions");
+ TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
+ TEST_EQ(attributes, TPM_NV_PER_WRITEDEFINE, " attributes");
+
+ /* Test whether a short response gets detected. */
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ ToTpmUint32(response + 10, 0x46);
+ TEST_EQ(TlclGetSpaceInfo(0x20000004, &attributes, &size, &policy,
+ &policy_size),
+ TPM_E_INVALID_RESPONSE, "GetSpaceInfo short length");
+ ToTpmUint32(response + 10, 0x47);
+
+ /* Test whether an overlong PCR selection length causes failure. */
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ ToTpmUint16(response + 20, 4);
+ TEST_EQ(TlclGetSpaceInfo(0x20000004, &attributes, &size, &policy,
+ &policy_size),
+ TPM_E_INVALID_RESPONSE, "GetSpaceInfo overlong pcr selection");
+ ToTpmUint16(response + 20, 3);
+
+ /* Test that a short policy buffer triggers an error. */
+ ResetMocks();
+ calls[0].rsp = response;
+ calls[0].rsp_size = sizeof(response);
+ policy_size = sizeof(policy) - 1;
+ TEST_EQ(TlclGetSpaceInfo(0x20000004, &attributes, &size, &policy,
+ &policy_size),
+ TPM_E_BUFFER_SIZE, "GetSpaceInfo short policy buffer");
+ TEST_EQ(sizeof(policy), policy_size, " policy_size");
+}
+
+/**
* Test flags / capabilities
*
* TODO: check params/data read/written.
@@ -475,7 +552,6 @@ static void FlagsTest(void)
TPM_PERMANENT_FLAGS pflags;
TPM_STCLEAR_FLAGS vflags;
uint8_t disable = 0, deactivated = 0, nvlocked = 0;
- uint32_t u;
uint8_t buf[32];
ResetMocks();
@@ -493,10 +569,6 @@ static void FlagsTest(void)
TEST_EQ(TlclGetFlags(&disable, &deactivated, &nvlocked), 0, "GetFlags");
ResetMocks();
- TEST_EQ(TlclGetPermissions(1, &u), 0, "GetPermissions");
- TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
-
- ResetMocks();
TEST_EQ(TlclGetOwnership(buf), 0, "GetOwnership");
TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd");
}
@@ -1084,6 +1156,7 @@ int main(void)
DefineSpaceExTest();
InitNvAuthPolicyTest();
PcrTest();
+ GetSpaceInfoTest();
FlagsTest();
RandomTest();
GetVersionTest();