diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/Page.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/Page.java index f216684d..4dd20d23 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/Page.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/Page.java @@ -54,14 +54,14 @@ public enum Page { */ RIM_DETAILS("Reference Integrity Manifest Details", "", null, true, false, null, null), + /** + * Page to display RIM event digest table. + */ + TPM_EVENTS("RIM Database", "ic_important_devices", "first"), /** * Page that manages Attestation CA Policy. */ POLICY("Policy", "ic_subtitles"), - /** - * Page to display RIM event digest table. - */ - TPM_EVENTS("RIM Database", null, "first"), /** * Help page. */ diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java index 73290a56..83365ca2 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java @@ -117,9 +117,6 @@ public class ReferenceManifestDetailsPageController LOGGER.error(uuidError, iaEx); } catch (Exception ioEx) { LOGGER.error(ioEx); - for (StackTraceElement ste : ioEx.getStackTrace()) { - LOGGER.error(ste.toString()); - } } if (data.isEmpty()) { String notFoundMessage = "Unable to find RIM with ID: " + params.getId(); diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java index 83be83be..ad4e7472 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java @@ -183,26 +183,27 @@ public class ReferenceManifestPageController input, orderColumnName, criteriaModifier); SupportReferenceManifest support; - List events; - for (ReferenceManifest rim : records) { - if (rim instanceof SupportReferenceManifest) { - support = (SupportReferenceManifest) rim; - events = referenceEventManager.getValuesByRimId(support); - for (ReferenceDigestValue rdv : events) { - // the selector isn't giving me what I want - if (support.getPlatformManufacturer() != null) { - rdv.setManufacturer(support.getPlatformManufacturer()); - } - if (support.getPlatformModel() != null) { - rdv.setModel(support.getPlatformModel()); - } - if (support.getAssociatedRim() != null) { - rdv.setBaseRimId(support.getAssociatedRim()); - } - referenceEventManager.updateRecord(rdv); - } - } - } +// List events; +// for (ReferenceManifest rim : records) { +// if (rim instanceof SupportReferenceManifest) { +// support = (SupportReferenceManifest) rim; +// events = referenceEventManager.getValuesByRimId(support); +// +// for (ReferenceDigestValue rdv : events) { +// // the selector isn't giving me what I want +// if (support.getPlatformManufacturer() != null) { +// rdv.setManufacturer(support.getPlatformManufacturer()); +// } +// if (support.getPlatformModel() != null) { +// rdv.setModel(support.getPlatformModel()); +// } +// if (support.getAssociatedRim() != null) { +// rdv.setBaseRimId(support.getAssociatedRim()); +// } +// referenceEventManager.updateRecord(rdv); +// } +// } +// } LOGGER.debug("Returning list of size: " + records.size()); return new DataTableResponse<>(records, input); @@ -238,34 +239,36 @@ public class ReferenceManifestPageController //Parse reference manifests ReferenceManifest rim = parseRIM(file, supportRIM, messages); - + // 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 rims = BaseReferenceManifest .select(referenceManifestManager).getRIMs(); support = (SupportReferenceManifest) rim; // update information for associated support rim - for (BaseReferenceManifest dbRim : rims) { - for (SwidResource swid : dbRim.parseResource()) { - if (swid.getName().equals(rim.getFileName())) { - support.setSwidTagVersion(dbRim.getSwidTagVersion()); - support.setPlatformManufacturer(dbRim.getPlatformManufacturer()); - support.setPlatformModel(dbRim.getPlatformModel()); - support.setTagId(dbRim.getTagId()); - support.setAssociatedRim(dbRim.getId()); - support.setUpdated(true); - break; + for (BaseReferenceManifest bRim : rims) { + for (SwidResource swid : bRim.parseResource()) { + if (support.getHexDecHash().equals(swid.getHashValue())) { + updateSupportRimInfo(bRim, support); } } + if (support.isUpdated()) { + break; + } } } else { - base = (BaseReferenceManifest) rim; - + base = (BaseReferenceManifest) referenceManifest; + // the base can find the support rim by the meta data hash for (SwidResource swid : base.parseResource()) { support = SupportReferenceManifest.select(referenceManifestManager) - .byFileName(swid.getName()).getRIM(); + .byHexDecHash(swid.getHashValue()).getRIM(); if (support != null) { base.setAssociatedRim(support.getId()); if (support.isUpdated()) { @@ -273,19 +276,12 @@ public class ReferenceManifestPageController // instead of finding it, it is uptodate but still search break; } else { - support.setSwidTagVersion(base.getSwidTagVersion()); - support.setPlatformManufacturer(base.getPlatformManufacturer()); - support.setPlatformModel(base.getPlatformModel()); - support.setTagId(base.getTagId()); - support.setUpdated(true); - - // add in update code for the events based on support id + updateSupportRimInfo(base, support); + updateTpmEvents(support); try { referenceManifestManager.update(support); } catch (DBManagerException dbmEx) { - LOGGER.error(String.format("Couldn't update Support RIM " - + "%s with associated UUID %s", rim.getTagId(), - support.getId()), dbmEx); + LOGGER.warn("Failed to update Support RIM"); } } } @@ -300,11 +296,6 @@ public class ReferenceManifestPageController } } } - - storeManifest(file.getOriginalFilename(), - messages, - rim, - supportRIM); } } @@ -346,6 +337,17 @@ public class ReferenceManifestPageController String deleteCompletedMessage = "RIM successfully deleted"; messages.addInfo(deleteCompletedMessage); LOGGER.info(deleteCompletedMessage); + + // if support rim, update associated events + if (referenceManifest instanceof SupportReferenceManifest) { + List rdvs = referenceEventManager + .getValuesByRimId(referenceManifest); + + for (ReferenceDigestValue rdv : rdvs) { + rdv.archive("Support RIM was deleted"); + referenceEventManager.updateRecord(rdv); + } + } } } catch (IllegalArgumentException ex) { String uuidError = "Failed to parse ID from: " + id; @@ -528,7 +530,7 @@ public class ReferenceManifestPageController * @param supportRim boolean flag indicating if this is a support RIM * process. */ - private void storeManifest( + private ReferenceManifest storeManifest( final String fileName, final PageMessages messages, final ReferenceManifest referenceManifest, @@ -571,7 +573,7 @@ public class ReferenceManifestPageController + "failed (%s): ", fileName); messages.addError(failMessage + e.getMessage()); LOGGER.error(failMessage, e); - return; + return null; } try { @@ -583,13 +585,14 @@ public class ReferenceManifestPageController fileName); messages.addSuccess(successMsg); LOGGER.info(successMsg); - return; + + return referenceManifest; } } catch (DBManagerException dbmEx) { final String failMessage = String.format("Storing RIM failed (%s): ", fileName); messages.addError(failMessage + dbmEx.getMessage()); LOGGER.error(failMessage, dbmEx); - return; + return null; } try { @@ -599,18 +602,62 @@ public class ReferenceManifestPageController existingManifest.restore(); existingManifest.resetCreateTime(); referenceManifestManager.update(existingManifest); - saveTpmEvents(existingManifest); final String successMsg = 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 " + "archive, but failed to unarchive it (%s): ", fileName); messages.addError(failMessage + dbmEx.getMessage()); LOGGER.error(failMessage, dbmEx); + + return null; + } + + 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 rdvs = referenceEventManager + .getValuesByRimId(referenceManifest); + + for (ReferenceDigestValue rdv : rdvs) { + rdv.setModel(model); + rdv.setManufacturer(manufacturer); + rdv.setBaseRimId(referenceManifest.getAssociatedRim()); + referenceEventManager.updateRecord(rdv); } } diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/TpmEventsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/TpmEventsPageController.java index a03b0b1b..79ee73d0 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/TpmEventsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/TpmEventsPageController.java @@ -9,12 +9,16 @@ import hirs.attestationca.portal.page.Page; import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.params.NoPageParams; import hirs.data.persist.ReferenceDigestValue; +import hirs.data.persist.SupportReferenceManifest; import hirs.data.persist.certificate.Certificate; import hirs.persist.CriteriaModifier; +import hirs.persist.DBManagerException; import hirs.persist.DBReferenceDigestManager; import hirs.persist.DBReferenceEventManager; +import hirs.persist.DBReferenceManifestManager; import hirs.persist.ReferenceDigestManager; import hirs.persist.ReferenceEventManager; +import hirs.persist.ReferenceManifestManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hibernate.Criteria; @@ -43,6 +47,7 @@ public class TpmEventsPageController private static final String BIOS_RELEASE_DATE_FORMAT = "yyyy-MM-dd"; private final BiosDateValidator biosValidator; + private final ReferenceManifestManager referenceManifestManager; private final ReferenceDigestManager referenceDigestManager; private final ReferenceEventManager referenceEventManager; private static final Logger LOGGER @@ -93,14 +98,17 @@ public class TpmEventsPageController /** * Constructor providing the Page's display and routing specification. * + * @param referenceManifestManager the ReferenceManifestManager object * @param referenceDigestManager the ReferenceDigestManager object * @param referenceEventManager the referenceEventManager object */ @Autowired public TpmEventsPageController( + final DBReferenceManifestManager referenceManifestManager, final DBReferenceDigestManager referenceDigestManager, final DBReferenceEventManager referenceEventManager) { super(Page.TPM_EVENTS); + this.referenceManifestManager = referenceManifestManager; this.referenceDigestManager = referenceDigestManager; this.referenceEventManager = referenceEventManager; this.biosValidator = new BiosDateValidator(BIOS_RELEASE_DATE_FORMAT); @@ -155,6 +163,24 @@ public class TpmEventsPageController referenceEventManager, input, orderColumnName, criteriaModifier); + SupportReferenceManifest support; + for (ReferenceDigestValue rdv : referenceDigestValues) { + // We are updating the base rim ID field if necessary and + if (rdv.getBaseRimId() == null) { + support = SupportReferenceManifest.select(referenceManifestManager) + .byEntityId(rdv.getSupportRimId()).getRIM(); + if (support != null) { + rdv.setBaseRimId(support.getAssociatedRim()); + try { + referenceEventManager.updateRecord(rdv); + } catch (DBManagerException e) { + LOGGER.error("Failed to update TPM Event with Base RIM ID"); + LOGGER.error(rdv); + } + } + } + } + return new DataTableResponse<>(referenceDigestValues, input); } }