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