cleaning up

This commit is contained in:
iadgovuser58 2024-08-07 11:15:22 -04:00
parent 042a830a6e
commit 6124e63201
22 changed files with 108 additions and 138 deletions

View File

@ -318,12 +318,8 @@ public class TpmPcrEvent {
case EvConstants.EV_EFI_EVENT_BASE:
break;
case EvConstants.EV_EFI_VARIABLE_DRIVER_CONFIG:
UefiVariable efiVar = null;
try {
efiVar = new UefiVariable(eventContent);
String efiVarDescription = efiVar.toString().replace("\n", "\n ");
sb.append(efiVarDescription.substring(0,
efiVarDescription.length() - INDENT_3));
sb.append(new UefiVariable(eventContent).toString());
} catch (CertificateException cEx) {
log.error(cEx);
sb.append(cEx.toString());
@ -508,9 +504,7 @@ public class TpmPcrEvent {
break;
case EvConstants.EV_EFI_VARIABLE_DRIVER_CONFIG:
UefiVariable efiVar = new UefiVariable(content);
String efiVarDescription = efiVar.toString().replace("\n", "\n ");
description += "Event Content:\n " + efiVarDescription.substring(0,
efiVarDescription.length() - INDENT_3);
description += "Event Content:\n" + efiVar.toString();
vendorTableFileStatus = efiVar.getVendorTableFileStatus();
break;
case EvConstants.EV_EFI_VARIABLE_BOOT:

View File

@ -2,9 +2,6 @@ package hirs.utils.tpm.eventlog.events;
import lombok.Getter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
/**
* Class to process DEVICE_SECURITY_EVENT_DATA.
* Parses event data per PFP v1.06 Rev52 Table 20.

View File

@ -2,8 +2,6 @@ package hirs.utils.tpm.eventlog.events;
import lombok.Getter;
import java.io.UnsupportedEncodingException;
/**
* Class to process DEVICE_SECURITY_EVENT_DATA2.
* Parses event data per PFP v1.06 Rev52 Table 26.

View File

@ -69,6 +69,5 @@ public abstract class DeviceSecurityEventDataDeviceContext {
return dSEDdeviceContextCommonInfo;
}
}

View File

@ -7,7 +7,7 @@ import hirs.utils.tpm.eventlog.uefi.UefiConstants;
import lombok.Getter;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
/**
* Class to process the DEVICE_SECURITY_EVENT_DATA_HEADER.
@ -89,8 +89,12 @@ public class DeviceSecurityEventDataHeader extends DeviceSecurityEventHeader {
ByteArrayInputStream spdmMeasurementBlockData =
new ByteArrayInputStream(spdmMeasBlockBytes);
spdmMeasurementBlock = new SpdmMeasurementBlock(spdmMeasurementBlockData);
spdmMeasurementBlockInfo = spdmMeasurementBlock.toString();
try {
spdmMeasurementBlock = new SpdmMeasurementBlock(spdmMeasurementBlockData);
spdmMeasurementBlockInfo = spdmMeasurementBlock.toString();
} catch (IOException e) {
spdmMeasurementBlockInfo = " Error reading SPDM Measurement Block";
}
int devPathLenStartByte = 28 + sizeOfSpdmMeasBlock;
extractDevicePathAndFinalSize(dsedBytes, devPathLenStartByte);

View File

@ -3,8 +3,6 @@ package hirs.utils.tpm.eventlog.events;
import hirs.utils.HexUtils;
import lombok.Getter;
import java.io.UnsupportedEncodingException;
/**
* Class to process the DEVICE_SECURITY_EVENT_DATA_HEADER2.
* DEVICE_SECURITY_EVENT_DATA_HEADER2 contains the measurement(s) and hash algorithm identifier
@ -84,6 +82,11 @@ public class DeviceSecurityEventDataHeader2 extends DeviceSecurityEventHeader {
*/
public static final int AUTH_NO_SPDM = 0xFF;
/**
* DeviceSecurityEventDataHeader2 Constructor.
*
* @param dsedBytes byte array holding the DeviceSecurityEventData2.
*/
public DeviceSecurityEventDataHeader2(final byte[] dsedBytes) {
super(dsedBytes);
@ -130,6 +133,11 @@ public class DeviceSecurityEventDataHeader2 extends DeviceSecurityEventHeader {
return dsedHeader2Info;
}
/**
* Returns a human-readable description of auth state based on numeric representation lookup.
*
* @return a description of the auth state.
*/
public String getAuthStateString() {
switch (authState) {

View File

@ -3,7 +3,6 @@ package hirs.utils.tpm.eventlog.events;
import hirs.utils.HexUtils;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
import static hirs.utils.PciIds.translateDevice;
@ -102,7 +101,6 @@ public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDe
byte[] pciSubsystemIdBytes = new byte[2];
System.arraycopy(dSEDpciContextBytes, 14, pciSubsystemIdBytes, 0, 2);
subsystemId = HexUtils.byteArrayToHexString(HexUtils.leReverseByte(pciSubsystemIdBytes));
}
/**

View File

@ -1,6 +1,5 @@
package hirs.utils.tpm.eventlog.events;
/**
* Class to process the DEVICE_SECURITY_EVENT_DATA_SUB_HEADER event per PFP.
*
@ -23,6 +22,10 @@ public abstract class DeviceSecurityEventDataSubHeader {
*/
public static final int SUBHEADERTYPE_CERT_CHAIN = 1;
/**
* DeviceSecurityEventDataSubHeader Default Constructor.
*
*/
public DeviceSecurityEventDataSubHeader() {
}

View File

@ -3,10 +3,6 @@ package hirs.utils.tpm.eventlog.events;
import hirs.utils.HexUtils;
import hirs.utils.tpm.eventlog.spdm.SpdmCertificateChain;
import hirs.utils.tpm.eventlog.spdm.SpdmHa;
import lombok.Getter;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
/**
* Class to process the DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN event per PFP.
@ -85,7 +81,6 @@ public class DeviceSecurityEventDataSubHeaderCertChain extends DeviceSecurityEve
else {
spdmBaseHashAlgoError += "SPDM base hash algorithm size is not >0";
}
}
/**

View File

@ -6,6 +6,7 @@ import hirs.utils.tpm.eventlog.spdm.SpdmMeasurementBlock;
import lombok.Getter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -52,6 +53,10 @@ public class DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock extends Device
* List of SPDM Measurement Blocks.
*/
private List<SpdmMeasurementBlock> spdmMeasurementBlockList;
/**
* Error reading SPDM Measurement Block.
*/
private boolean spdmMeasurementBlockReadError = false;
/**
* DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock Constructor.
@ -87,9 +92,14 @@ public class DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock extends Device
ByteArrayInputStream spdmMeasurementBlockListData =
new ByteArrayInputStream(spdmMeasurementBlockListBytes);
while (spdmMeasurementBlockListData.available() > 0) {
SpdmMeasurementBlock spdmMeasurementBlock;
spdmMeasurementBlock = new SpdmMeasurementBlock(spdmMeasurementBlockListData);
spdmMeasurementBlockList.add(spdmMeasurementBlock);
try {
SpdmMeasurementBlock spdmMeasurementBlock =
new SpdmMeasurementBlock(spdmMeasurementBlockListData);
spdmMeasurementBlockList.add(spdmMeasurementBlock);
} catch (IOException e) {
spdmMeasurementBlockReadError = true;
break;
}
}
}
@ -105,13 +115,18 @@ public class DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock extends Device
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 += spdmMeasBlock.toString();
}
if(spdmMeasurementBlockReadError) {
dsedSubHeaderInfo += " Error reading SPDM Measurement Block #" +
spdmMeasBlockCnt + ", halting processing\n";
}
return dsedSubHeaderInfo;
}

View File

@ -5,7 +5,6 @@ import hirs.utils.tpm.eventlog.uefi.UefiConstants;
import hirs.utils.tpm.eventlog.uefi.UefiDevicePath;
import lombok.Getter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
/**

View File

@ -3,7 +3,6 @@ package hirs.utils.tpm.eventlog.events;
import hirs.utils.HexUtils;
import hirs.utils.tpm.eventlog.uefi.UefiConstants;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
/**

View File

@ -106,6 +106,11 @@ public class EvNoAction {
return specIdInfo;
}
/**
* Returns a human-readable description of locality based on numeric representation lookup.
*
* @return a description of the locality.
*/
private String getLocality(final byte[] eventData) {
String localityInfo = "";
byte[] localityBytes = new byte[1];

View File

@ -39,7 +39,7 @@ public class EvSCrtmVersion {
if (UefiGuid.isValidUUID(data)) {
guid = new UefiGuid(data);
String guidInfo = guid.toStringNoLookup();
description = " SCRM Version = " + guidInfo;
description = " SCRM Version = " + guidInfo;
}
} else if (data.length < UefiConstants.SIZE_4) {
description = HexUtils.byteArrayToHexString(data);

View File

@ -2,7 +2,6 @@ package hirs.utils.tpm.eventlog.events;
import hirs.utils.HexUtils;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
/**

View File

@ -63,6 +63,7 @@ public class SpdmCertificateChain {
* SpdmCertificateChain Constructor.
*
* @param spdmCertChainBytes byte array holding the SPDM Cert Chain bytes.
* @param rootHashLength length of RootHash.
*/
public SpdmCertificateChain(final byte[] spdmCertChainBytes, final int rootHashLength) {
@ -108,7 +109,7 @@ public class SpdmCertificateChain {
certChainDataIS.read(certType);
byte[] certLength = new byte[2];
certChainDataIS.read(certLength);
// int cLength = new BigInteger(certLength).intValue() + UefiConstants.SIZE_4;
//int cLength = new BigInteger(certLength).intValue() + UefiConstants.SIZE_4;
int cLength = new BigInteger(certLength).intValue();
byte[] certData = new byte[cLength];
certChainDataIS.read(certData);

View File

@ -76,13 +76,12 @@ public class SpdmHa {
return alg;
}
/**
* Returns the hash name via a lookup.
* Returns the hash value size based on the hash algorithm.
* Lookup based upon SPDM Spec v1.03 section 10.4.
*
* @param algId int to convert to string
* @return name of the algorithm
* @return size of the algorithm output
*/
public static int tcgAlgIdToByteSize(final int algId) {
int byteSize;

View File

@ -1,7 +1,6 @@
package hirs.utils.tpm.eventlog.spdm;
import hirs.utils.HexUtils;
import lombok.AccessLevel;
import lombok.Getter;
/**
@ -36,7 +35,7 @@ public class SpdmMeasurement {
/**
* Measurement value (digest).
*/
private byte[] dmtfSpecMeasurementValue = null;
private byte[] dmtfSpecMeasurementValue;
/**
* SpdmMeasurement Constructor.

View File

@ -1,16 +1,10 @@
package hirs.utils.tpm.eventlog.spdm;
import hirs.utils.HexUtils;
import hirs.utils.tpm.eventlog.uefi.UefiConstants;
import lombok.Getter;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Class to process the SpdmMeasurementBlock.
@ -46,38 +40,30 @@ public class SpdmMeasurementBlock {
* SPDM Measurement.
*/
private SpdmMeasurement spdmMeasurement;
/**
* Error reading SPDM Measurement Block.
*/
private boolean spdmMeasurementBlockReadError = false;
/**
* SpdmMeasurementBlock Constructor.
*
* @param spdmMeasBlocks byte array holding the SPDM Measurement Block bytes.
*/
public SpdmMeasurementBlock(final ByteArrayInputStream spdmMeasBlocks) {
public SpdmMeasurementBlock(final ByteArrayInputStream spdmMeasBlocks) throws IOException {
try {
byte[] indexBytes = new byte[1];
spdmMeasBlocks.read(indexBytes);
index = HexUtils.leReverseInt(indexBytes);
byte[] indexBytes = new byte[1];
spdmMeasBlocks.read(indexBytes);
index = HexUtils.leReverseInt(indexBytes);
byte[] measurementSpecBytes = new byte[1];
spdmMeasBlocks.read(measurementSpecBytes);
measurementSpec = HexUtils.leReverseInt(measurementSpecBytes);
byte[] measurementSpecBytes = new byte[1];
spdmMeasBlocks.read(measurementSpecBytes);
measurementSpec = HexUtils.leReverseInt(measurementSpecBytes);
// in future, can crosscheck this measurement size with the MeasurementSpec hash alg size
byte[] measurementSizeBytes = new byte[2];
spdmMeasBlocks.read(measurementSizeBytes);
int measurementSize = HexUtils.leReverseInt(measurementSizeBytes);
// in future, can crosscheck this measurement size with the MeasurementSpec hash alg size
byte[] measurementSizeBytes = new byte[2];
spdmMeasBlocks.read(measurementSizeBytes);
int measurementSize = HexUtils.leReverseInt(measurementSizeBytes);
byte[] measurementBytes = new byte[measurementSize];
spdmMeasBlocks.read(measurementBytes);
spdmMeasurement = new SpdmMeasurement(measurementBytes);
} catch (IOException ioEx) {
spdmMeasurementBlockReadError = true;
}
byte[] measurementBytes = new byte[measurementSize];
spdmMeasBlocks.read(measurementBytes);
spdmMeasurement = new SpdmMeasurement(measurementBytes);
}
/**
@ -89,14 +75,9 @@ public class SpdmMeasurementBlock {
String spdmMeasBlockInfo = "";
if(spdmMeasurementBlockReadError) {
spdmMeasBlockInfo += " Error reading SPDM Measurement Block\n";
}
else {
spdmMeasBlockInfo += " Index = " + index + "\n";
spdmMeasBlockInfo += " MeasurementSpec = " + measurementSpec + "\n";
spdmMeasBlockInfo += spdmMeasurement.toString();
}
spdmMeasBlockInfo += " Index = " + index + "\n";
spdmMeasBlockInfo += " MeasurementSpec = " + measurementSpec + "\n";
spdmMeasBlockInfo += spdmMeasurement.toString();
return spdmMeasBlockInfo;
}

View File

@ -38,18 +38,18 @@ public class UefiSecureBoot {
}
/**
* Provides a human readable value for the Secure Boot variable.
* Provides a human-readable value for the Secure Boot variable.
*
* @return Human readable description.
*/
public String toString() {
if (!berror) {
if (secureBootVariable == 1) {
info += " Secure Boot is enabled ";
info += " Secure Boot is enabled ";
} else if (secureBootVariable == 0) {
info += " Secure Boot is NOT enabled ";
info += " Secure Boot is NOT enabled ";
} else {
info += " Unkown State: Secure Variable is undefined ";
info += " Unknown State: Secure Variable is undefined ";
}
}
return info;

View File

@ -112,37 +112,37 @@ public class UefiSignatureList {
@Getter
private String vendorTableFileStatus = FILESTATUS_NOT_ACCESSIBLE;
/**
* UefiSignatureList constructor.
*
* @param list byte array holding the signature list.
* @throws java.security.cert.CertificateException If there a problem parsing the X509 certificate.
* @throws java.security.NoSuchAlgorithmException if there's a problem hashing the certificate.
* @throws java.io.IOException If there's a problem parsing the signature data.
*/
UefiSignatureList(final byte[] list)
throws CertificateException, NoSuchAlgorithmException, IOException {
byte[] guid = new byte[UefiConstants.SIZE_16];
System.arraycopy(list, 0, guid, 0, UefiConstants.SIZE_16);
signatureType = new UefiGuid(guid);
vendorTableFileStatus = signatureType.getVendorTableFileStatus();
byte[] lSize = new byte[UefiConstants.SIZE_4];
System.arraycopy(list, UefiConstants.OFFSET_16, lSize, 0, UefiConstants.SIZE_4);
listSize = HexUtils.leReverseInt(lSize);
byte[] hSize = new byte[UefiConstants.SIZE_4];
System.arraycopy(list, UefiConstants.OFFSET_20, hSize, 0, UefiConstants.SIZE_4);
byte[] sSize = new byte[UefiConstants.SIZE_4];
System.arraycopy(list, UefiConstants.OFFSET_24, sSize, 0, UefiConstants.SIZE_4);
signatureSize = HexUtils.leReverseInt(sSize);
sigData = new byte[signatureSize];
System.arraycopy(list, UefiConstants.OFFSET_28, sigData, 0, signatureSize);
processSignatureList(sigData);
}
// /**
// * UefiSignatureList constructor.
// *
// * @param list byte array holding the signature list.
// * @throws java.security.cert.CertificateException If there a problem parsing the X509 certificate.
// * @throws java.security.NoSuchAlgorithmException if there's a problem hashing the certificate.
// * @throws java.io.IOException If there's a problem parsing the signature data.
// */
// UefiSignatureList(final byte[] list)
// throws CertificateException, NoSuchAlgorithmException, IOException {
//
// byte[] guid = new byte[UefiConstants.SIZE_16];
// System.arraycopy(list, 0, guid, 0, UefiConstants.SIZE_16);
// signatureType = new UefiGuid(guid);
// vendorTableFileStatus = signatureType.getVendorTableFileStatus();
//
// byte[] lSize = new byte[UefiConstants.SIZE_4];
// System.arraycopy(list, UefiConstants.OFFSET_16, lSize, 0, UefiConstants.SIZE_4);
// listSize = HexUtils.leReverseInt(lSize);
//
// byte[] hSize = new byte[UefiConstants.SIZE_4];
// System.arraycopy(list, UefiConstants.OFFSET_20, hSize, 0, UefiConstants.SIZE_4);
//
// byte[] sSize = new byte[UefiConstants.SIZE_4];
// System.arraycopy(list, UefiConstants.OFFSET_24, sSize, 0, UefiConstants.SIZE_4);
// signatureSize = HexUtils.leReverseInt(sSize);
//
// sigData = new byte[signatureSize];
// System.arraycopy(list, UefiConstants.OFFSET_28, sigData, 0, signatureSize);
// processSignatureList(sigData);
// }
/**
* EFI Signature list constructor.
@ -163,7 +163,6 @@ public class UefiSignatureList {
// however, if signatureType is valid, but some of the data later on is invalid, that will
// be caught when UefiSignatureData is processed
if (!isValidSigListGUID(signatureType)) {
//processSignatureData(lists);
signatureTypeValid = false;
} else { // valid SigData Processing
signatureTypeValid = true;
@ -207,28 +206,6 @@ public class UefiSignatureList {
}
}
/**
* Method for processing a set of EFI SignatureList(s).
*
* @param sigDataIS Byte array holding one or more SignatureLists.
* @throws java.security.cert.CertificateException If there's a problem parsing the X509 certificate.
* @throws java.security.NoSuchAlgorithmException if there's a problem hashing the certificate.
* @throws java.io.IOException If there's a problem parsing the signature data.
*/
private void processSignatureData(final ByteArrayInputStream sigDataIS)
throws CertificateException, NoSuchAlgorithmException, IOException {
while (sigDataIS.available() > 0) {
UefiSignatureData tmpigData = new UefiSignatureData(sigDataIS, signatureType);
if (!tmpigData.isValid()) {
dataValid = false;
dataInvalidStatus = tmpigData.getStatus();
break;
}
sigList.add(tmpigData);
numberOfCerts++;
}
}
/**
* Checks to see if GUID is listed on page 1729 of UEFI spec version 2.8.
*

View File

@ -248,7 +248,7 @@ public class UefiVariable {
/**
* Print out all the interesting characteristics available on this UEFI Variable.
*
* @return human readable description of the UEFi variable.
* @return human-readable description of the UEFi variable.
*/
public String toString() {
StringBuilder efiVariable = new StringBuilder();
@ -320,11 +320,11 @@ public class UefiVariable {
}
/**
* Retrieves human readable description from a Certificate.
* Retrieves human-readable description from a Certificate.
*
* @param data byte[] holding the certificate.
* @param offset offset to start of the certificate within the byte array.
* @return human readable description of a certificate.
* @return human-readable description of a certificate.
*/
public String printCert(final byte[] data, final int offset) {
String certInfo = "";