Search in sources :

Example 61 with ASException

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

the class OemBO method getAllOem.

/**
     * 
     * @return 
     */
public List<OemData> getAllOem() {
    List<OemData> allOemData = new ArrayList<OemData>();
    try {
        List<TblOem> allRecords = tblOemJpaController.findTblOemEntities();
        for (TblOem tblOem : allRecords) {
            OemData oemData = new OemData(tblOem.getName(), tblOem.getDescription());
            allOemData.add(oemData);
        }
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return allOemData;
}
Also used : OemData(com.intel.mtwilson.datatypes.OemData) TblOem(com.intel.mtwilson.as.data.TblOem) ArrayList(java.util.ArrayList) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException)

Example 62 with ASException

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

the class OsBO method getAllOs.

/**
     * 
     * @return 
     */
public List<OsData> getAllOs() {
    List<OsData> allOsData = new ArrayList<OsData>();
    try {
        List<TblOs> allRecords = tblOsJpaController.findTblOsEntities();
        for (TblOs tblOs : allRecords) {
            OsData osData = new OsData(tblOs.getName(), tblOs.getVersion(), tblOs.getDescription());
            allOsData.add(osData);
        }
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return allOsData;
}
Also used : ArrayList(java.util.ArrayList) OsData(com.intel.mtwilson.datatypes.OsData) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) TblOs(com.intel.mtwilson.as.data.TblOs)

Example 63 with ASException

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

the class CitrixClient method connect.

public void connect() throws NoSuchAlgorithmException, KeyManagementException, BadServerResponse, XenAPIException, XmlRpcException, XmlRpcException {
    URL url = null;
    try {
        url = new URL("https://" + hostIpAddress + ":" + port);
    } catch (MalformedURLException e) {
        throw new ASException(e, ErrorCode.AS_HOST_COMMUNICATION_ERROR, hostIpAddress);
    }
    TrustManager[] trustAllCerts = new TrustManager[] { tlsConnection.getTlsPolicy().getTrustManager() };
    // Install the all-trusting trust manager  
    SSLContext sc = SSLContext.getInstance("SSL");
    // Create empty HostnameVerifier  
    HostnameVerifier hv = tlsConnection.getTlsPolicy().getHostnameVerifier();
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
    connection = new Connection(url);
    Session.loginWithPassword(connection, userName, password, APIVersion.latest().toString());
}
Also used : SecureRandom(java.security.SecureRandom) MalformedURLException(java.net.MalformedURLException) TlsConnection(com.intel.mtwilson.tls.TlsConnection) Connection(com.xensource.xenapi.Connection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) SSLContext(javax.net.ssl.SSLContext) URL(java.net.URL) ASException(com.intel.mountwilson.as.common.ASException) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 64 with ASException

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

the class CitrixClient method getQuoteInformationForHost.

public HashMap<String, PcrManifest> getQuoteInformationForHost(String pcrList) {
    log.debug("getQuoteInformationForHost pcrList == " + pcrList);
    try {
        // We cannot reuse the connections across different calls since they are tied to a particular host.
        if (!isConnected()) {
            connect();
        }
        String nonce = generateNonce();
        String sessionId = generateSessionId();
        // We do not need to connect again. So, commenting it out.
        // System.err.println("stdalex-error connecting with " + userName + " " + password);
        // Session.loginWithPassword(connection, userName, password, APIVersion.latest().toString());
        // System.err.println( "CitrixClient: connected to server ["+hostIpAddress+"]");	
        Map<String, String> myMap = new HashMap<String, String>();
        Set<Host> hostList = Host.getAll(connection);
        Iterator iter = hostList.iterator();
        // hasNext() will always be valid otherwise we will get an exception from the getAll method. So, we not need
        // to throw an exception if the hasNext is false.
        Host h = null;
        if (iter.hasNext()) {
            h = (Host) iter.next();
        }
        String aik = h.callPlugin(connection, "tpm", "tpm_get_attestation_identity", myMap);
        int startP = aik.indexOf("<xentxt:TPM_Attestation_KEY_PEM>");
        int endP = aik.indexOf("</xentxt:TPM_Attestation_KEY_PEM>");
        // 32 is the size of the opening tag  <xentxt:TPM_Attestation_KEY_PEM>
        String cert = aik.substring(startP + "<xentxt:TPM_Attestation_KEY_PEM>".length(), endP);
        keys key = new keys();
        // This is the actual value for AIK!!!!!
        key.tpmAttKeyPEM = cert;
        String aikCertificate = key.tpmAttKeyPEM;
        myMap = new HashMap<String, String>();
        myMap.put("nonce", nonce);
        String quote = h.callPlugin(connection, "tpm", "tpm_get_quote", myMap);
        log.debug("extracted quote from response: " + quote);
        //saveFile(getCertFileName(sessionId), Base64.decodeBase64(aikCertificate));
        saveFile(getCertFileName(sessionId), aikCertificate.getBytes());
        log.debug("saved certificate with session id: " + sessionId);
        saveQuote(quote, sessionId);
        log.debug("saved quote with session id: " + sessionId);
        saveNonce(nonce, sessionId);
        log.debug("saved nonce with session id: " + sessionId);
        //createRSAKeyFile(sessionId);
        log.debug("created RSA key file for session id: " + sessionId);
        HashMap<String, PcrManifest> pcrMap = verifyQuoteAndGetPcr(sessionId, pcrList);
        log.debug("Got PCR map");
        return pcrMap;
    } catch (ASException e) {
        throw e;
    //        } catch(UnknownHostException e) {
    //            throw new ASException(e,ErrorCode.AS_HOST_COMMUNICATION_ERROR, hostIpAddress);
    } catch (Exception e) {
        log.debug("caught exception during login: " + e.toString() + " class: " + e.getClass());
        throw new ASException(e, ErrorCode.AS_CITRIX_ERROR, e.toString());
    }
}
Also used : HashMap(java.util.HashMap) Host(com.xensource.xenapi.Host) ASException(com.intel.mountwilson.as.common.ASException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) Iterator(java.util.Iterator) ASException(com.intel.mountwilson.as.common.ASException)

Example 65 with ASException

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

the class OsBO method updateOs.

/**
     * 
     * @param osData
     * @return 
     */
public String updateOs(OsData osData) {
    try {
        TblOs tblOs = tblOsJpaController.findTblOsByNameVersion(osData.getName(), osData.getVersion());
        if (tblOs == null) {
            throw new ASException(ErrorCode.WS_OS_DOES_NOT_EXIST, osData.getName(), osData.getVersion());
        }
        tblOs.setDescription(osData.getDescription());
        tblOsJpaController.edit(tblOs);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) 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