茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1675409 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_0070.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2013/1/6 14:43:08




前言



  • LDAPv3 用戶端認證機制 (Authentication)

    • Anonymous:使用空的 DN 及密碼 (換句話說就是什都不用輸入)

    • Simple:需輸入帳號及密碼,並以 明文 方式傳輸

    • SSL/TLS:需輸入帳號及密碼,並以 加密 方式 (需安裝
      [OpenSSL]) 傳輸
      [RFC2830]

    • SASL:用戶端與伺服器在進行任何憑證 傳輸前先協商 所使用的認證機制 (Cyrus-Sasl)
      [RFC2222]




另外有個很重要的觀念在
[OpenLDAP Faq-O-Matic: How do I use TLS/SSL?] 內有提到,LDAP 服務走 StartTLS 就用 ldap:// 來連接 (Port 389),若是 SSL 才是 ldaps:// 來連接 (Port 636)



  1. ldap:// + StartTLS should be directed to a normal LDAP port (normally 389), not the ldaps:// port.

  2. ldaps:// should be directed to an LDAPS port (normally 636), not the LDAP port.


實作環境



  • FreeBSD 6.1-STABLE

  • openldap-server-2.3.24

  • openldap-sasl-client-2.3.24

  • OpenSSL 0.9.7e-p1 25 Oct 2004


安裝及設定


步驟1.製作 RootCA 的 Private Key (rootca.key)



[SSL] 採用的是
[X.509] 由上而下金字塔式的憑證制度 (Root CA >> CA >> Certificate)


 #cd /usr/local/etc/openldap/ssl                               //切換路徑
#openssl genrsa -des3 -out rootca.key 2048 //產生最上層的 Private Key (rootca.key)
Generating RSA private key, 2048 bit long modulus
......................................................................+++
..........+++
e is 65537 (0x10001)
Enter pass phrase for rootca.key: //輸入密碼 (Rootca 的 Private key 密碼)
Verifying - Enter pass phrase for rootca.key: //再輸入一次密碼 (Private key 的密碼)

步驟2.填寫 RootCA 憑證申請書 (rootca.csr)


 #openssl req -new -key rootca.key -out rootca.req                                     //產生 rootca.csr(憑證申請書)
Enter pass phrase for rootca.key: //輸入密碼 (Rootca 的 Private 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]:TW //國碼臺灣是 TW
State or Province Name (full name) [Some-State]:Taiwan R.O.C //國名臺灣填 Taiwan
Locality Name (eg, city) []:Taipei //地名
Organization Name (eg, company) [Internet Widgits Pty Ltd]:FreeBSD Personal Reserach //組織單位名稱
Organizational Unit Name (eg, section) []:FreeBSD Personal Reserach //部門名稱
Common Name (eg, YOUR name) []:Weithenn-Wang //憑證的名稱
Email Address []:weithenn@weithenn.org //申請單位的連絡信箱
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:按Enter直接跳過 //申請書的密碼
An optional company name []:按Enter直接跳過 //憑證代辦公司的名稱

步驟3.簽發憑證 rootca.crt (因為自已是 RootCA 所以自己簽給自己)


最高層認證中心最好永遠不要過期。要是過期重簽,所有原來它簽發的憑證也都要重簽,所有
[SSL] 程式也都要重新設定。所以此次我們設定效期為 7305 天 (20年)。若不設效期的話,預設是 30 天(一個月)


 #openssl x509 -req -days 7305 -sha1 -extfile /etc/ssl/openssl.cnf -extensions v3_ca -signkey rootca.key -in rootca.req -out rootca.crt
Signature ok
subject=/C=TW/ST=Taiwan R.O.C/L=Taipei/O=FreeBSD Personal Reserach/OU=FreeBSD Personal Reserach
/CN=Weithenn-Wang/emailAddress=weithenn@weithenn.org
Getting Private key
Enter pass phrase for rootca.key: //輸入密碼(Rootca 的Private key密碼)

步驟4.製作 LDAP 伺服器用的 Private Key (ldap.weithenn.org.key)


請注意 LDAP 伺服器的 Private Key 建議不要設密碼,否則
[SSL] 伺服器程式啟動時,讀取憑證和 Private Key 時就要詢問一次密碼。


 #openssl genrsa -out ldap.weithenn.org.key 2048    //產生伺服器用的 Private  key (ldap.weithenn.org.key)
Generating RSA private key, 2048 bit long modulus
......................................................+++
......+++
e is 65537 (0x10001)

步驟5.LDAP 伺服器憑證申請書 (ldap.weithenn.org.csr)


 #openssl req -new -key ldap.weithenn.org.key -out ldap.weithenn.org.csr                 //產生伺服器憑證申請書 (ldap.weithenn.org.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]: TW //國碼臺灣是 TW
