diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/certificate/attributes/ComponentAttributeResult.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/certificate/attributes/ComponentAttributeResult.java index 12b19d2b..a689e6a9 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/certificate/attributes/ComponentAttributeResult.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/certificate/attributes/ComponentAttributeResult.java @@ -21,6 +21,7 @@ import java.util.UUID; public class ComponentAttributeResult extends ArchivableEntity { private UUID componentId; + private UUID deviceComponentId; @Setter private String provisionSessionId; private String expectedValue; @@ -29,13 +30,16 @@ public class ComponentAttributeResult extends ArchivableEntity { /** * Default constructor that populates the expected and actual values. * @param componentId id associated with component result + * @param deviceComponentId id associated with the device component * @param expectedValue platform certificate value * @param actualValue paccor value from the device */ public ComponentAttributeResult(final UUID componentId, + final UUID deviceComponentId, final String expectedValue, final String actualValue) { this.componentId = componentId; + this.deviceComponentId = deviceComponentId; this.expectedValue = expectedValue; this.actualValue = actualValue; } diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/info/ComponentInfo.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/info/ComponentInfo.java index 6db4f6f8..a4545ec7 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/info/ComponentInfo.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/info/ComponentInfo.java @@ -55,6 +55,8 @@ public class ComponentInfo extends ArchivableEntity { @XmlElement @Column private String componentClass; + @Column + private String componentClassStr; /** * Base constructor for children. diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/validation/CertificateAttributeScvValidator.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/validation/CertificateAttributeScvValidator.java index b296f32e..40d6542f 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/validation/CertificateAttributeScvValidator.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/validation/CertificateAttributeScvValidator.java @@ -337,6 +337,7 @@ public class CertificateAttributeScvValidator extends SupplyChainCredentialValid remainingComponentResults.add(componentResult); } } + List failedComponents = new ArrayList<>(); if (!remainingComponentResults.isEmpty()) { // continue down the options, move to a different method. // create component class mapping to component info @@ -369,23 +370,23 @@ public class CertificateAttributeScvValidator extends SupplyChainCredentialValid componentAttributeResult.setProvisionSessionId(provisionSessionId); componentAttributeRepository.save(componentAttributeResult); fieldValidation &= componentAttributeResult.checkMatchedStatus(); + if (!componentAttributeResult.checkMatchedStatus()) { + numOfAttributes++; + failedComponents.add(componentAttributeResult.getComponentId()); + } } - numOfAttributes = attributeResults.size(); } StringBuilder additionalInfo = new StringBuilder(); - if (!remainingComponentResults.isEmpty()) { - resultMessage.append(String.format("There are %d components not matched%n", - remainingComponentResults.size())); - resultMessage.append(String.format("\twith %d total attributes mismatched.", - numOfAttributes)); - } - passesValidation &= fieldValidation; if (passesValidation) { return new AppraisalStatus(PASS, PLATFORM_ATTRIBUTES_VALID); } else { + resultMessage.append(String.format("There are %d components not matched%n", + failedComponents.size())); + resultMessage.append(String.format("\twith %d total attributes mismatched.", + numOfAttributes)); return new AppraisalStatus(FAIL, resultMessage.toString(), additionalInfo.toString()); } } @@ -402,25 +403,17 @@ public class CertificateAttributeScvValidator extends SupplyChainCredentialValid final ComponentResult componentResult) { // there are instances of components with the same class (ie hard disks, memory) List attributeResults = new ArrayList<>(); - if (!componentInfo.getComponentManufacturer().equals(componentResult.getManufacturer())) { - attributeResults.add(new ComponentAttributeResult(componentResult.getId(), - componentResult.getManufacturer(), componentInfo.getComponentManufacturer())); - } + attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(), + componentResult.getManufacturer(), componentInfo.getComponentManufacturer())); - if (!componentInfo.getComponentModel().equals(componentResult.getModel())) { - attributeResults.add(new ComponentAttributeResult(componentResult.getId(), - componentResult.getModel(), componentInfo.getComponentModel())); - } + attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(), + componentResult.getModel(), componentInfo.getComponentModel())); - if (!componentInfo.getComponentSerial().equals(componentResult.getSerialNumber())) { - attributeResults.add(new ComponentAttributeResult(componentResult.getId(), - componentResult.getSerialNumber(), componentInfo.getComponentSerial())); - } + attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(), + componentResult.getSerialNumber(), componentInfo.getComponentSerial())); - if (!componentInfo.getComponentRevision().equals(componentResult.getRevisionNumber())) { - attributeResults.add(new ComponentAttributeResult(componentResult.getId(), - componentResult.getRevisionNumber(), componentInfo.getComponentRevision())); - } + attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(), + componentResult.getRevisionNumber(), componentInfo.getComponentRevision())); return attributeResults; } 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 c0b7970f..2907c416 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 @@ -7,12 +7,14 @@ import hirs.attestationca.persist.entity.manager.PlatformCertificateRepository; 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.entity.userdefined.certificate.attributes.ComponentClass; import hirs.attestationca.persist.entity.userdefined.info.ComponentInfo; 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.CertificateDetailsPageParams; +import hirs.utils.xjc.Link; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -24,6 +26,7 @@ import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -143,25 +146,52 @@ public class ComponentComparisonPageController extends PageController tempIdList = new ArrayList<>(); - attributeResults.stream().forEach((dbObject) -> { - if (!tempIdList.contains(dbObject.getComponentId())) { - tempIdList.add(dbObject.getComponentId()); + + List matchedResults = new LinkedList<>(); + List matchedDeviceComps = new LinkedList<>(); + List mismatchedResults = new LinkedList<>(); + List mismatchedDeviceComps = new LinkedList<>(); + for(ComponentAttributeResult dbObject : attributeResults) { + if (dbObject.checkMatchedStatus()) { + matchedResults.add(componentResultRepository.getReferenceById(dbObject.getComponentId())); + matchedDeviceComps.add(componentInfoRepository.getReferenceById(dbObject.getDeviceComponentId())); + } else { + mismatchedResults.add(componentResultRepository.getReferenceById(dbObject.getComponentId())); + mismatchedDeviceComps.add(componentInfoRepository.getReferenceById(dbObject.getDeviceComponentId())); } - }); - componentResults = componentResultRepository - .findByBoardSerialNumberOrderByComponentClassValueAsc( - platformCredential.getPlatformSerial()); - List componentInfos = componentInfoRepository - .findByDeviceNameOrderByComponentClassAsc(deviceName); - if (PciIds.DB.isReady()) { - componentResults = PciIds.translateResults(componentResults); - componentInfos = PciIds.translateDeviceComponentInfo(componentInfos); } - data.put("componentResults", componentResults); - data.put("componentInfos", componentInfos); - data.put("totalSize", Math.max(componentResults.size(), componentInfos.size())); +// componentResults.clear(); +// List componentInfos = componentInfoRepository +// .findByDeviceNameOrderByComponentClassAsc(deviceName); +// // find the ones that aren't matched or unmatched +// for (ComponentResult dbResult : componentResultRepository +// .findByBoardSerialNumberOrderByComponentClassValueAsc( +// platformCredential.getPlatformSerial())) { +// for (ComponentResult matched : matchedResults) { +// if (dbResult.getId().equals(matched.getId())) { +// +// } +// } +// } + if (PciIds.DB.isReady()) { +// componentResults = PciIds.translateResults(componentResults); +// componentInfos = PciIds.translateDeviceComponentInfo(componentInfos); + matchedResults = PciIds.translateResults(matchedResults); + matchedDeviceComps = PciIds.translateDeviceComponentInfo(matchedDeviceComps); + mismatchedResults = PciIds.translateResults(mismatchedResults); + mismatchedDeviceComps = PciIds.translateDeviceComponentInfo(mismatchedDeviceComps); + } + + matchedDeviceComps = translateComponentClass(matchedDeviceComps); + mismatchedDeviceComps = translateComponentClass(mismatchedDeviceComps); + + data.put("componentResults", matchedResults); + data.put("componentInfos", matchedDeviceComps); + data.put("misMatchedComponentResults", mismatchedResults); + data.put("misMatchedComponentInfos", mismatchedDeviceComps); +// data.put("notFoundResults", ); +// data.put("notFoundComponentInfs", ); } else { String notFoundMessage = "No components attribute comparison found " + "with ID: " + sessionId; @@ -169,6 +199,20 @@ public class ComponentComparisonPageController extends PageController translateComponentClass(final List componentInfos) { + List tempList = new ArrayList<>(); + ComponentInfo componentInfo; + ComponentClass componentClass; + for (ComponentInfo info : componentInfos) { + componentInfo = info; + componentClass = new ComponentClass("TCG", info.getComponentClass()); + componentInfo.setComponentClassStr(componentClass.toString()); + tempList.add(componentInfo); + } + + return tempList; + } } 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 index bff27475..8c01bb5c 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/component-comparison.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/component-comparison.jsp @@ -54,7 +54,17 @@
-
+
+ Component Class: ${componentResult.getComponentClassStr()}
+ Manufacturer: ${componentResult.getManufacturer()}
+ Model: ${componentResult.getModel()}
+ Serial Number: ${componentResult.getSerialNumber()}
+ Revision: ${componentResult.getRevisionNumber()}
+
+ + +
+ Component Class: ${componentResult.getComponentClassStr()}
Manufacturer: ${componentResult.getManufacturer()}
Model: ${componentResult.getModel()}
Serial Number: ${componentResult.getSerialNumber()}
@@ -68,7 +78,17 @@
-
+
+ Component Class: ${componentInfo.getComponentClassStr()}
+ Manufacturer: ${componentInfo.getComponentManufacturer()}
+ Model: ${componentInfo.getComponentModel()}
+ Serial Number: ${componentInfo.getComponentSerial()}
+ Revision: ${componentInfo.getComponentRevision()}
+
+ + +
+ Component Class: ${componentInfo.getComponentClassStr()}
Manufacturer: ${componentInfo.getComponentManufacturer()}
Model: ${componentInfo.getComponentModel()}
Serial Number: ${componentInfo.getComponentSerial()}