Search in sources :

Example 1 with CertificateResponse

use of org.apache.cloudstack.api.response.CertificateResponse in project cloudstack by apache.

the class IssueCertificateCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    if (StringUtils.isEmpty(getCsr()) && getDomains().isEmpty()) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please provide the domains or the CSR, none of them are provided");
    }
    final Certificate certificate = caManager.issueCertificate(getCsr(), getDomains(), getAddresses(), getValidityDuration(), getProvider());
    if (certificate == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to issue client certificate with given provider");
    }
    final CertificateResponse certificateResponse = new CertificateResponse();
    try {
        certificateResponse.setCertificate(CertUtils.x509CertificateToPem(certificate.getClientCertificate()));
        if (certificate.getPrivateKey() != null) {
            certificateResponse.setPrivateKey(CertUtils.privateKeyToPem(certificate.getPrivateKey()));
        }
        if (certificate.getCaCertificates() != null) {
            certificateResponse.setCaCertificate(CertUtils.x509CertificatesToPem(certificate.getCaCertificates()));
        }
    } catch (final IOException e) {
        LOG.error("Failed to generate and convert client certificate(s) to PEM due to error: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to process and return client certificate");
    }
    certificateResponse.setResponseName(getCommandName());
    setResponseObject(certificateResponse);
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) CertificateResponse(org.apache.cloudstack.api.response.CertificateResponse) IOException(java.io.IOException) Certificate(org.apache.cloudstack.framework.ca.Certificate)

Example 2 with CertificateResponse

use of org.apache.cloudstack.api.response.CertificateResponse in project cloudstack by apache.

the class ListCaCertificateCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final String caCertificates;
    try {
        caCertificates = caManager.getCaCertificate(getProvider());
    } catch (final IOException e) {
        throw new CloudRuntimeException("Failed to get CA certificates for given CA provider");
    }
    final CertificateResponse certificateResponse = new CertificateResponse("cacertificates");
    certificateResponse.setCertificate(caCertificates);
    certificateResponse.setResponseName(getCommandName());
    setResponseObject(certificateResponse);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CertificateResponse(org.apache.cloudstack.api.response.CertificateResponse) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 CertificateResponse (org.apache.cloudstack.api.response.CertificateResponse)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 Certificate (org.apache.cloudstack.framework.ca.Certificate)1