Search in sources :

Example 6 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class HostBO method createHostSpecificManifest.

private void createHostSpecificManifest(List<TblHostSpecificManifest> tblHostSpecificManifests, TblHosts tblHosts) throws IOException {
    if (tblHostSpecificManifests != null && !tblHostSpecificManifests.isEmpty()) {
        for (TblHostSpecificManifest tblHostSpecificManifest : tblHostSpecificManifests) {
            tblHostSpecificManifest.setHostID(tblHosts.getId());
            TblHostSpecificManifestJpaController tblHostSpecificManifestJpaController = getHostSpecificManifestJpaController();
            tblHostSpecificManifestJpaController.create(tblHostSpecificManifest);
        }
    }
}
Also used : TblHostSpecificManifestJpaController(com.intel.mtwilson.as.controller.TblHostSpecificManifestJpaController) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest)

Example 7 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class HostBO method updateHost.

public String updateHost(TxtHost host) {
    try {
        // datatype.Hostname
        TblHosts tblHosts = getHostByName(host.getHostName());
        if (tblHosts == null) {
            throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, host.getHostName().toString());
        }
        getBiosAndVMM(host);
        //host (aik cert, manifest,etc)
        if (tblHosts.getTlsPolicyName() == null && tblHosts.getTlsPolicyName().isEmpty()) {
            // XXX new code to test
            tblHosts.setTlsPolicyName("TRUST_FIRST_CERTIFICATE");
        // XXX bug #497 the TxtHost object doesn't have the ssl
        // certificate and policy
        }
        tblHosts.setAddOnConnectionInfo(host.getAddOn_Connection_String());
        if (host.getHostName() != null) {
            tblHosts.setName(host.getHostName().toString());
        }
        if (host.getIPAddress() != null) {
            tblHosts.setIPAddress(host.getIPAddress().toString());
        }
        if (host.getPort() != null) {
            tblHosts.setPort(host.getPort());
        }
        log.info("Getting identity.");
        if (canFetchAIKCertificateForHost(host.getVmm().getName())) {
            // datatype.Vmm
            String certificate = getAIKCertificateForHost(tblHosts, host);
            tblHosts.setAIKCertificate(certificate);
        } else {
            // the
            if (vmmMleId.getId().intValue() != tblHosts.getVmmMleId().getId().intValue()) {
                log.info("VMM is updated. Update the host specific manifest");
                // BUG #497 added tblHosts parameter
                HashMap<String, ? extends IManifest> pcrMap = getHostPcrManifest(tblHosts, host);
            // Building objects and validating that manifests are
            // created ahead of create of host
            }
        }
        List<TblHostSpecificManifest> tblHostSpecificManifests = null;
        if (vmmMleId.getId().intValue() != tblHosts.getVmmMleId().getId().intValue()) {
            log.info("VMM is updated. Update the host specific manifest");
            HashMap<String, ? extends IManifest> pcrs = getHostPcrManifest(tblHosts, host);
            deleteHostSpecificManifest(tblHosts);
            if (vmmMleId.getRequiredManifestList().contains(MODULE_PCR)) {
                log.debug("Host specific modules would be retrieved from the host that extends into PCR 19.");
                // Added the Vendor parameter to the below function so that we can handle the host specific records differently for different types of hosts.
                String hostType = host.getVendor();
                tblHostSpecificManifests = createHostSpecificManifestRecords(vmmMleId, pcrs, hostType);
            } else {
                log.debug("Host specific modules will not be configured since PCR 19 is not selected for attestation");
            }
        }
        biosMleId = findBiosMleForHost(host);
        vmmMleId = findVmmMleForHost(host);
        log.info("Saving Host in database");
        tblHosts.setBiosMleId(biosMleId);
        tblHosts.setDescription(host.getDescription());
        tblHosts.setEmail(host.getEmail());
        if (host.getIPAddress() != null)
            // datatype.IPAddress
            tblHosts.setIPAddress(host.getIPAddress().toString());
        tblHosts.setPort(host.getPort());
        tblHosts.setVmmMleId(vmmMleId);
        tblHosts.setBios_mle_uuid_hex(biosMleId.getUuid_hex());
        tblHosts.setVmm_mle_uuid_hex(vmmMleId.getUuid_hex());
        log.info("Updating Host in database");
        getHostsJpaController().edit(tblHosts);
        if (tblHostSpecificManifests != null) {
            log.debug("Updating Host Specific Manifest in database");
            createHostSpecificManifest(tblHostSpecificManifests, tblHosts);
        }
    } catch (ASException ase) {
        throw ase;
    } catch (CryptographyException e) {
        throw new ASException(e, ErrorCode.AS_ENCRYPTION_ERROR, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    } catch (Exception e) {
        throw new ASException(e);
    }
    // return new HostResponse(ErrorCode.OK);
    return "true";
}
Also used : CryptographyException(com.intel.mtwilson.crypto.CryptographyException) TblHosts(com.intel.mtwilson.as.data.TblHosts) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) ASException(com.intel.mountwilson.as.common.ASException) 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)

