Let'sEncryptワイルドカードHTTPS証明書Tomcatを使用する

参考記事:https//www.cnblogs.com/wzlinux/p/11188454.html

参考記事https://blog.csdn.net/lyq8479/article/details/79022888

 

1.1。ワイルドカード証明書とは何ですか

パンドメイン証明書とも呼ばれるワイルドカード証明書は、ドメイン名の同じレベルのサブドメインを保護できるため、すべてhttpsで暗号化されたリンクになります。サブドメイン名を構成して新しい証明書を申請する必要はありません。ドメイン名の数により、いつでもサブドメインを追加する際に追加料金を支払う必要がなくなります。複数のサブドメインを持つユーザー、特に多数のサブドメインを持つユーザーにとっては、費用対効果が高く、非常に効率的です。多くの時間とお金を節約します。

1.2 Let'sEncryptとは

HTTPS Webサイトを展開する場合は、証明書が必要です。証明書はCA組織によって発行されます。ほとんどの従来のCA組織は、証明書の発行に料金を請求しますが、これはHTTPSプロトコルの使用を促進するのに役立ちません。

Let's EncryptもCA組織ですが、このCA組織は無料です。つまり、証明書の発行は無料です。

Let's Encryptは非営利団体であり、経費を管理する必要があるため、非常に創造的なことを行い、ACMEプロトコルを設計しました。プロトコルの現在のバージョンはv1です。

次に、なぜACME契約を作成するのですか?従来のCA組織は、証明書の申請、証明書の更新、および証明書の失効を手動で受け入れます。これらはすべて手動で処理されます。ACMEプロトコルは、証明書の申請、更新、失効のプロセスを標準化します。クライアントがプロトコルの機能を実装している限り、クライアントはLet's Encryptから証明書を申請できます。つまり、Let's EncryptCAは完全に自動化されています。

ACMEプロトコルに基づいて誰でもクライアントを実装できます。公式に推奨されるクライアントはCertbotです。

公式クライアントのリストについては、https://letsencrypt.org/docs/client-options/を確認してください。

2、証明書アプリケーション(certbot)

2.1。システムの決定

私たちはawslightsailサービスによって作成されたシステムを使用しており、システムはCentOS7です。

 

2.2。ツールのインストール

まず、epelソースをシステムに追加します。

curl -o /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo

証明書アプリケーションツールCertbotをインストールします。

yum install -y certbot

2.3、証明書の申請

hlvy.comは、www.baidu.comなどのドメイン名です。baidu.comに入力する必要があります。どのxxx.baidu.comとも一致します。

certbot certonly  -d *.hlvy.com --manual \
--preferred-challenges dns \
--server https://acme-v02.api.letsencrypt.org/directory
  • -手動のインタラクティブな取得、
  • --preferred-challenges dnsはDNS検証を使用します(汎ドメイン名はDNS検証のみを使用できます)。このオプションをキャンセルすると、デフォルトでhttpフォーム認証(.well-known)が使用されます。
  • --serverは、acme-v02をサポートするサーバーアドレスを指定します。デフォルトはacme-v01のアドレスです。

申請プロセスは次のとおりです。ドメイン名が管理権限内にあることを確認するために、私たちは私たちの間でTXTDNS解決を行う必要があります。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for wzlinux.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.wzlinux.com with the following value:

EFC5zDV4Yyz1DY6796qHlUCS-TBWQCuxj3Re_-kTiiI

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
Waiting for verification...
Cleaning up challenges
Resetting dropped connection: acme-v02.api.letsencrypt.org

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/hlvy.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/hlvy.com/privkey.pem
   Your cert will expire on 2019-09-04. 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"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

上記のDNS解決要件があることがわかり、ここでAlibabaCloudに設定しました。Enterキーを押して続行する前にEnterキーを押さないでください

最初にAlibabaCloudでドメイン名を設定します

EFC5zDV4Yyz1DY6796qHlUCS-TBWQCuxj3Re_-kTiiIこれは、上記をコピーして生成された分析パスです。

