Warm tip: This article is reproduced from serverfault.com, please click

其他-如何将letsencrypt免费的ssl安装到glassfish 4.x服务器

(其他 - How to install letsencrypt free ssl to glassfish 4.x server)

发布于 2017-05-24 12:36:22

我已经扫描了SO,发现没有关于在glassfish上安装letsencrypt.org SSL证书的详细说明,特别是在本教程中,我将使用glassfish 4.1.2 build 1。整理以下指南。因此,我希望问和回答我自己的问题很好。

在本教程中,我将使用从Ubuntu 16.04 LTS桌面进行Shell访问的Ubuntu 16.04 LTS服务器。

Questioner
qualebs
Viewed
11
7,756 2017-07-20 15:25:50

访问certbot并按照以下说明设置系统

安装

在Ubuntu系统上,Certbot团队维护一个PPA。将其添加到存储库列表后,你需要做的就是适当地获得以下软件包。

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install certbot 

开始使用

由于你的服务器体系结构尚不支持自动安装,因此必须使用certonly命令来获取证书。

$ sudo certbot certonly

终端将输出

Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
1: Place files in webroot directory (webroot)
2: Spin up a temporary webserver (standalone)
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1

我们在1中选择第一个选项键,然后按Enter

终端将输出

Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel):yoursite.com www.yoursite.com
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for yoursite.com
http-01 challenge for www.yoursite.com

终端将输出

Select the webroot for yoursite.com:


1: Enter a new webroot
Press 1 [enter] to confirm the selection (press 'c' to cancel): 1
Input the webroot for yoursite.com: (Enter 'c' to cancel):/home/yourUsername/glassfish4/glassfish/domains/domain1/docroot

Select the webroot for www.yoursite.com:


1: Enter a new webroot
2: /home/yoursite/glassfish4/glassfish/domains/domain1/docroot


Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Waiting for verification...
Cleaning up challenges
Generating key (2048 bits): /etc/letsencrypt/keys/0000_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0000_csr-certbot.pem

终端将输出

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/yoursite.com/fullchain.pem. Your cert will
   expire on 2017-08-21. To obtain a new or tweaked version of this
   certificate in the future, simply run certbot again. To
   non-interactively renew *all* of your certificates, run "certbot
   renew"

自动续订

系统上的Certbot程序包附带一个cron作业,该作业将在证书过期之前自动对其进行续订。由于“让我们加密”证书可以使用90天,因此强烈建议你使用此功能。你可以通过运行以下命令来测试证书的自动续订:

certbot renew --dry-run

使以下脚本可以自动将证书导入到glassfish

进一步阅读

https://community.letsencrypt.org/t/importing-letsencrypt-into-java-and-glassfish/9711

现在,我们导入证书。制作以下脚本并将其保存为yourscriptname.sh自动化过程,然后使用以下命令运行它

$ sh yourscriptname.sh

#!/bin/sh

DOMAIN=yoursite.com
#note that changeit is the default keystore password
KEYSTOREPW=changeit
GFDOMAIN=/home/yourUsername/glassfish4/glassfish/domains/domain1
LIVE=/etc/letsencrypt/live/$DOMAIN

mkdir etc
cd etc

sudo openssl pkcs12 -export -in $LIVE/cert.pem -inkey $LIVE/privkey.pem -out cert_and_key.p12 -name myalias -CAfile $LIVE/chain.pem -caname root -password pass:$KEYSTOREPW
sudo keytool -importkeystore -destkeystore keystore.jks -srckeystore cert_and_key.p12 -srcstoretype PKCS12 -alias myalias -srcstorepass $KEYSTOREPW -deststorepass $KEYSTOREPW -destkeypass $KEYSTOREPW
sudo keytool -import -noprompt -trustcacerts -alias root -file $LIVE/chain.pem -keystore keystore.jks -srcstorepass $KEYSTOREPW -deststorepass $KEYSTOREPW -destkeypass $KEYSTOREPW

sudo openssl pkcs12 -export -in $LIVE/fullchain.pem -inkey $LIVE/privkey.pem -out pkcs.p12 -name glassfish-instance -password pass:$KEYSTOREPW
sudo keytool -importkeystore -destkeystore keystore.jks -srckeystore pkcs.p12 -srcstoretype PKCS12 -alias glassfish-instance -srcstorepass $KEYSTOREPW -deststorepass $KEYSTOREPW -destkeypass $KEYSTOREPW
sudo openssl pkcs12 -export -in $LIVE/fullchain.pem -inkey $LIVE/privkey.pem -out pkcs.p12 -name s1as -password pass:$KEYSTOREPW
sudo keytool -importkeystore -destkeystore keystore.jks -srckeystore pkcs.p12 -srcstoretype PKCS12 -alias s1as -srcstorepass $KEYSTOREPW -deststorepass $KEYSTOREPW -destkeypass $KEYSTOREPW

sudo keytool -list -keystore keystore.jks -storepass $KEYSTOREPW

sudo cp -f keystore.jks $GFDOMAIN/config/

sudo service glassfish stop
sudo service glassfish start

cd ..
sudo rm -rf etc

如果你需要更改密钥库密码

使用keytool命令。如果它不起作用,则可能必须转到cd它在glassfish-install-dir/glassfish/domains/domain1/config目录中的路径,然后在该目录中运行命令。

keytool -storepasswd -keystore /path/to/keystore
Enter keystore password:  changeit
New keystore password:  new-password
Re-enter new keystore password:  new-password

成功导入证书并重新启动glassfish服务器后,SSL可以与已安装的Web应用程序一起使用,但是不幸的是,尽管asadmin tool仍然可以使用,但我无法从浏览器登录到glassfish管理控制台

解决以上更改后无法登录管理控制台的问题

我们需要在脚本中添加wget命令,以从出现的每个日期下载最新的CA文件修订,这些更新来自mozilla的最近受信任的ca修订

将以下内容添加到该yourname.sh命令上方脚本中,sudo service glassfish stop以解决该问题。

wget https://curl.haxx.se/ca/cacert-2017-01-18.pem --no-check-certificate -O cacert.pem

PEM_FILE=cacert.pem
KEYSTORE=cacerts.jks

CERTS=$(grep 'END CERTIFICATE' $PEM_FILE| wc -l)

for N in $(seq 0 $(($CERTS -1))); do
    ALIAS="${PEM_FILE%.*}-$N"
    cat $PEM_FILE | awk "n==$N { print }; /END CERTIFICATE/ { n++ }" |
    keytool -noprompt -import -trustcacerts \
            -alias $ALIAS -keystore $KEYSTORE -storepass $KEYSTOREPW
done
sudo keytool -list -keystore keystore.jks -storepass $KEYSTOREPW
sudo keytool -list -keystore cacerts.jks -storepass $KEYSTOREPW

if [ ! -f $GFDOMAIN/config/keystore-orig.jks ]; then
echo "Backing up original files..."
sudo cp -f $GFDOMAIN/config/keystore.jks $GFDOMAIN/config/keystore-orig.jks
sudo cp -f $GFDOMAIN/config/cacerts.jks $GFDOMAIN/config/cacerts-orig.jks
fi
echo "Updating certificates..."
sudo cp -f keystore.jks $GFDOMAIN/config/keystore.jks
sudo cp -f cacerts.jks $GFDOMAIN/config/cacerts.jks

cd ..

echo stop and restart glassfish domain to complete

cd ..
sudo rm -rf etc

我希望这可以帮助所有人加油!