歡迎您光臨本站 註冊首頁

Freeradius+OpenLDAP+PEAP認證

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

Freeradius+OpenLDAP+PEAP認證

文檔介紹:

[*]作者:gavin
[*]電子郵箱:gavin.zhou@gmail.com
[*]MSN:gavin_zhm@msn.com
[*]博客地址:http://blog.yepn.net
[*]Wiki地址:http://wiki.yepn.net
[*]建立日期:2008年07月15日
[*]版本: 0.1
[*]版權說明:本文基於創作共用約定,內容歸作者版權所有,歡迎大家轉載,但要請保留作者的完整信息和出處,謝謝!


本文參考:
Extreme Networks Technical Brief 文檔號:TBLDAPEnviron_1370
http://www.nabble.com 討論列表也給了我很大的幫助,很多關於Freeradius和OpenLDAP保存數據的概念都在此討論區中弄明白的。對於文中所涉及的radius概念或是一些名詞請藉助google幫助學習,文中沒有更詳細的解釋。

關於:
公司原用認證伺服器為Soliton Net'Attest EPS,知道為什麼EPS證書一直不能正確導入到VISTA中,這點是從廠商方面得到的證明,不知道是什麼特別的原因。再加上EPS更換產品的空白伺服器,讓我感覺有些鬱悶,所以公司決定更換現在公司的認證系統,包括DHCP伺服器。
這是到公司后第二個自己獨立完成的比較完整的公司網路改造過程,記錄一下方便自己以後查閱,也希望能為準備用Freeradius認證和OpenLDAP的朋友提供一些有用的信息。
介於網路上流行的一些關於Freeradius+OpenLDAP+PEAP認證的一些資料都比較舊,所以在測試的時候Freeradius採用最新的Freeradius 2.0.5版本。由於2.0以前的版本配置文件格式和文件出入比較大,所以使用Freeradius2.0以前版本的朋友在配置的時候需要特別注意。CentOS下用yum安裝後為1.1.7版。

目的:
Freeradius在公司使用不是做為WLAN接認證,而是做為LAN接入認證用。先要通過認證后才能通論DHCP獲得IP,而且會因為Freeradius返回的信息為Client劃分VLAN ID以及訪問控制。

感謝:
首先是老婆對我生活上的細心照顧,才能讓我有更多的時間學習和測試來完成這份文檔。Freeradius的測試大部分在下班之後才能進行,所以每天晚上回家都很晚,老婆也一直等到我回家后才吃晚飯,另外要感謝遠在國內的父母,生活在異鄉的我們正因為有你們的牽挂,我們會更加努力。

===========================分割線==========================

伺服器環境:
CentOS 5.1 Linux blackduck 2.6.18-53.el5
#安裝時不含任何安裝包
yum –y update
#全部更新升級
openssl.i686 0.9.8b-10.el5
openssl-devel.i386 0.9.8b-10.el5
openldap.i386 2.3.27-8.el5_2.4
openldap-clients.i386 2.3.27-8.el5_2.4
openldap-devel.i386 2.3.27-8.el5_2.4
openldap-servers.i386 2.3.27-8.el5_2.4

對於OpenLDAP的配置可以參看我以前的文檔《Samba+LDAP+LAM管理工具應用》一文件中OpenLDAP的配置

Freeradius 安裝:
下載源碼包
#wget ftp://ftp.freeradius.org/pub/freeradius/freeradius-server-2.0.5.tar.bz2
#tar –jxvf freeradius-server-2.0.5.tar.bz2
#cd freeradius-server-2.0.5
#./configure --with-openssl --with-openssl-includes=/usr/include/openssl/ \
--with-openssl-libraries=/usr/lib/openssl/
#configure文件中說明配置支持OpenSSL但是裝完后運行EAP支持的時候會報錯。說手動沒有支持OpenSSL,所以此處給出OpenSSL的路徑。
#make && make install

安裝后可以直接執行進行測試
#radiusd –Xf   (2.0以前版本為-AXf  X為Debug模式 f為不運行在deamon狀態下 )

===========================分割線==========================

安裝后可以通過radtest測試
#radtest admin password localhost 0 testing123
返回信息如下說明測試成功,此步很重要,安裝后第一步應該測試一下Freeradius是不是可以正常運行,再進行下面的配置。
Sending Access-Request of id 85 to 127.0.0.1 port 1812
        User-Name = "admin"
        User-Password = "password"
        NAS-IP-Address = 127.0.0.1
        NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=85, length=20


測試通過後配置Freeradius,配置文件在/usr/local/etc/raddb下,2.0之後的配置對於對認證的支持方式採用模塊化,所以修改起來也很方便。配置文件忽略註釋項

