pjdavis/radiustar — Issue #5: Passwords longer than 16 characters are not en/decoded properly
Author: charl
Created: 2011-12-20 22:33:20+00:00
State: open

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