From a4d639925e2cce3653d53efad100e25ff7832a08 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Fri, 20 Nov 2020 20:56:26 -0500 Subject: [PATCH 1/8] Frontend changes: download link to validation report --- .../webapp/WEB-INF/jsp/validation-reports.jsp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp index 530d4f3c..d3663ac8 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp @@ -93,7 +93,10 @@ { // TODO render a link to a device details page, // passing the device.id - data: 'device.name' + data: 'device.name', + render: function (data, type, full, meta) { + return createDownloadLink(full); + } }, { data: 'id', @@ -126,6 +129,16 @@ dataTable.order([1, 'desc']).draw(); //order by createTime }); + /** + * This method builds a url to download the device validation report. + */ + function createDownloadLink(full) { + return full.device.name + ' ' + + '' + + ''; + } + /** * Gets HTML to display (icon tag) for the specified validation type. * If a validation for the requested type is not found, an empty From 18ec7d4a5b4a35af853075e4b56db33c4fae1792 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Wed, 25 Nov 2020 13:11:17 -0500 Subject: [PATCH 2/8] Controller changes: Pull platform credential for device and parse info --- .../ValidationReportsPageController.java | 33 ++++++++++++++++++- .../webapp/WEB-INF/jsp/validation-reports.jsp | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java index e95d4ca3..bdafe79d 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java @@ -6,6 +6,9 @@ import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter; import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.params.NoPageParams; import hirs.data.persist.certificate.Certificate; +import hirs.data.persist.certificate.PlatformCredential; +import hirs.data.persist.certificate.attributes.ComponentIdentifier; +import hirs.persist.CertificateManager; import org.apache.logging.log4j.Logger; import static org.apache.logging.log4j.LogManager.getLogger; import org.hibernate.Criteria; @@ -16,6 +19,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @@ -25,6 +29,10 @@ import hirs.data.persist.SupplyChainValidationSummary; import hirs.persist.CriteriaModifier; import hirs.persist.CrudManager; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.UUID; + /** * Controller for the Validation Reports page. */ @@ -33,6 +41,7 @@ import hirs.persist.CrudManager; public class ValidationReportsPageController extends PageController { private final CrudManager supplyChainValidatorSummaryManager; + private final CertificateManager certificateManager; private static final Logger LOGGER = getLogger(ValidationReportsPageController.class); @@ -42,9 +51,11 @@ public class ValidationReportsPageController extends PageController supplyChainValidatorSummaryManager) { + final CrudManager supplyChainValidatorSummaryManager, + final CertificateManager certificateManager) { super(VALIDATION_REPORTS); this.supplyChainValidatorSummaryManager = supplyChainValidatorSummaryManager; + this.certificateManager = certificateManager; } /** @@ -97,4 +108,24 @@ public class ValidationReportsPageController extends PageController(records, input); } + + @RequestMapping(value = "download", method = RequestMethod.GET) + public void download(@RequestParam final String id, + final HttpServletResponse response) { + LOGGER.info("Downloading validation report for " + id); + UUID uuid = UUID.fromString(id); + PlatformCredential pc = PlatformCredential.select(certificateManager).byDeviceId(uuid).getCertificate(); + LOGGER.info("Verified manufacturer: " + pc.getManufacturer()); + LOGGER.info("Model: " + pc.getModel()); + LOGGER.info("SN: " + pc.getChassisSerialNumber()); + LOGGER.info("Verification date: " + pc.getBeginValidity()); + if (pc.getComponentIdentifiers() != null && + pc.getComponentIdentifiers().size() > 0) { + for (ComponentIdentifier ci : pc.getComponentIdentifiers()) { + LOGGER.info("Manufacturer ID: " + ci.getComponentManufacturerId().toString() + + "\nModel: " + ci.getComponentModel().getString() + + "\nRevision: " + ci.getComponentRevision().getString()); + } + } + } } diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp index d3663ac8..ce09ed94 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp @@ -134,7 +134,7 @@ */ function createDownloadLink(full) { return full.device.name + ' ' + - '' + ''; } From bb6cbfe87174038198ee0e84feecc04b30b011d8 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Mon, 7 Dec 2020 16:31:26 -0500 Subject: [PATCH 3/8] Front end change: display modal dialog for user input on download link click. --- .../ValidationReportsPageController.java | 18 +++++++--- .../webapp/WEB-INF/jsp/validation-reports.jsp | 33 ++++++++++++++++--- .../webapp/WEB-INF/tags/download-info.tag | 14 ++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/tags/download-info.tag diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java index bdafe79d..c1548f77 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java @@ -29,8 +29,9 @@ import hirs.data.persist.SupplyChainValidationSummary; import hirs.persist.CriteriaModifier; import hirs.persist.CrudManager; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; +import java.util.Enumeration; import java.util.UUID; /** @@ -109,10 +110,17 @@ public class ValidationReportsPageController extends PageController(records, input); } - @RequestMapping(value = "download", method = RequestMethod.GET) + @RequestMapping(value = "download", method = RequestMethod.POST) public void download(@RequestParam final String id, + final HttpServletRequest request, final HttpServletResponse response) { + LOGGER.info("Downloading validation report for " + id); + Enumeration parameters = request.getParameterNames(); + while (parameters.hasMoreElements()) { + String parameter = (String) parameters.nextElement(); + LOGGER.info(parameter + ": " + request.getParameter(parameter)); + } UUID uuid = UUID.fromString(id); PlatformCredential pc = PlatformCredential.select(certificateManager).byDeviceId(uuid).getCertificate(); LOGGER.info("Verified manufacturer: " + pc.getManufacturer()); @@ -122,8 +130,10 @@ public class ValidationReportsPageController extends PageController 0) { for (ComponentIdentifier ci : pc.getComponentIdentifiers()) { - LOGGER.info("Manufacturer ID: " + ci.getComponentManufacturerId().toString() + - "\nModel: " + ci.getComponentModel().getString() + + if (ci.getComponentManufacturerId() != null) { + LOGGER.info("Manufacturer ID: " + ci.getComponentManufacturerId().toString()); + } + LOGGER.info("\nModel: " + ci.getComponentModel().getString() + "\nRevision: " + ci.getComponentRevision().getString()); } } diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp index ce09ed94..85ffeda2 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp @@ -133,10 +133,35 @@ * This method builds a url to download the device validation report. */ function createDownloadLink(full) { - return full.device.name + ' ' + - '' + - ''; + var device = full.device; + var html = '
' + + device.name + + '' + + '' + + '' + + '' + + '
'; + return html; } /** diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/tags/download-info.tag b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/tags/download-info.tag new file mode 100644 index 00000000..f14e33e0 --- /dev/null +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/tags/download-info.tag @@ -0,0 +1,14 @@ +<%@tag description="download icon that opens modal dialog with form" pageEncoding="UTF-8"%> + +<%@attribute name="id"%> +<%@attribute name="label"%> +<%@attribute name="customButtons" fragment="true" required="false"%> + +<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %> + + + + + + + \ No newline at end of file From 3cd9e06f97b2dbb74b6a482df18c2bc49247f7bc Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Wed, 23 Dec 2020 10:08:25 -0500 Subject: [PATCH 4/8] Add user input fields to modal dialog. Handle user input, collect device report data, and write to local file. --- .../ValidationReportsPageController.java | 72 ++++++++++++++++--- .../webapp/WEB-INF/jsp/validation-reports.jsp | 6 +- 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java index c1548f77..039f50bb 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java @@ -8,6 +8,7 @@ import hirs.attestationca.portal.page.params.NoPageParams; import hirs.data.persist.certificate.Certificate; import hirs.data.persist.certificate.PlatformCredential; import hirs.data.persist.certificate.attributes.ComponentIdentifier; +import hirs.data.persist.certificate.attributes.V2.ComponentIdentifierV2; import hirs.persist.CertificateManager; import org.apache.logging.log4j.Logger; import static org.apache.logging.log4j.LogManager.getLogger; @@ -31,6 +32,9 @@ import hirs.persist.CrudManager; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; import java.util.Enumeration; import java.util.UUID; @@ -49,6 +53,7 @@ public class ValidationReportsPageController extends PageController(records, input); } + /** + * This method handles downloading a validation report. The report will contain the + * following data: + * - Company devices where shipped from + * - Contract# + * - Report for Date range (default to current date) + * -Verified Manufacturer is the Platform Vendor + * - Model is the Platform Model + * - SN is the Chassis SN + * - Verification Data is the not before time on the Attestation Certificate + * - Component Status column is 8 component classes names listed above + * (Component Status data is taken from the pass/fail status of the report summary) + * - Device Status is the overall pass/fail of the report summary + * @param id of the validated device + * @param deviceName name of the validated device + * @param request object + * @param response object + * @throws IOException thrown by BufferedWriter object + */ @RequestMapping(value = "download", method = RequestMethod.POST) public void download(@RequestParam final String id, + @RequestParam final String deviceName, final HttpServletRequest request, - final HttpServletResponse response) { + final HttpServletResponse response) throws IOException { LOGGER.info("Downloading validation report for " + id); + response.setHeader("Content-Type", "text/plain"); + response.setHeader("Content-Disposition", + "attachment;filename=\"" + deviceName + "_validation_report.txt\""); + BufferedWriter bufferedWriter = new BufferedWriter( + new OutputStreamWriter(response.getOutputStream(), "UTF-8")); Enumeration parameters = request.getParameterNames(); while (parameters.hasMoreElements()) { String parameter = (String) parameters.nextElement(); + bufferedWriter.append(parameter + ": " + request.getParameter(parameter) + "\n"); LOGGER.info(parameter + ": " + request.getParameter(parameter)); } +// String columnHeaders = "Company, Contract Number, Date Range, Verified Manufacturer, " +// + "Model, SN, Verification Date, Component Statuses, Device Status"; +// bufferedWriter.append(columnHeaders + "\n"); +// LOGGER.info(columnHeaders); UUID uuid = UUID.fromString(id); - PlatformCredential pc = PlatformCredential.select(certificateManager).byDeviceId(uuid).getCertificate(); + PlatformCredential pc = PlatformCredential.select(certificateManager) + .byDeviceId(uuid).getCertificate(); + bufferedWriter.append("Verified manufacturer: " + pc.getManufacturer() + "\n"); + bufferedWriter.append("Model: " + pc.getModel() + "\n"); + bufferedWriter.append("SN: " + pc.getChassisSerialNumber() + "\n"); + bufferedWriter.append("Verification date: " + pc.getBeginValidity() + "\n"); LOGGER.info("Verified manufacturer: " + pc.getManufacturer()); LOGGER.info("Model: " + pc.getModel()); LOGGER.info("SN: " + pc.getChassisSerialNumber()); LOGGER.info("Verification date: " + pc.getBeginValidity()); - if (pc.getComponentIdentifiers() != null && - pc.getComponentIdentifiers().size() > 0) { + if (pc.getComponentIdentifiers() != null + && pc.getComponentIdentifiers().size() > 0) { for (ComponentIdentifier ci : pc.getComponentIdentifiers()) { - if (ci.getComponentManufacturerId() != null) { - LOGGER.info("Manufacturer ID: " + ci.getComponentManufacturerId().toString()); + if (ci instanceof ComponentIdentifierV2) { + bufferedWriter.append(((ComponentIdentifierV2) ci).getComponentClass() + + "\nComponent status: " + + ((ComponentIdentifierV2) ci).getAttributeStatus() + "\n"); + LOGGER.info(((ComponentIdentifierV2) ci).getComponentClass() + + "\nComponent status: " + + ((ComponentIdentifierV2) ci).getAttributeStatus()); + } else { + bufferedWriter.append("Platform Components" + "\n"); + LOGGER.info("Platform Components"); } - LOGGER.info("\nModel: " + ci.getComponentModel().getString() + - "\nRevision: " + ci.getComponentRevision().getString()); + bufferedWriter.append("Component manufacturer : " + + ci.getComponentManufacturer().getString() + + "\nComponent model: " + ci.getComponentModel().getString() + + "\nComponent revision: " + ci.getComponentRevision().getString() + "\n"); + LOGGER.info("Component manufacturer : " + + ci.getComponentManufacturer().getString() + + "\nComponent model: " + ci.getComponentModel().getString() + + "\nComponent revision: " + ci.getComponentRevision().getString()); } } + + bufferedWriter.flush(); } } diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp index 85ffeda2..f811c998 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/validation-reports.jsp @@ -134,7 +134,9 @@ */ function createDownloadLink(full) { var device = full.device; - var html = '
' + + var deviceStatus = full.overallValidationResult; + var html = '' + device.name + '' + '' + @@ -149,6 +151,8 @@ '' + '' + '' + + '' + '' + '