@Override public PemKeyCertOptions clone() { return new PemKeyCertOptions(this); } }
@Override public PemKeyCertOptions keyCertOptions() { return new PemKeyCertOptions() .setKeyPath(privateKeyPath()) .setCertPath(certificatePath()); }
case "pemKeyCertOptions": if (member.getValue() instanceof JsonObject) { obj.setPemKeyCertOptions(new io.vertx.core.net.PemKeyCertOptions((JsonObject)member.getValue()));
case "pemKeyCertOptions": if (member.getValue() instanceof JsonObject) { obj.setPemKeyCertOptions(new io.vertx.core.net.PemKeyCertOptions((JsonObject)member.getValue()));
setUseAlpn(true). setSsl(true). setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem") ));
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(new HttpServerOptions() .setSsl(true).setUseAlpn(true) .setPemKeyCertOptions(new PemKeyCertOptions() .setCertPath("server-cert.pem") .setKeyPath("server-key.pem") )); server.requestHandler(req -> { req.response() .putHeader("content-type", "text/html") .end("Hello using HTTP " + req.version()); }); server.listen(8443); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(new HttpServerOptions(). setUseAlpn(true). setSsl(true). setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem") )); server.requestHandler(req -> { req.response().putHeader("content-type", "text/html").end("<html><body>" + "<h1>Hello from vert.x!</h1>" + "<p>version = " + req.version() + "</p>" + "</body></html>"); }).listen(8443); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(new HttpServerOptions() .setSsl(true).setUseAlpn(true) .setPemKeyCertOptions(new PemKeyCertOptions() .setCertPath("server-cert.pem") .setKeyPath("server-key.pem") )); server.requestHandler(req -> { req.response() .putHeader("content-type", "text/html") .end("Hello using HTTP " + req.version()); }); server.listen(8443); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(new HttpServerOptions(). setUseAlpn(true). setSsl(true). setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem") )); server.requestHandler(req -> { HttpServerResponse resp = req.response(); req.customFrameHandler(frame -> { System.out.println("Received client frame " + frame.payload().toString("UTF-8")); // Write the sam resp.writeCustomFrame(10, 0, Buffer.buffer("pong")); }); }).listen(8443); } }
.setPemKeyCertOptions(new PemKeyCertOptions() .setKeyPath("server-key.pem") .setCertPath("server-cert.pem"))
@Override public void start() throws Exception { final Image image = new Image(vertx, "coin.png"); Router router = Router.router(vertx); router.get("/").handler(ctx -> { ctx.response() .putHeader("Content-Type", "text/html") .end(image.generateHTML(16)); }); router.get("/img/:x/:y").handler(ctx -> { ctx.response() .putHeader("Content-Type", "image/png") .end(image.getPixel(Integer.parseInt(ctx.pathParam("x")), Integer.parseInt(ctx.pathParam("y")))); }); vertx.createHttpServer( new HttpServerOptions() .setSsl(true) .setUseAlpn(true) .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem"))).requestHandler(router) .listen(8443); } }
@Test public void testDefaultKeyCertOptionsJson() throws Exception { PemKeyCertOptions def = new PemKeyCertOptions(); PemKeyCertOptions json = new PemKeyCertOptions(new JsonObject()); assertEquals(def.getKeyPath(), json.getKeyPath()); assertEquals(def.getCertPath(), json.getCertPath()); assertEquals(def.getKeyValue(), json.getKeyValue()); assertEquals(def.getCertValue(), json.getCertValue()); }
@Test public void testPemKeyCertOptionsJson() throws Exception { PemKeyCertOptions options = new PemKeyCertOptions(new JsonObject()); assertEquals(null, options.getKeyPath()); assertEquals(null, options.getKeyValue()); String certPath1 = TestUtils.randomAlphaString(100); Buffer certValue1 = Buffer.buffer(TestUtils.randomAlphaString(100)); options = new PemKeyCertOptions(new JsonObject(). put("keyPath", keyPath1). put("keyValue", keyValue1.getBytes()). String certPath2 = TestUtils.randomAlphaString(100); Buffer certValue2 = Buffer.buffer(TestUtils.randomAlphaString(100)); options = new PemKeyCertOptions(new JsonObject(). put("keyPaths", new JsonArray().add(keyPath1).add(keyPath2)). put("keyValues", new JsonArray().add(keyValue1.getBytes()).add(keyValue2.getBytes())).
@Test public void testCopyPemKeyCertOptions() throws Exception { PemKeyCertOptions options = new PemKeyCertOptions(new JsonObject()); String keyPath1 = TestUtils.randomAlphaString(100); Buffer keyValue1 = Buffer.buffer(TestUtils.randomAlphaString(100)); options.setCertPath(certPath1); options.setCertValue(certValue1); options = new PemKeyCertOptions(options); assertEquals(keyPath1, options.getKeyPath()); assertEquals(keyValue1, options.getKeyValue()); assertEquals(Collections.singletonList(certPath1), options.getCertPaths()); assertEquals(Collections.singletonList(certValue1), options.getCertValues()); options = new PemKeyCertOptions(options.toJson()); assertEquals(keyPath1, options.getKeyPath()); assertEquals(keyValue1, options.getKeyValue()); options.addCertPath(certPath2); options.addCertValue(certValue2); options = new PemKeyCertOptions(options); assertEquals(keyPath1, options.getKeyPath()); assertEquals(keyValue1, options.getKeyValue()); assertEquals(Arrays.asList(certPath1, certPath2), options.getCertPaths()); assertEquals(Arrays.asList(certValue1, certValue2), options.getCertValues()); options = new PemKeyCertOptions(options.toJson()); assertEquals(keyPath1, options.getKeyPath()); assertEquals(keyValue1, options.getKeyValue());
public static KeyCertOptions randomKeyCertOptions() { KeyCertOptions keyCertOptions; switch (TestUtils.randomPositiveInt() % 3) { case 0: keyCertOptions = new JksOptions(); String jksPassword = TestUtils.randomAlphaString(100); ((JksOptions) keyCertOptions).setPassword(jksPassword); break; case 1: keyCertOptions = new PemKeyCertOptions(); Buffer keyValue = TestUtils.randomBuffer(100); ((PemKeyCertOptions) keyCertOptions).setKeyValue(keyValue); break; default: keyCertOptions = new PfxOptions(); String pfxPassword = TestUtils.randomAlphaString(100); ((PfxOptions) keyCertOptions).setPassword(pfxPassword); } return keyCertOptions; }
@Test public void testKeyCertOptions() throws Exception { PemKeyCertOptions options = new PemKeyCertOptions(); assertNull(options.getKeyPath()); String randString = TestUtils.randomAlphaString(100); assertEquals(options, options.setKeyPath(randString)); assertEquals(randString, options.getKeyPath()); assertNull(options.getCertPath()); randString = TestUtils.randomAlphaString(100); assertEquals(options, options.setCertPath(randString)); assertEquals(randString, options.getCertPath()); }
@Test public void testCloseCompletionHandlerNotCalledWhenActualServerFailed() { server.close(); server = vertx.createNetServer( new NetServerOptions() .setSsl(true) .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("invalid"))) .connectHandler(c -> { }); try { server.listen(10000, r -> fail()); } catch (Exception ignore) { // Expected } server.close(onSuccess(v -> { testComplete(); })); await(); }
@Test public void testKeyOptionsEquality() { JksOptions jksOptions = Cert.SERVER_JKS.get(); JksOptions jksOptionsCopy = new JksOptions(jksOptions); PfxOptions pfxOptions = Cert.SERVER_PKCS12.get(); PfxOptions pfxOptionsCopy = new PfxOptions(pfxOptions); PemKeyCertOptions pemKeyCertOptions = Cert.SERVER_PEM.get(); PemKeyCertOptions pemKeyCertOptionsCopy = new PemKeyCertOptions(pemKeyCertOptions); assertEquals(jksOptions, jksOptionsCopy); assertEquals(jksOptions.hashCode(), jksOptionsCopy.hashCode()); assertEquals(pfxOptions, pfxOptionsCopy); assertEquals(pfxOptions.hashCode(), pfxOptionsCopy.hashCode()); assertEquals(pemKeyCertOptions, pemKeyCertOptionsCopy); assertEquals(pemKeyCertOptions.hashCode(), pemKeyCertOptionsCopy.hashCode()); }
@Override public PemKeyCertOptions keyCertOptions() { return new PemKeyCertOptions() .setKeyPath(privateKeyPath()) .setCertPath(certificatePath()); }
@Test public void testDefaultKeyCertOptionsJson() throws Exception { PemKeyCertOptions def = new PemKeyCertOptions(); PemKeyCertOptions json = new PemKeyCertOptions(new JsonObject()); assertEquals(def.getKeyPath(), json.getKeyPath()); assertEquals(def.getCertPath(), json.getCertPath()); assertEquals(def.getKeyValue(), json.getKeyValue()); assertEquals(def.getCertValue(), json.getCertValue()); }