use of io.vertx.core.net.TrustOptions in project vert.x by eclipse.
the class SSLHelper method getTrustMgrFactory.
private TrustManagerFactory getTrustMgrFactory(VertxInternal vertx) throws Exception {
TrustManagerFactory fact;
if (trustAll) {
TrustManager[] mgrs = new TrustManager[] { createTrustAllTrustManager() };
fact = new VertxTrustManagerFactory(mgrs);
} else if (trustOptions != null) {
fact = trustOptions.getTrustManagerFactory(vertx);
} else {
return null;
}
if (crlPaths != null && crlValues != null && (crlPaths.size() > 0 || crlValues.size() > 0)) {
Stream<Buffer> tmp = crlPaths.stream().map(path -> vertx.resolveFile(path).getAbsolutePath()).map(vertx.fileSystem()::readFileBlocking);
tmp = Stream.concat(tmp, crlValues.stream());
CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
ArrayList<CRL> crls = new ArrayList<>();
for (Buffer crlValue : tmp.collect(Collectors.toList())) {
crls.addAll(certificatefactory.generateCRLs(new ByteArrayInputStream(crlValue.getBytes())));
}
TrustManager[] mgrs = createUntrustRevokedCertTrustManager(fact.getTrustManagers(), crls);
fact = new VertxTrustManagerFactory(mgrs);
}
return fact;
}
use of io.vertx.core.net.TrustOptions in project hono by eclipse.
the class AbstractServiceBase method addTlsTrustOptions.
/**
* Copies TLS trust store configuration to a given set of server options.
* <p>
* The trust store configuration is taken from <em>config</em> and will
* be added only if the <em>ssl</em> flag is set on the given server options.
*
* @param serverOptions The options to add configuration to.
*/
protected final void addTlsTrustOptions(final NetServerOptions serverOptions) {
if (serverOptions.isSsl() && serverOptions.getTrustOptions() == null) {
TrustOptions trustOptions = getConfig().getTrustOptions();
if (trustOptions != null) {
serverOptions.setTrustOptions(trustOptions).setClientAuth(ClientAuth.REQUEST);
LOG.info("enabling TLS for client authentication");
}
}
}
use of io.vertx.core.net.TrustOptions in project vert.x by eclipse.
the class SSLHelper method getTrustMgrFactory.
private TrustManagerFactory getTrustMgrFactory(VertxInternal vertx, String serverName) throws Exception {
TrustManager[] mgrs = null;
if (trustAll) {
mgrs = new TrustManager[] { createTrustAllTrustManager() };
} else if (trustOptions != null) {
if (serverName != null) {
Function<String, TrustManager[]> mapper = trustOptions.trustManagerMapper(vertx);
if (mapper != null) {
mgrs = mapper.apply(serverName);
}
if (mgrs == null) {
TrustManagerFactory fact = trustOptions.getTrustManagerFactory(vertx);
if (fact != null) {
mgrs = fact.getTrustManagers();
}
}
} else {
TrustManagerFactory fact = trustOptions.getTrustManagerFactory(vertx);
if (fact != null) {
mgrs = fact.getTrustManagers();
}
}
}
if (mgrs == null) {
return null;
}
if (crlPaths != null && crlValues != null && (crlPaths.size() > 0 || crlValues.size() > 0)) {
Stream<Buffer> tmp = crlPaths.stream().map(path -> vertx.resolveFile(path).getAbsolutePath()).map(vertx.fileSystem()::readFileBlocking);
tmp = Stream.concat(tmp, crlValues.stream());
CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
ArrayList<CRL> crls = new ArrayList<>();
for (Buffer crlValue : tmp.collect(Collectors.toList())) {
crls.addAll(certificatefactory.generateCRLs(new ByteArrayInputStream(crlValue.getBytes())));
}
mgrs = createUntrustRevokedCertTrustManager(mgrs, crls);
}
return new VertxTrustManagerFactory(mgrs);
}
Aggregations