#!/usr/bin/perl -w use strict; use Digest::HMAC; use Digest::SHA1; use Digest::MD5; my %hashes = ( 'OAKLEY_SHA' => 'Digest::SHA1', 'OAKLEY_MD5' => 'Digest::MD5' ); my $nonce_i = $ENV{"NONCE_I"}; my $nonce_r = $ENV{"NONCE_R"}; my $hashtype = $ENV{"HASHTYPE"}; my $connection = $ENV{"CONN_NAME"}; $nonce_i =~ s/0x(.*)/$1/; $nonce_i = pack('H*', $nonce_i); $nonce_r =~ s/0x(.*)/$1/; $nonce_r =pack('H*', $nonce_r); my $key = get_secret($connection); my $hash_name = $hashes{$hashtype}; if (!defined($hash_name)) { print "ERROR=unsupported hash type: $hashtype\n"; exit(1); } my $hmac = Digest::HMAC->new($key, $hash_name); $hmac->add($nonce_i); $hmac->add($nonce_r); my $skeyid = $hmac->hexdigest; print "SKEYID=0x$skeyid\n"; sub get_secret { return "the big hidden secret noone can guess"; }