Search in sources :

Example 16 with Hostname

use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.

the class DemoPortalServicesImpl method deleteHostDetails.

/**
	 * This method will delete HOST information from Services.
	 * Also it will delete all entry from HOST VM Mapping information for that host, which is used to store Policy of VM.  
	 * 
	 * @param hostID
	 * @param hostName
	 * @param apiClientServices
	 * @param vmMappingData
	 * @return
	 * @throws DemoPortalException
	 */
@Override
public boolean deleteHostDetails(String hostID, String hostName, AttestationService apiClientServices) throws DemoPortalException {
    boolean result = false;
    try {
        //Call to Services to delete HOST.
        apiClientServices.deleteHost(new Hostname(hostName));
        result = true;
    } catch (Exception e) {
        log.error("Errror While Deleting Host.");
        throw ConnectionUtil.handleException(e);
    }
    return result;
}
Also used : Hostname(com.intel.mtwilson.util.net.Hostname) ApiException(com.intel.mtwilson.ApiException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) DemoPortalException(com.intel.mountwilson.common.DemoPortalException)

Example 17 with Hostname

use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.

the class DemoPortalServicesImpl method trustVerificationDetails.

/**
	 * This method is used to get SAML Assertion data for a Host.
	 * This data is shown in pop-up window when user click on trust details button in Home page to TrustDashBoard.
	 * 
	 * @param hostName
	 * @param apiClientServices
	 * @param trustedCertificates
	 * @return
	 * @throws DemoPortalException
     * @throws java.io.IOException
     * @throws com.intel.mtwilson.ApiException
	 */
@Override
public String trustVerificationDetails(String hostName, AttestationService apiClientServices, X509Certificate[] trustedCertificates) throws DemoPortalException {
    //return ConverterUtil.formateXMLString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<error>Not implemented</error>\n");
    Set<Hostname> hostnames = new HashSet<Hostname>();
    hostnames.add(new Hostname(hostName));
    try {
        return ConverterUtil.formateXMLString(apiClientServices.getSamlForMultipleHosts(hostnames, true));
    } catch (IOException | ApiException | SignatureException e) {
        log.error(e.getMessage());
        return ConverterUtil.formateXMLString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<error>Not implemented</error>\n");
    }
//        log.info("DemoPortalServicesImpl.trustVerificationDetails >>");
//	    String xmloutput = null;
//            Set<Hostname> hostnames = new HashSet<Hostname>();
//            //log.info("<<<<<<Hostname: " + hostName + ">>>>>>>");
//            hostnames.add(new Hostname(hostName));
//            try {
//                //calling into Services to get SAML for a Host.
//                List<HostTrustXmlResponse> trust = apiClientServices.getSamlForMultipleHosts(hostnames, false);
//
//                for (HostTrustXmlResponse hostTrustXmlResponse : trust) {
//                    if(trustedCertificates != null)
//                        log.info("TrustCertificates: " + trustedCertificates.toString());
//                    else
//                        log.info("TrustCertificates is null");
//                    if(hostTrustXmlResponse != null)
//                        log.info("HostTrustXMLResponse: " + hostTrustXmlResponse.getAssertion());
//                    else
//                        log.info("HostTrustXMLResponse is null");
//                    
//                    TrustAssertion trustAssertion = new TrustAssertion(trustedCertificates, hostTrustXmlResponse.getAssertion());
//                    
//                    if(trustAssertion != null)
//                        log.info("TrustAssertion: " + trustAssertion.toString());
//                    else
//                        log.info("TrustAssertion is null");
//                    if (trustAssertion.isValid()) {
//                        //Store SAML Assertion into a String.
//                        xmloutput = hostTrustXmlResponse.getAssertion();
//                    } else {
//                        log.error("Error While Getting SAML ." + hostTrustXmlResponse.getErrorCode() + ". " + hostTrustXmlResponse.getErrorMessage());
//                        throw new DemoPortalException("Error While Getting SAML. " + hostTrustXmlResponse.getErrorCode() + ". " + hostTrustXmlResponse.getErrorMessage());
//                    }
//                }
//            } catch (Exception e) {
//                log.error(e.getMessage());
//                e.printStackTrace();
//                throw ConnectionUtil.handleDemoPortalException(e);
//            }
//format a SAML String into a XML type using helper Function.
//            return ConverterUtil.formateXMLString(xmloutput);
}
Also used : Hostname(com.intel.mtwilson.util.net.Hostname) IOException(java.io.IOException) SignatureException(java.security.SignatureException) HashSet(java.util.HashSet) ApiException(com.intel.mtwilson.ApiException)

Example 18 with Hostname

use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.

the class DemoPortalServicesImpl method getSingleHostTrust.

/**
	 * This Method is used to get Trust Status for Single Host.
	 * 
	 * @param hostName
	 * @param apiClientServices
	 * @param trustedCertificates
	 * @return
	 * @throws DemoPortalException
	 */
