こんにちは。
夏休みが終わって愕然としている武田です。

今回は無料でSSL証明書が発行できるというLet’s Encryptを試してみたいと思います。
うまく使えるようなら開発環境とかでSSLなくて困る時なんかに便利だなとか目をつけておりました。

では早速、インストールできるか試してみましょう。
今回は以下の環境を利用します

CentOS release 6.9 (Final)
Apache/2.2.15 (Unix)

Certbot クライアントのインストール

どうも確認してみるとLet’s Encryptというものは普通のSSL証明書とは違い、専用のクライアントソフトを利用して証明書の取得をするようです。

  • yumの調整 epelリポジトリを見るように変更
    sudo yum install epel-release

  • Certbot クライアントをダウンロード・インストール

[root@localhost ~]# wget https://dl.eff.org/certbot-auto
--2017-10-05 18:36:44--  https://dl.eff.org/certbot-auto
Resolving dl.eff.org... 151.101.72.201, 2a04:4e42:11::201
Connecting to dl.eff.org|151.101.72.201|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 57312 (56K) [application/octet-stream]
Saving to: “certbot-auto”

100%[================================================================================================>] 57,312      --.-K/s   in 0.009s

2017-10-05 18:36:45 (5.95 MB/s) - “certbot-auto” saved [57312/57312]

[root@localhost ~]# chmod a+x certbot-auto
[root@localhost ~]# ./certbot-auto
Bootstrapping dependencies for RedHat-based OSes... (you can skip this with --no-bootstrap)
yum is /usr/bin/yum
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
Package gcc-4.4.7-18.el6.x86_64 already installed and

...

途中でいくつか選択肢がでるので入力します。

  • メールアドレスが必要そうなので設定
Invalid email address: .
Enter email address (used for urgent renewal and security notices)

If you really want to skip this, you can run the client with
--register-unsafely-without-email but make sure you then backup your account key
from /etc/letsencrypt/accounts

 (Enter 'c' to cancel): xxxxxxxxxxxx@gmail.com
/opt/eff.org/certbot/venv/lib/python2.6/site-packages/acme/jose/jwa.py:110: DeprecationWarning: signer and verifier have been deprecated.                                                                          Please use sign and verify instead.
  signer = key.signer(self.padding, self.hash)
  • 続いて利用許諾の選択肢がでるので受諾します。
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A
  • MLあるらしいので一応、受けるようにYとします。
-------------------------------------------------------------------------------
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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
  • おっと、そのままapacheのconfigを見てどのドメインで証明書使うか聞いてくれてますね。
    気が利くやつです。現状は1つしかドメインがないのでそれを選択します。
    選択後にその形でのapacheの設定ファイルまで書き出してるようです。
    本当に気が利くやつです。
Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: xxxxx.xyz
-------------------------------------------------------------------------------
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for xxxxx.xyz
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf/httpd-le-ssl.conf
Enabling NameVirtualHosts on *:443
Deploying Certificate for xxxxx.xyz to VirtualHost /etc/httpd/conf/httpd-le-ssl.conf
  • httpでのアクセスはhttpsへリダイレクトさせるか聞いてるようですね。ここはhttpをイキとしておきます。
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
  • これで一応の設定はできたようです。
-------------------------------------------------------------------------------
Congratulations! You have successfully enabled https://xxxxx.xyz

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=xxxxx.xyz
-------------------------------------------------------------------------------
  • 証明書の状況をみれるサイトが紹介されてるので見てみましょう。


なんかいけてそうな雰囲気ですね。

  • 先程、apacheの設定ファイルを書き出してくれたので有効化するため再起動をかけます。
[root@localhost ~]# service httpd configtest
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK
[root@localhost ~]#
[root@localhost ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]

問題なく再起動できましたね。

ちなみに設定ファイルを見てみると証明書に必要な(サーバ証明書(公開鍵)、中間証明書、秘密鍵)
が自動的に書き出さされているようですね

[root@localhost ~]# cat  /etc/httpd/conf/httpd-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
  ServerName xxxxx.xyz
  DirectoryIndex index.html index.php
  ErrorLog logs/xxxxx-error_log
  CustomLog logs/xxxxx-access_log common
  AddDefaultCharset UTF-8
  DocumentRoot /var/www/xxxxx/
  <Directory "/var/www/xxxxx/">
    AllowOverride All
    Options FollowSymLinks -Indexes
  </Directory>
SSLCertificateFile /etc/letsencrypt/live/xxxxx.xyz/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxxxx.xyz/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/xxxxx.xyz/chain.pem
</VirtualHost>
</IfModule>

ブラウザでの証明書確認

実機動いてくれなきゃ意味がありません。
ブラウザで見てみましょう。


ブラウザでもエラー出てないですね。

念のために証明書詳細を見てみても問題なさそうです。

他のブラウザでも試してみましたが全て問題なく証明書Okのマークが付いてました

  • windows
    Firefox、Internet Explorer、Chrome
  • Mac
    safari
  • Android
    Chrome
  • ios
    safari

まとめ

無料でSSL証明書が作れる[Let’s Encrypt]いかがでしたでしょうか。
割りと手軽に作れるので証明書必須の開発環境などあったら検討してみてはいかがでしょうか。
以下の点だけはちょっとご注意ください。

  • 専用のクライアントソフトを入れる必要があるのでインストール作業などを柔軟にできるサーバ
  • 期限が90日なのでちょっとそこは注意(コマンドで期限の近いものを更新するものはあるようです・・)

参考