use of com.intel.mtwilson.as.controller.TblModuleManifestJpaController in project OpenAttestation by OpenAttestation.
the class HostBO method createHostSpecificManifestRecords.
private List<TblHostSpecificManifest> createHostSpecificManifestRecords(TblMle vmmMleId, HashMap<String, ? extends IManifest> pcrManifest, String hostType) throws IOException {
List<TblHostSpecificManifest> tblHostSpecificManifests = new ArrayList<>();
if (vmmMleId.getRequiredManifestList().contains(MODULE_PCR) && pcrManifest != null) {
PcrManifest pcrMf19 = (PcrManifest) pcrManifest.get(MODULE_PCR);
if (pcrMf19.containsPcrEventLog(19)) {
PcrEventLog pcrEventLog = pcrMf19.getPcrEventLog(19);
if (pcrEventLog != null) {
for (Measurement m : pcrEventLog.getEventLog()) {
if (m != null && m.getInfo() != null && (!m.getInfo().isEmpty())) {
m.getInfo().get("EventName");
m.getInfo().get("ComponentName");
if (hostType.equals("intel") && m.getInfo().get("EventName") != null) {
log.debug("Adding host specific manifest for event " + m.getInfo().get("EventName") + ": field=" + m.getLabel() + " component=" + m.getInfo().get("ComponentName"));
log.debug("Querying manifest for event: " + m.getInfo().get("EventName") + ": MLE_ID=" + vmmMleId.getId() + " component=" + m.getInfo().get("ComponentName"));
// For open source XEN and KVM both the modules that get extended to PCR 19 should be added into the host specific table
//TblModuleManifest tblModuleManifest = My.jpa().mwModuleManifest().findByMleNameEventName(vmmMleId.getId(), m.getInfo().get("ComponentName"), m.getInfo().get("EventName"));
TblModuleManifestJpaController tblModuleManifestJpaController = getModuleJpaController();
TblModuleManifest tblModuleManifest = tblModuleManifestJpaController.findByMleNameEventName(vmmMleId.getId(), m.getInfo().get("ComponentName"), m.getInfo().get("EventName"));
TblHostSpecificManifest tblHostSpecificManifest = new TblHostSpecificManifest();
tblHostSpecificManifest.setDigestValue(m.getValue().toString());
tblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
tblHostSpecificManifests.add(tblHostSpecificManifest);
}
}
}
}
} else {
log.warn("No PCR 19 found.SO not saving host specific manifest.");
}
} else {
log.warn("It is not possible to get PCR 19 info. Unable to perform database insertion");
}
return tblHostSpecificManifests;
}
use of com.intel.mtwilson.as.controller.TblModuleManifestJpaController in project OpenAttestation by OpenAttestation.
the class HostBO method addModuleWhiteList.
private void addModuleWhiteList(PcrManifest pcr19, TblHosts tblHosts, TxtHost host, String uuid) {
try {
TblModuleManifestJpaController tblModuleManifestJpa = getModuleJpaController();
TblMleJpaController tblMleJpa = getMleJpaController();
TblEventTypeJpaController tblEventJpa = getEventJpaController();
TblPackageNamespaceJpaController tblPackageJpa = getPackageJpaController();
TblEventType tblEvent;
TblMle tblMle = tblMleJpa.findTblMleByUUID(uuid);
TblPackageNamespace nsPackNS;
if (tblMle == null) {
try {
// First check if the entry exists in the MLE table.
tblMle = getMleDetails(host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion(), "");
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, host.getVmm().getName(), host.getVmm().getVersion());
}
}
if (tblMle == null) {
log.error("MLE specified is not found in the DB");
throw new ASException(ErrorCode.WS_MLE_RETRIEVAL_ERROR, this.getClass().getSimpleName());
}
String eventName;
String componentName;
// String fullComponentName = "";
String fullComponentName;
String digest;
String packageName;
String packageVendor;
String packageVersion;
String extendedtoPCR;
boolean useHostSpecificDigest;
try {
// Before we insert the record, we need the identity for the event name
if (pcr19.containsPcrEventLog(19)) {
PcrEventLog pcrEventLog = pcr19.getPcrEventLog(19);
if (pcrEventLog != null) {
for (Measurement m : pcrEventLog.getEventLog()) {
extendedtoPCR = m.getInfo().get("ExtendedToPCR");
if (extendedtoPCR != null) {
if (extendedtoPCR.equals("19")) {
//tblEvent = tblEventJpa.findEventTypeByName(m.getInfo().get("EventName"));
eventName = m.getInfo().get("EventName");
componentName = m.getInfo().get("ComponentName");
packageName = String.valueOf(m.getInfo().get("PackageName"));
packageVendor = String.valueOf(m.getInfo().get("PackageVendor"));
packageVersion = String.valueOf(m.getInfo().get("PackageVersion"));
extendedtoPCR = String.valueOf(m.getInfo().get("ExtendedToPCR"));
digest = String.valueOf(m.getValue());
useHostSpecificDigest = Boolean.valueOf(m.getInfo().get("UseHostSpecificDigest"));
try {
// Before we insert the record, we need the identity for the event name
tblEvent = tblEventJpa.findEventTypeByName(eventName);
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_EVENT_TYPE_DOES_NOT_EXIST, eventName);
}
validateNull("EventName", eventName);
validateNull("ComponentName", componentName);
// corresponds to VMware, then we will append the event type fieldName to the component name. Otherwise we won't
if (eventName.contains("Vim25")) {
fullComponentName = tblEvent.getFieldName() + "." + componentName;
} else {
fullComponentName = componentName;
}
Integer componentID = tblModuleManifestJpa.findByMleIdEventId(tblMle.getId(), fullComponentName, tblEvent.getId());
if (componentID != null && componentID != 0) {
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_ALREADY_EXISTS, componentName);
}
try {
// Since there will be only one entry for now, we will just hardcode it for now.
// TO-DO: See if we can change this.
// Nov-12,2013: Changed to use the function that accepts the ID instead of the name for better
// performance.
nsPackNS = tblPackageJpa.findByName("Standard_Global_NS");
} catch (NoResultException nre) {
throw new ASException(ErrorCode.WS_NAME_SPACE_DOES_NOT_EXIST);
}
TblModuleManifest newModuleRecord = new TblModuleManifest();
if (uuid != null && !uuid.isEmpty()) {
newModuleRecord.setUuid_hex(uuid);
} else {
newModuleRecord.setUuid_hex(new UUID().toString());
}
newModuleRecord.setMleId(tblMle);
newModuleRecord.setMle_uuid_hex(tblMle.getUuid_hex());
newModuleRecord.setEventID(tblEvent);
newModuleRecord.setNameSpaceID(nsPackNS);
newModuleRecord.setComponentName(fullComponentName);
newModuleRecord.setDigestValue(digest);
newModuleRecord.setPackageName(packageName);
newModuleRecord.setPackageVendor(packageVendor);
newModuleRecord.setPackageVersion(packageVersion);
newModuleRecord.setUseHostSpecificDigestValue(useHostSpecificDigest);
newModuleRecord.setExtendedToPCR(extendedtoPCR);
newModuleRecord.setDescription("");
tblModuleManifestJpa.create(newModuleRecord);
// break;
}
}
}
}
}
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_EVENT_TYPE_DOES_NOT_EXIST);
}
} catch (ASException ase) {
throw ase;
} catch (Exception e) {
// throw new ASException(ErrorCode.SYSTEM_ERROR, "Exception while adding Module white list data. " + e.getMessage(), e);
// throw new ASException(e);
log.error("Error during Module whitelist creation.", e);
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_CREATE_ERROR, e.getClass().getSimpleName());
}
}
use of com.intel.mtwilson.as.controller.TblModuleManifestJpaController in project OpenAttestation by OpenAttestation.
the class HostBO method deleteModulesForMLE.
private void deleteModulesForMLE(TxtHostRecord host) throws NonexistentEntityException, IOException {
TblMleJpaController tblMleJpaController = getMleJpaController();
TblModuleManifestJpaController tblModuleManifestJpaController = getModuleJpaController();
try {
TblMle tblMle = tblMleJpaController.findVmmMle(host.VMM_Name, host.VMM_Version, host.VMM_OSName, host.VMM_OSVersion);
if (tblMle != null) {
// Retrieve the list of all the modules for the specified VMM MLE.
List<TblModuleManifest> moduleList = tblModuleManifestJpaController.findTblModuleManifestByHardwareUuid(host.Hardware_Uuid);
if (moduleList != null && moduleList.size() > 0) {
for (TblModuleManifest moduleObj : moduleList) {
//if (moduleObj.getUseHostSpecificDigestValue()) // we cannot delete the host specific one since it would be referenced by the Hosts
// continue;
tblModuleManifestJpaController.destroy(moduleObj.getId());
}
}
}
} catch (IllegalOrphanException | NonexistentEntityException ex) {
log.error("Error during the deletion of VMM modules {}. ", host.VMM_Name, ex);
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_DELETE_ERROR, ex.getClass().getSimpleName());
}
}
Aggregations