use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class ReportsBOTest method testGetTrustReportNoError.
@Test
public void testGetTrustReportNoError() {
Collection<Hostname> hostNames = new ArrayList<Hostname>();
hostNames.add(new Hostname(SERVER_NAME));
when(tblHostsJpaController.findByName(anyString())).thenReturn(mockFindByName());
when(tblTaLogJpaController.findTrustStatusByHostId(anyInt(), anyInt())).thenReturn(null);
HostsTrustReportType hostsTrustReportType = reportsBO.getTrustReport(hostNames);
assertNotNull(hostsTrustReportType);
assertFalse(hostsTrustReportType.getHost().size() > 0);
}
use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class ReportsBOTest method testGetReportManifest.
@Test
public void testGetReportManifest() {
when(tblHostsJpaController.findByName(anyString())).thenReturn(mockFindByName());
when(tblTaLogJpaController.findLastStatusTs(any(Integer.class))).thenReturn(new Date());
List<TblTaLog> taLogs = new ArrayList<TblTaLog>();
taLogs.add(new TblTaLog(Integer.valueOf(1), 1, 1, "0", "31B97D97B4679917EC3C1D943635693FFBAB4143", true, new Date()));
when(tblTaLogJpaController.findLogsByHostId(anyInt(), any(Date.class))).thenReturn(taLogs);
HostManifestReportType hostManifestReportType = reportsBO.getReportManifest(new Hostname(SERVER_NAME));
assertNotNull(hostManifestReportType);
assertNotNull(hostManifestReportType.getHost());
}
use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class ReportsBOTest method testGetHostAttestationReport.
@Test
public void testGetHostAttestationReport() {
when(tblHostsJpaController.findByName(anyString())).thenReturn(mockFindByName());
String attestationReport = reportsBO.getHostAttestationReport(new Hostname(SERVER_NAME));
assertNotNull(attestationReport);
assertFalse(attestationReport.equalsIgnoreCase(""));
}
use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class HostTrustBO method getTrustWithCache.
public HostTrust getTrustWithCache(String host, Boolean forceVerify) {
log.info("Getting trust for host: " + host + " Force verify flag: " + forceVerify);
try {
if (forceVerify != true) {
TblHosts tblHosts = getHostByName(new Hostname(host));
if (tblHosts != null) {
TblTaLog tblTaLog = new TblTaLogJpaController(getEntityManagerFactory()).getHostTALogEntryBefore(tblHosts.getId(), getCacheStaleAfter());
if (tblTaLog != null)
return getHostTrustObj(tblTaLog);
} else {
throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, host);
}
}
log.info("Getting trust status from host.");
HostTrustStatus status = getTrustStatus(new Hostname(host));
HostTrust hostTrust = new HostTrust(ErrorCode.OK, "OK");
hostTrust.setBiosStatus((status.bios) ? 1 : 0);
hostTrust.setVmmStatus((status.vmm) ? 1 : 0);
hostTrust.setIpAddress(host);
return hostTrust;
} catch (ASException e) {
log.error("Error while getting trust for host " + host, e);
return new HostTrust(e.getErrorCode(), e.getErrorMessage(), host, null, null);
} catch (Exception e) {
log.error("Error while getting trust for host " + host, e);
return new HostTrust(ErrorCode.SYSTEM_ERROR, new AuthResponse(ErrorCode.SYSTEM_ERROR, e.getMessage()).getErrorMessage(), host, null, null);
}
}
use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class HostTrustBO method getPollHosts.
public OpenStackHostTrustLevelReport getPollHosts(OpenStackHostTrustLevelQuery input) {
OpenStackHostTrustLevelReport hostTrusts = new OpenStackHostTrustLevelReport();
Date today = new Date(System.currentTimeMillis());
String trustLevel;
// fetch pcr value from host agent in parallel
for (final Hostname hostName : input.hosts) {
hostStatus.put(hostName.getHostname(), "");
Thread thread = new Thread() {
public void run() {
try {
String hostTrustStatus = getTrustStatusString(hostName);
log.info("The trust status of {} is :{}", new String[] { hostName.toString(), hostTrustStatus });
hostStatus.put(hostName.getHostname(), hostTrustStatus);
} catch (ASException e) {
log.error("Error while getting status of host " + hostName, e);
hostStatus.put(hostName.getHostname(), "unknown");
} catch (Exception e) {
log.error("Error while getting status of host " + hostName, e);
hostStatus.put(hostName.getHostname(), "unknown");
}
}
};
thread.start();
}
while (!isAllAttested(input)) {
try {
Thread.sleep(ASConfig.getTrustAgentSleepTimeinMilliSecs());
} catch (InterruptedException e) {
log.error("Error while sleeping " + e);
}
}
for (Hostname hostName : input.hosts) {
try {
String hostTrustStatus = hostStatus.get(hostName.getHostname());
log.info("The trust status of {} is :{}", new String[] { hostName.toString(), hostTrustStatus });
if (hostTrustStatus == "unknown") {
trustLevel = "unknown";
} else {
log.debug("Processing hostTrustStatus String: {}", hostTrustStatus);
trustLevel = parseTrustStatus(hostTrustStatus);
log.debug("Trust level obtained: {}", hostTrustStatus);
}
} catch (ASException e) {
log.error("Error while getting trust of host " + hostName, e);
trustLevel = "unknown";
} catch (Exception e) {
log.error("Error while getting trust of host " + hostName, e);
trustLevel = "unknown";
}
HostTrustLevel1String trust = new HostTrustLevel1String();
trust.hostname = hostName.toString();
trust.trustLevel = trustLevel;
trust.vtime = today;
// trust.timestamp = Util.getDateString(today);
// hostTrusts.pollHosts.put(hostName, trust);
hostTrusts.pollHosts.add(trust);
}
return hostTrusts;
}
Aggregations