Skip to content

Commit bc85403

Browse files
committed
adding variable in each subsequent file to track pciids file status
1 parent 6e9cb4b commit bc85403

File tree

6 files changed

+82
-24
lines changed

6 files changed

+82
-24
lines changed

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

+8-14
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.Collections;
2222
import java.util.List;
2323

24-
import static hirs.utils.tpm.eventlog.uefi.UefiConstants.FILESTATUS_NOT_ACCESSIBLE;
25-
2624
/**
2725
* Provide Java access to PCI IDs.
2826
*/
@@ -33,7 +31,7 @@ public final class PciIds {
3331
* Track status of pciids file.
3432
*/
3533
@Getter
36-
private static String pciidsFileStatus = FILESTATUS_NOT_ACCESSIBLE;
34+
private static String pciidsFileStatus = UefiConstants.FILESTATUS_NOT_ACCESSIBLE;
3735

3836
/**
3937
* Name of pciids file in code.
@@ -59,16 +57,12 @@ public final class PciIds {
5957

6058
/**
6159
* The PCI IDs Database object.
62-
*
6360
* This only needs to be loaded one time.
64-
*
6561
* The pci ids library protects the data inside the object by making it immutable.
6662
*/
6763
public static final PciIdsDatabase DB = new PciIdsDatabase();
6864

69-
/**
70-
* Configure the PCI IDs Database object.
71-
*/
65+
//Configure the PCI IDs Database object.
7266
static {
7367
if (!DB.isReady()) {
7468
String dbFile = null;
@@ -87,7 +81,7 @@ public final class PciIds {
8781
dbFile = PciIds.class.getResource(PCIIDS_FILENAME).getPath();
8882
}
8983
if (dbFile != null) {
90-
if (pciidsFileStatus != UefiConstants.FILESTATUS_FROM_FILESYSTEM) {
84+
if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_FROM_FILESYSTEM)) {
9185
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE;
9286
}
9387
InputStream is = null;
@@ -126,7 +120,7 @@ private PciIds() { }
126120
*/
127121
public static ASN1UTF8String translateVendor(final ASN1UTF8String refManufacturer) {
128122
ASN1UTF8String manufacturer = refManufacturer;
129-
if (pciidsFileStatus != FILESTATUS_NOT_ACCESSIBLE
123+
if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
130124
&& manufacturer != null
131125
&& manufacturer.getString().trim().matches("^[0-9A-Fa-f]{4}$")) {
132126
Vendor ven = DB.findVendor(manufacturer.getString().toLowerCase());
@@ -145,7 +139,7 @@ public static ASN1UTF8String translateVendor(final ASN1UTF8String refManufacture
145139
*/
146140
public static String translateVendor(final String refManufacturer) {
147141
String manufacturer = refManufacturer;
148-
if (pciidsFileStatus != FILESTATUS_NOT_ACCESSIBLE
142+
if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
149143
&& manufacturer != null
150144
&& manufacturer.trim().matches("^[0-9A-Fa-f]{4}$")) {
151145
Vendor ven = DB.findVendor(manufacturer.toLowerCase());
@@ -168,7 +162,7 @@ public static ASN1UTF8String translateDevice(final ASN1UTF8String refManufacture
168162
final ASN1UTF8String refModel) {
169163
ASN1UTF8String manufacturer = refManufacturer;
170164
ASN1UTF8String model = refModel;
171-
if (pciidsFileStatus != FILESTATUS_NOT_ACCESSIBLE
165+
if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
172166
&& manufacturer != null
173167
&& model != null
174168
&& manufacturer.getString().trim().matches("^[0-9A-Fa-f]{4}$")
@@ -193,7 +187,7 @@ public static ASN1UTF8String translateDevice(final ASN1UTF8String refManufacture
193187
public static String translateDevice(final String refManufacturer,
194188
final String refModel) {
195189
String model = refModel;
196-
if (pciidsFileStatus != FILESTATUS_NOT_ACCESSIBLE
190+
if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
197191
&& refManufacturer != null
198192
&& model != null
199193
&& refManufacturer.trim().matches("^[0-9A-Fa-f]{4}$")
@@ -224,7 +218,7 @@ public static List<String> translateDeviceClass(final String refClassCode) {
224218
List<String> translatedClassCode = new ArrayList<>();
225219

226220
String classCode = refClassCode;
227-
if (pciidsFileStatus != FILESTATUS_NOT_ACCESSIBLE
221+
if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
228222
&& classCode != null
229223
&& classCode.trim().matches("^[0-9A-Fa-f]{6}$")) {
230224
String deviceClass = classCode.substring(0, 2).toLowerCase();

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

+19-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
import java.util.Collection;
2121
import java.util.LinkedHashMap;
2222

23-
import static hirs.utils.tpm.eventlog.uefi.UefiConstants.FILESTATUS_FROM_FILESYSTEM;
24-
import static hirs.utils.tpm.eventlog.uefi.UefiConstants.FILESTATUS_NOT_ACCESSIBLE;
25-
2623
/**
2724
* Class for handling different formats of TCG Event logs.
2825
*/
@@ -88,7 +85,16 @@ public final class TCGEventLog {
8885
* and if that event causes a different status.
8986
*/
9087
@Getter
91-
private String vendorTableFileStatus = FILESTATUS_FROM_FILESYSTEM;
88+
private String vendorTableFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
89+
/**
90+
* Track status of pci.ids
91+
* This is only used if there is an event that uses functions from the pciids class.
92+
* Default is normal status (normal status is from-filesystem).
93+
* Status will only change IF there is an event that uses pciids file, and the file
94+
* causes a different status.
95+
*/
96+
@Getter
97+
private String pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
9298

9399
/**
94100
* Default blank object constructor.
@@ -169,11 +175,18 @@ public TCGEventLog(final byte[] rawlog, final boolean bEventFlag,
169175
// the if statement is executed
170176
// [new event file status = eventList.get(eventNumber-1).getVendorTableFileStatus()]
171177
// (ie. if the new file status is not-accessible or from-code, then want to update)
172-
if ((vendorTableFileStatus != FILESTATUS_NOT_ACCESSIBLE)
178+
if ((vendorTableFileStatus != UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
173179
&& (eventList.get(eventNumber - 1).getVendorTableFileStatus()
174-
!= FILESTATUS_FROM_FILESYSTEM)) {
180+
!= UefiConstants.FILESTATUS_FROM_FILESYSTEM)) {
175181
vendorTableFileStatus = eventList.get(eventNumber - 1).getVendorTableFileStatus();
176182
}
183+
if ((vendorTableFileStatus != UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
184+
&& (eventList.get(eventNumber - 1).getVendorTableFileStatus()
185+
!= UefiConstants.FILESTATUS_FROM_FILESYSTEM)) {
186+
vendorTableFileStatus = eventList.get(eventNumber - 1).getVendorTableFileStatus();
187+
}
188+
189+
//add pci here
177190
}
178191
calculatePcrValues();
179192
}

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ public class TpmPcrEvent {
127127
@Getter
128128
private String vendorTableFileStatus = FILESTATUS_FROM_FILESYSTEM;
129129

130+
/**
131+
* Track status of pci.ids
132+
* This is only used for events that access the pci.ids file.
133+
* Default is normal status (normal status is from-filesystem).
134+
* Status will only change IF this is an event that uses this file,
135+
* and if that event causes a different status.
136+
*/
137+
@Getter
138+
private String pciidsFileStatus = FILESTATUS_FROM_FILESYSTEM;
139+
130140
/**
131141
* Constructor.
132142
*
@@ -523,7 +533,9 @@ public String processEvent(final byte[] eventData, final byte[] content,
523533
break;
524534
case EvConstants.EV_EFI_SPDM_FIRMWARE_BLOB:
525535
case EvConstants.EV_EFI_SPDM_FIRMWARE_CONFIG:
526-
description += "Event Content:\n" + new EvEfiSpdmDeviceSecurityEvent(content).toString();
536+
EvEfiSpdmDeviceSecurityEvent efiSpdmDse = new EvEfiSpdmDeviceSecurityEvent(content);
537+
description += "Event Content:\n" + efiSpdmDse.toString();
538+
pciidsFileStatus = efiSpdmDse.getPciidsFileStatus();
527539
break;
528540
default:
529541
description += " Unknown Event found" + "\n";

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

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

3+
import hirs.utils.tpm.eventlog.uefi.UefiConstants;
34
import lombok.Getter;
45
import lombok.Setter;
56

@@ -44,7 +45,7 @@ public abstract class DeviceSecurityEvent {
4445
* DeviceSecurityEventDataContext Object.
4546
*/
4647
@Getter
47-
private DeviceSecurityEventDataDeviceContext dsedDevContext = null;
48+
private DeviceSecurityEventDataPciContext dsedPciContext = null;
4849

4950
/**
5051
* Device type.
@@ -60,6 +61,13 @@ public abstract class DeviceSecurityEvent {
6061
@Getter
6162
private String deviceContextInfo = "";
6263

64+
/**
65+
* Track status of pci.ids file.
66+
* This is only needed if DeviceSecurityEvent includes a DeviceSecurityEventDataPciContext
67+
*/
68+
@Getter
69+
private String pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
70+
6371
/**
6472
* DeviceSecurityEventData Default Constructor.
6573
*
@@ -82,8 +90,9 @@ public void instantiateDeviceContext(final byte[] dsedDeviceContextBytes) {
8290
if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_NONE) {
8391
deviceContextInfo = "\n No Device Context (indicated by device type value of 0)";
8492
} else if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_PCI) {
85-
dsedDevContext = new DeviceSecurityEventDataPciContext(dsedDeviceContextBytes);
86-
deviceContextInfo = dsedDevContext.toString();
93+
dsedPciContext = new DeviceSecurityEventDataPciContext(dsedDeviceContextBytes);
94+
deviceContextInfo = dsedPciContext.toString();
95+
pciidsFileStatus = dsedPciContext.getPciidsFileStatus();
8796
} else if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_USB) {
8897
deviceContextInfo = " Device Type: USB - To be implemented";
8998
} else {

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

+15
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.PciIds;
5+
import hirs.utils.tpm.eventlog.uefi.UefiConstants;
46
import lombok.Getter;
57

68
import java.util.List;
@@ -69,6 +71,12 @@ public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDe
6971
@Getter
7072
private String subsystemId = "";
7173

74+
/**
75+
* Track status of pci.ids file.
76+
*/
77+
@Getter
78+
private String pciidsFileStatus = UefiConstants.FILESTATUS_NOT_ACCESSIBLE;
79+
7280
/**
7381
* DeviceSecurityEventDataPciContext Constructor.
7482
*
@@ -114,6 +122,13 @@ public String toString() {
114122
dSEDpciContextInfo += super.toString();
115123
dSEDpciContextInfo += " Device Type = PCI\n";
116124
dSEDpciContextInfo += " Vendor = " + translateVendor(vendorId) + "\n";
125+
126+
// the above call to translateVendor() is the first location in this class where
127+
// a function in pciids class is called
128+
// thus, if pciids db has not previously been set up, this call will trigger that setup
129+
// the setup will look for the pciids file; need to check and store the status of that file
130+
pciidsFileStatus = PciIds.getPciidsFileStatus();
131+
117132
dSEDpciContextInfo += " Device = " + translateDevice(vendorId, deviceId) + "\n";
118133
dSEDpciContextInfo += " RevisionID = " + revisionId + "\n";
119134

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

+15
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import hirs.utils.HexUtils;
44
import hirs.utils.tpm.eventlog.uefi.UefiConstants;
5+
import lombok.Getter;
56

67
import java.nio.charset.StandardCharsets;
78

9+
import static hirs.utils.tpm.eventlog.uefi.UefiConstants.FILESTATUS_FROM_FILESYSTEM;
10+
811
/**
912
* Abstract class to process any SPDM event that is solely a DEVICE_SECURITY_EVENT_DATA or
1013
* DEVICE_SECURITY_EVENT_DATA2. The event field MUST be a
@@ -45,6 +48,16 @@ public class EvEfiSpdmDeviceSecurityEvent {
4548
*/
4649
private String spdmInfo = "";
4750

51+
/**
52+
* Track status of pci.ids
53+
* This is only used for events that access the pci.ids file.
54+
* Default is normal status (normal status is from-filesystem).
55+
* Status will only change IF this is an event that uses this file,
56+
* and if that event causes a different status.
57+
*/
58+
@Getter
59+
private String pciidsFileStatus = FILESTATUS_FROM_FILESYSTEM;
60+
4861
/**
4962
* EvEfiSpdmFirmwareBlob constructor.
5063
*
@@ -72,6 +85,7 @@ public EvEfiSpdmDeviceSecurityEvent(final byte[] eventData) {
7285
if (dsedVersion.equals("0200")) {
7386
dsed = new DeviceSecurityEventData2(eventData);
7487
spdmInfo += dsed.toString();
88+
pciidsFileStatus = dsed.getPciidsFileStatus();
7589
} else {
7690
spdmInfo += " Incompatible version for DeviceSecurityEventData2: " + dsedVersion + "\n";
7791
}
@@ -82,6 +96,7 @@ public EvEfiSpdmDeviceSecurityEvent(final byte[] eventData) {
8296
if (dsedVersion.equals("0100")) {
8397
dsed = new DeviceSecurityEventData(eventData);
8498
spdmInfo += dsed.toString();
99+
pciidsFileStatus = dsed.getPciidsFileStatus();
85100
} else {
86101
spdmInfo += " Incompatible version for DeviceSecurityEventData: " + dsedVersion + "\n";
87102
}

0 commit comments

Comments
 (0)