use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.
the class AssetTagCertBO method mapAssetTagCertToHostById.
/**
* This function would be used to associate a asset tag certificate with the host for which it is
* provisioned for. It requires you know the ID of the host it is to be associated with
* @param atagObj
* @return
*/
public boolean mapAssetTagCertToHostById(AssetTagCertAssociateRequest atagObj) {
boolean result;
log.debug("mapAssetTagCertToHostById");
// Before we map the asset tag cert to the host, we first need to unmap any associations if it already exists
try {
unmapAssetTagCertFromHostById(atagObj);
log.debug("Successfully unmapped the asset tag certificate assocation with host {}. ", atagObj.getHostID());
} catch (Exception ex) {
log.error("Error during unmap of asset tag cert from host with id {}. {}", atagObj.getHostID(), ex.getMessage());
}
try {
// Find the asset tag certificate for the specified Sha256Hash value
if (atagObj.getSha1OfAssetCert() != null) {
//List<MwAssetTagCertificate> atagCerts = My.jpa().mwAssetTagCertificate().findAssetTagCertificateBySha1Hash(atagObj.getSha1OfAssetCert());
MwAssetTagCertificateJpaController mwAssetTagCertificateJpaController = new MwAssetTagCertificateJpaController(getEntityManagerFactory());
List<MwAssetTagCertificate> atagCerts = mwAssetTagCertificateJpaController.findAssetTagCertificateBySha1Hash(atagObj.getSha1OfAssetCert());
// List<MwAssetTagCertificate> atagCerts = My.jpa().mwAssetTagCertificate().findAssetTagCertificatesByHostUUID("494cb5dc-a3e1-4e46-9b52-e694349b1654");
if (atagCerts.isEmpty()) {
log.error("mapAssetTagCertToHostById: The asset tag certificate does not exist");
throw new ASException(ErrorCode.AS_INVALID_ASSET_TAG_CERTIFICATE_HASH);
} else if (atagCerts.size() > 1) {
log.error("mapAssetTagCertToHostById: There were multiple matches for the specified hash");
throw new ASException(ErrorCode.AS_INVALID_ASSET_TAG_CERTIFICATE_HASH);
} else {
// Now that we have the asset tag identified, let us update the entry with the host ID for which it has
// to be associated.
MwAssetTagCertificate atagCert = atagCerts.get(0);
atagCert.setHostID(atagObj.getHostID());
// Now that the mapping is done, we need to calculate what the expected PCR value should be and put it in
// the PCREvent column.
Sha1Digest tag = Sha1Digest.digestOf(atagCert.getCertificate());
log.debug("mapAssetTagCertToHostById : Sha1 Hash of the certificate with UUID {} is {}.", atagCert.getUuid(), tag.toString());
Sha1Digest expectedHash = Sha1Digest.ZERO.extend(tag);
log.debug("mapAssetTagCertToHostById : Final expected PCR for the certificate with UUID {} is {}.", atagCert.getUuid(), expectedHash.toString());
atagCert.setPCREvent(expectedHash.toByteArray());
//My.jpa().mwAssetTagCertificate().edit(atagCert);
MwAssetTagCertificateJpaController asert_tag = new MwAssetTagCertificateJpaController(getEntityManagerFactory());
asert_tag.edit(atagCert);
result = true;
}
} else {
log.error("Sha1Hash for the asset tag is not specified.");
throw new ASException(ErrorCode.AS_INVALID_ASSET_TAG_CERTIFICATE_HASH);
}
} catch (ASException ase) {
log.error("Error during mapping of host to the asset tag certificate. Error Details - {}:{}.", ase.getErrorCode(), ase.getErrorMessage());
throw ase;
} catch (Exception ex) {
log.error("Unexpected error during mapping of host by id to the asset tag certificate. Error Details - {}.", ex.getMessage());
throw new ASException(ex);
}
return result;
}
use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.
the class HostBO method queryForHosts.
/**
* Author: Sudhir
*
* Searches for the hosts using the criteria specified.
*
* @param searchCriteria: If in case the user has not provided any
* search criteria, then all the hosts would be returned back to the
* caller
* @param includeHardwareUuid: if this is set to true, it causes the resulting
* TxtHostRecord to include the hardware_uuid field from the tblHost
* @return
*/
public List<TxtHostRecord> queryForHosts(String searchCriteria, boolean includeHardwareUuid) {
log.debug("queryForHost " + searchCriteria + " includeHardwareUuid[" + includeHardwareUuid + "]");
try {
//TblHostsJpaController tblHostsJpaController = My.jpa().mwHosts(); //new TblHostsJpaController(getEntityManagerFactory());
TblHostsJpaController tblHostsJpaController = new TblHostsJpaController(getEntityManagerFactory());
List<TxtHostRecord> txtHostList = new ArrayList<TxtHostRecord>();
List<TblHosts> tblHostList;
if (searchCriteria != null && !searchCriteria.isEmpty()) {
tblHostList = tblHostsJpaController.findHostsByNameSearchCriteria(searchCriteria);
} else {
tblHostList = tblHostsJpaController.findTblHostsEntities();
}
if (tblHostList != null) {
log.debug(String.format("Found [%d] host results for search criteria [%s]", tblHostList.size(), searchCriteria));
for (TblHosts tblHosts : tblHostList) {
TxtHostRecord hostObj = createTxtHostFromDatabaseRecord(tblHosts, includeHardwareUuid);
txtHostList.add(hostObj);
}
} else {
log.debug(String.format("Found no hosts for search criteria [%s]", searchCriteria));
}
return txtHostList;
} catch (ASException e) {
throw e;
} catch (Exception e) {
// throw new ASException(e);
// Bug: 1038 - prevent leaks in error messages to client
log.error("Error during querying for registered hosts.", e);
throw new ASException(ErrorCode.AS_QUERY_HOST_ERROR, e.getClass().getSimpleName());
}
}
use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.
the class HostBO method deleteModulesForMLE.
private void deleteModulesForMLE(TxtHostRecord host) throws NonexistentEntityException, IOException {
TblMleJpaController tblMleJpaController = getMleJpaController();
TblModuleManifestJpaController tblModuleManifestJpaController = getModuleJpaController();
try {
TblMle tblMle = tblMleJpaController.findVmmMle(host.VMM_Name, host.VMM_Version, host.VMM_OSName, host.VMM_OSVersion);
if (tblMle != null) {
// Retrieve the list of all the modules for the specified VMM MLE.
List<TblModuleManifest> moduleList = tblModuleManifestJpaController.findTblModuleManifestByHardwareUuid(host.Hardware_Uuid);
if (moduleList != null && moduleList.size() > 0) {
for (TblModuleManifest moduleObj : moduleList) {
//if (moduleObj.getUseHostSpecificDigestValue()) // we cannot delete the host specific one since it would be referenced by the Hosts
// continue;
tblModuleManifestJpaController.destroy(moduleObj.getId());
}
}
}
} catch (IllegalOrphanException | NonexistentEntityException ex) {
log.error("Error during the deletion of VMM modules {}. ", host.VMM_Name, ex);
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_DELETE_ERROR, ex.getClass().getSimpleName());
}
}
use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.
the class HostBO method isHostRegistered.
public HostResponse isHostRegistered(String hostnameOrAddress) {
try {
TblHostsJpaController tblHostsJpaController = new TblHostsJpaController(getEntityManagerFactory());
TblHosts tblHosts = tblHostsJpaController.findByName(hostnameOrAddress);
if (tblHosts != null) {
// host name exists in database
return new HostResponse(ErrorCode.OK);
}
tblHosts = tblHostsJpaController.findByIPAddress(hostnameOrAddress);
if (tblHosts != null) {
// host IP address exists in database
return new HostResponse(ErrorCode.OK);
}
return new HostResponse(ErrorCode.AS_HOST_NOT_FOUND);
} catch (ASException e) {
throw e;
} catch (Exception e) {
throw new ASException(e);
}
}
use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.
the class HostBO method getBiosAndVMM.
private void getBiosAndVMM(TxtHost host) {
TblMleJpaController mleController = getMleJpaController();
this.biosMleId = mleController.findBiosMle(host.getBios().getName(), host.getBios().getVersion(), host.getBios().getOem());
if (biosMleId == null) {
throw new ASException(ErrorCode.AS_BIOS_INCORRECT, host.getBios().getName(), host.getBios().getVersion(), host.getBios().getOem());
}
this.vmmMleId = mleController.findVmmMle(host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion());
if (vmmMleId == null) {
throw new ASException(ErrorCode.AS_VMM_INCORRECT, host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion());
}
}
Aggregations