Search in sources :

Example 11 with TblHosts

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

the class ReportsBO method getAttestationReport.

public AttestationReport getAttestationReport(Hostname hostName, Boolean failureOnly) throws NumberFormatException, IOException {
    AttestationReport attestationReport = new AttestationReport();
    TblHosts tblHosts = null;
    try {
        // datatype.Hostname
        tblHosts = getTblHostsJpaController().findByName(hostName.toString());
    } catch (CryptographyException e) {
        throw new ASException(e, ErrorCode.AS_ENCRYPTION_ERROR, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    }
    if (tblHosts == null) {
        throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, hostName.toString());
    }
    Date lastStatusTs = getTblTaLogJpaController().findLastStatusTs(tblHosts.getId());
    if (lastStatusTs != null) {
        List<TblTaLog> logs = getTblTaLogJpaController().findLogsByHostId(tblHosts.getId(), lastStatusTs);
        com.intel.mountwilson.as.hostmanifestreport.data.HostType hostType = new com.intel.mountwilson.as.hostmanifestreport.data.HostType();
        // datatype.Hostname
        hostType.setName(hostName.toString());
        if (logs != null) {
            for (TblTaLog log : logs) {
                boolean value = (failureOnly && log.getTrustStatus() == false);
                if (!failureOnly || value) {
                    if (log.getManifestName().equalsIgnoreCase(ASSET_TAG_PCR)) {
                        attestationReport.getPcrLogs().add(getPcrLogReportForAssetTag(log, tblHosts.getId()));
                    } else {
                        attestationReport.getPcrLogs().add(getPcrManifestLog(tblHosts, log, failureOnly));
                    }
                }
            }
        }
    }
    return attestationReport;
}
Also used : TblTaLog(com.intel.mtwilson.as.data.TblTaLog) HostType(com.intel.mountwilson.as.hosttrustreport.data.HostType) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) TblHosts(com.intel.mtwilson.as.data.TblHosts) ASException(com.intel.mountwilson.as.common.ASException)

Example 12 with TblHosts

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

the class HostTrustBO method getTrustWithSamlForHostnames.

public String getTrustWithSamlForHostnames(Collection<String> hosts) throws IOException {
    //My.initDataEncryptionKey();
    ArrayList<TblHosts> tblHostsList = new ArrayList<TblHosts>();
    for (String host : hosts) {
        TblHosts tblHosts = getHostByName(new Hostname((host)));
        tblHostsList.add(tblHosts);
    }
    return getTrustWithSaml(tblHostsList);
}
Also used : TblHosts(com.intel.mtwilson.as.data.TblHosts) ArrayList(java.util.ArrayList) Hostname(com.intel.mtwilson.util.net.Hostname)

Example 13 with TblHosts

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

the class HostBOTest method testDeleteHost.

@Test
public void testDeleteHost() throws CryptographyException {
    List<TblTaLog> taLogs = new ArrayList<TblTaLog>();
    taLogs.add(new TblTaLog(1));
    taLogs.add(new TblTaLog(2));
    when(taLogJpaController.findLogsByHostId(anyInt(), any(Date.class))).thenReturn(taLogs);
    doReturn(new TblHosts(1)).when(hostBO).getHostByName(new Hostname(SERVER_NAME));
    String response = hostBO.deleteHost(new Hostname(SERVER_NAME));
    assertTrue(response.equalsIgnoreCase("true"));
}
Also used : TblTaLog(com.intel.mtwilson.as.data.TblTaLog) TblHosts(com.intel.mtwilson.as.data.TblHosts) ArrayList(java.util.ArrayList) Hostname(com.intel.mtwilson.util.net.Hostname) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 14 with TblHosts

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

the class HostBO method updateHost.

