Search in sources :

Example 1 with MwAssetTagCertificate

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate)

Example 2 with MwAssetTagCertificate

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate)

Example 3 with MwAssetTagCertificate

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate)

Example 4 with MwAssetTagCertificate

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;
}
Also used : Sha1Digest(com.intel.mtwilson.util.crypto.Sha1Digest) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate)

Example 5 with MwAssetTagCertificate

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);
    }
}
Also used : MwAssetTagCertificateJpaController(com.intel.mtwilson.as.controller.MwAssetTagCertificateJpaController) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) ApiException(com.intel.mtwilson.ApiException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

MwAssetTagCertificate (com.intel.mtwilson.as.data.MwAssetTagCertificate)16 ASException (com.intel.mountwilson.as.common.ASException)11 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)10 IOException (java.io.IOException)10 MwAssetTagCertificateJpaController (com.intel.mtwilson.as.controller.MwAssetTagCertificateJpaController)7 ApiException (com.intel.mtwilson.ApiException)6 KeyManagementException (java.security.KeyManagementException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 SignatureException (java.security.SignatureException)6 CertificateException (java.security.cert.CertificateException)6 UnknownHostException (java.net.UnknownHostException)4 AssetTagCertBO (com.intel.mtwilson.as.business.AssetTagCertBO)3 Sha1Digest (com.intel.mtwilson.util.crypto.Sha1Digest)3 EntityManager (javax.persistence.EntityManager)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ConfigurationException (org.apache.commons.configuration.ConfigurationException)3 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)2 TblHosts (com.intel.mtwilson.as.data.TblHosts)2 TblSamlAssertion (com.intel.mtwilson.as.data.TblSamlAssertion)2 AssetTagCertAssociateRequest (com.intel.mtwilson.datatypes.AssetTagCertAssociateRequest)2