use of com.intel.mtwilson.as.data.MwAssetTagCertificate in project OpenAttestation by OpenAttestation.
the class MwAssetTagCertificateJpaController method findMwAssetTagCertificateEntities.
private List<MwAssetTagCertificate> findMwAssetTagCertificateEntities(boolean all, int maxResults, int firstResult) {
EntityManager em = getEntityManager();
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(MwAssetTagCertificate.class));
Query q = em.createQuery(cq);
if (!all) {
q.setMaxResults(maxResults);
q.setFirstResult(firstResult);
}
return q.getResultList();
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.data.MwAssetTagCertificate in project OpenAttestation by OpenAttestation.
the class MwAssetTagCertificateJpaController method destroy.
public void destroy(Integer id) throws NonexistentEntityException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
MwAssetTagCertificate mwAssetTagCertificate;
try {
mwAssetTagCertificate = em.getReference(MwAssetTagCertificate.class, id);
mwAssetTagCertificate.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The mwAssetTagCertificate with id " + id + " no longer exists.", enfe);
}
em.remove(mwAssetTagCertificate);
em.getTransaction().commit();
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.data.MwAssetTagCertificate in project OpenAttestation by OpenAttestation.
the class MwAssetTagCertificateJpaController method getMwAssetTagCertificateCount.
public int getMwAssetTagCertificateCount() {
EntityManager em = getEntityManager();
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
Root<MwAssetTagCertificate> rt = cq.from(MwAssetTagCertificate.class);
cq.select(em.getCriteriaBuilder().count(rt));
Query q = em.createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.data.MwAssetTagCertificate in project OpenAttestation by OpenAttestation.
the class ReportsBO method getPcrLogReportForAssetTag.
private PcrLogReport getPcrLogReportForAssetTag(TblTaLog taLog, Integer hostId) {
logger.debug("getPcrLogReportForAssetTag : Creating pcr log report for asset tag verification for host with uuid {}.", hostId);
AssetTagCertBO atagCertBO = new AssetTagCertBO();
MwAssetTagCertificate atagCert = atagCertBO.findValidAssetTagCertForHost(hostId);
if (atagCert != null) {
logger.debug("getPcrLogReportForAssetTag : Found a valid asset tag certificate for the host with white list value {}", atagCert.getPCREvent().toString());
PcrLogReport manifest = new PcrLogReport();
manifest.setName(Integer.parseInt(ASSET_TAG_PCR));
manifest.setValue(taLog.getManifestValue());
manifest.setWhiteListValue(new Sha1Digest(atagCert.getPCREvent()).toString());
if (manifest.getValue().equalsIgnoreCase(manifest.getWhiteListValue())) {
manifest.setTrustStatus(1);
} else {
manifest.setTrustStatus(0);
}
manifest.setVerifiedOn(new Date());
return manifest;
}
return null;
}
use of com.intel.mtwilson.as.data.MwAssetTagCertificate in project OpenAttestation by OpenAttestation.
the class AssetTagCertBO method findValidAssetTagCertForHost.
/**
* Finds a valid asset tag certificate for the specified host.
* @param uuid
* @return
*/
public MwAssetTagCertificate findValidAssetTagCertForHost(String uuid) {
uuid = uuid.replace("\n", "");
try {
// So if the host has been provisioned multiple times, we will pick up the latest one.
if (uuid != null && !uuid.isEmpty()) {
//List<MwAssetTagCertificate> atagCerts = My.jpa().mwAssetTagCertificate().findAssetTagCertificatesByHostUUID(uuid.toLowerCase());
MwAssetTagCertificateJpaController assetTagController = new MwAssetTagCertificateJpaController(getEntityManagerFactory());
List<MwAssetTagCertificate> atagCerts = assetTagController.findAssetTagCertificatesByHostUUID(uuid.toLowerCase());
if (atagCerts.isEmpty()) {
log.info("Asset tag certificate has not been provisioned for the host with UUID : {}.", uuid);
return null;
} else {
// For each of the asset tag certs that are returned back, we need to validate the certificate first.
for (MwAssetTagCertificate atagTempCert : atagCerts) {
if (validateAssetTagCert(atagTempCert)) {
log.debug("Valid asset tag certificate found for host with UUID {}.", uuid);
return atagTempCert;
}
}
log.info("No valid asset tag certificate found for host with UUID {}.", uuid);
return null;
}
} else {
log.error("UUID specified for the host is not valid.");
throw new ASException(ErrorCode.AS_HOST_NOT_FOUND);
}
} catch (ASException ase) {
log.error("Error during querying of valid asset tag certificate. Error Details - {}:{}.", ase.getErrorCode(), ase.getErrorMessage());
throw ase;
} catch (Exception ex) {
log.error("Unexpected error during querying of valid asset tag certificate. Error Details - {}.", ex.getMessage());
throw new ASException(ex);
}
}
Aggregations