Git Product home page Git Product logo

radiustar's Introduction

RADIUSTAR

Pretend this is ascii art of the “the more you know” star thing —=====*

by pjdavis github.com/pjdavis/radiustar

DESCRIPTION:

Ruby Radius Library

FEATURES

  • Import your own radius dictionaries

  • Authentication

  • Accounting

SYNOPSIS:

require 'rubygems'
require 'radiustar'

# Load dictionaries from freeradius directory
# NOTICE: here the Dictionary.new() only accept a parameter of "folder name" but not the dictionary file
dict = Radiustar::Dictionary.new('/usr/share/freeradius/')

# Lets get authenticated
auth_custom_attr = {
  'Framed-Address'  => '127.0.0.1',
  'NAS-Port'        => 0,
  'NAS-Port-Type'   => 'Ethernet'
}

req = Radiustar::Request.new('127.0.0.1', { :dict => dict })
reply = req.authenticate('John Doe', 'hello', 'testing123', auth_custom_attr)

if reply[:code] == 'Access-Accept'
  req = Radiustar::Request.new('127.0.0.1:1813', { :dict => dict })

  acct_custom_attr = {
    'Framed-Address'  => '127.0.0.1',
    'NAS-Port'        => 0,
    'NAS-Port-Type'   => 'Ethernet',
    'Acct-Session-Time' => 0
  }

  timings = Time.now
  reply = req.accounting_start('John Doe', 'testing123', '123456', acct_custom_attr)

  sleep(rand 5)
  acct_custom_attr['Acct-Session-Time'] = Time.now - timings
  reply = req.accounting_update('John Doe', 'testing123', '123456', acct_custom_attr)

  sleep(rand 5)
  acct_custom_attr['Acct-Session-Time'] = Time.now - timings
  reply = req.accounting_stop('John Doe', 'testing123', '123456', acct_custom_attr)

end

REQUIREMENTS:

  • Ruby 1.8

INSTALL:

gem install radiustar

Thanks:

Thanks to everyone who has contributed to this project. Without your help and support, this would not have been possible.

  • charl

  • Mark Bryars

  • jamesotron

  • dguerri

  • gderosa

  • mkocher

  • bwlang

  • cbascom

  • Paulche

LICENSE:

Copyright © 2010 [PJ Davis], released under the CC0 1.0 Universal license.

radiustar's People

Contributors

bwlang avatar cbascom avatar charl avatar darkskiez avatar dguerri avatar gderosa avatar jimsynz avatar mkocher avatar pbrit avatar pjdavis avatar youkugems avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

radiustar's Issues

feature: Radiustar::Dictionary#read_xml

Being able to interpret "dictionary" files like this would be really cool :

http://www.iana.org/assignments/radius-types/radius-types.xml

mainly because these data represent the official standard from IANA.

Well, there is actually a plain text format from the IANA website, but it's very different from FreeRADIUS-style dictionary files that Dictionary#read is currently able to parse. Here it is:

http://www.iana.org/assignments/radius-types/radius-types.txt

Mixed-case attribute/value dictionary references cause fatal error

I'm using radiustar with the dictionaries shipped with FreeRADIUS Server.

It crashes on startup:

radiustar-0.0.8/lib/radiustar/dictionary.rb:119:in `set_value': undefined method `add_value' for nil:NilClass (NoMethodError)

I've traced this back to case-insensitive attribute naming in the dictionaries.

For example, the first instance that throws this error is VALUE 3GPP-RAT-TYPE GERAN 2 defined in dictionary.3gpp. The atttrbute is actually defined using different case: ATTRIBUTE 3GPP-RAT-Type 21 byte. For clarity, as clipped from dictionary.3gpp:

ATTRIBUTE 3GPP-RAT-Type       21  byte

VALUE 3GPP-RAT-Type     UTRAN     1
VALUE 3GPP-RAT-TYPE     GERAN     2

By fixing the attribute names to always use the same case, I get around the error in radiustar. And taking a quick look at the code it appears radiustar is case-sensitive when it comes to dictionary references.

