1.Server制做自签名证书node
2.修改目录权限及全部者linux
3.修改配置文件,添加证书路径数据库
4.从新生成配置文件 并启动服务vim
5.客户端配置及测试安全
方案二:CA中心签名服务器
CA中心简介分布式
一、创建Ca中心ide
二、客户机公钥签名工具
建立证书的另外一种方法测试
三、将签名证书和CA证书导入ldap server
四、客户端配置(将ca证书导入)及测试
*******************************************
Openldap默认使用简单验证,对slapd的全部访问都使用明文密码经过未加密通道进行。为了确保信息安全,须要对信息进行加密传输,SSL(Secure Sockets Layer)是一个可靠的解决方案。
它使用 X.509 证书,由可信任第三方(Certificate Authority (CA))进行数字签名的一个标准格式的数据。有效的数字签名意味着已签名的数据没有被篡改。若是签名的数据被更改,将不会经过验证。
方案一采用自签名证书,由本身签发,便于测试时使用。
环境:red hat enterprise linux 6.3,已按照上一篇文章的步骤搭建好openldap server。
IP:192.168.0.254
# cd /etc/openldap/certs/
# openssl genrsa -out ldap.key 1024 //私钥
# openssl req -new -key ldap.key -out ldap.csr //生成签名请求
openssl req 接受生成密钥对的公共部分,添加一些位置信息,并将结果打包为Certificate Signing Request (CSR)由CA中心签署。
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]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name(eg, your name or your server's hostname)[]:master.example.com //主机名用FQDN格式
Email Address []:root@master.example.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# openssl x509 -req -days 1095 -in ldap.csr -signkey ldap.key -out ldap.crt//公钥(自签名)
将生成的ldap.csr文件发送到CA进行签名。若是发送此文件到CA进行签名,则须要确保提供的全部信息拼写正确。这里不使用ca中心对csr进行签名。
完成自签名证书的制做,ldap.key(私钥)、ldap.crt(证书、公钥)。
# chmod 700 certs/
# chown ldap.ldap certs/ -R
# vim /etc/openldap/ldap.conf
TLS_CACERTDIR /etc/openldap/certs //更改证书目录
TLS_REQCERT allow //容许自签名证书(服务器、客户机都加入)
# vim /etc/openldap/slapd.conf //修改配置文件
TLSCertificateFile /etc/openldap/certs/ldap.crt
TLSCertificateKeyFile /etc/openldap/certs/ldap.key
# service slapd stop
# rm -rf /etc/openldap/slapd.d/*
# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/
# chown ldap.ldap /etc/openldap/slapd.d/ -R
# slapd -h "ldaps:///" //启动服务,监听636端口
先利用setup工具配置,在# vim /etc/openldap/ldap.conf添加
TLS_REQCERT allow//容许自签名证书(服务器、客户机都加入)
TLS_CACERTDIR /etc/openldap/cacerts
URI ldaps://192.168.0.254
BASE dc=example,dc=com
客户端测试
1.# ldapwhoami -v -x -Z //匿名测试ssl连接
ldap_initialize( )
ldap_start_tls: Operations error (1)
additional info: TLS already started
anonymous
Result: Success (0)
2.ldaps验证用户密码
#ldapwhoami -D "uid=ldapuser1,ou=People,dc=example,dc=com" -W -H ldaps://192.168.0.254 -v
ldap_initialize( ldaps://192.168.0.254:636/??base )
Enter LDAP Password:
dn:uid=ldapuser1,ou=People,dc=example,dc=com
Result: Success (0)
-D 指定distinguish name
-W提示输入密码
-H 使用ldap://或ldaps://协议
-h IP
-v详细信息
3.搜索ldap服务器域信息
# ldapsearch -x -b "dc=example,dc=com" -H ldaps://192.168.0.254
CA中心 — 证书受权(Certificate Authority)中心,是电子商务交易中受信任的权威第三方,用来验证公钥合法性的机构。CA中心为每一个使用公钥的客户发放数字证书,数字证书的做用是证实证书中列出的客户合法拥有证书中列出的公钥。CA机构的数字签名使得第三者不能伪造和篡改证书。它负责产生、分配并管理全部参与网上信息交换各方所需的数字证书,所以是安全电子信息交换的核心。
CA中心,是PKI(Public Key Infrastructure)体系的核心。它为客户的公钥签发公钥证书、发放证书和管理证书,并提供密钥生命周期内的管理服务。它将客户的公钥与客户的名称及其余属性关联起来,为客户之间电子身份进行认证。
CA中心在密码管理方面的做用以下:
1. 自身密钥的产生、存储、备份/恢复、归档和销毁
从根CA开始到直接给客户发放证书的各层次CA,都有其自身的密钥对。CA中心的密钥对通常由硬件加密服务器在机器内直接产生,并存储于加密硬件内,或以必定的加密形式存放于密钥数据库内。加密备份于IC卡或其余存储介质中,并以高等级的物理安全措施保护起来。密钥的销毁要以安全的密钥冲写标准,完全清除原有的密钥痕迹。须要强调的是,根CA密钥的安全性相当重要,它的泄露意味着整个公钥信任体系的崩溃,因此CA的密钥保护必须按照最高安全级的保护方式来进行设置和管理。
2.为认证中心与各地注册审核发放机构的安全加密通讯提供安全密钥管理服务
在客户证书的生成与发放过程当中,除了有CA中心外,还有注册机构、审核机构和发放机构(对于有外部介质的证书)的存在。行业使用范围内的证书,其证书的审批控制,可由独立于CA中心的行业审核机构来完成。CA中心在与各机构进行安全通讯时,可采用多种手段。对于使用证书机制的安全通讯,各机构(通讯端)的密钥产生、发放与管理维护,均可由CA中心来完成。
3.肯定客户密钥生存周期,实施密钥吊销和更新管理
每一张客户公钥证书都会有有效期,密钥对生命周期的长短由签发证书的CA中心来肯定。各CA系统的证书有效期限有所不一样,通常大约为2~3年。
密钥更新有如下两种状况:密钥对到期、密钥泄露后须要启用新的密钥对(证书吊销)。
采用证书的公钥吊销,是经过吊销公钥证书来实现的。公钥证书的吊销来自于两个方向,一个是上级的主动吊销,另外一个是下级主动申请证书的吊销。当上级CA对下级CA不能信赖时(如上级发现下级CA的私钥有泄露的可能),它能够主动中止下级CA公钥证书的合法使用。当客户发现本身的私钥泄露时,也可主动申请公钥证书的吊销,防止其余客户继续使用该公钥来加密重要信息,而使非法客户有盗取机密的可能。通常而言,在电子商务实际应用中,可能会较少出现私钥泄露的状况,多数状况是因为某个客户因为组织变更而调离该单位,须要提早吊销表明企业身份的该客户的证书。
4.提供密钥生成和分发服务
CA中心可为客户提供密钥对的生成服务,它采用集中或分布式的方式进行。在集中的情形下,CA中心可以使用硬件加密服务器,为多个客户申请成批的生成密钥对,而后采用安全的信道分发给客户。也可由多个注册机构(RA)分布生成客户密钥对并分发给客户。
5.提供密钥托管和密钥恢复服务
CA中心可根据客户的要求提供密钥托管服务,备份和管理客户的加密密钥对。当客户须要时能够从密钥库中提出客户的加密密钥对,为客户恢复其加密密钥对,以解开先前加密的信息。这种情形下,CA中心的密钥管理器,采用对称加密方式对各个客户私钥进行加密,密钥加密密钥在加密后即销毁,保证了私钥存储的安全性。密钥恢复时,采用相应的密钥恢复模块进行解密,以保证客户的私钥在恢复时没有任何风险和不安全因素。同时,CA中心也应有一套备份库,避免密钥数据库的意外毁坏而没法恢复客户私钥。
6.其余密钥生成和管理、密码运算功能
CA中心在自身密钥和客户密钥管理方面的特殊地位和做用,决定了它具备主密钥、多级密钥加密密钥等多种密钥的生成和管理功能。
对于为客户提供公钥信任、管理和维护整个电子商务密码体系的CA中心来说,其密钥管理工做是一项十分复杂的任务,它涉及到CA中心自身的各个安全区域和部件、注册审核机构以及客户端的安全和密码管理策略。
1. # vim /etc/pki/tls/openssl.cnf 配置ca密钥签发信息
[ CA_default ]
dir = /etc/pki/CA #默认路径
certs = $dir/certs #颁发证书的备份,存放签名公钥
crl_dir = $dir/crl #证书吊销列表
database = $dir/index.txt #证书颁发的信息,吊销信息等
new_certs_dir = $dir/newcerts # 签发证书副本,吊销时用的(吊销凭证)
certificate = $dir/my-ca.crt # The CA certificate CA中心公钥
serial = $dir/serial #序列号,每作一次签名,增长一
crlnumber = $dir/crlnumber #吊销序列号,每吊销一次,增长一
crl = $dir/my-crl.crl #吊销列表,客户端须要下载,添加黑名单
private_key = $dir/private/my-ca.key # CA中心的私钥
…
default_days = 365 证书有效期(默认一年)
default_crl_days = 30 吊销列表更新周期
[ policy_match ] 策略匹配
countryName = match 必须匹配(城市名)
stateOrProvinceName = match (国家或州名)
organizationName = match (组织名)
organizationalUnitName = optional可选的匹配(单位名)
commonName = supplied用户提供的,必须不同 (经常使用名)
emailAddress = optional 邮件地址,能够不填
…
[ req_distinguished_name ]
countryName_default = CN 设置国家
stateOrProvinceName_default = BeiJing 省
localityNmae_default = BeiJing 城市
0.organizationName_default = Example, Inc. 组织
# cd /etc/pki/tls/
# mkdir {certs,netcerts,crl}
# touch index.txt
# echo "00" > serial
2. 建立CA私钥
# (umask 077 ; openssl genrsa -out /etc/pki/CA/private/my-ca.key -des3 1024)
# (umask 077 ; openssl genrsa -des3 1024 > /etc/pki/CA/private/my-ca.key )
pass phrase: //设置私钥密码
3. 生成公钥(CA证书).crt
# openssl req -new -x509 -key /etc/pki/CA/private/my-ca.key > /etc/pki/CA/my-ca.crt
按照x509格式签发公钥(证书)
Enter pass phrase for /etc/pki/CA/private/my-ca.key: redhat
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) [CN]:
State or Province Name (full name) [BeiJing]:
Locality Name (eg, city) [BeiJing]:
Organization Name (eg, company) [Example, Inc.]:
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:master.example.com
Email Address []:root@master.example.com
4. 安装ftp 分发CA证书my-ca.crt
# yum install vsftpd
# cp /etc/pki/CA/my-ca.crt /var/ftp/my-ca.crt
# service vsftpd restart;chkconfig vsftpd on
CA中心配置结束
客户机生成请求,csr -> CA签发 -> crt -> 拷回客户机已签名的证书
1. 客户机生成私钥
# openssl genrsa -des3 1024 > /etc/openldap/certs/ldap.key
2. 生成签名请求
# openssl req -new -key /etc/openldap/certs/ldap.key -out /etc/openldap/certs/ldap.csr
Enter pass phrase for /opt/httpd.key:redhat
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) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:Example, Inc.
--------以上信息要和CA中心同样---------
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:desktop9.example.com//本机FQDN域名
Email Address []:root@desktop9.example.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: //csr密码
An optional company name []: //可选的公司名称
3. 发给CA 签发 (用ca的私钥 .key 去签发csr -> crt证书)
# scp ldap.csr 192.168.0.254:/root/
CA端 签发证书:
# openssl ca -in /root/ldap.csr -out /root/ldap.crt
此时会弹出错误,须要根据错误信息创建一系列文件。
mkdir /etc/pki/CA/newcerts
touch /etc/pki/CA/index.txt
echo "00" > /etc/pki/CA/serial
报错:
# openssl ca -in /root/ldap.csr -out /root/ldap.crt
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for /etc/pki/CA/private/my-ca.key:
Check that the request matches the signature
Signature ok
The stateOrProvinceName field needed to be the same in the
CA certificate (BeiJing) and the request (BeiJing) //须要相同的字段
由于Rhel 5默认用MD5 1024位加密,Rhel 6用SHA-512 2048位加密。
(可在/etc/pki/tls/openssl.cnf修改)
# openssl ca -in /root/ldap.csr -out /root/ldap.crt
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for /etc/pki/CA/private/my-ca.key:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 0 (0x0)
Validity
Not Before: Dec 17 12:14:57 2012 GMT
Not After : Dec 17 12:14:57 2013 GMT
Subject:
countryName = CN
stateOrProvinceName = BeiJing
organizationName = Example, Inc.
organizationalUnitName = IT
commonName = master.example.com
emailAddress = root@master.example.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
5F:7F:55:F9:05:1B:F6:DB:A5:9D:36:EA:4B:0B:66:01:65:51:6F:13
X509v3 Authority Key Identifier:
keyid:80:38:73:E2:17:21:54:2B:B1:5D:A4:97:0A:E9:19:EF:3C:40:60:17
Certificate is to be certified until Dec 17 12:14:57 2013 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
成功~!把签名证书和CA证书导入客户机。
OpenSSL相关命令:
建立CA中心:( umask 77; openssl genrsa -out private/my-ca.key -des3 2048 )
openssl req -new -x509 -key private/my-ca.key -days 365 > my-ca.crt
私钥加密:openssl rsa -in encrypted.key -out unencrypted.key
私钥解密:openssl rsa -in unencrypted.key -out encrypted.key
生成私钥:( umask 77; openssl genrsa 1024 > dovecot.key )
生成CSR:(umask 77; openssl req -new -key somefile.key -out somefile.csr )
可用/etc/pki/tls/certs/Makefile建立CSR
查看CSR:openssl req -noout -in somefile.csr -text
建立CA签名证书:openssl ca -in my.csr -out my.crt
证书吊销:openssl ca -revoke badcert.crt
生成证书吊销列表CRL:openssl ca -gencrl -out revoked.crl
生成DER供firefox使用:openssl crl -in revoked.crl -outform. DER -out revoked.der.crl
检查CRL内容:openssl crl -in revoked.crl -noout -text
建立证书的另外一种方法:
1.建立证书(certificate)
分为3个步骤:
1. 创建CA中心
2. 签发server的证书
3. 签发client的证书
须要特别注意建立证书时,输入Common Name的时候必定要输入目标机器的fully qualified name。
1.1 建立CA
/etc/pki/tls/misc //建立CA脚本的目录
/etc/pki/CA //是存放全部CA相关文件的目录
完成后,会在/etc/pki/CA目录下生成一系列文件。
/etc/pki/CA/cakey.pem //CA私钥
/etc/pki/CA/cacert.pem //CA证书
tips:若是脚本检测到/etc/pki/CA下面有文件存在,会安静的退出,不会建立任何东西。
把/etc/pki/CA下的文件所有删除,script就能够正常工做了。
# cd /etc/pki/tls/misc
# ./CA -newca
[usage: ./CA -newcert|-newreq|-newreq-nodes|-newca|-sign|-verify]
Making CA certificate ...
Generating a 2048 bit RSA private key
...................................+++
..............................+++
writing new private key to '/etc/pki/CA/private/./cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
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) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:Example, Inc.
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:server.example.com
Email Address []:root@server.example.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: //csr密码
An optional company name []: //公司名
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for /etc/pki/CA/private/./cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
89:3a:ab:fa:52:5f:80:f4
Validity
Not Before: Dec 20 15:52:28 2012 GMT
Not After : Dec 20 15:52:28 2015 GMT
Subject:
countryName = CN
stateOrProvinceName = BeiJing
organizationName = Example, Inc.
organizationalUnitName = IT
commonName = server.example.com
emailAddress = root@server.example.com
X509v3 extensions:
X509v3 Subject Key Identifier:
D8:A2:05:AD:99:95:63:52:00:42:10:3A:37:DF:79:C0:55:6E:FA:4D
X509v3 Authority Key Identifier:
keyid:D8:A2:05:AD:99:95:63:52:00:42:10:3A:37:DF:79:C0:55:6E:FA:4D
X509v3 Basic Constraints:
CA:TRUE
Certificate is to be certified until Dec 20 15:52:28 2015 GMT (1095 days)
Write out database with 1 new entries
Data Base Updated
1.2 建立server证书
下面建立ldap server的证书。
分为两步:
第一步生成证书请求
第二步让CA签发证书
# ./CA -newreq-nodes
Generating a 2048 bit RSA private key
............................................................................................................................................+++
...........................................................................................+++
writing new private key to 'newreq.pem'
-----
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) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:Example, Inc.
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:ldap.example.com
Email Address []:root@ldap.example.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Request (and private key) is in newreq.pem
# ./CA -sign
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for ../../CA/private/cakey.pem: ca私钥密码
Check that the request matches the signature
Signature ok
Certificate Details:
.....省略部份内容......
Certificate is to be certified until Apr 16 22:37:14 2008 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
Signed certificate is in newcert.pem
完成两个步骤后,在当前目录下建立了2个文件:
/etc/pki/tls/misc/newreq.pem//证书请求文件和证书私钥
/etc/pki/tls/misc/newcert.pem//CA签发的证书
而后设置合适的权限,私钥文件要设为只有owner能读。不然ssl安全体系形同虚设!
# mv newcert.pem server.crt ; chmod 644 server.crt
# mv newreq.pem server.key ; chmod 600 server.key
最后把这两个文件和CA的证书拷贝到Openldap Server存放证书的目录下
# mv server.crt /etc/openldap/certs/
# mv server.key /etc/openldap/certs/
# cp ../../CA/cacert.pem /etc/openldap/certs/
1.3 建立client证书
建立client证书要注意:
1)输入Common Name的时候必定要输入client的fully qualified name!
2)证书、私钥和ca证书要拷贝到客户端的/etc/openldap/cacerts中。
1. 下载CA中心证书
# cp /etc/pki/CA/my-ca.crt /etc/openldap/certs/
# ls /etc/openldap/certs/
ldap.crt(已签名ldap服务器公钥)
ldap.csr(ldap服务器签名请求)
ldap.key(ldap服务器私钥)
my-ca.crt(CA证书)
# openssl rsa -in /etc/openldap/certs/ldap.key -out /etc/openldap/certs/ldap.key- //解密私钥,使启动时不须要输入私钥解密密码。(不然查询一次就要输入一次私钥密码,这个能够在调试模式下验证。[#slapd -d 256 -h “ldaps:///”])
# mv /etc/openldap/certs/ldap.key /etc/openldap/certs/ldap.key.encrypt
# mv /etc/openldap/certs/ldap.key- /etc/openldap/certs/ldap.key
2.修改权限及全部者
# chmod 700 /etc/openldap/certs/
# chmod 600 /etc/openldap/certs/ldap.key
# chown ldap.ldap certs/ -R
3. 修改配置文件,添加证书路径
# cp ldap.conf ldap.conf.bak;cp slapd.conf slapd.conf.bak //备份配置文件
# vim /etc/openldap/ldap.conf
TLS_CACERTDIR /etc/openldap/certs //更改证书目录(默认)
# vim /etc/openldap/slapd.conf //修改配置文件
TLSVerifyClient never//不须要认证客户端
TLSCACertificatePath /etc/openldap/certs
TLSCACertificateFile /etc/openldap/certs/my-ca.crt
TLSCertificateFile /etc/openldap/certs/ldap.crt
TLSCertificateKeyFile /etc/openldap/certs/ldap.key
TLSVerifyClient [never、allow、try、demand]
设置是否验证客户端发起的tls链接。
never:默认选项,不验证客户端证书。
allow:检查客户端证书,没有证书或证书错误,都容许链接。
try:检查客户端证书,没有证书(容许链接),证书错误(终止链接)。
demand | hard | true:检查客户端证书,没有证书或证书错误都将当即终止链接。
启用非默认TLSVerifyClient设置,为了使用外部身份验证机制和SASL TLS会话。
4. 从新生成配置文件 并启动服务
# service slapd stop
# rm -rf /etc/openldap/slapd.d/*
# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/
# chown ldap.ldap /etc/openldap/slapd.d/ -R
# slapd -h "ldaps:///" //启动服务,监听636端口
利用setup配置
# scp certs/my-ca.crt 192.168.0.18:/etc/openldap/cacerts/ //拷贝ca证书
在# vim /etc/openldap/ldap.conf添加
TLS_CACERT /etc/openldap/cacerts/my-ca.crt//ca证书
TLS_CACERTDIR /etc/openldap/cacerts
URI ldaps://master.example.com //要与证书中的域名同样
BASE dc=example,dc=com
TLS_REQCERT demand//总要求验证server
TLS_REQCERT [never、allow、try、demand | hard]
设置是否在TLS会话中检查server证书。
Never:不检查任何证书。
Allow:检查server证书,没有证书或证书错误,都容许链接。
Try:检查server证书,没有证书(容许链接),证书错误(终止链接)。
demand | hard:检查server证书,没有证书或证书错误都将当即终止链接。(默认)
客户端测试
1.#ldapwhoami -v -x -Z//匿名测试ssl连接
ldap_initialize( )
ldap_start_tls: Operations error (1)
additional info: TLS already started
anonymous
Result: Success (0)
2.ldaps验证用户密码
#ldapwhoami -D "uid=ldapuser1,ou=People,dc=example,dc=com" -W -H ldaps://master.example.com -v
ldap_initialize( ldaps://master.example.com:636/??base )
Enter LDAP Password:
dn:uid=ldapuser1,ou=People,dc=example,dc=com
Result: Success (0)
-D 指定distinguish name
-W提示输入密码
-H 使用ldap://或ldaps://协议
-h IP
-v详细信息
3.搜索ldap服务器域信息
# ldapsearch -x -b "dc=example,dc=com" -H ldaps://master.example.com
4.用openssl client链接ssl服务器
链接openssl服务器能够查看证书信息,加密方式等信息。
服务器不须要验证客户端:
# openssl s_client -connect server.example.com:636 -showcerts -state \
-CAfile /etc/openldap/cacerts/my-ca.crt
服务器须要验证客户端:
# openssl s_client -connect master.example.com:636 -showcerts -state \
-CAfile /etc/openldap/cacerts/my-ca.crt \
-cert /etc/openldap/cacerts/client.crt \
-key /etc/openldap/cacerts/client.key
调试方法:
配置完成之后,老是不能查询ldap条目。运行调试之后,在终端显示以下信息。原来是个人ldap.key没有解密,致使每次查询都要输入私钥密码。
# slapd -d 256 -h "ldaps:///"
conn=1000 fd=12 ACCEPT from IP=192.168.0.18:48343 (IP=0.0.0.0:636)
Please enter pin, password, or pass phrase for security token 'PEM Token #0':
TLS: could not authenticate to the security token PEM Token #0 - error -8025:A PKCS #11 module returned CKR_GENERAL_ERROR, indicating that an unrecoverable error has occurred..
TLS: error: unable to authenticate to the security device for certificate PEM Token #0:ldap.crt - 0
TLS: error: could not initialize moznss security context - error -8025:A PKCS #11 module returned CKR_GENERAL_ERROR, indicating that an unrecoverable error has occurred.
TLS: can't create ssl handle.
conn=1000 fd=12 closed (TLS negotiation failure)
私钥有密码~!!!须要解密,不然每次查询都要输入密码。
conn=1001 fd=12 ACCEPT from IP=192.168.0.18:48361 (IP=0.0.0.0:636)
TLS: error: accept - force handshake failure: errno 11 - moznss error -12195
TLS: can't accept: TLS error -12195:Peer does not recognize and trust the CA that issued your certificate..
conn=1001 fd=12 closed (TLS negotiation failure)
本文出自 “大蚊子linux” 博客,请务必保留此出处http://mosquito.blog.51cto.com/2973374/1098456