Download Using GSM SIM Authentication in VPNs

Transcript
A.4. OpenVPN User Authentication Script
use
IO : : S o c k e t : : INET ;
use
D i g e s t : : MD5 qw ( md5_hex ) ;
# Get
if
username / password
($ARG =
if
shift
( ! open
( UPFILE ,
print
exit
from
@ARGV)
" Could
91
file
{
"<$ARG " ) )
not
open
{
u s e r /pw
file :
$ARG\ n " ;
1;
}
}
else
{
print
"No
exit
u s e r /pw
file
specified
on
command
l i n e \n " ;
1;
}
$username
= <UPFILE>;
$password
= <UPFILE>;
if
( ! $username
print
||
! $password )
" Username / p a s s w o r d
exit
{
not
found
in
file :
$ARG\ n " ;
1;
}
chomp
$username ;
chomp
$password ;
close
( UPFILE ) ;
$HOSTNAME =
$PORTNO =
" y o s h i . t o s h . no " ;
5747;
−
$sock
= IO : : S o c k e t : : INET >new (
P e e r P o r t=>$PORTNO,
P r o t o =>'udp ' ,
P e e r A d d r=>$HOSTNAME)
print
$sock
die
"Can ' t
bind :
$@\ n " ;
" Sending . . \ n " ;
−>s e n d ( $ u s e r n a m e )
or
$MAXLEN =
die
" cannot
=
=
to
$HOSTNAME($PORTNO ) :
,
$MAXLEN,
gethostbyaddr ( $ipaddr ,
1024)
or
AF_INET ) ;
i f ( l e n g t h ( $ a u t h S t r i n g ) <8){
print
" Auth
user
exit
not
' $username '
found
or
failed ,
key
too
s h o r t \n " ;
1;
}
print
$hash
$ !";
"";
−>r e c v ( $ a u t h S t r i n g
$host
send
1024;
$authString
$sock
or
length ( $authString ) ;
= md5_hex
i f ( $hash
eq
exit
0;
$authString ;
$password ){
Torstein Bjørnstad
die
" recv :
$ !";