diff options
author | Mattias Nissler <mnissler@chromium.org> | 2017-11-27 15:35:10 +0100 |
---|---|---|
committer | Mattias Nissler <mnissler@chromium.org> | 2018-04-13 10:03:31 +0000 |
commit | ac2286e8f8337a6ced00f219ec59aab52a2ac6d7 (patch) | |
tree | edeaae00859b2b0880ba6eacbef8373a22a3b088 /tests/tlcl_tests.c | |
parent | 163b41233cbbfdd67da10017aab7c1ce9a6e0873 (diff) | |
download | vboot-ac2286e8f8337a6ced00f219ec59aab52a2ac6d7.tar.gz |
tpm_lite: Implement TakeOwnership support
Add the ability to take TPM ownership. This requires two new commands:
TPM_OIAP to start an auth session and TPM_TakeOwnership to establish
ownership. TPM_TakeOwnership requires an auth session and proper
command authentication to work, which is also added.
BRANCH=None
BUG=chromium:788719
TEST=new unit tests
Change-Id: Ib70144eedb0b1c7c43b26c06529d33ccbaa51a0e
Reviewed-on: https://chromium-review.googlesource.com/790414
Reviewed-by: Andrey Pronin <apronin@chromium.org>
Tested-by: Mattias Nissler <mnissler@chromium.org>
Trybot-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Trybot-Ready: Mattias Nissler <mnissler@chromium.org>
Diffstat (limited to 'tests/tlcl_tests.c')
-rw-r--r-- | tests/tlcl_tests.c | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/tests/tlcl_tests.c b/tests/tlcl_tests.c index 135311a4..31df17a9 100644 --- a/tests/tlcl_tests.c +++ b/tests/tlcl_tests.c @@ -664,6 +664,155 @@ void ReadPubekTest(void) { response[294] = 0x60; } +/** + * Test TakeOwnership + */ +void TakeOwnershipTest(void) { + uint8_t oiap_response[] = { + 0x00, 0xc4, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x4c, 0x04, 0x1a, 0x18, 0xa9, + 0xf7, 0x9b, 0x2e, 0xe1, 0xf2, 0x16, 0x99, 0xa0, + 0x27, 0x5f, 0x0c, 0x8f, 0x24, 0x55, 0x1d, 0xaf, + 0x96, 0x49, + }; + uint8_t take_ownership_response[] = { + 0x00, 0xc5, 0x00, 0x00, 0x01, 0x62, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x01, 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, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x92, 0x61, 0xa5, + 0x30, 0x5f, 0x39, 0xb7, 0xc3, 0x51, 0x53, 0x84, + 0xaf, 0x51, 0x64, 0x65, 0xd7, 0x58, 0xda, 0x15, + 0xb0, 0xb8, 0xe8, 0xea, 0xf5, 0xb2, 0x21, 0x34, + 0x09, 0x71, 0xa0, 0xd5, 0x2b, 0x21, 0xd6, 0x16, + 0xbd, 0x03, 0xc3, 0x83, 0x7e, 0x48, 0x36, 0xd7, + 0xfa, 0xc7, 0x5e, 0x5e, 0xb4, 0xc3, 0x9f, 0x00, + 0xcc, 0x7a, 0x3e, 0x0a, 0x00, 0x34, 0xbd, 0xbc, + 0x7b, 0x28, 0x0e, 0x4a, 0xef, 0xa5, 0x86, 0x50, + 0xa5, 0xfe, 0x8f, 0x7d, 0xbc, 0x86, 0xf3, 0x3d, + 0x8c, 0x65, 0x4c, 0x3b, 0x29, 0x3b, 0x40, 0x8b, + 0xca, 0xf9, 0xa1, 0xc8, 0x62, 0x52, 0xe1, 0x1f, + 0x0d, 0x89, 0x71, 0xca, 0xbb, 0x64, 0xef, 0x3f, + 0x97, 0x97, 0xed, 0x57, 0xb3, 0xd8, 0x67, 0x4c, + 0x46, 0x1c, 0x35, 0x0c, 0xba, 0x12, 0xae, 0x2e, + 0x6d, 0xa7, 0x48, 0xd6, 0x9a, 0x8a, 0x60, 0x22, + 0xd9, 0xe5, 0x97, 0x50, 0xc1, 0x24, 0xaf, 0xb6, + 0x41, 0xfe, 0x6d, 0xfe, 0x28, 0x3f, 0xce, 0x35, + 0x9b, 0x77, 0xe9, 0xd5, 0x36, 0xdb, 0x70, 0x5e, + 0xd7, 0xb9, 0x89, 0xac, 0xae, 0x55, 0x59, 0x00, + 0x7d, 0x47, 0x5d, 0x73, 0x4f, 0x1b, 0x17, 0xfa, + 0xae, 0xb0, 0xf7, 0xb7, 0x63, 0x4d, 0xa9, 0x94, + 0x0c, 0x1e, 0x02, 0x59, 0x8d, 0x34, 0x1f, 0x01, + 0x6d, 0xa7, 0x05, 0xa7, 0xae, 0xbd, 0x9b, 0xfa, + 0xed, 0xe6, 0xe3, 0xf2, 0xc0, 0xa9, 0x16, 0xb6, + 0xd2, 0x23, 0x37, 0x2e, 0x43, 0x5e, 0x5f, 0xe6, + 0x77, 0x0d, 0x49, 0x48, 0x07, 0x57, 0x64, 0xd2, + 0xd9, 0x60, 0xff, 0xe3, 0x60, 0xb6, 0xd7, 0xa5, + 0xe3, 0xd8, 0xa3, 0x93, 0xb3, 0xe9, 0xeb, 0x1c, + 0x53, 0x42, 0x08, 0x9f, 0x0c, 0x13, 0x72, 0x3c, + 0x80, 0xf8, 0xa1, 0x8c, 0x4d, 0xe5, 0x1e, 0xe7, + 0xef, 0x2b, 0x33, 0x23, 0x1e, 0x5a, 0xf6, 0xc1, + 0x46, 0x78, 0x06, 0x7e, 0xe7, 0x00, 0x00, 0x00, + 0x00, 0xef, 0x84, 0x26, 0xd3, 0xb6, 0x27, 0x4a, + 0x4a, 0x0f, 0x84, 0x65, 0x4b, 0xff, 0x80, 0x7e, + 0xb5, 0xf6, 0xbe, 0x8c, 0xed, 0x00, 0xad, 0xd1, + 0x73, 0x8a, 0x55, 0x9f, 0x50, 0xb4, 0x34, 0xba, + 0x2d, 0x6d, 0x80, 0x3a, 0xdc, 0x82, 0x94, 0x3b, + 0x96, 0x58, + }; + uint8_t encrypted_secret[] = { + 0x46, 0x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 0xf9, 0xc4, 0x53, + 0x72, 0x51, 0x48, 0x4b, 0xb3, 0xf9, 0x18, 0x43, + 0x3a, 0x85, 0xdc, 0x70, 0x46, 0x0c, 0x3c, 0xe1, + 0x17, 0x1c, 0x18, 0x6f, 0xfd, 0xff, 0x77, 0x8d, + 0x04, 0xfc, 0xb3, 0xc0, 0x9a, 0x03, 0x74, 0x1d, + 0x06, 0x8f, 0xb6, 0x0a, 0x3e, 0xea, 0x91, 0x87, + 0xa9, 0x68, 0x26, 0x91, 0x81, 0x02, 0xe4, 0x10, + 0x66, 0xb6, 0x5f, 0x43, 0x47, 0x55, 0x25, 0xe0, + 0xbd, 0xd3, 0xab, 0xbd, 0xfd, 0x15, 0x85, 0x39, + 0x22, 0x93, 0xfc, 0x9d, 0x74, 0x0e, 0xcf, 0x5a, + }; + uint8_t owner_secret[TPM_AUTH_DATA_LEN] = { 0 }; + + ResetMocks(); + calls[0].rsp = oiap_response; + calls[0].rsp_size = sizeof(oiap_response); + calls[1].rsp = take_ownership_response; + calls[1].rsp_size = sizeof(take_ownership_response); + TEST_EQ(TlclTakeOwnership(encrypted_secret, encrypted_secret, + owner_secret), TPM_SUCCESS, "TakeOwnership"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_OIAP, " oiap cmd"); + TEST_EQ(calls[1].req_cmd, TPM_ORD_TakeOwnership, " takeownership cmd"); + + /* Verify that the response gets authenticated. */ + ResetMocks(); + calls[0].rsp = oiap_response; + calls[0].rsp_size = sizeof(oiap_response); + calls[1].rsp = take_ownership_response; + calls[1].rsp_size = sizeof(take_ownership_response); + take_ownership_response[334] = 0; + TEST_EQ(TlclTakeOwnership(encrypted_secret, encrypted_secret, + owner_secret), + TPM_E_AUTHFAIL, "TakeOwnership - response auth"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_OIAP, " oiap cmd"); + TEST_EQ(calls[1].req_cmd, TPM_ORD_TakeOwnership, " takeownership cmd"); + take_ownership_response[334] = 0xad; + + /* Verify that a short OIAP response gets caught. */ + ResetMocks(); + calls[0].rsp = oiap_response; + calls[0].rsp_size = sizeof(oiap_response); + ToTpmUint32(oiap_response + sizeof(uint16_t), + kTpmRequestHeaderLength + sizeof(uint32_t) + + sizeof(TPM_NONCE) - 1); + TEST_EQ(TlclTakeOwnership(encrypted_secret, encrypted_secret, + owner_secret), + TPM_E_INVALID_RESPONSE, "TakeOwnership - short OIAP response"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_OIAP, " oiap cmd"); + ToTpmUint32(oiap_response + sizeof(uint16_t), sizeof(oiap_response)); + + /* Verify that a short TakeOwnership response gets caught. */ + ResetMocks(); + calls[0].rsp = oiap_response; + calls[0].rsp_size = sizeof(oiap_response); + calls[1].rsp = take_ownership_response; + calls[1].rsp_size = sizeof(take_ownership_response); + ToTpmUint32(take_ownership_response + sizeof(uint16_t), + kTpmResponseHeaderLength + kTpmResponseAuthBlockLength - 1); + TEST_EQ(TlclTakeOwnership(encrypted_secret, encrypted_secret, + owner_secret), + TPM_E_INVALID_RESPONSE, + "TakeOwnership - short TakeOwnership response"); + TEST_EQ(calls[0].req_cmd, TPM_ORD_OIAP, " oiap cmd"); + TEST_EQ(calls[1].req_cmd, TPM_ORD_TakeOwnership, " takeownership cmd"); + ToTpmUint32(take_ownership_response + sizeof(uint16_t), + sizeof(take_ownership_response)); +} + int main(void) { TlclTest(); @@ -675,6 +824,7 @@ int main(void) GetVersionTest(); IFXFieldUpgradeInfoTest(); ReadPubekTest(); + TakeOwnershipTest(); return gTestSuccess ? 0 : 255; } |