0
votes

When i am trying to connect https url... i am getting ssl handshaking failure... I am using vertx-version >>2.1.5 Please help me to resolve this... I am stuck here it is very important for me

 This code is working fine, giving me proper response..

     URL url = new  URL("https://bugzilla.mozilla.org/rest/bug/707428/comment");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestMethod("GET");
    conn.setRequestProperty("accept", "application/json");
    InputStream is=conn.getInputStream();
    InputStreamReader isr=new InputStreamReader(is);
    BufferedReader br=new BufferedReader(isr);
    String str=null;
    while((str=br.readLine())!=null){
        System.out.println(str);
    }
    conn.disconnect();     

but while using vertx. it is giving hand shaking Problem

 HttpClient client = MyServer.defaultVertx.createHttpClient().setSSL(true).setTrustAll(true)
                .setHost("bugzilla.mozilla.org").setPort(443).setVerifyHost(false);

        HttpClientRequest request= client.request("GET","/rest/bug/707428/comment",new Handler<HttpClientResponse>() {

            @Override
            public void handle(HttpClientResponse cRes) {
                System.out.println(" HttpClientResponse Done.."+cRes);
                cRes.bodyHandler(new Handler<Buffer>() {
                    @Override
                    public void handle(Buffer data) {
                        System.out.println("Response (" + data.length() + "): ");
                        System.out.println("Response  >>" +data.getString(0, data.length()));
                    }
                });

                cRes.dataHandler(new Handler<Buffer>() {
                    @Override
                    public void handle(Buffer data) {
                        System.out.println("data Handler (" + data.length() + "): ");
                        System.out.println("data Handler<>>  "+data.getString(0, data.length()));
                    }
                });

                cRes.exceptionHandler(new Handler<Throwable>() {
                    @Override
                    public void handle(Throwable arg0) {
                        arg0.printStackTrace();
                    }
                });
            }
        });

        request.exceptionHandler(new Handler<Throwable>() {
            @Override
            public void handle(Throwable arg0) {
                // TODO Auto-generated method stub
                arg0.printStackTrace();
            }
        });
        request.end();
        client.close();




 javax.net.ssl.SSLException: Received fatal alert: handshake_failure
           at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
           at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1619)
           at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1587)
           at sun.security.ssl.SSLEngineImpl.recvAlert(SSLEngineImpl.java:1756)
           at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:1060)
           at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
           at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
           at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
           at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1001)
           at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:927)
           at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:873)
           at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:241)
           at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:149)
           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
           at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
           at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125)
           at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
           at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
           at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
           at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
           at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
           at java.lang.Thread.run(Thread.java:745)
2
Please make an effort to format your code properly. - Matt C

2 Answers

0
votes

The code example is connecting to port 433, while HTTPS is listening on 443. My guess is that it's a typo in your question, otherwise you wouldn't get the SSL handshake failure.

Your code looks fine and it should be able to handle even self signed SSL certificates. I'm suspecting that this is an issue with the specific SSL setup of bugzilla.mozilla.org in combination with the HTTP client implementation in Vert.x 2. You can check this by accessing another host (https://google.com, for example).

A possible cause might be that the SSL setup on mozilla.org requires SNI (Server Name Indication), and that the Vert.x HTTPClient does not send this by default.

0
votes

It is difficult to pinpoint the exact issue for this exception.
It could be incompatible ciphers, JCE policy jars missing, SSL version issues, etc.

I would suggest enable debugging of Connection related issue to see what exactly went wrong.

-Djavax.net.debug=all

Refer to this link for moreinfo