AsyncHttpClient / async-http-client

Asynchronous Http and WebSocket Client library for Java
Other
6.29k stars 1.59k forks source link

Receive handshake_failure while access to a SSL Server #1388

Closed braghome closed 7 years ago

braghome commented 7 years ago

this issue exists tried 2.0.31 and 2.1.0-alpha11, see my code below I have put in placeholders for auth fields

` public static void main(final String[] args) {

abstract class __TestNetty_1 implements AsyncHandler<Response> {

  ByteArrayOutputStream bytes;

  Response.ResponseBuilder rs;
}

try {
  final RequestBuilder build = new RequestBuilder("POST");
  build.setUri(Uri.create("https://connect.urbanairship.com/api/events/"));
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Bearer placeholder");
  build.addHeader("Authorization", _builder.toString());
  build.addHeader("X-UA-Appkey", "token");
  build.addHeader("Accept", "application/vnd.urbanairship+x-ndjson; version=3;");
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("{");
  _builder_1.newLine();
  _builder_1.append("\t\t    ");
  _builder_1.append("\"filters\": [{");
  _builder_1.newLine();
  _builder_1.append("\t\t            ");
  _builder_1.append("\"device_types\": [\"ios\"],");
  _builder_1.newLine();
  _builder_1.append("\t\t            ");
  _builder_1.append("\"devices\": [{\"named_user_id\": \"nameduser\"},");
  _builder_1.newLine();
  _builder_1.append("\t\t                        ");
  _builder_1.append("{\"ios_channel\": \"channel\"}],");
  _builder_1.newLine();
  _builder_1.append("\t\t            ");
  _builder_1.append("\"latency\": 8000,");
  _builder_1.newLine();
  _builder_1.append("\t\t            ");
  _builder_1.append("\"types\": [\"SEND\"]");
  _builder_1.newLine();
  _builder_1.append("\t\t        ");
  _builder_1.append("}]");
  _builder_1.newLine();
  _builder_1.append("\t\t");
  _builder_1.append("}");
  build.setBody(_builder_1.toString());
  DefaultAsyncHttpClient asc = new DefaultAsyncHttpClient();
  final ZonedDateTime stop = ZonedDateTime.now().plusMinutes(2);
  __TestNetty_1 ___TestNetty_1 = new __TestNetty_1() {
    {
      bytes = new ByteArrayOutputStream();

      rs = new Response.ResponseBuilder();
    }
    @Override
    public AsyncHandler.State onBodyPartReceived(final HttpResponseBodyPart arg0) throws Exception {
      AsyncHandler.State _xblockexpression = null;
      {
        this.bytes.write(arg0.getBodyPartBytes());
        final ZonedDateTime start = ZonedDateTime.now();
        final UnaryOperator<ZonedDateTime> _function = (ZonedDateTime d) -> {
          return d.plusSeconds(1);
        };
        Stream<ZonedDateTime> _iterate = Stream.<ZonedDateTime>iterate(start, _function);
        long _between = ChronoUnit.MINUTES.between(start, stop);
        long _plus = (_between + 1);
        final Predicate<ZonedDateTime> _function_1 = (ZonedDateTime it) -> {
          long _between_1 = ChronoUnit.MINUTES.between(start, stop);
          return (_between_1 >= 0);
        };
        final boolean proc = _iterate.limit(_plus).anyMatch(_function_1);
        AsyncHandler.State _switchResult = null;
        String _string = this.bytes.toString("US-ASCII");
        final String part = _string;
        boolean _matched = false;
        if ((Objects.equal(part, System.lineSeparator()) && proc)) {
          _matched=true;
          _switchResult = AsyncHandler.State.CONTINUE;
        }
        if (!_matched) {
          AsyncHandler.State _xblockexpression_1 = null;
          {
            this.rs.accumulate(arg0);
            _xblockexpression_1 = AsyncHandler.State.ABORT;
          }
          _switchResult = _xblockexpression_1;
        }
        _xblockexpression = _switchResult;
      }
      return _xblockexpression;
    }

    @Override
    public Response onCompleted() throws Exception {
      return this.rs.build();
    }

    @Override
    public AsyncHandler.State onHeadersReceived(final HttpResponseHeaders arg0) throws Exception {
      AsyncHandler.State _xblockexpression = null;
      {
        this.rs.accumulate(arg0);
        _xblockexpression = AsyncHandler.State.CONTINUE;
      }
      return _xblockexpression;
    }

    @Override
    public AsyncHandler.State onStatusReceived(final HttpResponseStatus arg0) throws Exception {
      AsyncHandler.State _xblockexpression = null;
      {
        this.rs.accumulate(arg0);
        _xblockexpression = AsyncHandler.State.CONTINUE;
      }
      return _xblockexpression;
    }

    @Override
    public void onThrowable(final Throwable arg0) {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("error when check push on connect ");
      String _message = arg0.getMessage();
      _builder.append(_message);
      System.out.printf(_builder.toString());
    }
  };
  final ListenableFuture<Response> fut = asc.<Response>executeRequest(build, ___TestNetty_1);
  final Response re = fut.get(3000, TimeUnit.SECONDS);
  int _statusCode = re.getStatusCode();
  String _plus = ("Resp code: " + Integer.valueOf(_statusCode));
  System.out.printf(_plus);
} catch (Throwable _e) {
  throw Exceptions.sneakyThrow(_e);
}

} `

error occurs: error when check push on connect Received fatal alert: handshake_failureException in thread "main" java.util.concurrent.ExecutionException: java.net.ConnectException: Received fatal alert: handshake_failure at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357) at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1915) at org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:177) at com.trulia.api.bdd.heavy.service.TestNetty.main(TestNetty.java:148) Caused by: java.net.ConnectException: Received fatal alert: handshake_failure at org.asynchttpclient.netty.channel.NettyConnectListener.onFailure(NettyConnectListener.java:168) at org.asynchttpclient.netty.channel.NettyConnectListener$1.onFailure(NettyConnectListener.java:139) at org.asynchttpclient.netty.SimpleFutureListener.operationComplete(SimpleFutureListener.java:26) at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:507) at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:500) at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:479) at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:420) at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:122) at io.netty.handler.ssl.SslHandler.notifyHandshakeFailure(SslHandler.java:1387) at io.netty.handler.ssl.SslHandler.setHandshakeFailure(SslHandler.java:1379) at io.netty.handler.ssl.SslHandler.setHandshakeFailure(SslHandler.java:1353) at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1051) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:411) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:335) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:625) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:560) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:477) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:439) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:131) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) at java.lang.Thread.run(Thread.java:745) Caused by: 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:1666) at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1634) at sun.security.ssl.SSLEngineImpl.recvAlert(SSLEngineImpl.java:1800) at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:1083) at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:907) at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:781) at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624) at io.netty.handler.ssl.SslHandler$SslEngineType$2.unwrap(SslHandler.java:222) at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1119) at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1041)

curl works fine `

braghome commented 7 years ago

do we have a way to simply skip SSLValidation and trust all certs from client side

braghome commented 7 years ago

resolution is to replace your JRE's jre > lib > security jar's with Oracle http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

😭