Search in sources :

Example 1 with CertificateInfo

use of org.ovirt.engine.core.common.businessentities.CertificateInfo in project ovirt-engine by oVirt.

the class BackendExternalProviderCertificateResource method get.

@Override
public Certificate get() {
    // The resource identifier is actually the index of the certificate in the chain:
    int i;
    try {
        i = Integer.parseInt(id);
    } catch (NumberFormatException exception) {
        return notFound();
    }
    // The backend doesn't have a mechanism to retrieve just one of the certificates of the chain, so we have to
    // retrieve them all and find the one that matches the identifier:
    Provider provider = BackendExternalProviderHelper.getProvider(this, providerId);
    ProviderQueryParameters parameters = new ProviderQueryParameters();
    parameters.setProvider(provider);
    List<CertificateInfo> entities = getBackendCollection(CertificateInfo.class, QueryType.GetProviderCertificateChain, parameters);
    if (entities != null && i >= 0 && i < entities.size()) {
        CertificateInfo entity = entities.get(i);
        Certificate model = populate(map(entity), entity);
        model.setId(id);
        return model;
    }
    // No luck:
    return notFound();
}
Also used : ProviderQueryParameters(org.ovirt.engine.core.common.queries.ProviderQueryParameters) CertificateInfo(org.ovirt.engine.core.common.businessentities.CertificateInfo) Provider(org.ovirt.engine.core.common.businessentities.Provider) Certificate(org.ovirt.engine.api.model.Certificate)

Example 2 with CertificateInfo

use of org.ovirt.engine.core.common.businessentities.CertificateInfo in project ovirt-engine by oVirt.

the class BackendExternalProviderCertificatesResource method mapCollection.

protected Certificates mapCollection(List<CertificateInfo> entities) {
    Certificates collection = new Certificates();
    if (entities != null) {
        for (int i = 0; i < entities.size(); i++) {
            CertificateInfo entity = entities.get(i);
            Certificate model = populate(map(entity), entity);
            model.setId(String.valueOf(i));
            collection.getCertificates().add(model);
        }
    }
    return collection;
}
Also used : Certificates(org.ovirt.engine.api.model.Certificates) CertificateInfo(org.ovirt.engine.core.common.businessentities.CertificateInfo) Certificate(org.ovirt.engine.api.model.Certificate)

Example 3 with CertificateInfo

use of org.ovirt.engine.core.common.businessentities.CertificateInfo in project ovirt-engine by oVirt.

the class GetProviderCertificateChainQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Provider<?> provider = getProvider();
    try {
        ProviderProxy proxy = providerProxyFactory.create(provider);
        List<? extends Certificate> chain = proxy.getCertificateChain();
        List<CertificateInfo> results = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(chain)) {
            for (Certificate cert : chain) {
                if (cert instanceof X509Certificate) {
                    results.add(createCertificateInfo((X509Certificate) cert));
                }
            }
        }
        getQueryReturnValue().setReturnValue(results);
    } catch (Exception e) {
        log.error("Error in encoding certificate: {}", e.getMessage());
        log.debug("Exception", e);
    }
}
Also used : ArrayList(java.util.ArrayList) CertificateInfo(org.ovirt.engine.core.common.businessentities.CertificateInfo) ProviderProxy(org.ovirt.engine.core.bll.provider.ProviderProxy) X509Certificate(java.security.cert.X509Certificate) GeneralSecurityException(java.security.GeneralSecurityException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 4 with CertificateInfo

use of org.ovirt.engine.core.common.businessentities.CertificateInfo in project ovirt-engine by oVirt.

the class GetProviderCertificateChainQuery method createCertificateInfo.

private CertificateInfo createCertificateInfo(X509Certificate cert) throws GeneralSecurityException {
    MessageDigest sha1 = MessageDigest.getInstance("SHA1");
    sha1.update(cert.getEncoded());
    boolean selfSigned = false;
    try {
        cert.verify(cert.getPublicKey());
        selfSigned = true;
    } catch (GeneralSecurityException e) {
    // ignore
    }
    return new CertificateInfo(new Base64(0).encodeToString(cert.getEncoded()), cert.getSubjectX500Principal().toString(), cert.getIssuerX500Principal().toString(), selfSigned, Hex.encodeHexString(sha1.digest()));
}
Also used : Base64(org.apache.commons.codec.binary.Base64) GeneralSecurityException(java.security.GeneralSecurityException) CertificateInfo(org.ovirt.engine.core.common.businessentities.CertificateInfo) MessageDigest(java.security.MessageDigest)

Aggregations

CertificateInfo (org.ovirt.engine.core.common.businessentities.CertificateInfo)4 GeneralSecurityException (java.security.GeneralSecurityException)2 Certificate (org.ovirt.engine.api.model.Certificate)2 MessageDigest (java.security.MessageDigest)1 Certificate (java.security.cert.Certificate)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 Base64 (org.apache.commons.codec.binary.Base64)1 Certificates (org.ovirt.engine.api.model.Certificates)1 ProviderProxy (org.ovirt.engine.core.bll.provider.ProviderProxy)1 Provider (org.ovirt.engine.core.common.businessentities.Provider)1 ProviderQueryParameters (org.ovirt.engine.core.common.queries.ProviderQueryParameters)1