OpenLDAP集成TLS/SSL

目錄
*******************************************
方案一:自簽名證書

1.Server製作自簽名證書

2.修改目錄權限及所有者

3.修改配置文件,添加證書路徑

4.重新生成配置文件 並啓動服務

5.客戶端配置及測試

方案二:CA中心簽名

CA中心簡介

1、建立Ca中心

2、客戶機公鑰簽名

創建證書的另一種方法

3、將簽名證書和CA證書導入ldap server

4、客戶端配置(將ca證書導入)及測試

*******************************************

 

方案一:自簽名證書

    Openldap默認使用簡單驗證,對slapd的所有訪問都使用明文密碼通過未加密通道進行。爲了確保信息安全,需要對信息進行加密傳輸,SSL(Secure Sockets Layer)是一個可靠的解決方案。

它使用 X.509 證書,由可信任第三方(Certificate Authority (CA))進行數字簽名的一個標準格式的數據。有效的數字簽名意味着已簽名的數據沒有被篡改。如果簽名的數據被更改,將不會通過驗證。

方案一採用自簽名證書,由自己簽發,便於測試時使用。

 

環境:red hat enterprise linux 6.3,已按照上一篇文章的步驟搭建好openldap server。

IP:192.168.0.254

 

1.Server製作自簽名證書

# cd /etc/openldap/certs/

# openssl genrsa -out ldap.key 1024 //私鑰

# openssl req -new -key ldap.key -out ldap.csr //生成簽名請求

openssl req 接受生成密鑰對的公共部分,添加一些位置信息,並將結果打包爲Certificate Signing Request (CSR)由CA中心簽署。

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) [XX]:

State or Province Name (full name) []:

Locality Name (eg, city) [Default City]:

Organization Name (eg, company) [Default Company Ltd]:

Organizational Unit Name (eg, section) []:

