Skip to content

Commit 6d9863f

Browse files
committed
get pciids from code if not found on filesystem
1 parent 3017c13 commit 6d9863f

File tree

9 files changed

+82
-28
lines changed

9 files changed

+82
-28
lines changed

HIRS_Utils/src/main/java/hirs/utils/PciIds.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public final class PciIds {
6666
static {
6767
if (!DB.isReady()) {
6868

69-
// if pciids file is found on the system, then process using this
69+
// if pciids file is found on the system, then process using this file
7070
String dbFile = null;
7171
for (final String path : PCI_IDS_PATH) {
7272
if ((new File(path)).exists()) {
@@ -79,7 +79,7 @@ public final class PciIds {
7979
if(dbFile != null) {
8080
InputStream is = null;
8181
try {
82-
is = new FileInputStream(new File(dbFile));
82+
is = new FileInputStream(dbFile);
8383
DB.loadStream(is);
8484
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
8585
} catch (IOException e) {
@@ -98,17 +98,19 @@ public final class PciIds {
9898

9999
// if pciids file is not found on the system or not accessible, then attempt to grab it from code
100100
if(pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) {
101-
InputStream istemp = PciIds.class.getResourceAsStream(PCIIDS_FILENAME);
102-
try {
103-
DB.loadStream(istemp);
104-
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE;
105-
} catch (IOException e) {
106-
// DB will not be ready, hardware IDs will not be translated
107-
} finally {
108-
if (istemp != null) {
109-
try {
110-
istemp.close();
111-
} catch (IOException e) {
101+
InputStream isFromCode = PciIds.class.getResourceAsStream(PCIIDS_FILENAME);
102+
if(isFromCode != null) {
103+
try {
104+
DB.loadStream(isFromCode);
105+
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE;
106+
} catch (IOException e) {
107+
// DB will not be ready, hardware IDs will not be translated
108+
} finally {
109+
if (isFromCode != null) {
110+
try {
111+
isFromCode.close();
112+
} catch (IOException e) {
113+
}
112114
}
113115
}
114116
}

HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/TCGEventLog.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,12 @@ public TCGEventLog(final byte[] rawlog, final boolean bEventFlag,
180180
!= UefiConstants.FILESTATUS_FROM_FILESYSTEM)) {
181181
vendorTableFileStatus = eventList.get(eventNumber - 1).getVendorTableFileStatus();
182182
}
183-
if ((vendorTableFileStatus != UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
184-
&& (eventList.get(eventNumber - 1).getVendorTableFileStatus()
183+
//similar to above with vendor-table.json file, but here with pci.ids file
184+
if ((pciidsFileStatus != UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
185+
&& (eventList.get(eventNumber - 1).getPciidsFileStatus()
185186
!= UefiConstants.FILESTATUS_FROM_FILESYSTEM)) {
186-
vendorTableFileStatus = eventList.get(eventNumber - 1).getVendorTableFileStatus();
187+
pciidsFileStatus = eventList.get(eventNumber - 1).getPciidsFileStatus();
187188
}
188-
189-
//add pci here
190189
}
191190
calculatePcrValues();
192191
}

HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/TpmPcrEvent.java

+1
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ public String processEvent(final byte[] eventData, final byte[] content,
448448
specVersion = noAction.getSpecVersion();
449449
specErrataVersion = noAction.getSpecErrataVersion();
450450
}
451+
pciidsFileStatus = noAction.getPciidsFileStatus();
451452
break;
452453
case EvConstants.EV_SEPARATOR:
453454
if (EvPostCode.isAscii(content)) {

HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEvent.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ public abstract class DeviceSecurityEvent {
6262
private String deviceContextInfo = "";
6363

6464
/**
65-
* Track status of pci.ids file.
66-
* This is only needed if DeviceSecurityEvent includes a DeviceSecurityEventDataPciContext
65+
* Track status of pci.ids
66+
* This is only used for events that access the pci.ids file.
67+
* (In this class, this is only needed if DeviceSecurityEvent includes a DeviceSecurityEventDataPciContext)
68+
* Default is normal status (normal status is from-filesystem).
69+
* Status will only change IF this is an event that uses this file,
70+
* and if that event causes a different status.
6771
*/
6872
@Getter
6973
private String pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
@@ -92,6 +96,8 @@ public void instantiateDeviceContext(final byte[] dsedDeviceContextBytes) {
9296
} else if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_PCI) {
9397
dsedPciContext = new DeviceSecurityEventDataPciContext(dsedDeviceContextBytes);
9498
deviceContextInfo = dsedPciContext.toString();
99+
// getPciidsFileStatus() must be called after DeviceSecurityEventDataPciContext.toString(),
100+
// because the toString function is where the pciids db gets set up and used
95101
pciidsFileStatus = dsedPciContext.getPciidsFileStatus();
96102
} else if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_USB) {
97103
deviceContextInfo = " Device Type: USB - To be implemented";

HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiSpdmDeviceSecurityEvent.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import java.nio.charset.StandardCharsets;
88

9-
import static hirs.utils.tpm.eventlog.uefi.UefiConstants.FILESTATUS_FROM_FILESYSTEM;
10-
119
/**
1210
* Abstract class to process any SPDM event that is solely a DEVICE_SECURITY_EVENT_DATA or
1311
* DEVICE_SECURITY_EVENT_DATA2. The event field MUST be a
@@ -56,7 +54,7 @@ public class EvEfiSpdmDeviceSecurityEvent {
5654
* and if that event causes a different status.
5755
*/
5856
@Getter
59-
private String pciidsFileStatus = FILESTATUS_FROM_FILESYSTEM;
57+
private String pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
6058

6159
/**
6260
* EvEfiSpdmFirmwareBlob constructor.

HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvNoAction.java

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ public class EvNoAction {
5353
@Getter
5454
private String noActionInfo = "";
5555

56+
/**
57+
* Track status of pci.ids
58+
* This is only used for events that access the pci.ids file.
59+
* Default is normal status (normal status is from-filesystem).
60+
* Status will only change IF this is an event that uses this file,
61+
* and if that event causes a different status.
62+
*/
63+
@Getter
64+
private String pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
65+
5666
/**
5767
* EvNoAction constructor.
5868
*
@@ -78,9 +88,11 @@ public EvNoAction(final byte[] eventData) throws UnsupportedEncodingException {
7888
} else if (signature.contains("NvIndexInstance")) {
7989
NvIndexInstanceEventLogData nvIndexInstanceEvent = new NvIndexInstanceEventLogData(eventData);
8090
noActionInfo += nvIndexInstanceEvent.toString();
91+
pciidsFileStatus = nvIndexInstanceEvent.getPciidsFileStatus();
8192
} else if (signature.contains("NvIndexDynamic")) {
8293
NvIndexDynamicEventLogData nvIndexDynamicEvent = new NvIndexDynamicEventLogData(eventData);
8394
noActionInfo += nvIndexDynamicEvent.toString();
95+
pciidsFileStatus = nvIndexDynamicEvent.getPciidsFileStatus();
8496
} else {
8597
noActionInfo = " EV_NO_ACTION event named \"" + signature
8698
+ "\" encountered but support for processing it has not been"

HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/NvIndexDynamicEventLogData.java

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package hirs.utils.tpm.eventlog.events;
22

33
import hirs.utils.HexUtils;
4+
import hirs.utils.tpm.eventlog.uefi.UefiConstants;
5+
import lombok.Getter;
46

57
import java.nio.charset.StandardCharsets;
68

@@ -36,6 +38,16 @@ public class NvIndexDynamicEventLogData {
3638
*/
3739
private String nvIndexDynamicInfo = "";
3840

41+
/**
42+
* Track status of pci.ids
43+
* This is only used for events that access the pci.ids file.
44+
* Default is normal status (normal status is from-filesystem).
45+
* Status will only change IF this is an event that uses this file,
46+
* and if that event causes a different status.
47+
*/
48+
@Getter
49+
private String pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
50+
3951
/**
4052
* NvIndexInstanceEventLogData constructor.
4153
*

HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/NvIndexInstanceEventLogData.java

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package hirs.utils.tpm.eventlog.events;
22

33
import hirs.utils.HexUtils;
4+
import hirs.utils.tpm.eventlog.uefi.UefiConstants;
5+
import lombok.Getter;
46

57
import java.nio.charset.StandardCharsets;
68

@@ -38,6 +40,16 @@ public class NvIndexInstanceEventLogData {
3840
*/
3941
private String nvIndexInstanceInfo = "";
4042

43+
/**
44+
* Track status of pci.ids
45+
* This is only used for events that access the pci.ids file.
46+
* Default is normal status (normal status is from-filesystem).
47+
* Status will only change IF this is an event that uses this file,
48+
* and if that event causes a different status.
49+
*/
50+
@Getter
51+
private String pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
52+
4153
/**
4254
* NvIndexInstanceEventLogData constructor.
4355
*
@@ -84,6 +96,7 @@ public NvIndexInstanceEventLogData(final byte[] eventData) {
8496
if (dsedVersion.equals("0200")) {
8597
dsed = new DeviceSecurityEventData2(dsedEventData);
8698
nvIndexInstanceInfo += dsed.toString();
99+
pciidsFileStatus = dsed.getPciidsFileStatus();
87100
} else {
88101
nvIndexInstanceInfo += " Incompatible version for DeviceSecurityEventData2: "
89102
+ dsedVersion + "\n";

tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,24 @@ private static void handleEventLog() {
136136
+ evLog.getEventList().size() + " events:\n\n");
137137
}
138138
if (evLog.getVendorTableFileStatus() == FILESTATUS_NOT_ACCESSIBLE) {
139-
writeOut("*** WARNING: The file vendor-table.json was not accessible from the "
140-
+ "filesystem or the code, so some event data shown in the output of this "
141-
+ "tool may be outdated or omitted.\n\n");
139+
writeOut("*** WARNING: "
140+
+ "The file vendor-table.json was not accessible from the filesystem or the code,\n"
141+
+ " so some event data shown in the output of this tool may be outdated\n"
142+
+ " or omitted.\n\n");
142143
} else if (evLog.getVendorTableFileStatus() == FILESTATUS_FROM_CODE) {
143-
writeOut("*** NOTE: "
144+
writeOut("*** NOTE: "
144145
+ "The file vendor-table.json file was not accessible from the filesystem,\n"
145-
+ " so the vendor-table.json from code was used.\n\n");
146+
+ " so the vendor-table.json from code was used.\n\n");
147+
}
148+
if (evLog.getPciidsFileStatus() == FILESTATUS_NOT_ACCESSIBLE) {
149+
writeOut("*** WARNING: "
150+
+ "The file pci.ids was not accessible from the filesystem or the code,\n"
151+
+ " so some pci device info lookups in the output of this tool\n"
152+
+ " may be omitted or the hex code may be used instead.\n\n");
153+
} else if (evLog.getPciidsFileStatus() == FILESTATUS_FROM_CODE) {
154+
writeOut("*** NOTE: "
155+
+ "The file pci.ids file was not accessible from the filesystem,\n"
156+
+ " so the pci.ids from code was used.\n\n");
146157
}
147158
}
148159
int eventCount = 0;

0 commit comments

Comments
 (0)