Search in sources :

Example 1 with TblMleJpaController

use of com.intel.mtwilson.as.controller.TblMleJpaController in project OpenAttestation by OpenAttestation.

the class HostBO method findVmmMleForHost.

private TblMle findVmmMleForHost(TxtHost host) throws IOException {
    TblMleJpaController tblMleJpaController = getMleJpaController();
    TblMle vmmMleId = tblMleJpaController.findVmmMle(host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion());
    if (vmmMleId == null) {
        throw new ASException(ErrorCode.AS_VMM_INCORRECT, host.getVmm().getName(), host.getVmm().getVersion());
    }
    return vmmMleId;
}
Also used : TblMleJpaController(com.intel.mtwilson.as.controller.TblMleJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) ASException(com.intel.mountwilson.as.common.ASException)

Example 2 with TblMleJpaController

use of com.intel.mtwilson.as.controller.TblMleJpaController 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());
    }
}
Also used : Measurement(com.intel.mtwilson.util.model.Measurement) TblMleJpaController(com.intel.mtwilson.as.controller.TblMleJpaController) TblPackageNamespaceJpaController(com.intel.mtwilson.as.controller.TblPackageNamespaceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException) PcrEventLog(com.intel.mtwilson.util.model.PcrEventLog) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TblEventTypeJpaController(com.intel.mtwilson.as.controller.TblEventTypeJpaController) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblModuleManifestJpaController(com.intel.mtwilson.as.controller.TblModuleManifestJpaController) UUID(com.intel.mtwilson.util.io.UUID) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace) ASException(com.intel.mountwilson.as.common.ASException)

Example 3 with TblMleJpaController

use of com.intel.mtwilson.as.controller.TblMleJpaController in project OpenAttestation by OpenAttestation.

the class CitrixAgentStrategy method getPcrList.

private String getPcrList(TblHosts tblHosts) {
    // Get the Bios MLE without accessing cache    
    TblMle biosMle = new TblMleJpaController(getEntityManagerFactory()).findMleById(tblHosts.getBiosMleId().getId());
    String biosPcrList = biosMle.getRequiredManifestList();
    if (biosPcrList.isEmpty()) {
        throw new ASException(ErrorCode.AS_MISSING_MLE_REQD_MANIFEST_LIST, tblHosts.getBiosMleId().getName(), tblHosts.getBiosMleId().getVersion());
    }
    // Get the Vmm MLE without accessing cache
    TblMle vmmMle = new TblMleJpaController(getEntityManagerFactory()).findMleById(tblHosts.getVmmMleId().getId());
    String vmmPcrList = vmmMle.getRequiredManifestList();
    if (vmmPcrList == null || vmmPcrList.isEmpty()) {
        throw new ASException(ErrorCode.AS_MISSING_MLE_REQD_MANIFEST_LIST, tblHosts.getVmmMleId().getName(), tblHosts.getVmmMleId().getVersion());
    }
    return biosPcrList + "," + vmmPcrList;
}
Also used : TblMleJpaController(com.intel.mtwilson.as.controller.TblMleJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) ASException(com.intel.mountwilson.as.common.ASException)

Example 4 with TblMleJpaController

use of com.intel.mtwilson.as.controller.TblMleJpaController 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());
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) TblMleJpaController(com.intel.mtwilson.as.controller.TblMleJpaController) TblModuleManifestJpaController(com.intel.mtwilson.as.controller.TblModuleManifestJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) ASException(com.intel.mountwilson.as.common.ASException)

Example 5 with TblMleJpaController

use of com.intel.mtwilson.as.controller.TblMleJpaController in project OpenAttestation by OpenAttestation.

the class HostBO method getBiosAndVMM.

private void getBiosAndVMM(TxtHost host) {
    TblMleJpaController mleController = getMleJpaController();
    this.biosMleId = mleController.findBiosMle(host.getBios().getName(), host.getBios().getVersion(), host.getBios().getOem());
    if (biosMleId == null) {
        throw new ASException(ErrorCode.AS_BIOS_INCORRECT, host.getBios().getName(), host.getBios().getVersion(), host.getBios().getOem());
    }
    this.vmmMleId = mleController.findVmmMle(host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion());
    if (vmmMleId == null) {
        throw new ASException(ErrorCode.AS_VMM_INCORRECT, host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion());
    }
}
Also used : TblMleJpaController(com.intel.mtwilson.as.controller.TblMleJpaController) ASException(com.intel.mountwilson.as.common.ASException)

Aggregations

TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)8 ASException (com.intel.mountwilson.as.common.ASException)7 TblMle (com.intel.mtwilson.as.data.TblMle)7 TblModuleManifestJpaController (com.intel.mtwilson.as.controller.TblModuleManifestJpaController)2 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)2 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)2 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)2 TblEventTypeJpaController (com.intel.mtwilson.as.controller.TblEventTypeJpaController)1 TblPackageNamespaceJpaController (com.intel.mtwilson.as.controller.TblPackageNamespaceJpaController)1 TblEventType (com.intel.mtwilson.as.data.TblEventType)1 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)1 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)1 UUID (com.intel.mtwilson.util.io.UUID)1 Measurement (com.intel.mtwilson.util.model.Measurement)1 PcrEventLog (com.intel.mtwilson.util.model.PcrEventLog)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 NoResultException (javax.persistence.NoResultException)1