Search in sources :

Example 1 with TblEventTypeJpaController

use of com.intel.mtwilson.as.controller.TblEventTypeJpaController 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)

Aggregations

ASException (com.intel.mountwilson.as.common.ASException)1 TblEventTypeJpaController (com.intel.mtwilson.as.controller.TblEventTypeJpaController)1 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)1 TblModuleManifestJpaController (com.intel.mtwilson.as.controller.TblModuleManifestJpaController)1 TblPackageNamespaceJpaController (com.intel.mtwilson.as.controller.TblPackageNamespaceJpaController)1 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)1 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)1 TblEventType (com.intel.mtwilson.as.data.TblEventType)1 TblMle (com.intel.mtwilson.as.data.TblMle)1 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)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