分析が完了したら、サーバー上の分析レコードを確認します。

[root@ip-172-26-5-120 ~]# dig -t txt _acme-challenge.hlvy.com

; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> -t txt _acme-challenge.hlvy.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47252
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;_acme-challenge.hlvy.com.INTXT

;; ANSWER SECTION:
_acme-challenge.hlvy.com. 58INTXT"EFC5zDV4Yyz1DY6796qHlUCS-TBWQCuxj3Re_-kTiiI"

;; Query time: 0 msec
;; SERVER: 172.26.0.2#53(172.26.0.2)
;; WHEN: Thu Jun 06 07:04:07 UTC 2019
;; MSG SIZE  rcvd: 112

2.4、証明書ビュー

[root@ip-172-26-5-120 ~]# ll /etc/letsencrypt/live/hlvy.com/
total 4
lrwxrwxrwx. 1 root root  35 Jun  6 06:53 cert.pem -> ../../archive/hlvy.com/cert1.pem
lrwxrwxrwx. 1 root root  36 Jun  6 06:53 chain.pem -> ../../archive/hlvy.com/chain1.pem
lrwxrwxrwx. 1 root root  40 Jun  6 06:53 fullchain.pem -> ../../archive/hlvy.com/fullchain1.pem
lrwxrwxrwx. 1 root root  38 Jun  6 06:53 privkey.pem -> ../../archive/hlvy.com/privkey1.pem
-rw-r--r--. 1 root root 692 Jun  6 06:53 README

 

Tomcat7configure無料のSSL証明書を暗号化しましょう

上の図(証明書の取得が成功した場合のプロンプトメッセージ)からわかるように、取得したLet's Encrypt証明書は/etc/letsencrypt/live/hlvy.com/ディレクトリに保存され、4つの関連する証明書ファイルがあります。


cert.pem
chain.pem
fullchain.pem
privkey.pem


次の2つの証明書ファイルを使用する必要があります:fullchain.pemとprivkey.pem。次に、Linuxでopensslツールとkeytoolツールを使用して、SSL証明書を.pem形式からTomcatでサポートされている.jks形式に変換する必要があります。

# 导出.p12格式的证书
$ openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out hlvy_letsencrypt.p12 -name tomcat_letsencrypt

# 再将证书由.p12格式转换成.jks格式
$ keytool -importkeystore -deststorepass '123456' -destkeypass '123456' -destkeystore hlvy_letsencrypt.jks -srckeystore zyxx_letsencrypt.p12 -srcstoretype PKCS12 -srcstorepass '123456' -alias tomcat_letsencrypt


注:opensslコマンドを実行して.p12形式の証明書をエクスポートすると、キーを設定するように求められます。keytoolコマンドを実行するときにキーを書き込む場所も3つあります。最も簡単な方法は、同じキーを使用することです。キーが必要なすべての場所に。混乱します。

 

上記の2つの手順の後、新しい証明書hlvy_letsencrypt.jksが/etc/letsencrypt/live/hlvy.com/ディレクトリの下に生成されます。次に、%tomcat%/ conf / server.xmlファイルを変更し、2行の構成keystoreFileとkeystorePassを追加します。その中で、keystoreFileはjks証明書ファイルを指し、keystorePassは証明書のキーです。変更後の主な構成は次のとおりです。


<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS"
    keystoreFile="/home/test/hlvy_letsencrypt.jks"
    keystorePass="123456"
/>

プロジェクトアドレスにアクセスして、次のようなブラウザ証明書を表示します

2.6、证书更新
可以使用指令certbot renew进行更新,添加一个定时任务。

[root@ip-172-26-5-120 ~]# certbot renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/hlvy.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not yet due for renewal

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The following certs are not due for renewal yet:
  /etc/letsencrypt/live/hlvy.com/fullchain.pem expires on 2019-09-04 (skipped)
No renewals were attempted.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
定时任务。

certbot renew 30 1 10 * * /usr/bin/certbot renew && systemctl reload nginx

 

おすすめ

転載: blog.csdn.net/qq_39313596/article/details/103120778