diff --git a/HIRS_Utils/src/main/java/hirs/utils/digest/package-info.java b/HIRS_Utils/src/main/java/hirs/utils/digest/package-info.java new file mode 100644 index 000000000..2d2e9eca2 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/digest/package-info.java @@ -0,0 +1 @@ +package hirs.utils.digest; diff --git a/HIRS_Utils/src/main/java/hirs/utils/enums/package-info.java b/HIRS_Utils/src/main/java/hirs/utils/enums/package-info.java new file mode 100644 index 000000000..3ff5c9ba5 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/enums/package-info.java @@ -0,0 +1 @@ +package hirs.utils.enums; diff --git a/HIRS_Utils/src/main/java/hirs/utils/exception/package-info.java b/HIRS_Utils/src/main/java/hirs/utils/exception/package-info.java new file mode 100644 index 000000000..464dea8c2 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/exception/package-info.java @@ -0,0 +1 @@ +package hirs.utils.exception; diff --git a/HIRS_Utils/src/main/java/hirs/utils/package-info.java b/HIRS_Utils/src/main/java/hirs/utils/package-info.java new file mode 100644 index 000000000..361ebc748 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/package-info.java @@ -0,0 +1 @@ +package hirs.utils; diff --git a/HIRS_Utils/src/main/java/hirs/utils/rim/package-info.java b/HIRS_Utils/src/main/java/hirs/utils/rim/package-info.java new file mode 100644 index 000000000..e72d99d13 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/rim/package-info.java @@ -0,0 +1 @@ +package hirs.utils.rim; diff --git a/HIRS_Utils/src/main/java/hirs/utils/swid/SwidTagConstants.java b/HIRS_Utils/src/main/java/hirs/utils/swid/SwidTagConstants.java index a17086137..baec697f2 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/swid/SwidTagConstants.java +++ b/HIRS_Utils/src/main/java/hirs/utils/swid/SwidTagConstants.java @@ -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( diff --git a/HIRS_Utils/src/main/java/hirs/utils/swid/package-info.java b/HIRS_Utils/src/main/java/hirs/utils/swid/package-info.java new file mode 100644 index 000000000..91c5a00fb --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/swid/package-info.java @@ -0,0 +1 @@ +package hirs.utils.swid; diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventHeader.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventHeader.java index 13612538d..1f413c20c 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventHeader.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventHeader.java @@ -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. - * + *
* HEADERS defined by PFP v1.06 Rev 52. * Certain fields are common to both ..HEADER and ..HEADER2, and are noted below the structures. *
* 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; *
* 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; *
* Fields common to both ..HEADER and ..HEADER2: - * Signature - * Version - * DeviceType - * DevicePathLength - * DevicePath + * Signature + * Version + * DeviceType + * DevicePathLength + * DevicePath *
*/ 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. */ @@ -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. */ @@ -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; } /** diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmHa.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmHa.java index b64d013be..ae6189263 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmHa.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmHa.java @@ -6,11 +6,6 @@ */ public class SpdmHa { - /** - * Default private constructor so checkstyles doesn't complain - */ - private SpdmHa() { } - /** * Spdm Hash Alg = Raw bit stream. */ @@ -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. @@ -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; } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurement.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurement.java index 4a90cacb4..b1ed423ec 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurement.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurement.java @@ -8,34 +8,34 @@ *
* Measurement, defined by SPDM v1.03, Sect 10.11.1, Table 54:
* DMTF measurement spec format {
- * DMTFSpecMeasurementValueType 1 byte;
- * DMTFSpecMeasurementValueSize 2 bytes;
- * DMTFSpecMeasurementValue
* 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.
*
*/
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.
@@ -49,14 +49,16 @@ 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);
}
@@ -64,49 +66,24 @@ public SpdmMeasurement(final byte[] spdmMeasBytes) {
* 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;
}
diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/package-info.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/package-info.java
index 64b778b43..f76263ad5 100644
--- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/package-info.java
+++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/package-info.java
@@ -2,4 +2,4 @@
* Non-persistent classes related to TGC Event Logs.
*/
-package hirs.utils.tpm.eventlog.spdm;
\ No newline at end of file
+package hirs.utils.tpm.eventlog.spdm;
diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiConstants.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiConstants.java
index 655ffa686..71e942434 100644
--- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiConstants.java
+++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiConstants.java
@@ -7,11 +7,6 @@
*/
public final class UefiConstants {
- /**
- * Default private constructor so checkstyles doesn't complain
- */
- private UefiConstants() { }
-
/**
* 2 byte size.
*/
@@ -278,13 +273,18 @@ private UefiConstants() { }
public static final String FILESTATUS_FROM_FILESYSTEM = "fileFromFilesystem";
/**
* file status, where file was not found on local machine, so file from code was used.
- * For instance, if vendor-table.json is not found in filesystem at location
- * /etc/hirs/aca/default-properties/, it will be grabbed from code at
- * HIRS_AttestationCA/src/main/resources/.
+ * For instance, if vendor-table.json is not found in filesystem at location
+ * /etc/hirs/aca/default-properties/, it will be grabbed from code at
+ * HIRS_AttestationCA/src/main/resources/.
*/
public static final String FILESTATUS_FROM_CODE = "fileFromCode";
/**
* file status, where file is not accessible (either not found, or no access permission).
*/
public static final String FILESTATUS_NOT_ACCESSIBLE = "fileNotAccessible";
+ /**
+ * Default private constructor so checkstyles doesn't complain.
+ */
+ private UefiConstants() {
+ }
}
diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/DigestTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/DigestTest.java
index c0f4a82ad..bc030f81a 100644
--- a/HIRS_Utils/src/test/java/hirs/data/persist/DigestTest.java
+++ b/HIRS_Utils/src/test/java/hirs/data/persist/DigestTest.java
@@ -1,28 +1,61 @@
package hirs.data.persist;
-import java.util.Arrays;
-
import hirs.utils.digest.Digest;
import hirs.utils.digest.DigestAlgorithm;
import hirs.utils.digest.DigestComparisonResultType;
import org.apache.commons.codec.digest.DigestUtils;
-
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import java.util.Arrays;
+
/**
* Unit tests for the Digest
class.
*/
public class DigestTest {
private static final int DIGEST_LENGTH_BYTES = 20;
+ /**
+ * Get a test SHA1 digest.
+ *
+ * @return a test SHA1 digest
+ */
+ public static Digest getTestSHA1Digest() {
+ return new Digest(DigestAlgorithm.SHA1, getTestDigest(DIGEST_LENGTH_BYTES));
+ }
+
+ /**
+ * Get a test SHA1 digest filled with the given byte.
+ *
+ * @param fill the byte that will be used to fill the digest
+ * @return a test SHA1 digest with repeated entries of the given byte
+ */
+ public static Digest getTestSHA1Digest(final byte fill) {
+ return new Digest(DigestAlgorithm.SHA1, getTestDigest(DIGEST_LENGTH_BYTES, fill));
+ }
+
+ private static byte[] getTestDigest(final int count) {
+ return getTestDigest(count, (byte) 1);
+ }
+
+ private static byte[] getTestDigest(final int count, final byte fill) {
+ final byte[] ret = new byte[count];
+ Arrays.fill(ret, fill);
+ return ret;
+ }
+
+ private static byte[] getZeroValueDigest(final int count) {
+ return new byte[count];
+ }
+
/**
* Tests that constructor throws a IllegalArgumentException
when a
* null DigestAlgorithm
is passed into constructor.
*/
@Test
public final void nullAlgorithm() {
- final byte[] digest = getTestDigest(16);
+ final int count = 16;
+ final byte[] digest = getTestDigest(count);
Assertions.assertThrows(IllegalArgumentException.class,
() -> new Digest(null, digest));
}
@@ -52,7 +85,8 @@ public final void emptyArrayDigest() {
*/
@Test
public final void md2() {
- final byte[] digest = getTestDigest(16);
+ final int count = 16;
+ final byte[] digest = getTestDigest(count);
final Digest d = new Digest(DigestAlgorithm.MD2, digest);
Assertions.assertNotNull(d);
}
@@ -62,7 +96,8 @@ public final void md2() {
*/
@Test
public final void testFromStringMD2() {
- final byte[] digestBytes = getTestDigest(16);
+ final int count = 16;
+ final byte[] digestBytes = getTestDigest(count);
Digest digest = new Digest(DigestAlgorithm.MD2, digestBytes);
String digestString = digest.toString();
Digest digestFromString = Digest.fromString(digestString);
@@ -75,7 +110,8 @@ public final void testFromStringMD2() {
*/
@Test
public final void md2IllegalDigest() {
- final byte[] digest = getTestDigest(17);
+ final int count = 17;
+ final byte[] digest = getTestDigest(count);
Assertions.assertThrows(IllegalArgumentException.class,
() -> new Digest(DigestAlgorithm.MD2, digest));
}
@@ -85,7 +121,8 @@ public final void md2IllegalDigest() {
*/
@Test
public final void md5() {
- final byte[] digest = getTestDigest(16);
+ final int count = 16;
+ final byte[] digest = getTestDigest(count);
final Digest d = new Digest(DigestAlgorithm.MD5, digest);
Assertions.assertNotNull(d);
}
@@ -95,7 +132,8 @@ public final void md5() {
*/
@Test
public final void testFromStringMD5() {
- final byte[] digestBytes = getTestDigest(16);
+ final int count = 16;
+ final byte[] digestBytes = getTestDigest(count);
Digest digest = new Digest(DigestAlgorithm.MD5, digestBytes);
String digestString = digest.toString();
Digest digestFromString = Digest.fromString(digestString);
@@ -108,7 +146,8 @@ public final void testFromStringMD5() {
*/
@Test
public final void md5IllegalDigest() {
- final byte[] digest = getTestDigest(17);
+ final int count = 17;
+ final byte[] digest = getTestDigest(count);
Assertions.assertThrows(IllegalArgumentException.class,
() -> new Digest(DigestAlgorithm.MD5, digest));
}
@@ -118,7 +157,8 @@ public final void md5IllegalDigest() {
*/
@Test
public final void sha1() {
- final byte[] digest = getTestDigest(20);
+ final int count = 20;
+ final byte[] digest = getTestDigest(count);
final Digest d = new Digest(DigestAlgorithm.SHA1, digest);
Assertions.assertNotNull(d);
}
@@ -128,7 +168,8 @@ public final void sha1() {
*/
@Test
public final void testFromStringSHA1() {
- final byte[] digestBytes = getTestDigest(20);
+ final int count = 20;
+ final byte[] digestBytes = getTestDigest(count);
Digest digest = new Digest(DigestAlgorithm.SHA1, digestBytes);
String digestString = digest.toString();
Digest digestFromString = Digest.fromString(digestString);
@@ -141,7 +182,8 @@ public final void testFromStringSHA1() {
*/
@Test
public final void sha1IllegalDigest() {
- final byte[] digest = getTestDigest(21);
+ final int count = 21;
+ final byte[] digest = getTestDigest(count);
Assertions.assertThrows(IllegalArgumentException.class,
() -> new Digest(DigestAlgorithm.SHA1, digest));
}
@@ -151,7 +193,8 @@ public final void sha1IllegalDigest() {
*/
@Test
public final void sha256() {
- final byte[] digest = getTestDigest(32);
+ final int count = 32;
+ final byte[] digest = getTestDigest(count);
final Digest d = new Digest(DigestAlgorithm.SHA256, digest);
Assertions.assertNotNull(d);
}
@@ -161,7 +204,8 @@ public final void sha256() {
*/
@Test
public final void testFromStringSHA256() {
- final byte[] digestBytes = getTestDigest(32);
+ final int count = 32;
+ final byte[] digestBytes = getTestDigest(count);
Digest digest = new Digest(DigestAlgorithm.SHA256, digestBytes);
String digestString = digest.toString();
Digest digestFromString = Digest.fromString(digestString);
@@ -174,7 +218,8 @@ public final void testFromStringSHA256() {
*/
@Test
public final void sha256IllegalDigest() {
- final byte[] digest = getTestDigest(33);
+ final int count = 33;
+ final byte[] digest = getTestDigest(count);
Assertions.assertThrows(IllegalArgumentException.class,
() -> new Digest(DigestAlgorithm.SHA256, digest));
}
@@ -184,7 +229,8 @@ public final void sha256IllegalDigest() {
*/
@Test
public final void sha384() {
- final byte[] digest = getTestDigest(48);
+ final int count = 48;
+ final byte[] digest = getTestDigest(count);
final Digest d = new Digest(DigestAlgorithm.SHA384, digest);
Assertions.assertNotNull(d);
}
@@ -194,7 +240,8 @@ public final void sha384() {
*/
@Test
public final void testFromStringSHA384() {
- final byte[] digestBytes = getTestDigest(48);
+ final int count = 48;
+ final byte[] digestBytes = getTestDigest(count);
Digest digest = new Digest(DigestAlgorithm.SHA384, digestBytes);
String digestString = digest.toString();
Digest digestFromString = Digest.fromString(digestString);
@@ -207,7 +254,8 @@ public final void testFromStringSHA384() {
*/
@Test
public final void sha384IllegalDigest() {
- final byte[] digest = getTestDigest(49);
+ final int count = 49;
+ final byte[] digest = getTestDigest(count);
Assertions.assertThrows(IllegalArgumentException.class,
() -> new Digest(DigestAlgorithm.SHA384, digest));
}
@@ -217,7 +265,8 @@ public final void sha384IllegalDigest() {
*/
@Test
public final void sha512() {
- final byte[] digest = getTestDigest(64);
+ final int count = 64;
+ final byte[] digest = getTestDigest(count);
final Digest d = new Digest(DigestAlgorithm.SHA512, digest);
Assertions.assertNotNull(d);
}
@@ -227,7 +276,8 @@ public final void sha512() {
*/
@Test
public final void testFromStringSHA512() {
- final byte[] digestBytes = getTestDigest(64);
+ final int count = 64;
+ final byte[] digestBytes = getTestDigest(count);
Digest digest = new Digest(DigestAlgorithm.SHA512, digestBytes);
String digestString = digest.toString();
Digest digestFromString = Digest.fromString(digestString);
@@ -240,7 +290,8 @@ public final void testFromStringSHA512() {
*/
@Test
public final void sha512IllegalDigest() {
- final byte[] digest = getTestDigest(65);
+ final int count = 65;
+ final byte[] digest = getTestDigest(count);
Assertions.assertThrows(IllegalArgumentException.class,
() -> new Digest(DigestAlgorithm.SHA512, digest));
}
@@ -251,7 +302,8 @@ public final void sha512IllegalDigest() {
*/
@Test
public final void testGetAlgorithm() {
- final Digest d = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
+ final int count = 20;
+ final Digest d = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
Assertions.assertEquals(d.getAlgorithm(), DigestAlgorithm.SHA1);
}
@@ -261,9 +313,10 @@ public final void testGetAlgorithm() {
*/
@Test
public final void testGetDigest() {
- final Digest d = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
+ final int count = 20;
+ final Digest d = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
final byte[] digestBytes = d.getDigest();
- final byte[] testBytes = getTestDigest(20);
+ final byte[] testBytes = getTestDigest(count);
Assertions.assertArrayEquals(digestBytes, testBytes);
digestBytes[0] = (byte) (digestBytes[0] + 1);
Assertions.assertArrayEquals(d.getDigest(), testBytes);
@@ -276,8 +329,9 @@ public final void testGetDigest() {
*/
@Test
public final void testHashCodeEqual() {
- final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
- final Digest d2 = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
+ final int count = 20;
+ final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
+ final Digest d2 = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
Assertions.assertEquals(d2.hashCode(), d1.hashCode());
}
@@ -286,8 +340,9 @@ public final void testHashCodeEqual() {
*/
@Test
public final void testMatchedComparison() {
- final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
- final Digest d2 = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
+ final int count = 20;
+ final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
+ final Digest d2 = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
Assertions.assertEquals(DigestComparisonResultType.MATCH, d1.compare(d2));
Assertions.assertEquals(DigestComparisonResultType.MATCH, d2.compare(d1));
}
@@ -298,8 +353,9 @@ public final void testMatchedComparison() {
*/
@Test
public final void testHashCodeNotEqualAlgorithm() {
- final Digest d1 = new Digest(DigestAlgorithm.MD2, getTestDigest(16));
- final Digest d2 = new Digest(DigestAlgorithm.MD5, getTestDigest(16));
+ final int count = 16;
+ final Digest d1 = new Digest(DigestAlgorithm.MD2, getTestDigest(count));
+ final Digest d2 = new Digest(DigestAlgorithm.MD5, getTestDigest(count));
Assertions.assertNotEquals(d2.hashCode(), d1.hashCode());
}
@@ -308,8 +364,9 @@ public final void testHashCodeNotEqualAlgorithm() {
*/
@Test
public final void testMismatchAlgorithm() {
- final Digest d1 = new Digest(DigestAlgorithm.MD2, getTestDigest(16));
- final Digest d2 = new Digest(DigestAlgorithm.MD5, getTestDigest(16));
+ final int count = 16;
+ final Digest d1 = new Digest(DigestAlgorithm.MD2, getTestDigest(count));
+ final Digest d2 = new Digest(DigestAlgorithm.MD5, getTestDigest(count));
Assertions.assertEquals(DigestComparisonResultType.MISMATCH, d1.compare(d2));
Assertions.assertEquals(DigestComparisonResultType.MISMATCH, d2.compare(d1));
}
@@ -320,7 +377,8 @@ public final void testMismatchAlgorithm() {
*/
@Test
public final void testHashCodeNotEqualDigest() {
- final byte[] digest = getTestDigest(20);
+ final int count = 20;
+ final byte[] digest = getTestDigest(count);
final Digest d1 = new Digest(DigestAlgorithm.SHA1, digest);
digest[0] += 1;
final Digest d2 = new Digest(DigestAlgorithm.SHA1, digest);
@@ -334,8 +392,9 @@ public final void testHashCodeNotEqualDigest() {
*/
@Test
public final void testEqual() {
- final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
- final Digest d2 = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
+ final int count = 20;
+ final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
+ final Digest d2 = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
Assertions.assertEquals(d2, d1);
}
@@ -345,8 +404,9 @@ public final void testEqual() {
*/
@Test
public final void testNotEqualAlgorithm() {
- final Digest d1 = new Digest(DigestAlgorithm.MD2, getTestDigest(16));
- final Digest d2 = new Digest(DigestAlgorithm.MD5, getTestDigest(16));
+ final int count = 16;
+ final Digest d1 = new Digest(DigestAlgorithm.MD2, getTestDigest(count));
+ final Digest d2 = new Digest(DigestAlgorithm.MD5, getTestDigest(count));
Assertions.assertNotEquals(d2, d1);
}
@@ -356,7 +416,8 @@ public final void testNotEqualAlgorithm() {
*/
@Test
public final void testNotEqualDigest() {
- final byte[] digest = getTestDigest(20);
+ final int count = 20;
+ final byte[] digest = getTestDigest(count);
final Digest d1 = new Digest(DigestAlgorithm.SHA1, digest);
digest[0] += 1;
final Digest d2 = new Digest(DigestAlgorithm.SHA1, digest);
@@ -369,7 +430,8 @@ public final void testNotEqualDigest() {
*/
@Test
public final void testCompareToNull() {
- final Digest d1 = new Digest(DigestAlgorithm.MD2, getTestDigest(16));
+ final int count = 16;
+ final Digest d1 = new Digest(DigestAlgorithm.MD2, getTestDigest(count));
Assertions.assertEquals(DigestComparisonResultType.UNKNOWN, d1.compare(null));
}
@@ -379,8 +441,9 @@ public final void testCompareToNull() {
*/
@Test
public final void testCompareToDigestWithBothZeroizedHash() {
- final Digest d1 = new Digest(DigestAlgorithm.SHA1, getZeroValueDigest(20));
- final Digest d2 = new Digest(DigestAlgorithm.SHA1, getZeroValueDigest(20));
+ final int count = 20;
+ final Digest d1 = new Digest(DigestAlgorithm.SHA1, getZeroValueDigest(count));
+ final Digest d2 = new Digest(DigestAlgorithm.SHA1, getZeroValueDigest(count));
Assertions.assertEquals(DigestComparisonResultType.MATCH, d1.compare(d2));
Assertions.assertEquals(DigestComparisonResultType.MATCH, d2.compare(d1));
}
@@ -391,8 +454,9 @@ public final void testCompareToDigestWithBothZeroizedHash() {
*/
@Test
public final void testCompareToDigestWithOneZeroizedHash() {
- final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
- final Digest d2 = new Digest(DigestAlgorithm.SHA1, getZeroValueDigest(20));
+ final int count = 20;
+ final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
+ final Digest d2 = new Digest(DigestAlgorithm.SHA1, getZeroValueDigest(count));
Assertions.assertEquals(DigestComparisonResultType.MISMATCH, d1.compare(d2));
Assertions.assertEquals(DigestComparisonResultType.MISMATCH, d2.compare(d1));
}
@@ -415,7 +479,8 @@ public final void testCompareToDigestWithBothEmptyHash() {
*/
@Test
public final void testCompareToDigestWithOneEmptyHash() {
- final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(20));
+ final int count = 20;
+ final Digest d1 = new Digest(DigestAlgorithm.SHA1, getTestDigest(count));
final Digest d2 = new Digest(DigestAlgorithm.SHA1, getEmptySHA1Digest());
Assertions.assertEquals(DigestComparisonResultType.MISMATCH, d1.compare(d2));
Assertions.assertEquals(DigestComparisonResultType.MISMATCH, d2.compare(d1));
@@ -431,40 +496,7 @@ public final void testFromStringInvalid() {
() -> Digest.fromString(invalidDigestString));
}
- /**
- * Get a test SHA1 digest.
- *
- * @return a test SHA1 digest
- */
- public static Digest getTestSHA1Digest() {
- return new Digest(DigestAlgorithm.SHA1, getTestDigest(DIGEST_LENGTH_BYTES));
- }
-
- /**
- * Get a test SHA1 digest filled with the given byte.
- *
- * @param fill the byte that will be used to fill the digest
- * @return a test SHA1 digest with repeated entries of the given byte
- */
- public static Digest getTestSHA1Digest(final byte fill) {
- return new Digest(DigestAlgorithm.SHA1, getTestDigest(DIGEST_LENGTH_BYTES, fill));
- }
-
- private static byte[] getTestDigest(final int count) {
- return getTestDigest(count, (byte) 1);
- }
-
- private static byte[] getTestDigest(final int count, final byte fill) {
- final byte[] ret = new byte[count];
- Arrays.fill(ret, fill);
- return ret;
- }
-
- private static byte[] getZeroValueDigest(final int count) {
- return new byte[count];
- }
-
private byte[] getEmptySHA1Digest() {
- return DigestUtils.sha1(new byte[]{});
+ return DigestUtils.sha1(new byte[] {});
}
}
diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/FirmwareInfoTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/FirmwareInfoTest.java
index e337399f3..5c8aad511 100644
--- a/HIRS_Utils/src/test/java/hirs/data/persist/FirmwareInfoTest.java
+++ b/HIRS_Utils/src/test/java/hirs/data/persist/FirmwareInfoTest.java
@@ -2,11 +2,11 @@
import hirs.attestationca.persist.entity.userdefined.info.FirmwareInfo;
import org.apache.commons.lang3.StringUtils;
-import static hirs.utils.enums.DeviceInfoEnums.NOT_SPECIFIED;
-
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import static hirs.utils.enums.DeviceInfoEnums.NOT_SPECIFIED;
+
/**
* FirmwareInfoTest is a unit test class for FirmwareInfo.
*/
@@ -15,18 +15,20 @@ public class FirmwareInfoTest {
private static final String BIOS_VENDOR = "test bios vendor";
private static final String BIOS_VERSION = "test bios version";
private static final String BIOS_RELEASE_DATE = "test bios release date";
+ private static final int PRIMARY_SIZE = 257;
+ private static final int SECONDARY_SIZE = 33;
private static final String LONG_BIOS_VENDOR = StringUtils.rightPad(
- "test bios vendor",
- 257
+ BIOS_VENDOR,
+ PRIMARY_SIZE
);
private static final String LONG_BIOS_VERSION = StringUtils.rightPad(
- "test bios version",
- 257
+ BIOS_VERSION,
+ PRIMARY_SIZE
);
private static final String LONG_BIOS_RELEASE_DATE = StringUtils.rightPad(
- "test bios release date",
- 33
+ BIOS_RELEASE_DATE,
+ SECONDARY_SIZE
);
/**
@@ -44,8 +46,8 @@ public final void firmwareInfo() {
public final void firmwareInfoNoParams() {
FirmwareInfo firmwareInfo = new FirmwareInfo();
Assertions.assertEquals(NOT_SPECIFIED, firmwareInfo.getBiosVendor());
- Assertions.assertEquals(NOT_SPECIFIED,firmwareInfo.getBiosVersion());
- Assertions.assertEquals(NOT_SPECIFIED,firmwareInfo.getBiosReleaseDate());
+ Assertions.assertEquals(NOT_SPECIFIED, firmwareInfo.getBiosVersion());
+ Assertions.assertEquals(NOT_SPECIFIED, firmwareInfo.getBiosReleaseDate());
}
/**
diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/HardwareInfoTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/HardwareInfoTest.java
index a5ab1f4ef..d0ffee837 100644
--- a/HIRS_Utils/src/test/java/hirs/data/persist/HardwareInfoTest.java
+++ b/HIRS_Utils/src/test/java/hirs/data/persist/HardwareInfoTest.java
@@ -1,12 +1,12 @@
package hirs.data.persist;
import hirs.attestationca.persist.entity.userdefined.info.HardwareInfo;
-import static hirs.utils.enums.DeviceInfoEnums.NOT_SPECIFIED;
-
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import static hirs.utils.enums.DeviceInfoEnums.NOT_SPECIFIED;
+
/**
* HardwareInfoTest is a unit test class for HardwareInfo.
*/
@@ -18,30 +18,32 @@ public class HardwareInfoTest {
private static final String SERIAL_NUMBER = "test serial number";
private static final String CHASSIS_SERIAL_NUMBER = "test chassis serial number";
private static final String BASEBOARD_SERIAL_NUMBER = "test baseboard serial number";
+ private static final int PRIMARY_SIZE = 257;
+ private static final int SECONDARY_SIZE = 65;
private static final String LONG_MANUFACTURER = StringUtils.rightPad(
- "test manufacturer",
- 257
+ MANUFACTURER,
+ PRIMARY_SIZE
);
private static final String LONG_PRODUCT_NAME = StringUtils.rightPad(
- "test product name",
- 257
+ PRODUCT_NAME,
+ PRIMARY_SIZE
);
private static final String LONG_VERSION = StringUtils.rightPad(
- "test version",
- 65
+ VERSION,
+ SECONDARY_SIZE
);
private static final String LONG_SERIAL_NUMBER = StringUtils.rightPad(
- "test serial number",
- 257
+ SERIAL_NUMBER,
+ PRIMARY_SIZE
);
private static final String LONG_CHASSIS_SERIAL_NUMBER = StringUtils.rightPad(
- "test chassis serial number",
- 257
+ CHASSIS_SERIAL_NUMBER,
+ PRIMARY_SIZE
);
private static final String LONG_BASEBOARD_SERIAL_NUMBER = StringUtils.rightPad(
- "test baseboard serial number",
- 257
+ BASEBOARD_SERIAL_NUMBER,
+ PRIMARY_SIZE
);
/**
diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/NetworkInfoTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/NetworkInfoTest.java
index f8476597b..042f00379 100644
--- a/HIRS_Utils/src/test/java/hirs/data/persist/NetworkInfoTest.java
+++ b/HIRS_Utils/src/test/java/hirs/data/persist/NetworkInfoTest.java
@@ -1,12 +1,12 @@
package hirs.data.persist;
import hirs.attestationca.persist.entity.userdefined.info.NetworkInfo;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
/**
* NetworkInfoTest is a unit test class for NetworkInfo.
*/
@@ -17,6 +17,15 @@ public class NetworkInfoTest {
private static final byte[] MAC_ADDRESS = new byte[] {11, 22, 33, 44, 55,
66};
+ private static InetAddress getTestIpAddress() {
+ try {
+ final byte[] byteAddress = new byte[] {127, 0, 0, 1};
+ return InetAddress.getByAddress(byteAddress);
+ } catch (UnknownHostException e) {
+ return null;
+ }
+ }
+
/**
* Tests instantiation of a NetworkInfo object.
*/
@@ -103,14 +112,14 @@ public final void testHashCodeNotEqualsHostname() {
* Tests that hashcodes generated by NetworkInfo objects with different IP
* addresses are not equal.
*
- * @throws UnknownHostException
- * in case the InetAddress is not created correctly
+ * @throws UnknownHostException in case the InetAddress is not created correctly
*/
@Test
public final void testHashCodeNotEqualsIpAddress()
throws UnknownHostException {
+ final byte[] byteAddress = new byte[] {127, 0, 0, 2};
final InetAddress ipAddress2 =
- InetAddress.getByAddress(new byte[] {127, 0, 0, 2});
+ InetAddress.getByAddress(byteAddress);
NetworkInfo ni1 = new NetworkInfo(HOSTNAME, IP_ADDRESS, MAC_ADDRESS);
NetworkInfo ni2 = new NetworkInfo(HOSTNAME, ipAddress2, MAC_ADDRESS);
Assertions.assertNotEquals(ni2.hashCode(), ni1.hashCode());
@@ -155,13 +164,13 @@ public final void testNotEqualsHostname() {
* Tests that two NetworkInfo objects are not equal if they have different
* IP addresses.
*
- * @throws UnknownHostException
- * in case InetAddress is not created correctly
+ * @throws UnknownHostException in case InetAddress is not created correctly
*/
@Test
public final void testNotEqualsIpAddress() throws UnknownHostException {
+ final byte[] byteAddress = new byte[] {127, 0, 0, 2};
final InetAddress ipAddress2 =
- InetAddress.getByAddress(new byte[] {127, 0, 0, 2});
+ InetAddress.getByAddress(byteAddress);
NetworkInfo ni1 = new NetworkInfo(HOSTNAME, IP_ADDRESS, MAC_ADDRESS);
NetworkInfo ni2 = new NetworkInfo(HOSTNAME, ipAddress2, MAC_ADDRESS);
Assertions.assertNotEquals(ni2, ni1);
@@ -178,12 +187,4 @@ public final void testNotEqualsMacAddress() {
NetworkInfo ni2 = new NetworkInfo(HOSTNAME, IP_ADDRESS, macAddress2);
Assertions.assertNotEquals(ni2, ni1);
}
-
- private static InetAddress getTestIpAddress() {
- try {
- return InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
- } catch (UnknownHostException e) {
- return null;
- }
- }
}
diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/OSInfoTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/OSInfoTest.java
index 20b82abf0..39d648632 100644
--- a/HIRS_Utils/src/test/java/hirs/data/persist/OSInfoTest.java
+++ b/HIRS_Utils/src/test/java/hirs/data/persist/OSInfoTest.java
@@ -1,12 +1,12 @@
package hirs.data.persist;
import hirs.attestationca.persist.entity.userdefined.info.OSInfo;
-import static hirs.utils.enums.DeviceInfoEnums.NOT_SPECIFIED;
-
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import static hirs.utils.enums.DeviceInfoEnums.NOT_SPECIFIED;
+
/**
* OSInfoTest is a unit test class for OSInfo.
*/
@@ -17,10 +17,12 @@ public class OSInfoTest {
private static final String OS_ARCH = "test osArch";
private static final String DISTRIBUTION = "test distribution";
private static final String DISTRIBUTION_RELEASE = "test distribution release";
+ private static final int PRIMARY_SIZE = 257;
+ private static final int SECONDARY_SIZE = 33;
- private static final String LONG_OS_NAME = StringUtils.rightPad("test os", 257);
- private static final String LONG_OS_VERSION = StringUtils.rightPad("test osVersion", 257);
- private static final String LONG_OS_ARCH = StringUtils.rightPad("test osArch", 33);
+ private static final String LONG_OS_NAME = StringUtils.rightPad(OS_NAME, PRIMARY_SIZE);
+ private static final String LONG_OS_VERSION = StringUtils.rightPad(OS_VERSION, PRIMARY_SIZE);
+ private static final String LONG_OS_ARCH = StringUtils.rightPad(OS_ARCH, SECONDARY_SIZE);
/**
* Tests instantiation of an OSInfo object.
@@ -63,7 +65,7 @@ public final void osInfoGetters() {
@Test
public final void osNameNullTest() {
Assertions.assertThrows(IllegalArgumentException.class, () ->
- new OSInfo(null, OS_VERSION, OS_ARCH, DISTRIBUTION, DISTRIBUTION_RELEASE));
+ new OSInfo(null, OS_VERSION, OS_ARCH, DISTRIBUTION, DISTRIBUTION_RELEASE));
}
/**
@@ -72,7 +74,7 @@ public final void osNameNullTest() {
@Test
public final void osVersionNullTest() {
Assertions.assertThrows(IllegalArgumentException.class, () ->
- new OSInfo(OS_NAME, null, OS_ARCH, DISTRIBUTION, DISTRIBUTION_RELEASE));
+ new OSInfo(OS_NAME, null, OS_ARCH, DISTRIBUTION, DISTRIBUTION_RELEASE));
}
/**
@@ -81,7 +83,7 @@ public final void osVersionNullTest() {
@Test
public final void osArchNullTest() {
Assertions.assertThrows(IllegalArgumentException.class, () ->
- new OSInfo(OS_NAME, OS_VERSION, null, DISTRIBUTION, DISTRIBUTION_RELEASE));
+ new OSInfo(OS_NAME, OS_VERSION, null, DISTRIBUTION, DISTRIBUTION_RELEASE));
}
/**
@@ -108,7 +110,7 @@ public final void osVersionLongTest() {
@Test
public final void osArchLongTest() {
Assertions.assertThrows(IllegalArgumentException.class, () ->
- new OSInfo(OS_NAME, OS_VERSION, LONG_OS_ARCH, DISTRIBUTION, DISTRIBUTION_RELEASE));
+ new OSInfo(OS_NAME, OS_VERSION, LONG_OS_ARCH, DISTRIBUTION, DISTRIBUTION_RELEASE));
}
/**
diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/package-info.java b/HIRS_Utils/src/test/java/hirs/data/persist/package-info.java
new file mode 100644
index 000000000..387d0845f
--- /dev/null
+++ b/HIRS_Utils/src/test/java/hirs/data/persist/package-info.java
@@ -0,0 +1 @@
+package hirs.data.persist;
diff --git a/HIRS_Utils/src/test/java/hirs/tpm/eventlog/uefi/UefiProcessingTest.java b/HIRS_Utils/src/test/java/hirs/tpm/eventlog/uefi/UefiProcessingTest.java
index 183af2933..f069208ec 100644
--- a/HIRS_Utils/src/test/java/hirs/tpm/eventlog/uefi/UefiProcessingTest.java
+++ b/HIRS_Utils/src/test/java/hirs/tpm/eventlog/uefi/UefiProcessingTest.java
@@ -1,25 +1,29 @@
package hirs.tpm.eventlog.uefi;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-
import com.eclipsesource.json.JsonObject;
+import hirs.utils.HexUtils;
import hirs.utils.JsonUtils;
-import hirs.utils.tpm.eventlog.uefi.*;
+import hirs.utils.tpm.eventlog.uefi.UefiDevicePath;
+import hirs.utils.tpm.eventlog.uefi.UefiFirmware;
+import hirs.utils.tpm.eventlog.uefi.UefiGuid;
+import hirs.utils.tpm.eventlog.uefi.UefiPartition;
+import hirs.utils.tpm.eventlog.uefi.UefiVariable;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import hirs.utils.HexUtils;
-
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+
/**
* Class for testing TCG Event Log processing of UEFI defined Data.
*/
@@ -61,7 +65,7 @@ public static final void tearDown() {
* @throws IOException when processing the test fails.
* @throws NoSuchAlgorithmException if non TCG Algorithm is encountered.
* @throws CertificateException if parsing issue for X509 cert is encountered.
- * @throws URISyntaxException File location exception
+ * @throws URISyntaxException File location exception
*/
@Test
public final void testUefiVariables() throws IOException,
@@ -70,7 +74,7 @@ public final void testUefiVariables() throws IOException,
Path jsonPath = Paths.get(this.getClass()
.getResource(JSON_FILE).toURI());
String uefiTxt = IOUtils.toString(this.getClass().getResourceAsStream(UEFI_VARIABLE_BOOT),
- "UTF-8");
+ StandardCharsets.UTF_8);
byte[] uefiVariableBytes = HexUtils.hexStringToByteArray(uefiTxt);
UefiVariable uefiVariable = new UefiVariable(uefiVariableBytes);
UefiGuid guid = uefiVariable.getUefiVarGuid();
@@ -83,7 +87,7 @@ public final void testUefiVariables() throws IOException,
uefiTxt = IOUtils.toString(this.getClass()
.getResourceAsStream(UEFI_VARIABLE_BOOT_SECURE_BOOT),
- "UTF-8");
+ StandardCharsets.UTF_8);
uefiVariableBytes = HexUtils.hexStringToByteArray(uefiTxt);
uefiVariable = new UefiVariable(uefiVariableBytes);
guid = uefiVariable.getUefiVarGuid();
@@ -94,7 +98,7 @@ public final void testUefiVariables() throws IOException,
Assertions.assertEquals("SecureBoot", varName);
uefiTxt = IOUtils.toString(this.getClass().getResourceAsStream(
- UEFI_VARIABLE_BOOT_DRIVER_CONFIG_KEK), "UTF-8");
+ UEFI_VARIABLE_BOOT_DRIVER_CONFIG_KEK), StandardCharsets.UTF_8);
uefiVariableBytes = HexUtils.hexStringToByteArray(uefiTxt);
uefiVariable = new UefiVariable(uefiVariableBytes);
varName = uefiVariable.getEfiVarName();
@@ -107,7 +111,7 @@ public final void testUefiVariables() throws IOException,
* @throws IOException when processing the test fails.
* @throws NoSuchAlgorithmException if non TCG Algorithm is encountered.
* @throws CertificateException if parsing issue for X509 cert is encountered.
- * @throws URISyntaxException File location exception
+ * @throws URISyntaxException File location exception
*/
@Test
public final void testUefiPartiton() throws IOException,
@@ -116,7 +120,7 @@ public final void testUefiPartiton() throws IOException,
Path jsonPath = Paths.get(this.getClass()
.getResource(JSON_FILE).toURI());
String uefiTxt = IOUtils.toString(this.getClass().getResourceAsStream(UEFI_GPT_EVENT),
- "UTF-8");
+ StandardCharsets.UTF_8);
byte[] uefiPartitionBytes = HexUtils.hexStringToByteArray(uefiTxt);
UefiPartition gptPart = new UefiPartition(uefiPartitionBytes);
String gptPartName = gptPart.getPartitionName();
@@ -143,29 +147,33 @@ public final void testUefiFirmwareBlob() throws IOException,
CertificateException, NoSuchAlgorithmException {
LOGGER.debug("Testing the parsing of Uefi Firmware Blob");
String uefiTxt = IOUtils.toString(this.getClass()
- .getResourceAsStream(UEFI_FW_BLOB), "UTF-8");
+ .getResourceAsStream(UEFI_FW_BLOB), StandardCharsets.UTF_8);
byte[] uefiFwBlobBytes = HexUtils.hexStringToByteArray(uefiTxt);
UefiFirmware uefiFWBlob = new UefiFirmware(uefiFwBlobBytes);
int fwAddress = uefiFWBlob.getPhysicalBlobAddress();
int fwLength = uefiFWBlob.getBlobLength();
- Assertions.assertEquals(1797287936, fwAddress);
- Assertions.assertEquals(851968, fwLength);
+
+ final int expectedFwAddress = 1797287936;
+ Assertions.assertEquals(expectedFwAddress, fwAddress);
+
+ final int expectedFwLength = 851968;
+ Assertions.assertEquals(expectedFwLength, fwLength);
}
/**
* Tests the processing of a UEFI defined Device Path.
*
- * @throws IOException when processing the test fails.
+ * @throws IOException when processing the test fails.
* @throws URISyntaxException File location exception
*/
@Test
public final void testUefiDevicePath() throws IOException, URISyntaxException {
LOGGER.debug("Testing the parsing of Uefi Device Path");
String uefiTxt = IOUtils.toString(this.getClass().getResourceAsStream(UEFI_DEVICE_PATH),
- "UTF-8");
+ StandardCharsets.UTF_8);
byte[] uefiFwBlobBytes = HexUtils.hexStringToByteArray(uefiTxt);
UefiDevicePath uefiDevPath = new UefiDevicePath(uefiFwBlobBytes);
String devPathType = uefiDevPath.getType();
Assertions.assertEquals("Media Device Path", devPathType);
}
-}
\ No newline at end of file
+}
diff --git a/HIRS_Utils/src/test/java/hirs/tpm/eventlog/uefi/package-info.java b/HIRS_Utils/src/test/java/hirs/tpm/eventlog/uefi/package-info.java
new file mode 100644
index 000000000..8762db479
--- /dev/null
+++ b/HIRS_Utils/src/test/java/hirs/tpm/eventlog/uefi/package-info.java
@@ -0,0 +1 @@
+package hirs.tpm.eventlog.uefi;
diff --git a/HIRS_Utils/src/test/java/hirs/utils/BouncyCastleUtilsTest.java b/HIRS_Utils/src/test/java/hirs/utils/BouncyCastleUtilsTest.java
index 141165366..6588051c3 100644
--- a/HIRS_Utils/src/test/java/hirs/utils/BouncyCastleUtilsTest.java
+++ b/HIRS_Utils/src/test/java/hirs/utils/BouncyCastleUtilsTest.java
@@ -2,8 +2,9 @@
import org.apache.logging.log4j.util.Strings;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests methods in the (@link BouncyCastleUtils) utility class.
@@ -46,4 +47,4 @@ public void testX500NameCompareFalse() {
assertFalse(BouncyCastleUtils.x500NameCompare(
MALFORMED_RDN_STRING, MALFORMED_RDN_STRING));
}
-}
\ No newline at end of file
+}
diff --git a/HIRS_Utils/src/test/java/hirs/utils/HexUtilsTest.java b/HIRS_Utils/src/test/java/hirs/utils/HexUtilsTest.java
index 9e3ba416e..11fd72a8f 100644
--- a/HIRS_Utils/src/test/java/hirs/utils/HexUtilsTest.java
+++ b/HIRS_Utils/src/test/java/hirs/utils/HexUtilsTest.java
@@ -1,6 +1,7 @@
package hirs.utils;
import org.junit.jupiter.api.Test;
+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -14,11 +15,10 @@ public class HexUtilsTest {
*/
@Test
public void testHexStringToByteArray() {
- String s = "abcd1234";
- byte[] target = {-85, -51, 18, 52};
-
- byte[] b = HexUtils.hexStringToByteArray(s);
- assertArrayEquals(b, target);
+ final String testString = "abcd1234";
+ final byte[] expectedBytes = {-85, -51, 18, 52};
+ final byte[] actualBytes = HexUtils.hexStringToByteArray(testString);
+ assertArrayEquals(expectedBytes, actualBytes);
}
/**
@@ -26,11 +26,10 @@ public void testHexStringToByteArray() {
*/
@Test
public void testByteArrayToHexString() {
- String target = "abcd1234";
- byte[] b = {-85, -51, 18, 52};
-
- String s = HexUtils.byteArrayToHexString(b);
- assertEquals(s, target);
+ final byte[] byteArray = {-85, -51, 18, 52};
+ final String expectedString = "abcd1234";
+ final String actualString = HexUtils.byteArrayToHexString(byteArray);
+ assertEquals(expectedString, actualString);
}
/**
@@ -38,11 +37,10 @@ public void testByteArrayToHexString() {
*/
@Test
public void testByteArrayToHexStringConditional() {
- String target = "abcd0100";
- byte[] b = {-85, -51, 1, 0};
-
- String s = HexUtils.byteArrayToHexString(b);
- assertEquals(s, target);
+ final byte[] byteArray = {-85, -51, 1, 0};
+ final String expectedHexString = "abcd0100";
+ final String actualHexString = HexUtils.byteArrayToHexString(byteArray);
+ assertEquals(expectedHexString, actualHexString);
}
/**
@@ -50,9 +48,10 @@ public void testByteArrayToHexStringConditional() {
*/
@Test
public void testHexToInt() {
- String s = "ff";
- Integer i = HexUtils.hexToInt(s);
- assertEquals((int) i, HexUtils.FF_BYTE);
+ final String testString = "ff";
+ final int expectedInt = HexUtils.FF_BYTE;
+ final Integer actualInt = HexUtils.hexToInt(testString);
+ assertEquals(expectedInt, (int) actualInt);
}
/**
@@ -60,14 +59,11 @@ public void testHexToInt() {
*/
@Test
public void testSubarray() {
- byte[] b = {-85, -51, 18, 52};
- byte[] target = {-51, 18};
-
- byte[] sub = HexUtils.subarray(b, 1, 2);
-
- assertArrayEquals(sub, target);
+ final byte[] b = {-85, -51, 18, 52};
+ final byte[] expectedSubArray = {-51, 18};
+ final byte[] actualSubArray = HexUtils.subarray(b, 1, 2);
+ assertArrayEquals(expectedSubArray, actualSubArray);
}
-
}
diff --git a/HIRS_Utils/src/test/java/hirs/utils/StringValidatorTest.java b/HIRS_Utils/src/test/java/hirs/utils/StringValidatorTest.java
index 18efdbc76..200d1e25d 100644
--- a/HIRS_Utils/src/test/java/hirs/utils/StringValidatorTest.java
+++ b/HIRS_Utils/src/test/java/hirs/utils/StringValidatorTest.java
@@ -1,11 +1,12 @@
package hirs.utils;
import org.apache.logging.log4j.Logger;
-import org.mockito.Mockito;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import org.mockito.Mockito;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.times;
/**
@@ -114,10 +115,10 @@ public void testValidateMaxLengthSuccessOnNull() {
@Test
public void testValidateMaxLengthFailOnLongString() {
assertThrows(IllegalArgumentException.class, () ->
- assertEquals(
- StringValidator.check(NONEMPTY_VALUE, FIELD_NAME).maxLength(SMALL_LENGTH).getValue(),
- NONEMPTY_VALUE
- ));
+ assertEquals(
+ StringValidator.check(NONEMPTY_VALUE, FIELD_NAME).maxLength(SMALL_LENGTH).getValue(),
+ NONEMPTY_VALUE
+ ));
}
/**
@@ -138,8 +139,8 @@ public void testValidateSeveralConditionsSuccess() {
@Test
public void testValidateSeveralConditionsFailOnLast() {
assertThrows(IllegalArgumentException.class, () ->
- StringValidator.check(NONEMPTY_VALUE, FIELD_NAME)
- .notNull().notBlank().maxLength(SMALL_LENGTH));
+ StringValidator.check(NONEMPTY_VALUE, FIELD_NAME)
+ .notNull().notBlank().maxLength(SMALL_LENGTH));
}
/**
@@ -155,4 +156,4 @@ public void testCheckLoggerIsUsedOnFailure() {
}
Mockito.verify(mockLogger, times(1)).error(Mockito.anyString());
}
-}
\ No newline at end of file
+}
diff --git a/HIRS_Utils/src/test/java/hirs/utils/package-info.java b/HIRS_Utils/src/test/java/hirs/utils/package-info.java
new file mode 100644
index 000000000..361ebc748
--- /dev/null
+++ b/HIRS_Utils/src/test/java/hirs/utils/package-info.java
@@ -0,0 +1 @@
+package hirs.utils;
diff --git a/HIRS_Utils/src/test/java/hirs/utils/tpm/eventlog/TCGEventLogTest.java b/HIRS_Utils/src/test/java/hirs/utils/tpm/eventlog/TCGEventLogTest.java
index 7fe0aefd6..b3c81ac5d 100644
--- a/HIRS_Utils/src/test/java/hirs/utils/tpm/eventlog/TCGEventLogTest.java
+++ b/HIRS_Utils/src/test/java/hirs/utils/tpm/eventlog/TCGEventLogTest.java
@@ -1,20 +1,20 @@
package hirs.utils.tpm.eventlog;
+import org.apache.commons.io.IOUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
import java.io.IOException;
import java.io.InputStream;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Arrays;
-import org.apache.commons.io.IOUtils;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LogManager;
-
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
+import static hirs.utils.tpm.eventlog.TCGEventLog.PCR_COUNT;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -36,103 +36,108 @@ public class TCGEventLogTest {
@BeforeAll
public static final void setup() {
LOGGER.debug("retrieving session factory");
-
}
/**
* Closes the SessionFactory
from setup.
*/
@AfterAll
- public static final void tearDown() {
- LOGGER.debug("closing session factory");
- }
-
- /**
- * Tests the processing of a crypto agile event log.
- * @throws IOException when processing the test fails
- * @throws NoSuchAlgorithmException if an unknown algorithm is encountered.
- * @throws CertificateException if a certificate fails to parse.
- */
+ public static final void tearDown() {
+ LOGGER.debug("closing session factory");
+ }
+
+ /**
+ * Tests the processing of a crypto agile event log.
+ *
+ * @throws IOException when processing the test fails
+ * @throws NoSuchAlgorithmException if an unknown algorithm is encountered.
+ * @throws CertificateException if a certificate fails to parse.
+ */
@Test
public final void testCryptoAgileTCGEventLog() throws IOException, CertificateException,
- NoSuchAlgorithmException {
- LOGGER.debug("Testing the parsing of a Crypto Agile formatted TCG Event Log");
- InputStream log, pcrs;
- boolean testPass = true;
- log = this.getClass().getResourceAsStream(DEFAULT_EVENT_LOG);
- byte[] rawLogBytes = IOUtils.toByteArray(log);
- TCGEventLog evlog = new TCGEventLog(rawLogBytes, false, false, false);
- String[] pcrFromLog = evlog.getExpectedPCRValues();
- pcrs = this.getClass().getResourceAsStream(DEFAULT_EXPECTED_PCRS);
- Object[] pcrObj = IOUtils.readLines(pcrs, "UTF-8").toArray();
- String[] pcrTxt = Arrays.copyOf(pcrObj, pcrObj.length, String[].class);
-
- // Test 1 get all PCRs
- for (int i = 0; i < 24; i++) {
- if (pcrFromLog[i].compareToIgnoreCase(pcrTxt[i]) != 0) {
- testPass = false;
- LOGGER.error("\ntestTCGEventLogProcessorParser error with PCR " + i);
- }
- }
- assertTrue(testPass);
-
- // Test 2 get an individual PCR
- String pcr3 = evlog.getExpectedPCRValue(3);
- assertThat(pcrFromLog[3], equalTo(pcr3));
-
- // Test 3 check the Algorithm String Identifier used in the log
- String algStr = evlog.getEventLogHashAlgorithm();
- assertThat("TPM_ALG_SHA256", equalTo(algStr));
-
- // Test 4 check the Algorithm # Identifier used in the log
- int id = evlog.getEventLogHashAlgorithmID();
- assertThat(TcgTpmtHa.TPM_ALG_SHA256, equalTo(id));
-
- LOGGER.debug("OK. Parsing of a Crypto Agile Format Success");
+ NoSuchAlgorithmException {
+ LOGGER.debug("Testing the parsing of a Crypto Agile formatted TCG Event Log");
+
+ // setup
+ final InputStream log = this.getClass().getResourceAsStream(DEFAULT_EVENT_LOG);
+ final InputStream pcrs = this.getClass().getResourceAsStream(DEFAULT_EXPECTED_PCRS);
+ final byte[] rawLogBytes = IOUtils.toByteArray(log);
+ final TCGEventLog evlog = new TCGEventLog(rawLogBytes, false, false, false);
+ final String[] pcrFromLog = evlog.getExpectedPCRValues();
+ final Object[] pcrObj = IOUtils.readLines(pcrs, "UTF-8").toArray();
+ final String[] pcrTxt = Arrays.copyOf(pcrObj, pcrObj.length, String[].class);
+
+ boolean testPass = true;
+
+ // Test 1 get all PCRs
+ for (int i = 0; i < PCR_COUNT; i++) {
+ if (pcrFromLog[i].compareToIgnoreCase(pcrTxt[i]) != 0) {
+ testPass = false;
+ LOGGER.error("\ntestTCGEventLogProcessorParser error with PCR {}", i);
+ }
+ }
+ assertTrue(testPass);
+
+ // Test 2 get an individual PCR
+ final int pcrIndex = 3;
+ String pcr3 = evlog.getExpectedPCRValue(pcrIndex);
+ assertThat(pcrFromLog[pcrIndex], equalTo(pcr3));
+
+ // Test 3 check the Algorithm String Identifier used in the log
+ String algStr = evlog.getEventLogHashAlgorithm();
+ assertThat("TPM_ALG_SHA256", equalTo(algStr));
+
+ // Test 4 check the Algorithm # Identifier used in the log
+ int id = evlog.getEventLogHashAlgorithmID();
+ assertThat(TcgTpmtHa.TPM_ALG_SHA256, equalTo(id));
+
+ LOGGER.debug("OK. Parsing of a Crypto Agile Format Success");
}
/**
* Tests the processing of a SHA1 formatted Event log.
- * @throws IOException when processing the test fails
+ *
+ * @throws IOException when processing the test fails
* @throws NoSuchAlgorithmException if an unknown algorithm is encountered.
- * @throws CertificateException if a certificate fails to parse.
+ * @throws CertificateException if a certificate fails to parse.
*/
@Test
public final void testSHA1TCGEventLog() throws IOException, CertificateException,
- NoSuchAlgorithmException {
- LOGGER.debug("Testing the parsing of a SHA1 formated TCG Event Log");
- InputStream log, pcrs;
- boolean testPass = true;
- log = this.getClass().getResourceAsStream(SHA1_EVENT_LOG);
- byte[] rawLogBytes = IOUtils.toByteArray(log);
- TCGEventLog evlog = new TCGEventLog(rawLogBytes, false, false, false);
- String[] pcrFromLog = evlog.getExpectedPCRValues();
- pcrs = this.getClass().getResourceAsStream(SHA1_EXPECTED_PCRS);
- Object[] pcrObj = IOUtils.readLines(pcrs, "UTF-8").toArray();
- String[] pcrTxt = Arrays.copyOf(pcrObj, pcrObj.length, String[].class);
-
- // Test 1 get all PCRs
- for (int i = 0; i < 24; i++) {
- if (pcrFromLog[i].compareToIgnoreCase(pcrTxt[i]) != 0) {
- testPass = false;
- LOGGER.error("\ntestTCGEventLogProcessorParser error with PCR " + i);
- }
- }
- assertTrue(testPass);
-
- // Test 2 get an individual PCR
- String pcr0 = evlog.getExpectedPCRValue(0);
- assertThat(pcrFromLog[0], equalTo(pcr0));
-
- // Test 3 check the Algorithm String Identifier used in the log
- String algStr = evlog.getEventLogHashAlgorithm();
- assertThat("TPM_ALG_SHA1", equalTo(algStr));
-
- // Test 4 check the Algorithm # Identifier used in the log
- int id = evlog.getEventLogHashAlgorithmID();
- assertThat(TcgTpmtHa.TPM_ALG_SHA1, equalTo(id));
-
- LOGGER.debug("OK. Parsing of a SHA1 formatted TCG Event Log Success");
- }
-
+ NoSuchAlgorithmException {
+ LOGGER.debug("Testing the parsing of a SHA1 formated TCG Event Log");
+
+ // setup
+ final InputStream log = this.getClass().getResourceAsStream(SHA1_EVENT_LOG);
+ final InputStream pcrs = this.getClass().getResourceAsStream(SHA1_EXPECTED_PCRS);
+ final byte[] rawLogBytes = IOUtils.toByteArray(log);
+ final TCGEventLog evlog = new TCGEventLog(rawLogBytes, false, false, false);
+ final String[] pcrFromLog = evlog.getExpectedPCRValues();
+ final Object[] pcrObj = IOUtils.readLines(pcrs, "UTF-8").toArray();
+ final String[] pcrTxt = Arrays.copyOf(pcrObj, pcrObj.length, String[].class);
+
+ boolean testPass = true;
+
+ // Test 1 get all PCRs
+ for (int i = 0; i < PCR_COUNT; i++) {
+ if (pcrFromLog[i].compareToIgnoreCase(pcrTxt[i]) != 0) {
+ testPass = false;
+ LOGGER.error("\ntestTCGEventLogProcessorParser error with PCR {}", i);
+ }
+ }
+ assertTrue(testPass);
+
+ // Test 2 get an individual PCR
+ String pcr0 = evlog.getExpectedPCRValue(0);
+ assertThat(pcrFromLog[0], equalTo(pcr0));
+
+ // Test 3 check the Algorithm String Identifier used in the log
+ String algStr = evlog.getEventLogHashAlgorithm();
+ assertThat("TPM_ALG_SHA1", equalTo(algStr));
+
+ // Test 4 check the Algorithm # Identifier used in the log
+ int id = evlog.getEventLogHashAlgorithmID();
+ assertThat(TcgTpmtHa.TPM_ALG_SHA1, equalTo(id));
+
+ LOGGER.debug("OK. Parsing of a SHA1 formatted TCG Event Log Success");
+ }
}
diff --git a/HIRS_Utils/src/test/java/hirs/utils/tpm/eventlog/package-info.java b/HIRS_Utils/src/test/java/hirs/utils/tpm/eventlog/package-info.java
new file mode 100644
index 000000000..979c6b4f4
--- /dev/null
+++ b/HIRS_Utils/src/test/java/hirs/utils/tpm/eventlog/package-info.java
@@ -0,0 +1 @@
+package hirs.utils.tpm.eventlog;
diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
index dbae748b0..cf854c697 100644
--- a/config/checkstyle/checkstyle.xml
+++ b/config/checkstyle/checkstyle.xml
@@ -171,7 +171,12 @@