简体   繁体   English

如何配置播放! 2.4.2 HTTPS密钥库?

[英]How to configure Play! 2.4.2 HTTPS keystore?

I'm new to the Play Framework and just trying to get HTTPS going for the first time with 2.4.2 on Java 8. I can get it working with the default keystore but not with my own keystore. 我是Play Framework的新手,只是尝试使用Java 8上的2.4.2首次使用HTTPS。我可以使用默认密钥库但不能使用我自己的密钥库。 I configured the working default keystore in build.sbt : 我在build.sbt配置了工作默认密钥库:

javaOptions ++= Seq(
    "-Dhttps.port=9443"
)

Then the official documentation for configuring your own keystore gets a bit too abstract for me. 然后,配置您自己的密钥库的官方文档对我来说有点过于抽象。 It mentions configuring it in application.conf but doesn't say how, or on the command line but not with a Java example. 它提到在application.conf中配置它,但没有说明如何,或者在命令行上,而不是在Java示例中。 Googling reveals some Scala examples but I cannot cajole them as they use things like devSettings that don't seem to come across to the Java world, or at least I do not understand Play and Scala enough to get a grip on them. 谷歌搜索揭示了一些Scala示例,但我不能哄骗他们,因为他们使用的东西似乎似乎没有遇到Java世界的devSettings ,或者至少我不理解Play和Scala足以控制它们。

So as far as I know I seem to be using my own unique configuration in build.sbt : 据我所知,我似乎在build.sbt使用我自己的唯一配置:

javaOptions ++= Seq(
    "-Dhttps.port=9443",
    "-Dhttps.keyStore.path=keystore.jks",
    "-Dhttps.keyStore.password=password")

It builds and runs ok: 它构建并运行正常:

p.c.s.NettyServer - Listening for HTTPS on port /0:0:0:0:0:0:0:0:9443
play.api.Play - Application started (Dev)

But on the first https:// access I get an endless stack trace in the Actuator UI: 但是在第一个https://访问中,我在Actuator UI中获得了无限的堆栈跟踪:

play.core.server.NettyServer$PlayPipelineFactory - cannot load SSL context
java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_45]
    ...
play.core.server.netty.PlayDefaultUpstreamHandler - Exception caught in Netty
java.lang.IllegalArgumentException: empty text
    at org.jboss.netty.handler.codec.http.HttpVersion.<init>(HttpVersion.java:89) ~[netty-3.10.3.Final.jar:na]
    ...

My first thought is that I'm not configuring it correctly but I haven't managed to find a definitive guide for Play 2.4. 我的第一个想法是我没有正确配置它,但我还没有设法找到Play 2.4的权威指南。 I'm seriously starting to question my Googling powers. 我真的开始质疑我的谷歌搜索权力。 I find lots of references to front-end proxies and avoiding SSL termination in Play but I'm not developing a public website and find this approach overkill. 我发现很多对前端代理的引用并避免在Play中使用SSL终止,但是我没有开发一个公共网站并发现这种方法有点过分。

I don't know if it's a red herring but the Netty project dropped the org.jboss.netty a long time ago and now uses io.netty . 我不知道它是不是红鲱鱼,但Netty项目很久以前就放弃了org.jboss.netty ,现在使用的是io.netty I see org.jboss.netty all over the stack trace and Play 2.4.2 seems to be using Netty 3.10.3.Final which is very old. 我看到整个堆栈跟踪org.jboss.netty和Play 2.4.2似乎都在使用Netty 3.10.3.Final这是非常古老的。 I happen to be familiar with Netty and have used 4.x in production while 5.x is currently in Alpha. 我碰巧熟悉Netty并且在生产中使用了4.x,而5.x目前在Alpha中。 Why is Play stuck in the past here? 为什么Play在这里被困? Should I be worried? 我应该担心吗?

I found several issues which seem closely related such as a bug in Play 2.2.x and a bug in AHC (which Play uses), but both appear to have been fixed well before Play 2.4.2 that I'm using. 我发现了几个似乎密切相关的问题,例如Play 2.2.x中 的错误和AHC中的错误 (Play使用的),但是在我正在使用的Play 2.4.2之前,两者似乎已经很好地修复了。 Nevertheless I tried fixes such as upgrading the async-http-client dependency, excluding the org.jboss.netty transitive dependency from async-http-client and upgrading to Netty 3.10.4.Final. 不过我尝试了修复,例如升级async-http-client依赖项,从async-http-client中排除org.jboss.netty传递依赖项并升级到Netty 3.10.4.Final。

So now I'm stuck but I feel like I'm just missing a getting started guide. 所以现在我被卡住了,但我觉得我只是错过了入门指南。 Maybe all these dependency issues and related bugs are just a waste of time? 也许所有这些依赖性问题和相关的错误只是浪费时间?

So 5 minutes after posting the question I figured it out... My configuration keys were wrong and the keystore path needed to be either absolute or relative to the project root (ie add conf/ if it's in your conf folder): 发布问题后5分钟我发现了...我的配置密钥错误密钥库路径需要绝对或相对于项目根目录(即添加conf /如果它在您的conf文件夹中):

javaOptions ++= Seq(
    "-Dhttps.port=9443",
    "-Dhttps.keyStore=conf/keystore.jks",
    "-Dhttps.keyStorePassword=password")

My mistake with the keys was to use dots per the documentation : 我对密钥的错误是根据文档使用点:

https.keyStore.path
https.keyStore.password

Instead of: 代替:

https.keyStore
https.keyStorePassword

I'm not sure how one gets from dot.notation to camelCase or even what exactly I'm configuring here. 我不确定如何从dot.notation到camelCase,甚至我在这里配置的是什么。 These parameters are more like the standard JVM arguments javax.net.ssl.keyStore and javax.net.ssl.keyStorePassword , yet not quite. 这些参数更像是标准的JVM参数javax.net.ssl.keyStorejavax.net.ssl.keyStorePassword ,但还不完全。 I feel like I'm missing a trick here. 我觉得我在这里错过了一招。 It would also be nice if Play would report that it couldn't find the keystore rather than an NPE, but since I seem to be configuring the JVM maybe there's nothing Play can do about it unless there is another way to configure this stuff... with decent documentation! 如果Play报告它找不到密钥库而不是NPE也会很好,但是因为我似乎正在配置JVM,所以除非有另一种方法来配置这些东西,否则Play无法做到这一点。有良好的文件!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM