我正在使用Grizzly来启动服务器并部署需要客户端证书的应用程序才能工作。
当我启动Grizzly服务器时,我创建了两个网络侦听器。一个普通的监听 HTTP 和一个应该处理 HTTPS 请求的安全的。虽然普通网络侦听器的行为符合预期(在没有任何安全性的情况下提供请求),但HTTPS不是。问题是,当我点击HTTPS端点时,它会提示我输入我的客户端证书但是没有任何反应,请求超时。
我已经设置 “ - Djava.net.debug = all” 我可以看到SSL握手正在发生,因此我怀疑我错过了什么,而我设置Grizzly服务器。也许是认证者?
我用来启动服务器的代码如下:
public void startServer() {
final String contextPath = "/";
final WebappContext webappContext = new WebappContext( "Test", contextPath );
final Map< String, String > contextInitParams = Collections.singletonMap(
"jersey.config.server.provider.packages", "com.mywebapp" );
for ( Map.Entry< String, String > entry : contextInitParams.entrySet() )
{
webappContext.addContextInitParameter( entry.getKey(), entry.getValue() );
webappContext.setInitParameter( entry.getKey(), entry.getValue() );
}
ServletRegistration servletRegistration = webappContext.addServlet( ServletContainer.class.getName(),
ServletContainer.class );
servletRegistration.addMapping( new String[] { "/*" } );
servletRegistration.setInitParameters( contextInitParams );
SSLContextConfigurator ssl = new SSLContextConfigurator();
ssl.setKeyStoreFile( KEY_STORE_FILE_PATH );
ssl.setKeyStorePass( KEY_STORE_PASSWORD );
ssl.setTrustStoreFile( TRUSTSTORE_FILE_PATH );
ssl.setTrustStorePass( TRUSTSTORE_PASSWORD );
ssl.setSecurityProtocol( "TLSv1.2" );
SSLEngineConfigurator sslEngineConfigurator = new SSLEngineConfigurator( ssl, false, true, true );
sslEngineConfigurator.setEnabledCipherSuites( new String[] { "TLS_RSA_WITH_AES_128_CBC_SHA",
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_RSA_WITH_AES_128_CBC_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA" } );
// HTTP listener
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer( new URI( "http://localhost:8080" ) );
// HTTPS listener
NetworkListener lis = new NetworkListener( "HTTPS", "localhost", 8443 );
lis.setSecure( true );
lis.setTraceEnabled( true );
lis.setSSLEngineConfig( sslEngineConfigurator );
httpServer.addListener( lis );
httpServer.start();
webappContext.deploy( httpServer );
Thread.currentThread().join();
}
有人能发现上述代码中的错误吗?也许我错过了一个处理程序?
任何帮助非常感谢。 谢谢。