http://www.openldap.org/faq/data/cache/185.html

https://www.ibm.com/developerworks/cn/linux/1312_zhangchao_opensslldap/

http://blog.sina.com.cn/s/blog_88cdde9f01019vdt.html

http://phorum.study-area.org/index.php?topic=68194.0

http://wiki.weithenn.org/cgi-bin/wiki.pl?OpenLDAP-SSL_TLS_設定

startTLS & LDAPS

Transport Layer Security (TLS) is the standard name for the Secure Socket Layer (SSL). The terms (unless qualified with specific version numbers) are generally interchangable.

StartTLS is the name of the standard LDAP operation for initiating TLS/SSL. TLS/SSL is initiated upon successful completion of this LDAP operation. No alternative port is necessary. It is sometimes referred to as the TLS upgrade operation, as it upgrades a normal LDAP connection to one protected by TLS/SSL.

ldaps:// and LDAPS refers to "LDAP over TLS/SSL" or "LDAP Secured". TLS/SSL is initated upon connection to an alternative port (normally 636). Though the LDAPS port (636) is registered for this use, the particulars of the TLS/SSL initiation mechanism are not standardized.

Once initiated, there is no difference between ldaps:// and StartTLS. They share the same configuration options (excepting ldaps:// requires configuration of a separate listener, see slapd(8)'s -h option) and result in like security services being established.

服务端

复制证书

cp /etc/pki/CA/{openldap.key,openldap.crt,ca.crt} /etc/openldap/certs/

配置slapd.conf

TLSVerifyClient never # 设置是否验证 client 的身份,其值可以是 never/allow/try/demand,
#never 不需要验证 client 端的身份,Client 端只需要有 CA 证书就可以了
#allow Server会要求 client 提供证书,如果 client 端没有提供证书,会话会正常进行
#try Client端提供了证书,但是 Server 端有可能不能校验这个证书,这个证书会被忽略,会话正常进行
#demand Server端需要认证 client 端的身份,Client 端需要有自己的证书和私钥
vim /etc/openldap/slapd.conf
添加以下项目
TLSCACertificateFile /etc/openldap/certs/ca.crt
TLSCertificateFile /etc/openldap/certs/openldap.crt
TLSCertificateKeyFile /etc/openldap/certs/openldap.key
TLSVerifyClient never #

启用LDAPS

vim /etc/sysconfig/slapd
SLAPD_URLS="ldapi:/// ldap:///" -> SLAPD_URLS="ldapi:/// ldaps:///" # 如果使用StartTLS,这个步骤不用执行

配置生效