@Override
public TrustedHostVO getSingleHostTrust(String hostName, AttestationService apiClientServices, X509Certificate[] trustedCertificates, boolean forceVerify) throws DemoPortalException {
    TrustedHostVO hostVO = null;
    HostDetailsEntityVO hostDetailsEntityVO = new HostDetailsEntityVO();
    hostDetailsEntityVO.setHostName(hostName);
    String xmloutput = null;
    HostTrustResponse hostTrustResponse = null;
    try {
        log.info("Getting trust Information for Host " + hostName);
        //xmloutput = apiClientServices.getSamlForHost(new Hostname(hostName), false);
        // forceVerify=false when loading dashboard, it is true when refreshing host (Refresh button)
        xmloutput = apiClientServices.getSamlForHost(new Hostname(hostName), forceVerify);
        TrustAssertion trustAssertion = new TrustAssertion(trustedCertificates, xmloutput);
        HostTrustAssertion hostTrustAssertion = trustAssertion.getTrustAssertion(hostName);
        //Set<Hostname> hostnames = new HashSet<Hostname>();
        //hostnames.add(new Hostname(hostName));
        //xmloutput = ConverterUtil.formateXMLString(apiClientServices.getSamlForMultipleHosts(hostnames, false));
        hostTrustResponse = apiClientServices.getHostTrust(new Hostname(hostDetailsEntityVO.getHostName()));
        List<TxtHostRecord> hosts = apiClientServices.queryForHosts(hostDetailsEntityVO.getHostName());
        TxtHostRecord txtHostRecord = null;
        for (TxtHostRecord record : hosts) {
            if (record.HostName.equals(hostDetailsEntityVO.getHostName())) {
                txtHostRecord = record;
            }
        }
        hostVO = ConverterUtil.getTrustedHostVoFromHostTrustResponseAndTxtHostRecord(hostTrustResponse, txtHostRecord, hostTrustAssertion);
    } catch (Exception e) {
        hostVO = ConverterUtil.getTrustedHostVoFromHostTrustResponseAndErrorMessage(hostName, e.getMessage());
    }
    return hostVO;
}
Also used : TxtHostRecord(com.intel.mtwilson.datatypes.TxtHostRecord) HostDetailsEntityVO(com.intel.mountwilson.datamodel.HostDetailsEntityVO) HostTrustResponse(com.intel.mtwilson.datatypes.HostTrustResponse) TrustAssertion(com.intel.mtwilson.saml.TrustAssertion) HostTrustAssertion(com.intel.mtwilson.saml.TrustAssertion.HostTrustAssertion) Hostname(com.intel.mtwilson.util.net.Hostname) TrustedHostVO(com.intel.mountwilson.datamodel.TrustedHostVO) HostTrustAssertion(com.intel.mtwilson.saml.TrustAssertion.HostTrustAssertion) ApiException(com.intel.mtwilson.ApiException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) DemoPortalException(com.intel.mountwilson.common.DemoPortalException)

Example 19 with Hostname

use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.

the class DemoPortalServicesImpl method getFailureReportData.

/**
	 * This method is used to get failure report for Host. 
	 * 
	 * @param hostName
	 * @param attestationService
	 * @return
	 * @throws DemoPortalException
	 * @throws Exception
	 */
@Override
public List<PcrLogReport> getFailureReportData(String hostName, ApiClient attestationService) throws Exception {
    log.info("DemoPortalServicesImpl.getFailureReportData >>");
    AttestationReport report;
    try {
        report = attestationService.getAttestationReport(new Hostname(hostName));
    } catch (Exception e) {
        log.error(e.getMessage());
        throw ConnectionUtil.handleException(e);
    }
    return report.getPcrLogs();
}
Also used : AttestationReport(com.intel.mtwilson.datatypes.AttestationReport) Hostname(com.intel.mtwilson.util.net.Hostname) ApiException(com.intel.mtwilson.ApiException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) DemoPortalException(com.intel.mountwilson.common.DemoPortalException)

Example 20 with Hostname

use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.

the class DemoPortalServicesImpl method updateHostData.

/**
	 * This method is used to Update Host information, which was already configure.
	 * 
	 * @param dataVO
	 * @param apiClientServices
	 * @return
	 * @throws DemoPortalException
	 */
@Override
public boolean updateHostData(HostDetailsEntityVO dataVO, AttestationService apiClientServices) throws DemoPortalException {
    boolean result = false;
    try {
        //Call to Services to Update pre-configure host information.
        apiClientServices.updateHost(ConverterUtil.getTxtHostFromHostVO(dataVO));
        // Updating the SAML host report
        apiClientServices.getSamlForHost(new Hostname(dataVO.getHostName()), true);
        result = true;
    } catch (Exception e) {
        log.error("Errror While Updating Host.");
        throw ConnectionUtil.handleException(e);
    }
    return result;
}
Also used : Hostname(com.intel.mtwilson.util.net.Hostname) ApiException(com.intel.mtwilson.ApiException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) DemoPortalException(com.intel.mountwilson.common.DemoPortalException)

Aggregations

Hostname (com.intel.mtwilson.util.net.Hostname)30 Test (org.junit.Test)15 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 TblTaLog (com.intel.mtwilson.as.data.TblTaLog)7 ApiException (com.intel.mtwilson.ApiException)6 SignatureException (java.security.SignatureException)6 DemoPortalException (com.intel.mountwilson.common.DemoPortalException)5 TblHosts (com.intel.mtwilson.as.data.TblHosts)5 Date (java.util.Date)5 ASException (com.intel.mountwilson.as.common.ASException)4 HostsTrustReportType (com.intel.mountwilson.as.hosttrustreport.data.HostsTrustReportType)4 Matchers.anyString (org.mockito.Matchers.anyString)4 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)3 UnknownHostException (java.net.UnknownHostException)3 HostType (com.intel.mountwilson.as.hosttrustreport.data.HostType)2 AttestationReport (com.intel.mtwilson.datatypes.AttestationReport)2 HostTrustResponse (com.intel.mtwilson.datatypes.HostTrustResponse)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2