Skip to content

emka.web.id

menulis pengetahuan – merekam peradaban

Menu
  • Home
  • Tutorial
  • Search
Menu

Two Factor Authentication With One Time Passwords with FreeRADIUS and LinOTP

Posted on July 15, 2012

The API

While the Enterprise Edition comes with a C module for the FreeRADIUS Server, the Community Edition, that is licensed under the AGPLv3 does not. Nevertheless, LinOTP provides very simple WEB APIs that makes it easy to talk to LinOTP in many different ways. There is also an API to do authentication, i.e. to ask the LinOTP server if a given one time password for a certain user is valid. This is the URL

https://yourServer/validate/check?user=….&pass=….

or

https://yourServer/validate/simplecheck?user=…&pass=…

You can take a look at the complete API here.

The FreeRADIUS

The simple LinOTP API and some nice module of the FreeRADIUS make it easy to hack a simple solution for OTP via RADIUS. You could use the module rlm_exec to execute an external program but I’d rather use the module rlm_perl and add my limited perl knowlege 😉

The documentation of the rlm_perl module can be found here. It has a simple example, that we need to adapt only in the function authenticate. This is the point, where we need to talk to the LinOTP server (with the above URL) and repond according the the LinOTP feedback.

Solution

Use this perl module (beta):
[sourcecode language=”perl”]
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
# Copyright 2002 The FreeRADIUS server project
# Copyright 2002 Boian Jordanov <bjordanov@orbitel.bg>
# Copyright 2011 linotp project <linotp@lsexperts.de>

#
# Based on the Example code for use with rlm_perl
#
#

=head1 NAME

freeradius_perl – Perl module for use with FreeRADIUS rlm_perl, to authenticate against
LinOTP http://www.linotp.org

=head1 SYNOPSIS

use with freeradius:

Configure rlm_perl to work with LinOTP:
in /etc/freeradius/users
set:
DEFAULT Auth-type := perl

in /etc/freeradius/modules/perl
point
perl {
module =
to this file

in /etc/freeradius/sites-enabled/<yoursite>
set
authenticate{
perl
[….]

=head1 DESCRIPTION

This module enables freeradius to authenticate using LinOTP.

TODO:
* checking of server certificate

=head2 Methods

* authenticate

=head1 AUTHOR

Cornelius Koelbel (cornelius.koelbel@lsexperts.de)

=head1 COPYRIGHT

Copyright 2011

This library is free software; you can redistribute it
under the GPLv2.

=head1 SEE ALSO

perl(1).

=cut

use strict;
use LWP 5.64;

# use …
# This is very important ! Without this script will not get the filled hashesh from main.
use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK $URL);
use Data::Dumper;

$URL = "https://localhost/validate/simplecheck";

# This is hash wich hold original request from radius
#my %RAD_REQUEST;
# In this hash you add values that will be returned to NAS.
#my %RAD_REPLY;
#This is for check items
#my %RAD_CHECK;

#
# This the remapping of return values
#
use constant RLM_MODULE_REJECT=> 0;# /* immediately reject the request */
use constant RLM_MODULE_FAIL=> 1;# /* module failed, don’t reply */
use constant RLM_MODULE_OK=> 2;# /* the module is OK, continue */
use constant RLM_MODULE_HANDLED=> 3;# /* the module handled the request, so stop. */
use constant RLM_MODULE_INVALID=> 4;# /* the module considers the request invalid. */
use constant RLM_MODULE_USERLOCK=> 5;# /* reject the request (user is locked out) */
use constant RLM_MODULE_NOTFOUND=> 6;# /* user not found */
use constant RLM_MODULE_NOOP=> 7;# /* module succeeded without doing anything */
use constant RLM_MODULE_UPDATED=> 8;# /* OK (pairs modified) */
use constant RLM_MODULE_NUMCODES=> 9;# /* How many return codes there are */

# Function to handle authorize
sub authorize {
# For debugging purposes only
# &log_request_attributes;

# Here’s where your authorization code comes
# You can call another function from here:
&test_call;

return RLM_MODULE_OK;
}

# Function to handle authenticate
sub authenticate {
# For debugging purposes only
# &log_request_attributes;

my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new(GET => $URL . "?user=" .
$RAD_REQUEST{‘User-Name’} . "&pass=" .
$RAD_REQUEST{‘User-Password’} );
my $response = $ua->request( $req );

die "Error at $URL\n ", $response->status_line, "\n Aborting"
unless $response->is_success;

if($response->content =~ m/:\-\)/i) {
return RLM_MODULE_OK;
} else {
$RAD_REPLY{‘Reply-Message’} = "LinOTP server denied access!";
return RLM_MODULE_REJECT;
}
}

