歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> FreeBSD下利用ACI/SSL安全使用OpenLDAP

FreeBSD下利用ACI/SSL安全使用OpenLDAP

日期:2017/2/27 14:27:20   编辑:更多Linux
  一、使用訪問控制(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)中心發行的證書簽發證書或自簽發證書,這裡用的是自簽發證書。    參考:http://www.openldap.org/pub/ksoper/OpenLDAP_TLS_howto.Html  http://www.openldap.org/faq/data/cache/185.html    (一)服務端的證書    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




Copyright © Linux教程網 All Rights Reserved