主配置文件radiusd.conf:
#vi radiusd.conf
此文件只是把log選項中的認證log信息打開了其他部分沒有做任何修改
log {
        destination = files
file = ${logdir}/radius.log
        syslog_facility = daemon
        stripped_names = no
        auth = yes
        auth_badpass = no
        auth_goodpass = no
}

2.0以後的版本,所以有的認證模塊都保存在/usr/local/etc/raddb/modules目錄下
用戶認證配置文件

===========================分割線==========================

ldap認證模塊修改:
#vi ldap
比較重要的為前四行,設置你LDAP伺服器的配置,如何過慮User-Name的欄位,以前你LDAP的搜索域,如果你的LDAP需要許可權控制才能訪問,請修改配置文件中被註釋的兩行。
ldap {
        server = "localhost"
        #identity = "cn=admin,o=My Org,c=UA"
        #password = mypass
        basedn = "dc=yepn,dc=net"
        filter = "(uid=%{Stripped-User-Name:-%{User-Name}})"
        base_filter = "(objectclass=radiusprofile)"
        ldap_connections_number = 15
        timeout = 4
        timelimit = 3
        net_timeout = 1
        tls {
               start_tls = no
        }
        dictionary_mapping = ${confdir}/ldap.attrmap
}

紅色文件比較重要,這個表示在檢索LDAP時查找的欄位和返回的信息值,對於Client的網路配置部分都在這文件中表明,後文會詳細說明。

===========================分割線==========================

Freeradius字典文件修改:
通過LDAP認證時的返回值全部都要在Freeradius Dictionary中說明,否側不能被Freeradius識別。
Dictionary配置文件保存在/usr/local/etc/raddb目錄下
#cat dictionary |grep -v 「#」
$INCLUDE        /usr/local/share/freeradius/dictionary

Dictionary文件分部保存在/usr/local/share/freeradius/文件中
#cat dictionary |grep -v 「#」
$INCLUDE dictionary.compat
$INCLUDE dictionary.rfc2865
$INCLUDE dictionary.rfc2866
$INCLUDE dictionary.rfc2867
$INCLUDE dictionary.rfc2868
$INCLUDE dictionary.rfc2869
$INCLUDE dictionary.rfc3162
$INCLUDE dictionary.rfc3576
$INCLUDE dictionary.rfc3580
以下略

我的NAS用的是Extreme network summit X450交換機,需要修改的字典文件為dictionary.extreme,如果你使用的是其他NAS可以修改相應的字典文件,或是自己創建一個字典文件也可以。
加入下面兩行定義
ATTRIBUTE       Extreme-Netlogin-Extended-Vlan          211     string
ATTRIBUTE       Extreme-Security-Profile                212     string

字典修改後,修改ldap.attrmap讓LDAP可以返回extreme認證用的欄位。配置文件保存在/usr/local/etc/raddb/下

添加以下屬性
replyItem   Tunnel-Type                      radiusTunnelType
replyItem   Tunnel-Medium-Type              radiusTunnelMediumType
replyItem   Tunnel-Private-Group-Id           radiusTunnelPrivateGroupId
replyItem   Extreme-Security-Profile           radiusExtremeSecurityProfile
replyItem   Extreme-Netlogin-Vlan-Tag        radiusExtremeNetloginVlanTag
replyItem   Extreme-Netlogin-Extended-Vlan  radiusExtremeNetloginExtendedVlan
另外需要把NT-Password欄位修改如下,如果你希望radius用戶使用samba的密碼,可以不用修改這部分,因為我希望密碼分開管理,而且網路認證的密碼不會發給用戶,所以我用了其他的欄位做為Freeradius的認證密碼。

checkItem       NT-Password                     radiusUserPassword

這部分再次說明一下,如果是用Winxp客戶端認證的話,一定要用MD4(WinNT)方式加密后再放到radiusUserPassword中

另外Windows通過Freeradius認證時,密碼通過MD4(WinNT)的方式加密,所以需要儲存在LDAP中的radiusUserPassword也通過MD4的加密方式保存,這樣才能通過認證。另外,通過ntradping驗證工具是不能驗證MD4是否成功的需要,通過WinXP客戶端進行驗證。

===========================分割線==========================

配置可使用的認證方式:
修改認證方式配置文件,目錄為/usr/local/etc/raddb/sites-available
兩個比較重要的文件
default    #默認配置文件
inner-tunnel   #認證虛擬機配置文件,這個文件我沒做仔細研究,如果有了解的朋友希望能交流一下

