mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-03-22 12:05:59 +00:00
After discussion, the concept of a Support RIM was clarified and because of this the ReferenceManifest.java file has to be updated to treat the Support rim similarly to the Base (which is a binary file vs an XML file). This initial code push is the beginning of that
This commit is contained in:
parent
025ebc8908
commit
39cfaa5fac
@ -6,4 +6,5 @@
|
|||||||
|
|
||||||
<suppressions>
|
<suppressions>
|
||||||
<suppress checks="MagicNumber" files=".*[/\\]src[/\\]test[/\\]+" />
|
<suppress checks="MagicNumber" files=".*[/\\]src[/\\]test[/\\]+" />
|
||||||
|
<suppress checks="AvoidInlineConditionals" files=".*[/\\]src[/\\]test[/\\]+" />
|
||||||
</suppressions>
|
</suppressions>
|
||||||
|
@ -124,10 +124,24 @@ public class ReferenceManifestDetailsPageController
|
|||||||
// Software Identity
|
// Software Identity
|
||||||
data.put("swidName", rim.getSwidName());
|
data.put("swidName", rim.getSwidName());
|
||||||
data.put("swidVersion", rim.getSwidVersion());
|
data.put("swidVersion", rim.getSwidVersion());
|
||||||
data.put("swidCorpus", Boolean.toString(rim.isSwidCorpus()));
|
if (rim.isSwidCorpus() == 1) {
|
||||||
data.put("swidPatch", Boolean.toString(rim.isSwidPatch()));
|
data.put("swidCorpus", "True");
|
||||||
data.put("swidSupplemental", Boolean.toString(
|
} else {
|
||||||
rim.isSwidSupplemental()));
|
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());
|
data.put("swidTagId", rim.getTagId());
|
||||||
// Entity
|
// Entity
|
||||||
data.put("entityName", rim.getEntityName());
|
data.put("entityName", rim.getEntityName());
|
||||||
@ -137,7 +151,8 @@ public class ReferenceManifestDetailsPageController
|
|||||||
// Link
|
// Link
|
||||||
data.put("linkHref", rim.getLinkHref());
|
data.put("linkHref", rim.getLinkHref());
|
||||||
data.put("linkRel", rim.getLinkRel());
|
data.put("linkRel", rim.getLinkRel());
|
||||||
|
data.put("supportBaseRimId", "");
|
||||||
|
data.put("supportBaseRimTagId", "");
|
||||||
data.put("platformManufacturer", rim.getPlatformManufacturer());
|
data.put("platformManufacturer", rim.getPlatformManufacturer());
|
||||||
data.put("platformManufacturerId", rim.getPlatformManufacturerId());
|
data.put("platformManufacturerId", rim.getPlatformManufacturerId());
|
||||||
data.put("platformModel", rim.getPlatformModel());
|
data.put("platformModel", rim.getPlatformModel());
|
||||||
|
@ -10,6 +10,8 @@ import hirs.FilteredRecordsList;
|
|||||||
import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter;
|
import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter;
|
||||||
import hirs.attestationca.portal.page.PageMessages;
|
import hirs.attestationca.portal.page.PageMessages;
|
||||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||||
|
import hirs.data.persist.BaseReferenceManifest;
|
||||||
|
import hirs.data.persist.SupportReferenceManifest;
|
||||||
import hirs.persist.DBManagerException;
|
import hirs.persist.DBManagerException;
|
||||||
import hirs.persist.ReferenceManifestManager;
|
import hirs.persist.ReferenceManifestManager;
|
||||||
import hirs.persist.CriteriaModifier;
|
import hirs.persist.CriteriaModifier;
|
||||||
@ -22,8 +24,6 @@ import java.net.URISyntaxException;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -189,16 +189,20 @@ public class ReferenceManifestPageController
|
|||||||
final RedirectAttributes attr) throws URISyntaxException, Exception {
|
final RedirectAttributes attr) throws URISyntaxException, Exception {
|
||||||
Map<String, Object> model = new HashMap<>();
|
Map<String, Object> model = new HashMap<>();
|
||||||
PageMessages messages = new PageMessages();
|
PageMessages messages = new PageMessages();
|
||||||
List<MultipartFile> rims = new ArrayList<>();
|
|
||||||
String fileName;
|
String fileName;
|
||||||
Path filePath;
|
Path filePath;
|
||||||
|
Pattern pattern;
|
||||||
|
Matcher matcher;
|
||||||
|
boolean supportRIM = false;
|
||||||
|
|
||||||
// loop through the files
|
// loop through the files
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
fileName = file.getOriginalFilename();
|
fileName = file.getOriginalFilename();
|
||||||
Pattern pattern = Pattern.compile(LOG_FILE_PATTERN);
|
pattern = Pattern.compile(LOG_FILE_PATTERN);
|
||||||
Matcher matcher = pattern.matcher(fileName);
|
matcher = pattern.matcher(fileName);
|
||||||
if (matcher.matches()) {
|
supportRIM = matcher.matches();
|
||||||
|
|
||||||
|
if (supportRIM) {
|
||||||
filePath = Paths.get(String.format("%s/%s",
|
filePath = Paths.get(String.format("%s/%s",
|
||||||
SwidResource.RESOURCE_UPLOAD_FOLDER,
|
SwidResource.RESOURCE_UPLOAD_FOLDER,
|
||||||
file.getOriginalFilename()));
|
file.getOriginalFilename()));
|
||||||
@ -215,16 +219,10 @@ public class ReferenceManifestPageController
|
|||||||
"%s successfully uploaded", file.getOriginalFilename());
|
"%s successfully uploaded", file.getOriginalFilename());
|
||||||
messages.addSuccess(uploadCompletedMessage);
|
messages.addSuccess(uploadCompletedMessage);
|
||||||
LOGGER.info(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
|
//Parse reference manifests
|
||||||
ReferenceManifest rim = parseRIM(file, messages);
|
ReferenceManifest rim = parseRIM(file, supportRIM, messages);
|
||||||
|
|
||||||
//Store only if it was parsed
|
//Store only if it was parsed
|
||||||
if (rim != null) {
|
if (rim != null) {
|
||||||
@ -313,11 +311,16 @@ public class ReferenceManifestPageController
|
|||||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
StringBuilder fileName = new StringBuilder("filename=\"");
|
StringBuilder fileName = new StringBuilder("filename=\"");
|
||||||
fileName.append(referenceManifest.getSwidName());
|
if (referenceManifest.getRimType().equals(ReferenceManifest.BASE_RIM)) {
|
||||||
fileName.append("_[");
|
BaseReferenceManifest bRim = (BaseReferenceManifest) referenceManifest;
|
||||||
fileName.append(referenceManifest.getRimHash());
|
fileName.append(bRim.getSwidName());
|
||||||
fileName.append("]");
|
fileName.append("_[");
|
||||||
fileName.append(".swidTag\"");
|
fileName.append(referenceManifest.getRimHash());
|
||||||
|
fileName.append("]");
|
||||||
|
fileName.append(".swidTag\"");
|
||||||
|
} else {
|
||||||
|
// this needs to be updated for support rims
|
||||||
|
}
|
||||||
|
|
||||||
// Set filename for download.
|
// Set filename for download.
|
||||||
response.setHeader("Content-Disposition", "attachment;" + fileName);
|
response.setHeader("Content-Disposition", "attachment;" + fileName);
|
||||||
@ -360,7 +363,7 @@ public class ReferenceManifestPageController
|
|||||||
* @return a single or collection of reference manifest files.
|
* @return a single or collection of reference manifest files.
|
||||||
*/
|
*/
|
||||||
private ReferenceManifest parseRIM(
|
private ReferenceManifest parseRIM(
|
||||||
final MultipartFile file,
|
final MultipartFile file, final boolean supportRIM,
|
||||||
final PageMessages messages) {
|
final PageMessages messages) {
|
||||||
|
|
||||||
byte[] fileBytes;
|
byte[] fileBytes;
|
||||||
@ -378,7 +381,11 @@ public class ReferenceManifestPageController
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new ReferenceManifest(fileBytes);
|
if (supportRIM) {
|
||||||
|
return new SupportReferenceManifest(fileBytes);
|
||||||
|
} else {
|
||||||
|
return new BaseReferenceManifest(fileBytes);
|
||||||
|
}
|
||||||
// the this is a List<Object> is object is a JaxBElement that can
|
// the this is a List<Object> is object is a JaxBElement that can
|
||||||
// be matched up to the QName
|
// be matched up to the QName
|
||||||
} catch (IOException ioEx) {
|
} catch (IOException ioEx) {
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Tag ID</th>
|
<th>Tag ID</th>
|
||||||
|
<th>Type</th>
|
||||||
<th>Manufacturer</th>
|
<th>Manufacturer</th>
|
||||||
<th>Model</th>
|
<th>Model</th>
|
||||||
<th>Version</th>
|
<th>Version</th>
|
||||||
@ -44,6 +45,7 @@
|
|||||||
var url = pagePath +'/list';
|
var url = pagePath +'/list';
|
||||||
var columns = [
|
var columns = [
|
||||||
{data: 'tagId'},
|
{data: 'tagId'},
|
||||||
|
{data: 'rimType'},
|
||||||
{data: 'platformManufacturer'},
|
{data: 'platformManufacturer'},
|
||||||
{data: 'platformModel'},
|
{data: 'platformModel'},
|
||||||
{data: 'firmwareVersion'},
|
{data: 'firmwareVersion'},
|
||||||
|
@ -10,14 +10,31 @@
|
|||||||
<link type="text/css" rel="stylesheet" href="${common}/certificate_details.css"/>
|
<link type="text/css" rel="stylesheet" href="${common}/certificate_details.css"/>
|
||||||
</jsp:attribute>
|
</jsp:attribute>
|
||||||
<jsp:attribute name="pageHeaderTitle">
|
<jsp:attribute name="pageHeaderTitle">
|
||||||
Reference Integrity Manifest
|
${initialData.rimType} Reference Integrity Manifest
|
||||||
<a href="${portal}/reference-manifests/download?id=${param.id}">
|
<a href="${portal}/reference-manifests/download?id=${param.id}">
|
||||||
<img src="${icons}/ic_file_download_black_24dp.png" title="Download Certificate">
|
<img src="${icons}/ic_file_download_black_24dp.png" title="Download ${initialData.rimType} RIM">
|
||||||
</a>
|
</a>
|
||||||
</jsp:attribute>
|
</jsp:attribute>
|
||||||
<jsp:body>
|
<jsp:body>
|
||||||
|
|
||||||
<div id="certificate-details-page" class="container-fluid">
|
<div id="certificate-details-page" class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<c:if test="${initialData.swidSupplemental=='True'}">
|
||||||
|
<div class="col-md-1 col-md-offset-1"><span class="colHeader">Base RIM</span></div>
|
||||||
|
<div id="baseRim" class="col col-md-8">
|
||||||
|
<c:choose>
|
||||||
|
<c:when test="${not empty initialData.supportBaseRimTagId}">
|
||||||
|
<a href="${portal}/rim-details?id=${initialData.supportBaseRimId}">
|
||||||
|
${initialData.supportBaseRimTagId}
|
||||||
|
</a>
|
||||||
|
<!-- Event Number, Event Type, Digest (hex), Event Content -->
|
||||||
|
</c:when>
|
||||||
|
<c:otherwise>
|
||||||
|
<div class="component col col-md-10" style="color: red; padding-left: 20px">Base RIM not uploaded from the ACA RIM Page</div>
|
||||||
|
</c:otherwise>
|
||||||
|
</c:choose>
|
||||||
|
</div>
|
||||||
|
</c:if>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-1 col-md-offset-1"><span class="colHeader">Software Identity</span></div>
|
<div class="col-md-1 col-md-offset-1"><span class="colHeader">Software Identity</span></div>
|
||||||
<div id="softwareIdentity" class="col col-md-8">
|
<div id="softwareIdentity" class="col col-md-8">
|
||||||
@ -168,7 +185,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</c:if>
|
</c:if>
|
||||||
</div>
|
</div>
|
||||||
</c:when>
|
</c:when>
|
||||||
<c:otherwise>
|
<c:otherwise>
|
||||||
<div class="component col col-md-10" style="color: red; padding-left: 20px">Support RIM file named ${resource.getName()} was not imported via the Reference Integrity Manifest page.</div>
|
<div class="component col col-md-10" style="color: red; padding-left: 20px">Support RIM file named ${resource.getName()} was not imported via the Reference Integrity Manifest page.</div>
|
||||||
</c:otherwise>
|
</c:otherwise>
|
||||||
|
@ -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<SwidResource> 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<SwidResource> parseResource(final ResourceCollection rc) {
|
||||||
|
List<SwidResource> 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<QName, String> 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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,43 +1,22 @@
|
|||||||
package hirs.data.persist;
|
package hirs.data.persist;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.xml.namespace.QName;
|
|
||||||
import javax.xml.bind.JAXBElement;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import hirs.persist.DBReferenceManifestManager;
|
|
||||||
import hirs.persist.ReferenceManifestManager;
|
import hirs.persist.ReferenceManifestManager;
|
||||||
import hirs.persist.ReferenceManifestSelector;
|
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.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.xml.XMLConstants;
|
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.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import javax.xml.validation.Schema;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the Reference Integrity Manifest object that will be
|
* This class represents the Reference Integrity Manifest object that will be
|
||||||
@ -48,7 +27,9 @@ import javax.xml.validation.Schema;
|
|||||||
@XmlRootElement(name = "ReferenceManifest")
|
@XmlRootElement(name = "ReferenceManifest")
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
@Access(AccessType.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.
|
* 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";
|
public static final String SCHEMA_PACKAGE = "hirs.utils.xjc";
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(ReferenceManifest.class);
|
private static final Logger LOGGER = LogManager.getLogger(ReferenceManifest.class);
|
||||||
private static JAXBContext jaxbContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class enables the retrieval of PlatformCredentials by their
|
* 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.
|
* Holds the name of the 'rimHash' field.
|
||||||
*/
|
*/
|
||||||
@ -151,13 +84,21 @@ public class ReferenceManifest extends ArchivableEntity {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private final int rimHash;
|
private final int rimHash;
|
||||||
|
@Column(columnDefinition = "blob", nullable = false)
|
||||||
private String entityName = null;
|
@JsonIgnore
|
||||||
private String entityRegId = null;
|
private byte[] rimBytes;
|
||||||
private String entityRole = null;
|
@Column(nullable = false)
|
||||||
private String entityThumbprint = null;
|
private String rimType = "Base";
|
||||||
private String linkHref = null;
|
@Column
|
||||||
private String linkRel = null;
|
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.
|
* Get a Selector for use in retrieving ReferenceManifest.
|
||||||
@ -175,46 +116,12 @@ public class ReferenceManifest extends ArchivableEntity {
|
|||||||
*/
|
*/
|
||||||
protected ReferenceManifest() {
|
protected ReferenceManifest() {
|
||||||
super();
|
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.rimBytes = null;
|
||||||
this.rimHash = 0;
|
this.rimHash = 0;
|
||||||
this.linkHref = null;
|
this.rimType = 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ReferenceManifest(final byte[] rimBytes) {
|
||||||
* 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 {
|
|
||||||
Preconditions.checkArgument(rimBytes != null,
|
Preconditions.checkArgument(rimBytes != null,
|
||||||
"Cannot construct a RIM from a null byte array");
|
"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");
|
"Cannot construct a RIM from an empty byte array");
|
||||||
|
|
||||||
this.rimBytes = rimBytes.clone();
|
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.rimHash = Arrays.hashCode(this.rimBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method and code is pulled and adopted from the TCG Tool. Since this
|
* Getter for the file name of the data that was uploaded.
|
||||||
* is taking in an file stored in memory through http, this was changed from
|
* @return the file name
|
||||||
* 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 {
|
public String getFileName() {
|
||||||
JAXBElement jaxbe = unmarshallSwidTag(fileStream);
|
return fileName;
|
||||||
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
|
* Setter for the file name of the data that was uploaded.
|
||||||
* based on an already established and stored byte array.
|
* @param fileName file name to associate
|
||||||
*
|
|
||||||
* @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) {
|
public void setFileName(final String fileName) {
|
||||||
BaseElement baseElement = null;
|
this.fileName = fileName;
|
||||||
|
|
||||||
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<QName, String> 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<SwidResource> 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<SwidResource> parseResource(final ResourceCollection rc) {
|
|
||||||
List<SwidResource> 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -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() {
|
public String getRimType() {
|
||||||
return firmwareVersion;
|
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) {
|
public void setRimType(final String rimType) {
|
||||||
this.firmwareVersion = firmwareVersion;
|
this.rimType = rimType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -653,31 +238,17 @@ public class ReferenceManifest extends ArchivableEntity {
|
|||||||
this.tagId = tagId;
|
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.
|
* Getter for the Reference Integrity Manifest as a byte array.
|
||||||
*
|
*
|
||||||
* @return array of bytes
|
* @return array of bytes
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnore
|
||||||
public byte[] getRimBytes() {
|
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;
|
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
|
@Override
|
||||||
public String toString() {
|
public int hashCode() {
|
||||||
return String.format("ReferenceManifest{swidName=%s,"
|
return getRimHash();
|
||||||
+ "platformManufacturer=%s,"
|
|
||||||
+ " platformModel=%s,"
|
|
||||||
+ "firmwareVersion=%s, firmwareVersion=%s, rimHash=%d}",
|
|
||||||
swidName, platformManufacturer,
|
|
||||||
platformModel, firmwareVersion, tagId, rimHash);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -1075,7 +1075,7 @@ public abstract class Certificate extends ArchivableEntity {
|
|||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public byte[] getRawBytes() {
|
public byte[] getRawBytes() {
|
||||||
if (null != this.certificateBytes) {
|
if (this.certificateBytes != null) {
|
||||||
return this.certificateBytes.clone();
|
return this.certificateBytes.clone();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -28,6 +28,7 @@ public abstract class ReferenceManifestSelector<ReferenceManifest> {
|
|||||||
private static final String PLATFORM_MANUFACTURER_ID = "platformManufacturerId";
|
private static final String PLATFORM_MANUFACTURER_ID = "platformManufacturerId";
|
||||||
private static final String PLATFORM_MODEL = "platformModel";
|
private static final String PLATFORM_MODEL = "platformModel";
|
||||||
private static final String RIM_TYPE_FIELD = "rimType";
|
private static final String RIM_TYPE_FIELD = "rimType";
|
||||||
|
private static final String RIM_FILENAME_FIELD = "fileName";
|
||||||
|
|
||||||
private final ReferenceManifestManager referenceManifestManager;
|
private final ReferenceManifestManager referenceManifestManager;
|
||||||
|
|
||||||
@ -116,6 +117,16 @@ public abstract class ReferenceManifestSelector<ReferenceManifest> {
|
|||||||
return this;
|
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.
|
* Specify the RIM Type to match.
|
||||||
* @param rimType the type of rim
|
* @param rimType the type of rim
|
||||||
@ -124,7 +135,7 @@ public abstract class ReferenceManifestSelector<ReferenceManifest> {
|
|||||||
public ReferenceManifestSelector byRimType(final String rimType) {
|
public ReferenceManifestSelector byRimType(final String rimType) {
|
||||||
setFieldValue(RIM_TYPE_FIELD, rimType);
|
setFieldValue(RIM_TYPE_FIELD, rimType);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a field name and value to match.
|
* Set a field name and value to match.
|
||||||
@ -171,11 +182,11 @@ public abstract class ReferenceManifestSelector<ReferenceManifest> {
|
|||||||
* @return a matching RIM or null if none is found
|
* @return a matching RIM or null if none is found
|
||||||
*/
|
*/
|
||||||
public hirs.data.persist.ReferenceManifest getRIM() {
|
public hirs.data.persist.ReferenceManifest getRIM() {
|
||||||
Set<hirs.data.persist.ReferenceManifest> certs = execute();
|
Set<hirs.data.persist.ReferenceManifest> rims = execute();
|
||||||
if (certs.isEmpty()) {
|
if (rims.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return certs.iterator().next();
|
return rims.iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,6 +77,7 @@ public final class TCGEventLog {
|
|||||||
private boolean bEvent = false;
|
private boolean bEvent = false;
|
||||||
/** Event Output Flag use. */
|
/** Event Output Flag use. */
|
||||||
private boolean bCryptoAgile = false;
|
private boolean bCryptoAgile = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default blank object constructor.
|
* Default blank object constructor.
|
||||||
*/
|
*/
|
||||||
@ -255,6 +256,8 @@ public final class TCGEventLog {
|
|||||||
}
|
}
|
||||||
return pcrs;
|
return pcrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a flag which is set if the event log follows the "Crypto Agile" Format Type.
|
* Returns a flag which is set if the event log follows the "Crypto Agile" Format Type.
|
||||||
* A false implies the type is SHA1 format.
|
* A false implies the type is SHA1 format.
|
||||||
@ -263,6 +266,7 @@ public final class TCGEventLog {
|
|||||||
public boolean isCryptoAgile() {
|
public boolean isCryptoAgile() {
|
||||||
return bCryptoAgile;
|
return bCryptoAgile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of event found in the Event Log.
|
* Returns a list of event found in the Event Log.
|
||||||
* @return an arraylist of event.
|
* @return an arraylist of event.
|
||||||
@ -270,6 +274,7 @@ public final class TCGEventLog {
|
|||||||
public ArrayList<TpmPcrEvent> getEventList() {
|
public ArrayList<TpmPcrEvent> getEventList() {
|
||||||
return eventList;
|
return eventList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a single PCR value given an index (PCR Number).
|
* Returns a single PCR value given an index (PCR Number).
|
||||||
*
|
*
|
||||||
@ -286,7 +291,7 @@ public final class TCGEventLog {
|
|||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (TpmPcrEvent event:eventList) {
|
for (TpmPcrEvent event : eventList) {
|
||||||
sb.append(event.toString(bEvent, bHexEvent, bContent));
|
sb.append(event.toString(bEvent, bHexEvent, bContent));
|
||||||
}
|
}
|
||||||
sb.append("Event Log processing completed.\n");
|
sb.append("Event Log processing completed.\n");
|
||||||
|
@ -176,6 +176,7 @@ public class TpmPcrEvent {
|
|||||||
public String getSpecErrataVersion() {
|
public String getSpecErrataVersion() {
|
||||||
return errata;
|
return errata;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the event data after processing.
|
* Sets the event data after processing.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user