mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-02-20 17:52:47 +00:00
Did some testing on manual/curl uploading. This produced an error
because device name was being used to pull objects in the validation quote part of the provision. This was changed. The event log is deleted each time so that only one event log per device is maintained.
This commit is contained in:
parent
d4c35e09ab
commit
2e26823fc1
@ -940,31 +940,38 @@ public abstract class AbstractAttestationCertificateAuthority
|
||||
dv.getLivelog().toByteArray());
|
||||
// find previous version.
|
||||
measurements = EventLogMeasurements.select(referenceManifestManager)
|
||||
.byHexDecHash(temp.getHexDecHash()).includeArchived().getRIM();
|
||||
if (measurements == null) {
|
||||
measurements = temp;
|
||||
measurements.setPlatformManufacturer(dv.getHw().getManufacturer());
|
||||
measurements.setPlatformModel(dv.getHw().getProductName());
|
||||
measurements.setTagId(tagId);
|
||||
measurements.setDeviceName(dv.getNw().getHostname());
|
||||
this.referenceManifestManager.save(measurements);
|
||||
}
|
||||
// now save the hash to the base and support rims associated
|
||||
for (ReferenceManifest rim : listOfSavedRims) {
|
||||
if (rim != null) {
|
||||
rim.setEventLogHash(temp.getHexDecHash());
|
||||
this.referenceManifestManager.update(rim);
|
||||
}
|
||||
.byDeviceName(dv.getNw().getHostname())
|
||||
.includeArchived()
|
||||
.getRIM();
|
||||
|
||||
if (measurements != null) {
|
||||
// Find previous log and delete it
|
||||
referenceManifestManager.deleteReferenceManifest(measurements);
|
||||
}
|
||||
|
||||
for (BaseReferenceManifest baseRim : BaseReferenceManifest
|
||||
.select(referenceManifestManager).getRIMs()) {
|
||||
if (baseRim.getPlatformManufacturer().equals(dv.getHw().getManufacturer())
|
||||
&& baseRim.getPlatformModel().equals(dv.getHw().getProductName())) {
|
||||
baseRim.setEventLogHash(temp.getHexDecHash());
|
||||
this.referenceManifestManager.update(baseRim);
|
||||
}
|
||||
}
|
||||
BaseReferenceManifest baseRim = BaseReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.byManufacturerModelBase(dv.getHw().getManufacturer(),
|
||||
dv.getHw().getProductName())
|
||||
.getRIM();
|
||||
measurements = temp;
|
||||
measurements.setPlatformManufacturer(dv.getHw().getManufacturer());
|
||||
measurements.setPlatformModel(dv.getHw().getProductName());
|
||||
measurements.setTagId(tagId);
|
||||
measurements.setDeviceName(dv.getNw().getHostname());
|
||||
measurements.setAssociatedRim(baseRim.getAssociatedRim());
|
||||
this.referenceManifestManager.save(measurements);
|
||||
|
||||
// pull the base versions of the swidtag and rimel and set the
|
||||
// event log hash for use during provision
|
||||
SupportReferenceManifest sBaseRim = SupportReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.byEntityId(baseRim.getAssociatedRim())
|
||||
.getRIM();
|
||||
baseRim.setEventLogHash(temp.getHexDecHash());
|
||||
sBaseRim.setEventLogHash(temp.getHexDecHash());
|
||||
referenceManifestManager.update(baseRim);
|
||||
referenceManifestManager.update(sBaseRim);
|
||||
} catch (IOException ioEx) {
|
||||
LOG.error(ioEx);
|
||||
}
|
||||
@ -1030,7 +1037,7 @@ public abstract class AbstractAttestationCertificateAuthority
|
||||
rdv = new ReferenceDigestValue(baseSupportRim.getAssociatedRim(),
|
||||
baseSupportRim.getId(), manufacturer, model, tpe.getPcrIndex(),
|
||||
tpe.getEventDigestStr(), tpe.getEventTypeStr(),
|
||||
false, false, tpe.getEventContent());
|
||||
false, false, true, tpe.getEventContent());
|
||||
rdValues.add(rdv);
|
||||
}
|
||||
|
||||
@ -1044,7 +1051,7 @@ public abstract class AbstractAttestationCertificateAuthority
|
||||
rdv = new ReferenceDigestValue(baseSupportRim.getAssociatedRim(),
|
||||
supplemental.getId(), manufacturer, model, tpe.getPcrIndex(),
|
||||
tpe.getEventDigestStr(), tpe.getEventTypeStr(),
|
||||
false, false, tpe.getEventContent());
|
||||
false, false, true, tpe.getEventContent());
|
||||
rdValues.add(rdv);
|
||||
}
|
||||
}
|
||||
|
@ -621,7 +621,10 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe
|
||||
try {
|
||||
Set<SupportReferenceManifest> supportRims = SupportReferenceManifest
|
||||
.select(this.referenceManifestManager)
|
||||
.byDeviceName(deviceName).getRIMs();
|
||||
.byManufacturerModel(
|
||||
device.getDeviceInfo().getHardwareInfo().getManufacturer(),
|
||||
device.getDeviceInfo().getHardwareInfo().getProductName())
|
||||
.getRIMs();
|
||||
for (SupportReferenceManifest support : supportRims) {
|
||||
if (support.isBaseSupport()) {
|
||||
sRim = support;
|
||||
|
@ -50,6 +50,7 @@ import java.security.cert.CertificateException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -228,8 +229,8 @@ public class ReferenceManifestPageController
|
||||
Pattern logPattern = Pattern.compile(LOG_FILE_PATTERN);
|
||||
Matcher matcher;
|
||||
boolean supportRIM = false;
|
||||
BaseReferenceManifest base;
|
||||
SupportReferenceManifest support;
|
||||
List<BaseReferenceManifest> baseRims = new ArrayList<>();
|
||||
List<SupportReferenceManifest> supportRims = new ArrayList<>();
|
||||
|
||||
// loop through the files
|
||||
for (MultipartFile file : files) {
|
||||
@ -238,64 +239,62 @@ public class ReferenceManifestPageController
|
||||
supportRIM = matcher.matches();
|
||||
|
||||
//Parse reference manifests
|
||||
ReferenceManifest rim = parseRIM(file, supportRIM, messages);
|
||||
parseRIM(file, supportRIM, messages, baseRims, supportRims);
|
||||
}
|
||||
baseRims.stream().forEach((rim) -> {
|
||||
LOGGER.info(String.format("Storing swidtag %s", rim.getFileName()));
|
||||
storeManifest(messages, rim, false);
|
||||
});
|
||||
supportRims.stream().forEach((rim) -> {
|
||||
LOGGER.info(String.format("Storing event log %s", rim.getFileName()));
|
||||
storeManifest(messages, rim, false);
|
||||
});
|
||||
for (ReferenceManifest rim : baseRims) {
|
||||
// store first then update
|
||||
ReferenceManifest referenceManifest = storeManifest(file.getOriginalFilename(),
|
||||
messages,
|
||||
rim,
|
||||
supportRIM);
|
||||
//Store only if it was parsed
|
||||
if (rim != null) {
|
||||
if (supportRIM) {
|
||||
// look for associated base/support
|
||||
// if I am the support rim, my hash is in the meta data of the swidtag
|
||||
Set<BaseReferenceManifest> rims = BaseReferenceManifest
|
||||
.select(referenceManifestManager).getRIMs();
|
||||
support = (SupportReferenceManifest) rim;
|
||||
// update information for associated support rim
|
||||
for (BaseReferenceManifest bRim : rims) {
|
||||
for (SwidResource swid : bRim.parseResource()) {
|
||||
if (support.getHexDecHash().equals(swid.getHashValue())) {
|
||||
updateSupportRimInfo(bRim, support);
|
||||
referenceManifestManager.update(support);
|
||||
}
|
||||
}
|
||||
if (support.isUpdated()) {
|
||||
for (ReferenceDigestValue rdv : referenceEventManager
|
||||
.getValuesByRimId(support)) {
|
||||
rdv.updateInfo(support);
|
||||
referenceEventManager.updateEvent(rdv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
base = (BaseReferenceManifest) referenceManifest;
|
||||
// the base can find the support rim by the meta data hash
|
||||
for (SwidResource swid : base.parseResource()) {
|
||||
support = SupportReferenceManifest.select(referenceManifestManager)
|
||||
.byHexDecHash(swid.getHashValue()).getRIM();
|
||||
if (support != null) {
|
||||
base.setAssociatedRim(support.getId());
|
||||
if (support.isUpdated()) {
|
||||
// this is separate because I want to break if we found it
|
||||
// instead of finding it, it is uptodate but still search
|
||||
break;
|
||||
} else {
|
||||
updateSupportRimInfo(base, support);
|
||||
updateTpmEvents(support);
|
||||
try {
|
||||
referenceManifestManager.update(support);
|
||||
} catch (DBManagerException dbmEx) {
|
||||
LOGGER.warn("Failed to update Support RIM");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
storeManifest(messages, rim, false);
|
||||
|
||||
|
||||
/**
|
||||
* Ok so another redo. phased like the provision section
|
||||
* filter through, find base vs support
|
||||
* Maybe process base first, create a map of the support digest
|
||||
* to the base
|
||||
* go through support and pull the associated base
|
||||
* save those. Save the digests
|
||||
* re pull digests support from the DB and then do the events
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
for (ReferenceManifest rim : supportRims) {
|
||||
// store the rimels
|
||||
storeManifest(messages, rim, true);
|
||||
}
|
||||
|
||||
// Prep a map to associated the swidtag payload hash to the swidtag.
|
||||
// pass it in to update support rims that either were uploaded
|
||||
// or already exist
|
||||
// create a map of the supports rims in case an uploaded swidtag
|
||||
// isn't one to one with the uploaded support rims.
|
||||
Map<String, SupportReferenceManifest> updatedSupportRims
|
||||
= updateSupportRimInfo(generatePayloadHashMap(baseRims));
|
||||
|
||||
// look for missing uploaded support rims
|
||||
for (SupportReferenceManifest support : supportRims) {
|
||||
if (!updatedSupportRims.containsKey(support.getHexDecHash())) {
|
||||
// Make sure we are getting the db version of the file
|
||||
updatedSupportRims.put(support.getHexDecHash(),
|
||||
SupportReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.byHexDecHash(support.getHexDecHash())
|
||||
.getRIM());
|
||||
}
|
||||
}
|
||||
|
||||
// pass in the updated support rims
|
||||
// and either update or add the events
|
||||
processTpmEvents(new ArrayList<SupportReferenceManifest>(updatedSupportRims.values()));
|
||||
|
||||
//Add messages to the model
|
||||
model.put(MESSAGES_ATTRIBUTE, messages);
|
||||
|
||||
@ -479,15 +478,19 @@ public class ReferenceManifestPageController
|
||||
* object.
|
||||
*
|
||||
* @param file the provide user file via browser.
|
||||
* @param supportRIM matcher result
|
||||
* @param messages the object that handles displaying information to the
|
||||
* user.
|
||||
* @param baseRims object to store multiple files
|
||||
* @param supportRims object to store multiple files
|
||||
* @return a single or collection of reference manifest files.
|
||||
*/
|
||||
private ReferenceManifest parseRIM(
|
||||
private void parseRIM(
|
||||
final MultipartFile file, final boolean supportRIM,
|
||||
final PageMessages messages) {
|
||||
final PageMessages messages, final List<BaseReferenceManifest> baseRims,
|
||||
final List<SupportReferenceManifest> supportRims) {
|
||||
|
||||
byte[] fileBytes;
|
||||
byte[] fileBytes = new byte[0];
|
||||
String fileName = file.getOriginalFilename();
|
||||
|
||||
// build the manifest from the uploaded bytes
|
||||
@ -498,43 +501,39 @@ public class ReferenceManifestPageController
|
||||
= String.format("Failed to read uploaded file (%s): ", fileName);
|
||||
LOGGER.error(failMessage, e);
|
||||
messages.addError(failMessage + e.getMessage());
|
||||
return null;
|
||||
// return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (supportRIM) {
|
||||
return new SupportReferenceManifest(fileName, fileBytes);
|
||||
supportRims.add(new SupportReferenceManifest(fileName, fileBytes));
|
||||
} else {
|
||||
return new BaseReferenceManifest(fileName, fileBytes);
|
||||
baseRims.add(new BaseReferenceManifest(fileName, fileBytes));
|
||||
}
|
||||
// the this is a List<Object> is object is a JaxBElement that can
|
||||
// be matched up to the QName
|
||||
} catch (IOException ioEx) {
|
||||
final String failMessage
|
||||
= String.format("Failed to parse uploaded file (%s): ", fileName);
|
||||
LOGGER.error(failMessage, ioEx);
|
||||
messages.addError(failMessage + ioEx.getMessage());
|
||||
return null;
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the {@link ReferenceManifest} objects.
|
||||
*
|
||||
* @param fileName name of the file given
|
||||
* @param messages message object for user display of statuses
|
||||
* @param referenceManifest the object to store
|
||||
* @param supportRim boolean flag indicating if this is a support RIM
|
||||
* process.
|
||||
*/
|
||||
private ReferenceManifest storeManifest(
|
||||
final String fileName,
|
||||
private void storeManifest(
|
||||
final PageMessages messages,
|
||||
final ReferenceManifest referenceManifest,
|
||||
final boolean supportRim) {
|
||||
|
||||
ReferenceManifest existingManifest;
|
||||
|
||||
ReferenceManifest existingManifest = null;
|
||||
String fileName = referenceManifest.getFileName();
|
||||
MessageDigest digest = null;
|
||||
String rimHash = "";
|
||||
try {
|
||||
@ -570,32 +569,31 @@ public class ReferenceManifestPageController
|
||||
+ "failed (%s): ", fileName);
|
||||
messages.addError(failMessage + e.getMessage());
|
||||
LOGGER.error(failMessage, e);
|
||||
return null;
|
||||
// return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// save the new certificate if no match is found
|
||||
if (existingManifest == null) {
|
||||
saveTpmEvents(referenceManifestManager.save(referenceManifest));
|
||||
referenceManifestManager.save(referenceManifest);
|
||||
|
||||
final String successMsg = String.format("RIM successfully uploaded (%s): ",
|
||||
fileName);
|
||||
messages.addSuccess(successMsg);
|
||||
LOGGER.info(successMsg);
|
||||
|
||||
return referenceManifest;
|
||||
}
|
||||
} catch (DBManagerException dbmEx) {
|
||||
final String failMessage = String.format("Storing RIM failed (%s): ", fileName);
|
||||
final String failMessage = String.format("Storing RIM failed (%s): ",
|
||||
fileName);
|
||||
messages.addError(failMessage + dbmEx.getMessage());
|
||||
LOGGER.error(failMessage, dbmEx);
|
||||
return null;
|
||||
// return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// if an identical RIM is archived, update the existing RIM to
|
||||
// unarchive it and change the creation date
|
||||
if (existingManifest.isArchived()) {
|
||||
if (existingManifest != null && existingManifest.isArchived()) {
|
||||
existingManifest.restore();
|
||||
existingManifest.resetCreateTime();
|
||||
referenceManifestManager.update(existingManifest);
|
||||
@ -604,7 +602,6 @@ public class ReferenceManifestPageController
|
||||
= String.format("Pre-existing RIM found and unarchived (%s): ", fileName);
|
||||
messages.addSuccess(successMsg);
|
||||
LOGGER.info(successMsg);
|
||||
return existingManifest;
|
||||
}
|
||||
} catch (DBManagerException dbmEx) {
|
||||
final String failMessage = String.format("Found an identical pre-existing RIM in the "
|
||||
@ -612,90 +609,121 @@ public class ReferenceManifestPageController
|
||||
messages.addError(failMessage + dbmEx.getMessage());
|
||||
LOGGER.error(failMessage, dbmEx);
|
||||
|
||||
return null;
|
||||
// return null;
|
||||
}
|
||||
|
||||
return referenceManifest;
|
||||
// return referenceManifest;
|
||||
}
|
||||
|
||||
private void updateSupportRimInfo(final BaseReferenceManifest dbBaseRim,
|
||||
final SupportReferenceManifest supportRim) {
|
||||
// I have to assume the baseRim is from the database
|
||||
// Updating the id values, manufacturer, model
|
||||
if (supportRim != null) {
|
||||
supportRim.setSwidTagVersion(dbBaseRim.getSwidTagVersion());
|
||||
supportRim.setPlatformManufacturer(dbBaseRim.getPlatformManufacturer());
|
||||
supportRim.setPlatformModel(dbBaseRim.getPlatformModel());
|
||||
supportRim.setTagId(dbBaseRim.getTagId());
|
||||
supportRim.setAssociatedRim(dbBaseRim.getId());
|
||||
supportRim.setUpdated(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTpmEvents(final ReferenceManifest referenceManifest) {
|
||||
String manufacturer;
|
||||
String model;
|
||||
if (referenceManifest.getPlatformManufacturer() == null) {
|
||||
manufacturer = "";
|
||||
} else {
|
||||
manufacturer = referenceManifest.getPlatformManufacturer();
|
||||
}
|
||||
|
||||
if (referenceManifest.getPlatformModel() == null) {
|
||||
model = "";
|
||||
} else {
|
||||
model = referenceManifest.getPlatformModel();
|
||||
}
|
||||
|
||||
List<ReferenceDigestValue> rdvs = referenceEventManager
|
||||
.getValuesByRimId(referenceManifest);
|
||||
|
||||
for (ReferenceDigestValue rdv : rdvs) {
|
||||
rdv.setModel(model);
|
||||
rdv.setManufacturer(manufacturer);
|
||||
rdv.setBaseRimId(referenceManifest.getAssociatedRim());
|
||||
referenceEventManager.updateEvent(rdv);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveTpmEvents(final ReferenceManifest referenceManifest) {
|
||||
SupportReferenceManifest dbSupport;
|
||||
String manufacturer;
|
||||
String model;
|
||||
if (referenceManifest instanceof SupportReferenceManifest) {
|
||||
dbSupport = (SupportReferenceManifest) referenceManifest;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
TCGEventLog logProcessor = null;
|
||||
if (dbSupport.getPlatformManufacturer() == null) {
|
||||
manufacturer = "";
|
||||
} else {
|
||||
manufacturer = dbSupport.getPlatformManufacturer();
|
||||
}
|
||||
|
||||
if (dbSupport.getPlatformModel() == null) {
|
||||
model = "";
|
||||
} else {
|
||||
model = dbSupport.getPlatformModel();
|
||||
}
|
||||
try {
|
||||
logProcessor = new TCGEventLog(dbSupport.getRimBytes());
|
||||
ReferenceDigestValue rdv;
|
||||
for (TpmPcrEvent tpe : logProcessor.getEventList()) {
|
||||
rdv = new ReferenceDigestValue(dbSupport.getAssociatedRim(),
|
||||
dbSupport.getId(), manufacturer,
|
||||
model, tpe.getPcrIndex(),
|
||||
tpe.getEventDigestStr(), tpe.getEventTypeStr(),
|
||||
false, false, tpe.getEventContent());
|
||||
this.referenceEventManager.saveValue(rdv);
|
||||
private Map<String, BaseReferenceManifest> generatePayloadHashMap(
|
||||
final List<BaseReferenceManifest> uploadedBaseRims) {
|
||||
BaseReferenceManifest dbBaseRim;
|
||||
HashMap<String, BaseReferenceManifest> tempMap = new HashMap<>();
|
||||
for (BaseReferenceManifest base : uploadedBaseRims) {
|
||||
// this is done to make sure we have the version with the UUID
|
||||
dbBaseRim = BaseReferenceManifest.select(referenceManifestManager)
|
||||
.byBase64Hash(base.getBase64Hash()).getRIM();
|
||||
if (dbBaseRim != null) {
|
||||
for (SwidResource swid : dbBaseRim.parseResource()) {
|
||||
tempMap.put(swid.getHashValue(), dbBaseRim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tempMap;
|
||||
}
|
||||
|
||||
private Map<String, SupportReferenceManifest> updateSupportRimInfo(
|
||||
final Map<String, BaseReferenceManifest> dbBaseRims) {
|
||||
BaseReferenceManifest dbBaseRim;
|
||||
SupportReferenceManifest supportRim;
|
||||
Map<String, SupportReferenceManifest> updatedSupportRims = new HashMap<>();
|
||||
List<String> hashValues = new LinkedList<>(dbBaseRims.keySet());
|
||||
for (String supportHash : hashValues) {
|
||||
supportRim = SupportReferenceManifest.select(referenceManifestManager)
|
||||
.byHexDecHash(supportHash).getRIM();
|
||||
// I have to assume the baseRim is from the database
|
||||
// Updating the id values, manufacturer, model
|
||||
if (supportRim != null && !supportRim.isUpdated()) {
|
||||
dbBaseRim = dbBaseRims.get(supportHash);
|
||||
supportRim.setSwidTagVersion(dbBaseRim.getSwidTagVersion());
|
||||
supportRim.setPlatformManufacturer(dbBaseRim.getPlatformManufacturer());
|
||||
supportRim.setPlatformModel(dbBaseRim.getPlatformModel());
|
||||
supportRim.setTagId(dbBaseRim.getTagId());
|
||||
supportRim.setAssociatedRim(dbBaseRim.getId());
|
||||
supportRim.setUpdated(true);
|
||||
referenceManifestManager.update(supportRim);
|
||||
updatedSupportRims.put(supportHash, supportRim);
|
||||
}
|
||||
}
|
||||
|
||||
return updatedSupportRims;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the support rim is a supplemental or base, this method looks for the
|
||||
* original oem base rim to associate with each event.
|
||||
* @param supportRim assumed db object
|
||||
* @return reference to the base rim
|
||||
*/
|
||||
private ReferenceManifest findBaseRim(final SupportReferenceManifest supportRim) {
|
||||
if (supportRim != null && (supportRim.getId() != null
|
||||
&& !supportRim.getId().toString().equals(""))) {
|
||||
Set<BaseReferenceManifest> baseRims = BaseReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.byManufacturerModel(supportRim.getPlatformManufacturer(),
|
||||
supportRim.getPlatformModel()).getRIMs();
|
||||
|
||||
for (BaseReferenceManifest base : baseRims) {
|
||||
if (base.isBase()) {
|
||||
// there should be only one
|
||||
return base;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processTpmEvents(final List<SupportReferenceManifest> dbSupportRims) {
|
||||
boolean updated = true;
|
||||
List<ReferenceDigestValue> tpmEvents;
|
||||
TCGEventLog logProcessor = null;
|
||||
ReferenceManifest baseRim;
|
||||
|
||||
for (SupportReferenceManifest dbSupport : dbSupportRims) {
|
||||
// So first we'll have to pull values based on support rim
|
||||
// get by support rim id NEXT
|
||||
|
||||
tpmEvents = referenceEventManager.getValuesByRimId(dbSupport);
|
||||
baseRim = findBaseRim(dbSupport);
|
||||
if (tpmEvents.isEmpty()) {
|
||||
ReferenceDigestValue rdv;
|
||||
try {
|
||||
logProcessor = new TCGEventLog(dbSupport.getRimBytes());
|
||||
for (TpmPcrEvent tpe : logProcessor.getEventList()) {
|
||||
rdv = new ReferenceDigestValue(baseRim.getId(),
|
||||
dbSupport.getId(), dbSupport.getPlatformManufacturer(),
|
||||
dbSupport.getPlatformModel(), tpe.getPcrIndex(),
|
||||
tpe.getEventDigestStr(), tpe.getEventTypeStr(),
|
||||
false, false, updated, tpe.getEventContent());
|
||||
|
||||
this.referenceEventManager.saveValue(rdv);
|
||||
}
|
||||
} catch (CertificateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
for (ReferenceDigestValue rdv : tpmEvents) {
|
||||
if (!rdv.isUpdated()) {
|
||||
rdv.updateInfo(dbSupport, baseRim.getId());
|
||||
this.referenceEventManager.updateEvent(rdv);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CertificateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,35 @@ public class BaseReferenceManifest extends ReferenceManifest {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the platform manufacturer/model that rims must have to be considered
|
||||
* as matching.
|
||||
* @param manufacturer string for the manufacturer
|
||||
* @param model string for the model
|
||||
* @return this instance
|
||||
*/
|
||||
public Selector byManufacturerModel(final String manufacturer, final String model) {
|
||||
setFieldValue(PLATFORM_MANUFACTURER, manufacturer);
|
||||
setFieldValue(PLATFORM_MODEL, model);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the platform manufacturer/model/base flag that rims must have to be considered
|
||||
* as matching.
|
||||
* @param manufacturer string for the manufacturer
|
||||
* @param model string for the model
|
||||
* @return this instance
|
||||
*/
|
||||
public Selector byManufacturerModelBase(final String manufacturer, final String model) {
|
||||
setFieldValue(PLATFORM_MANUFACTURER, manufacturer);
|
||||
setFieldValue(PLATFORM_MODEL, model);
|
||||
setFieldValue("swidPatch", false);
|
||||
setFieldValue("swidSupplemental", false);
|
||||
//setFieldValue("", false); //corpus?
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the device name that rims must have to be considered
|
||||
* as matching.
|
||||
@ -492,6 +521,15 @@ public class BaseReferenceManifest extends ReferenceManifest {
|
||||
this.swidCorpus = swidCorpus;
|
||||
}
|
||||
|
||||
/**
|
||||
* The assumed requirement for being the initial swidtag.
|
||||
* @return flag for the status
|
||||
*/
|
||||
public boolean isBase() {
|
||||
return !this.isSwidPatch() && !this.isSwidSupplemental()
|
||||
&& (this.isSwidCorpus() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Entity Name.
|
||||
*
|
||||
|
@ -47,6 +47,8 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
private boolean matchFail;
|
||||
@Column(nullable = false)
|
||||
private boolean patched = false;
|
||||
@Column(nullable = false)
|
||||
private boolean updated = false;
|
||||
|
||||
/**
|
||||
* Default constructor necessary for Hibernate.
|
||||
@ -62,6 +64,7 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
this.eventType = "";
|
||||
this.matchFail = false;
|
||||
this.patched = false;
|
||||
this.updated = false;
|
||||
this.contentBlob = null;
|
||||
}
|
||||
|
||||
@ -75,14 +78,16 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
* @param digestValue the key digest value
|
||||
* @param eventType the event type to store
|
||||
* @param matchFail the status of the baseline check
|
||||
* @param patched the status of the value being updated to to patch
|
||||
* @param patched the status of the value being updated to patch
|
||||
* @param updated the status of the value being updated with info
|
||||
* @param contentBlob the data value of the content
|
||||
*/
|
||||
public ReferenceDigestValue(final UUID baseRimId, final UUID supportRimId,
|
||||
final String manufacturer, final String model,
|
||||
final int pcrIndex, final String digestValue,
|
||||
final String eventType, final boolean matchFail,
|
||||
final boolean patched, final byte[] contentBlob) {
|
||||
final boolean patched, final boolean updated,
|
||||
final byte[] contentBlob) {
|
||||
this.baseRimId = baseRimId;
|
||||
this.supportRimId = supportRimId;
|
||||
this.manufacturer = manufacturer;
|
||||
@ -92,6 +97,7 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
this.eventType = eventType;
|
||||
this.matchFail = matchFail;
|
||||
this.patched = patched;
|
||||
this.updated = updated;
|
||||
this.contentBlob = Arrays.clone(contentBlob);
|
||||
}
|
||||
|
||||
@ -239,6 +245,22 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
this.patched = patched;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the status of the updated state.
|
||||
* @return updated flag
|
||||
*/
|
||||
public boolean isUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the status of the updated state.
|
||||
* @param updated the flag to set
|
||||
*/
|
||||
public void setUpdated(final boolean updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the byte array of event values.
|
||||
* @return a clone of the byte array
|
||||
@ -260,12 +282,19 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
/**
|
||||
* Helper method to update the attributes of this object.
|
||||
* @param support the associated RIM.
|
||||
* @param baseRimId the main id to update
|
||||
*/
|
||||
public void updateInfo(final SupportReferenceManifest support) {
|
||||
if (support != null && support.getId().equals(getSupportRimId())) {
|
||||
setBaseRimId(support.getAssociatedRim());
|
||||
public void updateInfo(final SupportReferenceManifest support, final UUID baseRimId) {
|
||||
if (support != null) {
|
||||
setBaseRimId(baseRimId);
|
||||
setManufacturer(support.getPlatformManufacturer());
|
||||
setModel(support.getPlatformModel());
|
||||
setUpdated(true);
|
||||
if (support.isSwidPatch()) {
|
||||
// come back to this later, how does this get
|
||||
// identified to be patched
|
||||
setPatched(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,7 +317,7 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = Objects.hash(pcrIndex, digestValue, manufacturer, model,
|
||||
eventType, matchFail, patched);
|
||||
eventType, matchFail, patched, updated);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -297,7 +326,8 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
* @return a string
|
||||
*/
|
||||
public String toString() {
|
||||
return String.format("ReferenceDigestValue: {%s, %d, %s, %s, %b}",
|
||||
model, pcrIndex, digestValue, eventType, matchFail);
|
||||
return String.format("ReferenceDigestValue: {%s, %d, %s, %s, "
|
||||
+ "matchFail - %b, updated - %b, patched - %b}",
|
||||
model, pcrIndex, digestValue, eventType, matchFail, updated, patched);
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,19 @@ public class SupportReferenceManifest extends ReferenceManifest {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the platform model that rims must have to be considered
|
||||
* as matching.
|
||||
* @param manufacturer string for the manufacturer
|
||||
* @param model string for the model
|
||||
* @return this instance
|
||||
*/
|
||||
public Selector byManufacturerModel(final String manufacturer, final String model) {
|
||||
setFieldValue(PLATFORM_MANUFACTURER, manufacturer);
|
||||
setFieldValue(PLATFORM_MODEL, model);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the device name that rims must have to be considered
|
||||
* as matching.
|
||||
|
@ -41,4 +41,12 @@ public interface ReferenceManifestManager extends OrderedListQuerier<ReferenceMa
|
||||
* @return true if the deletion succeeded, false otherwise.
|
||||
*/
|
||||
boolean delete(ReferenceManifest referenceManifest);
|
||||
|
||||
/**
|
||||
* Remove a ReferenceManifest from the database.
|
||||
*
|
||||
* @param referenceManifest the referenceManifest to delete
|
||||
* @return true if deletion was successful, false otherwise
|
||||
*/
|
||||
boolean deleteReferenceManifest(ReferenceManifest referenceManifest);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user