#vi default
用戶認證部分只保留了ldap和eap部分,其他的認證用不到我註釋掉了,如果你需要其他的認證去掉相應的註釋部分。
authorize {
        ldap
        eap
}

驗證部分保留了下面的選項,支持MS-CHAP驗證方式,LDAP驗證和EAP驗證
authenticate {
        Auth-Type MS-CHAP {
                mschap
        }
        ldap
        eap
}
authorize    配置用戶信息通過那種方式獲得,LDAP伺服器、Mysql伺服器、Unix系統帳號還是files文件。
authenticate 配置驗證方式,密碼的格式等等
除上述部分外未作任何修改。

===========================分割線==========================
配置eap認證方式:
修改內容如下
#cat eap.conf|grep -v 「#」
eap {
                default_eap_type = peap
                timer_expire     = 60
                ignore_unknown_eap_types = no
                tls {
                        certdir = ${confdir}/certs
                        cadir = ${confdir}/certs
                        private_key_password = cyberstep
                        private_key_file = ${certdir}/server.pem
                        certificate_file = ${certdir}/server.pem
                        CA_file = ${cadir}/ca.pem
                        dh_file = ${certdir}/dh
                        random_file = ${certdir}/random
                        fragment_size = 1024
                        include_length = yes
                        make_cert_command = "${certdir}/bootstrap"
                }
                peap {
                        default_eap_type = mschapv2
                }
                mschapv2 {
                }
        }
主要修改部分為交eap的默認認證方式改為peap,原為MD5,另外添加對tls的支持,希望客戶端和Freeradius通信時採用證書加密。另外將peap默認認證方式改為mschapv2。

Freeradius生成證書
Freeradius2.0.5含有證書製作腳本,只要OpenSSL的路徑正確,Freeradius可以自己製作證書,不過需要修改一下相關的信息,文件在/usr/local/etc/raddb/certs目錄下,需要修改的文件為ca.cnf server.cnf client.cnf
#more ca.cnf
default_days            = 3650
default_crl_days        = 3650

countryName             = JP
stateOrProvinceName     = Tokyo
localityName            = Shibuya
organizationName        = Yepn Inc.
emailAddress            = zhou@yepn.net
commonName              = "yepn Certificate Authority"

其中比較重要的是這幾部分,days問題你也希望你的證書只能用一個月,或是一年的時間,相信網管都不喜歡這樣,所以我把時間設的長一點改成了10年。下面的certificate_authority是你證書的相關信息這個是方便查詢證書的出處,不清楚的地方請找OpenSSL的資料看一下,另外在cert文件夾中有Makefile文件,我也小修改了一下,不知道為什麼前面對於ca.cnf日期的修改在cn.cnf中不生效,所以我只好把命令行那邊加上一個-days 3650
修改後如下
#more Makefile
openssl req -new -x509 -days 3650 -keyout ca.key -out ca.pem -config ./ca.cnf

因為OpenSSL自己也不是特別明白,所以沒辦法講的更細了,希望明白的朋友指點一下。

這樣生成后的ca.der證書可以導入到Winxp中。

到此為止Freeradius的配置就完成了,可以通過radiusd –Xf 測試一下radius的配置是否正確。可以通過radtest命令來驗證一下Freeradius能驗證。

===========================分割線==========================
OpenLDAP配置:
因為LDAP中加入了對radius屬性的支持,所以需要修改OpenLDAP配置文件。
複製raiuds.schema文件到openLDAP的schema目錄下
#cp /usr/local/share/doc/freeradius/examples/ openldap.schema /etc/openldap/schema/radius.schema

因為上面剛剛新加的幾個attribute的值在這個標準的radius.schema文件中沒有,所以需要自己定義幾個新的attribute的值
添加內容如下:
attributetype
( 1.3.6.1.4.1.3317.4.3.1.61
NAME 『radiusExtremeSecurityProfile』
DESC 『』
EQUALITY caseIgnoreIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
)
attributetype
( 1.3.6.1.4.1.3317.4.3.1.62
NAME 『radiusExtremeNetloginVlanTag』
DESC 『』
EQUALITY caseIgnoreIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
)
attributetype
( 1.3.6.1.4.1.3317.4.3.1.63
NAME 『radiusExtremeNetloginExtendedVlan』
DESC 『』
EQUALITY caseIgnoreIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
)
attributetype
   ( 1.3.6.1.4.1.3317.4.3.1.66
      NAME 'radiusUserPassword'
      DESC 'radiusUserPassword'
      SUP userPassword
   )