# Function to handle preacct
sub preacct {
# For debugging purposes only
# &log_request_attributes;

return RLM_MODULE_OK;
}

# Function to handle accounting
sub accounting {
# For debugging purposes only
# &log_request_attributes;

# You can call another subroutine from here
&test_call;

return RLM_MODULE_OK;
}

# Function to handle checksimul
sub checksimul {
# For debugging purposes only
# &log_request_attributes;

return RLM_MODULE_OK;
}

# Function to handle pre_proxy
sub pre_proxy {
# For debugging purposes only
# &log_request_attributes;

return RLM_MODULE_OK;
}

# Function to handle post_proxy
sub post_proxy {
# For debugging purposes only
# &log_request_attributes;

return RLM_MODULE_OK;
}

# Function to handle post_auth
sub post_auth {
# For debugging purposes only
# &log_request_attributes;

return RLM_MODULE_OK;
}

# Function to handle xlat
sub xlat {
# For debugging purposes only
# &log_request_attributes;

# Loads some external perl and evaluate it
my ($filename,$a,$b,$c,$d) = @_;
&radiusd::radlog(1, "From xlat $filename ");
&radiusd::radlog(1,"From xlat $a $b $c $d ");
local *FH;
open FH, $filename or die "open ‘$filename’ $!";
local($/) = undef;
my $sub = <FH>;
close FH;
my $eval = qq{ sub handler{ $sub;} };
eval $eval;
eval {main->handler;};
}

# Function to handle detach
sub detach {
# For debugging purposes only
# &log_request_attributes;

# Do some logging.
&radiusd::radlog(0,"rlm_perl::Detaching. Reloading. Done.");
}

#
# Some functions that can be called from other functions
#

sub test_call {
# Some code goes here
}

sub log_request_attributes {
# This shouldn’t be done in production environments!
# This is only meant for debugging!
for (keys %RAD_REQUEST) {
&radiusd::radlog(1, "RAD_REQUEST: $_ = $RAD_REQUEST{$_}");
}
}

1;
[/sourcecode]

Sumber: HowToForge

