<?xml version="1.0" encoding="windows-1252"?>
<node id="1006916" title="Using Authen::Radius with LDAP: Password being encrypted or corrupted" created="2012-12-03 12:15:07" updated="2012-12-03 12:15:07">
<type id="115">
perlquestion</type>
<author id="1006911">
serafina</author>
<data>
<field name="doctext">
&lt;p&gt;Hello, all! I'm here for a bit of help using Authen::Radius to authenticate against RADIUS with LDAP in the backend. My problem is that RADIUS is receiving a packet from Authen::Radius with the password encrypted or corrupted, so the user is not authenticated. The password needs to be in plaintext.  radtest is able to authenticate successfully.&lt;/p&gt;

&lt;code&gt;#!/usr/bin/perl -w

# radtest username "ldappassword" localhost 2 testing123
use strict;
use Authen::Radius;

my $r = new Authen::Radius(
	Host =&gt; 'localhost',
	Secret =&gt; 'radiuspassword',
	Debug =&gt; 1
);

$r-&gt;load_dictionary('/etc/freeradius/dictionary');
#$r-&gt;check_pwd('username', 'ldappassword'); # also fails
$r-&gt;add_attributes (
	{ Name =&gt; 'User-Name', Value =&gt; 'username' },
	{ Name =&gt; 'NAS-IP-Address', Value =&gt; '127.0.0.1' },
	{ Name =&gt; 'User-Password', Value =&gt; 'ldappassword' },
	{ Name =&gt; 'NAS-Port', Value =&gt; '2' },
);
$r-&gt;send_packet(ACCESS_REQUEST) || print "send_packet failed\n";
my $type = $r-&gt;recv_packet(1);
if (!$type &amp;&amp; $r-&gt;get_error() eq 'EBADAUTH') {
		print "Authentication failed\n";
		exit();
}
print "server response type = $type\n";
&lt;/code&gt;

&lt;p&gt;The output of this script is "Authentication failed." As indicated above, radtest is able to authenticate and prints the password in plain text in the log. However, with Authen::Radius, the log contains (with jibberish replacing each instance of "#65533;" here):&lt;/p&gt;
&lt;code&gt;rad_recv: Access-Request packet from host 127.0.0.1 port 58912, id=203, length=50
	User-Name = "username"
	User-Password = "=\337R\3361\001&amp;#1575;.!\353\346\352\010&amp;#1835;"
	NAS-IP-Address = 127.0.0.1
*snip*
[ldap] login attempt by "username" with password "=&amp;#65533;R&amp;#65533;1?&amp;#1575;.!&amp;#65533;&amp;#65533;&amp;#65533;?&amp;#1835;"
[ldap] user DN: uid=username,ou=People,dc=example,dc=com
  [ldap] (re)connect to localhost:389, authentication 1
  [ldap] bind as uid=username,ou=People,dc=example,dc=com/=&amp;#65533;R&amp;#65533;1?&amp;#1575;.!&amp;#65533;&amp;#65533;&amp;#65533;?&amp;#1835; to localhost:389
  [ldap] waiting for bind result ...
  [ldap] Bind failed with invalid credentials
++[ldap] returns reject
Failed to authenticate the user.
  WARNING: Unprintable characters in the password.  Double-check the shared secret on the server and the NAS!
&lt;/code&gt;
&lt;p&gt;When using radtest, log looks like this:&lt;/p&gt;
&lt;code&gt;rad_recv: Access-Request packet from host 127.0.0.1 port 47900, id=129, length=74
	User-Name = "username"
	User-Password = "ldappassword"
	NAS-IP-Address = 127.0.0.1
	NAS-Port = 2
	Message-Authenticator = 0x935a295ea594eea2237c17b4cdb74a5e
&lt;/code&gt;
&lt;p&gt;How can I make Authen::Radius send the request like this so that it will get authenticated correctly?&lt;/p&gt;</field>
</data>
</node>
