CONTENTS


Lastmodified 2015-05-22 (金) 08:16:24


server.crt の更新

https://www.cacert.org/ で、更新にチェックして新しい証明書を更新して、

-----BEGIN CERTIFICATE-----
6+VIBrK82HtXgeFbr0feGYS3hfuEO2MqSH7moISWEkHBoKfqaY7KwayWejTXupSm
piFFLVRO6R+I7fmDdNi2hA==
-----END CERTIFICATE-----

をゲットする。

使用中のserver.crtと入れ換えて、

# apachectl restart

する

バーチャルホストの証明書の更新の場合は、設定ファイルを翌確認することw

/usr/local/etc/apache22/ssl/thousand_winds_jp

間違うと、apache が起動しません。

FreeBSDに限っての話ですが、2018bit キーの作り方をφ(..)メモメモ

キーを置きたいディレクトリに移動。(例:/usr/local/etc/apache22/

1. server.key (2048bit)作成

# /usr/bin/openssl genrsa -rand /var/log/messages -des3 -out server.key 2048 semi-random bytes loaded

2. server.scr を作成

# /usr/bin/openssl req -new -key server.key -out server.csr

このときCNとFQDNを一致させないと「証明書のエラーアドレスが一致しません」と言わる

3. key のパスフレーズを消去。(Apacheの再起動のたびに訊かれるので)

# mv  server.key server.key.orig
# openssl rsa -in server.key.orig -out server.key
Enter pass phrase for www.smb.net.key.orig:*********
writing RSA key

4.パーミッションを変えておく

# chmod 600 server.*

いじょ!( ̄^ ̄)ゞ


証明書の更新ができなくなったった!Σ(゚д゚lll)

CACertから「サーバ証明書の期限がきれるお」っちうメールがきたので、いつものようにCACertへアクセスして、

更新にチェックして実行する・・・も、

以下の証明書を更新しています:
Processing request 514883:
The keys that you use are very small and therefore insecure. Please generate stronger keys.
More information about this issue can be found in the wiki

と怒られた。で、Wikiを見ると https://wiki.cacert.org/WeakKeys#SmallKey

Cause: Small Key Size

If the key is too small: 
The keys that you use are very small and therefore insecure. Please generate stronger keys. 

Currently 2048 bit key size with an exponent of at least 65537 is recommended (see <NIST>) 

More information about this issue can be found in How to prevent Small Key size and Suggest Key Sizes 

という、お達し。手元のキーが作ったキーが、1024 bit だったのが駄目らしい。

ということで、作り直し!( ̄^ ̄)ゞ

新しいserver.key(2048bit)を作る

コマンドは、こう。前は、1024 54002 とか指定してたのを、2048だけにしてみる。

/usr/bin/openssl genrsa -rand /var/log/messages -des3 -out /usr/local/etc/apache22/server.key 2048 semi-random bytes loaded

或いは、相対パスで、

/usr/bin/openssl genrsa -rand /var/log/messages -des3 -out server.key 2048 semi-random bytes loaded

実際には、こんな風。

root@mail:/usr/local/etc/apache22 # /usr/bin/openssl genrsa -rand /var/log/messages -des3 -out /usr/local/etc/apache22/server.key 2048 semi-random bytes loaded 43223 semi-random bytes loaded
Generating RSA private key, 2048 bit long modulus
......................+++
..........................................................................................................................................+++
e is 65537 (0x10001)
Enter pass phrase for /usr/local/etc/apache22/server.key: パスフレーズを打ちます
Verifying - Enter pass phrase for /usr/local/etc/apache22/server.key: も一回パスフレーズを打つ、ヨロシ

すると、server.key 出来るアル。

root@mail:/usr/local/etc/apache22 # ll
total 92
drwxr-xr-x  2 root  wheel    512 Nov 12 17:19 Includes/
drwxr-xr-x  2 root  wheel    512 Nov 12 17:19 envvars.d/
drwxr-xr-x  2 root  wheel    512 Nov 12 17:19 extra/
-rw-r--r--  1 root  wheel  17056 Jul 26 11:26 httpd.conf
-rw-r--r--  1 root  wheel  12958 Nov 12 17:19 magic
-rw-r--r--  1 root  wheel  53011 Nov 12 17:19 mime.types
-rw-r--r--  1 root  wheel   1743 Nov 30 16:15 server.key

CACert 提出用 server.scr を作るアル

root@mail:/usr/local/etc/apache22 # /usr/bin/openssl req -new -key /usr/local/etc/apache22/server.key -out /usr/local/etc/apache22/server.csr

あるいは、相対パスで、

guard# /usr/bin/openssl req -new -key server.key -out server.csr

Enter pass phrase for /usr/local/etc/apache22/server.key: さっきのパスフレーズね
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 ←日本なのでJP
State or Province Name (full name) [Some-State]:EHIME ←取り敢えず
Locality Name (eg, city) []:MATSUYAMA ←取り敢えず
Organization Name (eg, company) [Internet Widgits Pty Ltd]:SMB_Films ←取り敢えず
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:mail.kuji-clinic.net ←取り敢えず
Email Address []:********@smb.net ←取り敢えず連絡先

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: 
An optional company name []:
root@mail:/usr/local/etc/apache22 #

で、出来上がった server.csr を https://www.cacert.org/ へ持ってって server.cert を貰ってくる。

更新できるかどうか、試して観たらOKだった。

Apacheの開始時に毎回パスフレーズを求められるようになってしまいます

ので、これをあらかじめ解消して使うことにしています。

# cd /usr/local/etc/apache22/ssl.key/
# mv  server.key server.key.orig
# openssl rsa -in server.key.orig -out server.key
Enter pass phrase for www.smb.net.key.orig:*********
writing RSA key
# chmod 600 server.*

これで、

root@hotshot:/usr/local/etc/apache22 # apachectl restart
Performing sanity check on apache22 configuration:
Syntax OK
Stopping apache22.
Waiting for PIDS: 13299.
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.
Apache/2.2.25 mod_ssl/2.2.25 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.

Server mail.smb.net:443 (RSA)
Enter pass phrase:

OK: Pass Phrase Dialog successful.

と、パスフレーズを求められていたのが、

root@hotshot:/usr/local/etc/apache22 # apachectl restart
Performing sanity check on apache22 configuration:
Syntax OK
Stopping apache22.
Waiting for PIDS: 13673.
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.

となりますた。( ´▽`)ノ



k222 のserver.crtを更新したら、apacheが落ちた。再起動不可能になった。古いのにもどしたら、なおった

May 31 06:00:00 k222 newsyslog[75667]: logfile turned over
[Tue May 31 06:15:02 2011] [warn] RSA server certificate CommonName (CN) `kuji- clinic.net' does NOT match server name!?
[Tue May 31 06:15:02 2011] [error] Unable to configure RSA server private key
[Tue May 31 06:15:02 2011] [error] SSL Library Error: 185073780 error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch

pianoでapachectl restart したら、

[Sat Aug 21 03:58:54 2010] [warn] RSA server certificate CommonName (CN) `piano.smb.net' does NOT match server name!?
[Sat Aug 21 03:58:54 2010] [error] Unable to configure RSA server private key
[Sat Aug 21 03:58:54 2010] [error] SSL Library Error: 185073780 error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch

と言われ、Apacheが起動できなくなった。ググると「鍵と証明書のmodulusが不一致」なのだそうだ。modulusを見るには

 181  5:24    openssl rsa -noout -text -in server.key -modulus
 182  5:24    openssl x509 -noout -text -in server.crt -modulus

で、久々にキーを生成


SSL を設置するメモ

秘密鍵生成[/usr/local/etc/apache22/ssl.key/www.smb.net.key]

# cd /usr/local/etc/apache22/ssl.key/
# /usr/bin/openssl genrsa -rand /var/log/messages -des3 \
-out /usr/local/etc/apache22/ssl.key/server.key 1024 54002 \
semi-random bytes loaded

Generating RSA private key, 1024 bit long modulus
....++++++
.............++++++
e is 65537 (0x10001)
Enter pass phrase for
/usr/local/etc/apache22/ssl.key/www.smb.net.key:*********
Verifying - Enter pass phrase for
/usr/local/etc/apache22/ssl.key/www.smb.net.key:*********

# chmod 600 server.*

CSR(証明書申請データ)生成[/usr/local/etc/apache22/ssl.key/server.csr]

# /usr/bin/openssl req -new -key \
/usr/local/etc/apache22/server.key \
-out /usr/local/etc/apache22/ssl.key/server.csr

Enter pass phrase for \
/usr/local/etc/apache22/ssl.key/www.smb.net.key:*********
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]:EHIME
Locality Name (eg, city) []:MATSUYAMA
Organization Name (eg, company)
[Internet Widgits Pty Ltd]:CAcert Inc.
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:ここは、ドメインやマシン名がわかる名前の方がよい piano.smb.net
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

CSRは、認証局(CA)に渡す ものなので、これを cat で表示させて、その内容を範囲コピーしておきます。

CAcert.orgのサーバー証明書に登録

http://www.cacert.org/index.php?id=0&lang=ja_JP

まずはhttp://www.cacert.org/へアクセス。右のメニューのTransrations で日本語を :)

ドメインの指定は、上記のCSRを作成する時に指定した

Common Name (eg, YOUR name)

の部分に相当しますので、自動で登録されることになります。

サーバ証明書の新規作成をクリックします。

下にCSRをペーストしてください。

と書かれている部分に、CSRの内容をそのままコピーします。

私は、CAcertの保証制度には協力していないので、詳細な情報は出ませんが、そもそもそんな情報を欲するようなユーザが利用する用途では用いていないので無視して大丈夫。

送信を選択すると、SSLにするFQDNが表示され、その先に進めると、キーができあがってきました

左のような部分をコピーし、 /usr/local/etc/apache2/ssl.key/にserver.crt として、保存します。 (eeでもviでもいいので、これを新規で作成します)

それが完了したら、同ディレクトリにあるものを

# chmod 600 server.*

してキーの生成は完了です。

これだけですと、Apacheの開始時に毎回パスフレーズを求められるようになってしまいますので、これをあらかじめ解消して使うことにしています。

# cd /usr/local/etc/apache22/ssl.key/
# mv  server.key server.key.orig
# openssl rsa -in server.key.orig -out server.key
Enter pass phrase for www.smb.net.key.orig:*********
writing RSA key
# chmod 600 server.*

これで必要な鍵はそろいました。

[ ssl.confの設定 ]

設定ファイルの待避

# cd /usr/local/etc/apache22/extra
# cp httpd-ssl.conf httpd-ssl.conf-dist

/usr/local/etc/apache22/extra/httpd-ssl.conf の最低限?の設定

Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:/var/run/ssl_scache(512000)"
SSLSessionCacheTimeout  300
SSLMutex  "file:/var/run/ssl_mutex"

## SSL Virtual Host Context
<VirtualHost _default_:443>
#   General setup for the virtual host
DocumentRoot "/usr/local/www/apache22/data"
ServerName www.smb.net:443
ServerAdmin webmaster@smb.net
ErrorLog "/var/log/httpd-error.log"
TransferLog "/var/log/httpd-access.log" 

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/etc/apache22/ssl.crt/www.smb.net.server.crt
SSLCertificateKeyFile /usr/local/etc/apache22/ssl.key/www.smb.net.key

SSLCertificateKeyFile "/usr/local/etc/apache22/ssl.key/www.smb.net.key"

<FilesMatch "\.(cgi|shtml|phtml|php)$">
   SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/usr/local/www/apache22/cgi-bin">
   SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
CustomLog "/var/log/httpd-ssl_request.log" \
         "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>                                  

のように指定します。

 /etc/rc.confには

apache22_enable="YES"
apache22ssl_enable="YES"

を入れておきましょう。

ページを参照して、確認すると128bitのSSLで接続されていることが確認できたと思います。

Tips

CSRのCNとアクセス先のFQDNを合わせ

ておかないと、「証明書のエラー アドレスが一致しません」と言われます

ちなみに証明書と鍵の確認方法、証明書の内容を見る方法は

openssl x509 -noout -text -in filename.crt

秘密鍵の内容を見る方法は

openssl rsa -noout -text -in filename.key

http://freebsd.fkimura.com/cacert-a0.html


Counter: 2894, today: 1, yesterday: 1

2015-05-22 (金) 08:16:24


Total access 2894:本日 1:昨日 1

Counter: 2894, today: 1, yesterday: 1

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-05-22 (金) 08:16:24