OpenLDAP schema修改:
對於OpenLDAP schema的格式問題不在這裡作更多說明,有很多文章解決如果編寫自己的schema文件請參閱。只在這裡說明一點對於radiusUserPassword部分的定義,我讓radiusUserPassword繼承userPassword的特性,如果需要修改的朋友可以自己改成其他屬性。
最後,別忘記在你的objectclass里添加剛剛加的屬性

objectclass
   ( 1.3.6.1.4.1.3317.4.3.2.1
      NAME 'radiusprofile'
      SUP top AUXILIARY
      DESC ''
      MUST cn
      MAY ( radiusArapFeatures $ radiusArapSecurity $ radiusArapZoneAccess $
            radiusAuthType $ radiusCallbackId $ radiusCallbackNumber $
            radiusCalledStationId $ radiusCallingStationId $ radiusClass $
            radiusClientIPAddress $ radiusFilterId $ radiusFramedAppleTalkLink $
            radiusFramedAppleTalkNetwork $ radiusFramedAppleTalkZone $
            radiusFramedCompression $ radiusFramedIPAddress $
            radiusFramedIPNetmask $ radiusFramedIPXNetwork $
            radiusFramedMTU $ radiusFramedProtocol $
            radiusCheckItem $ radiusReplyItem $
            radiusFramedRoute $ radiusFramedRouting $ radiusIdleTimeout $
            radiusGroupName $ radiusHint $ radiusHuntgroupName $
            radiusLoginIPHost $ radiusLoginLATGroup $ radiusLoginLATNode $
            radiusLoginLATPort $ radiusLoginLATService $ radiusLoginService $
            radiusLoginTCPPort $ radiusLoginTime $ radiusPasswordRetry $
            radiusPortLimit $ radiusPrompt $ radiusProxyToRealm $
            radiusRealm $ radiusReplicateToRealm $ radiusServiceType $
            radiusSessionTimeout $ radiusStripUserName $
            radiusTerminationAction $ radiusTunnelClientEndpoint $
radiusProfileDn $
            radiusSimultaneousUse $ radiusTunnelAssignmentId $
            radiusTunnelMediumType $ radiusTunnelPassword $
radiusTunnelPreference $
            radiusTunnelPrivateGroupId $ radiusTunnelServerEndpoint $
            radiusTunnelType $ radiusUserCategory $ radiusVSA $
            radiusExpiration $ dialupAccess $ radiusNASIpAddress $
            radiusReplyMessage $ radiusExtremeSecurityProfile $
            radiusExtremeNetloginVlanTag $ radiusExtremeNetloginExtendedVlan $
            radiusUserPassword)
   )

看似很複雜,其實schema的說明很簡單,多找些資料看看會明白很多,我這裡給出了全部的objectclass的值。

radius.schema文件修改後,別忘了修改slapd.conf配置文件載入radius.schema文件,讓OpenLDAP能識別這些新屬性。

加入以下內容
include /etc/openldap/schema/radius.schema

重啟OpenLDAP
#service ldap restart

到這裡OpenLDAP的配置就結束了,可以說Freeradius+OpenLDAP+PEAP認證的配置已經完成了一大部分了,最後就是OpenLDAP數據的添加。

對於批量的OpenLDAP資料庫修改不放在這裡,需要的朋友請到我的Wiki上查找,可以實現大批量的LDAP數據修改。

===========================分割線==========================

一個radius用戶的例子:
#cat zhou.ldif
dn: uid=zhou,ou=Users,dc=yepn,dc=net
add: objectClass
objectClass: radiusprofile
-
add: radiusSessionTimeout
radiusSessionTimeout: 43200
-
add: radiusTunnelType
radiusTunnelType: VLAN
-
add: radiusTunnelMediumType
radiusTunnelMediumType: IEEE-802
-
add: radiusTunnelPrivateGroupId
radiusTunnelPrivateGroupId: 160
-
add: radiusTerminationAction
radiusTerminationAction: RADIUS-Request
-
add: radiusExtremeSecurityProfile
-
add: radiusUserPassword
radiusUserPassword:  178DEACBFD994B3A6A67F49F420DB96A

格式要與我上面的相同,如果不一樣的話不能通過ldapmodify方式導入

#ldapmodify –x –D 「cn=root,dc=yepn,dc=net」 –w password –f zhou.ldif

把修改後的數據導入到LDAP中
#ldapsearch –x uid=zhou   
我的LDAP支持匿名查詢

===========================分割線==========================
以下為完整的zhou用戶信息
# extended LDIF
#
# LDAPv3
# base <> with scope subtree
# filter: uid=zhou
# requesting: ALL
#

