你的位置:首页 > 软件开发 > 操作系统 > OpenLDAP配置TLS加密传输

OpenLDAP配置TLS加密传输

发布时间:2017-09-13 22:00:14
原文发表于cu:2016-07-04参考文档:基于OpenSSL自建CA与颁发SSL证书 OpenLDAP with TLS >Server:基于CentOS-7-x86_64-1511 Server IP: 172.18.12.203 OpenLDAP:openldap- ...

OpenLDAP配置TLS加密传输

原文发表于cu:2016-07-04

参考文档:

  1. 基于OpenSSL自建CA与颁发SSL证书
  2. OpenLDAP with TLS >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"查看相关说明,请参考

    openssl相关依赖包一定要安装在openldap安装之前,在openldap安装之后再yum安装openssl相关依赖包,运行ldaps命令时时报" 573d212b daemon: TLS not supported (ldaps://0.0.0.0:636/)"错(如下图),安装openssl相关包之后重新编译安装openldap解决。

    OpenLDAP配置TLS加密传输

    可以使用"/usr/local/openldap-2.4.44/libexec/slapd"命令查看执行命令是否关联相应libraries,上面就是通过此方法定位故障点的

    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

    OpenLDAP配置TLS加密传输

    7. 启动验证

    [root@localhost ~]# netstat –tunlp 

    OpenLDAP配置TLS加密传输

    8. 通过ldapdmin验证

    1) 修改已通过389端口可访问数据库的属性:数据库名,右键-->Properties;

    OpenLDAP配置TLS加密传输

    2) 修改389端口为636端口;

    OpenLDAP配置TLS加密传输

    3) 弹出窗口提示,选择" View Certificate",点击"Yes";

    OpenLDAP配置TLS加密传输

    4) 可以查看证书相关信息,选择"安装证书",一路默认"下一步";

    OpenLDAP配置TLS加密传输

    5) 证书导入成功;

    OpenLDAP配置TLS加密传输

    6) 通过636端口已可以访问数据库。

    OpenLDAP配置TLS加密传输

     

    海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

    原标题:OpenLDAP配置TLS加密传输

    关键词:加密

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。