Search in sources :

Example 16 with TblHosts

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

the class HostBO method getHostByName.

/**
	 * This is not a REST API method, it is public because it is used by
	 * HostTrustBO.
	 * 
	 * @param hostName
	 * @return
	 * @throws CryptographyException
	 */
public TblHosts getHostByName(Hostname hostName) throws CryptographyException {
    // datatype.Hostname
    TblHosts tblHosts = new TblHosts();
    try {
        InetAddress addr = InetAddress.getByName(hostName.toString());
        String hostname = addr.getHostName();
        String ip = addr.getHostAddress();
        tblHosts = new TblHostsJpaController(getEntityManagerFactory()).findByName(hostname);
        tblHosts = tblHosts != null ? tblHosts : new TblHostsJpaController(getEntityManagerFactory()).findByName(ip);
    } catch (UnknownHostException e) {
        log.error("Unknown host", e);
    }
    return tblHosts;
}
Also used : TblHostsJpaController(com.intel.mtwilson.as.controller.TblHostsJpaController) UnknownHostException(java.net.UnknownHostException) TblHosts(com.intel.mtwilson.as.data.TblHosts) InetAddress(java.net.InetAddress)

Example 17 with TblHosts

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

the class HostTrustBO method getTrustStatus.

/**
     * 
     * @param hostName must not be null
     * @return 
     */
public HostTrustStatus getTrustStatus(Hostname hostName) {
    HashMap<String, ? extends IManifest> pcrManifestMap;
    HashMap<String, ? extends IManifest> gkvBiosPcrManifestMap, gkvVmmPcrManifestMap;
    if (hostName == null) {
        throw new IllegalArgumentException("missing hostname");
    }
    TblHosts tblHosts = null;
    try {
        tblHosts = getHostByIpAddress(InetAddress.getByName(hostName.toString()).getHostAddress());
    } catch (UnknownHostException e) {
        throw new ASException(e);
    }
    if (tblHosts == null) {
        throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, hostName.toString());
    }
    log.info("VMM name for host is {}", tblHosts.getVmmMleId().getName());
    log.info("OS name for host is {}", tblHosts.getVmmMleId().getOsId().getName());
    // bug #538 first check if the host supports tpm
    HostAgentFactory factory = new HostAgentFactory();
    HostAgent agent = factory.getHostAgent(tblHosts);
    if (!agent.isTpmAvailable()) {
        //Bug 510 add a blank row in the ta log for this host. this is so the host does not report mle's incorrectly.  
        logBlankTrustStatus(tblHosts);
        throw new ASException(ErrorCode.AS_INTEL_TXT_NOT_ENABLED, hostName.toString());
    }
    IManifestStrategy manifestStrategy = getManifestStrategy(tblHosts);
    try {
        long start = System.currentTimeMillis();
        pcrManifestMap = manifestStrategy.getManifest(tblHosts);
        log.info("Manifest Time {}", (System.currentTimeMillis() - start));
    } catch (ASException e) {
        throw e;
    } catch (Exception e) {
        throw new ASException(e);
    }
    long start = System.currentTimeMillis();
    log.info("PCRS from the VMM host {}", pcrManifestMap);
    /**
         * Get GKV for the given host
		 *
         */
    IGKVStrategy gkvStrategy = getGkvStrategy(tblHosts);
    gkvBiosPcrManifestMap = gkvStrategy.getBiosGoodKnownManifest(tblHosts.getBiosMleId().getName(), tblHosts.getBiosMleId().getVersion(), tblHosts.getBiosMleId().getOemId().getName());
    gkvVmmPcrManifestMap = gkvStrategy.getVmmGoodKnownManifest(tblHosts.getVmmMleId().getName(), tblHosts.getVmmMleId().getVersion(), tblHosts.getVmmMleId().getOsId().getName(), tblHosts.getVmmMleId().getOsId().getVersion(), tblHosts.getId());
    /**
         * Verify trust
		 *
         */
    log.info("tblHosts.getId()" + tblHosts.getId());
    log.info("tblHosts.getIPAddress()" + tblHosts.getIPAddress());
    HostTrustStatus trust = verifyTrust(tblHosts, pcrManifestMap, gkvBiosPcrManifestMap, gkvVmmPcrManifestMap);
    log.info("Verfication Time {}", (System.currentTimeMillis() - start));
    return trust;
}
Also used : IManifestStrategy(com.intel.mountwilson.manifest.IManifestStrategy) UnknownHostException(java.net.UnknownHostException) ASException(com.intel.mountwilson.as.common.ASException) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TblHosts(com.intel.mtwilson.as.data.TblHosts) IGKVStrategy(com.intel.mtwilson.as.business.trust.gkv.IGKVStrategy) ASException(com.intel.mountwilson.as.common.ASException)