rm -rf /etc/openldap/slapd.d/*
slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d
chown -R ldap:ldap /etc/openldap/slapd.d
systemctl restart slapd

服务端口

#StartTLS 继续使用389端口
netstat -nlp -t |grep :389
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 1981/slapd
tcp6 0 0 :::389 :::* LISTEN 1981/slapd #LDAPS 启用636端口
netstat -nlp -t |grep :636
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:636 0.0.0.0:* LISTEN 1981/slapd
tcp6 0 0 :::636 :::* LISTEN 1981/slapd

测试StartTLS

ldap服务器/etc/openldap/ldap.conf
添加以下内容
TLS_REQCERT never 执行ldapsearch -x -ZZ后,查看日志,内容有 TLS established tls_ssf=256 ssf=256, 服务端配置正常
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 fd=22 ACCEPT from IP=[::1]:39720 (IP=[::]:389)
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 op=0 EXT oid=1.3.6.1.4.1.1466.20037
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 op=0 STARTTLS
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 op=0 RESULT oid= err=0 text=
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 fd=22 TLS established tls_ssf=256 ssf=256
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 op=1 BIND dn="" method=128
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 op=1 RESULT tag=97 err=0 text=
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 op=2 SRCH base="" scope=2 deref=0 filter="(objectClass=*)"
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 op=2 SEARCH RESULT tag=101 err=32 nentries=0 text=
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 op=3 UNBIND
Sep 22 15:23:23 openldap-01 slapd[1981]: conn=1003 fd=22 closed

测试LDAPS

# openssl verify -CAfile /etc/openldap/certs/ca.crt /etc/openldap/certs/openldap.crt
/etc/openldap/certs/openldap.crt: OK # openssl s_client -connect slave.local:636 -showcerts -state -CAfile /etc/openldap/certs/ca.crt
---
Server certificate
subject=/C=CN/ST=Beijing/O=TVM/OU=Tech Dept/CN=OPENLDAP
issuer=/C=CN/ST=Beijing/L=Beijing/O=TVM/OU=Tech Dept/CN=CA
---
No client certificate CA names sent
Server Temp Key: ECDH, prime256v1, 256 bits
---
SSL handshake has read 2354 bytes and written 375 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES256-GCM-SHA384
Session-ID: 022E6922974AD42984230001FC3CD5923A44B73FFE94CE324BA12A58B120DDBF
Session-ID-ctx:
Master-Key: CCFF58FFF333BA758C31123C9DC469F4BA752B2464B6CE5C4B998012C329D319898F873617CD98F6970AEA7CE5F413D8
Key-Arg : None
Krb5 Principal: None
PSK identity: None
PSK identity hint: None
Start Time: 1474511415
Timeout : 300 (sec)
Verify return code: 0 (ok)
---

客户端

使用nslcd(Naming services LDAP client daemon)

yum -y install openldap-clients nss-pam-ldapd

配置客户端

# StartTLS
authconfig --enableldap --enableldapauth --enableldaptls --ldapserver=ldap://master.local,ldap://slave.local --ldapbasedn='dc=suntv,dc=tv' --enablemkhomedir --update # LDAPS
authconfig --enableldap --enableldapauth --enableldaptls --ldapserver=ldaps://master.local,ldaps://slave.local --ldapbasedn='dc=suntv,dc=tv' --enablemkhomedir --update
# 注意 --ldapserver=ldaps://master.local,ldaps://slave.local

下载服务器的ca证书

wget http://master.local/ca.crt -O /etc/openldap/cacerts/ca.crt
# ls -lh /etc/openldap/cacerts
total 4.0K
lrwxrwxrwx 1 root root 6 Sep 22 12:31 100934e9.0 -> ca.crt
-rw------- 1 root root 1.3K Sep 22 12:30 ca.crt

配置/etc/openldap/ldap.conf

TLS_REQCERT [never、allow、try、demand | hard] # 设置是否在TLS会话中检查server证书。
Never:不检查任何证书。
Allow:检查server证书,没有证书或证书错误,都允许连接。
Try:检查server证书,没有证书(允许连接),证书错误(终止连接)。
demand | hard:检查server证书,没有证书或证书错误都将立即终止连接。
TLS_CACERTDIR /etc/openldap/cacerts
TLS_CACERT /etc/openldap/cacerts/ca.crt
TLS_REQCERT never

配置/etc/nslcd.conf

ssl start_tls # StartTLS
或ssl on # LDAPS
tls_cacertdir /etc/openldap/cacerts
tls_cacertfile /etc/openldap/cacerts/ca.crt
tls_reqcert never

重启nslcd服务

systemctl restart nslcd
systemctl enable nslcd

配置/etc/nsswitch.conf

变更为
passwd: files ldap
shadow: files ldap
group: files ldap

测试

# ldapwhoami -v -x -Z
ldap_initialize( <DEFAULT> )
ldap_start_tls: Operations error (1)
additional info: TLS already started
anonymous
Result: Success (0)
# ldapsearch -x -Z -H ldaps://slave.local -b 'ou=group,dc=suntv,dc=tv'
ldap_start_tls: Operations error (1)
additional info: TLS already started
# extended LDIF
#
# LDAPv3
# base <ou=group,dc=suntv,dc=tv> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
# # Group, suntv.tv
dn: ou=Group,dc=suntv,dc=tv
ou: Group
objectClass: top
objectClass: organizationalUnit # g01, Group, suntv.tv
dn: cn=g01,ou=Group,dc=suntv,dc=tv
objectClass: posixGroup
objectClass: top
cn: g01
gidNumber: 2001 # g02, Group, suntv.tv
dn: cn=g02,ou=Group,dc=suntv,dc=tv
objectClass: posixGroup
objectClass: top
cn: g02
gidNumber: 2002 # search result
search: 3
result: 0 Success # numResponses: 4
# numEntries: 3

帐号登录测试

ssh u01@10.0.1.53

passwd

openldap加密传输 nslcd的更多相关文章

  1. openldap加密传输sssd

    http://blog.father.gedow.net/2015/09/29/sssd-ldap-sudo/ yum -y install openldap-clients sssd authcon ...

  2. 09-OpenLDAP加密传输配置

    OpenLDAP加密传输配置(CA服务器与openldap服务器异机) 阅读视图 环境准备 CA证书服务器搭建 OpenLDAP服务端与CA集成 OpenLDAP客户端配置 客户端测试验证 故障处理 ...

  3. SQL Server 2008, 2008 R2, 2012 and 2014 完全支持TLS1.2加密传输

    SQL Server 2008, 2008 R2, 2012 and 2014 完全支持TLS1.2加密传输 微软高兴地宣布所有主流SQL Server客户端驱动和SQL Server发行版已经支持T ...

  4. Java 前端加密传输后端解密以及验证码功能

    目录(?)[-] 加密解密 1 前端js加密概述 2 前后端加密解密 21 引用的js加密库 22 js加密解密 23 Java端加密解密PKCS5Padding与js的Pkcs7一致 验证码 1 概 ...

  5. 用RSA加密实现Web登录密码加密传输

    通常我们做一个Web应用程序的时候都需要登录,登录就要输入用户名和登录密码,并且,用户名和登录密码都是明文传输的,这样就有可能在中途被别人拦截,尤其是在网吧等场合. 这里顺带一个小插曲,我以前有家公司 ...

  6. 加密传输SSL协议6_验证公钥

    如上图所示,我怎么能确定我手里的公钥就是我心中的接收方的公钥呢?怎么防止被钓鱼呢? 解决的办法就是引入一个第三方,一个权威机构,一个我们都相信的机构. 验证公钥,Digital Certificate ...

  7. 加密传输SSL协议5_Hash Function

    怎么对一个大的文件进行签名,因为文件比较大,非对称签名很慢.那么想,我能把这个大的文件通过一种函数变换,变成一个和源文件唯一对应的的小的文件吗?答案是可以的. Hash Function 这里任何的文 ...

  8. 加密传输SSL协议4_综合方案

    隔了那么多天终于有时间继续把这个专题做完了,这次一定连续写完这方面的笔记. 上篇博文说明了非对称加密和对称加密各自的优缺点,那么就很自然的衍生出了一种综合的方案. 两种方案的结合--扬长避短 首先发送 ...

  9. js中变量base64加密传输

    首先对base64进行定义: var Base64 = { _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01 ...

随机推荐

  1. python3 使用pyperclip读写剪贴板(windows)

    2016年5月14日 03:41:38 codegay 使用pyperclip库读写剪贴板非常简单~, 1.使用命令安装: pip install pyperclip 2.然后...就可以了: 以下是 ...

  2. Javascript笔记一

    Javascript: ECMAscript :相当于翻译器 翻译电脑于代码  解释器 DOM document object model  文档 对象 模型  --->document  获取 ...

  3. TCP 状态机

    TCP 状态机 TCP 协议的操作可以使用一个具有 11 种状态的有限状态机( Finite State Machine )来表示,图 3-12 描述了 TCP 的有限状态机,图中的圆角矩形表示状态, ...

  4. 如何使用git 跟进项目进程

    首先,git能够记录版本信息,方便大家在任何时刻能够取回之前的项目版本,其次可以记录分支信息,方便进行分支作业. Step1:cd到你的项目根目录下,从团队github 项目clone到本地. 命令如 ...

  5. Oracle数据库初级学习

    第一天 SQL查询语句 CMD——SQLPLUS----账号 soctt 密码 tiger,输入完成后进入SQL数据库,如图显示即连接成功. 连接成功后 ,我们首先设置一下基本界面, --设置 每列显 ...

  6. 为python-sproto添加map支持

    上个月太忙了,做完这个修改还没写博客,现在补一下.. 之前使用protobuf做协议打包的时候,经常会有个痛点,没法用具体数据的值作为key来索引数据.比如现在客户端上传了造兵协议,协议大概长这样: ...

  7. oracle 跨数据库取数据

    思路:先从另一个数据库里把数据取出来, 然后,把这个数据集合解析,根据这个数据集合拆分组合成一个创建oralce临时表的方法及数据的插入.紧接着就可以写sql语句进行联合查询了. 下面是具体实例的方法 ...

  8. CSS值得关注的那些事?

    CSS值得关注的那些事? CSS层叠样式表的出现,使得样式表现层与HTML结构层分离,CSS样式与HTML结构层次清晰,一目了然.给我们前端开发者带来诸多的便利,然而,在实际前端开发中,还是有相当多的 ...

  9. javaScript 1

    js 字符串 1. 必须在写在一行,写在多行会报错,可以用 / 分开写在多行 也可以用 “+” 连接 . ===> /转义字符   /r/n:  (以下来在百度) \r是回车,英文是Carria ...

  10. 安卓中自定义并使用Volley框架请求网络

    大家好,今天我们讲一下如何使用Volley框架请求网络,为何要使用Volley框架,这就要先说一下使用Volley框架请求网络的优点了,volley是易于定制的,即你可以根据需求来设定volley框架 ...