我意识到这是一个非常古老的线程,但现在您可以从名为 Let's Encrypt 的 CA(证书颁发机构)获得免费证书。使用 Certbot ACME 协议客户端(自动证书管理环境)https://certbot.eff.org/ 获取证书非常容易。客户端需要您的服务器中的 root 访问权限。
1) 使用 certbot-auto 脚本安装 Cerbot
wget https://dl.eff.org/certbot-auto
chmod a+x ./certbot-auto
./certbot-auto --help
2) 使用独立插件或 webroot 插件获取许可证。 Standalone 将小型服务器打开到端口 80 或 443,因此任何一个端口都必须是空闲的。 Webroot 使用现有的正在运行的服务器。使用独立运行命令
certbot-auto certonly --standalone --standalone-supported-challenges http-01 -d yourdomain.com
使用 webroot 插件和独立插件,certonly 选项 certbot 将获取证书并将其存储到 /etc/letsencrypt/live/。
3) Let's Encrypt 的证书是短暂的(只有 90 天),所以记得更新这些证书
certbot-auto renew
4) 获得证书后,需要将其转换为 PKCS12 格式并将其存储到 Java 密钥库中。
openssl pkcs12 -export -in /etc/letsencrypt/live/yourdomain.com/fullchain.pem -inkey /etc/letsencrypt/live/yourdomain.com/privkey.pem -out /etc/letsenscrypt/live/yourdomain.com/pkcs.p12 -name mytlskeyalias -passout pass:mykeypassword
keytool -keystore /path/to/my/keystore -delete -alias ‘mytlskeyalias’ -storepass ‘mystorepassword’
keytool -importkeystore -deststorepass mystorepassword -destkeypass mykeypassword -destkeystore /path/to/my/keystore -srckeystore /etc/letsencrypt/live/mydomain.com/pkcs.p12 -srcstoretype PKCS12 -srcstorepass mykeypassword -alias mytlskeyalias
所有步骤在https://vaadin.com/blog/-/blogs/enabling-https-in-your-java-server-using-a-free-certificate中有更详细的描述
然后按照 Nikola Yovchev 的链接获取特定 Servlet 容器以启用 SSL/TLS。