Jetty 9.3 SSL-ALPN-HTTP2错误ERR_EMPTY_REPONSE(仅使用HTTPS)



我已将Jetty 9.2 HTTP/1.1+SSL纯服务器(嵌入式)升级到Jetty 9.3.0(v220150612)HTTP/HTTPS 2.0(SLL(TLS)-ALPN-HTTP/2)。我使用JRE 8(Oracle 1.8.0 Build 45-b15)和Eclipse。

*JOAKIM的回答解决了问题:解决方案见文章末尾*

在升级之前,HTTP和HTTPS运行良好,只需使用Jetty 9.3 Jar文件进行重建即可。然后,我升级了代码(从我设法找到的示例中学习),以包含SSL(TLS)-APN-HTTP/2-HTTP/1.1。我使用的主要示例是在这个链接中使用代码

Google Chrome浏览器(版本43.0.2357.130 m)可以很好地处理http请求,如http://10.32.1.110:8080/,然后显示网页。但是,如果我打开第二个选项卡并尝试https://10.32.1.110:8443/,我会收到一个错误ERR_EMPTY_REPONSE。但是,我可以连接到webtid.com并获得https会话。防火墙对我的系统的干扰已被排除。10.32。???对于工作的HTTP和失败的HTTPS,连接并没有很好地传递它。

这个错误不会阻止Jetty服务器(服务器不会抛出或记录错误),我可以回到第一个浏览器选项卡,继续请求网页,每次都会看到它更新(我有一个时间戳和计数器)。

