This should finish off the code changes for issues #280.

This commit is contained in:
Cyrus 2020-09-25 08:57:12 -04:00
parent 3636782987
commit 778380f70c
4 changed files with 101 additions and 52 deletions

View File

@ -4,21 +4,21 @@ import hirs.data.persist.BaseReferenceManifest;
import hirs.data.persist.ReferenceManifest;
import hirs.data.persist.SupportReferenceManifest;
import hirs.data.persist.SwidResource;
import hirs.persist.DBManagerException;
import hirs.persist.ReferenceManifestManager;
import hirs.tpm.eventlog.TCGEventLog;
import hirs.attestationca.portal.page.Page;
import hirs.attestationca.portal.page.PageController;
import hirs.attestationca.portal.page.PageMessages;
import hirs.attestationca.portal.page.params.ReferenceManifestDetailsPageParams;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
@ -57,13 +57,13 @@ public class ReferenceManifestDetailsPageController
* Returns the filePath for the view and the data model for the page.
*
* @param params The object to map url parameters into.
* @param model The data model for the request. Can contain data from
* redirect.
* @param model The data model for the request. Can contain data from
* redirect.
* @return the path for the view and data model for the page.
*/
@Override
public ModelAndView initPage(final ReferenceManifestDetailsPageParams params,
final Model model) {
final Model model) {
// get the basic information to render the page
ModelAndView mav = getBaseModelAndView();
PageMessages messages = new PageMessages();
@ -106,16 +106,16 @@ public class ReferenceManifestDetailsPageController
* This method takes the place of an entire class for a string builder.
* Gathers all information and returns it for displays.
*
* @param uuid database reference for the requested RIM.
* @param uuid database reference for the requested RIM.
* @param referenceManifestManager the reference manifest manager.
* @return mapping of the RIM information from the database.
* @throws java.io.IOException error for reading file bytes.
* @throws java.io.IOException error for reading file bytes.
* @throws NoSuchAlgorithmException If an unknown Algorithm is encountered.
* @throws CertificateException if a certificate doesn't parse.
* @throws CertificateException if a certificate doesn't parse.
*/
public static HashMap<String, Object> getRimDetailInfo(final UUID uuid,
final ReferenceManifestManager referenceManifestManager) throws IOException,
CertificateException, NoSuchAlgorithmException {
final ReferenceManifestManager referenceManifestManager) throws IOException,
CertificateException, NoSuchAlgorithmException {
HashMap<String, Object> data = new HashMap<>();
ReferenceManifest rim = ReferenceManifest
@ -169,7 +169,6 @@ public class ReferenceManifestDetailsPageController
data.put("pcUriLocal", bRim.getPcURILocal());
data.put("rimLinkHash", bRim.getRimLinkHash());
data.put("rimType", bRim.getRimType());
data.put("associatedRim", bRim.getAssociatedRim());
List<SwidResource> resources = bRim.parseResource();
String resourceFilename = null;
@ -177,45 +176,49 @@ public class ReferenceManifestDetailsPageController
// going to have to pull the filename and grab that from the DB
// to get the id to make the link
try {
for (SwidResource swidRes : resources) {
resourceFilename = swidRes.getName();
ReferenceManifest dbRim = ReferenceManifest.select(
referenceManifestManager).byFileName(resourceFilename).getRIM();
for (SwidResource swidRes : resources) {
resourceFilename = swidRes.getName();
ReferenceManifest dbRim = ReferenceManifest.select(
referenceManifestManager).byFileName(resourceFilename).getRIM();
if (dbRim != null) {
logProcessor = new TCGEventLog(dbRim.getRimBytes());
swidRes.setPcrValues(Arrays.asList(
logProcessor.getExpectedPCRValues()));
if (dbRim != null) {
logProcessor = new TCGEventLog(dbRim.getRimBytes());
swidRes.setPcrValues(Arrays.asList(
logProcessor.getExpectedPCRValues()));
if (bRim.getAssociatedRim() == null) {
bRim.setAssociatedRim(dbRim.getId());
}
} else {
swidRes.setPcrValues(new ArrayList<>());
if (bRim.getAssociatedRim() == null) {
bRim.setAssociatedRim(dbRim.getId());
}
} else {
swidRes.setPcrValues(new ArrayList<>());
}
} catch (NoSuchFileException nsfEx) {
LOGGER.error(String.format("File Not found!: %s",
resourceFilename));
LOGGER.error(nsfEx);
} catch (DBManagerException dbmEx) {
LOGGER.error(dbmEx);
}
data.put("associatedRim", bRim.getAssociatedRim());
data.put("swidFiles", resources);
} else if (rim instanceof SupportReferenceManifest) {
SupportReferenceManifest sRim = (SupportReferenceManifest) rim;
data.put("baseRim", sRim.getFileName());
if (sRim.getAssociatedRim() == null) {
Set<ReferenceManifest> rims = ReferenceManifest
.select(referenceManifestManager).getRIMs();
for (ReferenceManifest dbRim : rims) {
if (dbRim instanceof BaseReferenceManifest
&& dbRim.getTagId().equals(sRim.getTagId())) {
sRim.setAssociatedRim(dbRim.getId());
break;
}
}
}
data.put("baseRim", sRim.getTagId());
data.put("associatedRim", sRim.getAssociatedRim());
data.put("rimType", sRim.getRimType());
TCGEventLog logProcessor = new TCGEventLog(sRim.getRimBytes());
data.put("events", logProcessor.getEventList());
} else {
LOGGER.error(String.format("Unable to find Reference Integrity "
+ "Manifest with ID: %s", uuid));
LOGGER.error(String.format("Unable to find Reference Integrity "
+ "Manifest with ID: %s", uuid));
}
return data;

View File

@ -28,7 +28,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.nio.file.Path;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletResponse;
@ -189,7 +188,6 @@ public class ReferenceManifestPageController
Map<String, Object> model = new HashMap<>();
PageMessages messages = new PageMessages();
String fileName;
Path filePath;
Pattern pattern;
Matcher matcher;
boolean supportRIM = false;
@ -208,26 +206,24 @@ public class ReferenceManifestPageController
.select(referenceManifestManager).getRIMs();
// update information for associated support rims
if (supportRIM) {
for (ReferenceManifest element : rims) {
for (ReferenceManifest element : rims) {
if (supportRIM) {
if (element instanceof BaseReferenceManifest) {
BaseReferenceManifest bRim = (BaseReferenceManifest) element;
for (SwidResource swid : bRim.parseResource()) {
if (swid.getName().equals(rim.getFileName())) {
rim.setFirmwareVersion(swid.getSize());
rim.setPlatformManufacturer(element.getPlatformManufacturer());
rim.setPlatformModel(element.getPlatformModel());
rim.setTagId(element.getTagId());
rim.setAssociatedRim(element.getId());
rim.setPlatformManufacturer(bRim.getPlatformManufacturer());
rim.setPlatformModel(bRim.getPlatformModel());
rim.setTagId(bRim.getTagId());
rim.setAssociatedRim(bRim.getId());
break;
}
}
}
}
} else {
BaseReferenceManifest bRim = (BaseReferenceManifest) rim;
for (SwidResource swid : bRim.parseResource()) {
for (ReferenceManifest element : rims) {
} else {
BaseReferenceManifest bRim = (BaseReferenceManifest) rim;
for (SwidResource swid : bRim.parseResource()) {
if (element instanceof SupportReferenceManifest) {
SupportReferenceManifest sRim = (SupportReferenceManifest) element;
if (swid.getName().equals(sRim.getFileName())) {
@ -239,8 +235,8 @@ public class ReferenceManifestPageController
try {
referenceManifestManager.update(sRim);
} catch (DBManagerException dbmEx) {
LOGGER.error(String.format("Couldn't update Base RIM %s with "
+ "associated UUID %s", rim.getTagId(),
LOGGER.error(String.format("Couldn't update Support RIM "
+ "%s with associated UUID %s", rim.getTagId(),
sRim.getId()), dbmEx);
}
break;

View File

@ -28,7 +28,6 @@
<a href="${portal}/rim-details?id=${initialData.associatedRim}">
${initialData.associatedRim}
</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>
@ -54,18 +53,18 @@
<c:forEach items="${initialData.events}" var="event">
<tr>
<td>${count}</td>
<td>${event.getPcrIndex()}</td>
<td>PCR${event.getPcrIndex()}</td>
<td>${event.getEventTypeStr()}</td>
<td>${event.getEventDigestStr()}</td>
<td>${event.getEventContentStr()}</td>
</tr>
<c:set var="count" value="${count + 1}" scope="page"/>
<!-- not status.last ? <hr/> : <br/> -->
</c:forEach>
</c:if>
</tbody>
</table>
</div>
<div class="col-md-a col-md-offset-1"><span class="colHeader">${initialData.events.size()} entries</span></div>
</c:when>
<c:otherwise>
<div class="row">
@ -279,6 +278,21 @@
}
}
}
window.onload = function() {
// Constant retrieved from server-side via JSP
var maxRows = 11;
var table = document.getElementById('eventLog');
var wrapper = table.parentNode;
var rowsInTable = table.rows.length;
var height = 0;
if (rowsInTable > maxRows) {
for (var i = 0; i < maxRows; i++) {
height += table.rows[i].clientHeight;
}
wrapper.style.height = height + "px";
}
}
</script>
</jsp:body>
</my:page>

View File

@ -0,0 +1,36 @@
#eventInput {
width: 100%;
font-size: 16px; /* Increase font-size */
padding: 12px 20px 12px 40px; /* Add some padding */
border: 1px solid #ddd; /* Add a grey border */
margin-bottom: 12px; /* Add some space below the input */
}
#tableDivTag {
padding-top: 5px;
padding-left: 125px;
padding-right: 150px;
overflow-y: scroll;
}
#eventLog {
border-collapse: collapse; /* Collapse borders */
width: 100%;
border: 1px solid #ddd; /* Add a grey border */
font-size: 14px; /* Increase font-size */
}
#eventLog th, #eventLog td {
text-align: left; /* Left-align text */
padding: 10px; /* Add padding */
}
#eventLog tr {
/* Add a bottom border to all table rows */
border-bottom: 1px solid #ddd;
}
#eventLog tr.header, #eventLog tr:hover {
/* Add a grey background color to the table header and on hover */
background-color: #f1f1f1;
}