mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-30 09:49:00 +00:00
minor updates to replace deprecated function, swap actual/expected in assertthat, and use lombok Getter
This commit is contained in:
parent
435ce61a5a
commit
a0238abe8b
@ -29,7 +29,7 @@ public final class TCGEventLog {
|
|||||||
private static final Logger LOGGER = LogManager.getLogger(TCGEventLog.class);
|
private static final Logger LOGGER = LogManager.getLogger(TCGEventLog.class);
|
||||||
/** Name of the hash algorithm used to process the Event Log, default is SHA256. */
|
/** Name of the hash algorithm used to process the Event Log, default is SHA256. */
|
||||||
@Getter
|
@Getter
|
||||||
private String algorithm = "TPM_ALG_SHA256";
|
private String eventLogHashAlgorithm = "TPM_ALG_SHA256";
|
||||||
/** Parsed event log array. */
|
/** Parsed event log array. */
|
||||||
private static final int SIG_OFFSET = 32;
|
private static final int SIG_OFFSET = 32;
|
||||||
/** TEV_NO_ACTION signature size. */
|
/** TEV_NO_ACTION signature size. */
|
||||||
@ -87,7 +87,7 @@ public final class TCGEventLog {
|
|||||||
initLocalityFourValue = LOCALITY4_SHA1_LIST;
|
initLocalityFourValue = LOCALITY4_SHA1_LIST;
|
||||||
pcrLength = EvConstants.SHA1_LENGTH;
|
pcrLength = EvConstants.SHA1_LENGTH;
|
||||||
hashType = HASH_STRING;
|
hashType = HASH_STRING;
|
||||||
algorithm = "TPM_ALG_SHA1";
|
eventLogHashAlgorithm = "TPM_ALG_SHA1";
|
||||||
initPcrList();
|
initPcrList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,14 +121,14 @@ public final class TCGEventLog {
|
|||||||
if (bCryptoAgile) {
|
if (bCryptoAgile) {
|
||||||
initValue = INIT_SHA256_LIST;
|
initValue = INIT_SHA256_LIST;
|
||||||
initLocalityFourValue = LOCALITY4_SHA256_LIST;
|
initLocalityFourValue = LOCALITY4_SHA256_LIST;
|
||||||
algorithm = "TPM_ALG_SHA256";
|
eventLogHashAlgorithm = "TPM_ALG_SHA256";
|
||||||
hashType = HASH256_STRING;
|
hashType = HASH256_STRING;
|
||||||
pcrLength = EvConstants.SHA256_LENGTH;
|
pcrLength = EvConstants.SHA256_LENGTH;
|
||||||
} else {
|
} else {
|
||||||
initValue = INIT_SHA1_LIST;
|
initValue = INIT_SHA1_LIST;
|
||||||
initLocalityFourValue = LOCALITY4_SHA1_LIST;
|
initLocalityFourValue = LOCALITY4_SHA1_LIST;
|
||||||
hashType = HASH_STRING;
|
hashType = HASH_STRING;
|
||||||
algorithm = "TPM_ALG_SHA1";
|
eventLogHashAlgorithm = "TPM_ALG_SHA1";
|
||||||
pcrLength = EvConstants.SHA1_LENGTH;
|
pcrLength = EvConstants.SHA1_LENGTH;
|
||||||
}
|
}
|
||||||
this.pcrList = new byte[PCR_COUNT][pcrLength];
|
this.pcrList = new byte[PCR_COUNT][pcrLength];
|
||||||
@ -181,7 +181,7 @@ public final class TCGEventLog {
|
|||||||
// TPMMeasurementRecord record;
|
// TPMMeasurementRecord record;
|
||||||
// String pcrValue;
|
// String pcrValue;
|
||||||
// for (int i = 0; i < PCR_COUNT; i++) {
|
// for (int i = 0; i < PCR_COUNT; i++) {
|
||||||
// if (algorithm.compareToIgnoreCase("TPM_ALG_SHA1") == 0) { // Log Was SHA1 Format
|
// if (eventLogHashAlgorithm.compareToIgnoreCase("TPM_ALG_SHA1") == 0) { // Log Was SHA1 Format
|
||||||
// pcrValue = getExpectedPCRValue(i);
|
// pcrValue = getExpectedPCRValue(i);
|
||||||
// byte[] hexValue = HexUtils.hexStringToByteArray(pcrValue);
|
// byte[] hexValue = HexUtils.hexStringToByteArray(pcrValue);
|
||||||
// final Digest hash = new Digest(DigestAlgorithm.SHA1, hexValue);
|
// final Digest hash = new Digest(DigestAlgorithm.SHA1, hexValue);
|
||||||
@ -315,22 +315,13 @@ public final class TCGEventLog {
|
|||||||
return this.toString();
|
return this.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the TCG Algorithm Registry defined string for the Digest Algorithm
|
|
||||||
* used in the event log.
|
|
||||||
* @return TCG Defined Algorithm name
|
|
||||||
*/
|
|
||||||
public String getEventLogHashAlgorithm() {
|
|
||||||
return algorithm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the TCG Algorithm Registry defined ID for the Digest Algorithm
|
* Returns the TCG Algorithm Registry defined ID for the Digest Algorithm
|
||||||
* used in the event log.
|
* used in the event log.
|
||||||
* @return TCG Defined Algorithm name
|
* @return TCG Defined Algorithm name
|
||||||
*/
|
*/
|
||||||
public int getEventLogHashAlgorithmID() {
|
public int getEventLogHashAlgorithmID() {
|
||||||
return TcgTpmtHa.tcgAlgStringToId(algorithm);
|
return TcgTpmtHa.tcgAlgStringToId(eventLogHashAlgorithm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +64,7 @@ public class TCGEventLogTest {
|
|||||||
TCGEventLog evlog = new TCGEventLog(rawLogBytes, false, false, false);
|
TCGEventLog evlog = new TCGEventLog(rawLogBytes, false, false, false);
|
||||||
String[] pcrFromLog = evlog.getExpectedPCRValues();
|
String[] pcrFromLog = evlog.getExpectedPCRValues();
|
||||||
pcrs = this.getClass().getResourceAsStream(DEFAULT_EXPECTED_PCRS);
|
pcrs = this.getClass().getResourceAsStream(DEFAULT_EXPECTED_PCRS);
|
||||||
Object[] pcrObj = IOUtils.readLines(pcrs).toArray();
|
Object[] pcrObj = IOUtils.readLines(pcrs, "UTF-8").toArray();
|
||||||
String[] pcrTxt = Arrays.copyOf(pcrObj, pcrObj.length, String[].class);
|
String[] pcrTxt = Arrays.copyOf(pcrObj, pcrObj.length, String[].class);
|
||||||
|
|
||||||
// Test 1 get all PCRs
|
// Test 1 get all PCRs
|
||||||
@ -78,15 +78,15 @@ public class TCGEventLogTest {
|
|||||||
|
|
||||||
// Test 2 get an individual PCR
|
// Test 2 get an individual PCR
|
||||||
String pcr3 = evlog.getExpectedPCRValue(3);
|
String pcr3 = evlog.getExpectedPCRValue(3);
|
||||||
assertThat(pcr3, equalTo(pcrFromLog[3]));
|
assertThat(pcrFromLog[3], equalTo(pcr3));
|
||||||
|
|
||||||
// Test 3 check the Algorithm String Identifier used in the log
|
// Test 3 check the Algorithm String Identifier used in the log
|
||||||
String algStr = evlog.getEventLogHashAlgorithm();
|
String algStr = evlog.getEventLogHashAlgorithm();
|
||||||
assertThat(algStr, equalTo("TPM_ALG_SHA256"));
|
assertThat("TPM_ALG_SHA256", equalTo(algStr));
|
||||||
|
|
||||||
// Test 4 check the Algorithm # Identifier used in the log
|
// Test 4 check the Algorithm # Identifier used in the log
|
||||||
int id = evlog.getEventLogHashAlgorithmID();
|
int id = evlog.getEventLogHashAlgorithmID();
|
||||||
assertThat(id, equalTo(TcgTpmtHa.TPM_ALG_SHA256));
|
assertThat(TcgTpmtHa.TPM_ALG_SHA256, equalTo(id));
|
||||||
|
|
||||||
LOGGER.debug("OK. Parsing of a Crypto Agile Format Success");
|
LOGGER.debug("OK. Parsing of a Crypto Agile Format Success");
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ public class TCGEventLogTest {
|
|||||||
TCGEventLog evlog = new TCGEventLog(rawLogBytes, false, false, false);
|
TCGEventLog evlog = new TCGEventLog(rawLogBytes, false, false, false);
|
||||||
String[] pcrFromLog = evlog.getExpectedPCRValues();
|
String[] pcrFromLog = evlog.getExpectedPCRValues();
|
||||||
pcrs = this.getClass().getResourceAsStream(SHA1_EXPECTED_PCRS);
|
pcrs = this.getClass().getResourceAsStream(SHA1_EXPECTED_PCRS);
|
||||||
Object[] pcrObj = IOUtils.readLines(pcrs).toArray();
|
Object[] pcrObj = IOUtils.readLines(pcrs, "UTF-8").toArray();
|
||||||
String[] pcrTxt = Arrays.copyOf(pcrObj, pcrObj.length, String[].class);
|
String[] pcrTxt = Arrays.copyOf(pcrObj, pcrObj.length, String[].class);
|
||||||
|
|
||||||
// Test 1 get all PCRs
|
// Test 1 get all PCRs
|
||||||
@ -122,15 +122,15 @@ public class TCGEventLogTest {
|
|||||||
|
|
||||||
// Test 2 get an individual PCR
|
// Test 2 get an individual PCR
|
||||||
String pcr0 = evlog.getExpectedPCRValue(0);
|
String pcr0 = evlog.getExpectedPCRValue(0);
|
||||||
assertThat(pcr0, equalTo(pcrFromLog[0]));
|
assertThat(pcrFromLog[0], equalTo(pcr0));
|
||||||
|
|
||||||
// Test 3 check the Algorithm String Identifier used in the log
|
// Test 3 check the Algorithm String Identifier used in the log
|
||||||
String algStr = evlog.getEventLogHashAlgorithm();
|
String algStr = evlog.getEventLogHashAlgorithm();
|
||||||
assertThat(algStr, equalTo("TPM_ALG_SHA1"));
|
assertThat("TPM_ALG_SHA1", equalTo(algStr));
|
||||||
|
|
||||||
// Test 4 check the Algorithm # Identifier used in the log
|
// Test 4 check the Algorithm # Identifier used in the log
|
||||||
int id = evlog.getEventLogHashAlgorithmID();
|
int id = evlog.getEventLogHashAlgorithmID();
|
||||||
assertThat(id, equalTo(TcgTpmtHa.TPM_ALG_SHA1));
|
assertThat(TcgTpmtHa.TPM_ALG_SHA1, equalTo(id));
|
||||||
|
|
||||||
LOGGER.debug("OK. Parsing of a SHA1 formatted TCG Event Log Success");
|
LOGGER.debug("OK. Parsing of a SHA1 formatted TCG Event Log Success");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user