设为首页 加入收藏

TOP

OpenLDAP配置TLS加密传输(一)
2017-10-13 10:37:14 】 浏览:6942
Tags:OpenLDAP 配置 TLS 加密 传输

原文发表于cu2016-07-04

参考文档:

  1. 基于OpenSSL自建CA与颁发SSL证书:http://seanlook.com/2015/01/18/openssl-self-sign-ca/
  2. OpenLDAP with TLS:http://my.oschina.net/aiguozhe/blog/151554

一.环境

Server:基于CentOS-7-x86_64-1511

Server IP: 172.18.12.203

OpenLDAP:openldap-2.4.44已安装

二.准备工作

1. 依赖包

#理论上只需要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解决。

可以使用"/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.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

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.cnf
42 dir             = /usr/local/openldap-2.4.44/certs

签署证书(6)

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇linux中必会的目录 下一篇Ansible(二) - 配置及命令简介

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目