| 1 |
// Copyright 2019 Google Inc. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 |
// use this file except in compliance with the License. You may obtain a copy of |
| 5 |
// the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 |
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 |
// License for the specific language governing permissions and limitations under |
| 13 |
// the License. |
| 14 |
|
| 15 |
// Package eventlog implements experimental logic for parsing the TCG event log format. |
| 16 |
package eventlog |
| 17 |
|
| 18 |
import "fmt" |
| 19 |
|
| 20 |
// eventType indicates what kind of data an event is reporting. |
| 21 |
type eventType uint32 |
| 22 |
|
| 23 |
func isReserved(t eventType) bool { |
| 24 |
if 0x00000013 <= t && t <= 0x0000FFFF { |
| 25 |
return true |
| 26 |
} |
| 27 |
if 0x800000E1 <= t && t <= 0x8000FFFF { |
| 28 |
return true |
| 29 |
} |
| 30 |
return false |
| 31 |
} |
| 32 |
|
| 33 |
// String returns the name as defined by the TCG specification. |
| 34 |
func (e eventType) String() string { |
| 35 |
if s, ok := eventTypeNames[e]; ok { |
| 36 |
return s |
| 37 |
} |
| 38 |
s := fmt.Sprintf("eventType(0x%08x)", int(e)) |
| 39 |
if isReserved(e) { |
| 40 |
s += " (reserved)" |
| 41 |
} |
| 42 |
return s |
| 43 |
} |
| 44 |
|
| 45 |
const ( |
| 46 |
// https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClient_Specific_Platform_Profile_for_TPM_2p0_1p04_PUBLIC.pdf#page=103 |
| 47 |
|
| 48 |
// Reserved for future use. |
| 49 |
evPrebootCert eventType = 0x00000000 |
| 50 |
|
| 51 |
// Host platform trust chain measurements. The event data can contain one of |
| 52 |
// the following, indicating different points of boot: "POST CODE", "SMM CODE", |
| 53 |
// "ACPI DATA", "BIS CODE", "Embedded UEFI Driver". |
| 54 |
// |
| 55 |
// PCR[0] MUST be extended with this event type. |
| 56 |
// |
| 57 |
// https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClient_Specific_Platform_Profile_for_TPM_2p0_1p04_PUBLIC.pdf#page=38 |
| 58 |
evPostCode eventType = 0x00000001 |
| 59 |
|
| 60 |
// The event type was never used and is considered reserved. |
| 61 |
evUnused eventType = 0x00000002 |
| 62 |
|
| 63 |
// Used for PCRs[0,6]. This event type doesn't extend the PCR, the digest MUST |
| 64 |
// be all zeros, and the data holds information intended for parsers such as |
| 65 |
// delimiting a switch to the agile crypto event format. |
| 66 |
// |
| 67 |
// This event MUST NOT extend any PCR |
| 68 |
evNoAction eventType = 0x00000003 |
| 69 |
|
| 70 |
// Delineates the point where the Platform Firmware relinquishes control of TPM |
| 71 |
// measurements to the operating system. |
| 72 |
// |
| 73 |
// Event data size MUST contain either 0x00000000 or 0xFFFFFFFF, the digest MUST |
| 74 |
// match the data. |
| 75 |
// |
| 76 |
// This event MUST extend the PCRs 0 through 7 inclusive. |
| 77 |
evSeparator eventType = 0x00000004 |
| 78 |
|
| 79 |
// An event indicating a particular action in the boot sequence, for example |
| 80 |
// "User Password Entered" or "Booting BCV Device s". |
| 81 |
// |
| 82 |
// The digests field contains the tagged hash of the event field for each PCR bank. |
| 83 |
// |
| 84 |
// Used for PCRs [1, 2, 3, 4, 5, and 6]. |
| 85 |
evAction eventType = 0x00000005 |
| 86 |
|
| 87 |
// Used for PCRs defined for OS and application usage. The digest field MUST |
| 88 |
// contain a hash of the data. The data contains a TCG_PCClientTaggedEvent |
| 89 |
// structure. |
| 90 |
evEventTag eventType = 0x00000006 |
| 91 |
|
| 92 |
// Used for PCR[0] only. The digest contains the hash of the SRTM for each PCR |
| 93 |
// bank. The data is informative and not expected to match the digest. |
| 94 |
evSCRTMContents eventType = 0x00000007 |
| 95 |
evSCRTMVersion eventType = 0x00000008 |
| 96 |
|
| 97 |
// The digests field contains the tagged hash of the microcode patch applied for |
| 98 |
// each PCR bank. The data is informative and not expected to match the digest. |
| 99 |
evCUPMicrocode eventType = 0x00000009 |
| 100 |
|
| 101 |
// TODO(ericchiang): explain these events |
| 102 |
evPlatformConfigFiles eventType = 0x0000000A |
| 103 |
evTableOfDevices eventType = 0x0000000B |
| 104 |
|
| 105 |
// Can be used for any PCRs except 0, 1, 2, or 3. |
| 106 |
evCompactHash eventType = 0x0000000C |
| 107 |
|
| 108 |
// IPL events are deprecated |
| 109 |
evIPL eventType = 0x0000000D |
| 110 |
evIPLPartitionData eventType = 0x0000000E |
| 111 |
|
| 112 |
// Used for PCR[0] only. |
| 113 |
// |
| 114 |
// TODO(ericchiang): explain these events |
| 115 |
evNonhostCode eventType = 0x0000000F |
| 116 |
evNonhostConfig eventType = 0x00000010 |
| 117 |
evNonhostInfo eventType = 0x00000011 |
| 118 |
evOmitBootDeviceEvents eventType = 0x00000012 |
| 119 |
|
| 120 |
// The following events are UEFI specific. |
| 121 |
|
| 122 |
// Data contains a UEFI_VARIABLE_DATA structure. |
| 123 |
evEFIVariableDriverConfig eventType = 0x80000001 // PCR[1,3,5] |
| 124 |
evEFIVariableBoot eventType = 0x80000002 // PCR[1] |
| 125 |
|
| 126 |
// Data contains a UEFI_IMAGE_LOAD_EVENT structure. |
| 127 |
evEFIBootServicesApplication eventType = 0x80000003 // PCR[2,4] |
| 128 |
evEFIBootServicesDriver eventType = 0x80000004 // PCR[0,2] |
| 129 |
evEFIRuntimeServicesDriver eventType = 0x80000005 // PCR[2,4] |
| 130 |
|
| 131 |
// Data contains a UEFI_GPT_DATA structure. |
| 132 |
evEFIGPTEvent eventType = 0x80000006 // PCR[5] |
| 133 |
|
| 134 |
evEFIAction eventType = 0x80000007 // PCR[1,2,3,4,5,6,7] |
| 135 |
|
| 136 |
// Data contains a UEFI_PLATFORM_FIRMWARE_BLOB structure. |
| 137 |
evEFIPlatformFirmwareBlob eventType = 0x80000008 // PCR[0,2,4] |
| 138 |
|
| 139 |
// Data contains a UEFI_HANDOFF_TABLE_POINTERS structure. |
| 140 |
evEFIHandoffTables eventType = 0x80000009 // PCR[1] |
| 141 |
|
| 142 |
// The digests field contains the tagged hash of the H-CRTM event |
| 143 |
// data for each PCR bank. |
| 144 |
// |
| 145 |
// The Event Data MUST be the string: “HCRTM”. |
| 146 |
evEFIHCRTMEvent eventType = 0x80000010 // PCR[0] |
| 147 |
|
| 148 |
// Data contains a UEFI_VARIABLE_DATA structure. |
| 149 |
evEFIVariableAuthority eventType = 0x800000E0 // PCR[7] |
| 150 |
) |
| 151 |
|
| 152 |
var eventTypeNames = map[eventType]string{ |
| 153 |
evPrebootCert: "EV_PREBOOT_CERT", |
| 154 |
evPostCode: "EV_POST_CODE", |
| 155 |
evUnused: "EV_UNUSED", |
| 156 |
evNoAction: "EV_NO_ACTION", |
| 157 |
evSeparator: "EV_SEPARATOR", |
| 158 |
evAction: "EV_ACTION", |
| 159 |
evEventTag: "EV_EVENT_TAG", |
| 160 |
evSCRTMContents: "EV_S_CRTM_CONTENTS", |
| 161 |
evSCRTMVersion: "EV_S_CRTM_VERSION", |
| 162 |
evCUPMicrocode: "EV_CPU_MICROCODE", |
| 163 |
evPlatformConfigFiles: "EV_PLATFORM_CONFIG_FLAGS", |
| 164 |
evTableOfDevices: "EV_TABLE_OF_DEVICES", |
| 165 |
evCompactHash: "EV_COMPACT_HASH", |
| 166 |
evIPL: "EV_IPL (deprecated)", |
| 167 |
evIPLPartitionData: "EV_IPL_PARTITION_DATA (deprecated)", |
| 168 |
evNonhostCode: "EV_NONHOST_CODE", |
| 169 |
evNonhostConfig: "EV_NONHOST_CONFIG", |
| 170 |
evNonhostInfo: "EV_NONHOST_INFO", |
| 171 |
evOmitBootDeviceEvents: "EV_OMIT_BOOT_DEVICE_EVENTS", |
| 172 |
|
| 173 |
// UEFI events |
| 174 |
evEFIVariableDriverConfig: "EV_EFI_VARIABLE_DRIVER_CONFIG", |
| 175 |
evEFIVariableBoot: "EV_EFI_VARIABLE_BOOT", |
| 176 |
evEFIBootServicesApplication: "EV_EFI_BOOT_SERVICES_APPLICATION", |
| 177 |
evEFIBootServicesDriver: "EV_EFI_BOOT_SERVICES_DRIVER", |
| 178 |
evEFIRuntimeServicesDriver: "EV_EFI_RUNTIME_SERVICES_DRIVER", |
| 179 |
evEFIGPTEvent: "EV_EFI_GPT_EVENT", |
| 180 |
evEFIAction: "EV_EFI_ACTION", |
| 181 |
evEFIPlatformFirmwareBlob: "EV_EFI_PLATFORM_FIRMWARE_BLOB", |
| 182 |
evEFIHandoffTables: "EV_EFI_HANDOFF_TABLES", |
| 183 |
evEFIHCRTMEvent: "EV_EFI_HCRTM_EVENT", |
| 184 |
evEFIVariableAuthority: "EV_EFI_VARIABLE_AUTHORITY", |
| 185 |
} |