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;
}
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;
}
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();
}
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();
}
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);
}
Aggregations