Play框架中的SSL导致“常规SSLEngine概率”。 (nginx的)

我有一个2服务器的服务器结构:一个是与内容的主要服务器,另一个是与运行的Play的Scala服务器,做用户pipe理,包括社会login(fb,tw,g +)。 两台服务器都使用相同的通配符SSL证书。

我最近把主服务器从Apache切换到nginx,由于某种原因,Scala服务器抱怨SSL不匹配(在Apache之前这从来都不是问题)。

当我尝试login时,从Play中收到以下错误:

[error] scProviderController - Unable to log user in. An exception was thrown java.net.ConnectException: General SSLEngine problem to https://www.example.com/login/corsValid at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:103) ~[async-http-client.jar:na] at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427) ~[netty.jar:na] at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:413) ~[netty.jar:na] at org.jboss.netty.channel.DefaultChannelFuture.setFailure(DefaultChannelFuture.java:380) ~[netty.jar:na] at org.jboss.netty.handler.ssl.SslHandler.setHandshakeFailure(SslHandler.java:1417) ~[netty.jar:na] at org.jboss.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1293) ~[netty.jar:na] Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1290) ~[na:1.7.0_51] at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:513) ~[na:1.7.0_51] at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:793) ~[na:1.7.0_51] at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:761) ~[na:1.7.0_51] at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624) ~[na:1.7.0_51] at org.jboss.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1225) ~[netty.jar:na] Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[na:1.7.0_51] at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1694) ~[na:1.7.0_51] at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:278) ~[na:1.7.0_51] at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270) ~[na:1.7.0_51] at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341) ~[na:1.7.0_51] at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153) ~[na:1.7.0_51] Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385) ~[na:1.7.0_51] at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) ~[na:1.7.0_51] at sun.security.validator.Validator.validate(Validator.java:260) ~[na:1.7.0_51] at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326) ~[na:1.7.0_51] at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:283) ~[na:1.7.0_51] at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:138) ~[na:1.7.0_51] Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196) ~[na:1.7.0_51] at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268) ~[na:1.7.0_51] at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380) ~[na:1.7.0_51] at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) ~[na:1.7.0_51] at sun.security.validator.Validator.validate(Validator.java:260) ~[na:1.7.0_51] at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326) ~[na:1.7.0_51] 

我追溯了这个问题,发现application.conf需要正确使用SSL证书的参数。 我创build了一个JKS和P12证书,并将其包含在conf文件中,但仍然出现此错误。 (也许是错误的path?尝试,以及…)

 ws.ssl { trustManager = { stores = [ { path: "ssl.jks" } ] } } 

但是,当我添加ws.acceptAnyCertificate=true而不是一切都很好,但这显然是一个安全漏洞,没有什么我想做的。

为什么要在Play上安装一个SSL证书?

谢谢

我认为Play主要是一个应用程序框架,而不是一个Web服务器。

我们的游戏应用程序始终与Nginx网络服务器(在DMZ中)进行通信,Nginx终止SSL / TLS通信。 有了这个设计,如果您的Play应用程序是无状态的,您可以负载平衡。

然后,如果你想,将所有自定义http头文件从Nginx转发到后端(例如客户端认证)进行验证。

 proxy_set_header APP-Cert-Verified $ssl_client_verify; proxy_set_header APP-Client-Cert $ssl_client_cert; proxy_set_header APP-Client-Cert-DN $ssl_client_s_dn; 

您也可以在官方文档中找到它: https : //www.playframework.com/documentation/2.5.x/HTTPserver#Set-up-with-nginx 。

奖励:如果认证到期,您可以更轻松地更改nginx中的证书,而不是重新启动您的Play应用。