## page was renamed from ssl-selfcert ## Please edit system and help pages ONLY in the master wiki! ## For more information, please see MoinMoin:MoinDev/Translation. ## IMPORTANT NOTE: ## When you use this page as a template for creating your project page: ## * please remove all lines starting with two hashes (##) ## * except the acl line, please keep that, but remove one hash, so it reads #acl ... ## * fix the acl line so it has the correct page instead of the sample Project/...Group ##acl Project/AdminGroup:admin,read,write,delete,revert Project/ReadWriteGroup:read,write Project/ReadGroup:read ##master-page:Unknown-Page ##master-date:Unknown-Date #format wiki #language en = SSL証明書の作成方法 = == SSL自己発行証明書(暫定)の作成 == 1. opensslを使用してSHA1で署名する場合(期限10年) {{{ openssl genrsa -out test.key 2048 openssl req -new -key test.key -x509 -days 3652 -out test.crt -sha1 }}} 内容の確認方法 {{{ openssl x509 -text -noout -in test.crt }}} == Let's Encrypt SSL証明書の作成と更新 == == EPELの certbot を使用する場合  == 参考 *[[https://free-ssl.jp/|Let's Encrypt 総合ポータル(公式ではない)]] *[[https://www.server-memo.net/tips/lets-encrypt.html|【CentOS7】Lets EncryptでSSL証明書を取得 ]] 1.certbotを epelからインストール (2021.5.28時点で CentOS7/SL7 および CentOS 8 に certbot がepelにある) {{{ # yum install epel-release # yum install certbot python-certbot-apache }}} 2. httpdを停止して、初期の証明書ファイルを作成 (注:あらかじめ、SSL自己発行証明書でセキュリティ監査を受け、http/https は外部にopenしていること) -d の後に、証明したいホストのFQDNを記述する。 {{{ # systemctl stop httpd # certbot certonly --standalone -d ribfnewhost.riken.jp }}} その後、自分のEmailアドレスを入力(証明書の有効期限の19日前にメール通知がくる)、規約を読み承諾(A)gree する。後半の選択(share your email address with the Electronic Frontier Foundation)は、必要があれば承諾する(無理に承諾する必要はない)その後、以下のようにSSL証明書が作成されるので、これらを /etc/httpd/conf.d/ssl.conf 中で指定。 {{{ Starting new HTTPS connection (1): supporters.eff.org Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org Obtaining a new certificate Performing the following challenges: http-01 challenge for ribfnewhost.riken.jp Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/ribfnewhost.riken.jp/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/ribfnewhost.riken.jp/privkey.pem Your cert will expire on 2019-02-05. 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" - 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 }}} 必要な証明書のpath (下記のsymbolic linkの元を指定:証明書を更新するとlink先のファイル名が変わる) {{{ # ls -l /etc/letsencrypt/live/ribfnewhost.riken.jp/ total 4 -rw-r--r-- 1 root root 682 Nov 7 14:28 README lrwxrwxrwx 1 root root 39 Nov 7 14:28 cert.pem -> ../../archive/ribfnewhost.riken.jp/cert1.pem lrwxrwxrwx 1 root root 40 Nov 7 14:28 chain.pem -> ../../archive/ribfnewhost.riken.jp/chain1.pem lrwxrwxrwx 1 root root 44 Nov 7 14:28 fullchain.pem -> ../../archive/ribfnewhost.riken.jp/fullchain1.pem lrwxrwxrwx 1 root root 42 Nov 7 14:28 privkey.pem -> ../../archive/rribfnewhost.riken.jp/privkey1.pem # }}} 3. conf.d/ssl.conf 中 以下の設定等 {{{ SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 # https://mozilla.github.io/server-side-tls/ssl-config-generator/ # https://www.ssllabs.com/ssltest/analyze.html SSLCipherSuite ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:!DSS:!3DES SSLHonorCipherOrder on SSLCertificateFile /etc/letsencrypt/live/ribfnewhost.riken.jp/cert.pem SSLCertificateChainFile /etc/letsencrypt/live/ribfnewhost.riken.jp/chain.pem SSLCertificateKeyFile /etc/letsencrypt/live/ribfnewhost.riken.jp/privkey.pem }}} 4.証明書の有効期限は3ヶ月なので、cronで自動更新の設定(週に〜1度程度実行) 更新を standalone で行いたい時は {{{ certbot renew --pre-hook "systemctl stop httpd" --post-hook "systemctl start httpd" }}} を実行。(--pre-hook --post-hook は実際に更新が行われる時のみに実行される) NB1:certbot renew実行時は http/https は外部に対して openしている必要がある. 上記は apache httpd で Document Root を標準の /var/www/html/ として使用している場合。 NB2: apache httpdが動いている時のcertbotでの更新はエラーでうまく実行できない時があるので注意。 更新は standalone で行うのが安全 (2019.3.25追記) crontabの実際の設定例(SL7.6) {{{ 50 2 * * 1 certbot renew --webroot-path /var/www/html/ --pre-hook "systemctl stop httpd" --post-hook "systemctl start httpd" }}} (2019.8.19動作再検証OK, @ribfml)