Common Name(eg, your name or your server's hostname)[]:master.example.com //主機名用FQDN格式

Email Address []:[email protected]

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

 

# openssl x509 -req -days 1095 -in ldap.csr -signkey ldap.key -out ldap.crt//公鑰(自簽名)

將生成的ldap.csr文件發送到CA進行簽名。如果發送此文件到CA進行簽名,則需要確保提供的所有信息拼寫正確。這裏不使用ca中心對csr進行簽名。

完成自簽名證書的製作,ldap.key(私鑰)、ldap.crt(證書、公鑰)。

 

2.修改目錄權限及所有者

# chmod 700 certs/

# chown ldap.ldap certs/ -R

 

3.修改配置文件,添加證書路徑

# vim /etc/openldap/ldap.conf

TLS_CACERTDIR /etc/openldap/certs //更改證書目錄

TLS_REQCERT allow //允許自簽名證書(服務器、客戶機都加入)

 

# vim /etc/openldap/slapd.conf //修改配置文件

TLSCertificateFile /etc/openldap/certs/ldap.crt

TLSCertificateKeyFile /etc/openldap/certs/ldap.key

 

4.重新生成配置文件 並啓動服務

# service slapd stop

# rm -rf /etc/openldap/slapd.d/*

# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/

# chown ldap.ldap /etc/openldap/slapd.d/ -R

 

# slapd -h "ldaps:///" //啓動服務,監聽636端口

 

5.客戶端配置及測試

先利用setup工具配置,在# vim /etc/openldap/ldap.conf添加

TLS_REQCERT allow//允許自簽名證書(服務器、客戶機都加入)

TLS_CACERTDIR /etc/openldap/cacerts

URI ldaps://192.168.0.254

BASE dc=example,dc=com

 

客戶端測試

1.# ldapwhoami -v -x -Z //匿名測試ssl鏈接

ldap_initialize( )

ldap_start_tls: Operations error (1)

additional info: TLS already started

anonymous

Result: Success (0)

 

2.ldaps驗證用戶密碼

#ldapwhoami -D "uid=ldapuser1,ou=People,dc=example,dc=com" -W -H ldaps://192.168.0.254 -v

ldap_initialize( ldaps://192.168.0.254:636/??base )

Enter LDAP Password:

dn:uid=ldapuser1,ou=People,dc=example,dc=com

Result: Success (0)

-D 指定distinguish name

-W提示輸入密碼

-H 使用ldap://或ldaps://協議

-h IP

-v詳細信息

 

3.搜索ldap服務器域信息

# ldapsearch -x -b "dc=example,dc=com" -H ldaps://192.168.0.254

 

方案二:CA中心簽名

 

CA中心簡介

CA中心 — 證書授權(Certificate Authority)中心,是電子商務交易中受信任的權威第三方,用來驗證公鑰合法性的機構。CA中心爲每個使用公鑰的客戶發放數字證書,數字證書的作用是證明證書中列出的客戶合法擁有證書中列出的公鑰。CA機構的數字簽名使得第三者不能僞造和篡改證書。它負責產生、分配並管理所有參與網上信息交換各方所需的數字證書,因此是安全電子信息交換的核心。

 

CA中心,是PKI(Public Key Infrastructure)體系的核心。它爲客戶的公鑰簽發公鑰證書、發放證書和管理證書,並提供密鑰生命週期內的管理服務。它將客戶的公鑰與客戶的名稱及其他屬性關聯起來,爲客戶之間電子身份進行認證。

CA中心在密碼管理方面的作用如下:

 

1. 自身密鑰的產生、存儲、備份/恢復、歸檔和銷燬

    從根CA開始到直接給客戶發放證書的各層次CA,都有其自身的密鑰對。CA中心的密鑰對一般由硬件加密服務器在機器內直接產生,並存儲於加密硬件內,或以一定的加密形式存放於密鑰數據庫內。加密備份於IC卡或其他存儲介質中,並以高等級的物理安全措施保護起來。密鑰的銷燬要以安全的密鑰衝寫標準,徹底清除原有的密鑰痕跡。需要強調的是,根CA密鑰的安全性至關重要,它的泄露意味着整個公鑰信任體系的崩潰,所以CA的密鑰保護必須按照最高安全級的保護方式來進行設置和管理。

 

2.爲認證中心與各地註冊審覈發放機構的安全加密通信提供安全密鑰管理服務

    在客戶證書的生成與發放過程中,除了有CA中心外,還有註冊機構、審覈機構和發放機構(對於有外部介質的證書)的存在。行業使用範圍內的證書,其證書的審批控制,可由獨立於CA中心的行業審覈機構來完成。CA中心在與各機構進行安全通信時,可採用多種手段。對於使用證書機制的安全通信,各機構(通信端)的密鑰產生、發放與管理維護,都可由CA中心來完成。

 

3.確定客戶密鑰生存週期,實施密鑰吊銷和更新管理

    每一張客戶公鑰證書都會有有效期,密鑰對生命週期的長短由簽發證書的CA中心來確定。各CA系統的證書有效期限有所不同,一般大約爲2~3年。

 

    密鑰更新有以下兩種情況:密鑰對到期、密鑰泄露後需要啓用新的密鑰對(證書吊銷)。

 

    採用證書的公鑰吊銷,是通過吊銷公鑰證書來實現的。公鑰證書的吊銷來自於兩個方向,一個是上級的主動吊銷,另一個是下級主動申請證書的吊銷。當上級CA對下級CA不能信賴時(如上級發現下級CA的私鑰有泄露的可能),它可以主動停止下級CA公鑰證書的合法使用。當客戶發現自己的私鑰泄露時,也可主動申請公鑰證書的吊銷,防止其他客戶繼續使用該公鑰來加密重要信息,而使非法客戶有盜取機密的可能。一般而言,在電子商務實際應用中,可能會較少出現私鑰泄露的情況,多數情況是由於某個客戶由於組織變動而調離該單位,需要提前吊銷代表企業身份的該客戶的證書。

 

4.提供密鑰生成和分發服務

    CA中心可爲客戶提供密鑰對的生成服務,它採用集中或分佈式的方式進行。在集中的情形下,CA中心可使用硬件加密服務器,爲多個客戶申請成批的生成密鑰對,然後採用安全的信道分發給客戶。也可由多個註冊機構(RA)分佈生成客戶密鑰對並分發給客戶。

 

5.提供密鑰託管和密鑰恢復服務

    CA中心可根據客戶的要求提供密鑰託管服務,備份和管理客戶的加密密鑰對。當客戶需要時可以從密鑰庫中提出客戶的加密密鑰對,爲客戶恢復其加密密鑰對,以解開先前加密的信息。這種情形下,CA中心的密鑰管理器,採用對稱加密方式對各個客戶私鑰進行加密,密鑰加密密鑰在加密後即銷燬,保證了私鑰存儲的安全性。密鑰恢復時,採用相應的密鑰恢復模塊進行解密,以保證客戶的私鑰在恢復時沒有任何風險和不安全因素。同時,CA中心也應有一套備份庫,避免密鑰數據庫的意外毀壞而無法恢復客戶私鑰。

 

6.其他密鑰生成和管理、密碼運算功能

    CA中心在自身密鑰和客戶密鑰管理方面的特殊地位和作用,決定了它具有主密鑰、多級密鑰加密密鑰等多種密鑰的生成和管理功能。

 

    對於爲客戶提供公鑰信任、管理和維護整個電子商務密碼體系的CA中心來講,其密鑰管理工作是一項十分複雜的任務,它涉及到CA中心自身的各個安全區域和部件、註冊審覈機構以及客戶端的安全和密碼管理策略。

 

一、建立CA中心

1. # vim /etc/pki/tls/openssl.cnf 配置ca密鑰簽發信息

[ CA_default ]

dir = /etc/pki/CA #默認路徑

certs = $dir/certs #頒發證書的備份,存放簽名公鑰

crl_dir = $dir/crl #證書吊銷列表

database = $dir/index.txt #證書頒發的信息,吊銷信息等

new_certs_dir = $dir/newcerts # 簽發證書副本,吊銷時用的(吊銷憑證)

 

certificate = $dir/my-ca.crt # The CA certificate CA中心公鑰

serial = $dir/serial #序列號,每做一次簽名,增加一

crlnumber = $dir/crlnumber #吊銷序列號,每吊銷一次,增加一

 

crl = $dir/my-crl.crl #吊銷列表,客戶端需要下載,添加黑名單

private_key = $dir/private/my-ca.key # CA中心的私鑰

default_days = 365 證書有效期(默認一年)

default_crl_days = 30 吊銷列表更新週期

 

[ policy_match ] 策略匹配

countryName = match 必須匹配(城市名)

stateOrProvinceName = match (國家或州名)

organizationName = match (組織名)

organizationalUnitName = optional可選的匹配(單位名)

commonName = supplied用戶提供的,必須不一樣 (常用名)

emailAddress = optional 郵件地址,可以不填

[ req_distinguished_name ]

countryName_default = CN 設置國家

stateOrProvinceName_default = BeiJing 

localityNmae_default = BeiJing 城市

0.organizationName_default = Example, Inc. 組織

 

# cd /etc/pki/tls/

# mkdir {certs,netcerts,crl}

# touch index.txt

# echo "00" > serial

 

2. 創建CA私鑰

# (umask 077 ; openssl genrsa -out /etc/pki/CA/private/my-ca.key -des3 1024)

# (umask 077 ; openssl genrsa -des3 1024 > /etc/pki/CA/private/my-ca.key )

pass phrase: //設置私鑰密碼

 

3. 生成公鑰(CA證書).crt

# openssl req -new -x509 -key /etc/pki/CA/private/my-ca.key > /etc/pki/CA/my-ca.crt

按照x509格式簽發公鑰(證書)

Enter pass phrase for /etc/pki/CA/private/my-ca.key: redhat

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) [CN]: 

State or Province Name (full name) [BeiJing]:

Locality Name (eg, city) [BeiJing]:

Organization Name (eg, company) [Example, Inc.]:

Organizational Unit Name (eg, section) []:IT

Common Name (eg, your name or your server's hostname) []:master.example.com

Email Address []:[email protected]

 

4. 安裝ftp 分發CA證書my-ca.crt

# yum install vsftpd

# cp /etc/pki/CA/my-ca.crt /var/ftp/my-ca.crt

# service vsftpd restart;chkconfig vsftpd on

 

CA中心配置結束

 

二、客戶機公鑰簽名

客戶機生成請求,csr -> CA簽發 -> crt -> 拷回客戶機已簽名的證書

 

1. 客戶機生成私鑰

# openssl genrsa -des3 1024 > /etc/openldap/certs/ldap.key

2. 生成簽名請求

# openssl req -new -key /etc/openldap/certs/ldap.key -out /etc/openldap/certs/ldap.csr

Enter pass phrase for /opt/httpd.key:redhat

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) [XX]:CN

State or Province Name (full name) []:BeiJing

Locality Name (eg, city) [Default City]:BeiJing

Organization Name (eg, company) [Default Company Ltd]:Example, Inc.

--------以上信息要和CA中心一樣---------

Organizational Unit Name (eg, section) []:IT

Common Name (eg, your name or your server's hostname) []:desktop9.example.com//本機FQDN域名

Email Address []:[email protected]

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []: //csr密碼

An optional company name []: //可選的公司名稱

 

3. 發給CA 簽發 (用ca的私鑰 .key 去簽發csr -> crt證書)

# scp ldap.csr 192.168.0.254:/root/

 

CA端 簽發證書:

# openssl ca -in /root/ldap.csr -out /root/ldap.crt

此時會彈出錯誤,需要根據錯誤信息建立一系列文件。

mkdir /etc/pki/CA/newcerts

touch /etc/pki/CA/index.txt

echo "00" > /etc/pki/CA/serial

 

報錯:

# openssl ca -in /root/ldap.csr -out /root/ldap.crt

Using configuration from /etc/pki/tls/openssl.cnf

Enter pass phrase for /etc/pki/CA/private/my-ca.key:

Check that the request matches the signature

Signature ok

The stateOrProvinceName field needed to be the same in the

CA certificate (BeiJing) and the request (BeiJing) //需要相同的字段

因爲Rhel 5默認用MD5 1024位加密,Rhel 6用SHA-512 2048位加密。

(可在/etc/pki/tls/openssl.cnf修改)

 

# openssl ca -in /root/ldap.csr -out /root/ldap.crt

Using configuration from /etc/pki/tls/openssl.cnf

Enter pass phrase for /etc/pki/CA/private/my-ca.key:

Check that the request matches the signature

Signature ok

Certificate Details:

Serial Number: 0 (0x0)

Validity

Not Before: Dec 17 12:14:57 2012 GMT

Not After : Dec 17 12:14:57 2013 GMT

Subject:

countryName = CN

stateOrProvinceName = BeiJing

organizationName = Example, Inc.

organizationalUnitName = IT

commonName = master.example.com

emailAddress = [email protected]

X509v3 extensions:

X509v3 Basic Constraints:

CA:FALSE

Netscape Comment:

OpenSSL Generated Certificate

X509v3 Subject Key Identifier:

5F:7F:55:F9:05:1B:F6:DB:A5:9D:36:EA:4B:0B:66:01:65:51:6F:13

X509v3 Authority Key Identifier:

keyid:80:38:73:E2:17:21:54:2B:B1:5D:A4:97:0A:E9:19:EF:3C:40:60:17

 

Certificate is to be certified until Dec 17 12:14:57 2013 GMT (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

 

成功~!把簽名證書和CA證書導入客戶機。

 

OpenSSL相關命令:

創建CA中心:( umask 77; openssl genrsa -out private/my-ca.key -des3 2048 )

openssl req -new -x509 -key private/my-ca.key -days 365 > my-ca.crt

私鑰加密:openssl rsa -in encrypted.key -out unencrypted.key

私鑰解密:openssl rsa -in unencrypted.key -out encrypted.key

生成私鑰:( umask 77; openssl genrsa 1024 > dovecot.key )

生成CSR:(umask 77; openssl req -new -key somefile.key -out somefile.csr )

可用/etc/pki/tls/certs/Makefile創建CSR

查看CSR:openssl req -noout -in somefile.csr -text

創建CA簽名證書:openssl ca -in my.csr -out my.crt

證書吊銷:openssl ca -revoke badcert.crt

生成證書吊銷列表CRL:openssl ca -gencrl -out revoked.crl

生成DER供firefox使用:openssl crl -in revoked.crl -outform. DER -out revoked.der.crl

檢查CRL內容:openssl crl -in revoked.crl -noout -text

 

創建證書的另一種方法:

1.創建證書(certificate)

分爲3個步驟:

1. 建立CA中心

2. 簽發server的證書

3. 簽發client的證書

需要特別注意創建證書時,輸入Common Name的時候一定要輸入目標機器的fully qualified name。

 

1.1 創建CA

/etc/pki/tls/misc //創建CA腳本的目錄

/etc/pki/CA //是存放所有CA相關文件的目錄

 

完成後,會在/etc/pki/CA目錄下生成一系列文件。

/etc/pki/CA/cakey.pem //CA私鑰

/etc/pki/CA/cacert.pem //CA證書

 

tips:如果腳本檢測到/etc/pki/CA下面有文件存在,會安靜的退出,不會創建任何東西。

把/etc/pki/CA下的文件全部刪除,script就可以正常工作了。

 

# cd /etc/pki/tls/misc

# ./CA -newca

[usage: ./CA -newcert|-newreq|-newreq-nodes|-newca|-sign|-verify]

Making CA certificate ...

Generating a 2048 bit RSA private key

...................................+++

..............................+++

writing new private key to '/etc/pki/CA/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) [XX]:CN

State or Province Name (full name) []:BeiJing

Locality Name (eg, city) [Default City]:BeiJing

Organization Name (eg, company) [Default Company Ltd]:Example, Inc.

Organizational Unit Name (eg, section) []:IT

Common Name (eg, your name or your server's hostname) []:server.example.com

Email Address []:[email protected]

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []: //csr密碼

An optional company name []: //公司名

Using configuration from /etc/pki/tls/openssl.cnf

Enter pass phrase for /etc/pki/CA/private/./cakey.pem:

Check that the request matches the signature

Signature ok

Certificate Details:

Serial Number:

89:3a:ab:fa:52:5f:80:f4

Validity

Not Before: Dec 20 15:52:28 2012 GMT

Not After : Dec 20 15:52:28 2015 GMT

Subject:

countryName = CN

stateOrProvinceName = BeiJing

organizationName = Example, Inc.

organizationalUnitName = IT

commonName = server.example.com

emailAddress = [email protected]

X509v3 extensions:

X509v3 Subject Key Identifier:

D8:A2:05:AD:99:95:63:52:00:42:10:3A:37:DF:79:C0:55:6E:FA:4D

X509v3 Authority Key Identifier:

keyid:D8:A2:05:AD:99:95:63:52:00:42:10:3A:37:DF:79:C0:55:6E:FA:4D

 

X509v3 Basic Constraints:

CA:TRUE

Certificate is to be certified until Dec 20 15:52:28 2015 GMT (1095 days)

 

Write out database with 1 new entries

Data Base Updated

 

1.2 創建server證書

下面創建ldap server的證書。

分爲兩步:

第一步生成證書請求

第二步讓CA簽發證書

 

# ./CA -newreq-nodes

Generating a 2048 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) [XX]:CN

State or Province Name (full name) []:BeiJing

Locality Name (eg, city) [Default City]:BeiJing

Organization Name (eg, company) [Default Company Ltd]:Example, Inc.

Organizational Unit Name (eg, section) []:IT

Common Name (eg, your name or your server's hostname) []:ldap.example.com

Email Address []:[email protected]

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

Request (and private key) is in newreq.pem

 

# ./CA -sign

Using configuration from /etc/pki/tls/openssl.cnf

Enter pass phrase for ../../CA/private/cakey.pem: ca私鑰密碼

Check that the request matches the signature

Signature ok

Certificate Details:

.....省略部分內容......

 

Certificate is to be certified until Apr 16 22:37:14 2008 GMT (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

 

完成兩個步驟後,在當前目錄下創建了2個文件:

/etc/pki/tls/misc/newreq.pem//證書請求文件和證書私鑰

/etc/pki/tls/misc/newcert.pem//CA簽發的證書

 

然後設置合適的權限,私鑰文件要設爲只有owner能讀。否則ssl安全體系形同虛設!

# mv newcert.pem server.crt ; chmod 644 server.crt

# mv newreq.pem server.key ; chmod 600 server.key

 

最後把這兩個文件和CA的證書拷貝到Openldap Server存放證書的目錄下

# mv server.crt /etc/openldap/certs/

# mv server.key /etc/openldap/certs/

# cp ../../CA/cacert.pem /etc/openldap/certs/

 

1.3 創建client證書

創建client證書要注意:

1)輸入Common Name的時候一定要輸入client的fully qualified name!

2)證書、私鑰和ca證書要拷貝到客戶端的/etc/openldap/cacerts中。

 

三、將簽名證書和CA證書導入ldap server

1. 下載CA中心證書

# cp /etc/pki/CA/my-ca.crt /etc/openldap/certs/

# ls /etc/openldap/certs/

ldap.crt(已簽名ldap服務器公鑰)

ldap.csr(ldap服務器簽名請求)

ldap.key(ldap服務器私鑰)

my-ca.crt(CA證書)

 

# openssl rsa -in /etc/openldap/certs/ldap.key -out /etc/openldap/certs/ldap.key- //解密私鑰,使啓動時不需要輸入私鑰解密密碼。(否則查詢一次就要輸入一次私鑰密碼,這個可以在調試模式下驗證。[#slapd -d 256 -h “ldaps:///”]

# mv /etc/openldap/certs/ldap.key /etc/openldap/certs/ldap.key.encrypt

# mv /etc/openldap/certs/ldap.key- /etc/openldap/certs/ldap.key

 

2.修改權限及所有者

# chmod 700 /etc/openldap/certs/

# chmod 600 /etc/openldap/certs/ldap.key

# chown ldap.ldap certs/ -R

 

3. 修改配置文件,添加證書路徑

# cp ldap.conf ldap.conf.bak;cp slapd.conf slapd.conf.bak //備份配置文件

# vim /etc/openldap/ldap.conf

TLS_CACERTDIR /etc/openldap/certs //更改證書目錄(默認)

 

# vim /etc/openldap/slapd.conf //修改配置文件

TLSVerifyClient never//不需要認證客戶端

TLSCACertificatePath /etc/openldap/certs

TLSCACertificateFile /etc/openldap/certs/my-ca.crt

TLSCertificateFile /etc/openldap/certs/ldap.crt

TLSCertificateKeyFile /etc/openldap/certs/ldap.key

 

TLSVerifyClient [never、allow、try、demand]

設置是否驗證客戶端發起的tls連接。

never:默認選項,不驗證客戶端證書。

allow檢查客戶端證書,沒有證書或證書錯誤,都允許連接。

try檢查客戶端證書,沒有證書(允許連接),證書錯誤(終止連接)。

demand | hard | true檢查客戶端證書,沒有證書或證書錯誤都將立即終止連接。

啓用非默認TLSVerifyClient設置,爲了使用外部身份驗證機制和SASL TLS會話。

 

4. 重新生成配置文件 並啓動服務

# service slapd stop

# rm -rf /etc/openldap/slapd.d/*

# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/

# chown ldap.ldap /etc/openldap/slapd.d/ -R

# slapd -h "ldaps:///" //啓動服務,監聽636端口

 

四、客戶端配置(將CA證書導入)及測試

利用setup配置

# scp certs/my-ca.crt 192.168.0.18:/etc/openldap/cacerts/ //拷貝ca證書

 

在# vim /etc/openldap/ldap.conf添加

TLS_CACERT /etc/openldap/cacerts/my-ca.crt//ca證書

TLS_CACERTDIR /etc/openldap/cacerts

URI ldaps://master.example.com //要與證書中的域名一樣

BASE dc=example,dc=com

TLS_REQCERT demand//總要求驗證server

 

TLS_REQCERT [never、allow、try、demand | hard]

設置是否在TLS會話中檢查server證書。

Never不檢查任何證書。

Allow檢查server證書,沒有證書或證書錯誤,都允許連接。

Try檢查server證書,沒有證書(允許連接),證書錯誤(終止連接)。

demand | hard檢查server證書,沒有證書或證書錯誤都將立即終止連接。(默認)

 

客戶端測試

1.#ldapwhoami -v -x -Z//匿名測試ssl鏈接

ldap_initialize( )

ldap_start_tls: Operations error (1)

additional info: TLS already started

anonymous

Result: Success (0)

 

2.ldaps驗證用戶密碼

#ldapwhoami -D "uid=ldapuser1,ou=People,dc=example,dc=com" -W -H ldaps://master.example.com -v

ldap_initialize( ldaps://master.example.com:636/??base )

Enter LDAP Password:

dn:uid=ldapuser1,ou=People,dc=example,dc=com

Result: Success (0)

-D 指定distinguish name

-W提示輸入密碼

-H 使用ldap://或ldaps://協議

-h IP

-v詳細信息

 

3.搜索ldap服務器域信息

# ldapsearch -x -b "dc=example,dc=com" -H ldaps://master.example.com

 

4.用openssl client連接ssl服務器

連接openssl服務器可以查看證書信息,加密方式等信息。

服務器不需要驗證客戶端:

# openssl s_client -connect server.example.com:636 -showcerts -state \

-CAfile /etc/openldap/cacerts/my-ca.crt

 

服務器需要驗證客戶端:

# openssl s_client -connect master.example.com:636 -showcerts -state \

-CAfile /etc/openldap/cacerts/my-ca.crt \

-cert /etc/openldap/cacerts/client.crt \

-key /etc/openldap/cacerts/client.key

 

調試方法:

配置完成以後,總是不能查詢ldap條目。運行調試以後,在終端顯示如下信息。原來是我的ldap.key沒有解密,導致每次查詢都要輸入私鑰密碼。

# slapd -d 256 -h "ldaps:///"

conn=1000 fd=12 ACCEPT from IP=192.168.0.18:48343 (IP=0.0.0.0:636)

Please enter pin, password, or pass phrase for security token 'PEM Token #0':

TLS: could not authenticate to the security token PEM Token #0 - error -8025:A PKCS #11 module returned CKR_GENERAL_ERROR, indicating that an unrecoverable error has occurred..

TLS: error: unable to authenticate to the security device for certificate PEM Token #0:ldap.crt - 0

TLS: error: could not initialize moznss security context - error -8025:A PKCS #11 module returned CKR_GENERAL_ERROR, indicating that an unrecoverable error has occurred.

TLS: can't create ssl handle.

conn=1000 fd=12 closed (TLS negotiation failure)

私鑰有密碼~!!!需要解密,否則每次查詢都要輸入密碼。

 

conn=1001 fd=12 ACCEPT from IP=192.168.0.18:48361 (IP=0.0.0.0:636)

TLS: error: accept - force handshake failure: errno 11 - moznss error -12195

TLS: can't accept: TLS error -12195:Peer does not recognize and trust the CA that issued your certificate..

conn=1001 fd=12 closed (TLS negotiation failure)

 

 

本文出自 “大蚊子linux” 博客,請務必保留此出處http://mosquito.blog.51cto.com/2973374/1098456

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章