本文整理汇总了Java中io.vertx.core.net.PemTrustOptions类的典型用法代码示例。如果您正苦于以下问题:Java PemTrustOptions类的具体用法?Java PemTrustOptions怎么用?Java PemTrustOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PemTrustOptions类属于io.vertx.core.net包,在下文中一共展示了PemTrustOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
@Override
public Handler<ClientOptionsBase> parse(
final JsonObject options) {
return Fn.get(() -> {
final PemTrustOptions pem = Fn.getSemi(
!options.containsKey(PATH_CERT), LOGGER,
Trust.CLIENT_PEM,
() -> new PemTrustOptions().addCertPath(PATH_CERT)
);
return option -> option
.setSsl(true)
.setUseAlpn(true)
.setPemTrustOptions(pem)
.setOpenSslEngineOptions(new OpenSSLEngineOptions());
}, options);
}
示例2: ex10
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
public void ex10(Vertx vertx) {
PgConnectOptions options = new PgConnectOptions()
.setPort(5432)
.setHost("the-host")
.setDatabase("the-db")
.setUsername("user")
.setPassword("secret")
.setSsl(true)
.setPemTrustOptions(new PemTrustOptions().addCertPath("/path/to/cert.pem"));
PgClient.connect(vertx, options, res -> {
if (res.succeeded()) {
// Connected with SSL
} else {
System.out.println("Could not connect " + res.cause());
}
});
}
示例3: testTLS
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
@Test
public void testTLS(TestContext ctx) {
Async async = ctx.async();
PgConnectOptions options = new PgConnectOptions(PgTestBase.options)
.setSsl(true)
.setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server.crt"));
PgClient.connect(vertx, new PgConnectOptions(options).setSsl(true).setTrustAll(true), ctx.asyncAssertSuccess(conn -> {
ctx.assertTrue(conn.isSSL());
conn.query("SELECT * FROM Fortune WHERE id=1", ctx.asyncAssertSuccess(result -> {
ctx.assertEquals(1, result.size());
Tuple row = result.iterator().next();
ctx.assertEquals(1, row.getInteger(0));
ctx.assertEquals("fortune: No such file or directory", row.getString(1));
async.complete();
}));
}));
}
示例4: setGrpcSslOptions
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
private void setGrpcSslOptions(TCPSSLOptions sslOptions) {
PemTrustOptions pemTrustOptions = new PemTrustOptions();
this.config.getSslTrustCerts()
.forEach(trustKey -> pemTrustOptions.addCertValue(Buffer.buffer(trustKey)));
sslOptions
.setSsl(true)
.setUseAlpn(true)
.setPemTrustOptions(pemTrustOptions);
final String sslCert = this.config.getSslCert();
final String sslKey = this.config.getSslKey();
if (sslKey != null && sslCert != null) {
PemKeyCertOptions pemKeyCertOptions = new PemKeyCertOptions()
.setKeyValue(Buffer.buffer(sslKey))
.setCertValue(Buffer.buffer(sslCert));
sslOptions.setPemKeyCertOptions(pemKeyCertOptions);
}
}
示例5: setSsl
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
private void setSsl(HttpServerOptions httpServerOptions) {
ApiConfig.SslConfig sslConfig = config.getSsl();
if (!sslConfig.isEnable()) {
return;
}
httpServerOptions.setSsl(true);
PemKeyCertOptions pemKeyCertOptions = new PemKeyCertOptions()
.setKeyValue(Buffer.buffer(sslConfig.getSslKey()))
.setCertValue(Buffer.buffer(sslConfig.getSslCert()));
httpServerOptions.setPemKeyCertOptions(pemKeyCertOptions);
PemTrustOptions pemTrustOptions = new PemTrustOptions();
Arrays.stream(sslConfig.getSslTrustCerts())
.map(Object::toString)
.forEach(trustKey -> pemTrustOptions.addCertValue(Buffer.buffer(trustKey)));
if (!pemTrustOptions.getCertValues().isEmpty()) {
httpServerOptions.setPemTrustOptions(pemTrustOptions);
ClientAuth clientAuth = sslConfig.isSslRequireClientAuth() ?
ClientAuth.REQUIRED : ClientAuth.REQUEST;
httpServerOptions.setClientAuth(clientAuth);
}
}
示例6: testLoginByCert_usingPemConfig
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
/**
* Tests authentication with the cert auth backend using PEM file
*/
@Test
public void testLoginByCert_usingPemConfig(TestContext tc) throws VaultException {
JsonObject config = new JsonObject();
config.put("host", process.getHost());
config.put("port", process.getPort());
config.put("ssl", true);
PemKeyCertOptions options = new PemKeyCertOptions()
.addCertPath("target/vault/config/ssl/client-cert.pem")
.addKeyPath("target/vault/config/ssl/client-privatekey.pem");
config.put("pemKeyCertOptions", options.toJson());
PemTrustOptions trust = new PemTrustOptions()
.addCertPath("target/vault/config/ssl/cert.pem");
config.put("pemTrustStoreOptions", trust.toJson());
JksOptions jks = new JksOptions()
.setPath("target/vault/config/ssl/truststore.jks");
config.put("trustStoreOptions", jks.toJson());
client = new SlimVaultClient(vertx, config);
checkWeCanLoginAndAccessRestrictedSecrets(tc);
}
示例7: getRetrieverConfiguration
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
@Override
protected JsonObject getRetrieverConfiguration() {
JsonObject config = new JsonObject();
config.put("host", process.getHost());
config.put("port", process.getPort());
config.put("ssl", true);
PemKeyCertOptions options = new PemKeyCertOptions()
.addCertPath("target/vault/config/ssl/client-cert.pem")
.addKeyPath("target/vault/config/ssl/client-privatekey.pem");
config.put("pemKeyCertOptions", options.toJson());
PemTrustOptions trust = new PemTrustOptions()
.addCertPath("target/vault/config/ssl/cert.pem");
config.put("pemTrustStoreOptions", trust.toJson());
JksOptions jks = new JksOptions()
.setPath("target/vault/config/ssl/truststore.jks");
config.put("trustStoreOptions", jks.toJson());
config.put("auth-backend", "cert");
return config;
}
示例8: createClientOptions
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
/**
* Create an options instance for the ProtonClient
*
* @return ProtonClient options instance
*/
private ProtonClientOptions createClientOptions() {
ProtonClientOptions options = new ProtonClientOptions();
options.setConnectTimeout(5000);
options.setReconnectAttempts(-1).setReconnectInterval(1000); // reconnect forever, every 1000 millisecs
if (certDir != null) {
options.setSsl(true)
.addEnabledSaslMechanism("EXTERNAL")
.setHostnameVerificationAlgorithm("")
.setPemTrustOptions(new PemTrustOptions()
.addCertPath(new File(certDir, "ca.crt").getAbsolutePath()))
.setPemKeyCertOptions(new PemKeyCertOptions()
.addCertPath(new File(certDir, "tls.crt").getAbsolutePath())
.addKeyPath(new File(certDir, "tls.key").getAbsolutePath()));
}
return options;
}
示例9: createClientOptions
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
/**
* Create an options instance for the ProtonClient
*
* @return ProtonClient options instance
*/
private ProtonClientOptions createClientOptions() {
ProtonClientOptions options = new ProtonClientOptions();
options.setConnectTimeout(1000);
options.setReconnectAttempts(-1).setReconnectInterval(1000); // reconnect forever, every 1000 millisecs
if (this.bridgeConfigProperties.getEndpointConfigProperties().getCertDir() != null && this.bridgeConfigProperties.getEndpointConfigProperties().getCertDir().length() > 0) {
String certDir = this.bridgeConfigProperties.getEndpointConfigProperties().getCertDir();
log.info("Enabling SSL configuration for AMQP with TLS certificates from {}", certDir);
options.setSsl(true)
.addEnabledSaslMechanism("EXTERNAL")
.setHostnameVerificationAlgorithm("")
.setPemTrustOptions(new PemTrustOptions()
.addCertPath(new File(certDir, "ca.crt").getAbsolutePath()))
.setPemKeyCertOptions(new PemKeyCertOptions()
.addCertPath(new File(certDir, "tls.crt").getAbsolutePath())
.addKeyPath(new File(certDir, "tls.key").getAbsolutePath()));
}
return options;
}
示例10: connect
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
@Override
public void connect(String username, String password, Handler<AsyncResult<Client>> connectHandler) {
MqttClientOptions options =
new MqttClientOptions()
.setUsername(username)
.setPassword(password);
if (this.serverCert != null && !this.serverCert.isEmpty()) {
options.setSsl(true)
.setHostnameVerificationAlgorithm("")
.setPemTrustOptions(new PemTrustOptions().addCertPath(this.serverCert));
}
this.client = io.vertx.mqtt.MqttClient.create(vertx, options);
this.client.connect(this.port, this.hostname, done -> {
if (done.succeeded()) {
log.info("Connected to {}:{}", this.hostname, this.port);
this.client.publishHandler(m -> {
MessageDelivery messageDelivery = new MessageDelivery(m.topicName(), m.payload().getBytes());
this.receivedHandler.handle(messageDelivery);
});
this.client.subscribeCompletionHandler(suback -> {
log.info("Subscription [{}], granted QoS levels {}", suback.messageId(), suback.grantedQoSLevels());
});
connectHandler.handle(Future.succeededFuture(this));
} else {
log.error("Error connecting to the service", done.cause());
connectHandler.handle(Future.failedFuture(done.cause()));
}
});
}
示例11: getTrustOptions
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
/**
* Gets the trust options derived from the trust store properties.
*
* @return The trust options or {@code null} if trust store path is not set or not supported.
*/
public final TrustOptions getTrustOptions() {
if (trustStorePath == null) {
return null;
}
final FileFormat format = FileFormat.orDetect(trustStoreFormat, trustStorePath);
if (format == null) {
LOG.debug("unsupported trust store format");
return null;
}
switch (format) {
case PEM:
LOG.debug("using certificates from file [{}] as trust anchor", trustStorePath);
return new PemTrustOptions().addCertPath(trustStorePath);
case PKCS12:
LOG.debug("using certificates from PKCS12 key store [{}] as trust anchor", trustStorePath);
return new PfxOptions()
.setPath(getTrustStorePath())
.setPassword(getTrustStorePassword());
case JKS:
LOG.debug("using certificates from JKS key store [{}] as trust anchor", trustStorePath);
return new JksOptions()
.setPath(getTrustStorePath())
.setPassword(getTrustStorePassword());
default:
LOG.debug("unsupported trust store format: {}", format);
return null;
}
}
示例12: exampleWithCerts
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
public void exampleWithCerts(Vertx vertx) {
JsonObject vault_config = new JsonObject();
// ...
PemKeyCertOptions certs = new PemKeyCertOptions()
.addCertPath("target/vault/config/ssl/client-cert.pem")
.addKeyPath("target/vault/config/ssl/client-privatekey.pem");
vault_config.put("pemKeyCertOptions", certs.toJson());
PemTrustOptions trust = new PemTrustOptions()
.addCertPath("target/vault/config/ssl/cert.pem");
vault_config.put("pemTrustStoreOptions", trust.toJson());
JksOptions jks = new JksOptions()
.setPath("target/vault/config/ssl/truststore.jks");
vault_config.put("trustStoreOptions", jks.toJson());
vault_config.put("auth-backend", "cert");
// Path to the secret to read.
vault_config.put("path", "secret/my-secret");
ConfigStoreOptions store = new ConfigStoreOptions()
.setType("vault")
.setConfig(vault_config);
ConfigRetriever retriever = ConfigRetriever.create(vertx,
new ConfigRetrieverOptions().addStore(store));
}
示例13: createClientOptions
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
private static ProtonClientOptions createClientOptions(String certDir)
{
ProtonClientOptions options = new ProtonClientOptions();
if (certDir != null) {
options.setSsl(true)
.setHostnameVerificationAlgorithm("")
.setPemTrustOptions(new PemTrustOptions()
.addCertPath(new File(certDir, "ca.crt").getAbsolutePath()))
.setPemKeyCertOptions(new PemKeyCertOptions()
.setCertPath(new File(certDir, "tls.crt").getAbsolutePath())
.setKeyPath(new File(certDir, "tls.key").getAbsolutePath()));
}
return options;
}
示例14: getOptions
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
private ProtonClientOptions getOptions() {
ProtonClientOptions options = new ProtonClientOptions();
if (certDir != null) {
options.setHostnameVerificationAlgorithm("")
.setSsl(true)
.addEnabledSaslMechanism("EXTERNAL")
.setHostnameVerificationAlgorithm("")
.setPemTrustOptions(new PemTrustOptions()
.addCertPath(new File(certDir, "ca.crt").getAbsolutePath()))
.setPemKeyCertOptions(new PemKeyCertOptions()
.setCertPath(new File(certDir, "tls.crt").getAbsolutePath())
.setKeyPath(new File(certDir, "tls.key").getAbsolutePath()));
}
return options;
}
示例15: createOptionsForTls
import io.vertx.core.net.PemTrustOptions; //导入依赖的package包/类
private static ProtonServerOptions createOptionsForTls(final String certDir) {
ProtonServerOptions options = new ProtonServerOptions();
PemKeyCertOptions pemKeyCertOptions = new PemKeyCertOptions();
pemKeyCertOptions.setCertPath(certDir + File.separator + "tls.crt");
pemKeyCertOptions.setKeyPath(certDir + File.separator + "tls.key");
options.setPemKeyCertOptions(pemKeyCertOptions);
options.setClientAuth(ClientAuth.REQUIRED);
options.setSsl(true);
PemTrustOptions pemTrustOptions = new PemTrustOptions();
pemTrustOptions.addCertPath(certDir + File.separator + "ca.crt");
options.setPemTrustOptions(pemTrustOptions);
return options;
}