Skip to content

Commit

Permalink
TpmTestingPkg: Add initial package
Browse files Browse the repository at this point in the history
Adds a new package that holds TPM testing functionality.

Currently, a feature is present called "TPM Replay" that provides
the ability to replay TPM measurements from a custom-made event log.

The primary purpose is for testing operating system features
dependent on TPM measurements. More details about this feature are
available in TpmTestingPkg/TpmReplayPeiDxe/Readme.md.

This feature is designed to ease platform integration and can be
applied to physical and virtual systems.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Aug 23, 2023
1 parent 2304375 commit e611923
Show file tree
Hide file tree
Showing 48 changed files with 10,655 additions and 0 deletions.
1 change: 1 addition & 0 deletions .pytool/CISettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def GetPackagesSupported(self):
"MsGraphicsPkg",
"MsWheaPkg",
"PcBdsPkg",
"TpmTestingPkg",
"UefiTestingPkg",
"XmlSupportPkg"
)
Expand Down
36 changes: 36 additions & 0 deletions TpmTestingPkg/Include/Library/FvMeasurementExclusionLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @file
Firmware Volume Measurement Exclusion Library
Provides a simple interface for platforms to have a list of firmware volumes
excluded from measurement by the traditional TCG driver infrastructure.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef FV_MEASUREMENT_EXCLUSION_LIB_H
#define FV_MEASUREMENT_EXCLUSION_LIB_H

#include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>

/**
Gets a list of FVs excluded from measurement.
@param[out] ExcludedFvs A pointer to an array of excluded FV structures.
@param[out] ExcludedFvsCount The number of excluded FV structures.
@retval EFI_SUCCESS The excluded FVs were returned successfully.
@retval Others An error occurred preventing the excluded FVs from being
return successfully.
**/
EFI_STATUS
EFIAPI
GetPlatformFvExclusions (
OUT CONST EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_FV **ExcludedFvs,
OUT UINTN *ExcludedFvsCount
);

#endif
48 changes: 48 additions & 0 deletions TpmTestingPkg/Include/TpmReplayConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/** @file
TPM Replay Configuration Structure
Defines structures used to configure the TPM Replay feature.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef TPM_REPLAY_CONFIG_H__
#define TPM_REPLAY_CONFIG_H__

#define TPM_REPLAY_CONFIG_SIGNATURE SIGNATURE_64 ('_', 'T', 'R', '_', 'C', 'F', 'G', '_')
#define TPM_REPLAY_CONFIG_STRUCT_VERSION 0x00000001

#pragma pack(push, 1)

typedef union {
UINT32 Data;
struct {
UINT32 Pcr0 : 1; ///< 0 - PCR0
UINT32 Pcr1 : 1; ///< 1 - PCR1
UINT32 Pcr2 : 1; ///< 2 - PCR2
UINT32 Pcr3 : 1; ///< 3 - PCR3
UINT32 Pcr4 : 1; ///< 4 - PCR4
UINT32 Pcr5 : 1; ///< 5 - PCR5
UINT32 Pcr6 : 1; ///< 6 - PCR6
UINT32 Pcr7 : 1; ///< 7 - PCR7
UINT32 Reserved : 24; ///< 31:8 - Reserved
} Pcrs;
} ACTIVE_PCRS;

typedef struct {
UINT64 Signature; // Structure signature - TPM_REPLAY_CONFIG_SIGNATURE
UINT32 StructureVersion; // Structure version - Updates must be backward compatible
UINT32 HeaderLength; // Length of this header in bytes
ACTIVE_PCRS ActivePcrs; // PCRs that are actively used by the TPM Replay feature
// If a PCR is active, it will be cleared except for values
// explicitly defined in a given TPM Replay event log.
} TPM_REPLAY_CONFIG;

#pragma pack(pop)

extern EFI_GUID gTpmReplayConfigHobGuid;

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/** @file
Firmware Volume Measurement Measurement Exclusion Library NULL instance.
This library instance does not exclude any firmware volumes.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Uefi.h>
#include <Library/FvMeasurementExclusionLib.h>

/**
Gets a list of FVs excluded from measurement.
@param[out] ExcludedFvs A pointer to an array of excluded FV structures.
@param[out] ExcludedFvsCount The number of excluded FV structures.
@retval EFI_SUCCESS The excluded FVs were returned successfully.
@retval Others An error occurred preventing the excluded FVs from being
return successfully.
**/
EFI_STATUS
EFIAPI
GetPlatformFvExclusions (
OUT CONST EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_FV **ExcludedFvs,
OUT UINTN *ExcludedFvsCount
)
{
if (ExcludedFvs != NULL) {
*ExcludedFvs = NULL;
}

if (ExcludedFvsCount != NULL) {
*ExcludedFvsCount = 0;
}

return EFI_SUCCESS;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## @file
# Firmware Volume Measurement NULL library instance.
#
# Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = BaseFvMeasurementExclusionLibNull
FILE_GUID = 104D6CF7-B500-44A5-8EC6-4055FE6A0F8F
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = FvMeasurementExclusionLib

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
#

[Packages]
MdePkg/MdePkg.dec
SecurityPkg/SecurityPkg.dec
TpmTestingPkg/TpmTestingPkg.dec

[Sources]
BaseFvMeasurementExclusionLibNull.c
Loading

0 comments on commit e611923

Please sign in to comment.