State or Province Name (full name) [Some-State]: Taiwan R.O.C //國名臺灣填 Taiwan
Locality Name (eg, city) []: Taipei //地名
Organization Name (eg, company) [Internet Widgits Pty Ltd]: FreeBSD Personal Reserach //組織單位名稱
Organizational Unit Name (eg, section) []: FreeBSD Personal Reserach //部門名稱
Common Name (eg, YOUR name) []: ldap.weithenn.org //憑證的名稱 (伺服器的 FQDN,很重要後面會用到)
Email Address []: weithenn@weithenn.org //申請單位的連絡信箱
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: 請按 Enter 直接跳過 //申請書的密碼
An optional company name []: 請按 Enter 直接跳過 //憑證代辦公司的名稱

步驟6.最高層認證中心簽發憑證 (RootCA 發給 LDAP 伺服器)


以最高層認證中心發給伺服器 (RootCA >> LDAP Server) 十年的憑證。


 #openssl x509 -req -days 3650 -sha1 -extfile /etc/ssl/openssl.cnf -extensions v3_req -CA rootca.crt -CAkey rootca.key \
-CAserial rootca.srl -CAcreateserial -in ldap.weithenn.org.csr -out ldap.weithenn.org.crt //接續上一行
Signature ok
subject=/C=TW/ST=Taiwan R.O.C/L=Taipei/O=FreeBSD Personal Research/OU=FreeBSD Personal Research
/CN=www.weithenn.org/emailAddress=weithenn@weithenn.org
Getting CA Private Key
Enter pass phrase for rootca.key: //輸入密碼 (Rootca 的 Private key 密碼)

以上步驟完成後整理一下剛才產生的檔案


 /usr/local/etc/openldap/ssl/rootca.key                //RootCA Private Key (記得權限設為 400)
/usr/local/etc/openldap/ssl/rootca.csr //RootCA 憑證申請書
/usr/local/etc/openldap/ssl/rootca.crt //RootCA 憑證
/usr/local/etc/openldap/ssl/ldap.weithenn.org.key //LDAP ServerPrivate Key (記得權限設為 400)
/usr/local/etc/openldap/ssl/ldap.weithenn.org.csr //LDAP Server 憑證申請書
/usr/local/etc/openldap/ssl/ldap.weithenn.org.crt //LDAP Server 憑證

步驟7.修改 LDAP 設定檔 (slapd.conf)


修改 LDAP 設定檔 (slapd.conf) 加入以下 TLS 相關設定


 TLSCipherSuite          HIGH:MEDIUM:+SSLv2:+SSLv3:TLSv1
TLSCACertificateFile /usr/local/etc/openldap/ssl/rootca.crt //Root CA certs
TLSCertificateFile /usr/local/etc/openldap/ssl/ldap.weithenn.org.crt //LDAP Server certs
TLSCertificateKeyFile /usr/local/etc/openldap/ssl/ldap.weithenn.org.key //LDAP Server Private Key
TLSVerifyClient try

步驟8.修改 PAM 設定檔 (ldap.conf)


修改 PAM 設定檔 (ldap.conf) 加入以下 TLS Client相關設定


 #vi /usr/local/etc/openldap/ldap.conf
HOST 127.0.0.1
URI ldap://ldap.weithenn.org //請注意此欄位為填入產生伺服器憑時的 CN
BASE dc=weithenn, dc=org
TLS_CACERT /usr/local/etc/openldap/ssl/rootca.crt
TLS_REQCERT demand

步驟9.修改 rc.conf


修改 /etc/rc.conf 加入以下 TLS 相關設定


 slapd_flags='-h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap://0.0.0.0/"'                  //若是 SSL start_tls 則不用改
slapd_flags='-h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap://0.0.0.0/ ldaps://0.0.0.0/"' //若是 SSL On 則改成此行

步驟10.修改 PAM 設定檔 (ldap.conf)


修改 PAM 設定檔 (ldap.conf、也就是 pam_ldap、nss_ldap) 加入以下 TLS 相關設定


 #vi /usr/local/etc/ldap.conf
uri ldap://ldap.weithenn.org //若是使用 SSL On 請改成 ldaps://
ssl start_tls //StartTLS (注意 start_tls 是走 Port 389,若為 On 才是走 Port 636)
tls_checkpeer yes //是否要求驗證 LDAP Server 憑證
tls_cacertfile /usr/local/etc/openldap/ssl/rootca.crt //指定 RootCA 憑證
tls_cacertdir /usr/local/etc/openldap/ssl //指定 RootCA 目錄

步驟11.重新啟動 slapd 服務


鍵入以下指令來重新啟動 LDAP 服務


 #/usr/local/etc/rc.d/slapd restart                        //重新啟動 slapd 服務

查看 SSL/TLS Port是否開啟


 #sockstat |grep ldap
ldap slapd 81896 3 dgram -> /var/run/logpriv
ldap slapd 81896 6 stream /var/run/openldap/ldapi
ldap slapd 81896 7 tcp4 *:389 *:*
ldap slapd 81896 8 tcp4 *:636 *:* //若使用 SSL On 則應該開啟此 Port

