Skip to content

Commit

Permalink
fixing checkstyle warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
iadgovuser58 committed Aug 15, 2024
1 parent 30a049a commit 583869f
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 140 deletions.
6 changes: 3 additions & 3 deletions HIRS_Utils/src/main/java/hirs/utils/PciIds.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public static List<String> translateDeviceClass(final String refClassCode) {

String classCode = refClassCode;
if (classCode != null && classCode.trim().matches("^[0-9A-Fa-f]{6}$")) {
String deviceClass = classCode.substring(0,2).toLowerCase();
String deviceSubclass = classCode.substring(2,4).toLowerCase();
String programInterface = classCode.substring(4,6).toLowerCase();
String deviceClass = classCode.substring(0, 2).toLowerCase();
String deviceSubclass = classCode.substring(2, 4).toLowerCase();
String programInterface = classCode.substring(4, 6).toLowerCase();
translatedClassCode.add(deviceClass);
translatedClassCode.add(deviceSubclass);
translatedClassCode.add(programInterface);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public TCGEventLog(final byte[] rawlog, final boolean bEventFlag,
// the if statement is executed
// [new event file status = eventList.get(eventNumber-1).getVendorTableFileStatus()]
// (ie. if the new file status is not-accessible or from-code, then want to update)
if((vendorTableFileStatus != FILESTATUS_NOT_ACCESSIBLE) &&
(eventList.get(eventNumber-1).getVendorTableFileStatus() != FILESTATUS_FROM_FILESYSTEM)) {
vendorTableFileStatus = eventList.get(eventNumber-1).getVendorTableFileStatus();
if ((vendorTableFileStatus != FILESTATUS_NOT_ACCESSIBLE)
&& (eventList.get(eventNumber - 1).getVendorTableFileStatus() != FILESTATUS_FROM_FILESYSTEM)) {
vendorTableFileStatus = eventList.get(eventNumber - 1).getVendorTableFileStatus();
}
}
calculatePcrValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public abstract class DeviceSecurityEvent {
* DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT. DEVICE can be either PCI or USB.
*/
@Getter
String deviceContextInfo = "";
private String deviceContextInfo = "";

/**
* DeviceSecurityEventData Default Constructor.
Expand All @@ -76,21 +76,17 @@ public DeviceSecurityEvent() {
*/
public void instantiateDeviceContext(final byte[] dsedDeviceContextBytes) {

if(dsedDeviceContextBytes.length == 0) {
if (dsedDeviceContextBytes.length == 0) {
deviceContextInfo = "\n DeviceSecurityEventDataDeviceContext object is empty";
}
else {
} else {
if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_NONE) {
deviceContextInfo = "\n No Device Context (indicated by device type value of 0)";
}
else if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_PCI) {
} else if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_PCI) {
dsedDevContext = new DeviceSecurityEventDataPciContext(dsedDeviceContextBytes);
deviceContextInfo = dsedDevContext.toString();
}
else if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_USB) {
} else if (deviceType == DeviceSecurityEventDataDeviceContext.DEVICE_TYPE_USB) {
deviceContextInfo = " Device Type: USB - To be implemented";
}
else {
} else {
deviceContextInfo = " Unknown device type; cannot process device context";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DeviceSecurityEventData extends DeviceSecurityEvent {
* DEVICE_SECURITY_EVENT_DATA_HEADER.
*/
@Getter
String headerInfo = "";
private String headerInfo = "";

/**
* DeviceSecurityEventData Constructor.
Expand All @@ -34,10 +34,9 @@ public class DeviceSecurityEventData extends DeviceSecurityEvent {
*/
public DeviceSecurityEventData(final byte[] dsedBytes) {

if(dsedBytes.length == 0) {
if (dsedBytes.length == 0) {
headerInfo = " DeviceSecurityEventData object is empty";
}
else {
} else {
dsedHeader = new DeviceSecurityEventDataHeader(dsedBytes);
headerInfo = dsedHeader.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DeviceSecurityEventData2 extends DeviceSecurityEvent {
* DEVICE_SECURITY_EVENT_DATA_HEADER2.
*/
@Getter
String headerInfo = "";
private String headerInfo = "";

/**
* Human-readable description of the data within the
Expand All @@ -41,7 +41,7 @@ public class DeviceSecurityEventData2 extends DeviceSecurityEvent {
* DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN
*/
@Getter
String subHeaderInfo = "";
private String subHeaderInfo = "";

/**
* DeviceSecurityEventData2 Constructor.
Expand All @@ -50,10 +50,9 @@ public class DeviceSecurityEventData2 extends DeviceSecurityEvent {
*/
public DeviceSecurityEventData2(final byte[] dsedBytes) {

if(dsedBytes.length == 0) {
if (dsedBytes.length == 0) {
headerInfo = " DeviceSecurityEventData2 object is empty";
}
else {
} else {
dsedHeader2 = new DeviceSecurityEventDataHeader2(dsedBytes);
headerInfo = dsedHeader2.toString();

Expand All @@ -71,12 +70,10 @@ public DeviceSecurityEventData2(final byte[] dsedBytes) {
if (subHeaderType == DeviceSecurityEventDataSubHeader.SUBHEADERTYPE_MEAS_BLOCK) {
dsedSubHeader = new DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock(dsedSubHeaderBytes);
subHeaderInfo += dsedSubHeader.toString();
}
else if (subHeaderType == DeviceSecurityEventDataSubHeader.SUBHEADERTYPE_CERT_CHAIN) {
} else if (subHeaderType == DeviceSecurityEventDataSubHeader.SUBHEADERTYPE_CERT_CHAIN) {
dsedSubHeader = new DeviceSecurityEventDataSubHeaderCertChain(dsedSubHeaderBytes);
subHeaderInfo += dsedSubHeader.toString();
}
else {
} else {
subHeaderInfo += " Sub header type unknown\n";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class DeviceSecurityEventDataHeader2 extends DeviceSecurityEventHeader {

/**
* Event auth state
* Event auth state.
*/
@Getter
private int authState = 0;
Expand All @@ -38,7 +38,7 @@ public class DeviceSecurityEventDataHeader2 extends DeviceSecurityEventHeader {
@Getter
private int length = 0;
/**
* Event sub headerType
* Event sub headerType.
* SUBHEADERTYPE_MEAS_BLOCK = 0
* SUBHEADERTYPE_CERT_CHAIN = 1
*/
Expand All @@ -56,12 +56,12 @@ public class DeviceSecurityEventDataHeader2 extends DeviceSecurityEventHeader {
private String subHeaderUid = "";

/**
* Auth state - success
* Auth state - success.
*/
public static final int AUTH_SUCCESS = 0;
/**
* Auth state - digital signature of the data is valid, but the public key certificate chain is not
* validated with the entry in in the UEFI device signature variable
* validated with the entry in the UEFI device signature variable.
*/
public static final int AUTH_NO_AUTHORITY = 1;
/**
Expand All @@ -70,15 +70,15 @@ public class DeviceSecurityEventDataHeader2 extends DeviceSecurityEventHeader {
*/
public static final int AUTH_NO_BINDING = 2;
/**
* Auth state - data has no digital signature
* Auth state - data has no digital signature.
*/
public static final int AUTH_FAIL_NO_SIG = 3;
/**
* Auth state - data is invalid
* Auth state - data is invalid.
*/
public static final int AUTH_FAIL_INVALID = 4;
/**
* Auth state - device is not an SPDM-capable device
* Auth state - device is not an SPDM-capable device.
*/
public static final int AUTH_NO_SPDM = 0xFF;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public String toString() {

List<String> classCodeList = translateDeviceClass(classCode);
dSEDpciContextInfo += " Device Class: \n";
if(classCodeList.size() == 3) {
if (classCodeList.size() == 3) {
dSEDpciContextInfo += " Class = " + classCodeList.get(0) + "\n";
dSEDpciContextInfo += " Subclass = " + classCodeList.get(1) + "\n";
dSEDpciContextInfo += " Programming Interface = " + classCodeList.get(2) + "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
public abstract class DeviceSecurityEventDataSubHeader {

/**
* Sub header type - SPDM measurement block
* Sub header type - SPDM measurement block.
*/
public static final int SUBHEADERTYPE_MEAS_BLOCK = 0;
/**
* Sub header type - SPDM cert chain
* Sub header type - SPDM cert chain.
*/
public static final int SUBHEADERTYPE_CERT_CHAIN = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SpdmBaseHashAlgo: SPDM Base Hash Algorithm for the root certificate in the SPDM Certificate chain
* SpdmCertChain: SPDM Certificate Chain
*/
public class DeviceSecurityEventDataSubHeaderCertChain extends DeviceSecurityEventDataSubHeader{
public class DeviceSecurityEventDataSubHeaderCertChain extends DeviceSecurityEventDataSubHeader {

/**
* SPDM version.
Expand All @@ -42,7 +42,7 @@ public class DeviceSecurityEventDataSubHeaderCertChain extends DeviceSecurityEve
/**
* Human-readable description of any error associated with SPDM base hash alg.
*/
String spdmCertChainError = "";
private String spdmCertChainError = "";

/**
* DeviceSecurityEventDataSubHeaderCertChain Constructor.
Expand Down Expand Up @@ -75,15 +75,14 @@ public DeviceSecurityEventDataSubHeaderCertChain(final byte[] dsedSubHBytes) {

int spdmBaseHashAlgoSize = SpdmHa.tcgAlgIdToByteSize(spdmBaseHashAlgo);

if(spdmCertChainSize <= 0) {
spdmCertChainError += "SPDM cert chain length is not >0, " +
"stopping cert chain processing";
if (spdmCertChainSize <= 0) {
spdmCertChainError += "SPDM cert chain length is not >0, "
+ "stopping cert chain processing";
} else if (spdmBaseHashAlgoSize <= 0) {
spdmCertChainError += "SPDM base hash algorithm size is not >0 "
+ "stopping cert chain processing";
}
else if(spdmBaseHashAlgoSize <= 0) {
spdmCertChainError += "SPDM base hash algorithm size is not >0 " +
"stopping cert chain processing";
}
if(spdmCertChainError.isEmpty()) {
if (spdmCertChainError.isEmpty()) {
spdmCertChain = new SpdmCertificateChain(spdmCertChainBytes, spdmBaseHashAlgoSize);
}
}
Expand All @@ -101,13 +100,11 @@ public String toString() {
dsedSubHeaderInfo += " SPDM Base Hash Algorithm = " + spdmBaseHashAlgoStr + "\n";

// SPDM Certificate Chain output
if(!spdmCertChainError.isEmpty()) {
if (!spdmCertChainError.isEmpty()) {
dsedSubHeaderInfo += " SPDM cert chain error: " + spdmCertChainError + "\n";
}
else if(spdmCertChain == null) {
} else if (spdmCertChain == null) {
dsedSubHeaderInfo += " SPDM cert chain error: Could not parse cert chain\n";
}
else {
} else {
dsedSubHeaderInfo += spdmCertChain.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ public String toString() {
dsedSubHeaderInfo += " SPDM Hash Algorithm = " + spdmHashAlgoStr + "\n";

// SPDM Measurement Block List output
dsedSubHeaderInfo += " Number of SPDM Measurement Blocks = " +
spdmMeasurementBlockList.size() + "\n";
dsedSubHeaderInfo += " Number of SPDM Measurement Blocks = "
+ spdmMeasurementBlockList.size() + "\n";
int spdmMeasBlockCnt = 1;
for (SpdmMeasurementBlock spdmMeasBlock : spdmMeasurementBlockList) {
dsedSubHeaderInfo += " SPDM Measurement Block # " + spdmMeasBlockCnt++ + " of " +
spdmMeasurementBlockList.size() + "\n";
dsedSubHeaderInfo += " SPDM Measurement Block # " + spdmMeasBlockCnt++ + " of "
+ spdmMeasurementBlockList.size() + "\n";
dsedSubHeaderInfo += spdmMeasBlock.toString();
}
if(spdmMeasurementBlockReadError) {
dsedSubHeaderInfo += " Error reading SPDM Measurement Block #" +
spdmMeasBlockCnt + ", halting processing\n";
if (spdmMeasurementBlockReadError) {
dsedSubHeaderInfo += " Error reading SPDM Measurement Block #"
+ spdmMeasBlockCnt + ", halting processing\n";
}

return dsedSubHeaderInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public abstract class DeviceSecurityEventHeader {
@Getter
private String signature = "";
/**
* Version determines data structure used (..DATA or ..DATA2),
* which determines whether ..HEADER or ..HEADER2 is used
* Version determines data structure used (..DATA or ..DATA2).
* This determines whether ..HEADER or ..HEADER2 is used.
*/
@Getter
private String version = "";
Expand Down Expand Up @@ -108,7 +108,7 @@ public DeviceSecurityEventHeader(final byte[] dSEDbytes) {
* @param dsedBytes byte array holding the DeviceSecurityEventData/Data2.
* @param startByte starting byte of device type (depends on header fields before it).
*/
public void extractDeviceType(final byte[] dsedBytes, int startByte) {
public void extractDeviceType(final byte[] dsedBytes, final int startByte) {

// get the device type ID
byte[] deviceTypeBytes = new byte[UefiConstants.SIZE_4];
Expand All @@ -124,24 +124,26 @@ public void extractDeviceType(final byte[] dsedBytes, int startByte) {
* @param dsedBytes byte array holding the DeviceSecurityEventData/Data2.
* @param startByte starting byte of device path (depends on header fields before it).
*/
public void extractDevicePathAndFinalSize(final byte[] dsedBytes, int startByte) {
public void extractDevicePathAndFinalSize(final byte[] dsedBytes, final int startByte) {

int startByteUpdated = startByte;

// get the device path length
byte[] devicePathLengthBytes = new byte[8];
System.arraycopy(dsedBytes, startByte, devicePathLengthBytes, 0, 8);
System.arraycopy(dsedBytes, startByteUpdated, devicePathLengthBytes, 0, 8);
int devicePathLength = HexUtils.leReverseInt(devicePathLengthBytes);

// get the device path
if (devicePathLength > 0) {
startByte = startByte + 8;
startByteUpdated = startByteUpdated + 8;
byte[] devPathBytes = new byte[devicePathLength];
System.arraycopy(dsedBytes, startByte, devPathBytes,
System.arraycopy(dsedBytes, startByteUpdated, devPathBytes,
0, devicePathLength);
devicePath = new UefiDevicePath(devPathBytes);
}

// header total size
dsedHeaderLength = startByte + devicePathLength;
dsedHeaderLength = startByteUpdated + devicePathLength;
}

/**
Expand Down Expand Up @@ -176,8 +178,7 @@ public String toString() {
if (devicePath != null) {
dsedHeaderCommonInfo += " SPDM Device Path:\n";
dsedHeaderCommonInfo += devicePath;
}
else {
} else {
dsedHeaderCommonInfo += " SPDM Device Path = Unknown or invalid\n";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class EvEfiSpdmDeviceSecurityEvent {
/**
* Human-readable description of the data within this DEVICE_SECURITY_EVENT_DATA/..DATA2 event.
*/
String spdmInfo = "";
private String spdmInfo = "";

/**
* EvEfiSpdmFirmwareBlob constructor.
Expand Down Expand Up @@ -72,24 +72,20 @@ public EvEfiSpdmDeviceSecurityEvent(final byte[] eventData) {
if (dsedVersion.equals("0200")) {
dsed = new DeviceSecurityEventData2(eventData);
spdmInfo += dsed.toString();
}
else {
} else {
spdmInfo += " Incompatible version for DeviceSecurityEventData2: " + dsedVersion + "\n";
}
}
else if (dsedSignature.contains("SPDM Device Sec")) { // implies Device Security event
} else if (dsedSignature.contains("SPDM Device Sec")) { // implies Device Security event

spdmInfo = " Signature = SPDM Device Sec\n";

if (dsedVersion.equals("0100")) {
dsed = new DeviceSecurityEventData(eventData);
spdmInfo += dsed.toString();
}
else {
} else {
spdmInfo += " Incompatible version for DeviceSecurityEventData: " + dsedVersion + "\n";
}
}
else {
} else {
spdmInfo = " Signature = Undetermined value: " + dsedSignature + "\n";
}
}
Expand Down
Loading

0 comments on commit 583869f

Please sign in to comment.