Skip to content

Commit

Permalink
Update the TCG2 protocol tests based on upstreaming work
Browse files Browse the repository at this point in the history
In preparing commits to send the TCG2 protocol tests upstream
a number of issues were found.  This commit addresses
these issues:
-some GUIDs did not match specification
-unused definitions
-missing checks if TCG2 protocol is null
-misc typos, spelling, formatting
-definition for EFI_PHYSICAL_ADDRESS already existed
-for submit command test switched to using hash command to
 conform to specification

Signed-off-by: Stuart Yoder <[email protected]>
  • Loading branch information
stuyod01 committed Feb 1, 2024
1 parent dbc2642 commit 3d2967f
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 184 deletions.
28 changes: 18 additions & 10 deletions bbsr/sct-tests/TCG2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Copyright 2006 - 2016 Unified EFI, Inc.<BR>
Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2021, Arm Inc. All rights reserved.<BR>
Copyright (c) 2021 - 2023, Arm Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
Expand All @@ -27,11 +26,16 @@ Module Name:
--*/


#ifndef __TCG2_PROTOCOL_H__
#define __TCG2_PROTOCOL_H__

//
// Global ID for the TCG2 Protocol
//
#define EFI_TCG2_PROTOCOL_GUID \
{0x607f766c, 0x7455, 0x42be, {0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f}}

// Following defintions come from TCG2 Efi Protocol Spec
#define EFI_TCG2_BOOT_HASH_ALG_SHA1 0x00000001

#define EFI_TCG2_BOOT_HASH_ALG_SHA256 0x00000002
Expand All @@ -42,21 +46,25 @@ Module Name:

#define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010

typedef struct _EFI_TCG2_PROTOCOL EFI_TCG2_PROTOCOL;

#define EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 0x00000001

#define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002

#define HASH_NUMBER 0x04

typedef UINT64 EFI_PHYSICAL_ADDRESS;
typedef struct _EFI_TCG2_PROTOCOL EFI_TCG2_PROTOCOL;

typedef UINT32 EFI_TCG2_EVENT_LOG_BITMAP;

typedef UINT32 EFI_TCG2_EVENT_LOG_FORMAT;

typedef UINT32 EFI_TCG2_EVENT_ALGORITHM_BITMAP;

typedef UINT32 TCG_PCRINDEX;

typedef UINT32 TCG_EVENTTYPE;

// Following struct defintions come from TCG2 Efi Protocol Spec
typedef struct {
UINT8 Major;
UINT8 Minor;
Expand Down Expand Up @@ -93,11 +101,9 @@ EFI_STATUS
OUT BOOLEAN *EventLogTruncated
);

typedef UINT32 TCG_PCRINDEX;

typedef UINT32 TCG_EVENTTYPE;

// all structs except EFI_TCG2_BOOT_SERVICE_CAPABILITY are packed
#pragma pack(1)

