+
${componentInfo.getComponentClassStr()}
${componentInfo.getComponentManufacturer()}
${componentInfo.getComponentModel()}
From b4940d664b0b93aea6c673f91e546912e7e0d870 Mon Sep 17 00:00:00 2001
From: Cyrus <24922493+cyrus-dev@users.noreply.github.com>
Date: Thu, 21 Mar 2024 21:02:40 -0400
Subject: [PATCH 14/18] Cleaned up the errors
---
.../userdefined/info/ComponentInfo.java | 49 +++++--
.../attestationca/persist/util/PciIds.java | 7 +-
.../ComponentComparisonPageController.java | 131 ++++++++++--------
.../WEB-INF/jsp/component-comparison.jsp | 11 +-
4 files changed, 125 insertions(+), 73 deletions(-)
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 a4545ec79..c11da1831 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
@@ -60,10 +60,11 @@ public class ComponentInfo extends ArchivableEntity {
/**
* Base constructor for children.
+ *
* @param componentManufacturer Component Manufacturer (must not be null)
- * @param componentModel Component Model (must not be null)
- * @param componentSerial Component Serial Number (can be null)
- * @param componentRevision Component Revision or Version (can be null)
+ * @param componentModel Component Model (must not be null)
+ * @param componentSerial Component Serial Number (can be null)
+ * @param componentRevision Component Revision or Version (can be null)
*/
public ComponentInfo(final String componentManufacturer,
final String componentModel,
@@ -72,13 +73,15 @@ public ComponentInfo(final String componentManufacturer,
this(DeviceInfoEnums.NOT_SPECIFIED, componentManufacturer, componentModel,
componentSerial, componentRevision);
}
+
/**
* Constructor.
- * @param deviceName the host machine associated with this component. (must not be null)
+ *
+ * @param deviceName the host machine associated with this component. (must not be null)
* @param componentManufacturer Component Manufacturer (must not be null)
- * @param componentModel Component Model (must not be null)
- * @param componentSerial Component Serial Number (can be null)
- * @param componentRevision Component Revision or Version (can be null)
+ * @param componentModel Component Model (must not be null)
+ * @param componentSerial Component Serial Number (can be null)
+ * @param componentRevision Component Revision or Version (can be null)
*/
public ComponentInfo(final String deviceName,
final String componentManufacturer,
@@ -112,12 +115,13 @@ public ComponentInfo(final String deviceName,
/**
* Constructor.
- * @param deviceName the host machine associated with this component.
+ *
+ * @param deviceName the host machine associated with this component.
* @param componentManufacturer Component Manufacturer (must not be null)
- * @param componentModel Component Model (must not be null)
- * @param componentSerial Component Serial Number (can be null)
- * @param componentRevision Component Revision or Version (can be null)
- * @param componentClass Component Class (can be null)
+ * @param componentModel Component Model (must not be null)
+ * @param componentSerial Component Serial Number (can be null)
+ * @param componentRevision Component Revision or Version (can be null)
+ * @param componentClass Component Class (can be null)
*/
public ComponentInfo(final String deviceName,
final String componentManufacturer,
@@ -131,6 +135,18 @@ public ComponentInfo(final String deviceName,
this.componentClass = Objects.requireNonNullElse(componentClass, StringUtils.EMPTY);
}
+ /**
+ * Blank object to display on comparision page.
+ * @param empty nothing
+ */
+ public ComponentInfo(final String empty) {
+ this.deviceName = StringUtils.EMPTY;
+ this.componentManufacturer = StringUtils.EMPTY;
+ this.componentModel = StringUtils.EMPTY;
+ this.componentSerial = StringUtils.EMPTY;
+ this.componentRevision = StringUtils.EMPTY;
+ }
+
/**
* Determines whether the given properties represent a
* ComponentInfo that will be useful in validation.
@@ -138,9 +154,9 @@ public ComponentInfo(final String deviceName,
* manufacturer and model are considered valid.
*
* @param componentManufacturer a String containing a component's manufacturer
- * @param componentModel a String representing a component's model
- * @param componentSerial a String representing a component's serial number
- * @param componentRevision a String representing a component's revision
+ * @param componentModel a String representing a component's model
+ * @param componentSerial a String representing a component's serial number
+ * @param componentRevision a String representing a component's revision
* @return true if the component is valid, false if not
*/
public static boolean isComplete(final String componentManufacturer,
@@ -153,6 +169,7 @@ public static boolean isComplete(final String componentManufacturer,
/**
* Equals for the component info that just uses this classes attributes.
+ *
* @param object the object to compare
* @return the boolean result
*/
@@ -173,6 +190,7 @@ public boolean equals(Object object) {
/**
* Returns a hash code that is associated with common fields for components.
+ *
* @return int value of the elements
*/
public int hashCommonElements() {
@@ -182,6 +200,7 @@ public int hashCommonElements() {
/**
* Hash method for the attributes of this class.
+ *
* @return int value that represents this class
*/
@Override
diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/util/PciIds.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/util/PciIds.java
index 1efeb3775..aaec23691 100644
--- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/util/PciIds.java
+++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/util/PciIds.java
@@ -146,7 +146,12 @@ public static List translateDeviceComponentInfo(final List newList = new ArrayList<>();
if (componentInfos != null && !componentInfos.isEmpty()) {
for (final ComponentInfo componentInfo : componentInfos) {
- newList.add(translateDeviceComponentInfo(componentInfo));
+ if (!componentInfo.getDeviceName().isEmpty()) {
+ newList.add(translateDeviceComponentInfo(componentInfo));
+ } else {
+ // if the object is all StringUtils.empty()
+ newList.add(componentInfo);
+ }
}
}
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 0ae642b4a..aa8cb0aaf 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
@@ -40,6 +40,7 @@ public class ComponentComparisonPageController extends PageController getPlatformComponentInformation(
@@ -131,7 +132,7 @@ public static HashMap getPlatformComponentInformation(
data.put("deviceName", deviceName);
if (!attributeResults.isEmpty()) {
ComponentResult componentResult = componentResultRepository.findById(attributeResults.get(0).getComponentId()).get();
- platformCredential = platformCertificateRepository
+ platformCredential = platformCertificateRepository
.findByPlatformSerialAndSerialNumber(componentResult.getBoardSerialNumber(),
BigInteger.valueOf(Long.parseLong(
componentResult.getCertificateSerialNumber())));
@@ -147,39 +148,75 @@ public static HashMap getPlatformComponentInformation(
+ componentResults.get(0).getBoardSerialNumber());
return data;
}
+ // get all db objects
+ componentResults = componentResultRepository
+ .findByBoardSerialNumberOrderByComponentClassValueAsc(
+ platformCredential.getPlatformSerial());
List componentInfos = componentInfoRepository
.findByDeviceNameOrderByComponentClassAsc(deviceName);
- Map componentInfoHashMap = findMatchedComponents(componentResults, componentInfos);
- List matchedResults = new LinkedList<>(componentInfoHashMap.keySet());
- List matchedDeviceComps = new LinkedList<>(componentInfoHashMap.values());
+ // first get what we know, the attribute results have the platform component
+ // and device component that are mismatched
List mismatchedResults = new LinkedList<>();
List mismatchedDeviceComps = new LinkedList<>();
- for(ComponentAttributeResult dbObject : attributeResults) {
- mismatchedResults.add(componentResultRepository.getReferenceById(dbObject.getComponentId()));
- mismatchedDeviceComps.add(componentInfoRepository.getReferenceById(dbObject.getDeviceComponentId()));
+ // quick list to hold what we've found so we don't look for the ID again.
+ List tempIds = new ArrayList<>();
+ for (ComponentAttributeResult car : attributeResults) {
+ if (!tempIds.contains(car.getComponentId())) {
+ mismatchedResults.add(componentResultRepository
+ .getReferenceById(car.getComponentId()));
+ tempIds.add(car.getComponentId());
+ }
+ if (!tempIds.contains(car.getDeviceComponentId())) {
+ mismatchedDeviceComps.add(componentInfoRepository
+ .getReferenceById(car.getDeviceComponentId()));
+ tempIds.add(car.getDeviceComponentId());
+ }
+ }
+
+ // we got the provisioned mismatches, so all that is left are matched
+ Map deviceComponentHashMap = new HashMap<>();
+ for (ComponentInfo componentInfo : componentInfos) {
+ // skip the ones we know
+ if (!tempIds.contains(componentInfo.getId())) {
+ deviceComponentHashMap.put(componentInfo.hashCommonElements(), componentInfo);
+ }
+ }
+ // do the same for componentResults
+ Map platformComponentHashMap = new HashMap<>();
+ for (ComponentResult result : componentResults) {
+ // skip the ones we know
+ if (!tempIds.contains(result.getId())) {
+ platformComponentHashMap.put(result.hashCommonElements(), result);
+ }
+ }
+ // find platform component match
+ Map mappedComponents = new HashMap<>();
+ for (Integer key : platformComponentHashMap.keySet()) {
+ if (deviceComponentHashMap.containsKey(key)) {
+ mappedComponents.put(platformComponentHashMap.get(key),
+ deviceComponentHashMap.get(key));
+ deviceComponentHashMap.remove(key);
+ } else {
+ // it doesn't exist, put null
+ mappedComponents.put(platformComponentHashMap.get(key), new ComponentInfo(""));
+ }
}
-// 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())) {
-//
-// }
-// }
-// }
+ List matchedResults = new LinkedList<>(mappedComponents.keySet());
+ List matchedDeviceComps = new LinkedList<>(mappedComponents.values());
+ List notFoundDevices = null;
+ if (!deviceComponentHashMap.values().isEmpty()) {
+ notFoundDevices = new ArrayList<>(deviceComponentHashMap.values());
+ }
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);
+ if (notFoundDevices != null) {
+ notFoundDevices = PciIds.translateDeviceComponentInfo(notFoundDevices);
+ }
}
matchedDeviceComps = translateComponentClass(matchedDeviceComps);
@@ -189,8 +226,11 @@ public static HashMap getPlatformComponentInformation(
data.put("componentInfos", matchedDeviceComps);
data.put("misMatchedComponentResults", mismatchedResults);
data.put("misMatchedComponentInfos", mismatchedDeviceComps);
-// data.put("notFoundResults", );
-// data.put("notFoundComponentInfs", );
+
+ if (notFoundDevices != null) {
+ data.put("notFoundDeviceComponents", translateComponentClass(notFoundDevices));
+ }
+
} else {
String notFoundMessage = "No components attribute comparison found "
+ "with ID: " + sessionId;
@@ -204,38 +244,17 @@ private static List translateComponentClass(final List findMatchedComponents(
- final List componentResults, final List componentInfos) {
- // first create hash map based on hashCode
- Map resultComponentInfoMap = new HashMap<>();
- Map deviceHashMap = new HashMap<>();
- componentInfos.stream().forEach((componentInfo) -> {
- deviceHashMap.put(componentInfo.hashCommonElements(), componentInfo);
- });
-
- // Look for hash code in device mapping
- // if it exists, don't save the component
- List remainingComponentResults = new ArrayList<>();
- int numOfAttributes = 0;
- for (ComponentResult componentResult : componentResults) {
- if (!deviceHashMap.containsKey(componentResult.hashCommonElements())) {
- // didn't find the component result in the hashed mapping
- remainingComponentResults.add(componentResult);
+ if (!info.getDeviceName().isEmpty()) {
+ componentInfo = info;
+ componentClass = new ComponentClass("TCG", info.getComponentClass());
+ componentInfo.setComponentClassStr(componentClass.toString());
+ tempList.add(componentInfo);
} else {
- resultComponentInfoMap.put(componentResult, deviceHashMap.get(componentResult.hashCommonElements()));
+ tempList.add(info);
}
}
- return resultComponentInfoMap;
+ 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 6a2f6c826..a8fb09f8f 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
@@ -62,7 +62,7 @@
${componentResult.getRevisionNumber()}
-
+
${componentResult.getComponentClassStr()}
${componentResult.getManufacturer()}
@@ -95,6 +95,15 @@
${componentInfo.getComponentRevision()}
+
+
+ ${componentInfo.getComponentClassStr()}
+ ${componentInfo.getComponentManufacturer()}
+ ${componentInfo.getComponentModel()}
+ ${componentInfo.getComponentSerial()}
+ ${componentInfo.getComponentRevision()}
+
+