Search in sources :

Example 21 with ASException

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

the class Host method get.

/**
     * Returns the trust status of a host.
     * 
     * Sample request:
     * GET http://localhost:8080/AttestationService/resources/hosts/trust?hostName=Some+TXT+Host
     * 
     * Sample output for untrusted host:
     * BIOS:0,VMM:0
     * 
     * Sample output for trusted host:
     * BIOS:1,VMM:1
     * 
     * @param hostName unique name of the host to query
     * @return a string like BIOS:0,VMM:0 representing the trust status
     */
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("/trust")
public HostTrustResponse get(@QueryParam("hostName") String hostName) {
    try {
        // 0.5.1 returned MediaType.TEXT_PLAIN string like "BIOS:0,VMM:0" :  return new HostTrustBO().getTrustStatusString(new Hostname(hostName)); // datatype.Hostname            
        Hostname hostname = new Hostname(hostName);
        HostTrustStatus trust = new ASComponentFactory().getHostTrustBO().getTrustStatus(hostname);
        return new HostTrustResponse(hostname, trust);
    } catch (ASException e) {
        throw e;
    } catch (Exception e) {
        throw new ASException(e);
    }
}
Also used : ASComponentFactory(com.intel.mtwilson.as.helper.ASComponentFactory) Hostname(com.intel.mtwilson.util.net.Hostname) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 22 with ASException

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

the class CitrixAgentStrategy method getPcrList.

private String getPcrList(TblHosts tblHosts) {
    // Get the Bios MLE without accessing cache    
    TblMle biosMle = new TblMleJpaController(getEntityManagerFactory()).findMleById(tblHosts.getBiosMleId().getId());
    String biosPcrList = biosMle.getRequiredManifestList();
    if (biosPcrList.isEmpty()) {
        throw new ASException(ErrorCode.AS_MISSING_MLE_REQD_MANIFEST_LIST, tblHosts.getBiosMleId().getName(), tblHosts.getBiosMleId().getVersion());
    }
    // Get the Vmm MLE without accessing cache
    TblMle vmmMle = new TblMleJpaController(getEntityManagerFactory()).findMleById(tblHosts.getVmmMleId().getId());
    String vmmPcrList = vmmMle.getRequiredManifestList();
    if (vmmPcrList == null || vmmPcrList.isEmpty()) {
        throw new ASException(ErrorCode.AS_MISSING_MLE_REQD_MANIFEST_LIST, tblHosts.getVmmMleId().getName(), tblHosts.getVmmMleId().getVersion());
    }
    return biosPcrList + "," + vmmPcrList;
}
Also used : TblMleJpaController(com.intel.mtwilson.as.controller.TblMleJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) ASException(com.intel.mountwilson.as.common.ASException)

Example 23 with ASException

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

the class MleBO method addPCRWhiteList.

/**
         * Added By: Sudhir on June 20, 2012
         * 
         * Processes the add request for a new PCR white list for the specified MLE.
         * 
         * @param pcrData: White list data sent by the user
         * @return : true if the call is successful or else exception.
         */
