CA 証明書

Mercurial における https URL の SSL 証明書の扱いについて。

1. Mercurial 1.7.x での変更点

Mercurial は 1.7.x 系で HTTPS サポートを改善し、 HTTPS サーバー接続時にサーバー証明書を確認するようになりました。 不正な身元情報を提示したサーバーへの接続は拒否します。 Mercurial 1.7.3 以降では、認証局(CA)についての設定不備で証明書を確認できない場合は、警告を表示します。

{i} "certificate not verified" という警告は、以前より安全でなくなったという意味ではありません。 以前から安全ではなかったと通知しているだけです。

SSL に求めてた安全性を得るため(そして、警告を消すため)には、設定を直す必要があります。 そうでなければ、 HTTPS を使う意味はないでしょう。

2. HTTPS 認証局の設定

オペレーティングシステムはたいてい、信頼できるルート証明書を保持しています。 なお、その認証局はどんなサーバーの身元であっても承認しようと思えば可能であり、ひいてはどんなサーバーの身元情報であっても成りすますことができることを述べておきます。

2.1. Debian/Ubuntu

Debian と Ubuntu では、以下のグローバル設定を利用できます:

[web]
cacerts = /etc/ssl/certs/ca-certificates.crt

2.2. Fedora/RHEL

Fedora と RHEL では、以下のグローバル設定を利用できます:

[web]
cacerts = /etc/pki/tls/certs/ca-bundle.crt

2.3. Mac OS X before 10.6

You can generate the file you need by opening Keychain Access (from /Applications/Utilities), going to the System Roots keychain, selecting everything and then choosing Export Items... from the File menu. Make sure the File Format is set to Privacy Enhanced Mail (.pem), then save it to your Desktop as Certificates. Next, in Terminal enter

sudo cp ~/Desktop/Certificates.pem /etc/hg-ca-roots.pem

then configure Mercurial as follows:

[web]
cacerts = /etc/hg-ca-roots.pem

Note that because the vendor supplied set of CA root certificates on Mac OS X is in the system keychain, you may wish to repeat these steps after installing software updates if they include changes to the root certificate list.

2.4. Mac OS X 10.6 and higher

On Mac OS X 10.6 and higher, OpenSSL (which is what Python and therefore Mercurial use to implement their SSL support) will look in the system keychain. Unfortunately, the SSL code in the Python core doesn't allow for this situation---it always expects you to specify a certificate bundle, and if one is specified if must contain at least one certificate. A simple way to deal with this problem is to enter (in Terminal)

openssl req -new -x509 -extensions v3_ca -keyout /dev/null -out dummycert.pem -days 3650

to generate a dummy certificate (the contents don't matter, so you can just hit return at all of the prompts), then

sudo cp dummycert.pem /etc/hg-dummy-cert.pem

and set your configuration as follows:

[web]
cacerts = /etc/hg-dummy-cert.pem

Don't download a dummy certificate someone on the Internet has created to solve this problem unless you're certain that they're trustworthy; if they kept the private key, they would be able to sign certificates that Mercurial would trust. Better just to enter the commands above.

2.5. Windows

Mercurial 1.7.3 のインストーラー(と対応する TortoiseHg インストーラー)には cacert.pem がパッケージされており、デフォルトで web.cacertshgrc.d\paths.rc に設定します。そのため、自己署名証明書を提示したリポジトリへの接続は拒否されます。

2.6. 他のプラットフォーム

あなたのプラットフォームが適当な CA リストを提供していなければ、 cacert ファイルを http://curl.haxx.se/docs/caextract.html や他の信頼できる場所より手可能です。

2.7. 自己署名証明書

必要に応じて cacert ファイルをカスタマイズし、例えば信頼しない CA を削除したり自分のイントラまたは自己署名認証局を追加したりしてください。 cacerts ファイルを複数指定することはできないため、 web.cacerts をユーザーまたはリポジトリ設定で上書きすると良いでしょう。

3. リポジトリごとの設定

あなたが認証あるいは pull するサーバーの成りすましについて、より積極的にコントロールしたければ、ローカル clone ごとに信頼できる CA を設定することが可能です。

サーバーのルート CA 証明書は、例えば Firefox では次のように取得できます。 https://server/repo へアクセスし、あなたが信頼するリポジトリであることを確認後、右下の錠アイコンをクリックします。証明書を表示→詳細→証明書の階層の一番上を選択→エクスポート→「X.509 証明書 (PEM)」で例えば server.pem という名前で保存します。 Windows (XP) の他のブラウザでは、証明パスの最上位の証明書を表示し、「Base-64 エンコードした X.509 (.CER)」として「ファイルへコピー」する必要があります。

{i} 単一の PEM エンコードされた証明書の内容を表示するには、以下のようにしてください

ローカルリポジトリの .hg/hgrc を開いて、下記を追加してください

[web]
cacerts = /path/to/server.pem

注: Mercurial 1.7.3 以降が必要です。

4. パッケージ化

プラットフォームごとの PKI を利用するようにパッケージ化することを推奨します。 例えば、 web.cacerts が設定された hgrc.d/cacert.rc を提供してください。プラットフォームに適当な CA リストがない場合は、独自に (例えば cURL/Mozilla などの) CA リストを配布すれば良いでしょう。

事前設定された cacert リストをデフォルトで使用すると、自己署名証明書つきのサーバーへ接続していたユーザーへはリグレッションを招くことに留意してください。従って、あなたのアップデート方針に基づき、バグフィックスリリースではなく、メジャーアップデートで導入すべきでしょう。

5. HTTP プロキシーサポート

Mercurial は今のところ HTTP プロキシーの CONNECT を通した HTTPS 接続では証明書を確認していません。

6. SMTP TLS 証明書

Mercurial は今のところ SMTP の TLS 証明書は確認していません。

7. 参考


CategoryJapanese

English