OpenLDAP配置TLS加密傳輸,openldaptls加密
原文發表於cu:2016-07-04
參考文檔:
一.環境
Server:基於CentOS-7-x86_64-1511
Server IP: 172.18.12.203
OpenLDAP:openldap-2.4.44已安裝
二.準備工作1. 依賴包
#理論上只需要openssl與openssl-develyum install *openssl* -y
openldap編譯需要開啟"--with-tls"選項,可通過"./configure --help"查看相關說明,請參考:http://www.cnblogs.com/netonline/p/7486832.html;
openssl相關依賴包一定要安裝在openldap安裝之前,在openldap安裝之後再yum安裝openssl相關依賴包,運行ldaps命令時時報" 573d212b daemon: TLS not supported (ldaps://0.0.0.0:636/)"錯(如),安裝openssl相關包之後重新編譯安裝openldap解決。
可以使用"/usr/local/openldap-2.4.44/libexec/slapd"命令查看執行命令是否關聯相應libraries,上面就是通過此方法定位故障點的:http://comments.gmane.org/gmane.network.openldap.technical/874
2. iptables
OpenLDAP with TLS/SSL預設使用tcp 636連接埠,提前在iptables允許存取。
三.配置TLS
在OpenLDAP的home目錄建立1個子目錄,後續操作均在此目錄進行[root@localhost ~]# cd /usr/local/openldap-2.4.44[root@localhost openldap-2.4.44]# mkdir -p certs[root@localhost openldap-2.4.44]# cd certs/
1. CA中心操作(如已有CA認證則跳過)產生CA根密鑰(1)
#帶上”-des3”參數時,建立的私密金鑰採取Triple DES演算法加密,命令執行後會要求輸入密碼,這樣後續在調用此密鑰時都會要求輸入密碼,如 “openssl genrsa -des3 -out ca-key.pem 2048”,這裡為了方便省略此參數[root@localhost certs]# openssl genrsa -out cakey.pem 2048#可以查看產生的rsa 私密金鑰[root@localhost certs]# openssl rsa -noout -text -in cakey.pem#option選項,基於安全性考慮,建議修改根密鑰許可權為600或400[root@localhost certs]# chmod 600 cakey.pem
產生CA根憑證(2)
#利用req命令與CA根憑證產生自簽署的根憑證,認證有效期間1年;#產生認證時,上方紅色粗體字部分是要求輸入的資訊,其中需要注意的是”Common Name”請填寫伺服器域或IP[root@localhost certs]# openssl req -new -x509 -days 365 -key cakey.pem -out ca.crtYou are about to be asked to enter information that will be incorporatedinto 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 blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [XX]:CNState or Province Name (full name) []:SichuanLocality Name (eg, city) [Default City]:ChengduOrganization Name (eg, company) [Default Company Ltd]:SYSOrganizational Unit Name (eg, section) []:ITCommon Name (eg, your name or your server's hostname) []:172.18.12.203Email Address []:xxx@sys.com#可以查看產生的根憑證[root@localhost certs]# openssl x509 -noout -text -in ca.crt
2. OpenLDAP伺服器端操作產生OpenLDAP伺服器私密金鑰(3)
#同上,可帶"-des3"參數,同步驟(1)[root@localhost certs]# openssl genrsa -out ldapkey.pem 2048
產生OpenLDAP伺服器憑證簽署請求檔案(4)
#請求檔案需要發給CA中心簽署產生認證,相當於公開金鑰;#同步驟(2)會要求輸入一些資訊,相對於步驟(2)額外的資訊可忽略[root@localhost certs]# openssl req -new -key ldapkey.pem -out ldapserver.csr#查看請求檔案[root@localhost certs]# openssl req -noout -text -in ldapserver.csr
3. CA中心簽署認證簽署認證的準備工作 (5)
#如果CA中心準備工作已經做好,此步可跳過。[root@localhost certs]# cp /etc/pki/tls/openssl.cnf ./[root@localhost certs]# mkdir -p newcerts[root@localhost certs]# touch index.txt[root@localhost certs]# echo "00" > serial#修改第42行,認證組建組態檔案的工作目錄”dir =/etc/pki/CA”修改為當前設定檔工作的目錄,如下:[root@localhost certs]# vim openssl.cnf42 dir = /usr/local/openldap-2.4.44/certs
簽署認證(6)
#需要將OpenLDAP伺服器產生的csr請求檔案發給CA中;#產生認證會有兩次確認,”y”即可;#如果重新簽署認證,需要先將index.txt的內容用index.txt.old還原[root@localhost certs]# openssl ca -days 365 -cert ca.crt -keyfile cakey.pem -in ldapserver.csr -out ldapserver.crt -config openssl.cnf
4. 複製認證/密鑰到工作目錄(7)
#主要涉及CA中心的認證,CA中心為OpenLDAP伺服器簽署的認證與私密金鑰[root@localhost certs]# mkdir -p /usr/local/openldap-2.4.44/etc/openldap/cacerts[root@localhost certs]# cp ca.crt /usr/local/openldap-2.4.44/etc/openldap/cacerts[root@localhost certs]# cp ldapserver.crt /usr/local/openldap-2.4.44/etc/openldap/[root@localhost certs]# cp ldapkey.pem /usr/local/openldap-2.4.44/etc/openldap/
5. 修改OpenLDAP主設定檔slapd.conf(8)
#可以在檔案最後添加步驟(7)中認證/密鑰的工作路徑[root@localhost certs]# cd /usr/local/openldap-2.4.44/etc/openldap/[root@localhost openldap]# vim slapd.confTLSCACertificateFile /usr/local/openldap-2.4.44/etc/openldap/cacerts/ca.crtTLSCertificateFile /usr/local/openldap-2.4.44/etc/openldap/ldapserver.crtTLSCertificateKeyFile /usr/local/openldap-2.4.44/etc/openldap/ldapkey.pem
6. 啟動LDAPS
#”-d 256”是為debug,後台運行不需要;[root@localhost ~]# /usr/local/openldap-2.4.44/libexec/slapd -h “ldaps://0.0.0.0:636/” -d 256#或者:[root@localhost ~]# /usr/local/openldap-2.4.44/libexec/slapd -h “ldaps:///” -d 256#或者同時啟動389與636連接埠:[root@localhost ~]# /usr/local/openldap-2.4.44/libexec/slapd -h “ldap:/// ldaps:///” -d 256
7. 啟動驗證
[root@localhost ~]# netstat –tunlp
8. 通過ldapdmin驗證
1) 修改已通過389連接埠可訪問資料庫的屬性:資料庫名,右鍵-->Properties;
2) 修改389連接埠為636連接埠;
3) 快顯視窗提示,選擇" View Certificate",點擊"Yes";
4) 可以查看認證相關資訊,選擇"安裝認證",一路預設"下一步";
5) 認證匯入成功;
6) 通過636連接埠已可以訪問資料庫。