`
fanrey
  • 浏览: 251916 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

radius协议(转载)

    博客分类:
  • AAA
 
阅读更多
转自: http://blog.csdn.net/zhaori/article/details/554004

1、 RADIUS协议的包格式
RADIUS数据包是被封装在UDP的数据域中的。

RADIUS的包数据格式如下所示,各域(Fields)的先后次序是从左到右。

    0                   1                   2                   3

    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |     Code      |  Identifier   |            Length             |

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |                                                               |

   |                         Authenticator                         |

   |                                                               |

   |                                                               |

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |  Attributes ...

   +-+-+-+-+-+-+-+-+-+-+-+-+-

Code





Code域有一个字节长度,用来标示RADIUS通信包的类型。当收到一个非法的包类型,将被丢弃。

Code可代表如下类型(十进制):

1       Access-Request

        2       Access-Accept

        3       Access-Reject

        4       Accounting-Request

        5       Accounting-Response

       11       Access-Challenge

       12       Status-Server (experimental)

       13       Status-Client (experimental)

      255       Reserved

Identifier





Identifier有一个字节长度,用来匹配RADIUS的请求和应答。

Length





Length有2个字节长度,它标明整个RADIUS数据包的长度,包括:Code, Identifier, Length, Authenticator 和Attributes。Length的最小值为20,最大值为4096。RADIUS的应用程序将丢弃小于20的包;对大于4096的包将把超出部分丢弃,只处理有效部分(超出部分被认为是填充域)。

Authenticator





Authenticator域有16个字节。这个域用来完成安全性检查,所以是非常重要的。Authenticator的作用有两个,一个是验证从RADIUS服务器返回的应答;另一个是为对口令部分加密算法做参数。

有两种Authenticator:

1)          Request Authenticator

出现在通信包“Access-Request”中,是长度为16字节的随机二进制串。格式为:

    0                   1                   2                   3

    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |     Code      |  Identifier   |            Length             |

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |                                                               |

   |                     Request Authenticator                     |

   |                                                               |

   |                                                               |

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |  Attributes ...

   +-+-+-+-+-+-+-+-+-+-+-+-+-

RADIUS协议建议Request Authenticator应该是不可预测和在整个生命期内是唯一的。这是为了防止攻击者伪装成通信的一方的措施。RADIUS请求方(NAS)用Request Authenticatior加密用户密码;相反,RADIUS服务器则用它来对用户密码,并生成应答包的Authenticator(Response Authenticatior)。如果Request Authenticator不是唯一的话,别人将可以伪造RADIUS服务器的应答,因为此时Response Authenticator的加密算法有相同的参数(详见下文)。

用户密码部分的加密算法是:

enpassword = password XOR MD5(secret + Request Authenticator)

2)          Response Authenticator

出现在通信包“Access-Accept”、“Access-Reject”、“Access-Challenge”和“Accounting-Response”中。格式为:

    0                   1                   2                   3

    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |     Code      |  Identifier   |            Length             |

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |                                                               |

   |                     Response Authenticator                    |

   |                                                               |

   |                                                               |

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   |  Attributes ...

   +-+-+-+-+-+-+-+-+-+-+-+-+-

Response Authenticator产生的算法:

Response Authenticator =

MD5(Code + Id + Length + Req-Authenticator + Attributes + Secret)

Attributes





RADIUS通信包装载了验证、授权、统计等信息。这些信息都是用Attribute数据结构来表示的。Attributes域包含了0到数个属性描述(Attribute)。

2、 Attribute格式
Attributes域包含了0到数个属性描述(Attribute)。Attribute的基本格式在请求包和应答包中是一样的,各域(Fields)的先后次序是从左到右。

    0                   1                   2

    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

   |     Type      |    Length     |  Value ...

   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

Type





Type域长度为一个字节。数值192-223被保留作实验使用;数值224-240被保留作特殊的应用;数值241-255被不建议使用。RADIUS服务器和客户机将可能忽略未知的Type值。被定义的值如下所列:




     #      attribute                               value-type





     -------  ---------------------------      -----------------





          1      User-Name                  string

          2      User-Password              string

          3      CHAP-Password              string

          4      NAS-IP-Address             address

          5      NAS-Port                   string

          6      Service-Type               integer

          7      Framed-Protocol            integer

          8      Framed-IP-Address          address

          9      Framed-IP-Netmask          address

         10      Framed-Routing             integer

         11      Filter-Id                  string

         12      Framed-MTU                 integer

         13      Framed-Compression         integer

         14      Login-IP-Host              address

         15      Login-Service              integer

         16      Login-TCP-Port             integer

         17      (unassigned)

         18      Reply-Message              string

         19      Callback-Number            string

         20      Callback-Id                string

         21      (unassigned)

         22      Framed-Route               integer

         23      Framed-IPX-Network         integer

         24      State                      string

         25      Class                      string

         26      Vendor-Specific            string

         27      Session-Timeout            integer

         28      Idle-Timeout               integer

         29      Termination-Action         integer

         30      Called-Station-Id          string

         31      Calling-Station-Id         string

         32      NAS-Identifier             string

         33      Proxy-State                string

         34      Login-LAT-Service          string

         35      Login-LAT-Node             string

         36      Login-LAT-Group            string

         37      Framed-AppleTalk-Link      integer

         38      Framed-AppleTalk-Network   integer

         39      Framed-AppleTalk-Zone      string

  40      Acct-Status-Type           integer

         41      Acct-Delay-Time            integer

         42      Acct-Input-Octets          integer

         43      Acct-Output-Octets         integer

         44      Acct-Session-Id            string

         45      Acct-Authentic             integer

         46      Acct-Session-Time          integer

         47      Acct-Input-Packets         integer

         48      Acct-Output-Packets        integer

         49      Acct-Terminate-Cause       integer

         50      Acct-Multi-Session-Id      string

51                     Acct-Link-Count             integer




         52-59   (unassigned)        

         60      CHAP-Challenge             string

         61      NAS-Port-Type              integer

         62      Port-Limit                 integer

         63      Login-LAT-Port             string








         60      CHAP-Challenge             string












         61      NAS-Port-Type              integer












         62      Port-Limit                 integer












         63      Login-LAT-Port             string












70     ARAP-Password                string






71     ARAP-Features                string






72     ARAP-Zone-Access             integer






73     ARAP-Security                integer






74     ARAP-Security-Data           string






75     Password-Retry               integer






76     Prompt                       integer






77     Connect-Info                 string






78     Configuration-Token          string






79     EAP-Message                  string






80     Message-Authenticator        string # 18 octets






84     ARAP-Challenge-Response      string # 10 octets






85     Acct-Interim-Interval        integer






87     NAS-Port-Id                  string






88     Framed-Pool                  string





Length





Length域长度为一个字节,标示Attribute的总长度,包括Type、Length和Value域。




Value





Value域长度可以是0到若干个字节,它包含了Attribte规定的值。Value的格式和长度由Type和Length域来决定。




Value有如下四种数据格式:




      string    0-253 octets,does not require termination by an ASCII null.








      address   32 bit value, most significant octet first.








      integer   32 bit value, most significant octet first.








      time      32 bit value, most significant octet first -- seconds

                since 00:00:00 GMT, January 1, 1970.  The standard

                Attributes do not use this data type but it is presented

                here for possible use within Vendor-Specific attributes.








3、 Attribute在验证通信包中的要求
下列表格显示各属性(Attribute)在RADIUS验证通信包中的要求:

   Request   Accept   Reject   Challenge   #    Attribute

   1         0        0        0            1   User-Name

   0-1       0        0        0            2   User-Password [注 1]

   0-1       0        0        0            3   CHAP-Password [注 1]

   0-1       0        0        0            4   NAS-IP-Address

   0-1       0        0        0            5   NAS-Port

   0-1       0-1      0        0            6   Service-Type

   0-1       0-1      0        0            7   Framed-Protocol

   0-1       0-1      0        0            8   Framed-IP-Address

   0-1       0-1      0        0            9   Framed-IP-Netmask

   0         0-1      0        0           10   Framed-Routing

   0         0+       0        0           11   Filter-Id

   0         0-1      0        0           12   Framed-MTU

   0+        0+       0        0           13   Framed-Compression

   0+        0+       0        0           14   Login-IP-Host

   0         0-1      0        0           15   Login-Service

   0         0-1      0        0           16   Login-TCP-Port

   0         0+       0+       0+          18   Reply-Message

   0-1       0-1      0        0           19   Callback-Number

   0         0-1      0        0           20   Callback-Id

   0         0+       0        0           22   Framed-Route

   0         0-1      0        0           23   Framed-IPX-Network

   0-1       0-1      0        0-1         24   State

   0         0+       0        0           25   Class

   0+        0+       0        0+          26   Vendor-Specific

   0         0-1      0        0-1         27   Session-Timeout

   0         0-1      0        0-1         28   Idle-Timeout

   0         0-1      0        0           29   Termination-Action

   0-1       0        0        0           30   Called-Station-Id

   0-1       0        0        0           31   Calling-Station-Id

   0-1       0        0        0           32   NAS-Identifier

   0+        0+       0+       0+          33   Proxy-State

   0-1       0-1      0        0           34   Login-LAT-Service

   0-1       0-1      0        0           35   Login-LAT-Node

   0-1       0-1      0        0           36   Login-LAT-Group

   0         0-1      0        0           37   Framed-AppleTalk-Link

   0         0+       0        0           38   Framed-AppleTalk-Network

   0         0-1      0        0           39   Framed-AppleTalk-Zone

   0-1       0        0        0           60   CHAP-Challenge

   0-1       0        0        0           61   NAS-Port-Type

   0-1       0-1      0        0           62   Port-Limit

   0-1       0-1      0        0           63   Login-LAT-Port

注1:在Access-Request中,只能且必须包含User-Password与CHAP-Password两者其中一个。

上表中数字代表的意义是:




    0     这个属性必须不出现在通信包中。

    0+    此属性可能有0或多个出现在通信包中。

    0-1   此属性只能有0个或一个出现在通信包中。

    1     此属性必须有一个出现在通信包中。




4、 Attribute在统计通信包中的要求
RADIUS协议规范中,在Account-Response通信包不应该有任何属性(Attribute)。下列表格显示各属性在RADIUS统计通信包Accounting-Request中的要求:








                      #     Attribute

                      0-1   User-Name

                      0     User-Password

                      0     CHAP-Password

                      0-1   NAS-IP-Address [注 1]

                      0-1   NAS-Port

                      0-1   Service-Type

                      0-1   Framed-Protocol

                      0-1   Framed-IP-Address

                      0-1   Framed-IP-Netmask

                      0-1   Framed-Routing

                      0+    Filter-Id

                      0-1   Framed-MTU

                      0+    Framed-Compression

                      0+    Login-IP-Host

                      0-1   Login-Service

                      0-1   Login-TCP-Port

                      0     Reply-Message

                      0-1   Callback-Number

                      0-1   Callback-Id

                      0+    Framed-Route

                      0-1   Framed-IPX-Network

                      0     State

                      0+    Class

                      0+    Vendor-Specific

                      0-1   Session-Timeout

                      0-1   Idle-Timeout

                      0-1   Termination-Action

                      0-1   Called-Station-Id

                      0-1   Calling-Station-Id

                      0-1   NAS-Identifier [注 1]

                      0+    Proxy-State

                      0-1   Login-LAT-Service

                      0-1   Login-LAT-Node

                      0-1   Login-LAT-Group

                      0-1   Framed-AppleTalk-Link

                      0-1   Framed-AppleTalk-Network

                      0-1   Framed-AppleTalk-Zone

                      1     Acct-Status-Type

                      0-1   Acct-Delay-Time

                      0-1   Acct-Input-Octets

                      0-1   Acct-Output-Octets

                      1     Acct-Session-Id

                      0-1   Acct-Authentic

                      0-1   Acct-Session-Time

                      0-1   Acct-Input-Packets

                      0-1   Acct-Output-Packets

                      0-1   Acct-Terminate-Cause

                      0+    Acct-Multi-Session-Id

                      0+    Acct-Link-Count

                      0     CHAP-Challenge

                      0-1   NAS-Port-Type

                      0-1   Port-Limit

                      0-1   Login-LAT-Port

注 1:在Accounting-Request通信包中,必须包含NAS-IP-Address或NAS-Identifer中的一个,也可以同时包含两者,但不建议。

上表中数字代表的意义是:




    0     这个属性必须不出现在通信包中。

    0+    此属性可能有0或多个出现在通信包中。

    0-1   此属性只能有0个或一个出现在通信包中。

    1     此属性必须有一个出现在通信包中。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics