Run SSL Httpserver on Groovy

183 views
Skip to first unread message

Paul

unread,
Jul 26, 2016, 9:59:51 AM7/26/16
to vert.x
I´m trying to create an HttpServer working on SSL with Groovy, but I´m not able to make it works, and I cannot find a good code example or documentation about it.

Here the code base that I did so far



Map options = new HashMap()
options.put("tcpKeepAlive",true)
options.put("verifyHost", true)
options.put("trustAll", false)
options.put("keyCertOptions", new JksOptions().setPath("keystore.jks").setPassword("CosPassword123"))
options.put("ssl", true)
vertx.createHttpServer(options).requestHandler(router.&accept).listen(9000, { response ->
if (response.succeeded()) {
startFuture.complete()
} else {
startFuture.fail(response.cause())
}
})


When When I run it I receive the exception

io.vertx.core.VertxException: io.vertx.core.VertxException: Key/certificate is mandatory for SSL
at io.vertx.core.net.impl.SSLHelper.createContext(SSLHelper.java:303)
at io.vertx.core.net.impl.SSLHelper.getContext(SSLHelper.java:458)
at io.vertx.core.net.impl.SSLHelper.validate(SSLHelper.java:472)
at io.vertx.core.http.impl.HttpServerImpl.listen(HttpServerImpl.java:219)
at io.vertx.core.http.impl.HttpServerImpl.listen(HttpServerImpl.java:191)
at io.vertx.groovy.core.http.HttpServer.listen(HttpServer.groovy:178)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrap.invoke(PogoMetaMethodSite.java:190)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at com.tesco.price.mocks.identity.IdentityMock.startServer(IdentityMock.groovy:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
at com.tesco.price.mocks.identity.IdentityMock.start(IdentityMock.groovy:29)
at io.vertx.lang.groovy.GroovyVerticle$1.start(GroovyVerticle.groovy:93)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:434)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:359)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:339)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:393)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
at java.lang.Thread.run(Thread.java:745)
Caused by: io.vertx.core.VertxException: Key/certificate is mandatory for SSL
at io.vertx.core.net.impl.SSLHelper.createContext(SSLHelper.java:270)
... 32 more

Filip Panovski

unread,
Jul 26, 2016, 10:17:21 AM7/26/16
to vert.x
Not Groovy, but here is my own SSL-able Vert.x deployment:


        private HttpServer server;

        @Override
        public void start(Future<Void> start)
        {
                HttpServerOptions options = getDefaultOptions();
                server = vertx.createHttpServer(options)
                                .requestHandler(createRouter()::accept)
                                .listen(20060, result ->
                                                           {
                                                                   if(result.succeeded()) {
                                                                           System.out.println("Start: SUCCESS");
                                                                           start.complete();
                                                                   }
                                                                   else {
                                                                           System.out.println("Start FAILED. Cause:
");
                                                                           start.fail(result.cause());
                                                                   }
                                                           }
                                                );
                System.out.println("Port: " + server.actualPort());
        }


        private HttpServerOptions getDefaultOptions()
        {
                HttpServerOptions options = new HttpServerOptions();

                options.setLogActivity(true);
                options.setPort(20060);
                options.setHost("localhost");
                options.setSsl(true);
                options.setKeyStoreOptions(
                                new JksOptions()
                                        .setPath("keystore.jks")
                                        .setPassword("changeit"));

                return options;
        }

        public static void main (String[] args)
        {
                Vertx vertx = Vertx.vertx();
                vertx.deployVerticle(APIServer.class.getName());
                System.out.println("Starting API server...");
        }

Hope it helps.

Paul

unread,
Jul 26, 2016, 10:21:28 AM7/26/16
to vert.x
Thanks for the code, but I also have a Java implementation that works, but it´s the groovy the one that is giving me a hard time. 

Julien Viet

unread,
Jul 26, 2016, 10:46:08 AM7/26/16
to ve...@googlegroups.com
-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/439df52c-004e-4506-83d6-94e388f8de8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul

unread,
Jul 26, 2016, 11:25:47 AM7/26/16
to vert.x
Thanks!, that code make the server run. Now I´m having this error which I´m 100% sure it´s about the client

GRAVE: java.lang.IllegalArgumentException: invalid version format: ￀ /￀ ￀ 32￀+￀/ワ￀-￀1゙ᄁ￀ ￀

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:992)
  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
  at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
  at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
  at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
  at scalaj.http.DefaultConnectFunc$.apply(Http.scala:471)
  at scalaj.http.DefaultConnectFunc$.apply(Http.scala:469)
  at scalaj.http.HttpRequest.scalaj$http$HttpRequest$$doConnection(Http.scala:355)


But just to be sure, it´s nothing related with the server config right?

Julien Viet

unread,
Jul 26, 2016, 11:43:16 AM7/26/16
to ve...@googlegroups.com
that’s what happens when you connect from a non SSL client.



Reply all
Reply to author
Forward
0 new messages