概要
Raspbian(Jessie) Apache2.4をSSLに対応させる。
OpenSSLとmod_ssl
参考にさせて頂いたWEBページ
ほぼまんまです。
http://symfoware.blog68.fc2.com/blog-entry-1120.html
公開鍵暗号について解り易い説明があります。
http://www.adminweb.jp/web-service/ssh/index4.html
環境
Raspbery Pi2 Jessie
Apache/2.4.10 (Raspbian)
手順
1. OpenSSLのインストール
$ sudo apt-get install openssl
2. 秘密鍵の生成
ディレクトリに移動してRSA形式の秘密鍵を作成します。。赤字の部分に入力していきます。
$ cd /etc/ssl/certs
$ sudo openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
.......++++++
..++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:パスフレーズ入力
Verifying - Enter pass phrase for server.key:パスフレーズ再入力
このままだとApacheの起動のたびにパスフレーズの入力を求められるので、ENCRIPTを解除しておきます。
$ sudo openssl rsa -in server.key -out server.key
Enter pass phrase for server.key:先程のパスフレーズ
writing RSA key
3.サーバー証明書の生成
まず証明要求を生成します。
赤字の部分に入力していきます。
Common Nameはhttps://[ここの名称]/を指定しますが、ローカルでの確認のみなのでプライベートIPアドレスを設定しました。
$ openssl req -new -days 3650 -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Hyogo
Locality Name (eg, city) []:Kinosaki
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Nonomura Co.,Ltd.
Organizational Unit Name (eg, section) []:Member of a prefectural assembly
Common Name (e.g. server FQDN or YOUR name) []:サーバーのFQDN
Email Address []:Eメールアドレス
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
これで要求ファイルが出来たので証明書を発行します。
$ sudo openssl x509 -in server.csr -out server.crt -req -signkey
これで以下のファイルが出来ました。
server.key:秘密鍵
server.csr:証明書要求ファイル(不要)
server.cst:証明書
パーミッションを変更しておきます。
$ sudo chmode 400 server.*
4. ApacheのSSL設定
ApacheのインストールでSSLモジュールも標準でインストールされていますので、これを有効化します。
$ sudo a2enamod ssl
次に/etc/apache2/sites-available/default-ssl.confを編集し、ServerNameと証明書、秘密鍵のパスを設定します。
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
# add 20160609
ServerName 192.168.1.222:443 # 追加 証明書作成時のCommon Name
(略)
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
# modified 20160609
SSLCertificateFile /etc/ssl/certs/server.crt # 証明書
SSLCertificateKeyFile /etc/ssl/certs/server.key # 秘密鍵
(略)
a2ensiteで、sslのサイトを有効化。
$ sudo a2ensite default-ssl
最後にapacheを再起動します。
$ sudo service apache2 reload
確認
ローカルにある別マシンでWEBブラウザを立ち上げurlに
https://192.168.1.222/
と入力。
セキュリティの問題ありとの警告がですので証明書をインポートしてやると、以降はhttpsでアクセスが可能となります。