diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CertificateRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CertificateRepository.java index 900a30a6..e39c4281 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CertificateRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CertificateRepository.java @@ -25,6 +25,7 @@ public interface CertificateRepository extends JpaRepository List findByType(String dType); @Query(value = "SELECT * FROM Certificate where serialNumber = ?1 AND DTYPE = ?2", nativeQuery = true) Certificate findBySerialNumber(BigInteger serialNumber, String dType); + Certificate findByPlatformSerialAndSerialNumber(String platformSerial, BigInteger serialNumber); @Query(value = "SELECT * FROM Certificate where platformSerial = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true) List byBoardSerialNumber(String boardSerialNumber); @Query(value = "SELECT * FROM Certificate where holderSerialNumber = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true) diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ComponentInfoRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ComponentInfoRepository.java index 67fec4f0..e84fd2b0 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ComponentInfoRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ComponentInfoRepository.java @@ -13,6 +13,12 @@ public interface ComponentInfoRepository extends JpaRepository findByDeviceName(String deviceName); + /** + * Query that retrieves device components by device name and order them + * @param deviceName string for the host name + * @return a list of device components + */ + List findByDeviceNameOrderByDeviceNameAsc(String deviceName); /** * Query that retrieves device components by device name and diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ComponentComparisonPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ComponentComparisonPageController.java index 3a5f58a8..78811ead 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ComponentComparisonPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ComponentComparisonPageController.java @@ -2,11 +2,16 @@ package hirs.attestationca.portal.page.controllers; import hirs.attestationca.persist.entity.manager.CertificateRepository; import hirs.attestationca.persist.entity.manager.ComponentAttributeRepository; +import hirs.attestationca.persist.entity.manager.ComponentInfoRepository; import hirs.attestationca.persist.entity.manager.ComponentResultRepository; +import hirs.attestationca.persist.entity.userdefined.certificate.ComponentResult; +import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential; +import hirs.attestationca.persist.entity.userdefined.certificate.attributes.ComponentAttributeResult; +import hirs.attestationca.persist.util.PciIds; import hirs.attestationca.portal.page.Page; import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.PageMessages; -import hirs.attestationca.portal.page.params.NoPageParams; +import hirs.attestationca.portal.page.params.CertificateDetailsPageParams; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -14,19 +19,31 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; +import java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + @Log4j2 @Controller @RequestMapping("/HIRS_AttestationCAPortal/portal/component-validation") -public class ComponentComparisonPageController extends PageController { +public class ComponentComparisonPageController extends PageController { private final CertificateRepository certificateRepository; private final ComponentResultRepository componentResultRepository; + private final ComponentInfoRepository componentInfoRepository; private final ComponentAttributeRepository componentAttributeRepository; @Autowired - public ComponentComparisonPageController(final CertificateRepository certificateRepository, final ComponentResultRepository componentResultRepository, final ComponentAttributeRepository componentAttributeRepository) { + public ComponentComparisonPageController(final CertificateRepository certificateRepository, + final ComponentResultRepository componentResultRepository, + final ComponentInfoRepository componentInfoRepository, + final ComponentAttributeRepository componentAttributeRepository) { super(Page.COMPONENT_COMPARISON); this.certificateRepository = certificateRepository; this.componentResultRepository = componentResultRepository; + this.componentInfoRepository = componentInfoRepository; this.componentAttributeRepository = componentAttributeRepository; } @@ -40,16 +57,98 @@ public class ComponentComparisonPageController extends PageController data = new HashMap<>(); mav.addObject(MESSAGES_ATTRIBUTE, messages); mav.addObject(INITIAL_DATA, data); + // Check if parameters were set + if (params.getId() == null) { + String typeError = "ID was not provided"; + messages.addError(typeError); + log.debug(typeError); + mav.addObject(MESSAGES_ATTRIBUTE, messages); + } else { + try { + UUID uuid = UUID.fromString(params.getId()); + data.putAll(getPlatformComponentInformation(uuid, params.getDeviceName(), + certificateRepository, componentResultRepository, + componentInfoRepository, + componentAttributeRepository)); + } catch (IllegalArgumentException iaEx) { + String uuidError = "Failed to parse ID from: " + params.getId(); + messages.addError(uuidError); + log.error(uuidError, iaEx); + } catch (IOException ioEx) { + log.error(ioEx); + } catch (Exception ex) { + log.error(ex); + } + + if (data.isEmpty()) { + String notFoundMessage = "Unable to find RIM with ID: " + params.getId(); + messages.addError(notFoundMessage); + log.warn(notFoundMessage); + mav.addObject(MESSAGES_ATTRIBUTE, messages); + } else { + mav.addObject(INITIAL_DATA, data); + } + } return mav; } + + /** + * Compiles and returns Platform Certificate component information. + * + * @param uuid ID for the certificate. + * @param certificateRepository the certificate manager for retrieving certs. + * @return a hash map with the endorsement certificate information. + * @throws IOException when parsing the certificate + * @throws IllegalArgumentException invalid argument on parsing the certificate + */ + public static HashMap getPlatformComponentInformation( + final UUID sessionId, final String deviceName, + final CertificateRepository certificateRepository, + final ComponentResultRepository componentResultRepository, + final ComponentInfoRepository componentInfoRepository, + final ComponentAttributeRepository componentAttributeRepository) + throws IllegalArgumentException, IOException { + HashMap data = new HashMap<>(); + List componentResults = new ArrayList<>(); + List attributeResults = componentAttributeRepository.findByProvisionSessionId(sessionId); + if (!attributeResults.isEmpty()) { + List tempIdList = new ArrayList<>(); + attributeResults.stream().forEach((dbObject) -> { + if (!tempIdList.contains(dbObject.getComponentId())) { + tempIdList.add(dbObject.getComponentId()); + } + }); + componentResults.addAll(componentResultRepository.findAllById(tempIdList)); + PlatformCredential platformCredential = certificateRepository.findByPlatformSerialAndSerialNumber(componentResults.get(0).getBoardSerialNumber(), BigInteger.valueOf(Long.parseLong(componentResults.get(0).getCertificateSerialNumber())); + + if (platformCredential != null) { + data.put("certificateId", platformCredential.getId()); + data.put("certificateSerialNumber", platformCredential.getSerialNumber()); + data.put("platformManufacturer", platformCredential.getManufacturer()); + data.put("platformModel", platformCredential.getModel()); + } + if (PciIds.DB.isReady()) { + componentResults = PciIds.translateResults(componentResults); + } + data.put("componentResults", componentResults); + data.put("componentInfos", componentInfoRepository.findByDeviceNameOrderByDeviceNameAsc(deviceName)); + } else { + String notFoundMessage = "Unable to find Platform Certificate " + + "with ID: " + uuid; + log.error(notFoundMessage); + } + return data; + } } diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/params/CertificateDetailsPageParams.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/params/CertificateDetailsPageParams.java index 7df3d2b2..da800b5f 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/params/CertificateDetailsPageParams.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/params/CertificateDetailsPageParams.java @@ -18,6 +18,7 @@ public class CertificateDetailsPageParams implements PageParams { private String id; private String type; private String sessionId; + private String deviceName; /** * Constructor to set ID Certificate Details URL parameters. @@ -35,6 +36,7 @@ public class CertificateDetailsPageParams implements PageParams { id = null; type = null; sessionId = null; + deviceName = null; } /** @@ -57,5 +59,4 @@ public class CertificateDetailsPageParams implements PageParams { + "type: " + type + "}"; } - } diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/component-comparison.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/component-comparison.jsp new file mode 100644 index 00000000..f6529330 --- /dev/null +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/component-comparison.jsp @@ -0,0 +1,83 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + +<%-- JSP TAGS --%> +<%@taglib prefix="c" uri="jakarta.tags.core" %> +<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@taglib prefix="fn" uri="jakarta.tags.functions"%> +<%@taglib prefix="my" tagdir="/WEB-INF/tags"%> + +<%--CONTENT--%> + + + + + + + + + Platform Component Failure Comparison + + +
+
+
+
Support Component Objects
+
+ +
Device: ${initialData.hostName} +
+
+ +
Platform Certificate: ${initialData.certificateFileName} +
+
+
+
+
+
+
+
Client Log
+ + + +
+
+
Failed Event Digest:
+
+
+ PCR Index: ${lEvent.getPcrIndex()}
+ Digest: ${lEvent.getEventDigestStr()}
+ Event Content: ${lEvent.getEventContentStr()} +
+
+
+
+
+ Expected Events from RIM DB:
+ ${lEvent.getEventTypeString()} +
+
+ + + + +
+
PCR Index: ${event.getPcrIndex()}
+
Digest: ${event.getEventDigestStr()}
+
Event Content: ${event.getEventContentStr()}
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
\ No newline at end of file