Skip to content

Commit

Permalink
issue-844: Finished cleaning up code using checkstyles guidelines on …
Browse files Browse the repository at this point in the history
…HIRS-Utils test module. Finishing up cleaning on main module.
  • Loading branch information
ThatSilentCoder committed Oct 11, 2024
1 parent b80d722 commit 337a626
Show file tree
Hide file tree
Showing 27 changed files with 458 additions and 422 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hirs.utils.digest;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hirs.utils.enums;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hirs.utils.exception;
1 change: 1 addition & 0 deletions HIRS_Utils/src/main/java/hirs/utils/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hirs.utils;
1 change: 1 addition & 0 deletions HIRS_Utils/src/main/java/hirs/utils/rim/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hirs.utils.rim;
56 changes: 28 additions & 28 deletions HIRS_Utils/src/main/java/hirs/utils/swid/SwidTagConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,34 @@ public class SwidTagConstants {
public static final String FX_SEPARATOR = ":";
public static final String RFC3852_PFX = "rcf3852";
public static final String RFC3339_PFX = "rcf3339";
public static final String _COLLOQUIAL_VERSION_STR = N8060_PFX + FX_SEPARATOR +
COLLOQUIAL_VERSION;
public static final String _PRODUCT_STR = N8060_PFX + FX_SEPARATOR +
PRODUCT;
public static final String _REVISION_STR = N8060_PFX + FX_SEPARATOR +
REVISION;
public static final String _EDITION_STR = N8060_PFX + FX_SEPARATOR +
EDITION;
public static final String _RIM_LINK_HASH_STR = RIM_PFX + FX_SEPARATOR +
RIM_LINK_HASH;
public static final String _BINDING_SPEC_STR = RIM_PFX + FX_SEPARATOR +
BINDING_SPEC;
public static final String _BINDING_SPEC_VERSION_STR = RIM_PFX + FX_SEPARATOR +
BINDING_SPEC_VERSION;
public static final String _PLATFORM_MANUFACTURER_STR = RIM_PFX + FX_SEPARATOR +
PLATFORM_MANUFACTURER_STR;
public static final String _PLATFORM_MANUFACTURER_ID_STR = RIM_PFX + FX_SEPARATOR +
PLATFORM_MANUFACTURER_ID;
public static final String _PLATFORM_MODEL_STR = RIM_PFX + FX_SEPARATOR +
PLATFORM_MODEL;
public static final String _PLATFORM_VERSION_STR = RIM_PFX + FX_SEPARATOR +
PLATFORM_VERSION;
public static final String _PAYLOAD_TYPE_STR = RIM_PFX + FX_SEPARATOR +
PAYLOAD_TYPE;
public static final String _PC_URI_LOCAL_STR = RIM_PFX + FX_SEPARATOR +
PC_URI_LOCAL;
public static final String _PC_URI_GLOBAL_STR = RIM_PFX + FX_SEPARATOR +
PC_URI_GLOBAL;
public static final String _COLLOQUIAL_VERSION_STR = N8060_PFX + FX_SEPARATOR
+ COLLOQUIAL_VERSION;
public static final String _PRODUCT_STR = N8060_PFX + FX_SEPARATOR
+ PRODUCT;
public static final String _REVISION_STR = N8060_PFX + FX_SEPARATOR
+ REVISION;
public static final String _EDITION_STR = N8060_PFX + FX_SEPARATOR
+ EDITION;
public static final String _RIM_LINK_HASH_STR = RIM_PFX + FX_SEPARATOR
+ RIM_LINK_HASH;
public static final String _BINDING_SPEC_STR = RIM_PFX + FX_SEPARATOR
+ BINDING_SPEC;
public static final String _BINDING_SPEC_VERSION_STR = RIM_PFX + FX_SEPARATOR
+ BINDING_SPEC_VERSION;
public static final String _PLATFORM_MANUFACTURER_STR = RIM_PFX + FX_SEPARATOR
+ PLATFORM_MANUFACTURER_STR;
public static final String _PLATFORM_MANUFACTURER_ID_STR = RIM_PFX + FX_SEPARATOR
+ PLATFORM_MANUFACTURER_ID;
public static final String _PLATFORM_MODEL_STR = RIM_PFX + FX_SEPARATOR
+ PLATFORM_MODEL;
public static final String _PLATFORM_VERSION_STR = RIM_PFX + FX_SEPARATOR
+ PLATFORM_VERSION;
public static final String _PAYLOAD_TYPE_STR = RIM_PFX + FX_SEPARATOR
+ PAYLOAD_TYPE;
public static final String _PC_URI_LOCAL_STR = RIM_PFX + FX_SEPARATOR
+ PC_URI_LOCAL;
public static final String _PC_URI_GLOBAL_STR = RIM_PFX + FX_SEPARATOR
+ PC_URI_GLOBAL;
public static final QName _SHA256_HASH = new QName(
"http://www.w3.org/2001/04/xmlenc#sha256", HASH, "SHA256");
public static final QName _COLLOQUIAL_VERSION = new QName(
Expand Down
1 change: 1 addition & 0 deletions HIRS_Utils/src/main/java/hirs/utils/swid/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hirs.utils.swid;
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,55 @@
* The first 16 bytes of the event data header MUST be a String based identifier (Signature),
* NUL-terminated, per PFP. The only currently defined Signature is "SPDM Device Sec",
* which implies the data is a DEVICE_SECURITY_EVENT_DATA or ..DATA2.
*
* <p>
* HEADERS defined by PFP v1.06 Rev 52.
* Certain fields are common to both ..HEADER and ..HEADER2, and are noted below the structures.
* <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER {
* UINT8 Signature[16];
* UINT16 Version;
* UINT16 Length;
* UINT32 SpdmHashAlg;
* UINT32 DeviceType;
* SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock;
* UINT64 DevicePathLength;
* UNIT8 DevicePath[DevicePathLength]
* UINT8 Signature[16];
* UINT16 Version;
* UINT16 Length;
* UINT32 SpdmHashAlg;
* UINT32 DeviceType;
* SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock;
* UINT64 DevicePathLength;
* UNIT8 DevicePath[DevicePathLength]
* } DEVICE_SECURITY_EVENT_DATA_HEADER;
* <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER2 { - NOT IMPLEMENTED YET
* UINT8 Signature[16];
* UINT16 Version;
* UINT8 AuthState;
* UINT8 Reserved;
* UINT32 Length;
* UINT32 DeviceType;
* UINT32 SubHeaderType;
* UINT32 SubHeaderLength;
* UINT32 SubHeaderUID;
* UINT64 DevicePathLength;
* UNIT8 DevicePath[DevicePathLength]
* UINT8 Signature[16];
* UINT16 Version;
* UINT8 AuthState;
* UINT8 Reserved;
* UINT32 Length;
* UINT32 DeviceType;
* UINT32 SubHeaderType;
* UINT32 SubHeaderLength;
* UINT32 SubHeaderUID;
* UINT64 DevicePathLength;
* UNIT8 DevicePath[DevicePathLength]
* } DEVICE_SECURITY_EVENT_DATA_HEADER2;
* <p>
* Fields common to both ..HEADER and ..HEADER2:
* Signature
* Version
* DeviceType
* DevicePathLength
* DevicePath
* Signature
* Version
* DeviceType
* DevicePathLength
* DevicePath
* <p>
*/
public abstract class DeviceSecurityEventHeader {

/**
* UEFI Device Path Length.
*/
@Getter
private final int devicePathLength = 0;
/**
* Contains the size (in bytes) of the header.
*/
@Getter
private Integer dsedHeaderLength = 0;

/**
* Signature (text) data.
*/
Expand All @@ -73,11 +77,6 @@ public abstract class DeviceSecurityEventHeader {
*/
@Getter
private int deviceType = -1;
/**
* UEFI Device Path Length.
*/
@Getter
private int devicePathLength = 0;
/**
* UEFI Device path.
*/
Expand Down Expand Up @@ -131,19 +130,19 @@ public void extractDevicePathAndFinalSize(final byte[] dsedBytes, final int star
// get the device path length
byte[] devicePathLengthBytes = new byte[8];
System.arraycopy(dsedBytes, startByteUpdated, devicePathLengthBytes, 0, 8);
int devicePathLength = HexUtils.leReverseInt(devicePathLengthBytes);
int retrievedDevicePathLength = HexUtils.leReverseInt(devicePathLengthBytes);

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

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

/**
Expand Down
21 changes: 8 additions & 13 deletions HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmHa.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
*/
public class SpdmHa {

/**
* Default private constructor so checkstyles doesn't complain
*/
private SpdmHa() { }

/**
* Spdm Hash Alg = Raw bit stream.
*/
Expand Down Expand Up @@ -40,6 +35,12 @@ private SpdmHa() { }
*/
public static final int TPM_ALG_SHA3_512 = 64;

/**
* Default private constructor so checkstyles doesn't complain.
*/
private SpdmHa() {
}

/**
* Returns the hash name via a lookup.
* Lookup based upon SPDM Spec v1.03 section 10.4.
Expand Down Expand Up @@ -93,21 +94,15 @@ public static int tcgAlgIdToByteSize(final int algId) {
case TPM_ALG_SHA_256:
byteSize = 32;
break;
case TPM_ALG_SHA_384:
case TPM_ALG_SHA_384, TPM_ALG_SHA3_384:
byteSize = 48;
break;
case TPM_ALG_SHA_512:
case TPM_ALG_SHA_512, TPM_ALG_SHA3_512:
byteSize = 64;
break;
case TPM_ALG_SHA3_256:
byteSize = 32;
break;
case TPM_ALG_SHA3_384:
byteSize = 48;
break;
case TPM_ALG_SHA3_512:
byteSize = 64;
break;
default:
byteSize = -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@
* <p>
* Measurement, defined by SPDM v1.03, Sect 10.11.1, Table 54:
* DMTF measurement spec format {
* DMTFSpecMeasurementValueType 1 byte;
* DMTFSpecMeasurementValueSize 2 bytes;
* DMTFSpecMeasurementValue <DMTFSpecMeasurementValueSize> bytes;
* DMTFSpecMeasurementValueType 1 byte;
* DMTFSpecMeasurementValueSize 2 bytes;
* DMTFSpecMeasurementValue <DMTFSpecMeasurementValueSize> bytes;
* }
* <p>
* DMTFSpecMeasurementValueType[7]
* Indicates how bits [0:6] are represented
* Bit = 0: Digest
* Bit = 1: Raw bit stream
* Indicates how bits [0:6] are represented
* Bit = 0: Digest
* Bit = 1: Raw bit stream
* DMTFSpecMeasurementValueType[6:0] (see SPDM Spec, Table 55 "DMTFSpecMeasurementValueType[6:0]")
* Immutable ROM 0x0
* Mutable firmware 0x1
* Hardware configuration 0x2
* Firmware configuration 0x3
* etc.
* Immutable ROM 0x0
* Mutable firmware 0x1
* Hardware configuration 0x2
* Firmware configuration 0x3
* etc.
* <p>
*/
public class SpdmMeasurement {

/**
* Measurement value (digest).
*/
private final byte[] dmtfSpecMeasurementValue;
/**
* Measurement value type (such as mutable firmware, etc).
*/
@Getter
private int dmtfSpecMeasurementValueType = 0;
/**
* Measurement value (digest).
*/
private byte[] dmtfSpecMeasurementValue;

/**
* SpdmMeasurement Constructor.
Expand All @@ -49,64 +49,41 @@ public SpdmMeasurement(final byte[] spdmMeasBytes) {
1);
dmtfSpecMeasurementValueType = HexUtils.leReverseInt(dmtfSpecMeasurementValueTypeBytes);

// in future, can crosscheck this value size + 3 with the spdm block MeasurementSize size
// in the future, can crosscheck this value size + 3 with the spdm block MeasurementSize size
byte[] dmtfSpecMeasurementValueSizeBytes = new byte[2];
System.arraycopy(spdmMeasBytes, 1, dmtfSpecMeasurementValueSizeBytes, 0,
2);
int dmtfSpecMeasurementValueSize = HexUtils.leReverseInt(dmtfSpecMeasurementValueSizeBytes);

dmtfSpecMeasurementValue = new byte[dmtfSpecMeasurementValueSize];
System.arraycopy(spdmMeasBytes, 3, dmtfSpecMeasurementValue, 0,

final int sourceIndex = 3;
System.arraycopy(spdmMeasBytes, sourceIndex, dmtfSpecMeasurementValue, 0,
dmtfSpecMeasurementValueSize);
}

/**
* Lookup for SPDM measurement value type.
*
* @param measValType the numerical representation of the measurement value type.
*
* @return a description of the measurement value type.
*/
public String dmtfSpecMeasurementValueTypeToString(final int measValType) {

String measValTypeStr;
switch (measValType) {
case 0:
measValTypeStr = "Immutable ROM";
break;
case 1:
measValTypeStr = "Mutable firmware";
break;
case 2:
measValTypeStr = "Hardware configuration";
break;
case 3:
measValTypeStr = "Firmware configuration";
break;
case 4:
measValTypeStr = "Freeform measurement manifest";
break;
case 5:
measValTypeStr = "Structured representation of debug and device mode";
break;
case 6:
measValTypeStr = "Mutable firmware's version number";
break;
case 7:
measValTypeStr = "Mutable firmware's security version number";
break;
case 8:
measValTypeStr = "Hash-extended measurement";
break;
case 9:
measValTypeStr = "Informational";
break;
case 10:
measValTypeStr = "Structured measurement manifest";
break;
default:
measValTypeStr = "Unknown or invalid DMTF Spec Measurement Value Type";
}
String measValTypeStr = switch (measValType) {
case 0 -> "Immutable ROM";
case 1 -> "Mutable firmware";
case 2 -> "Hardware configuration";
case 3 -> "Firmware configuration";
case 4 -> "Freeform measurement manifest";
case 5 -> "Structured representation of debug and device mode";
case 6 -> "Mutable firmware's version number";
case 7 -> "Mutable firmware's security version number";
case 8 -> "Hash-extended measurement";
case 9 -> "Informational";
case 10 -> "Structured measurement manifest";
default -> "Unknown or invalid DMTF Spec Measurement Value Type";
};
return measValTypeStr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* Non-persistent classes related to TGC Event Logs.
*/

package hirs.utils.tpm.eventlog.spdm;
package hirs.utils.tpm.eventlog.spdm;
Loading

0 comments on commit 337a626

Please sign in to comment.