Refactored the Reference Digest code so that the ReferenceDigestValue

table is accessible and upated the contoller for the getOrderedList.
This commit is contained in:
Cyrus 2022-01-21 06:29:53 -05:00
parent 6d8392da45
commit f503457bd4
8 changed files with 312 additions and 62 deletions

View File

@ -978,7 +978,7 @@ public abstract class AbstractAttestationCertificateAuthority
rdr = referenceDigestManager.saveRecord(dbObj);
} // right now this will not deal with updating
if (this.referenceEventManager.getValuesByRecordId(rdr).isEmpty()) {
if (this.referenceEventManager.getValuesByRimId(dbSupport).isEmpty()) {
try {
TCGEventLog logProcessor = new TCGEventLog(dbSupport.getRimBytes());
ReferenceDigestValue rdv;

View File

@ -9,7 +9,6 @@ import hirs.data.persist.Device;
import hirs.data.persist.DeviceInfoReport;
import hirs.data.persist.EventLogMeasurements;
import hirs.data.persist.PCRPolicy;
import hirs.data.persist.ReferenceDigestRecord;
import hirs.data.persist.ReferenceDigestValue;
import hirs.data.persist.ReferenceManifest;
import hirs.data.persist.SupplyChainPolicy;
@ -391,7 +390,6 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe
BaseReferenceManifest baseReferenceManifest = null;
ReferenceManifest supportReferenceManifest = null;
ReferenceManifest measurement = null;
ReferenceDigestRecord digestRecord = null;
baseReferenceManifests = BaseReferenceManifest.select(referenceManifestManager)
.byDeviceName(device.getDeviceInfo().getNetworkInfo().getHostname()).getRIMs();
@ -530,7 +528,6 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe
// vs baseline tcg event log
// find the measurement
TCGEventLog tcgMeasurementLog;
digestRecord = this.referenceDigestManager.getRecord(manufacturer, model);
LinkedList<TpmPcrEvent> tpmPcrEvents = new LinkedList<>();
List<ReferenceDigestValue> eventValue;
HashMap<String, ReferenceDigestValue> eventValueMap = new HashMap<>();
@ -538,7 +535,7 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe
if (measurement.getPlatformManufacturer().equals(manufacturer)) {
tcgMeasurementLog = new TCGEventLog(measurement.getRimBytes());
eventValue = this.referenceEventManager
.getValuesByRecordId(digestRecord);
.getValuesByRimId(supportReferenceManifest);
for (ReferenceDigestValue rdv : eventValue) {
eventValueMap.put(rdv.getDigestValue(), rdv);
}

View File

@ -7,7 +7,6 @@ import hirs.attestationca.portal.page.params.ReferenceManifestDetailsPageParams;
import hirs.attestationca.service.SupplyChainValidationServiceImpl;
import hirs.data.persist.BaseReferenceManifest;
import hirs.data.persist.EventLogMeasurements;
import hirs.data.persist.ReferenceDigestRecord;
import hirs.data.persist.ReferenceDigestValue;
import hirs.data.persist.ReferenceManifest;
import hirs.data.persist.SupportReferenceManifest;
@ -529,7 +528,6 @@ public class ReferenceManifestDetailsPageController
BaseReferenceManifest base = null;
List<SupportReferenceManifest> supports = new ArrayList<>();
SupportReferenceManifest baseSupport = null;
List<ReferenceDigestRecord> digestRecords = new LinkedList<>();
data.put("supportFilename", "Blank");
data.put("supportId", "");
@ -539,9 +537,8 @@ public class ReferenceManifestDetailsPageController
data.put("validationResult", measurements.getOverallValidationResult());
data.put("swidBase", true);
List<ReferenceDigestValue> eventValues = new ArrayList<>();
if (measurements.getDeviceName() != null) {
digestRecords = referenceDigestManager
.getRecordsByDeviceName(measurements.getDeviceName());
supports.addAll(SupportReferenceManifest
.select(referenceManifestManager)
.byDeviceName(measurements
@ -565,24 +562,20 @@ public class ReferenceManifestDetailsPageController
if (base != null) {
data.put("associatedRim", base.getId());
}
eventValues.addAll(referenceEventManager.getValuesByRimId(base));
}
}
TCGEventLog measurementLog = new TCGEventLog(measurements.getRimBytes());
List<ReferenceDigestValue> eventValue = new ArrayList<>();
Map<String, ReferenceDigestValue> eventValueMap = new HashMap<>();
if (!digestRecords.isEmpty()) {
for (ReferenceDigestRecord rdr : digestRecords) {
eventValue.addAll(referenceEventManager
.getValuesByRecordId(rdr));
}
for (ReferenceDigestValue rdv : eventValue) {
eventValueMap.put(rdv.getDigestValue(), rdv);
}
for (TpmPcrEvent measurementEvent : measurementLog.getEventList()) {
if (!eventValueMap.containsKey(measurementEvent.getEventDigestStr())) {
livelogEvents.add(measurementEvent);
}
for (ReferenceDigestValue rdv : eventValues) {
eventValueMap.put(rdv.getDigestValue(), rdv);
}
for (TpmPcrEvent measurementEvent : measurementLog.getEventList()) {
if (!eventValueMap.containsKey(measurementEvent.getEventDigestStr())) {
livelogEvents.add(measurementEvent);
}
}

View File

@ -135,7 +135,7 @@ public class TpmEventsPageController
@RequestMapping(value = "/list",
produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET)
public DataTableResponse<ReferenceDigestRecord> getTableData(
public DataTableResponse<ReferenceDigestValue> getTableData(
final DataTableInput input) {
LOGGER.info("Handling request for summary list: " + input);
@ -151,17 +151,14 @@ public class TpmEventsPageController
};
LOGGER.info("Querying with the following datatableinput: " + input.toString());
FilteredRecordsList<ReferenceDigestRecord> referenceDigestRecords
= OrderedListQueryDataTableAdapter.getOrderedList(
ReferenceDigestRecord.class,
referenceDigestManager,
FilteredRecordsList<ReferenceDigestValue> referenceDigestValues =
OrderedListQueryDataTableAdapter.getOrderedList(
ReferenceDigestValue.class,
referenceEventManager,
input, orderColumnName, criteriaModifier);
// FilteredRecordsList<HashMap<ReferenceDigestRecord, ReferenceDigestValue>>
// mappedRecordValues = mapRecordToValues(referenceDigestRecords);
// LOGGER.info("Returning list mapping: " + Arrays.toString(mappedRecordValues.toArray()));
return new DataTableResponse<>(referenceDigestRecords, input);
return new DataTableResponse<>(referenceDigestValues, input);
}
/**

View File

@ -17,12 +17,14 @@
<jsp:body>
<br/>
<div class="aca-data-table">
<table id="tpmEventTable" class="display" width="100%">
<table id="digestValueTable" class="display" width="100%">
<thead>
<tr>
<th>Manufacturer</th>
<th>Model</th>
<th>Support RIM</th>
<th>Event Type</th>
<th>PCR Index</th>
<th>Digest Value</th>
</tr>
</thead>
</table>
@ -32,13 +34,25 @@
$(document).ready(function() {
var url = pagePath +'/list';
var columns = [
{data: 'manufacturer'},
{data: 'model'},
{data: 'supportRim'}
{data: 'manufacturer',
orderable: true,
searchable:false},
{data: 'model',
orderable: false,
searchable:false},
{data: 'eventType',
orderable: false,
searchable:false,},
{data: 'pcrIndex',
orderable: true,
searchable:false},
{data: 'digestValue',
orderable: false,
searchable:false}
];
//Set data tables
setDataTables("#tpmEventTable", url, columns);
setDataTables("#digestValueTable", url, columns);
});
</script>
</jsp:body>

View File

@ -1,11 +1,16 @@
package hirs.data.persist;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.util.Arrays;
import org.hibernate.annotations.Type;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Objects;
import java.util.UUID;
@ -14,17 +19,21 @@ import java.util.UUID;
* Digest Value, Event Type, index, RIM Tagid
*/
@Entity
public class ReferenceDigestValue extends AbstractEntity {
@Table(name = "ReferenceDigestValue")
@XmlRootElement(name = "ReferenceDigestValue")
@XmlAccessorType(XmlAccessType.FIELD)
@Access(AccessType.FIELD)
public class ReferenceDigestValue extends ArchivableEntity {
private static final Logger LOGGER = LogManager.getLogger(ReferenceDigestValue.class);
@Type(type = "uuid-char")
@Column
private UUID baseRimId;
@Type(type = "uuid-char")
@Column
private UUID supportRimId;
@Column
@Column(nullable = false)
private String manufacturer;
@Column
@Column(nullable = false)
private String model;
@Column(nullable = false)
private int pcrIndex;
@ -40,12 +49,12 @@ public class ReferenceDigestValue extends AbstractEntity {
private boolean patched = false;
/**
* Default Constructor.
* Default constructor necessary for Hibernate.
*/
public ReferenceDigestValue() {
protected ReferenceDigestValue() {
super();
this.baseRimId = UUID.randomUUID();
this.supportRimId = UUID.randomUUID();
this.baseRimId = null;
this.supportRimId = null;
this.manufacturer = "";
this.model = "";
this.pcrIndex = -1;
@ -83,7 +92,7 @@ public class ReferenceDigestValue extends AbstractEntity {
this.eventType = eventType;
this.matchFail = matchFail;
this.patched = patched;
this.contentBlob = contentBlob;
this.contentBlob = Arrays.clone(contentBlob);
}
/**
@ -118,6 +127,38 @@ public class ReferenceDigestValue extends AbstractEntity {
this.supportRimId = supportRimId;
}
/**
* Getter for the manufacturer value.
* @return the stored value
*/
public String getManufacturer() {
return manufacturer;
}
/**
* Setter for the manufacturer value.
* @param manufacturer the value to store
*/
public void setManufacturer(final String manufacturer) {
this.manufacturer = manufacturer;
}
/**
* Getter for the model value.
* @return the stored value
*/
public String getModel() {
return model;
}
/**
* Setter for the model value.
* @param model the value to store
*/
public void setModel(final String model) {
this.model = model;
}
/**
* Getter for the event number.
* @return the stored value
@ -198,6 +239,24 @@ public class ReferenceDigestValue extends AbstractEntity {
this.patched = patched;
}
/**
* Getter for the byte array of event values.
* @return a clone of the byte array
*/
public byte[] getContentBlob() {
return contentBlob.clone();
}
/**
* Setter for the byte array of values.
* @param contentBlob non-null array.
*/
public void setContentBlob(final byte[] contentBlob) {
if (contentBlob != null) {
this.contentBlob = contentBlob.clone();
}
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {

View File

@ -1,16 +1,23 @@
package hirs.persist;
import hirs.FilteredRecordsList;
import hirs.data.persist.BaseReferenceManifest;
import hirs.data.persist.ReferenceDigestRecord;
import hirs.data.persist.ReferenceDigestValue;
import hirs.data.persist.ReferenceManifest;
import hirs.data.persist.SupportReferenceManifest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
@ -30,6 +37,7 @@ public class DBReferenceEventManager extends DBManager<ReferenceDigestValue>
public DBReferenceEventManager(final SessionFactory sessionFactory) {
super(ReferenceDigestValue.class, sessionFactory);
}
@Override
public ReferenceDigestValue saveValue(final ReferenceDigestValue referenceDigestValue) {
LOGGER.debug("saving event digest value: {}", referenceDigestValue);
@ -118,24 +126,107 @@ public class DBReferenceEventManager extends DBManager<ReferenceDigestValue>
}
@Override
public List<ReferenceDigestValue> getValuesByRecordId(
final ReferenceDigestRecord referenceDigestRecord) {
LOGGER.debug("Getting digest values for {}", referenceDigestRecord);
if (referenceDigestRecord == null) {
LOGGER.error("null referenceDigestRecord argument");
throw new NullPointerException("null referenceDigestRecord");
}
if (referenceDigestRecord.getId() == null) {
LOGGER.error("null referenceDigestRecord ID argument");
throw new NullPointerException("null referenceDigestRecord ID");
public List<ReferenceDigestValue> getValueByManufacturer(final String manufacturer) {
if (manufacturer == null) {
LOGGER.error("null manufacturer argument");
throw new NullPointerException("null manufacturer parameter");
}
List<ReferenceDigestValue> dbDigestValues = new ArrayList<>();
UUID uuid = referenceDigestRecord.getId();
try {
List<ReferenceDigestValue> dbTempList = super.getList(ReferenceDigestValue.class);
for (ReferenceDigestValue rdv : dbTempList) {
if (rdv.getSupportRimId().equals(uuid)) {
if (rdv.getManufacturer().equals(manufacturer)) {
dbDigestValues.add(rdv);
}
}
} catch (DBManagerException dbMEx) {
throw new RuntimeException(dbMEx);
}
return dbDigestValues;
}
@Override
public List<ReferenceDigestValue> getValueByModel(final String model) {
if (model == null) {
LOGGER.error("null model argument");
throw new NullPointerException("null model parameter");
}
List<ReferenceDigestValue> dbDigestValues = new ArrayList<>();
try {
List<ReferenceDigestValue> dbTempList = super.getList(ReferenceDigestValue.class);
for (ReferenceDigestValue rdv : dbTempList) {
if (rdv.getModel().equals(model)) {
dbDigestValues.add(rdv);
}
}
} catch (DBManagerException dbMEx) {
throw new RuntimeException(dbMEx);
}
return dbDigestValues;
}
@Override
public List<ReferenceDigestValue> getValueByManufacturerModel(
final String manufacturer, final String model) {
if (model == null) {
LOGGER.error("null model argument");
throw new NullPointerException("null model parameter");
}
if (manufacturer == null) {
LOGGER.error("null manufacturer argument");
throw new NullPointerException("null manufacturer parameter");
}
List<ReferenceDigestValue> dbDigestValues = new ArrayList<>();
try {
List<ReferenceDigestValue> dbTempList = super.getList(ReferenceDigestValue.class);
for (ReferenceDigestValue rdv : dbTempList) {
if (rdv.getManufacturer().equals(manufacturer)
&& rdv.getModel().equals(model)) {
dbDigestValues.add(rdv);
}
}
} catch (DBManagerException dbMEx) {
throw new RuntimeException(dbMEx);
}
return dbDigestValues;
}
@Override
public List<ReferenceDigestValue> getValuesByRecordId(
final ReferenceDigestRecord referenceDigestRecord) {
List<ReferenceDigestValue> dbDigestValues = new ArrayList<>(0);
return dbDigestValues;
}
@Override
public List<ReferenceDigestValue> getValuesByRimId(
final ReferenceManifest referenceManifest) {
LOGGER.debug("Getting digest values for {}", referenceManifest);
if (referenceManifest == null) {
LOGGER.error("null referenceManifest argument");
throw new NullPointerException("null referenceManifest");
}
if (referenceManifest.getId() == null) {
LOGGER.error("null referenceManifest ID argument");
throw new NullPointerException("null referenceManifest ID");
}
List<ReferenceDigestValue> dbDigestValues = new ArrayList<>();
UUID uuid = referenceManifest.getId();
UUID rdvUuid = UUID.randomUUID();
try {
List<ReferenceDigestValue> dbTempList = super.getList(ReferenceDigestValue.class);
for (ReferenceDigestValue rdv : dbTempList) {
if (referenceManifest instanceof BaseReferenceManifest) {
rdvUuid = rdv.getBaseRimId();
} else if (referenceManifest instanceof SupportReferenceManifest) {
rdvUuid = rdv.getSupportRimId();
}
if (rdvUuid.equals(uuid)) {
dbDigestValues.add(rdv);
}
}
@ -167,6 +258,53 @@ public class DBReferenceEventManager extends DBManager<ReferenceDigestValue>
return dbDigestValues;
}
/**
* Returns a list of all <code>Device</code>s that are ordered by a column
* and direction (ASC, DESC) that is provided by the user. This method
* helps support the server-side processing in the JQuery DataTables.
*
* @param columnToOrder Column to be ordered
* @param ascending direction of sort
* @param firstResult starting point of first result in set
* @param maxResults total number we want returned for display in table
* @param search string of criteria to be matched to visible columns
*
* @return FilteredRecordsList object with fields for DataTables
*/
@Override
public final FilteredRecordsList<ReferenceDigestValue> getOrderedDigestValueList(
final String columnToOrder,
final boolean ascending, final int firstResult,
final int maxResults, final String search) {
if (columnToOrder == null) {
LOGGER.debug("null object argument");
throw new NullPointerException("object");
}
//Maps object types and their ability to be searched by Hibernate
//without modification
Map<String, Boolean> searchableColumns = new HashMap<>();
searchableColumns.put("name", true);
searchableColumns.put("group.name", true);
searchableColumns.put("last_report_timestamp", false);
CriteriaModifier modifier = new CriteriaModifier() {
@Override
public void modify(final Criteria criteria) {
criteria.createAlias("valueGroup", "group");
}
};
try {
LOGGER.debug("Getting baseline list");
return super.getOrderedList(ReferenceDigestValue.class, columnToOrder, ascending,
firstResult,
maxResults, search, searchableColumns, modifier);
} catch (DBManagerException e) {
throw new AlertManagerException(e);
}
}
@Override
public void updateRecord(final ReferenceDigestValue referenceDigestValue) {
try {

View File

@ -1,7 +1,9 @@
package hirs.persist;
import hirs.FilteredRecordsList;
import hirs.data.persist.ReferenceDigestRecord;
import hirs.data.persist.ReferenceDigestValue;
import hirs.data.persist.ReferenceManifest;
import java.util.List;
@ -9,7 +11,7 @@ import java.util.List;
* This class facilitates the persistence of {@link hirs.data.persist.ReferenceDigestValue}s
* including storage, retrieval, and deletion.
*/
public interface ReferenceEventManager {
public interface ReferenceEventManager extends OrderedListQuerier<ReferenceDigestValue> {
/**
* Persists a new Reference Digest value.
*
@ -34,6 +36,31 @@ public interface ReferenceEventManager {
*/
ReferenceDigestValue getValueById(ReferenceDigestValue referenceDigestValue);
/**
* Persists a new Reference Digest Value.
*
* @param manufacturer the string value to search for
* @return the persisted ReferenceDigestValue
*/
List<ReferenceDigestValue> getValueByManufacturer(String manufacturer);
/**
* Persists a new Reference Digest.
*
* @param model the string value to search for
* @return the persisted ReferenceDigestValue
*/
List<ReferenceDigestValue> getValueByModel(String model);
/**
* Persists a new Reference Digest.
*
* @param manufacturer the string value to search for
* @param model the string value to search for
* @return the persisted ReferenceDigestValue
*/
List<ReferenceDigestValue> getValueByManufacturerModel(String manufacturer, String model);
/**
* Persists a new Reference Digest value.
*
@ -42,6 +69,14 @@ public interface ReferenceEventManager {
*/
List<ReferenceDigestValue> getValuesByRecordId(ReferenceDigestRecord referenceDigestRecord);
/**
* Persists a new Reference Digest value.
*
* @param referenceManifest the referenceManifest
* @return the persisted list of ReferenceDigestValue
*/
List<ReferenceDigestValue> getValuesByRimId(ReferenceManifest referenceManifest);
/**
* Persists a new Reference Digest value.
*
@ -50,6 +85,23 @@ public interface ReferenceEventManager {
*/
List<ReferenceDigestValue> getValueByEventType(String eventType);
/**
* Returns a list of all <code>ReferenceDigestValue</code>s that are ordered by a column
* and direction (ASC, DESC) that is provided by the user. This method
* helps support the server-side processing in the JQuery DataTables.
*
* @param columnToOrder Column to be ordered
* @param ascending direction of sort
* @param firstResult starting point of first result in set
* @param maxResults total number we want returned for display in table
* @param search string of criteria to be matched to visible columns
*
* @return FilteredRecordsList object with fields for DataTables
*/
FilteredRecordsList<ReferenceDigestValue> getOrderedDigestValueList(
String columnToOrder, boolean ascending, int firstResult,
int maxResults, String search);
/**
* Updates an existing ReferenceDigestRecord.
* @param referenceDigestValue the Reference Event update