I have a database with usernames and passwords that are encrypted using password_hash that are used for several other applications.
I would like to reuse these passwords for authenticating the users using freeradius (for wifi access).
I'm using FreeRADIUS Version 3.0.15, for host x86_64-pc-linux-gnu, built on Jul 28 2017 at 06:41:27 FreeRADIUS Version 3.0.15 on an Ubuntu 16.04 server. The clients are Unifi AP PRO.
I start from a default installation with minimal changes to the config. For testing purposes, I added one user with clear text username and password in users. That user works.
In sites-enabled/default I added in the authorize section
update control {Auth-type := "/usr/bin/php -f /etc/freeradius/php/checkpasswd.php'%{User-Name}' '%{User-Password}'"}
at the very beginning of the authorize section. The relevant part of checkpasswd.php is
//arguments ophalen
$username_radius = $argv[1];
$password_radius = $argv[2];
//wachtwoorden opzoeken in de databank
$query = $conn->prepare('SELECT passwordHash FROM gebruikers WHERE username = :username');
$query->bindParam(':username', $username_radius);
$query->execute();
$row_count = $query->rowCount();
if ($row_count != 1){
echo 'Reject';
}
else {
//is de hash van het radiuswachtwoord gelijk aan de hash in de databank?
$rs = $query->fetchAll();
$passwordHash = $rs[0][0];
if (password_verify($password_radius,$passwordHash)) {
echo 'Accept';
}
else {
echo 'Reject';
}
(sorry for the Dutch comments) Basically it says Accept when password matches and Reject in all other cases.
I understood that I need to use TTLS / PAP to be able to see the password. But the password never ends up on my server. I get the following output with freeradius -X
(0) Received Access-Request Id 18 from 10.1.8.99:55827 to 192.168.2.32:1812 length 157
(0) User-Name = "krog"
(0) NAS-Identifier = "24a43cb081ea"
(0) NAS-Port = 0
(0) Called-Station-Id = "36-A4-3C-B1-81-EA:ritaexam"
(0) Calling-Station-Id = "48-45-20-FB-4B-31"
(0) Framed-MTU = 1400
(0) NAS-Port-Type = Wireless-802.11
(0) Connect-Info = "CONNECT 0Mbps 802.11b"
(0) EAP-Message = 0x02660009016b726f67
(0) Message-Authenticator = 0xfa1433a62a8b77ea794a62ac47f8320d
(0) # Executing section authorize from file /etc/freeradius/sites-enabled/default
(0) authorize {
(0) update control {
(0) EXPAND /usr/bin/php -f /etc/freeradius/php/checkpasswd.php '%{User-Name}' '%{User-Password}'
(0) --> /usr/bin/php -f /etc/freeradius/php/checkpasswd.php 'krog' ''
(0) } # update control = fail
(0) } # authorize = fail
(0) Using Post-Auth-Type Reject
(0) # Executing group from file /etc/freeradius/sites-enabled/default
(0) Post-Auth-Type REJECT {
(0) attr_filter.access_reject: EXPAND %{User-Name}
(0) attr_filter.access_reject: --> krog
(0) attr_filter.access_reject: Matched entry DEFAULT at line 11
(0) [attr_filter.access_reject] = updated
(0) eap: Request was previously rejected, inserting EAP-Failure
(0) eap: Sending EAP Failure (code 4) ID 102 length 4
(0) [eap] = updated
(0) policy remove_reply_message_if_eap {
(0) if (&reply:EAP-Message && &reply:Reply-Message) {
(0) if (&reply:EAP-Message && &reply:Reply-Message) -> FALSE
(0) else {
(0) [noop] = noop
(0) } # else = noop
(0) } # policy remove_reply_message_if_eap = noop
(0) } # Post-Auth-Type REJECT = updated
(0) Delaying response for 1.000000 seconds
Waking up in 0.3 seconds.
Waking up in 0.6 seconds.
(0) Sending delayed response
(0) Sent Access-Reject Id 18 from 192.168.2.32:1812 to 10.1.8.99:55827 length 44
(0) EAP-Message = 0x04660004
(0) Message-Authenticator = 0x00000000000000000000000000000000
As you can see, the User-Password is nowhere in the communication. I found various posts that mention that this should work. Am I missing the obvious somewhere?
Thank you for your insights. Koen
changing
update control {Auth-type := "/usr/bin/php -f /etc/freeradius/php/checkpasswd.php'%{User-Name}' '%{User-Password}'"}
to
update control {Auth-type := `/usr/bin/php -f /etc/freeradius/php/checkpasswd.php '%{User-Name}' '%{User-Password}'`}
fixed the error for me (using ` instead of ")