Example 8 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest 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;
}
Also used : Measurement(com.intel.mtwilson.util.model.Measurement) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) TblModuleManifestJpaController(com.intel.mtwilson.as.controller.TblModuleManifestJpaController) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) PcrEventLog(com.intel.mtwilson.util.model.PcrEventLog)

Example 9 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method edit_v2.

public void edit_v2(TblModuleManifest tblModuleManifest, EntityManager em) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    try {
        TblModuleManifest persistentTblModuleManifest = em.find(TblModuleManifest.class, tblModuleManifest.getId());
        TblMle mleIdOld = persistentTblModuleManifest.getMleId();
        TblMle mleIdNew = tblModuleManifest.getMleId();
        TblEventType eventIDOld = persistentTblModuleManifest.getEventID();
        TblEventType eventIDNew = tblModuleManifest.getEventID();
        TblPackageNamespace nameSpaceIDOld = persistentTblModuleManifest.getNameSpaceID();
        TblPackageNamespace nameSpaceIDNew = tblModuleManifest.getNameSpaceID();
        Collection<TblHostSpecificManifest> tblHostSpecificManifestCollectionOld = persistentTblModuleManifest.getTblHostSpecificManifestCollection();
        Collection<TblHostSpecificManifest> tblHostSpecificManifestCollectionNew = tblModuleManifest.getTblHostSpecificManifestCollection();
        List<String> illegalOrphanMessages = null;
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionOldTblHostSpecificManifest : tblHostSpecificManifestCollectionOld) {
            if (!tblHostSpecificManifestCollectionNew.contains(tblHostSpecificManifestCollectionOldTblHostSpecificManifest)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain TblHostSpecificManifest " + tblHostSpecificManifestCollectionOldTblHostSpecificManifest + " since its moduleManifestID field is not nullable.");
            }
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        if (mleIdNew != null) {
            mleIdNew = em.getReference(mleIdNew.getClass(), mleIdNew.getId());
            tblModuleManifest.setMleId(mleIdNew);
        }
        if (eventIDNew != null) {
            eventIDNew = em.getReference(eventIDNew.getClass(), eventIDNew.getId());
            tblModuleManifest.setEventID(eventIDNew);
        }
        if (nameSpaceIDNew != null) {
            nameSpaceIDNew = em.getReference(nameSpaceIDNew.getClass(), nameSpaceIDNew.getId());
            tblModuleManifest.setNameSpaceID(nameSpaceIDNew);
        }
        Collection<TblHostSpecificManifest> attachedTblHostSpecificManifestCollectionNew = new ArrayList<TblHostSpecificManifest>();
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach : tblHostSpecificManifestCollectionNew) {
            tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach = em.getReference(tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach.getClass(), tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach.getId());
            attachedTblHostSpecificManifestCollectionNew.add(tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach);
        }
        tblHostSpecificManifestCollectionNew = attachedTblHostSpecificManifestCollectionNew;
        tblModuleManifest.setTblHostSpecificManifestCollection(tblHostSpecificManifestCollectionNew);
        tblModuleManifest = em.merge(tblModuleManifest);
        if (mleIdOld != null && !mleIdOld.equals(mleIdNew)) {
            mleIdOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            mleIdOld = em.merge(mleIdOld);
        }
        if (mleIdNew != null && !mleIdNew.equals(mleIdOld)) {
            mleIdNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(mleIdNew);
        }
        if (eventIDOld != null && !eventIDOld.equals(eventIDNew)) {
            eventIDOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            eventIDOld = em.merge(eventIDOld);
        }
        if (eventIDNew != null && !eventIDNew.equals(eventIDOld)) {
            eventIDNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(eventIDNew);
        }
        if (nameSpaceIDOld != null && !nameSpaceIDOld.equals(nameSpaceIDNew)) {
            nameSpaceIDOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            nameSpaceIDOld = em.merge(nameSpaceIDOld);
        }
        if (nameSpaceIDNew != null && !nameSpaceIDNew.equals(nameSpaceIDOld)) {
            nameSpaceIDNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(nameSpaceIDNew);
        }
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionNewTblHostSpecificManifest : tblHostSpecificManifestCollectionNew) {
            if (!tblHostSpecificManifestCollectionOld.contains(tblHostSpecificManifestCollectionNewTblHostSpecificManifest)) {
                TblModuleManifest oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest = tblHostSpecificManifestCollectionNewTblHostSpecificManifest.getModuleManifestID();
                tblHostSpecificManifestCollectionNewTblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
                tblHostSpecificManifestCollectionNewTblHostSpecificManifest = em.merge(tblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                if (oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest != null && !oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest.equals(tblModuleManifest)) {
                    oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                    em.merge(oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                }
            }
        }
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblModuleManifest.getId();
            if (findTblModuleManifest(id) == null) {
                throw new NonexistentEntityException("The tblModuleManifest with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) TblMle(com.intel.mtwilson.as.data.TblMle) ArrayList(java.util.ArrayList) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Example 10 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method create_v2.

public void create_v2(TblModuleManifest tblModuleManifest, EntityManager em) {
    long createV2_1 = System.currentTimeMillis();
    if (tblModuleManifest.getTblHostSpecificManifestCollection() == null) {
        tblModuleManifest.setTblHostSpecificManifestCollection(new ArrayList<TblHostSpecificManifest>());
    }
    try {
        TblMle mleId = tblModuleManifest.getMleId();
        if (mleId != null) {
            mleId = em.getReference(mleId.getClass(), mleId.getId());
            tblModuleManifest.setMleId(mleId);
        }
        TblEventType eventID = tblModuleManifest.getEventID();
        if (eventID != null) {
            eventID = em.getReference(eventID.getClass(), eventID.getId());
            tblModuleManifest.setEventID(eventID);
        }
        TblPackageNamespace nameSpaceID = tblModuleManifest.getNameSpaceID();
        if (nameSpaceID != null) {
            nameSpaceID = em.getReference(nameSpaceID.getClass(), nameSpaceID.getId());
            tblModuleManifest.setNameSpaceID(nameSpaceID);
        }
        long createV2_2 = System.currentTimeMillis();
        log.debug("CREATE_V2 - Time taken to setup IDs :" + (createV2_2 - createV2_1) + "milliseconds.");
        Collection<TblHostSpecificManifest> attachedTblHostSpecificManifestCollection = new ArrayList<TblHostSpecificManifest>();
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach : tblModuleManifest.getTblHostSpecificManifestCollection()) {
            tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach = em.getReference(tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach.getClass(), tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach.getId());
            attachedTblHostSpecificManifestCollection.add(tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach);
        }
        tblModuleManifest.setTblHostSpecificManifestCollection(attachedTblHostSpecificManifestCollection);
        em.persist(tblModuleManifest);
        long createV2_3 = System.currentTimeMillis();
        log.debug("CREATE_V2 - Time taken to insert and persist :" + (createV2_3 - createV2_2) + "milliseconds.");
        if (mleId != null) {
            mleId.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(mleId);
        }
        if (eventID != null) {
            eventID.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(eventID);
        }
        if (nameSpaceID != null) {
            nameSpaceID.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(nameSpaceID);
        }
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionTblHostSpecificManifest : tblModuleManifest.getTblHostSpecificManifestCollection()) {
            TblModuleManifest oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest = tblHostSpecificManifestCollectionTblHostSpecificManifest.getModuleManifestID();
            tblHostSpecificManifestCollectionTblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
            tblHostSpecificManifestCollectionTblHostSpecificManifest = em.merge(tblHostSpecificManifestCollectionTblHostSpecificManifest);
            if (oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest != null) {
                oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifestCollectionTblHostSpecificManifest);
                em.merge(oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest);
            }
        }
        long createV2_4 = System.currentTimeMillis();
        log.debug("CREATE_V2 - Time taken for merge operations :" + (createV2_4 - createV2_3) + "milliseconds.");
    } finally {
    }
}
Also used : TblEventType(com.intel.mtwilson.as.data.TblEventType) TblMle(com.intel.mtwilson.as.data.TblMle) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Aggregations

TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)16 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)9 EntityManager (javax.persistence.EntityManager)9 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)7 NoResultException (javax.persistence.NoResultException)7 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)5 TblEventType (com.intel.mtwilson.as.data.TblEventType)5 TblMle (com.intel.mtwilson.as.data.TblMle)5 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)5 ArrayList (java.util.ArrayList)5 EntityNotFoundException (javax.persistence.EntityNotFoundException)5 Query (javax.persistence.Query)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)3 ASException (com.intel.mountwilson.as.common.ASException)2 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)2 TblHostSpecificManifestJpaController (com.intel.mtwilson.as.controller.TblHostSpecificManifestJpaController)2 TblHosts (com.intel.mtwilson.as.data.TblHosts)2 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)2 IOException (java.io.IOException)2