在HTTPS的情况下,我的handle()方法不是由Jetty调用的(我有一个日志行来监控它),我只看到handle(()方法中有HTTP请求。根据Jetty请求对象,到达我的handle()中的http请求的类型是http/1.1。根据我的研究,这是正常的,因为谷歌浏览器不会做HTTP/2没有SSL/ALPN。

我一直认为SSL和ALPN问题是HTTPS请求导致ERR_EMPTY_REPONSE的原因。alpn-api-1.1.2.v20150522.jar被添加到我的Eclipse VM Arguments(相当于JVM引导类路径)中,作为"-Xbootclasspath/p:D:\Users\TWO\DATA\Eclipse\alpn-api-1.1.2.v20150522.jar"。从那时起,Jetty就不会抱怨alpn不在JVM引导类道路上(像以前一样抛出错误)。从下面的Jetty日志中,SLL和HTTP/2也正确启动。

Jetty服务器以以下日志正常启动:

2015-06-24 15:53:29.292:INFO:oejs.Server:main: jetty-9.3.0.v20150612
2015-06-24 15:53:29.323:INFO:oejs.ServerConnector:main: Started ServerConnector@123772c4{HTTP/1.1,[http/1.1, h2c, h2c-17, h2c-16, h2c-15, h2c-14]}{0.0.0.0:8080}
2015-06-24 15:53:29.338:INFO:oejus.SslContextFactory:main: x509={jetty.eclipse.org=jetty} wild={} alias=null for SslContextFactory@6f75e721(file:///D:/Users/[removed]/keystores/keystore,file:///D:/Users/[removed]/keystores/keystore)
2015-06-24 15:53:29.495:INFO:oejs.ServerConnector:main: Started ServerConnector@13deb50e{SSL,[ssl, alpn, h2, h2-17, h2-16, h2-15, h2-14, http/1.1]}{0.0.0.0:8443}
2015-06-24 15:53:29.495:INFO:oejs.Server:main: Started @321ms

以下是相关的Java服务器代码:

... standard Jetty imports plus
import org.eclipse.jetty.alpn.ALPN;
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
import org.eclipse.jetty.http2.HTTP2Cipher;
import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory;
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;

QueuedThreadPool oTP = new QueuedThreadPool(20);
this.oServer = new Server(oTP);
this.oServer.setHandler((Handler) this);
HttpConfiguration httpcfg = new HttpConfiguration();
httpcfg.setSecureScheme("https");
httpcfg.setSecurePort(8443);
HttpConnectionFactory httpF=new HttpConnectionFactory(httpcfg);
HTTP2CServerConnectionFactory http2F=new HTTP2CServerConnectionFactory(httpcfg);
ServerConnector http=new ServerConnector(this.oServer,httpF,http2F);
http.setPort(8080);
this.oServer.addConnector(http);
SslContextFactory sslCF=new SslContextFactory();
sslCF.setKeyStorePath(MetaWebServerConfig.getWebServerKeystore()+"keystore"); 
sslCF.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslCF.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslCF.setTrustStorePath(MetaWebServerConfig.getWebServerKeystore()+"keystore"); 
sslCF.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslCF.setExcludeCipherSuites(
              "SSL_RSA_WITH_DES_CBC_SHA",
              "SSL_DHE_RSA_WITH_DES_CBC_SHA",
              "SSL_DHE_DSS_WITH_DES_CBC_SHA",
              "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
              "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
              "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
              "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
sslCF.setCipherComparator(new HTTP2Cipher.CipherComparator());
HttpConfiguration httpscfg = new HttpConfiguration(httpcfg);
httpscfg.addCustomizer(new SecureRequestCustomizer());
HTTP2ServerConnectionFactory h2F=new HTTP2ServerConnectionFactory(httpscfg);
NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
ALPNServerConnectionFactory alpnF=new ALPNServerConnectionFactory();
alpnF.setDefaultProtocol(http.getDefaultProtocol());
SslConnectionFactory sslF=new SslConnectionFactory(sslCF,alpnF.getProtocol());
HttpConnectionFactory https2F=new HttpConnectionFactory(httpscfg);
ServerConnector http2=new ServerConnector(this.oServer,sslF,alpnF,h2F,https2F);
http2.setPort(8443);
this.oServer.addConnector(http2);
ALPN.debug=false;
this.oServer.start();

应gregw的请求,我尝试了顶部链接中的示例代码。我只修改了SslContextFactory的密钥库路径。我总是使用相同的密钥库文件,因为我知道它是可以的(请参阅文章的开头-我以前的HTTP/1.1+SLL工作并使用了相同的密钥存储

2015-06-25 14:07:14.972:INFO:oejs.Server:main: jetty-9.3.0.v20150612
2015-06-25 14:07:15.019:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@6f75e721{/,file:///D:/Users/[path]/docroot,AVAILABLE}
2015-06-25 14:07:15.082:INFO:oejs.ServerConnector:main: Started ServerConnector@1888ff2c{HTTP/1.1,[http/1.1, h2c, h2c-17, h2c-16, h2c-15, h2c-14]}{0.0.0.0:8080}
2015-06-25 14:07:15.097:INFO:oejus.SslContextFactory:main: x509={jetty.eclipse.org=jetty} wild={} alias=null for SslContextFactory@4b952a2d(file:///D:/Users/[path]/keystores/keystore,null)
2015-06-25 14:07:15.269:INFO:oejs.ServerConnector:main: Started ServerConnector@5594a1b5{SSL,[ssl, alpn, h2, h2-17, h2-16, h2-15, h2-14, http/1.1]}{0.0.0.0:8443}
2015-06-25 14:07:15.269:INFO:oejs.Server:main: Started @587ms

用http访问可以,但用https访问不行,浏览器再次显示ERR_EMPTY_REPONSE。

尝试使用IExplorer 11。同样的结果。适用于http而不适用于https(msg=无法显示此页面),以免与404混淆(无法找到此页面)。与Chrome不同的是,当greg的代码与http一起使用时,IE确实发出了"Cookie"警告,但它没有与https一起使用。

有没有人可能知道如何解决上述问题。TIA-

*解决方案*

根据Joakim的建议,我在引导类路径中添加了alpn-boot-8.1.3.v20150130.jar,而不是alpn-api-1.1.2.v20150522.jar。在以下组合中重复使用的测试完美工作:

  • HTTP/1.1(HTTP)-使用Google Chrome完成
  • HTTP/1.1(HTTP)-第二次尝试使用IE

  • HTTP/2.0+SSL(HTTPS)-使用谷歌Chrome 完成

  • HTTP/1_1+SLL(HTTPS)-使用IE 完成

  • HTTP/2_0(HTTP)-没有进行测试,因为缺乏快速的用户代理。

这些是我唯一感兴趣的未来组合,尽管我确信HTTP/2_0和SSL也会起作用。

此Jetty Documentation链接显示JRE版本和ALPN JAR文件版本之间的表,以防其中一个JRE与另一个JRE出现相同问题。

非常感谢所有试图帮助解决这个问题的人。

对于Oracle/OpenJDK Java JRE/JDK,您使用的是alpn-boot.jar,而不是alpn-api.jar…

  • 对于Java 1.8.0_25,使用alpn-boot-8.1.2.v20141202.jar
  • 对于Java 1.8.0_45,使用alpn-boot-8.1.3.v20150130.jar

有关Java到ALPN引导版本的表格,请参阅ALPN/Versions文档。

这一点至关重要,因为这修改了Java本身的SSL/TLS层,以添加对HTTP/2所需的ALPN协议的支持。

这个-Xbootclasspath要求是强制性的,直到将来Java内置ALPN(计划用于Java 9)

相关内容

最新更新