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();
}
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;
}
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);
}
}
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()));
}
Aggregations