public String addPCRWhiteList(PCRWhiteList pcrData) {
    TblMle tblMle;
    TblPcrManifest tblPcr;
    try {
        tblMle = getMleDetails(pcrData.getMleName(), pcrData.getMleVersion(), pcrData.getOsName(), pcrData.getOsVersion(), pcrData.getOemName());
        if (tblMle == null && pcrData.getOemName() != null) {
            throw new ASException(ErrorCode.WS_MLE_OEM_DOES_NOT_EXIST, pcrData.getMleName(), pcrData.getMleVersion(), pcrData.getOemName());
        }
        if (tblMle == null && pcrData.getOsName() != null) {
            throw new ASException(ErrorCode.WS_MLE_OS_DOES_NOT_EXIST, pcrData.getMleName(), pcrData.getMleVersion(), pcrData.getOsName(), pcrData.getOsVersion());
        }
        // Now we need to check if PCR is already configured. If yes, then
        // we ned to ask the user to use the Update option instead of create
        tblPcr = getPCRWhiteListDetails(tblMle.getId(), pcrData.getPcrName());
        if (tblPcr != null) {
            throw new ASException(ErrorCode.WS_PCR_WHITELIST_ALREADY_EXISTS, pcrData.getPcrName());
        }
        /*
           if (StringUtils.isNotBlank(pcrData.getOemName())) {
               log.info("BIOS MLE, check the range of PCR value " + pcrData.getPcrName());
               if (Integer.valueOf(pcrData.getPcrName()).intValue() > 5 || Integer.valueOf(pcrData.getPcrName()).intValue() < 0)
                   throw new ASException(ErrorCode.WS_MLE_PCR_NOT_VALID, pcrData.getPcrName());
           } else {
               log.info("VMM MLE, check the range of PCR value " + pcrData.getPcrName());
               if (Integer.valueOf(pcrData.getPcrName()).intValue() > 20 || Integer.valueOf(pcrData.getPcrName()).intValue() < 17)
                   throw new ASException(ErrorCode.WS_MLE_PCR_NOT_VALID, pcrData.getPcrName());
           } */
        // In order to reuse the addPCRManifest function, we need to create a list and
        // add a single entry into it using the manifest data that we got.
        List<ManifestData> pcrWhiteList = new ArrayList<ManifestData>();
        pcrWhiteList.add(new ManifestData(pcrData.getPcrName(), pcrData.getPcrDigest()));
        // Now add the pcr to the database.
        addPcrManifest(tblMle, pcrWhiteList);
    } 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) ManifestData(com.intel.mtwilson.datatypes.ManifestData) 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 24 with ASException

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

the class MleBO method updateMleSource.

/**
    * Updates an existing MLE with the name of the white list host that was used to modify the white list values.
    * @param mleSourceObj
    * @return 
    */
public String updateMleSource(MleSource mleSourceObj) {
    TblMle tblMle;
    MleData mleData = null;
    try {
        try {
            mleData = mleSourceObj.getMleData();
            // Verify if the MLE exists in the system.
            tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        } catch (NoResultException nre) {
            throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, mleData.getName(), mleData.getVersion());
        }
        MwMleSourceJpaController mleSourceJpaController = new MwMleSourceJpaController(getEntityManagerFactory());
        // If the mapping does not exist already in the db, then we need to return back error.
        MwMleSource mwMleSource = mleSourceJpaController.findByMleId(tblMle.getId());
        if (mwMleSource == null) {
            throw new ASException(ErrorCode.WS_MLE_SOURCE_MAPPING_DOES_NOT_EXIST, mleData.getName());
        }
        mwMleSource.setHostName(mleSourceObj.getHostName());
        mleSourceJpaController.edit(mwMleSource);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : MwMleSourceJpaController(com.intel.mtwilson.as.controller.MwMleSourceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) MleData(com.intel.mtwilson.datatypes.MleData) NoResultException(javax.persistence.NoResultException) MwMleSource(com.intel.mtwilson.as.data.MwMleSource) 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 25 with ASException

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

the class MleBO method deleteMleSource.

/**
    * Deletes an existing mapping between the MLE and the WhiteList host that was used during the creation of MLE.
    * This method is called during the deletion of MLEs.
    * 
    * @param mleName
    * @param mleVersion
    * @param osName
    * @param osVersion
    * @param oemName
    * @return 
    */
public String deleteMleSource(String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    TblMle tblMle;
    try {
        try {
            // First check if the entry exists in the MLE table.
            tblMle = getMleDetails(mleName, mleVersion, osName, osVersion, oemName);
        } catch (NoResultException nre) {
            throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, mleName, mleVersion);
        }
        MwMleSourceJpaController mleSourceJpaController = new MwMleSourceJpaController(getEntityManagerFactory());
        MwMleSource mwMleSource = mleSourceJpaController.findByMleId(tblMle.getId());
        // configured manully, this entry does not exist.
        if (mwMleSource != null)
            mleSourceJpaController.destroy(mwMleSource.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : MwMleSourceJpaController(com.intel.mtwilson.as.controller.MwMleSourceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) NoResultException(javax.persistence.NoResultException) MwMleSource(com.intel.mtwilson.as.data.MwMleSource) 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)

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