Before diving in to "fix" this (which I'm happy to do) I'd like some feedback and a sanity check:

  • am I using radiustar correctly? (this is my first time)
  • are dictionaries supposed to be case-sensitive? (i.e. is this a FreeRADIUS bug in their dictionaries and not a radiustar problem)

BlastRADIUS affects radiustar

See blastradius.fail for details. In short:

  • RADIUS Client should send a Message-Authenticator Attribute in all their Access-Requests
  • RADIUS Clients should check the Message-Authenticator Attribute in Access-Accept/-Reject/-Challenge and should have the option to require the presence of the Message-Authenticator attribute in responses from the RADIUS server

Support on ruby2?

Will radius start work on Ruby2? i'm testing it and having issues, so just wanted to figure out if I'm the only one...

NoMethodError: undefined method `key' for #<Hash:0xb73c2be0>

When using radiustar-0.0.5 I get the following error:

NoMethodError: undefined method key' for #<Hash:0xb73c2be0> /usr/lib/ruby/gems/1.8/gems/radiustar-0.0.5/lib/radiustar/packet.rb:148:inunpack'
/usr/lib/ruby/gems/1.8/gems/radiustar-0.0.5/lib/radiustar/packet.rb:30:in initialize' /usr/lib/ruby/gems/1.8/gems/radiustar-0.0.5/lib/radiustar/request.rb:139:innew'
/usr/lib/ruby/gems/1.8/gems/radiustar-0.0.5/lib/radiustar/request.rb:139:in recv_packet' /usr/lib/ruby/gems/1.8/gems/radiustar-0.0.5/lib/radiustar/request.rb:39:inauthenticate'

New release on rubygems.org

This gem hasn't had a release since 2012 on rubygems.org. I need to use the GitHub version in my Gemfiles, which isn't too bad, but I'd like to make radiustar a dependency in another gem, and the gemspec format doesn't allow github constraints, meaning the end-user will have to manually add the :github => 'pjdavis/radiustar' in the Gemfile, which is less than ideal.

Would it be possible to cut a new release?

Passwords longer than 16 characters are not en/decoded properly

Here's a simple script illustrating the issue:

require 'rubygems'
require 'radiustar'

Monkey-patch to allow access to private decode

module Radiustar
class Packet
def decode_attribute(name, secret)
decode @attributes[name], secret
end
end
end

secret = 's3cr3t'
username = 'radiustar'
password = '1234567890123456' # 16 character password

dict = Radiustar::Dictionary.default
packet = Radiustar::Packet.new(dict, Process.pid & 0xff)
packet.code = 'Access-Request'
packet.gen_authenticator
packet.set_attribute('User-Name', username)
packet.set_attribute('NAS-IP-Address', '127.0.0.1')
packet.set_encoded_attribute('User-Password', password, secret)
packet.pack
packet.increment_id
puts "Could decode username? #{packet.attribute("User-Name") == username}"
puts "Could decode password? #{packet.decode_attribute("User-Password", secret) == password}"

password = '12345678901234567' # > 16 character password
dict = Radiustar::Dictionary.default
packet = Radiustar::Packet.new(dict, Process.pid & 0xff)
packet.code = 'Access-Request'
packet.gen_authenticator
packet.set_attribute('User-Name', username)
packet.set_attribute('NAS-IP-Address', '127.0.0.1')
packet.set_encoded_attribute('User-Password', password, secret)
packet.pack
packet.increment_id
puts "Could decode username? #{packet.attribute("User-Name") == username}"
puts "Could decode password? #{packet.decode_attribute("User-Password", secret) == password}" # FAIL

Reading vendor specific attributes is bugged

When reading a vendor specific attribute, if there is at least one more attribute in the response which appears after the vendor specific attribute, then the extracted value is wrong as it also contains the first two bytes off the next attribute.

I believe this is a problem in packet.rb with the following line:
vid, attribute_type, attribute_value = attribute_data.unpack("xxNCxa#{length-6}")

Reading the unpack documentation, the values in the String passed into unpack mean:
x - Skip a byte
N - 32 bit unsigned integer
C - 8 bit unsigned integer
a - Arbitrary String

This means the unpack statement skips 8 bytes, then reads in the next (length - 6) bytes as the String (so 2 bytes off the next attribute).

I think the line should be:
vid, attribute_type, attribute_value = attribute_data.unpack("xxNCxa#{length-8}")

I'm at work and have never contributed to a public repository before - which is why I'm raising this as an issue with the solution in it.

Thanks for the gem - we use it and it's very useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.