From acc022d7845c119840976af7d8f71d3680ccb421 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Wed, 20 Jan 2021 13:05:43 -0500 Subject: [PATCH] Finalized clean up. --- .../SupplyChainCredentialValidator.java | 71 +++++++++++++------ 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/HIRS_Utils/src/main/java/hirs/validation/SupplyChainCredentialValidator.java b/HIRS_Utils/src/main/java/hirs/validation/SupplyChainCredentialValidator.java index 96cdb323..ad2b2f4c 100644 --- a/HIRS_Utils/src/main/java/hirs/validation/SupplyChainCredentialValidator.java +++ b/HIRS_Utils/src/main/java/hirs/validation/SupplyChainCredentialValidator.java @@ -589,6 +589,7 @@ public final class SupplyChainCredentialValidator implements CredentialValidator final List origPcComponents) { boolean fieldValidation = true; StringBuilder resultMessage = new StringBuilder(); + String tempStringMessage = ""; List validOrigPcComponents = origPcComponents.stream() .filter(identifier -> identifier.getComponentManufacturer() != null && identifier.getComponentModel() != null) @@ -618,46 +619,72 @@ public final class SupplyChainCredentialValidator implements CredentialValidator resultMessage.append("There are errors with Delta " + "Component Statuses:\n"); List leftOverDeltas = new ArrayList<>(); - resultMessage.append(validateDeltaChain(deltaMapping, baseCompList, - leftOverDeltas, chainCertificates)); + List absentSerialNum = new ArrayList<>(); + tempStringMessage = validateDeltaChain(deltaMapping, baseCompList, + leftOverDeltas, absentSerialNum, chainCertificates); + + // check if there were any issues + if (!tempStringMessage.isEmpty()) { + resultMessage.append(tempStringMessage); + fieldValidation = false; + } // finished up List certificateList = null; SupplyChainValidation scv = null; - // go through the leaf and check the changes against the valid components - // forget modifying validOrigPcComponents - - // what wasn't handled by the serial number, - // not match by the serial number and the class type - // then the matching manufacturer and model - + // Ok, we went through valid non-empty serial values + // now do the rest, if there are more deltas and if there are any + // non-empty serial values for (ComponentIdentifier deltaCi : leftOverDeltas) { String classValue; ComponentIdentifierV2 ciV2 = (ComponentIdentifierV2) deltaCi; ComponentIdentifierV2 baseCiV2; boolean classFound; - for (ComponentIdentifier ci : baseCompList) { + for (ComponentIdentifier ci : absentSerialNum) { classValue = ciV2.getComponentClass().getClassValueString(); baseCiV2 = (ComponentIdentifierV2) ci; classFound = classValue.equals(baseCiV2.getComponentClass() .getClassValueString()); if (classFound) { if (isMatch(ciV2, baseCiV2)) { - LOGGER.error("Not Found and added"); + if (ciV2.isAdded()) { + // error + resultMessage.append("ADDED attempted with prior instance\n"); + } + if (ciV2.isModified()) { + // since the base list doesn't have this ci + // just add the delta + baseCompList.add(deltaCi); + } + // if it is a remove + // we do nothing because baseCompList doesn't have it } else { - LOGGER.error("Not Found and added"); + // it is an add + if (ciV2.isAdded()) { + baseCompList.add(deltaCi); + } } } else { // delta change to a class not there // is it an add? if (ciV2.isAdded()) { - LOGGER.error("Not Found and added"); + baseCompList.add(deltaCi); + } + + if (ciV2.isModified()) { + // error because you can't modify something + // that isn't here + resultMessage.append("MODIFIED attempted without prior instance\n"); + } + + if (ciV2.isRemoved()) { + // error because you can't remove something + // that isn't here + resultMessage.append("REMOVED attempted without prior instance\n"); } } } - // this needs to be removed. - baseCompList.add(deltaCi); } if (!fieldValidation) { @@ -705,13 +732,6 @@ public final class SupplyChainCredentialValidator implements CredentialValidator List subCompInfoList = allDeviceInfoComponents .stream().collect(Collectors.toList()); - subCompIdList.stream().forEach((ci) -> { - LOGGER.error(ci.toString()); - }); - - subCompInfoList.stream().forEach((ci) -> { - LOGGER.error(ci.toString()); - }); // Delta is the baseline for (ComponentInfo cInfo : allDeviceInfoComponents) { for (ComponentIdentifier cId : fullDeltaChainComponents) { @@ -1379,6 +1399,7 @@ public final class SupplyChainCredentialValidator implements CredentialValidator final Map deltaMapping, final List baseCompList, final List leftOvers, + final List absentSerials, final List chainCertificates) { StringBuilder resultMessage = new StringBuilder(); List noneSerialValues = new ArrayList<>(); @@ -1390,7 +1411,11 @@ public final class SupplyChainCredentialValidator implements CredentialValidator // map the components throughout the chain Map chainCiMapping = new HashMap<>(); baseCompList.stream().forEach((ci) -> { - chainCiMapping.put(ci.getComponentSerial().toString(), ci); + if (!noneSerialValues.contains(ci.getComponentSerial().toString())) { + chainCiMapping.put(ci.getComponentSerial().toString(), ci); + } else { + absentSerials.add(ci); + } }); String ciSerial;