public String updateHost(TxtHost host) {
    try {
        // datatype.Hostname
        TblHosts tblHosts = getHostByName(host.getHostName());
        if (tblHosts == null) {
            throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, host.getHostName().toString());
        }
        getBiosAndVMM(host);
        //host (aik cert, manifest,etc)
        if (tblHosts.getTlsPolicyName() == null && tblHosts.getTlsPolicyName().isEmpty()) {
            // XXX new code to test
            tblHosts.setTlsPolicyName("TRUST_FIRST_CERTIFICATE");
        // XXX bug #497 the TxtHost object doesn't have the ssl
        // certificate and policy
        }
        tblHosts.setAddOnConnectionInfo(host.getAddOn_Connection_String());
        if (host.getHostName() != null) {
            tblHosts.setName(host.getHostName().toString());
        }
        if (host.getIPAddress() != null) {
            tblHosts.setIPAddress(host.getIPAddress().toString());
        }
        if (host.getPort() != null) {
            tblHosts.setPort(host.getPort());
        }
        log.info("Getting identity.");
        if (canFetchAIKCertificateForHost(host.getVmm().getName())) {
            // datatype.Vmm
            String certificate = getAIKCertificateForHost(tblHosts, host);
            tblHosts.setAIKCertificate(certificate);
        } else {
            // the
            if (vmmMleId.getId().intValue() != tblHosts.getVmmMleId().getId().intValue()) {
                log.info("VMM is updated. Update the host specific manifest");
                // BUG #497 added tblHosts parameter
                HashMap<String, ? extends IManifest> pcrMap = getHostPcrManifest(tblHosts, host);
            // Building objects and validating that manifests are
            // created ahead of create of host
            }
        }
        List<TblHostSpecificManifest> tblHostSpecificManifests = null;
        if (vmmMleId.getId().intValue() != tblHosts.getVmmMleId().getId().intValue()) {
            log.info("VMM is updated. Update the host specific manifest");
            HashMap<String, ? extends IManifest> pcrs = getHostPcrManifest(tblHosts, host);
            deleteHostSpecificManifest(tblHosts);
            if (vmmMleId.getRequiredManifestList().contains(MODULE_PCR)) {
                log.debug("Host specific modules would be retrieved from the host that extends into PCR 19.");
                // Added the Vendor parameter to the below function so that we can handle the host specific records differently for different types of hosts.
                String hostType = host.getVendor();
                tblHostSpecificManifests = createHostSpecificManifestRecords(vmmMleId, pcrs, hostType);
            } else {
                log.debug("Host specific modules will not be configured since PCR 19 is not selected for attestation");
            }
        }
        biosMleId = findBiosMleForHost(host);
        vmmMleId = findVmmMleForHost(host);
        log.info("Saving Host in database");
        tblHosts.setBiosMleId(biosMleId);
        tblHosts.setDescription(host.getDescription());
        tblHosts.setEmail(host.getEmail());
        if (host.getIPAddress() != null)
            // datatype.IPAddress
            tblHosts.setIPAddress(host.getIPAddress().toString());
        tblHosts.setPort(host.getPort());
        tblHosts.setVmmMleId(vmmMleId);
        tblHosts.setBios_mle_uuid_hex(biosMleId.getUuid_hex());
        tblHosts.setVmm_mle_uuid_hex(vmmMleId.getUuid_hex());
        log.info("Updating Host in database");
        getHostsJpaController().edit(tblHosts);
        if (tblHostSpecificManifests != null) {
            log.debug("Updating Host Specific Manifest in database");
            createHostSpecificManifest(tblHostSpecificManifests, tblHosts);
        }
    } catch (ASException ase) {
        throw ase;
    } catch (CryptographyException e) {
        throw new ASException(e, ErrorCode.AS_ENCRYPTION_ERROR, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    } catch (Exception e) {
        throw new ASException(e);
    }
    // return new HostResponse(ErrorCode.OK);
    return "true";
}
Also used : CryptographyException(com.intel.mtwilson.crypto.CryptographyException) TblHosts(com.intel.mtwilson.as.data.TblHosts) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 15 with TblHosts

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

the class HostBO method checkForDuplicate.

private void checkForDuplicate(TxtHost host) throws CryptographyException {
    TblHostsJpaController tblHostsJpaController = getHostsJpaController();
    TblHosts tblHosts1 = tblHostsJpaController.findByName(host.getHostName().toString());
    TblHosts tblHosts2 = tblHostsJpaController.findByIPAddress(host.getIPAddress().toString());
    if (tblHosts1 != null) {
        throw new ASException(ErrorCode.AS_HOST_EXISTS, host.getHostName());
    }
    if (tblHosts2 != null) {
        throw new ASException(ErrorCode.AS_IPADDRESS_EXISTS, host.getIPAddress().toString());
    }
}
Also used : TblHostsJpaController(com.intel.mtwilson.as.controller.TblHostsJpaController) TblHosts(com.intel.mtwilson.as.data.TblHosts) ASException(com.intel.mountwilson.as.common.ASException)

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