# zhou, Users, yepn,net
dn: uid=zhou,ou=Users,dc=yepn,dc=com
sn: zhou
givenName: zhou
gecos: System User
sambaLogonTime: 0
sambaLogoffTime: 2147483647
displayName: zhou
sambaSID: S-1-5-21-1153389650-4125104348-4025214935-3060
sambaPrimaryGroupSID: S-1-5-21-1153389650-4125104348-4025214935-2001
sambaLogonScript: logon.bat
sambaProfilePath: \\PDC-SRV\profiles\zhou
sambaHomePath: \\PDC-SRV\zhou
sambaHomeDrive: H:
sambaPasswordHistory: 00000000000000000000000000000000000000000000000000000000
00000000
mail: zhou@yepn.com
shadowMax: 45
uid: zhou
cn: zhou
homeDirectory: /home/zhou
uidNumber: 1030
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
objectClass: sambaSamAccount
objectClass: radiusprofile
gidNumber: 500
shadowLastChange: 14027
loginShell: /bin/bash
radiusSessionTimeout: 43200
radiusTunnelType: VLAN
radiusTunnelMediumType: IEEE-802
radiusTerminationAction: RADIUS-Request
sambaDomainName: YEPN
radiusTunnelPrivateGroupId: 310
sambaAcctFlags:
sambaLMPassword: 44EFCE164AB921CAAAD3B435B51404EE
sambaNTPassword: 32ED87BDB5FDC5E9CBA88547376818D4
sambaPwdLastSet: 1216031836
radiusUserPassword: 3FA45A060BD2693AE4C05B601D05CA0C
userPassword:: e0NSWVBUfSQxJGNFb0N5Z2JqJHpnSXdkUmpaUzl1MkdVR0hsZ2s3YTE=

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

需要說明的一點,關於radiusUserPassword密碼為000000,通過mkntpwd加密成MD4(WinNT)格式的密碼放到LDAP中,修改密碼時也不能直接修改,需要通過mkntpwd生成新密碼后再添加到LDAP中。
mkntpwd可以在SF.net的網站上下載
#wget http://nchc.dl.sourceforge.net/sourceforge/ldaputils/mkntpwd.tar.gz
#mkdir mkntpwd
#tar –zxvf mkntpwd.tar.gz –C mkntpwd
#cd mkntpwd
#make
#./mkntpwd –N password
8846F7EAEE8FB117AD06BDD830B7586C

生成密碼MD4格式密碼

Summit X450的配置
#configure radius netlogin primary server 172.31.7.7 1812 client-ip 172.16.0.1 vr VR-Default
#configure radius netlogin primary shared-secret testing123

Summit交換機因為我也了解不多,所以沒辦法做更多的說明。

===========================分割線==========================

客戶端配置:
修改WinXP客戶端配置,網路屬性中如下圖修改。我的系統是日文的所以找來了一份英文的圖片,按下圖修改就OK了。

這裡貼圖比較麻煩~需要的朋友請下載我做好的PDF文檔

這裡沒有使用CA證書,先測試一下能不能通過認證。

需要修改Select Authentication Method的Configure選項,把Automatically use my Windows logon name and password這裡去掉。

祝你好運,希望能一次通過認證。

Freeradius+OpenLDAP+PEAP_Authenticate 點擊下載

[ 本帖最後由 gavinzhm 於 2008-7-17 11:45 編輯 ]
《解決方案》

挺不錯的.支持一下.
《解決方案》

恩,是不錯,最近正想試試freeradius呢
《解決方案》

這個要贊一下,收藏了,感謝樓主忠於分享的GPL精神!
《解決方案》

lz不錯:mrgreen:
《解決方案》

看帖回帖是一種美德!感謝樓主的分享!
《解決方案》

好東西,謝謝樓主分享
《解決方案》

謝謝樓主!!學習了,不過對ldap還是不太熟悉啊!需要學習啊!
《解決方案》

一直覺得radius作複雜的辦公網路管理是個比較好的選擇,頂一下!
《解決方案》

感謝gavin,本人之前的PPTP通過Radius驗證LDAP帳號,老是提示Told to do MS-CHAPv2 for xxx with NT-Password,看完此帖才明白MS-CHAP-V2使用MD4密碼,而userPassword不支持MD4密碼,故參照作者,在inetOrgPerson對象類中添加了屬性radiusUserPassword,並使用mkntpwd創建MD4密碼保存在此欄位中,然後在ldap.attrmap中添加checkItem       NT-Password   radiusUserPassword,測試成功,感謝gavin~~

[火星人 ] Freeradius+OpenLDAP+PEAP認證已經有2527次圍觀

http://coctec.com/docs/service/show-post-11198.html