从godaddy购买ssl证书以及如何应用到tomcat上

折腾了几个小时,因为就没一个完整的说的对的。
大体过程是生成keystore和csr,然后提交csr给godaddy,下载tomcat版本的证书,把证书导入到自己的keystore。
下面是具体过程。
准备工作是把jdk的bin文件夹加入到path里面,保证能访问到keytool(或者直接进入这个文件夹执行命令)
1.访问
https://www.digicert.com/easy-csr/keytool.htm
填写必要的信息,尤其是common name,是网站域名.结果是生成命令,拷贝到命令行里面直接之行,会生成一个jks文件和一个csr文件,注意jks文件其实就是.keystore,名字不同而已。
注意这里要记住密码。

2.csr文件内容提交到godaddy,然后下载tomcat版本。

3.下面先解释一下压缩包里面几个文件的含义。
根据
http://serverfault.com/questions/578025/discerning-godaddy-ssl-certificate-types
的说明:
gd_bundle-g2-g1.crt: Go Daddy Certificate Bundles - G2 With Cross to G1, includes Root
gdig2.crt: Go Daddy Secure Server Certificate (Intermediate Certificate) - G2
随机id.crt: Your certificate

4.下面开始导入这几个文件到.keystore文件(或者说是jks文件)
正常给人的感觉是分别导入
gd_bundle-g2-g1.crt
gdig2.crt
xxxxxx.crt(压缩包里面一个随机id.crt的文件)
是可以的,godaddy的文档貌似也是这么解释的,实际上不是。
需要访问
https://certs.godaddy.com/repository
下载gdroot-g2.crt,作为root CA进行签名。
对我来说是:
keytool -import -alias root -keystore tomcat.keystore -storepass 密码 -trustcacerts -file gdroot-g2.crt
keytool -import -alias intermed -keystore tomcat.keystore -storepass 密码 -trustcacerts -file gdig2.crt
keytool -import -alias server -keystore tomcat.keystore -storepass 密码-trustcacerts -file 随机id.crt (注意这里alias是server,是因为最早生成keystore的时候,alias是server,很多文档写的tomcat,因为开始生成keystore使用的alias是tomcat)
需要注意的是,如果直接把gd_bundle-g2-g1.crt作为root,会报告错误:无法从回复中建立链(Failed to establish chain from reply)

然后把这个tomcata.keystore(我没有叫tomcat.jks主要是为了以后看起来明确这个文件是干什么的),以及密码配置到server.xml即可。

    <Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"  keystoreFile="路径/tomcat.keystore" keystorePass="密码"/>
现在浏览器访问,不会再报告ssl不安全了。

猜你喜欢

转载自flashing.iteye.com/blog/2162315