Search in sources :

Example 31 with TblPcrManifest

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

the class MleBO method createMleDataFromDatabaseRecord.

/**
         * 
         * @param tblMle
         * @param addManifest
         * @return 
         */
public MleData createMleDataFromDatabaseRecord(TblMle tblMle, boolean addManifest) {
    List<ManifestData> manifestList = null;
    if (addManifest) {
        manifestList = new ArrayList<ManifestData>();
        for (TblPcrManifest pcrManifest : tblMle.getTblPcrManifestCollection()) {
            manifestList.add(new ManifestData(pcrManifest.getName(), pcrManifest.getValue()));
        }
    }
    String osName = (tblMle.getOsId() == null) ? null : tblMle.getOsId().getName();
    String osVersion = (tblMle.getOsId() == null) ? null : tblMle.getOsId().getVersion();
    String oemName = (tblMle.getOemId() == null) ? null : tblMle.getOemId().getName();
    MleData s = new MleData(tblMle.getName(), tblMle.getVersion(), MleData.MleType.valueOf(tblMle.getMLEType()), MleData.AttestationType.valueOf(tblMle.getAttestationType()), manifestList, tblMle.getDescription(), osName, osVersion, oemName);
    return s;
}
Also used : MleData(com.intel.mtwilson.datatypes.MleData) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) ManifestData(com.intel.mtwilson.datatypes.ManifestData)

Example 32 with TblPcrManifest

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

the class MleBO method updatePcrManifest.

/**
         * 
         * @param tblMle
         * @param mleData
         * @throws NonexistentEntityException
         * @throws ASDataException 
         */
private void updatePcrManifest(TblMle tblMle, MleData mleData) throws NonexistentEntityException, ASDataException {
    HashMap<String, String> newPCRMap = getPcrMap(mleData);
    if (tblMle.getTblPcrManifestCollection() != null) {
        for (TblPcrManifest pcrManifest : tblMle.getTblPcrManifestCollection()) {
            if (newPCRMap.containsKey(pcrManifest.getName())) {
                log.info(String.format("Updating Pcr manifest value for mle %s  version %s pcr name %s", pcrManifest.getMleId().getName(), pcrManifest.getMleId().getVersion(), pcrManifest.getName()));
                pcrManifest.setValue(newPCRMap.get(pcrManifest.getName()));
                pcrManifestJpaController.edit(pcrManifest);
                newPCRMap.remove(pcrManifest.getName());
            } else {
                log.info(String.format("Deleting Pcr manifest value for mle %s  version %s pcr name %s", pcrManifest.getMleId().getName(), pcrManifest.getMleId().getVersion(), pcrManifest.getName()));
                pcrManifestJpaController.destroy(pcrManifest.getId());
            }
        }
        for (String pcrName : newPCRMap.keySet()) {
            TblPcrManifest pcrManifest = new TblPcrManifest();
            pcrManifest.setName(pcrName);
            pcrManifest.setValue(newPCRMap.get(pcrName));
            pcrManifest.setMleId(tblMle);
            log.info(String.format("Creating Pcr manifest value for mle %s  version %s pcr name %s", pcrManifest.getMleId().getName(), pcrManifest.getMleId().getVersion(), pcrManifest.getName()));
            pcrManifestJpaController.create(pcrManifest);
        }
    }
}
Also used : TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Example 33 with TblPcrManifest

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

the class MleBOTest method testDeletePCRWhiteList.

@Test
public void testDeletePCRWhiteList() {
    doReturn(new TblMle(MLE_ID1, "DELL", "A08", "PCR", "BIOS", "0")).when(tblMleJpaController).findBiosMle("DELL", "A08", "DELL");
    doReturn(new TblMle(MLE_ID2, "XEN", "4.3", "PCR", "VMM", "18")).when(tblMleJpaController).findVmmMle("XEN", "4.3", "Fedora", "20");
    doReturn(new TblPcrManifest(PcrManifest_ID1, "0", "31B97D97B4679917EC3C1D943635693FFBAB4143")).when(tblPcrManifestJpaController).findByMleIdName(MLE_ID1, "0");
    doReturn(new TblPcrManifest(PcrManifest_ID2, "18", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")).when(tblPcrManifestJpaController).findByMleIdName(MLE_ID2, "18");
    String biosResult = mleBO.deletePCRWhiteList("0", "DELL", "A08", "", "", "DELL");
    assertEquals("true", biosResult);
    String vmmResult = mleBO.deletePCRWhiteList("18", "XEN", "4.3", "Fedora", "20", "");
    assertEquals("true", vmmResult);
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) Matchers.anyString(org.mockito.Matchers.anyString) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) Test(org.junit.Test)

Example 34 with TblPcrManifest

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

the class MleBOTest method testUpdatePCRWhiteList.

@Test
public void testUpdatePCRWhiteList() {
    PCRWhiteList biosPcrData = new PCRWhiteList("0", "31B97D97B4679917EC3C1D943635693FFBAB4143", "DELL", "A08", "", "", "DELL");
    PCRWhiteList vmmPcrData = new PCRWhiteList("18", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "XEN", "4.3", "Fedora", "20", "");
    doReturn(new TblMle(MLE_ID1, "DELL", "A08", "PCR", "BIOS", "0")).when(tblMleJpaController).findBiosMle(biosPcrData.getMleName(), biosPcrData.getMleVersion(), biosPcrData.getOemName());
    doReturn(new TblMle(MLE_ID2, "XEN", "4.3", "PCR", "VMM", "18")).when(tblMleJpaController).findVmmMle(vmmPcrData.getMleName(), vmmPcrData.getMleVersion(), vmmPcrData.getOsName(), vmmPcrData.getOsVersion());
    doReturn(new TblPcrManifest(PcrManifest_ID1, biosPcrData.getPcrName(), biosPcrData.getPcrDigest())).when(tblPcrManifestJpaController).findByMleIdName(MLE_ID1, biosPcrData.getPcrName());
    doReturn(new TblPcrManifest(PcrManifest_ID2, vmmPcrData.getPcrName(), vmmPcrData.getPcrDigest())).when(tblPcrManifestJpaController).findByMleIdName(MLE_ID2, vmmPcrData.getPcrName());
    String biosResult = mleBO.updatePCRWhiteList(biosPcrData);
    assertEquals("true", biosResult);
    String vmmResult = mleBO.updatePCRWhiteList(vmmPcrData);
    assertEquals("true", vmmResult);
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) Matchers.anyString(org.mockito.Matchers.anyString) PCRWhiteList(com.intel.mtwilson.datatypes.PCRWhiteList) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) Test(org.junit.Test)

Aggregations

TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)34 TblMle (com.intel.mtwilson.as.data.TblMle)18 Matchers.anyString (org.mockito.Matchers.anyString)12 ArrayList (java.util.ArrayList)9 EntityManager (javax.persistence.EntityManager)9 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)8 TblHosts (com.intel.mtwilson.as.data.TblHosts)7 Test (org.junit.Test)7 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)6 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)6 TblOem (com.intel.mtwilson.as.data.TblOem)6 TblOs (com.intel.mtwilson.as.data.TblOs)6 NoResultException (javax.persistence.NoResultException)5 ASException (com.intel.mountwilson.as.common.ASException)4 IManifest (com.intel.mountwilson.manifest.data.IManifest)4 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)4 HashMap (java.util.HashMap)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 Query (javax.persistence.Query)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4