From ee7befca812c7e6d301391e994f1d6565f407412 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Fri, 8 Oct 2021 16:35:40 -0400 Subject: [PATCH 1/4] This initial commit adds the ability to download all platform credentials and trust chain credentials from their respective pages in a bulk zip. --- .../CertificateRequestPageController.java | 93 ++++++++++++++++++- .../WEB-INF/jsp/platform-credentials.jsp | 6 ++ .../main/webapp/WEB-INF/jsp/trust-chain.jsp | 6 ++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java index 1032d836..2b74d217 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.util.StreamUtils; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -48,11 +49,13 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; import static org.apache.logging.log4j.LogManager.getLogger; /** - * Controller for the Device page. + * Controller for the Certificates list all pages. */ @Controller @RequestMapping("/certificate-request") @@ -374,6 +377,94 @@ public class CertificateRequestPageController extends PageController +
+ Bulk Platform Credentials Download + + + +

diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp index ca8782c2..3e19cd67 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp @@ -78,6 +78,12 @@
+
+ Bulk Trust Chain CA Credentials Download + + + +

From 9492c680da3499052e2058e3987a4a74bcb6893f Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Tue, 12 Oct 2021 08:41:45 -0400 Subject: [PATCH 2/4] There was an checkstyles error that needed to be corrected. --- .../page/controllers/CertificateRequestPageController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java index 2b74d217..312b3d04 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java @@ -398,7 +398,8 @@ public class CertificateRequestPageController extends PageController Date: Fri, 29 Oct 2021 15:42:57 -0400 Subject: [PATCH 3/4] Updated the labeling for the Trust chain and platform certificates. The import label is removed and the download icon moved next to the import button. Added the same functionality to the RIMs. --- .../ReferenceManifestPageController.java | 57 +++++++++++++++++++ .../WEB-INF/jsp/platform-credentials.jsp | 11 ++-- .../WEB-INF/jsp/reference-manifests.jsp | 5 +- .../main/webapp/WEB-INF/jsp/trust-chain.jsp | 12 ++-- 4 files changed, 69 insertions(+), 16 deletions(-) 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 f73d4c16..999b03dc 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 @@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.util.StreamUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -45,11 +46,15 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; /** * Controller for the Reference Manifest page. @@ -356,6 +361,58 @@ public class ReferenceManifestPageController } } + /** + * Handles request to download bulk of RIMs by writing it to the response stream + * for download in bulk. + * + * @param response the response object (needed to update the header with the + * file name) + * @throws java.io.IOException when writing to response output stream + */ + @RequestMapping(value = "/bulk", method = RequestMethod.GET) + public void bulk(final HttpServletResponse response) + throws IOException { + LOGGER.info("Handling request to download all Reference Integrity Manifests"); + String fileName = "rims.zip"; + String zipFileName; + + // Set filename for download. + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + response.setContentType("application/zip"); + + List referenceManifestList = new LinkedList<>(); + referenceManifestList.addAll(BaseReferenceManifest + .select(referenceManifestManager).getRIMs()); + referenceManifestList.addAll(SupportReferenceManifest + .select(referenceManifestManager).getRIMs()); + + try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) { + // get all files + for (ReferenceManifest rim : referenceManifestList) { + if (rim.getFileName().isEmpty()) { + zipFileName = ""; + } else { + // configure the zip entry, the properties of the 'file' + zipFileName = rim.getFileName(); + } + ZipEntry zipEntry = new ZipEntry(zipFileName); + zipEntry.setSize((long) rim.getRimBytes().length * Byte.SIZE); + zipEntry.setTime(System.currentTimeMillis()); + zipOut.putNextEntry(zipEntry); + // the content of the resource + StreamUtils.copy(rim.getRimBytes(), zipOut); + zipOut.closeEntry(); + } + zipOut.finish(); + // write cert to output stream + } catch (IllegalArgumentException ex) { + String uuidError = "Failed to parse ID from: "; + LOGGER.error(uuidError, ex); + // send a 404 error when invalid certificate + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + /** * This method takes the parameter and looks for this information in the * Database. diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp index 67e3e02a..c0e44451 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp @@ -19,18 +19,15 @@
- Import Platform Credentials + Platform Credentials + + +
-
- Bulk Platform Credentials Download - - - -

diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/reference-manifests.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/reference-manifests.jsp index 4c090170..dee517ad 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/reference-manifests.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/reference-manifests.jsp @@ -18,10 +18,13 @@
- Import RIMs + Reference Integrity Manifests + + +

diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp index 3e19cd67..0e7eb26f 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp @@ -71,20 +71,16 @@
- Import Trust Chain CA Certificates + Trust Chain CA Certificates + + +

-
- Bulk Trust Chain CA Credentials Download - - - -
-
From bd5d9059906b41fad0a51c77b33fc0b41583c26e Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Thu, 4 Nov 2021 15:55:55 -0400 Subject: [PATCH 4/4] Updated the code to include bulk downloads for issued, eks. --- .../CertificateRequestPageController.java | 94 ++++++++++++++++++- .../jsp/endorsement-key-credentials.jsp | 3 + .../WEB-INF/jsp/issued-certificates.jsp | 8 +- .../WEB-INF/jsp/platform-credentials.jsp | 2 +- .../main/webapp/WEB-INF/jsp/trust-chain.jsp | 2 +- 5 files changed, 104 insertions(+), 5 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java index 312b3d04..684f903b 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificateRequestPageController.java @@ -401,7 +401,7 @@ public class CertificateRequestPageController extends PageController + + +
diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/issued-certificates.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/issued-certificates.jsp index 04c7ad79..2beacdff 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/issued-certificates.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/issued-certificates.jsp @@ -13,8 +13,14 @@ Issued Certificates - +
+ Issued Credentials + + + +
+
diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp index c0e44451..54b6ce35 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp @@ -24,7 +24,7 @@ - + diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp index 0e7eb26f..1870a0b1 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/trust-chain.jsp @@ -76,7 +76,7 @@ - +