Search in sources :

Example 26 with Hostname

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);
}
Also used : HostsTrustReportType(com.intel.mountwilson.as.hosttrustreport.data.HostsTrustReportType) ArrayList(java.util.ArrayList) Hostname(com.intel.mtwilson.util.net.Hostname) Test(org.junit.Test)

Example 27 with Hostname

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());
}
Also used : TblTaLog(com.intel.mtwilson.as.data.TblTaLog) ArrayList(java.util.ArrayList) Hostname(com.intel.mtwilson.util.net.Hostname) HostManifestReportType(com.intel.mountwilson.as.hostmanifestreport.data.HostManifestReportType) Date(java.util.Date) Test(org.junit.Test)

Example 28 with Hostname

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(""));
}
Also used : Hostname(com.intel.mtwilson.util.net.Hostname) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 29 with Hostname

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);
    }
}
Also used : TblTaLogJpaController(com.intel.mtwilson.as.controller.TblTaLogJpaController) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) TblHosts(com.intel.mtwilson.as.data.TblHosts) Hostname(com.intel.mtwilson.util.net.Hostname) ASException(com.intel.mountwilson.as.common.ASException) 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)

Example 30 with Hostname

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;
}
Also used : Hostname(com.intel.mtwilson.util.net.Hostname) Date(java.util.Date) ASException(com.intel.mountwilson.as.common.ASException) 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)

Aggregations

Hostname (com.intel.mtwilson.util.net.Hostname)30 Test (org.junit.Test)15 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 TblTaLog (com.intel.mtwilson.as.data.TblTaLog)7 ApiException (com.intel.mtwilson.ApiException)6 SignatureException (java.security.SignatureException)6 DemoPortalException (com.intel.mountwilson.common.DemoPortalException)5 TblHosts (com.intel.mtwilson.as.data.TblHosts)5 Date (java.util.Date)5 ASException (com.intel.mountwilson.as.common.ASException)4 HostsTrustReportType (com.intel.mountwilson.as.hosttrustreport.data.HostsTrustReportType)4 Matchers.anyString (org.mockito.Matchers.anyString)4 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)3 UnknownHostException (java.net.UnknownHostException)3 HostType (com.intel.mountwilson.as.hosttrustreport.data.HostType)2 AttestationReport (com.intel.mtwilson.datatypes.AttestationReport)2 HostTrustResponse (com.intel.mtwilson.datatypes.HostTrustResponse)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2