Auth-Yubikey_Decrypter
view release on metacpan or search on metacpan
lib/Auth/Yubikey_Decrypter.pm view on Meta::CPAN
# strip out the actual token
my $publicID = substr($fulltoken,0,length($fulltoken)-32);
my $token = substr($fulltoken,length($fulltoken)-32);
# decode the token from modhex down to binary
my $token_bin = &yubikey_modhex_decode($token);
# Decrypt the token using it's key
my $cipher = Crypt::Rijndael->new( $aeskey_bin );
my $token_decoded_bin = $cipher->decrypt($token_bin);
my $token_decoded_hex = unpack "H*", $token_decoded_bin;
# get all the values from the decoded token
my $secretid_hex = substr($token_decoded_hex,0,12);
my $counter_dec = ord(substr($token_decoded_bin,7,1))*256+ord(substr($token_decoded_bin,6,1));
my $timestamp_dec = ord(substr($token_decoded_bin,10,1))*65536+ord(substr($token_decoded_bin,9,1))*256+ord(substr($token_decoded_bin,8,1));
my $session_use_dec = ord(substr($token_decoded_bin,11,1));
my $random_dec = ord(substr($token_decoded_bin,13,1))*256+ord(substr($token_decoded_bin,12,1));
my $crc_dec = ord(substr($token_decoded_bin,15,1))*256+ord(substr($token_decoded_bin,14,1));
my $crc_ok = &yubikey_crc_check($token_decoded_bin);
return ($publicID,$secretid_hex,$counter_dec,$timestamp_dec,$session_use_dec,$random_dec,$crc_dec,$crc_ok);
}
=head2 yubikey_modhex_decode
Input : the modhex code
Output : decoded modhex code in hex
=cut
sub yubikey_modhex_decode
{
my $mstring = $_[0];
my $cset="cbdefghijklnrtuv";
my $decoded="";
my $hbyte=0;
my $pos;
for (my $i=0; $i<length($mstring);$i++)
{
$pos=index($cset,substr($mstring,$i,1));
if ($i/2 != int($i/2))
{
$decoded .= chr($hbyte+$pos);
$hbyte=0;
}
else
{
$hbyte=$pos*16;
}
}
return $decoded;
}
=head2 yubikey_crc_check
Performs a crc check on the decoded data
=cut
sub yubikey_crc_check
{
my $buffer = $_[0];
my $m_crc=0xffff;
my $j;
for(my $bpos=0; $bpos<16; $bpos++)
{
( run in 0.299 second using v1.01-cache-2.11-cpan-26ccb49234f )