Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2462480
  • 博文数量: 867
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 9800
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-27 14:44
文章分类

全部博文(867)

文章存档

2007年(6)

2006年(861)

我的朋友

分类: BSD

2006-09-14 10:41:04

 
TAG:System(FreeBSD)

  一、使用访问控制(Access Control),实现用户认证
  
  关于它,在OpenLDAP 2.1 Administrator's Guide里有详细说明。这里只管应用。
  
  修改OpenLDAP的配置文件,增加控制块
  
  # vi /usr/local/etc/openldap/slapd.conf
  access to attr=userPassword
  by anonymous auth
  by self write
  by * none
  
  access to *
  by self write
  by users read
  
  此控制块用于禁止匿名查询,而认证用户可以修改自己的所有属性,允许查询它人的信息条目,但除了userPassword属性。基本上上面的每一行都是必须的,经过反复删除恢复,终于对访问控制块的认识有了质的飞跃。特别是对于“by anonymous auth”的理解,没有了它,需要认证的用户不能完成认证,因为它查询不到密码呀!所以“auth”在这里的作用就是允许匿名用户可以读到密码,但只能用于验证,而不能用于其它的用途,这就保证了密码属性的安全。
  
  重启ldap服务
  
  # /usr/local/etc/rc.d/slapd.sh restart
  
  查询测试
  
  1、如果还使用LDAP Browser 2.6的话,这次就可以使用其它的用户bind了,如使用用户:
  
  uid=abc,ou=people,dc=example,dc=com
  
  它的密码是:abcabc(见前面的例子)
  
  2、在命令行完成
  
  # ldapsearch -x -b 'dc=example,dc=com' 'objectClass=*'
  
  匿名查询结果:(显然没有任何条目)
  
  # extended LDIF
  #
  # LDAPv3
  # base with scope sub
  # filter: objectClass=*
  # requesting: ALL
  #
  
  # search result
  search: 2
  result: 0 Success
  
  # numResponses: 1
  
  # ldapsearch -x -b 'dc=example,dc=com' -D 'uid=abc,ou=people,dc=example,dc=com' -w abcabc 'uid=a*'
  
  通过指定用户查询的结果:
  
  # extended LDIF
  #
  # LDAPv3
  # base with scope sub
  # filter: uid=a*
  # requesting: ALL
  #
  
  # abc, people, example.com
  dn: uid=abc,ou=people,dc=example,dc=com
  objectClass: person
  objectClass: organizationalPerson
  objectClass: inetOrgPerson
  uid: abc
  sn: zhangs
  cn: zs
  userPassword:: YWJjYWJj
  
  # aaa, people, example.com
  dn: uid=aaa,ou=people,dc=example,dc=com
  objectClass: person
  objectClass: organizationalPerson
  objectClass: inetOrgPerson
  uid: aaa
  sn: aaaa
  cn:: YWFkQSA=
  
  # search result
  search: 2
  result: 0 Success
  
  # numResponses: 3
  # numEntries: 2
  
  如果过滤条件还是用'objectClass=*'的话,产生的条目数很多,所以这里就必为了'uid=a*'。从结果中我们可以看到“uid=abc,ou=people,dc=example,dc=com”的userPassword属性显示了出来,而另一个用户则没有显示。上面执行的命令中红色部分分别是查询时使用的用户名和密码,其中密码就是条目“uid=abc,ou=people,dc=example,dc=com”中所存放的userPassword的值。
  
  二、使用SSL/TLS
  
  通过认证授权(Certificate Authority)中心发行的证书签发证书或自签发证书,这里用的是自签发证书。
  
  参考:
  
  
  (一)服务端的证书
  
  1、建立一临时目录
  
  # mkdir ~/ldap
  #cd ~/ldap
  
  2、建立用于签署其它证书的CA证书(应该是X509v3格式的)
  
  # /usr/local/openssl/misc/CA.sh -newca
  
  如果不输入文件名,则会在当前目录下会生成demoCA目录,里边存放有cacert.pem 和private/cakey.pem (CA证书和RSA私有密钥)。在填写各项目的过程上,有些项目不是很重要,对于“Common Name”,应该填入有一定意义易于阅读的字符串,不一定是服务器的名字,我的就是abc.cn,而服务器名字为myth.unix.cn。
  其实,它是一个自签署证书,此时CA已进行了自签署,而形成了根证书。其中依然有公钥和私钥。公钥可以发布,用于确认服务器证书的合法性。
  
  2、建立服务器的“证书签署请求(certificate signing request - CSR)”,即签署请求证书
  
  同时也将它做为服务器的私有密钥
  
  # openssl req -newkey rsa:1024 -nodes -keyout newreq.pem -out newreq.pem
  
  其它没什么,对于“Common Name”则一定要小心,此处应该填入服务器的FQDN(fully-qualified distinguished name),即运行OpenLDAP的服务器的完整名称,而不是一般的简写名称。如果你的服务器有多个名称,就先把主名填入这里,而对于其它的别名,则可以利用openssl.cnf文件里的subjectAltName。例如:
  subjectAltName=DNS:alias1.domain1,DNS:host2.domain2,DNS:*.domain3
  
  关于FQDN,对于unix或linux的用户来说应该不陌生,实际上在你安装系统时,配置IP地址那个地方就已经进行FQDN的设定。现在想知道你的服务器的FQDN的方法,可以通过执行
  
  # hostname
  
  得到,或查看/etc/rc.conf。
  
  我的自己的名字就是:myth.unix.cn。据说90%的错误都出在这里。
  
  查看newreq.pem的内容:
  
  # openssl req -noout -text -in newreq.pem
  
  3、使用前面的CA证书签署CSR,得到签署后的证书,可以发布
  
  此证书也称为服务器证书,里面主要包含了证书的签署机构、服务器的公钥以及服务器的全域名(FQDN)等等。其有效性可以通过使用CA证书的公钥,即demoCA/cacert.pem来进行确认。主要用于对此服务器的验证。
  
  # /usr/local/openssl/misc/CA.sh -sign
  
  注意,不要出错,尤其是密码不要错了。除此以外,另外还有两次确认选项。
  
  Using configuration from /etc/ssl/openssl.cnf
  Enter pass phrase for ./demoCA/private/cakey.pem:
  Check that the request matches the signature
  Signature ok
  Certificate Details:
  Serial Number: 1 (0x1)
  Validity
  Not Before: Nov 18 17:11:48 2004 GMT
  Not After : Nov 18 17:11:48 2005 GMT
  Subject:
  countryName = CN
  stateOrProvinceName = Some-State
  organizationName = Internet Widgits Pty Ltd
  commonName = myth.unix.cn
  X509v3 extensions:
  X509v3 Basic Constraints:
  CA:FALSE
  Netscape Comment:
  OpenSSL Generated Certificate
  X509v3 Subject Key Identifier:
  EC:5A:A3:89:D0:24:7F:83:70:25:E6:A6:CA:D8:35:09:5A:65:70:E3
  X509v3 Authority Key Identifier:
  keyid:4E:A0:2B:E4:B2:BB:01:9B:5D:12:7D:90:79:40:22:36:8B:29:28:AC
  DirName:/C=CN/ST=Some-State/O=Internet Widgits Pty Ltd/CN=abc.cn
  serial:00
  
  Certificate is to be certified until Nov 18 17:11:48 2005 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
  Certificate:
  Data:
  Version: 3 (0x2)
  Serial Number: 1 (0x1)
  Signature Algorithm: md5WithRSAEncryption
  Issuer: C=CN, ST=Some-State, O=Internet Widgits Pty Ltd, CN=abc.cn
  Validity
  Not Before: Nov 18 17:11:48 2004 GMT
  Not After : Nov 18 17:11:48 2005 GMT
  Subject: C=CN, ST=Some-State, O=Internet Widgits Pty Ltd, CN=myth.unix.cn
  Subject Public Key Info:
  Public Key Algorithm: rsaEncryption
  RSA Public Key: (1024 bit)
  Modulus (1024 bit):
  00:b7:7a:49:0f:53:53:b2:d0:c3:38:c5:fc:ba:1b:
  db:69:56:a6:e2:20:e8:f9:48:77:f1:95:c9:0b:f3:
  8d:0d:d6:43:7b:de:c2:82:88:58:7c:8a:0f:59:0e:
  00:46:4e:b1:ff:03:e4:49:39:1a:33:6d:94:b4:e8:
  36:e6:99:63:2a:16:21:7a:21:be:4e:92:08:92:35:
  d6:59:cd:39:9b:bc:0d:6e:31:7a:1b:e1:50:c3:e2:
  62:e0:99:1c:25:78:22:fa:e4:26:1b:b6:0c:71:0c:
  52:99:64:81:03:77:56:ec:8c:7e:3d:0a:ca:4e:9c:
  82:a9:55:5d:9d:75:64:f1:9d
  Exponent: 65537 (0x10001)
  X509v3 extensions:
  X509v3 Basic Constraints:
  CA:FALSE
  Netscape Comment:
  OpenSSL Generated Certificate
  X509v3 Subject Key Identifier:
  EC:5A:A3:89:D0:24:7F:83:70:25:E6:A6:CA:D8:35:09:5A:65:70:E3
  X509v3 Authority Key Identifier:
  keyid:4E:A0:2B:E4:B2:BB:01:9B:5D:12:7D:90:79:40:22:36:8B:29:28:AC
  DirName:/C=CN/ST=Some-State/O=Internet Widgits Pty Ltd/CN=abc.cn
  serial:00
  
  Signature Algorithm: md5WithRSAEncryption
  67:bf:f5:2e:6b:7e:e1:53

阅读(2568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~