diff --git a/HIRS_AttestationCAPortal/config/checkstyle/suppressions.xml b/HIRS_AttestationCAPortal/config/checkstyle/suppressions.xml index ec0b37b0..4e02338a 100644 --- a/HIRS_AttestationCAPortal/config/checkstyle/suppressions.xml +++ b/HIRS_AttestationCAPortal/config/checkstyle/suppressions.xml @@ -6,4 +6,5 @@ + diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java index 1637a3e4..32dea87b 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java @@ -124,10 +124,24 @@ public class ReferenceManifestDetailsPageController // Software Identity data.put("swidName", rim.getSwidName()); data.put("swidVersion", rim.getSwidVersion()); - data.put("swidCorpus", Boolean.toString(rim.isSwidCorpus())); - data.put("swidPatch", Boolean.toString(rim.isSwidPatch())); - data.put("swidSupplemental", Boolean.toString( - rim.isSwidSupplemental())); + if (rim.isSwidCorpus() == 1) { + data.put("swidCorpus", "True"); + } else { + data.put("swidCorpus", "False"); + } + if (rim.isSwidPatch() == 1) { + data.put("swidPatch", "True"); + } else { + data.put("swidPatch", "False"); + } + if (rim.isSwidSupplemental() == 1) { + data.put("swidSupplemental", "True"); + } else { + data.put("swidSupplemental", "False"); + } +// data.put("swidCorpus", (rim.isSwidCorpus() == 1) ? "True" : "False"); +// data.put("swidPatch", (rim.isSwidPatch() == 1) ? "True" : "False"); +// data.put("swidSupplemental", (rim.isSwidSupplemental() == 1) ? "True" : "False"); data.put("swidTagId", rim.getTagId()); // Entity data.put("entityName", rim.getEntityName()); @@ -137,7 +151,8 @@ public class ReferenceManifestDetailsPageController // Link data.put("linkHref", rim.getLinkHref()); data.put("linkRel", rim.getLinkRel()); - + data.put("supportBaseRimId", ""); + data.put("supportBaseRimTagId", ""); data.put("platformManufacturer", rim.getPlatformManufacturer()); data.put("platformManufacturerId", rim.getPlatformManufacturerId()); data.put("platformModel", rim.getPlatformModel()); 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 df8acdf1..c320f9e4 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 @@ -10,6 +10,8 @@ import hirs.FilteredRecordsList; import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter; import hirs.attestationca.portal.page.PageMessages; import hirs.attestationca.portal.page.params.NoPageParams; +import hirs.data.persist.BaseReferenceManifest; +import hirs.data.persist.SupportReferenceManifest; import hirs.persist.DBManagerException; import hirs.persist.ReferenceManifestManager; import hirs.persist.CriteriaModifier; @@ -22,8 +24,6 @@ import java.net.URISyntaxException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.List; -import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -189,16 +189,20 @@ public class ReferenceManifestPageController final RedirectAttributes attr) throws URISyntaxException, Exception { Map model = new HashMap<>(); PageMessages messages = new PageMessages(); - List rims = new ArrayList<>(); String fileName; Path filePath; + Pattern pattern; + Matcher matcher; + boolean supportRIM = false; // loop through the files for (MultipartFile file : files) { fileName = file.getOriginalFilename(); - Pattern pattern = Pattern.compile(LOG_FILE_PATTERN); - Matcher matcher = pattern.matcher(fileName); - if (matcher.matches()) { + pattern = Pattern.compile(LOG_FILE_PATTERN); + matcher = pattern.matcher(fileName); + supportRIM = matcher.matches(); + + if (supportRIM) { filePath = Paths.get(String.format("%s/%s", SwidResource.RESOURCE_UPLOAD_FOLDER, file.getOriginalFilename())); @@ -215,16 +219,10 @@ public class ReferenceManifestPageController "%s successfully uploaded", file.getOriginalFilename()); messages.addSuccess(uploadCompletedMessage); LOGGER.info(uploadCompletedMessage); - } else { - // assume it is a swid tag, processing below will throw and error - // if it is not. - rims.add(file); } - } - for (MultipartFile file : rims) { //Parse reference manifests - ReferenceManifest rim = parseRIM(file, messages); + ReferenceManifest rim = parseRIM(file, supportRIM, messages); //Store only if it was parsed if (rim != null) { @@ -313,11 +311,16 @@ public class ReferenceManifestPageController response.sendError(HttpServletResponse.SC_NOT_FOUND); } else { StringBuilder fileName = new StringBuilder("filename=\""); - fileName.append(referenceManifest.getSwidName()); - fileName.append("_["); - fileName.append(referenceManifest.getRimHash()); - fileName.append("]"); - fileName.append(".swidTag\""); + if (referenceManifest.getRimType().equals(ReferenceManifest.BASE_RIM)) { + BaseReferenceManifest bRim = (BaseReferenceManifest) referenceManifest; + fileName.append(bRim.getSwidName()); + fileName.append("_["); + fileName.append(referenceManifest.getRimHash()); + fileName.append("]"); + fileName.append(".swidTag\""); + } else { + // this needs to be updated for support rims + } // Set filename for download. response.setHeader("Content-Disposition", "attachment;" + fileName); @@ -360,7 +363,7 @@ public class ReferenceManifestPageController * @return a single or collection of reference manifest files. */ private ReferenceManifest parseRIM( - final MultipartFile file, + final MultipartFile file, final boolean supportRIM, final PageMessages messages) { byte[] fileBytes; @@ -378,7 +381,11 @@ public class ReferenceManifestPageController } try { - return new ReferenceManifest(fileBytes); + if (supportRIM) { + return new SupportReferenceManifest(fileBytes); + } else { + return new BaseReferenceManifest(fileBytes); + } // the this is a List is object is a JaxBElement that can // be matched up to the QName } catch (IOException ioEx) { 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 d99a1a91..b4d5cda5 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 @@ -30,6 +30,7 @@ Tag ID + Type Manufacturer Model Version @@ -44,6 +45,7 @@ var url = pagePath +'/list'; var columns = [ {data: 'tagId'}, + {data: 'rimType'}, {data: 'platformManufacturer'}, {data: 'platformModel'}, {data: 'firmwareVersion'}, diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/rim-details.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/rim-details.jsp index 05090a0f..7cba9213 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/rim-details.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/rim-details.jsp @@ -10,14 +10,31 @@ - Reference Integrity Manifest + ${initialData.rimType} Reference Integrity Manifest - + -
+
+ +
Base RIM
+
+ + + + ${initialData.supportBaseRimTagId} + + + + +
Base RIM not uploaded from the ACA RIM Page
+
+
+
+
+
Software Identity
@@ -168,7 +185,7 @@
- +
Support RIM file named ${resource.getName()} was not imported via the Reference Integrity Manifest page.
diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/BaseReferenceManifest.java b/HIRS_Utils/src/main/java/hirs/data/persist/BaseReferenceManifest.java new file mode 100644 index 00000000..c0d34018 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/data/persist/BaseReferenceManifest.java @@ -0,0 +1,776 @@ +package hirs.data.persist; + +import hirs.persist.DBReferenceManifestManager; +import hirs.utils.xjc.BaseElement; +import hirs.utils.xjc.Directory; +import hirs.utils.xjc.FilesystemItem; +import hirs.utils.xjc.Meta; +import hirs.utils.xjc.ResourceCollection; +import hirs.utils.xjc.SoftwareIdentity; +import hirs.utils.xjc.SoftwareMeta; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.persistence.Column; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.UnmarshalException; +import javax.xml.bind.Unmarshaller; +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class BaseReferenceManifest extends ReferenceManifest { + private static final Logger LOGGER = LogManager.getLogger(BaseReferenceManifest.class); + + private static JAXBContext jaxbContext; + + @Column + private String swidName = null; + @Column + private String swidVersion = null; + @Column(nullable = false) + private int swidCorpus = 0; + @Column(nullable = false) + private int swidPatch = 0; + @Column(nullable = false) + private int swidSupplemental = 0; + @Column + private String firmwareVersion = null; + @Column + private String colloquialVersion = null; + @Column + private String product = null; + @Column + private String revision = null; + @Column + private String edition = null; + @Column + private String rimLinkHash = null; + @Column + private String bindingSpec = null; + @Column + private String bindingSpecVersion = null; + @Column + private String platformVersion = null; + @Column + private String payloadType = null; + @Column + private String pcURIGlobal = null; + @Column + private String pcURILocal = null; + + private String entityName = null; + private String entityRegId = null; + private String entityRole = null; + private String entityThumbprint = null; + private String linkHref = null; + private String linkRel = null; + + /** + * + * @param fileName + * @param rimBytes + * @throws IOException + */ + public BaseReferenceManifest(final String fileName, final byte[] rimBytes) throws IOException { + this(rimBytes); + this.setFileName(fileName); + } + + /** + * Main constructor for the RIM object. This takes in a byte array of a + * valid swidtag file and parses the information. + * + * @param rimBytes byte array representation of the RIM + * @throws IOException if unable to unmarshal the string + */ + @SuppressWarnings("checkstyle:AvoidInlineConditionals") + public BaseReferenceManifest(final byte[] rimBytes) throws IOException { + super(rimBytes); + this.setRimType(BASE_RIM); + SoftwareIdentity si = validateSwidTag(new ByteArrayInputStream(rimBytes)); + + // begin parsing valid swid tag + if (si != null) { + setTagId(si.getTagId()); + this.swidName = si.getName(); + this.swidCorpus = si.isCorpus() ? 1 : 0; + this.swidPatch = si.isPatch() ? 1 : 0; + this.swidSupplemental = si.isSupplemental() ? 1 : 0; + this.swidVersion = si.getVersion(); + + for (Object object : si.getEntityOrEvidenceOrLink()) { + if (object instanceof JAXBElement) { + JAXBElement element = (JAXBElement) object; + String elementName = element.getName().getLocalPart(); + switch (elementName) { + case "Meta": + parseSoftwareMeta((SoftwareMeta) element.getValue()); + break; + case "Entity": + hirs.utils.xjc.Entity entity + = (hirs.utils.xjc.Entity) element.getValue(); + if (entity != null) { + this.entityName = entity.getName(); + this.entityRegId = entity.getRegid(); + StringBuilder sb = new StringBuilder(); + for (String role : entity.getRole()) { + sb.append(String.format("%s%n", role)); + } + this.entityRole = sb.toString(); + this.entityThumbprint = entity.getThumbprint(); + } + break; + case "Link": + hirs.utils.xjc.Link link + = (hirs.utils.xjc.Link) element.getValue(); + if (link != null) { + this.linkHref = link.getHref(); + this.linkRel = link.getRel(); + } + break; + case "Payload": + parseResource((ResourceCollection) element.getValue()); + break; + case "Signature": + // left blank for a followup issue enhancement + default: + } + } + } + } + } + + /** + * Default constructor necessary for Hibernate. + */ + protected BaseReferenceManifest() { + + } + + /** + * This method and code is pulled and adopted from the TCG Tool. Since this + * is taking in an file stored in memory through http, this was changed from + * a file to a stream as the input. + * + * @param fileStream stream of the swidtag file. + * @return a {@link SoftwareIdentity} object + * @throws IOException Thrown by the unmarhsallSwidTag method. + */ + private SoftwareIdentity validateSwidTag(final InputStream fileStream) throws IOException { + JAXBElement jaxbe = unmarshallSwidTag(fileStream); + SoftwareIdentity swidTag = (SoftwareIdentity) jaxbe.getValue(); + + LOGGER.info(String.format("SWID Tag found: %nname: %s;%ntagId: %s%n%s", + swidTag.getName(), swidTag.getTagId(), SCHEMA_STATEMENT)); + return swidTag; + } + + /** + * Helper method that is used to parse a specific element of the SwidTag + * based on an already established and stored byte array. + * + * @param elementName string of an xml tag in the file. + * @return the object value of the element, if it exists + */ + private BaseElement getBaseElementFromBytes(final String elementName) { + BaseElement baseElement = null; + + if (getRimBytes() != null && elementName != null) { + try { + SoftwareIdentity si = validateSwidTag(new ByteArrayInputStream(getRimBytes())); + JAXBElement element; + for (Object object : si.getEntityOrEvidenceOrLink()) { + if (object instanceof JAXBElement) { + element = (JAXBElement) object; + if (element.getName().getLocalPart().equals(elementName)) { + // found the element + baseElement = (BaseElement) element.getValue(); + } + } + } + + } catch (IOException ioEx) { + LOGGER.error("Failed to parse Swid Tag bytes.", ioEx); + } + } + + return baseElement; + } + + /** + * Default method for parsing the payload element. + * + * @return a collection of payload objects. + */ + public final List parseResource() { + return parseResource((ResourceCollection) this.getBaseElementFromBytes("Payload")); + } + + /** + * This method parses the payload method of a {@link ResourceCollection}. + * + * @param rc Resource Collection object. + * @return a collection of payload objects. + */ + public final List parseResource(final ResourceCollection rc) { + List resources = new ArrayList<>(); + + try { + if (rc != null) { + for (Meta meta : rc.getDirectoryOrFileOrProcess()) { + if (meta != null) { + if (meta instanceof Directory) { + Directory directory = (Directory) meta; + for (FilesystemItem fsi : directory.getDirectoryOrFile()) { + if (fsi != null) { + resources.add(new SwidResource( + (hirs.utils.xjc.File) fsi, null)); + } + } + } else if (meta instanceof hirs.utils.xjc.File) { + resources.add(new SwidResource((hirs.utils.xjc.File) meta, null)); + } + } + } + } + } catch (ClassCastException ccEx) { + LOGGER.error(ccEx); + LOGGER.error("At this time, the code does not support the " + + "particular formatting of this SwidTag's Payload."); + } + + return resources; + } + + /** + * This method unmarshalls the swidtag found at [path] and validates it + * according to the schema. + * + * @param stream to the input swidtag + * @return the SoftwareIdentity element at the root of the swidtag + * @throws IOException if the swidtag cannot be unmarshalled or validated + */ + private JAXBElement unmarshallSwidTag(final InputStream stream) throws IOException { + JAXBElement jaxbe = null; + Schema schema; + + try { + schema = DBReferenceManifestManager.getSchemaObject(); + if (jaxbContext == null) { + jaxbContext = JAXBContext.newInstance(SCHEMA_PACKAGE); + } + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + unmarshaller.setSchema(schema); + jaxbe = (JAXBElement) unmarshaller.unmarshal(stream); + } catch (UnmarshalException umEx) { + LOGGER.error(String.format("Error validating swidtag file!%n%s%n%s", + umEx.getMessage(), umEx.toString())); + for (StackTraceElement ste : umEx.getStackTrace()) { + LOGGER.error(ste.toString()); + } + } catch (IllegalArgumentException iaEx) { + LOGGER.error("Input file empty."); + } catch (JAXBException jaxEx) { + for (StackTraceElement ste : jaxEx.getStackTrace()) { + LOGGER.error(ste.toString()); + } + } + + if (jaxbe != null) { + return jaxbe; + } else { + throw new IOException("Invalid Base RIM, swidtag format expected."); + } + } + + /** + * This is a helper method that parses the SoftwareMeta tag and stores the + * information in the class fields. + * + * @param softwareMeta The object to parse. + */ + private void parseSoftwareMeta(final SoftwareMeta softwareMeta) { + if (softwareMeta != null) { + for (Map.Entry entry + : softwareMeta.getOtherAttributes().entrySet()) { + switch (entry.getKey().getLocalPart()) { + case "colloquialVersion": + this.colloquialVersion = entry.getValue(); + break; + case "product": + this.product = entry.getValue(); + break; + case "revision": + this.revision = entry.getValue(); + break; + case "edition": + this.edition = entry.getValue(); + break; + case "rimLinkHash": + this.rimLinkHash = entry.getValue(); + break; + case "bindingSpec": + this.bindingSpec = entry.getValue(); + break; + case "bindingSpecVersion": + this.bindingSpecVersion = entry.getValue(); + break; + case "platformManufacturerId": + this.setPlatformManufacturerId(entry.getValue()); + break; + case "platformModel": + this.setPlatformModel(entry.getValue()); + break; + case "platformManufacturerStr": + this.setPlatformManufacturer(entry.getValue()); + break; + case "platformVersion": + this.platformVersion = entry.getValue(); + break; + case "payloadType": + this.payloadType = entry.getValue(); + break; + case "pcURIGlobal": + this.pcURIGlobal = entry.getValue(); + break; + case "pcURILocal": + this.pcURILocal = entry.getValue(); + break; + default: + } + } + } + } + + /** + * Getter for the SWID name parameter. + * + * @return string representation of the SWID name + */ + public String getSwidName() { + return swidName; + } + + /** + * Setter for the SWID name parameter. + * + * @param swidName string of the name + */ + public void setSwidName(final String swidName) { + this.swidName = swidName; + } + + /** + * Getter for the SWID version. + * + * @return string of the version number + */ + public String getSwidVersion() { + return swidVersion; + } + + /** + * Setter for the SWID version. + * + * @param swidVersion string of the version + */ + public void setSwidVersion(final String swidVersion) { + this.swidVersion = swidVersion; + } + + /** + * Getter for the corpus flag. + * + * @return int flag for corpus + */ + public int isSwidCorpus() { + return swidCorpus; + } + + /** + * Setter for the corpus flag. + * + * @param swidCorpus int value + */ + public void setSwidCorpus(final int swidCorpus) { + this.swidCorpus = swidCorpus; + } + + /** + * Getter for the patch flag. + * + * @return int flag for the patch flag + */ + public int isSwidPatch() { + return swidPatch; + } + + /** + * Setter for the patch flag. + * + * @param swidPatch int value + */ + public void setSwidPatch(final int swidPatch) { + this.swidPatch = swidPatch; + } + + /** + * Getter for the supplemental flag. + * + * @return int flag for the supplemental flag + */ + public int isSwidSupplemental() { + return swidSupplemental; + } + + /** + * Setter for the supplemental flag. + * + * @param swidSupplemental int value + */ + public void setSwidSupplemental(final int swidSupplemental) { + this.swidSupplemental = swidSupplemental; + } + + /** + * Getter for the firmware version info. + * + * @return string for the firmware version + */ + public String getFirmwareVersion() { + return firmwareVersion; + } + + /** + * Setter for the firmware version info. + * + * @param firmwareVersion passed in firmware version + */ + public void setFirmwareVersion(final String firmwareVersion) { + this.firmwareVersion = firmwareVersion; + } + + /** + * Getter for the Entity Name. + * + * @return string of the entity name. + */ + public String getEntityName() { + return entityName; + } + + /** + * Setter for the Entity Name. + * + * @param entityName string of the entity name. + */ + public void setEntityName(final String entityName) { + this.entityName = entityName; + } + + /** + * Getter for the Entity Reg ID. + * + * @return string of the entity reg id. + */ + public String getEntityRegId() { + return entityRegId; + } + + /** + * Setter for the Entity Reg ID. + * + * @param entityRegId string of the entity reg id. + */ + public void setEntityRegId(final String entityRegId) { + this.entityRegId = entityRegId; + } + + /** + * Getter for the Entity Role. + * + * @return string of the entity role. + */ + public String getEntityRole() { + return entityRole; + } + + /** + * Setter for the Entity Role. + * + * @param entityRole string of the entity role . + */ + public void setEntityRole(final String entityRole) { + this.entityRole = entityRole; + } + + /** + * Getter for the Entity thumbprint. + * + * @return string of the entity thumbprint. + */ + public String getEntityThumbprint() { + return entityThumbprint; + } + + /** + * Setter for the Entity Thumbprint. + * + * @param entityThumbprint string of the entity thumbprint. + */ + public void setEntityThumbprint(final String entityThumbprint) { + this.entityThumbprint = entityThumbprint; + } + + /** + * Getter for the Link Href. + * + * @return string of the link href. + */ + public String getLinkHref() { + return linkHref; + } + + /** + * Setter for the Link href. + * + * @param linkHref in string representation. + */ + public void setLinkHref(final String linkHref) { + this.linkHref = linkHref; + } + + /** + * Getter for the Link Rel. + * + * @return string of the link rel + */ + public String getLinkRel() { + return linkRel; + } + + /** + * Setter for the Link Rel. + * + * @param linkRel in string representation. + */ + public void setLinkRel(final String linkRel) { + this.linkRel = linkRel; + } + + /** + * Getter for Colloquial Version. + * + * @return string of the colloquial version. + */ + public String getColloquialVersion() { + return colloquialVersion; + } + + /** + * Setter for Colloquial Version. + * + * @param colloquialVersion in string representation. + */ + public void setColloquialVersion(final String colloquialVersion) { + this.colloquialVersion = colloquialVersion; + } + + /** + * Getter for Product. + * + * @return string of the product information + */ + public String getProduct() { + return product; + } + + /** + * Setter for the Product. + * + * @param product in string representation. + */ + public void setProduct(final String product) { + this.product = product; + } + + /** + * Getter for the Revision string. + * + * @return string of revision information. + */ + public String getRevision() { + return revision; + } + + /** + * Setter for the Revision. + * + * @param revision in string representation. + */ + public void setRevision(final String revision) { + this.revision = revision; + } + + /** + * Getter for the Edition. + * + * @return string of edition information. + */ + public String getEdition() { + return edition; + } + + /** + * Setter for the Edition string. + * + * @param edition in string representation. + */ + public void setEdition(final String edition) { + this.edition = edition; + } + + /** + * Getter for the RIM Link Hash. + * + * @return string of the RIM link hash. + */ + public String getRimLinkHash() { + return rimLinkHash; + } + + /** + * Setter for the RIM link hash. + * + * @param rimLinkHash in string representation. + */ + public void setRimLinkHash(final String rimLinkHash) { + this.rimLinkHash = rimLinkHash; + } + + /** + * Getter for the Binding Spec. + * + * @return string of Binding spec. + */ + public String getBindingSpec() { + return bindingSpec; + } + + /** + * Setter for the Binding Spec. + * + * @param bindingSpec in string representation. + */ + public void setBindingSpec(final String bindingSpec) { + this.bindingSpec = bindingSpec; + } + + /** + * Getter for the Binding Spec Version. + * + * @return string of binding spec version. + */ + public String getBindingSpecVersion() { + return bindingSpecVersion; + } + + /** + * Setter for the binding spec version. + * + * @param bindingSpecVersion in string representation. + */ + public void setBindingSpecVersion(final String bindingSpecVersion) { + this.bindingSpecVersion = bindingSpecVersion; + } + + /** + * Getter for the Platform Version. + * + * @return string of platform version. + */ + public String getPlatformVersion() { + return platformVersion; + } + + /** + * Setter for the Platform Version. + * + * @param platformVersion in string representation. + */ + public void setPlatformVersion(final String platformVersion) { + this.platformVersion = platformVersion; + } + + /** + * Getter for the Payload Type. + * + * @return string of payload type. + */ + public String getPayloadType() { + return payloadType; + } + + /** + * Setter for the Payload type. + * + * @param payloadType in string representation. + */ + public void setPayloadType(final String payloadType) { + this.payloadType = payloadType; + } + + /** + * Getter for the PC URI Global. + * + * @return string of Pc URI Global. + */ + public String getPcURIGlobal() { + return pcURIGlobal; + } + + /** + * Setter for the PC URI Global. + * + * @param pcURIGlobal in string representation. + */ + public void setPcURIGlobal(final String pcURIGlobal) { + this.pcURIGlobal = pcURIGlobal; + } + + /** + * Getter for the PC URI Local. + * + * @return string of PC URI Local. + */ + public String getPcURILocal() { + return pcURILocal; + } + + /** + * Setter for the PC URI Local. + * + * @param pcURILocal in string representation. + */ + public void setPcURILocal(final String pcURILocal) { + this.pcURILocal = pcURILocal; + } + + @Override + public String toString() { + return String.format("ReferenceManifest{swidName=%s," + + "platformManufacturer=%s," + + " platformModel=%s," + + "firmwareVersion=%s, firmwareVersion=%s, rimHash=%d}", + swidName, this.getPlatformManufacturer(), + this.getPlatformModel(), firmwareVersion, getTagId(), this.getRimHash()); + } +} diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/ReferenceManifest.java b/HIRS_Utils/src/main/java/hirs/data/persist/ReferenceManifest.java index e2bdeecb..b4cc61e2 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/ReferenceManifest.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/ReferenceManifest.java @@ -1,43 +1,22 @@ package hirs.data.persist; -import java.io.ByteArrayInputStream; -import java.io.IOException; import java.util.Arrays; -import java.util.Map; -import java.util.List; -import java.util.ArrayList; import javax.persistence.Access; import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.Entity; -import javax.xml.namespace.QName; -import javax.xml.bind.JAXBElement; import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.common.base.Preconditions; -import hirs.persist.DBReferenceManifestManager; import hirs.persist.ReferenceManifestManager; import hirs.persist.ReferenceManifestSelector; -import hirs.utils.xjc.BaseElement; -import hirs.utils.xjc.ResourceCollection; -import hirs.utils.xjc.SoftwareIdentity; -import hirs.utils.xjc.SoftwareMeta; -import hirs.utils.xjc.Meta; -import hirs.utils.xjc.Directory; -import hirs.utils.xjc.FilesystemItem; -import java.io.InputStream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.persistence.Table; import javax.xml.XMLConstants; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.UnmarshalException; -import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.validation.Schema; /** * This class represents the Reference Integrity Manifest object that will be @@ -48,7 +27,9 @@ import javax.xml.validation.Schema; @XmlRootElement(name = "ReferenceManifest") @XmlAccessorType(XmlAccessType.FIELD) @Access(AccessType.FIELD) -public class ReferenceManifest extends ArchivableEntity { +public abstract class ReferenceManifest extends ArchivableEntity { + public static final String BASE_RIM = "Base"; + public static final String SUPPORT_RIM = "Support"; /** * String for the xml schema ios standard. @@ -69,7 +50,6 @@ public class ReferenceManifest extends ArchivableEntity { public static final String SCHEMA_PACKAGE = "hirs.utils.xjc"; private static final Logger LOGGER = LogManager.getLogger(ReferenceManifest.class); - private static JAXBContext jaxbContext; /** * This class enables the retrieval of PlatformCredentials by their @@ -97,53 +77,6 @@ public class ReferenceManifest extends ArchivableEntity { */ } - @Column - private String swidName = null; - @Column - private String swidVersion = null; - @Column - private boolean swidCorpus = false; - @Column - private boolean swidPatch = false; - @Column - private boolean swidSupplemental = false; - @Column - private String platformManufacturer = null; - @Column - private String platformManufacturerId = null; - @Column - private String platformModel = null; - @Column - private String firmwareVersion = null; - @Column - private String tagId = null; - @Column - private String rimType = null; - @Column - private String colloquialVersion = null; - @Column - private String product = null; - @Column - private String revision = null; - @Column - private String edition = null; - @Column - private String rimLinkHash = null; - @Column - private String bindingSpec = null; - @Column - private String bindingSpecVersion = null; - @Column - private String platformVersion = null; - @Column - private String payloadType = null; - @Column - private String pcURIGlobal = null; - @Column - private String pcURILocal = null; - @Column(columnDefinition = "blob", nullable = false) - @JsonIgnore - private byte[] rimBytes; /** * Holds the name of the 'rimHash' field. */ @@ -151,13 +84,21 @@ public class ReferenceManifest extends ArchivableEntity { @Column(nullable = false) @JsonIgnore private final int rimHash; - - private String entityName = null; - private String entityRegId = null; - private String entityRole = null; - private String entityThumbprint = null; - private String linkHref = null; - private String linkRel = null; + @Column(columnDefinition = "blob", nullable = false) + @JsonIgnore + private byte[] rimBytes; + @Column(nullable = false) + private String rimType = "Base"; + @Column + private String tagId = null; + @Column + private String platformManufacturer = null; + @Column + private String platformManufacturerId = null; + @Column + private String platformModel = null; + @Column(nullable = false) + private String fileName = null; /** * Get a Selector for use in retrieving ReferenceManifest. @@ -175,46 +116,12 @@ public class ReferenceManifest extends ArchivableEntity { */ protected ReferenceManifest() { super(); - this.swidName = null; - this.swidVersion = null; - this.swidVersion = null; - this.swidCorpus = false; - this.swidPatch = false; - this.swidSupplemental = false; - this.platformManufacturer = null; - this.platformManufacturerId = null; - this.platformModel = null; - this.firmwareVersion = null; - this.tagId = null; this.rimBytes = null; this.rimHash = 0; - this.linkHref = null; - this.linkRel = null; - this.entityName = null; - this.entityRegId = null; - this.entityRole = null; - this.entityThumbprint = null; - this.colloquialVersion = null; - this.product = null; - this.revision = null; - this.edition = null; - this.rimLinkHash = null; - this.bindingSpec = null; - this.bindingSpecVersion = null; - this.platformVersion = null; - this.payloadType = null; - this.pcURIGlobal = null; - this.pcURILocal = null; + this.rimType = null; } - /** - * Main constructor for the RIM object. This takes in a byte array of a - * valid swidtag file and parses the information. - * - * @param rimBytes byte array representation of the RIM - * @throws IOException if unable to unmarshal the string - */ - public ReferenceManifest(final byte[] rimBytes) throws IOException { + public ReferenceManifest(final byte[] rimBytes) { Preconditions.checkArgument(rimBytes != null, "Cannot construct a RIM from a null byte array"); @@ -222,345 +129,23 @@ public class ReferenceManifest extends ArchivableEntity { "Cannot construct a RIM from an empty byte array"); this.rimBytes = rimBytes.clone(); - - SoftwareIdentity si = validateSwidTag(new ByteArrayInputStream(rimBytes)); - - // begin parsing valid swid tag - if (si != null) { - this.tagId = si.getTagId(); - this.swidName = si.getName(); - this.swidCorpus = si.isCorpus(); - this.swidPatch = si.isPatch(); - this.swidSupplemental = si.isSupplemental(); - this.swidVersion = si.getVersion(); - - for (Object object : si.getEntityOrEvidenceOrLink()) { - if (object instanceof JAXBElement) { - JAXBElement element = (JAXBElement) object; - String elementName = element.getName().getLocalPart(); - switch (elementName) { - case "Meta": - parseSoftwareMeta((SoftwareMeta) element.getValue()); - break; - case "Entity": - hirs.utils.xjc.Entity entity - = (hirs.utils.xjc.Entity) element.getValue(); - if (entity != null) { - this.entityName = entity.getName(); - this.entityRegId = entity.getRegid(); - StringBuilder sb = new StringBuilder(); - for (String role : entity.getRole()) { - sb.append(String.format("%s%n", role)); - } - this.entityRole = sb.toString(); - this.entityThumbprint = entity.getThumbprint(); - } - break; - case "Link": - hirs.utils.xjc.Link link - = (hirs.utils.xjc.Link) element.getValue(); - if (link != null) { - this.linkHref = link.getHref(); - this.linkRel = link.getRel(); - } - break; - case "Payload": - parseResource((ResourceCollection) element.getValue()); - break; - case "Signature": - // left blank for a followup issue enhancement - default: - } - } - } - } - this.rimHash = Arrays.hashCode(this.rimBytes); } /** - * This method and code is pulled and adopted from the TCG Tool. Since this - * is taking in an file stored in memory through http, this was changed from - * a file to a stream as the input. - * - * @param fileStream stream of the swidtag file. - * @return a {@link SoftwareIdentity} object - * @throws IOException Thrown by the unmarhsallSwidTag method. + * Getter for the file name of the data that was uploaded. + * @return the file name */ - private SoftwareIdentity validateSwidTag(final InputStream fileStream) throws IOException { - JAXBElement jaxbe = unmarshallSwidTag(fileStream); - SoftwareIdentity swidTag = (SoftwareIdentity) jaxbe.getValue(); - - LOGGER.info(String.format("SWID Tag found: %nname: %s;%ntagId: %s%n%s", - swidTag.getName(), swidTag.getTagId(), SCHEMA_STATEMENT)); - return swidTag; + public String getFileName() { + return fileName; } /** - * Helper method that is used to parse a specific element of the SwidTag - * based on an already established and stored byte array. - * - * @param elementName string of an xml tag in the file. - * @return the object value of the element, if it exists + * Setter for the file name of the data that was uploaded. + * @param fileName file name to associate */ - private BaseElement getBaseElementFromBytes(final String elementName) { - BaseElement baseElement = null; - - if (rimBytes != null && elementName != null) { - try { - SoftwareIdentity si = validateSwidTag(new ByteArrayInputStream(this.rimBytes)); - JAXBElement element; - for (Object object : si.getEntityOrEvidenceOrLink()) { - if (object instanceof JAXBElement) { - element = (JAXBElement) object; - if (element.getName().getLocalPart().equals(elementName)) { - // found the element - baseElement = (BaseElement) element.getValue(); - } - } - } - - } catch (IOException ioEx) { - LOGGER.error("Failed to parse Swid Tag bytes.", ioEx); - } - } - - return baseElement; - } - - /** - * This is a helper method that parses the SoftwareMeta tag and stores the - * information in the class fields. - * - * @param softwareMeta The object to parse. - */ - private void parseSoftwareMeta(final SoftwareMeta softwareMeta) { - if (softwareMeta != null) { - for (Map.Entry entry - : softwareMeta.getOtherAttributes().entrySet()) { - switch (entry.getKey().getLocalPart()) { - case "colloquialVersion": - this.colloquialVersion = entry.getValue(); - break; - case "product": - this.product = entry.getValue(); - break; - case "revision": - this.revision = entry.getValue(); - break; - case "edition": - this.edition = entry.getValue(); - break; - case "rimLinkHash": - this.rimLinkHash = entry.getValue(); - break; - case "bindingSpec": - this.bindingSpec = entry.getValue(); - break; - case "bindingSpecVersion": - this.bindingSpecVersion = entry.getValue(); - break; - case "platformManufacturerId": - this.platformManufacturerId = entry.getValue(); - break; - case "platformModel": - this.platformModel = entry.getValue(); - break; - case "platformManufacturerStr": - this.platformManufacturer = entry.getValue(); - break; - case "platformVersion": - this.platformVersion = entry.getValue(); - break; - case "payloadType": - this.payloadType = entry.getValue(); - break; - case "pcURIGlobal": - this.pcURIGlobal = entry.getValue(); - break; - case "pcURILocal": - this.pcURILocal = entry.getValue(); - break; - default: - } - } - } - } - - /** - * Default method for parsing the payload element. - * - * @return a collection of payload objects. - */ - public final List parseResource() { - return parseResource((ResourceCollection) this.getBaseElementFromBytes("Payload")); - } - - /** - * This method parses the payload method of a {@link ResourceCollection}. - * - * @param rc Resource Collection object. - * @return a collection of payload objects. - */ - public final List parseResource(final ResourceCollection rc) { - List resources = new ArrayList<>(); - - try { - if (rc != null) { - for (Meta meta : rc.getDirectoryOrFileOrProcess()) { - if (meta != null) { - if (meta instanceof Directory) { - Directory directory = (Directory) meta; - for (FilesystemItem fsi : directory.getDirectoryOrFile()) { - if (fsi != null) { - resources.add(new SwidResource( - (hirs.utils.xjc.File) fsi, null)); - } - } - } else if (meta instanceof hirs.utils.xjc.File) { - resources.add(new SwidResource((hirs.utils.xjc.File) meta, null)); - } - } - } - } - } catch (ClassCastException ccEx) { - LOGGER.error(ccEx); - LOGGER.error("At this time, the code does not support the " - + "particular formatting of this SwidTag's Payload."); - } - - return resources; - } - - /** - * This method unmarshalls the swidtag found at [path] and validates it - * according to the schema. - * - * @param stream to the input swidtag - * @return the SoftwareIdentity element at the root of the swidtag - * @throws IOException if the swidtag cannot be unmarshalled or validated - */ - private JAXBElement unmarshallSwidTag(final InputStream stream) throws IOException { - JAXBElement jaxbe = null; - Schema schema; - - try { - schema = DBReferenceManifestManager.getSchemaObject(); - if (jaxbContext == null) { - jaxbContext = JAXBContext.newInstance(SCHEMA_PACKAGE); - } - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - unmarshaller.setSchema(schema); - jaxbe = (JAXBElement) unmarshaller.unmarshal(stream); - } catch (UnmarshalException umEx) { - LOGGER.error(String.format("Error validating swidtag file!%n%s%n%s", - umEx.getMessage(), umEx.toString())); - for (StackTraceElement ste : umEx.getStackTrace()) { - LOGGER.error(ste.toString()); - } - } catch (IllegalArgumentException iaEx) { - LOGGER.error("Input file empty."); - } catch (JAXBException jaxEx) { - for (StackTraceElement ste : jaxEx.getStackTrace()) { - LOGGER.error(ste.toString()); - } - } - - if (jaxbe != null) { - return jaxbe; - } else { - throw new IOException("Invalid Base RIM, swidtag format expected."); - } - } - - /** - * Getter for the SWID name parameter. - * - * @return string representation of the SWID name - */ - public String getSwidName() { - return swidName; - } - - /** - * Setter for the SWID name parameter. - * - * @param swidName string of the name - */ - public void setSwidName(final String swidName) { - this.swidName = swidName; - } - - /** - * Getter for the SWID version. - * - * @return string of the version number - */ - public String getSwidVersion() { - return swidVersion; - } - - /** - * Setter for the SWID version. - * - * @param swidVersion string of the version - */ - public void setSwidVersion(final String swidVersion) { - this.swidVersion = swidVersion; - } - - /** - * Getter for the corpus flag. - * - * @return boolean flag for corpus - */ - public boolean isSwidCorpus() { - return swidCorpus; - } - - /** - * Setter for the corpus flag. - * - * @param swidCorpus boolean value - */ - public void setSwidCorpus(final boolean swidCorpus) { - this.swidCorpus = swidCorpus; - } - - /** - * Getter for the patch flag. - * - * @return boolean flag for the patch flag - */ - public boolean isSwidPatch() { - return swidPatch; - } - - /** - * Setter for the patch flag. - * - * @param swidPatch boolean value - */ - public void setSwidPatch(final boolean swidPatch) { - this.swidPatch = swidPatch; - } - - /** - * Getter for the supplemental flag. - * - * @return boolean flag for the supplemental flag - */ - public boolean isSwidSupplemental() { - return swidSupplemental; - } - - /** - * Setter for the supplemental flag. - * - * @param swidSupplemental boolean value - */ - public void setSwidSupplemental(final boolean swidSupplemental) { - this.swidSupplemental = swidSupplemental; + public void setFileName(final String fileName) { + this.fileName = fileName; } /** @@ -618,21 +203,21 @@ public class ReferenceManifest extends ArchivableEntity { } /** - * Getter for the firmware version info. + * Getter for the RIM Type (Primary, Supplemental, Patch). * - * @return string for the firmware version + * @return string for the RIM Type */ - public String getFirmwareVersion() { - return firmwareVersion; + public String getRimType() { + return rimType; } /** - * Setter for the firmware version info. + * Setter for the RIM Type. * - * @param firmwareVersion passed in firmware version + * @param rimType passed in RIM Type */ - public void setFirmwareVersion(final String firmwareVersion) { - this.firmwareVersion = firmwareVersion; + public void setRimType(final String rimType) { + this.rimType = rimType; } /** @@ -653,31 +238,17 @@ public class ReferenceManifest extends ArchivableEntity { this.tagId = tagId; } - /** - * Getter for the RIM Type (Primary, Supplemental, Patch). - * - * @return string for the RIM Type - */ - public String getRimType() { - return rimType; - } - - /** - * Setter for the RIM Type. - * - * @param timType passed in RIM Type - */ - public void setRimType(final String timType) { - this.rimType = timType; - } - /** * Getter for the Reference Integrity Manifest as a byte array. * * @return array of bytes */ + @JsonIgnore public byte[] getRimBytes() { - return rimBytes.clone(); + if (this.rimBytes != null) { + return this.rimBytes.clone(); + } + return null; } /** @@ -689,319 +260,8 @@ public class ReferenceManifest extends ArchivableEntity { return rimHash; } - /** - * Getter for the Entity Name. - * - * @return string of the entity name. - */ - public String getEntityName() { - return entityName; - } - - /** - * Setter for the Entity Name. - * - * @param entityName string of the entity name. - */ - public void setEntityName(final String entityName) { - this.entityName = entityName; - } - - /** - * Getter for the Entity Reg ID. - * - * @return string of the entity reg id. - */ - public String getEntityRegId() { - return entityRegId; - } - - /** - * Setter for the Entity Reg ID. - * - * @param entityRegId string of the entity reg id. - */ - public void setEntityRegId(final String entityRegId) { - this.entityRegId = entityRegId; - } - - /** - * Getter for the Entity Role. - * - * @return string of the entity role. - */ - public String getEntityRole() { - return entityRole; - } - - /** - * Setter for the Entity Role. - * - * @param entityRole string of the entity role . - */ - public void setEntityRole(final String entityRole) { - this.entityRole = entityRole; - } - - /** - * Getter for the Entity thumbprint. - * - * @return string of the entity thumbprint. - */ - public String getEntityThumbprint() { - return entityThumbprint; - } - - /** - * Setter for the Entity Thumbprint. - * - * @param entityThumbprint string of the entity thumbprint. - */ - public void setEntityThumbprint(final String entityThumbprint) { - this.entityThumbprint = entityThumbprint; - } - - /** - * Getter for the Link Href. - * - * @return string of the link href. - */ - public String getLinkHref() { - return linkHref; - } - - /** - * Setter for the Link href. - * - * @param linkHref in string representation. - */ - public void setLinkHref(final String linkHref) { - this.linkHref = linkHref; - } - - /** - * Getter for the Link Rel. - * - * @return string of the link rel - */ - public String getLinkRel() { - return linkRel; - } - - /** - * Setter for the Link Rel. - * - * @param linkRel in string representation. - */ - public void setLinkRel(final String linkRel) { - this.linkRel = linkRel; - } - - /** - * Getter for Colloquial Version. - * - * @return string of the colloquial version. - */ - public String getColloquialVersion() { - return colloquialVersion; - } - - /** - * Setter for Colloquial Version. - * - * @param colloquialVersion in string representation. - */ - public void setColloquialVersion(final String colloquialVersion) { - this.colloquialVersion = colloquialVersion; - } - - /** - * Getter for Product. - * - * @return string of the product information - */ - public String getProduct() { - return product; - } - - /** - * Setter for the Product. - * - * @param product in string representation. - */ - public void setProduct(final String product) { - this.product = product; - } - - /** - * Getter for the Revision string. - * - * @return string of revision information. - */ - public String getRevision() { - return revision; - } - - /** - * Setter for the Revision. - * - * @param revision in string representation. - */ - public void setRevision(final String revision) { - this.revision = revision; - } - - /** - * Getter for the Edition. - * - * @return string of edition information. - */ - public String getEdition() { - return edition; - } - - /** - * Setter for the Edition string. - * - * @param edition in string representation. - */ - public void setEdition(final String edition) { - this.edition = edition; - } - - /** - * Getter for the RIM Link Hash. - * - * @return string of the RIM link hash. - */ - public String getRimLinkHash() { - return rimLinkHash; - } - - /** - * Setter for the RIM link hash. - * - * @param rimLinkHash in string representation. - */ - public void setRimLinkHash(final String rimLinkHash) { - this.rimLinkHash = rimLinkHash; - } - - /** - * Getter for the Binding Spec. - * - * @return string of Binding spec. - */ - public String getBindingSpec() { - return bindingSpec; - } - - /** - * Setter for the Binding Spec. - * - * @param bindingSpec in string representation. - */ - public void setBindingSpec(final String bindingSpec) { - this.bindingSpec = bindingSpec; - } - - /** - * Getter for the Binding Spec Version. - * - * @return string of binding spec version. - */ - public String getBindingSpecVersion() { - return bindingSpecVersion; - } - - /** - * Setter for the binding spec version. - * - * @param bindingSpecVersion in string representation. - */ - public void setBindingSpecVersion(final String bindingSpecVersion) { - this.bindingSpecVersion = bindingSpecVersion; - } - - /** - * Getter for the Platform Version. - * - * @return string of platform version. - */ - public String getPlatformVersion() { - return platformVersion; - } - - /** - * Setter for the Platform Version. - * - * @param platformVersion in string representation. - */ - public void setPlatformVersion(final String platformVersion) { - this.platformVersion = platformVersion; - } - - /** - * Getter for the Payload Type. - * - * @return string of payload type. - */ - public String getPayloadType() { - return payloadType; - } - - /** - * Setter for the Payload type. - * - * @param payloadType in string representation. - */ - public void setPayloadType(final String payloadType) { - this.payloadType = payloadType; - } - - /** - * Getter for the PC URI Global. - * - * @return string of Pc URI Global. - */ - public String getPcURIGlobal() { - return pcURIGlobal; - } - - /** - * Setter for the PC URI Global. - * - * @param pcURIGlobal in string representation. - */ - public void setPcURIGlobal(final String pcURIGlobal) { - this.pcURIGlobal = pcURIGlobal; - } - - /** - * Getter for the PC URI Local. - * - * @return string of PC URI Local. - */ - public String getPcURILocal() { - return pcURILocal; - } - - /** - * Setter for the PC URI Local. - * - * @param pcURILocal in string representation. - */ - public void setPcURILocal(final String pcURILocal) { - this.pcURILocal = pcURILocal; - } - @Override - public String toString() { - return String.format("ReferenceManifest{swidName=%s," - + "platformManufacturer=%s," - + " platformModel=%s," - + "firmwareVersion=%s, firmwareVersion=%s, rimHash=%d}", - swidName, platformManufacturer, - platformModel, firmwareVersion, tagId, rimHash); + public int hashCode() { + return getRimHash(); } } diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/SupportReferenceManifest.java b/HIRS_Utils/src/main/java/hirs/data/persist/SupportReferenceManifest.java new file mode 100644 index 00000000..03ee6d9b --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/data/persist/SupportReferenceManifest.java @@ -0,0 +1,46 @@ +package hirs.data.persist; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.persistence.Column; +import java.io.IOException; + +/** + * Sub class that will just focus on PCR Values and Events + */ +public class SupportReferenceManifest extends ReferenceManifest { + private static final Logger LOGGER = LogManager.getLogger(SupportReferenceManifest.class); + + @Column(nullable = false) + @JsonIgnore + private int pcrHash; + + /** + * Main constructor for the RIM object. This takes in a byte array of a + * valid swidtag file and parses the information. + * + * @param rimBytes byte array representation of the RIM + * @throws IOException if unable to unmarshal the string + */ + public SupportReferenceManifest(final byte[] rimBytes) throws IOException { + super(rimBytes); + this.setRimType(SUPPORT_RIM); + } + + /** + * Default constructor necessary for Hibernate. + */ + protected SupportReferenceManifest() { + + } + + public int getPcrHash() { + return pcrHash; + } + + public void setPcrHash(final int pcrHash) { + this.pcrHash = pcrHash; + } +} diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/certificate/Certificate.java b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/Certificate.java index a0d3487a..d483cbec 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/certificate/Certificate.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/Certificate.java @@ -1075,7 +1075,7 @@ public abstract class Certificate extends ArchivableEntity { */ @JsonIgnore public byte[] getRawBytes() { - if (null != this.certificateBytes) { + if (this.certificateBytes != null) { return this.certificateBytes.clone(); } return null; diff --git a/HIRS_Utils/src/main/java/hirs/persist/ReferenceManifestSelector.java b/HIRS_Utils/src/main/java/hirs/persist/ReferenceManifestSelector.java index 951f8cc2..f6c260e8 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/ReferenceManifestSelector.java +++ b/HIRS_Utils/src/main/java/hirs/persist/ReferenceManifestSelector.java @@ -28,6 +28,7 @@ public abstract class ReferenceManifestSelector { private static final String PLATFORM_MANUFACTURER_ID = "platformManufacturerId"; private static final String PLATFORM_MODEL = "platformModel"; private static final String RIM_TYPE_FIELD = "rimType"; + private static final String RIM_FILENAME_FIELD = "fileName"; private final ReferenceManifestManager referenceManifestManager; @@ -116,6 +117,16 @@ public abstract class ReferenceManifestSelector { return this; } + /** + * Specif the file name of the object to grab. + * @param fileName the name of the file associated with the rim + * @return + */ + public ReferenceManifestSelector byFileName(final int fileName) { + setFieldValue(RIM_FILENAME_FIELD, fileName); + return this; + } + /** * Specify the RIM Type to match. * @param rimType the type of rim @@ -124,7 +135,7 @@ public abstract class ReferenceManifestSelector { public ReferenceManifestSelector byRimType(final String rimType) { setFieldValue(RIM_TYPE_FIELD, rimType); return this; - } + } /** * Set a field name and value to match. @@ -171,11 +182,11 @@ public abstract class ReferenceManifestSelector { * @return a matching RIM or null if none is found */ public hirs.data.persist.ReferenceManifest getRIM() { - Set certs = execute(); - if (certs.isEmpty()) { + Set rims = execute(); + if (rims.isEmpty()) { return null; } - return certs.iterator().next(); + return rims.iterator().next(); } /** diff --git a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TCGEventLog.java b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TCGEventLog.java index a3c960df..b849c9e3 100644 --- a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TCGEventLog.java +++ b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TCGEventLog.java @@ -77,6 +77,7 @@ public final class TCGEventLog { private boolean bEvent = false; /** Event Output Flag use. */ private boolean bCryptoAgile = false; + /** * Default blank object constructor. */ @@ -255,6 +256,8 @@ public final class TCGEventLog { } return pcrs; } + + /** * Returns a flag which is set if the event log follows the "Crypto Agile" Format Type. * A false implies the type is SHA1 format. @@ -263,6 +266,7 @@ public final class TCGEventLog { public boolean isCryptoAgile() { return bCryptoAgile; } + /** * Returns a list of event found in the Event Log. * @return an arraylist of event. @@ -270,6 +274,7 @@ public final class TCGEventLog { public ArrayList getEventList() { return eventList; } + /** * Returns a single PCR value given an index (PCR Number). * @@ -286,7 +291,7 @@ public final class TCGEventLog { */ public String toString() { StringBuilder sb = new StringBuilder(); - for (TpmPcrEvent event:eventList) { + for (TpmPcrEvent event : eventList) { sb.append(event.toString(bEvent, bHexEvent, bContent)); } sb.append("Event Log processing completed.\n"); diff --git a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TpmPcrEvent.java b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TpmPcrEvent.java index 2d124105..f9252e1a 100644 --- a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TpmPcrEvent.java +++ b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TpmPcrEvent.java @@ -176,6 +176,7 @@ public class TpmPcrEvent { public String getSpecErrataVersion() { return errata; } + /** * Sets the event data after processing. *