原文发表于cu:2016-07-04html
参考文档:算法
Server:基于CentOS-7-x86_64-1511 数据库
Server IP: 172.18.12.203 vim
OpenLDAP:openldap-2.4.44已安装安全
#理论上只须要openssl与openssl-devel yum 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解决。 tcp
可使用"/usr/local/openldap-2.4.44/libexec/slapd"命令查看执行命令是否关联相应libraries,上面就是经过此方法定位故障点的:http://comments.gmane.org/gmane.network.openldap.technical/874 ide
OpenLDAP with TLS/SSL默认使用tcp 636端口,提早在iptables放行。ui
在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/
#带上”-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
#利用req命令与CA根证书生成自签署的根证书,证书有效期1年; #生成证书时,上方红色粗体字部分是要求输入的信息,其中须要注意的是”Common Name”请填写服务器域或IP [root@localhost certs]# openssl req -new -x509 -days 365 -key cakey.pem -out ca.crt 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) []:Sichuan Locality Name (eg, city) [Default City]:Chengdu Organization Name (eg, company) [Default Company Ltd]:SYS Organizational Unit Name (eg, section) []:IT Common Name (eg, your name or your server's hostname) []:172.18.12.203 Email Address []:xxx@sys.com #能够查看生成的根证书 [root@localhost certs]# openssl x509 -noout -text -in ca.crt
#同上,可带"-des3"参数,同步骤(1) [root@localhost certs]# openssl genrsa -out ldapkey.pem 2048
#请求文件须要发给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
#若是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.cnf 42 dir = /usr/local/openldap-2.4.44/certs
#须要将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
#主要涉及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/
#能够在文件最后添加步骤(7)中证书/密钥的工做路径 [root@localhost certs]# cd /usr/local/openldap-2.4.44/etc/openldap/ [root@localhost openldap]# vim slapd.conf TLSCACertificateFile /usr/local/openldap-2.4.44/etc/openldap/cacerts/ca.crt TLSCertificateFile /usr/local/openldap-2.4.44/etc/openldap/ldapserver.crt TLSCertificateKeyFile /usr/local/openldap-2.4.44/etc/openldap/ldapkey.pem
#”-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
[root@localhost ~]# netstat –tunlp
1) 修改已经过389端口可访问数据库的属性:数据库名,右键-->Properties;加密
2) 修改389端口为636端口;