本文整理汇总了Java中io.vertx.core.net.PemKeyCertOptions类的典型用法代码示例。如果您正苦于以下问题:Java PemKeyCertOptions类的具体用法?Java PemKeyCertOptions怎么用?Java PemKeyCertOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PemKeyCertOptions类属于io.vertx.core.net包,在下文中一共展示了PemKeyCertOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
@Override
public Handler<TCPSSLOptions> parse(final JsonObject options) {
return Fn.get(() -> {
final PemKeyCertOptions pem = Fn.getSemi(
null == options ||
!options.containsKey(PATH_KEY) ||
!options.containsKey(PATH_CERT), LOGGER,
Cert.SERVER_PEM,
() -> new PemKeyCertOptions().setKeyPath(PATH_KEY).setCertPath(PATH_CERT)
);
return option -> option
.setSsl(true)
.setUseAlpn(true)
.setPemKeyCertOptions(pem)
.setOpenSslEngineOptions(new OpenSSLEngineOptions());
}, options);
}
示例2: setGrpcSslOptions
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的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);
}
}
示例3: setSsl
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的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);
}
}
示例4: before
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
@Before
public void before(TestContext context) {
PemKeyCertOptions pemKeyCertOptions = new PemKeyCertOptions()
.setKeyPath("tls/server-key.pem")
.setCertPath("tls/server-cert.pem");
MqttServerOptions options = new MqttServerOptions()
.setPort(MQTT_SERVER_TLS_PORT)
.setKeyCertOptions(pemKeyCertOptions)
.setSsl(true);
// just useful for enabling decryption using Wireshark (which doesn't support default Diffie-Hellmann for key exchange)
// options.addEnabledCipherSuite("TLS_RSA_WITH_AES_256_CBC_SHA256");
this.setUp(context, options);
}
示例5: testLoginByCert_usingPemConfig
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的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);
}
示例6: getRetrieverConfiguration
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的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;
}
示例7: createSecureServer
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
private void createSecureServer(VertxRequestHandler requestHandler, Future<Void> startPromise) {
if (new File(certDir).exists()) {
HttpServerOptions options = new HttpServerOptions();
File keyFile = new File(certDir, "tls.key");
File certFile = new File(certDir, "tls.crt");
log.info("Loading key from " + keyFile.getAbsolutePath() + ", cert from " + certFile.getAbsolutePath());
options.setKeyCertOptions(new PemKeyCertOptions()
.setKeyPath(keyFile.getAbsolutePath())
.setCertPath(certFile.getAbsolutePath()));
options.setSsl(true);
httpsServer = vertx.createHttpServer(options)
.requestHandler(requestHandler)
.listen(SECURE_PORT, ar -> {
if (ar.succeeded()) {
log.info("Started HTTPS server. Listening on port " + SECURE_PORT);
startPromise.complete();
} else {
log.info("Error starting HTTPS server");
startPromise.fail(ar.cause());
}
});
} else {
startPromise.complete();
}
}
示例8: createClientOptions
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的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.PemKeyCertOptions; //导入依赖的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: startTcpServer
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
private void startTcpServer(ConfigParser c) {
int port = c.getPort();
String keyPath = c.getTlsKeyPath();
String certPath = c.getTlsCertPath();
boolean tlsEnabled = c.isTlsEnabled();
int idleTimeout = c.getSocketIdleTimeout();
// MQTT over TCP
NetServerOptions opt = new NetServerOptions()
.setTcpKeepAlive(true)
.setIdleTimeout(idleTimeout) // in seconds; 0 means "don't timeout".
.setPort(port);
if(tlsEnabled) {
opt.setSsl(true).setPemKeyCertOptions(new PemKeyCertOptions()
.setKeyPath(keyPath)
.setCertPath(certPath)
);
}
NetServer netServer = vertx.createNetServer(opt);
Map<String, MQTTSession> sessions = new MonitoredMap<>();
netServer.connectHandler(netSocket -> {
MQTTNetSocket mqttNetSocket = new MQTTNetSocket(vertx, c, netSocket, sessions);
mqttNetSocket.start();
}).listen();
}
示例11: testSslClientAuthentication
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
@Test
public void testSslClientAuthentication(TestContext context) {
JsonObject config = TestConfig.getApiConfig();
deployApiVerticle(context, config);
final Async asyncSslClient = context.async();
HttpClientOptions sslOpts = new HttpClientOptions().setSsl(true)
.setPemTrustOptions(TestConfig.HTTP_API_CERTIFICATE.trustOptions());
vertx.createHttpClient(sslOpts).get(port, "localhost", "/api/v1.0/pr/latest", res -> {
context.assertEquals(200, res.statusCode());
asyncSslClient.complete();
}).end();
final Async asyncSslClientAuth = context.async();
HttpClientOptions sslClientAuthOpts = new HttpClientOptions().setSsl(true)
.setPemTrustOptions(TestConfig.HTTP_API_CERTIFICATE.trustOptions())
.setPemKeyCertOptions(new PemKeyCertOptions()
.setKeyPath(TestConfig.HTTP_CLIENT_CERTIFICATE.privateKeyPath())
.setCertPath(TestConfig.HTTP_CLIENT_CERTIFICATE.certificatePath()));
vertx.createHttpClient(sslClientAuthOpts).get(port, "localhost", "/api/v1.0/pr/latest", res -> {
context.assertEquals(200, res.statusCode());
asyncSslClientAuth.complete();
}).end();
final Async asyncClient = context.async();
vertx.createHttpClient().get(port, "localhost", "/api/v1.0/pr/latest", res ->
context.fail("Connected to HTTPS connection with HTTP!")
).exceptionHandler(res ->
asyncClient.complete()
).end();
}
示例12: testSslRequiredClientAuthentication
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
@Test
public void testSslRequiredClientAuthentication(TestContext context) {
JsonObject config = TestConfig.getApiConfig();
config.getJsonObject("ssl").put("sslRequireClientAuth", true);
deployApiVerticle(context, config);
final Async asyncSslClient = context.async();
HttpClientOptions sslOpts = new HttpClientOptions().setSsl(true)
.setPemTrustOptions(TestConfig.HTTP_API_CERTIFICATE.trustOptions());
vertx.createHttpClient(sslOpts).get(port, "localhost", "/api/v1.0/pr/latest", res ->
context.fail("Connected without client authentication!")
).exceptionHandler(res ->
asyncSslClient.complete()
).end();
final Async asyncSslClientAuth = context.async();
HttpClientOptions sslClientAuthOpts = new HttpClientOptions().setSsl(true)
.setPemTrustOptions(TestConfig.HTTP_API_CERTIFICATE.trustOptions())
.setPemKeyCertOptions(new PemKeyCertOptions()
.setKeyPath(TestConfig.HTTP_CLIENT_CERTIFICATE.privateKeyPath())
.setCertPath(TestConfig.HTTP_CLIENT_CERTIFICATE.certificatePath()));
vertx.createHttpClient(sslClientAuthOpts).get(port, "localhost", "/api/v1.0/pr/latest", res -> {
context.assertEquals(200, res.statusCode());
asyncSslClientAuth.complete();
}).end();
final Async asyncClient = context.async();
vertx.createHttpClient().get(port, "localhost", "/api/v1.0/pr/latest", res ->
context.fail("Connected to HTTPS connection with HTTP!")
).exceptionHandler(res ->
asyncClient.complete()
).end();
}
示例13: testPemConfig
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
/**
* Test a valid PEM configuration.
*/
@Test
public void testPemConfig() {
final TestConfig cfg = new TestConfig();
cfg.setKeyPath(PREFIX_KEY_PATH + "hono-messaging-key.pem");
cfg.setCertPath(PREFIX_KEY_PATH + "hono-messaging-cert.pem");
final KeyCertOptions options = cfg.getKeyCertOptions();
Assert.assertNotNull(options);
Assert.assertThat(options, instanceOf(PemKeyCertOptions.class));
}
示例14: before
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
@Before
public void before() {
PemKeyCertOptions pemKeyCertOptions = new PemKeyCertOptions()
.setKeyPath("tls/server-key.pem")
.setCertPath("tls/server-cert.pem");
MqttServerOptions serverOptions = new MqttServerOptions()
.setPort(MQTT_SERVER_TLS_PORT)
.setHost(MQTT_SERVER_HOST)
.setKeyCertOptions(pemKeyCertOptions)
.setSsl(true);
server = MqttServer.create(vertx, serverOptions);
server.endpointHandler(e -> {
log.info("Client connected");
e.disconnectHandler(d -> log.info("Client disconnected"));
e.accept(false);
}).listen(ar -> {
if (ar.succeeded()) {
log.info("MQTT server listening on port " + ar.result().actualPort());
} else {
log.error("Error starting MQTT server", ar.cause());
System.exit(1);
}
});
server.exceptionHandler(t -> context.assertTrue(false));
}
示例15: example1WithConfig
import io.vertx.core.net.PemKeyCertOptions; //导入依赖的package包/类
public void example1WithConfig(Vertx vertx) {
JsonObject vault_config = new JsonObject()
.put("host", "127.0.0.1") // The host name
.put("port", 8200) // The port
.put("ssl", true); // Whether or not SSL is used (disabled by default)
// Certificates
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());
// Truststore
JksOptions jks = new JksOptions()
.setPath("target/vault/config/ssl/truststore.jks");
vault_config.put("trustStoreOptions", jks.toJson());
// 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));
}