typedef struct tdEFI_TCG2_EVENT_HEADER {
UINT32 HeaderSize;
UINT16 HeaderVersion;
Expand All @@ -121,7 +127,6 @@ typedef struct tdTPML_DIGEST_VALUES {
TPMT_HA Digests[HASH_NUMBER]; // Count digests
} TPML_DIGEST_VALUES;


// This Declaration is for parsing the eventlog header which is defined to be 20 bytes in TCG EFI Protocol Spec
typedef UINT8 TCG_DIGEST[20];

Expand Down Expand Up @@ -155,6 +160,7 @@ typedef struct tdTCG_EfiSpecIdEventStruct {
UINT8 specErrata;
UINT8 uintnSize;
} TCG_EfiSpecIDEventStruct;

#pragma pack()

typedef
Expand Down Expand Up @@ -201,6 +207,7 @@ EFI_STATUS

//
// Interface structure for the TCG2 Protocol
//
struct _EFI_TCG2_PROTOCOL {
EFI_TCG2_GET_CAPABILITY GetCapability;
EFI_TCG2_GET_EVENT_LOG GetEventLog;
Expand All @@ -213,3 +220,4 @@ struct _EFI_TCG2_PROTOCOL {

extern EFI_GUID gEfiTcg2ProtocolGuid;

#endif
5 changes: 3 additions & 2 deletions bbsr/sct-tests/TCG2Protocol/BlackBoxTest/Guid.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Copyright 2006 - 2013 Unified EFI, Inc.<BR>
Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2021, Arm Inc. All rights reserved.<BR>
Copyright (c) 2021 - 2023, Arm Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
Expand Down Expand Up @@ -60,3 +59,5 @@ EFI_GUID gTcg2ConformanceTestAssertionGuid014 = EFI_TEST_TCG2CONFORMANCE_ASSERTI
EFI_GUID gTcg2ConformanceTestAssertionGuid015 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_015_GUID;

EFI_GUID gTcg2ConformanceTestAssertionGuid016 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_016_GUID;

EFI_GUID gTcg2ConformanceTestAssertionGuid017 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_017_GUID;
39 changes: 19 additions & 20 deletions bbsr/sct-tests/TCG2Protocol/BlackBoxTest/Guid.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Copyright 2006 - 2016 Unified EFI, Inc.<BR>
Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2021, Arm Inc. All rights reserved.<BR>
Copyright (c) 2021 - 2023, Arm Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
Expand Down Expand Up @@ -43,71 +42,71 @@ extern EFI_GUID gTcg2ConformanceTestAssertionGuid002;
extern EFI_GUID gTcg2ConformanceTestAssertionGuid003;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_004_GUID \
{ 0x7a1e79a3, 0x4064, 0x4372, {0xbb, 0x64, 0x55, 0xb8, 0xf2, 0xa5, 0xa3, 0x26 }}
{ 0x8ddb031b, 0x7448, 0x40ee, {0xb1, 0xa2, 0xe6, 0xf8, 0xe8, 0xc4, 0xe5, 0x5f }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid004;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_005_GUID \
{ 0xb0e717c4, 0xb1e2, 0x49f7, {0xb2, 0xd7, 0x60, 0x58, 0x97, 0x7d, 0x09, 0x2c }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid005;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_005_GUID \
{ 0xb0e717c4, 0xb1e2, 0x49f7, {0xb2, 0xd7, 0x60, 0x58, 0x97, 0x7d, 0x09, 0x2c }}
{ 0x7a1e79a3, 0x4064, 0x4372, {0xbb, 0x64, 0x55, 0xb8, 0xf2, 0xa5, 0xa3, 0x26 }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid005;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_006_GUID \
{ 0xa8e1b5e6, 0xfc09, 0x461c, {0xb0, 0xe9, 0x2a, 0x49, 0xcd, 0x25, 0xc1, 0x24 }}
{ 0xb0e717c4, 0xb1e2, 0x49f7, {0xb2, 0xd7, 0x60, 0x58, 0x97, 0x7d, 0x09, 0x2c }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid006;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_007_GUID \
{ 0x26f04a9b, 0x7b7a, 0x4f47, {0xbe, 0xa8, 0xb1, 0xa6, 0x02, 0x65, 0x19, 0x8a }}
{ 0xa8e1b5e6, 0xfc09, 0x461c, {0xb0, 0xe9, 0x2a, 0x49, 0xcd, 0x25, 0xc1, 0x24 }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid007;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_008_GUID \
{ 0x4d1d9985, 0x91e2, 0x4948, {0x89, 0x16, 0xbb, 0x98, 0x13, 0x62, 0x39, 0x1d }}
{ 0x26f04a9b, 0x7b7a, 0x4f47, {0xbe, 0xa8, 0xb1, 0xa6, 0x02, 0x65, 0x19, 0x8a }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid008;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_009_GUID \
{ 0xfb59cab7, 0x4f8c, 0x4ded, {0xa4, 0x1c, 0xc8, 0x41, 0x20, 0x1c, 0x37, 0x22 }}
{ 0x4d1d9985, 0x91e2, 0x4948, {0x89, 0x16, 0xbb, 0x98, 0x13, 0x62, 0x39, 0x1d }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid009;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_010_GUID \
{ 0x0363d22f, 0xc66a, 0x4872, {0xa5, 0x46, 0x06, 0x7f, 0x6a, 0x0d, 0xdb, 0xcd }}
{ 0xfb59cab7, 0x4f8c, 0x4ded, {0xa4, 0x1c, 0xc8, 0x41, 0x20, 0x1c, 0x37, 0x22 }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid010;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_011_GUID \
{ 0x9cd6d636, 0x603a, 0x4b78, {0x80, 0xa3, 0xa3, 0xb9, 0xcc, 0x6a, 0x0b, 0x08 }}
{ 0x0363d22f, 0xc66a, 0x4872, {0xa5, 0x46, 0x06, 0x7f, 0x6a, 0x0d, 0xdb, 0xcd }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid011;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_012_GUID \
{ 0xfc80408e, 0x9a3c, 0x4054, {0x96, 0xf9, 0x31, 0x23, 0x35, 0xc2, 0x31, 0x35 }}
{ 0x9cd6d636, 0x603a, 0x4b78, {0x80, 0xa3, 0xa3, 0xb9, 0xcc, 0x6a, 0x0b, 0x08 }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid012;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_013_GUID \
{ 0x45fa1a42, 0x912a, 0x5124, {0x84, 0xf4, 0x41, 0x67, 0xab, 0xb5, 0x89, 0x90 }}
{ 0xfc80408e, 0x9a3c, 0x4054, {0x96, 0xf9, 0x31, 0x23, 0x35, 0xc2, 0x31, 0x35 }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid013;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_014_GUID \
{ 0x1689bc3a, 0x2298, 0xa116, {0x28, 0x4c, 0xc1, 0xdd, 0xaa, 0xd8, 0xef, 0x51 }}
{ 0x45fa1a42, 0x912a, 0x5124, {0x84, 0xf4, 0x41, 0x67, 0xab, 0xb5, 0x89, 0x90 }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid014;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_015_GUID \
{ 0x126a789a, 0x1932, 0x3234, {0x21, 0xab, 0x42, 0x64, 0x8a, 0x7b, 0x63, 0x76 }}
{ 0x1689bc3a, 0x2298, 0xa116, {0x28, 0x4c, 0xc1, 0xdd, 0xaa, 0xd8, 0xef, 0x51 }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid015;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_016_GUID \
{ 0x8ddb031b, 0x7448, 0x40ee, {0xb1, 0xa2, 0xe6, 0xf8, 0xe8, 0xc4, 0xe5, 0x5f }}
{ 0x126a789a, 0x1932, 0x3234, {0x21, 0xab, 0x42, 0x64, 0x8a, 0x7b, 0x63, 0x76 }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid016;

#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_017_GUID \
{ 0x3aac8b9a, 0x312a, 0x4dcf, {0x12, 0x76, 0x54, 0x55, 0x32, 0xcd, 0x3a, 0xea }}

extern EFI_GUID gTcg2ConformanceTestAssertionGuid017;
60 changes: 41 additions & 19 deletions bbsr/sct-tests/TCG2Protocol/BlackBoxTest/TCG2ProtocolBBTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Copyright 2006 - 2017 Unified EFI, Inc.<BR>
Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2021, Arm Inc. All rights reserved.<BR>
Copyright (c) 2021 - 2023, Arm Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
Expand Down Expand Up @@ -31,8 +30,6 @@ Module Name:

#define EFI_TCG2_TEST_REVISION 0x00010000

extern EFI_HANDLE mImageHandle;

//////////////////////////////////////////////////////////////////////////////
//
// Entry GUIDs for Function Test
Expand All @@ -57,38 +54,63 @@ extern EFI_HANDLE mImageHandle;

#define PE_COFF_IMAGE 0x0000000000000010

// ST_NO_SESSION as definied in Table 19 of TPM Library Part 2: Structures
// ST_NO_SESSION as defined in Table 19 of TPM Library Part 2: Structures
#define ST_NO_SESSIONS (UINT16) 0x8001

// TPM_RC_SUCCESS as definied in Table 16 of TPM Library Spec Part 2: Structures
// TPM_RC_SUCCESS as defined in Table 16 of TPM Library Spec Part 2: Structures
#define TPM_RC_SUCCESS (UINT32) 0x0000000

// TPM_CC_GetRandom as definied in Table 12 of TPM Library Spec Part 2: Structures
#define TPM_CC_GetRandom (UINT32) 0x0000017B
// TPM_CC_Hash as defined in Table 12 of TPM Library Spec Part 2: Structures
#define TPM_CC_Hash (UINT32)(0x0000017D)

#define TPM_RH_NULL (UINT32) 0x40000007

#define TPM_ALG_SHA256 (UINT16) 0x000B

#define SHA256_LENGTH (UINT16) 0x0020

#pragma pack(1)
// TPM2B_DIGEST as definied in Table 73 of TPM Library Spec Part 2: Structures
// TPM2B_MAX_BUFFER as defined in Table 86 of TPM Library Spec Part 2: Structures
// Size of buffer in spec is variable length, but hash test will always use a fixed length string
// of length 43
#define TEST_STRING_LEN 43
typedef struct {
UINT16 size;
UINT8 digest[8]; // Size of buffer in spec is defined to be variable length but for this test will always be 8
UINT8 buffer[TEST_STRING_LEN];
} TPM2B_MAX_BUFFER;

#pragma pack(1)
// TPM2B_DIGEST as defined in Table 73 of TPM Library Spec Part 2: Structures
typedef struct {
UINT16 size;
UINT8 digest[32]; // Size of buffer in spec is defined to be variable length but for this test will always be 32
} TPM2B_DIGEST;

// GetRandomCommand Structure as defined in Sectin 16.1 of TPM Spec Part 3: Commands
typedef struct {
UINT16 tag;
UINT32 hierarchy;
UINT16 digest; // Size of buffer in spec is defined to be variable length but for this test will always be UINT16
} TPMT_TK_HASHCHECK;

// TPM2_Hash command Structure as defined in Section 15.4 of TPM Spec Part 3: Commands
typedef struct {
UINT16 Tag;
UINT32 CommandSize;
UINT32 CommandCode;
UINT16 BytesRequested;
} GET_RANDOM_COMMAND;
TPM2B_MAX_BUFFER data;
UINT16 hashAlg;
UINT32 hierarchy;
} TPM2_HASH_COMMAND;

// GetRandomResponse Structure as defined in Sectin 16.1 of TPM Spec Part 3: Commands
// TPM2_Hash Response Structure as defined in Section 15.4 of TPM Spec Part 3: Commands
typedef struct {
UINT16 Tag;
UINT32 ResponseSize;
UINT32 ResponseCode;
TPM2B_DIGEST randomBytes;
} GET_RANDOM_RESPONSE;
#pragma
TPM2B_DIGEST data;
TPMT_TK_HASHCHECK validation;
} TPM2_HASH_RESPONSE;
#pragma pack()

EFI_STATUS
EFIAPI
Expand Down Expand Up @@ -145,13 +167,13 @@ BBTestHashLogExtendEventConformanceTestCheckpoint2 (
);

EFI_STATUS
BBTestHashLogExtendEventConformanceTestCheckpoint3 (
BBTestGetEventLogConformanceTestCheckpoint1 (
IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,
IN EFI_TCG2_PROTOCOL *TCG2
);

EFI_STATUS
BBTestHashLogExtendEventConformanceTestCheckpoint4 (
BBTestGetEventLogConformanceTestCheckpoint2 (
IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,
IN EFI_TCG2_PROTOCOL *TCG2
);
Expand Down
Loading

0 comments on commit 3d2967f

Please sign in to comment.