retailnext / node-radius

Node.js RADIUS library for packet encoding and decoding.
Other
200 stars 60 forks source link

At what condition I get the 'Vendor-Specific' attributes value in the decoded response #50

Closed nareshbandameedi closed 5 years ago

nareshbandameedi commented 5 years ago

Hi, I am able to load the dictionary with vendor specific attributes in radius server. I can receive the vendor specific attributes in a response in the form of "raw_attributes" but not as a value of attributes object with 'Vendor-Specific' key

server-encoding response:

var response = radius.encode_response({ packet: packet, code: code, secret: secret, attributes: [ // ['NAS-IP-Addess', '10.5.5.5'], ['User-Name', 'rajiv'], ['User-Password', 'Ltrx12345'], ['Vendor-Specific', 14988, [['Mikrotik-Wireless-PSK', 'shiva']]] ] });

client-decoded packet data:

{ code: 'Access-Accept', identifier: 0, length: 58, authenticator: <Buffer eb c1 e2 81 72 0a bc db 20 ce 18 c6 24 ef 12 9e>, attributes: { 'User-Name': 'rajiv', 'User-Password': 'A�\u0013��t7��\u001c���F�9', 'Vendor-Specific': {} }, raw_attributes: [ [ 1, <Buffer 72 61 6a 69 76> ], [ 2, <Buffer 1d 12 74 44 c1 cc 36 e0 e9 7c 32 7f 25 8c 0a e9> ], [ 26, <Buffer 00 00 3a 8c 10 07 73 68 69 76 61> ] ] }

I want to know the exact format of decoded response with 'Vendor-Specific' attributes. How do I form the server encoding response to get the values as 'Vendor-Specific' attributes in the decoded response(when will be 'Venodor-Specific' attribute value get fulfilled). Please guide I am unable find it out.

psanford commented 5 years ago

Can you provide a minimal executable example that demonstrates the problem? I think it would be as simple as providing the dictionary file and then a script that encodes a packet with the dictionary and then decodes it.

Otherwise you can look at the tests for examples for how to use vendor-specific attributes.

nareshbandameedi commented 5 years ago

@psanford
client.js

var radius = require('radius');
var dgram = require('dgram');
var util = require('util');
var secret = 'MEAZ7iOegPr69lB';
var packet_accepted = {
  code: "Access-Request",
  secret: secret,
  identifier: 0,
  attributes: [
    ['User-Name', 'rajiv'],
    ['User-Password', 'Ltrx12345']
  ]
};
var client = dgram.createSocket("udp4");
client.bind(49011);
client.on('err', function(msg) {
    console.log('error', msg)
});
client.on('message', function(msg, rinfo) {
  var response = radius.decode({packet: msg, secret: secret});
  console.log('decoded response', response);
  var vsa= response['raw_attributes'][2][1];
  console.log(vsa, 'venoder specific attribute', vsa.toString())
});

var encoded = radius.encode(packet_accepted);
client.send(encoded, 0, encoded.length, 1812, "localhost");

server.js

var radius = require('radius');
//loading dictionary file
radius.add_dictionary('vs.dict');
var dgram = require("dgram");

var secret = 'MEAZ7iOegPr69lB';
var server = dgram.createSocket("udp4");

server.on("message", function (msg, rinfo) {
  var code, username, password, packet;
  try {
    packet = radius.decode({packet: msg, secret: secret});
  } catch (e) {
    console.log("Failed to decode radius packet, silently dropping:", e);
    return;
  }

  if (packet.code != 'Access-Request') {
    console.log('unknown packet type: ', packet.code);
    return;
  }

  username = packet.attributes['User-Name'];
  password = packet.attributes['User-Password'];

  console.log(password,'Access-Request for ' + username);

  if (username == 'rajiv' && password == 'Ltrx12345') {
    code = 'Access-Accept';
  } else {
    code = 'Access-Reject';
  }
  //setting up vendor specific attributes
  var response = radius.encode_response({
    packet: packet,
    code: code,
    secret: secret,
    attributes:  [
        ['User-Name', 'rajiv'],
        ['User-Password', 'Ltrx12345'],
        ['Vendor-Specific', 14988, [['Mikrotik-Wireless-PSK', 'shiva']]]
      ]
  });

  console.log('Sending ' + code + ' for user ' + username);
  server.send(response, 0, response.length, rinfo.port, rinfo.address, function(err, bytes) {
    if (err) {
      console.log('Error sending response to ', rinfo);
    }
  });
});

server.on("listening", function () {
  var address = server.address();
  console.log("radius server listening " +
      address.address + ":" + address.port);
});

server.bind(1812);

vs.dict

# MikroTik vendor specific dictionary
# MikroTik Attributes

VENDOR          Mikrotik        14988

BEGIN-VENDOR    Mikrotik

ATTRIBUTE       Mikrotik-Recv-Limit             1   integer
ATTRIBUTE       Mikrotik-Xmit-Limit             2   integer
ATTRIBUTE       Mikrotik-Group                  3   string  
ATTRIBUTE       Mikrotik-Wireless-Forward       4   integer
ATTRIBUTE       Mikrotik-Wireless-Skip-Dot1x    5   integer
ATTRIBUTE       Mikrotik-Wireless-Enc-Algo      6   string
ATTRIBUTE       Mikrotik-Wireless-Enc-Key       7   string
ATTRIBUTE       Mikrotik-Rate-Limit             8   string
ATTRIBUTE       Mikrotik-Realm                  9   string
ATTRIBUTE       Mikrotik-Host-IP                10  ipaddr
ATTRIBUTE       Mikrotik-Mark-Id                11  string
ATTRIBUTE       Mikrotik-Advertise-URL          12  string
ATTRIBUTE       Mikrotik-Advertise-Interval     13  integer
ATTRIBUTE       Mikrotik-Recv-Limit-Gigawords   14  integer
ATTRIBUTE       Mikrotik-Xmit-Limit-Gigawords   15  integer
ATTRIBUTE       Mikrotik-Wireless-PSK           16  string
ATTRIBUTE       Mikrotik-Total-Limit            17  integer
ATTRIBUTE       Mikrotik-Total-Limit-Gigawords  18  integer
ATTRIBUTE       Mikrotik-Address-List           19  string
ATTRIBUTE       Mikrotik-Wireless-MPKey         20  string
ATTRIBUTE       Mikrotik-Wireless-Comment       21  string
ATTRIBUTE       Mikrotik-Delegated-IPv6-Pool    22  string
ATTRIBUTE       Mikrotik_DHCP_Option_Set        23  string
ATTRIBUTE       Mikrotik_DHCP_Option_Param_STR1 24  string
ATTRIBUTE       Mikortik_DHCP_Option_Param_STR2 25  string
ATTRIBUTE       Mikrotik_Wireless_VLANID        26  integer
ATTRIBUTE       Mikrotik_Wireless_VLANIDtype    27  integer
ATTRIBUTE       Mikrotik_Wireless_Minsignal     28  string
ATTRIBUTE       Mikrotik_Wireless_Maxsignal     29  string

# MikroTik Values

VALUE           Mikrotik-Wireless-Enc-Algo            sfwNaresh                0
VALUE           Mikrotik-Wireless-Enc-Algo            40-bit-WEP                     1
VALUE           Mikrotik-Wireless-Enc-Algo            24
VALUE           Mikrotik-Wireless-Enc-Algo            AES-CCM                        3
VALUE           Mikrotik-Wireless-Enc-Algo            TKIP                           4 
VALUE           Mikrotik_Wireless_VLANIDtype          802.1q                         0
VALUE           Mikrotik_Wireless_VLANIDtype          802.1ad    
VALUE           Mikrotik-Group                        setup-private-value   
                     1

END-VENDOR      Mikrotik

client logs are followed as below:

decoder response:

{ code: 'Access-Accept', identifier: 0, length: 58, authenticator: <Buffer 32 dc 73 12 9b 52 d4 78 39 27 dd f7 74 3c da 18>, attributes: { 'User-Name': 'rajiv', 'User-Password': '&OwAx��3�\b+�\u001b\u00193�', 'Vendor-Specific': {} }, raw_attributes: [ [ 1, <Buffer 72 61 6a 69 76> ], [ 2, <Buffer 44 a1 4d 4a 9c a7 0e bb a4 1a 96 81 0e 51 bb e4> ], [ 26, <Buffer 00 00 3a 8c 10 07 73 68 69 76 61> ] ] }

<Buffer 00 00 3a 8c 10 07 73 68 69 76 61> 'venoder specific attribute' '\u0000\u0000:�\u0010\u0007shiva'

muirdm commented 5 years ago

The client needs to load the dictionary file as well.

muirdm commented 5 years ago

Closing. Reopen if issue persists.