retailnext/node-radius

How to pass custom attributes ?

sizovilya opened this issue · 4 comments

Hi guys. I working with radius authentication and billing on jerasoft platform. Docs link - https://docs.jerasoft.net/display/IM/JeraSoft+VCS%3A+RADIUS+Integration

I need to pass custom no vendor-specific attributes: request-type, src-gw-ip, src-gw-name.

If i do it like this:

    const packet = radius.encode({  
          code: 'Access-Request',  
          secret: 'my secret',  
          attributes: [  
           ['request-type', 'user'],  
           ['src-gw-name', 'my-gw'],  
           ['gw-ip', '127.0.0.1'],  
          ],  
        })  

I get an error:

Error: encode: invalid attributes - must give Buffer for unknown attribute 'request-type'

If i do it like this:

        const packet = radius.encode({
          code: 'Access-Request',
          secret: 'my secret',
          attributes: [
           ['request-type', Buffer.from('user')],
           ['src-gw-name', Buffer.from('my-gw')],
           ['gw-ip', Buffer.from('127.0.0.1')],
          ],
        })

I have no errors, but i have tcp-dump with Unknown-Attribute instead of fields

User Datagram Protocol, Src Port: 9984, Dst Port: 1812
RADIUS Protocol
Code: Access-Request (1)
Packet identifier: 0x88 (136)
Length: 44
Authenticator: 3390678678fccvcvbcvb62770fedfgdfg806fc
Attribute Value Pairs
AVP: l=6 t=Unknown-Attribute(0): 75736572
AVP: l=7 t=Unknown-Attribute(0): 6d792d6777
AVP: l=11 t=Unknown-Attribute(0): 3132372e302e302e31

Please help me. What i did wrong?

The radius protocol (rfc2865) requires that all custom attributes have a vendor-id. I'm a little surprised that your second example didn't also generate an error.

If you want to use a Buffer you should use the uint8 attribute type value as the key not a string (see rfc2865 section 5 for details).

I don't think this is actually what you want to do though.

The attributes you are trying to set 'request-type', 'src-gw-name' and 'gw-ip' are not standard radius attributes, so I would guess that they are vendor specific attributes. If they are, the easiest thing would be to get a radius dictionary file and load that. Then you can use the attribute names.

@psanford Thank you for the response!
I found out that these attributes can be sent like Cisco-AVPair "key=value" . Is it possible now ?

I found solution. Need just create right dictionary file with BEGIN VENDOR/END VENDOR syntax.
Example here - https://gist.github.com/sizovilya/2e9c14eb76ce09da5aaf044aacafbae6

Next create packet like this:

        const packet = radius.encode({
          code: 'Access-Request',
          secret: 'very secret',
          attributes: [
            ['Vendor-Specific', 9, [['Cisco-AVPair', 'request-type=user']]],
            ['Vendor-Specific', 9, [['Cisco-AVPair', 'src-gw-ip=127.0.0.1']]],
            ['Vendor-Specific', 9, [['Cisco-AVPair', 'src-gw-name=user']]],
            ['Vendor-Specific', 9, [['Cisco-AVPair', 'h323-conf-id=i am any hash']]],
            ['Vendor-Specific', 9, [['Cisco-AVPair', 'h323-call-id=i am any hash 2']]],
            ['Vendor-Specific', 9, [['Cisco-AVPair', 'Calling-Station_id=123456789']]],
            ['Vendor-Specific', 9, [['Cisco-AVPair', 'Called-Station_id=987654321']]],
          ],
        })

After, all should works fine.

@psanford thank you.

Great! I'm glad you got it working.