Chapter 46. LDAPとトランスポート層のセキュリティ

Gavin Henry

Suretec Systems Limited, UK

July 8, 2005

Table of Contents

概要
設定
認証局の作成
サーバー証明書の生成
証明書のインストール
評価
トラブルシューティング

概要

現在に至るまで、ACLのような、いくつかの高度な機能を含む、 OpenLDAP™の簡単な設定について議論してきた。 しかし、ネットワーク上の通信が引き続き平文であるという現状には対応しない。 これが、Transport Layer Security (TLS)が導入された 理由である。

OpenLDAP™クライアントとサーバーは、 RFC 2830(訳注:現在は RFC 4513が最新) Lightweight Directory Access Protocol (v3): Extension for Transport Layer Security. による、完全性と機密性を提供するため、Transport Layer Security (TLS)を使う 能力がある。

TLSはX.509証明書を使う。すべてのサーバーは有効な証明書を持つ必要があるが、 クライアント証明書はあってもなくてもよい。ここではサーバー証明書のみを 議論の対象とする。

Tip

サーバー証明書のDNはサーバーの名前を指定するCN属性を使う必要があり、CNは、サーバーの、 完全に記述されたドメイン名(FQDN)を引き継ぐ必要がある。追加の別名と ワイルドカードは、subjectAltName証明書エクステンションに存在しても よい。サーバー証明書の名前についてのより詳細については、 RFC2830にある。

これについては次の節で詳細に説明する。

設定

これから重要なところを説明する。

認証局の作成

適切な証明書を作成するために、固有の認証局(CA)を立てる必要がある。 [8] これは必要であり、そうすると、サーバー証明書に署名できる。

これに対しては、ほとんどのLinux® ディストリビューションに含まれているOpenSSL [9] を使うことになる。

TLSは多くの種類のサーバーによって使われるが、その手続きは、 [10] ここで説明されていて、OpenLDAP に特化している。

Note

以下の例におけるCommon Name (CN)は、使用しているLDAPサーバーの 完全に記述されたドメイン名(FQDN)でなければならない

最初に認証局(CA)を生成する必要がある:


root#  mkdir myCA

そのディレクトリに移動する:


root#  cd myCA

Now generate the CA:[11]


root#  /usr/share/ssl/misc/CA.pl -newca
CA certificate filename (or enter to create)
  
Making CA certificate ...
Generating a 1024 bit RSA private key
.......................++++++
.............................++++++
writing new private key to './demoCA/private/cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
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]:AU
State or Province Name (full name) [Some-State]:NSW
Locality Name (eg, city) []:Sydney
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Abmas
Organizational Unit Name (eg, section) []:IT
Common Name (eg, YOUR name) []:ldap.abmas.biz
Email Address []:support@abmas.biz

注意すべき点がいくつかある。

  1. サーバーの証明書に署名するのに必要なので、 パスワードを覚えておく必要がある

  2. Common Name (CN)は使用しているLDAPサーバーの 完全に記述されたドメイン名(FQDN)でなければならない

サーバー証明書の生成

次にサーバー証明書を生成する必要がある:


root#  openssl req -new -nodes -keyout newreq.pem -out newreq.pem
Generating a 1024 bit RSA private key
.............++++++
........................................................++++++
writing new private key to 'newreq.pem'
-----
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]:AU
State or Province Name (full name) [Some-State]:NSW
Locality Name (eg, city) []:Sydney
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Abmas
Organizational Unit Name (eg, section) []:IT
Common Name (eg, YOUR name) []:ldap.abmas.biz
Email Address []:support@abmas.biz
  
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

繰り返すが、ここでもいくつか注意すべき事がある。

  1. パスワードを入力すべきではない

  2. Common Name (CN)は使用しているLDAPサーバーの 完全に記述されたドメイン名(FQDN)でなければならない

次に新しい認証局(CA)の証明書に署名する:


root#  /usr/share/ssl/misc/CA.pl -sign
Using configuration from /etc/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
	Not Before: Mar  6 18:22:26 2005 EDT
	Not After : Mar  6 18:22:26 2006 EDT
Subject:
	countryName               = AU
	stateOrProvinceName       = NSW
	localityName              = Sydney
	organizationName          = Abmas
	organizationalUnitName    = IT
	commonName                = ldap.abmas.biz
	emailAddress              = support@abmas.biz
X509v3 extensions:
	X509v3 Basic Constraints:
	    CA:FALSE
	Netscape Comment:
	    OpenSSL Generated Certificate
	X509v3 Subject Key Identifier:
	    F7:84:87:25:C4:E8:46:6D:0F:47:27:91:F0:16:E0:86:6A:EE:A3:CE
	X509v3 Authority Key Identifier:
	    keyid:27:44:63:3A:CB:09:DC:B1:FF:32:CC:93:23:A4:F1:B4:D5:F0:7E:CC
	    DirName:/C=AU/ST=NSW/L=Sydney/O=Abmas/OU=IT/
						CN=ldap.abmas.biz/emailAddress=support@abmas.biz
	    serial:00

Certificate is to be certified until Mar  6 18:22:26 2006 EDT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
Signed certificate is in newcert.pem

これでサーバー証明書の生成が完了する。

証明書のインストール

次に、正しい設定ディレクトリ中に証明書をコピーする必要があり、その後同時に改名して (利便性のために)、所有権を変更し、最後にアクセス許可を与える:


root#  cp demoCA/cacert.pem /etc/openldap/
root#  cp newcert.pem /etc/openldap/servercrt.pem
root#  cp newreq.pem /etc/openldap/serverkey.pem
root#  chown ldap.ldap /etc/openldap/*.pem
root#  chmod 640 /etc/openldap/cacert.pem;
root#  chmod 600 /etc/openldap/serverkey.pem

次に、これらのファイル位置情報を、以下のようにして、slapd.conf の、database定義の前のどこかに追加する必要がある:


TLSCertificateFile /etc/openldap/servercrt.pem
TLSCertificateKeyFile /etc/openldap/serverkey.pem
TLSCACertificateFile /etc/openldap/cacert.pem

以下は、ldap.confでの定義である: ldap.conf


TLS_CACERT /etc/openldap/cacert.pem

これですべてである。次にthe section called “評価”を行う。

評価

ここは簡単な部分である。サーバーを再起動する:


root#  /etc/init.d/ldap restart
Stopping slapd:                                            [  OK  ]
Checking configuration files for slapd: config file testing succeeded
Starting slapd:                                            [  OK  ]

次に、ldapsearchを使い、-ZZオプションを使って [12] 匿名検索で評価する:


root#  ldapsearch -x -b "dc=ldap,dc=abmas,dc=biz" \
        -H 'ldap://ldap.abmas.biz:389' -ZZ

以下のように、サーバーを再起動する前と結果は同じであるべきである:


root#  ldapsearch -x -b "dc=ldap,dc=abmas,dc=biz" \
    -H 'ldap://ldap.abmas.biz:389' -ZZ

# extended LDIF
#
# LDAPv3
# base <> with scope sub
# filter: (objectclass=*)
# requesting: ALL
#

# abmas.biz
dn: dc=ldap,dc=abmas,dc=biz
objectClass: dcObject
objectClass: organization
o: Abmas
dc: abmas

# Manager, ldap.abmas.biz
dn: cn=Manager,dc=ldap,dc=abmas,dc=biz
objectClass: organizationalRole
cn: Manager

# ABMAS, abmas.biz
dn: sambaDomainName=ABMAS,dc=ldap,dc=abmas,dc=biz
sambaDomainName: ABMAS
sambaSID: S-1-5-21-238355452-1056757430-1592208922
sambaAlgorithmicRidBase: 1000
objectClass: sambaDomain
sambaNextUserRid: 67109862
sambaNextGroupRid: 67109863

何か問題が起きた場合は、the section called “トラブルシューティング”を読んでみてほしい。

トラブルシューティング

TLSを設定しているときに最もよくあるエラーは、何回も説明したように、 the section called “サーバー証明書の生成”で入力したCommon Name (CN)が、 使用しているLDAPサーバーの、完全に記述されたドメイン名(FQDN)でないという ものである。

他のエラーとしては、ldapsearchコマンドのどこかでタイプミスしたとか、 servercrt.pemcacert.pemに間違ったアクセス 許可を設定しているかである。the section called “証明書のインストール”単位に chmod 640で設定すべきである。

それ以外は、ldapのログファイルを読むか、OpenLDAPメーリングリストに参加するのが最も良い方法 である。



[8] しかし、作成したサーバー証明書は、たとえば、 ThawteVeriSignのような、有料または CAcert経由の、無料のものを使って、 適切なCAによって署名されるようにできる。

[9] 固有の認証局(CA)を作ることの不都合な点は、商用のものがそうであるように、 証明書がクライアントによって自動的に認識されないということである。

[10] 一番確かなところからの情報は、 http://www.openssl.org/docs/HOWTO/ のmain OpenSSLサイトを参照のこと。

[11] Your CA.pl or CA.sh might not be in the same location as mine is, you can find it by using the locate command, i.e., locate CA.pl. If the command complains about the database being too old, run updatedb as root to update it.

[12] man ldapsearchを参照