简体   繁体   English

Tomcat/TomEE SSL 配置与 Cloudflare

[英]Tomcat/TomEE SSL config with Cloudflare

I have been having problems with the correct way to configure tomee with cloudflare provided SSL.我在使用 cloudflare 提供的 SSL 配置 tomee 的正确方法方面遇到问题。 First time doing this, so here is the situation:第一次这样做,所以情况如下:

1) First i create the keystore file: 1)首先我创建密钥库文件:

keytool -keysize 2048 -genkey -alias tomee -keyalg RSA -keystore tomee.keystore

2) Then i import the generated keystore: 2)然后我导入生成的密钥库:

keytool -importkeystore -srckeystore tomee.keystore -destkeystore tomee.keystore -deststoretype pkcs12

3) After importing, I create the CSR file for issuing a certificate request: 3) 导入后,我创建用于发出证书请求的 CSR 文件:

keytool -certreq -keyalg RSA -alias tomee -file FQDN.csr -keystore tomee.keystore

4) Then i go into cloudflare > ssl/tls > origin server > create certificate > select "I have my own private key and csr" > then i paste the FDQN.csr content in the text area > click next > finally i receive the PEM contents which i save on my server as FQDN.pem 4)然后我 go 进入 cloudflare > ssl/tls > 源服务器 > 创建证书 > select “我有自己的私钥和 csr” > 然后我将 FDQN.csr 内容粘贴到文本区域 > 单击下一步 > 最后我收到我在服务器上保存为 FQDN.pem 的 PEM 内容

5) Import the FQDN.pem into the keystore as a trusted certificate: 5) 将 FQDN.pem 作为可信证书导入密钥库:

keytool -import -alias tomee -keystore tomee.keystore -trustcacerts -file FQDN.pem

6) Copy the tomee.keystore file into the tomee conf dir 6) 将tomee.keystore 文件复制到tomee conf 目录中

7) Lastly I configure server.xml for tomee like so: 7) 最后,我为 tomee 配置 server.xml,如下所示:

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxThreads="150" SSLEnabled="true" 
            compression="on"  scheme="https" secure="true" keystoreFile="conf/tomee.keystore"
            keystorePass="myPasswordHere"
            SSLVerifyClient="none" SSLProtocol="TLSv1.2"
/>

8) Here i encounter the problem: Restart tomcat and issue a request over port 8443. It works but the certificate shows as invalid. 8)在这里我遇到了问题:重新启动tomcat并通过端口8443发出请求。它可以工作,但证书显示为无效。 And viewing the certificate, I get this: "This CA Root certificate is not trusted because it is not in the Trusted Root Certification Authorities store."查看证书,我得到:“此 CA 根证书不受信任,因为它不在受信任的根证书颁发机构存储中。”

As i see, by documentation HERE - Add Cloudflare Origin CA root certificates , i may need to add additional configurations with the provided files.如我所见,通过 此处的文档-添加 Cloudflare Origin CA 根证书,我可能需要使用提供的文件添加其他配置。 Do i understand correctly or am i missing something?我理解正确还是我错过了什么? If so - what would those configs look like?如果是这样 - 这些配置会是什么样子? Should i be doing something like in the demonstrated format in the server.xml file, like so:( or is that a completely different thing?)我是否应该像 server.xml 文件中演示的格式那样做一些事情,就像这样:(或者那是完全不同的事情?)

<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
           maxThreads="150" SSLEnabled="true" >
    <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" xpoweredBy="false" server="Apache TomEE" />
    <SSLHostConfig>
        <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                     certificateFile="conf/localhost-rsa-cert.pem"
                     certificateChainFile="conf/localhost-rsa-chain.pem"
                     type="RSA" />
    </SSLHostConfig>
</Connector>

Interestingly there is not that much info on this online and i have been struggling to understand the problem for quite a few days now.有趣的是,网上没有太多关于此的信息,而且我这几天一直在努力理解这个问题。 Any light shed on this would be helpful.对此的任何启示都会有所帮助。

Kudos to people who posted a similar topic HERE向在此处发布类似主题的人表示敬意

Managed to solve it.设法解决它。 To anyone interested, there were 2 problems:对于任何感兴趣的人,有两个问题:

1) Before performing step 5) for tomcat/tomee webservers, you need to add a trusted root certificate, with the cloudflare provided key from HERE(Configure the SSL/TLS mode in the Cloudflare SSL/TLS app) . 1) 在为 tomcat/tomee 网络服务器执行步骤 5) 之前,您需要添加一个受信任的根证书,其中 cloudflare 提供的密钥来自HERE(在 Cloudflare SSL/TLS 应用程序中配置 SSL/TLS 模式)

keytool -import -alias root -keystore tomee.keystore -trustcacerts -file origin_ca_rsa_root.pem

Then add your aliased rsa to the keystore as in 5).然后将您的别名 rsa 添加到密钥库,如 5)。

2) Other problem was with an overlooked CN config on cloudflare DNS settings, so check your configs. 2) 其他问题是 cloudflare DNS 设置上的 CN 配置被忽略,因此请检查您的配置。

Hope this helps someone:)希望这对某人有帮助:)

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

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