Terbaru

  • Apa Itu Aplikasi Dooie Live? Ini Pengertian dan Cara Pakai Aplikasinya untuk Cari Jodoh
  • Apa Itu Battle Emote Jefri Nichol dan Om Telolet Om di MLBB? Ini Penjelasannya
  • Apa itu Game Luna Mobile dan Bagaimana Cara Menangnya?
  • Apa Itu Kompensasi Sistem Trail Mobile Legends? Ini Penjelasan dan Cara Klaim Hadiahnya
  • Apa Itu Update Google Pixel 2 Desember 2025? Ini Penjelasannya!
  • Ini Cara Reset Desil di Aplikasi Cek Bansos Biar Valid (Update Januari 2026)
  • Apa Itu EZNET Wireless dan Fiber Optic? Ini Perbedaan dan Pengertian Lengkapnya
  • Pengertian Rework Magic Wheel dan Rank Mythic Eternal: Apa itu Perubahan Sistem Baru Mobile Legends?
  • Apa Itu Diamond Combo? Pengertian Game Puzzle Viral yang Katanya Bisa Hasilkan Cuan
  • Apa Itu Showbox? Pengertian, Fungsi, dan Cara Menggunakannya di Android
  • Cara Mengatasi Fitur Monet Facebook Pro Tiba-tiba Hilang
  • Google Bikin Kejutan! Pixel 10 Diskon Gila-gilaan di YouTube Premium
  • Apa Itu Google CC? Ini Pengertian Agen Produktivitas AI Eksperimental Terbaru
  • Apa Itu Ultras Seblak di eSport? Pengertian dan Fenomena Baru Suporter eSport
  • Android 16: Animasi Folder Baru yang Mengubah Cara Kita Berinteraksi!
  • Android 16: Notifikasi Lokasi ‘Blue Dot’ – Fitur Baru yang Perlu Kalian Ketahui!
  • Apa Itu Risiko Auto Click di Event Spongebob Mobile Legends? Ini Penjelasannya
  • Apa Itu Fitur Eksperimental Windows? Ini Pengertian dan Cara Menonaktifkannya
  • Apa Itu Android 16 Beta 1? Ini Pengertian dan Fitur Terbarunya
  • Belum Tahu? Ini Trik Supaya Bisa Dapat Skin Patrick Mobile Legends dengan Harga Murah
  • Pixel Desember 2025: Update Besar Siap Meluncur, Apa yang Baru?
  • Apa Itu HYFE XL Prioritas? Ini Pengertian, FUP, dan Realita Kecepatannya
  • Pengertian Render dan Convert: Apa Bedanya dalam Video Editing?
  • Cara Mengatasi Aplikasi Office yang Terus Muncul dan Menerapkan Perubahan Pengaturan Privasi
  • Pixel Launcher Mendapatkan Sentuhan Google Search Baru!
  • Penyebab Aplikasi Wondr BNI Tidak Bisa Dibuka
  • Kode 0425 Daerah Mana? Ini Pengertian dan Fakta Sebenarnya
  • Apa Itu SSS CapCut? Pengertian Downloader Video Tanpa Watermark yang Wajib Kalian Tahu
  • Apa Itu Paket GamesMAX Telkomsel? Ini Pengertian dan Fungsinya Bagi Gamers
  • Apa Itu Menu Plus di Google Search? Ini Pengertian dan Fungsinya
  • Apa Itu AI Kill Switch di Firefox? Ini Pengertian dan Detail Fitur Terbarunya
  • Apa Itu Platform Modular Intel Alder Lake N (N100)? Ini Pengertian dan Spesifikasinya
  • Apa Itu Armbian Imager? Pengertian Utilitas Flashing Resmi untuk Perangkat ARM Kalian
  • Apa Itu OpenShot 3.4? Pengertian dan Fitur LUT Terbaru untuk Grading Warna
  • Flatpak 1.16.2: Sandbox Baru untuk GPU Intel Xe dan VA-API
  • Apa itu RunPod? Ini Pengertian dan Tutorial Cara Deploy Pod Pertamamu
  • Apa Itu Migrasi Pod di RunPod? Ini Pengertian dan Cara Kerjanya
  • Loading Model AI Lama? Coba Fitur Cached Models RunPod Ini, Hemat Waktu & Biaya!
  • Replicate Diakuisisi Cloudflare? Tenang, Ini Justru Kabar Baik Buat Developer AI
  • Apa Itu Nemotron-3 Nano? Pengertian Model Bahasa Ringkas dan Hasil Uji Cobanya
  • Apa Itu Serangan Siber Infrastruktur Kritikal? Belajar dari Kasus Peretasan Air Bersih Denmark
  • Apa Itu Error Update MSMQ di Windows 10? Ini Penjelasan Lengkap dan Solusinya
  • Apa Itu “I Am Not a Robot – reCAPTCHA Verification ID: 2165”? Ini Pengertian dan Bahayanya
  • Apa Itu Serangan Clop Ransomware pada CentreStack? Ini Pengertian dan Dampaknya
  • Apa Itu E-Note? Pengertian Platform Kripto yang Baru Saja Disita FBI
Beli Pemotong Rumput dengan Baterai IRONHOOF 588V Mesin Potong Rumput 88V disini https://s.shopee.co.id/70DBGTHtuJ
Beli Morning Star Kursi Gaming/Kantor disini: https://s.shopee.co.id/805iTUOPRV

©2025 emka.web.id | Design: Newspaperly WordPress Theme