Example 18 with TblHosts

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

the class TblHostsJpaControllerTest method testDestroy.

@Test
public void testDestroy() throws IllegalOrphanException, NonexistentEntityException {
    TblHosts tblHost = new TblHosts(HOST_ID);
    doReturn(tblHost).when(em).getReference(TblHosts.class, HOST_ID);
    tblHostsJpaController.destroy(HOST_ID);
    verify(em).remove(tblHost);
    verify(em).close();
    verify(transaction).begin();
    verify(transaction).commit();
}
Also used : TblHosts(com.intel.mtwilson.as.data.TblHosts) Test(org.junit.Test)

Example 19 with TblHosts

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

the class TblHostsJpaControllerTest method testEdit.

@Test
public void testEdit() throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    TblHosts tblHost = new TblHosts(HOST_ID);
    TblHosts persistentTblHosts = new TblHosts(HOST_ID);
    persistentTblHosts.setDescription("test");
    doReturn(persistentTblHosts).when(em).find(TblHosts.class, HOST_ID);
    doReturn(tblHost).when(tblHostsJpaController).findTblHosts(HOST_ID);
    tblHostsJpaController.edit(tblHost);
    verify(em).merge(tblHost);
    verify(em).close();
    verify(transaction).begin();
    verify(transaction).commit();
}
Also used : TblHosts(com.intel.mtwilson.as.data.TblHosts) Test(org.junit.Test)

Example 20 with TblHosts

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

the class HostTrustBOTest method testGetTrustStatus.

@Test
public void testGetTrustStatus() throws Exception {
    TblHosts tblHosts = mockGetHostByIpAddress();
    doReturn(tblHosts).when(hostTrustBO).getHostByIpAddress(SERVER_NAME);
    //get pcrMap 
    HashMap<String, IManifest> pcrManifestMap = new HashMap<String, IManifest>();
    pcrManifestMap.put("0", new PcrManifest(0, "31B97D97B4679917EC3C1D943635693FFBAB4143"));
    pcrManifestMap.put("18", new PcrManifest(18, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"));
    doReturn(pcrManifestMap).when(manifestStrategy).getManifest(tblHosts);
    //get gkv for given host
    HashMap<String, IManifest> gkvBiosPcrManifestMap = new HashMap<String, IManifest>();
    HashMap<String, IManifest> gkvVmmPcrManifestMap = new HashMap<String, IManifest>();
    gkvBiosPcrManifestMap.put("0", new PcrManifest(0, "31B97D97B4679917EC3C1D943635693FFBAB4143"));
    gkvVmmPcrManifestMap.put("18", new PcrManifest(18, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"));
    doReturn(gkvBiosPcrManifestMap).when(gkvStrategy).getBiosGoodKnownManifest(anyString(), anyString(), anyString());
    doReturn(gkvVmmPcrManifestMap).when(gkvStrategy).getVmmGoodKnownManifest(anyString(), anyString(), anyString(), anyString(), any(Integer.class));
    doNothing().when(taLogJpaController).create(any(TblTaLog.class));
    HostTrustStatus trustStatus = hostTrustBO.getTrustStatus(new Hostname(SERVER_NAME));
    assertNotNull(trustStatus);
    assertTrue(trustStatus.bios);
    assertTrue(trustStatus.vmm);
}
Also used : TblTaLog(com.intel.mtwilson.as.data.TblTaLog) HashMap(java.util.HashMap) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) TblHosts(com.intel.mtwilson.as.data.TblHosts) Hostname(com.intel.mtwilson.util.net.Hostname) Matchers.anyString(org.mockito.Matchers.anyString) IManifest(com.intel.mountwilson.manifest.data.IManifest) HostTrustStatus(com.intel.mtwilson.datatypes.HostTrustStatus) Test(org.junit.Test)

Aggregations

TblHosts (com.intel.mtwilson.as.data.TblHosts)42 ASException (com.intel.mountwilson.as.common.ASException)17 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)15 EntityManager (javax.persistence.EntityManager)14 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)13 IOException (java.io.IOException)12 UnknownHostException (java.net.UnknownHostException)11 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)10 ArrayList (java.util.ArrayList)10 TblMle (com.intel.mtwilson.as.data.TblMle)9 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)9 NoResultException (javax.persistence.NoResultException)8 TblHostsJpaController (com.intel.mtwilson.as.controller.TblHostsJpaController)7 TblTaLog (com.intel.mtwilson.as.data.TblTaLog)6 EntityNotFoundException (javax.persistence.EntityNotFoundException)6 Query (javax.persistence.Query)6 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)6 Hostname (com.intel.mtwilson.util.net.Hostname)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)4