查看 /var/log/ldap.log 可看到 TLS 已經作用了


 Jul 25 17:30:00 ldap slapd[81896]: conn=9 fd=12 ACCEPT from IP=127.0.0.1:58956 (IP=0.0.0.0:636)    //SSL ON
Jul 25 17:30:00 ldap slapd[81896]: conn=9 fd=12 TLS established tls_ssf=256 ssf=256
Jul 25 17:30:00 ldap slapd[81896]: conn=9 fd=12 closed (connection lost)

步驟12.測試 SSL Connection


 #openssl s_client -connect localhost:636 -showcerts -state -CAfile /usr/local/etc/openldap/ssl/rootca.crt   //指令執行後可看到如下訊息
SSL_connect:SSLv3 read server certificate A
SSL_connect:SSLv3 read server certificate request A
SSL_connect:SSLv3 read server done A
SSL_connect:SSLv3 write client certificate A
SSL_connect:SSLv3 write client key exchange A
SSL_connect:SSLv3 write change cipher spec A
SSL_connect:SSLv3 write finished A
SSL_connect:SSLv3 flush data
SSL_connect:SSLv3 read finished A

參考



[ OpenLDAP Server With Server-Side SSL/TLS and Client Authentication]



[ OpenLDAP Software 2.3 Administrator's Guide: Using TLS]



[OpenLDAP Server With Server-Side SSL/TLS and Client Authentication]



[OpenLDAP Faq-O-Matic: How do I use TLS/SSL?]



[旅舍依瑪-如何製作 SSL X.509 憑證?]



[小明網誌 | 為 openldap 加上 SSL 囉]



[使用 OpenLDAP 集中管理用户帐号]



[ SSL Certificates HOWTO]



[ 基於安全LDAP 伺服器之整合服務認證系統設計與實現]



[ FreeBSD下利用ACL/SSL安全使用OpenLDAP]



[針對 UNIX 的 Microsoft Windows 安全和目錄服務解決方案指南]


Me FAQ


Q1.加入 TLS 設定後 slapd 服務起不來?



Error Meaage:


當我在相關設定檔加入 TLS 選項後 slapd 服務卻起不來,查看 ldap.log 如下


 Jul 18 18:14:28 ldap slapd[52830]: @(#) $OpenLDAP: slapd 2.3.24 (Jul 13 2006 17:08:02)
Jul 18 18:14:58 ldap slapd[52830]: connections_destroy: nothing to destroy. //連接毀壞
Jul 18 18:14:58 ldap slapd[52830]: main: TLS init def ctx failed: -1 //TLS 失敗
Jul 18 18:14:58 ldap slapd[52830]: slapd stopped. //服務停止


Ans:


原因在於我產生的 LDAP 伺服器用的 Private Key (ldap.weithenn.org.key) 其檔案的擁有人 (owner) 是 root 不是 ldap 造成 slapd 服務無法讀取該檔案,因而造成啟動失敗


 #chown ldap ldap.weithenn.org.key

將檔案擁有人 (owner) 修改為 ldap 後再次重新啟動 slapd 服務可以從 ldap.log 看到正常啟動了,訊息如下


 Jul 19 09:52:40 ldap slapd[55582]: slapd starting

Q2.加入 TLS 設定後 id 及 finger 指令無法查詢 LDAP Account?



Error Meaage:


當我在相關設定檔加入 TLS 選項後,使用id 及 finger 指令都查詢不到 LDAP Account 似乎 pam_ldap/nss_ldap 沒作用一般



Ans:


此次原因就是未把 OpenLDAP Client 設定檔內 uri ldap://FQDN 填入 (我填的是機器的 IP),因此記得把 uri ldap:// 填入


 /usr/local/etc/openldap/ldap.conf
/usr/loca/etc/nss_ldap.conf


[RE: openldap tools starttls]


Q3.加入 TLS 設定後 /var/log/message 一直跳 nss_ldap 找不到 LDAP?



Error Meaage:


當我在相關設定檔加入 TLS 選項後,當 nss_ldap 定期 (大約五分鐘) 去找 LDAP 時在 /var/log/ldap.log 不會出現錯誤訊息,但 /var/log/message 卻一直出現訊息說找不到 LDAP Server


 Jul 26 02:22:00 ldap cron[83445]: nss_ldap: could not search LDAP server - Server is unavailable


Ans:


將原本 nss_ldap.conf 內的 HOST IP 改成機器的 IP 後, /var/log/message 便不會在出現這樣的訊息了


 #vi /usr/local/etc/nss_ldap.conf
HOST 127.0.0.1 //原設定值
HOST 192.168.10.9 //修改後







原文出處:不自量力 の Weithenn: OpenLDAP-SSL TLS 設定
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|