Search in sources :

Example 26 with ASException

use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.

the class CitrixClient method generateNonce.

public String generateNonce() {
    try {
        // Create a secure random number generator
        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
        // Get 1024 random bits
        byte[] bytes = new byte[16];
        sr.nextBytes(bytes);
        //            nonce = new BASE64Encoder().encode( bytes);
        String nonce = Base64.encodeBase64String(bytes);
        log.info("Nonce Generated " + nonce);
        return nonce;
    } catch (NoSuchAlgorithmException e) {
        throw new ASException(e);
    }
}
Also used : SecureRandom(java.security.SecureRandom) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ASException(com.intel.mountwilson.as.common.ASException)

Example 27 with ASException

use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.

the class MleBO method deleteMle.

/**
    * 
    * @param mleName
    * @param mleVersion
    * @param osName
    * @param osVersion
    * @param oemName
    * @return 
    */
public String deleteMle(String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    try {
        TblMle tblMle = getMleDetails(mleName, mleVersion, osName, osVersion, oemName);
        if (tblMle == null) {
            throw new ASException(ErrorCode.WS_MLE_DOES_NOT_EXIST, mleName, mleVersion);
        }
        Collection<TblHosts> tblHostsCollection;
        if (oemName == null || oemName.isEmpty()) {
            tblHostsCollection = tblMle.getTblHostsCollection();
        } else {
            tblHostsCollection = tblMle.getTblHostsCollection1();
        }
        if (tblHostsCollection != null) {
            log.info(String.format("MLE '%s' is currently associated with '%d' hosts. ", mleName, tblHostsCollection.size()));
            if (!tblHostsCollection.isEmpty()) {
                throw new ASException(ErrorCode.WS_MLE_ASSOCIATION_EXISTS, mleName, mleVersion, tblHostsCollection.size());
            }
        }
        for (TblPcrManifest manifest : tblMle.getTblPcrManifestCollection()) {
            pcrManifestJpaController.destroy(manifest.getId());
        }
        // We also need to delete entries in the MleSource table for the MLE. This table would store the host
        // name that was used to white list the MLE.
        deleteMleSource(mleName, mleVersion, osName, osVersion, oemName);
        mleJpaController.destroy(tblMle.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) TblHosts(com.intel.mtwilson.as.data.TblHosts) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 28 with ASException

use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.

the class MleBO method deletePCRWhiteList.

/**
         * 
         * Added By: Sudhir on June 20, 2012
         * 
         * Processes the delete request for an existing PCR white list for the specified MLE.
         * 
         * @param pcrName : Name of the PCR, which is usually the number
         * @param mleName : Name of the associated MLE
         * @param mleVersion : Version of the associated MLE
         * @param osName : OS name associated with the VMM MLE
         * @param osVersion : OS version associated with the VMM MLE
         * @param oemName : OEM Name associated with the BIOS MLE
         * @return 
         */
public String deletePCRWhiteList(String pcrName, String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    TblPcrManifest tblPcr;
    TblMle tblMle;
    try {
        tblMle = getMleDetails(mleName, mleVersion, osName, osVersion, oemName);
        if (tblMle == null && oemName != null) {
            throw new ASException(ErrorCode.WS_MLE_OEM_DOES_NOT_EXIST, mleName, mleVersion, oemName);
        }
        if (tblMle == null && osName != null) {
            throw new ASException(ErrorCode.WS_MLE_OS_DOES_NOT_EXIST, mleName, mleVersion, osName, osVersion);
        }
        // Now we need to check if PCR value exists. If it does, then we do delete or else
        // we still return true since the data does not exist.
        tblPcr = getPCRWhiteListDetails(tblMle.getId(), pcrName);
        if (tblPcr == null) {
            return "true";
        }
        // Delete the PCR white list entry.
        pcrManifestJpaController.destroy(tblPcr.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 29 with ASException

use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.

the class MleBO method updateMle.

/**
    * 
    * @param mleData
    * @return 
    */
public String updateMle(MleData mleData) {
    try {
        TblMle tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        if (tblMle == null && mleData.getOemName() != null) {
            throw new ASException(ErrorCode.WS_MLE_OEM_DOES_NOT_EXIST, mleData.getName(), mleData.getVersion(), mleData.getOemName());
        }
        if (tblMle == null && mleData.getOsName() != null) {
            throw new ASException(ErrorCode.WS_MLE_OS_DOES_NOT_EXIST, mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion());
        }
        setTblMle(tblMle, mleData);
        mleJpaController.edit(tblMle);
        updatePcrManifest(tblMle, mleData);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 30 with ASException

use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.

the class MleBO method addMLe.

/**
	 * For VMM, the OS Name and OS Version in the new MLE must ALREADY be in the
	 * database, or this method will throw an error.
	 * 
	 * @param mleData
	 * @return
	 */
public String addMLe(MleData mleData, String mleUuid) {
    String osOemUuid = null;
    try {
        TblMle tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        if (tblMle != null) {
            throw new ASException(ErrorCode.WS_MLE_ALREADY_EXISTS, mleData.getName());
        }
        if (mleData.getName().toUpperCase().contains("ESX")) {
            String version = getUpperCase(mleData.getVersion()).substring(0, 2);
            if (!version.equals("51") && !version.equals("50")) {
                throw new ASException(ErrorCode.WS_ESX_MLE_NOT_SUPPORTED);
            }
        }
        if (mleData.getMleType().equals("VMM")) {
            TblOs osObj = new TblOsJpaController(getEntityManagerFactory()).findTblOsByNameVersion(mleData.getOsName(), mleData.getOsVersion());
            //TblOs osObj = My.jpa().mwOs().findTblOsByNameVersion(mleData.getOsName(), mleData.getOsVersion());
            osOemUuid = osObj.getUuid_hex();
        } else if (mleData.getMleType().equals("BIOS")) {
            TblOem oemObj = new TblOemJpaController(getEntityManagerFactory()).findTblOemByName(mleData.getOemName());
            //TblOem oemObj = My.jpa().mwOem().findTblOemByName(mleData.getOemName());
            osOemUuid = oemObj.getUuid_hex();
        }
        /*
             if (mleData.getMleType().equalsIgnoreCase("BIOS")){
                 if (mleData.getManifestList() != null){
                     for (ManifestData manifestData : mleData.getManifestList()) {
                         if (Integer.valueOf(manifestData.getName()).intValue() > 5 || Integer.valueOf(manifestData.getName()).intValue() < 0) {
                             throw new ASException(ErrorCode.WS_MLE_PCR_NOT_VALID, manifestData.getName());
                         }
                     }
                 }
             }
             
             if (mleData.getMleType().equalsIgnoreCase("VMM")){
                 if (mleData.getManifestList() != null){
                     for (ManifestData manifestData : mleData.getManifestList()) {
                         if (Integer.valueOf(manifestData.getName()).intValue() > 20 || Integer.valueOf(manifestData.getName()).intValue() < 17) {
                             throw new ASException(ErrorCode.WS_MLE_PCR_NOT_VALID, manifestData.getName());
                         }
                     }
                 }
             }*/
        tblMle = getTblMle(mleData, mleUuid, osOemUuid);
        mleJpaController.create(tblMle);
        addPcrManifest(tblMle, mleData.getManifestList());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblOsJpaController(com.intel.mtwilson.as.controller.TblOsJpaController) TblOemJpaController(com.intel.mtwilson.as.controller.TblOemJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) TblOem(com.intel.mtwilson.as.data.TblOem) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) TblOs(com.intel.mtwilson.as.data.TblOs)

Aggregations

ASException (com.intel.mountwilson.as.common.ASException)69 IOException (java.io.IOException)28 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)26 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)20 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)20 TblMle (com.intel.mtwilson.as.data.TblMle)20 NoResultException (javax.persistence.NoResultException)19 UnknownHostException (java.net.UnknownHostException)18 TblHosts (com.intel.mtwilson.as.data.TblHosts)17 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)12 KeyManagementException (java.security.KeyManagementException)10 MwAssetTagCertificate (com.intel.mtwilson.as.data.MwAssetTagCertificate)9 SignatureException (java.security.SignatureException)8 CertificateException (java.security.cert.CertificateException)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 ConfigurationException (org.apache.commons.configuration.ConfigurationException)8 ApiException (com.intel.mtwilson.ApiException)7 MwAssetTagCertificateJpaController (com.intel.mtwilson.as.controller.MwAssetTagCertificateJpaController)7 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)7