#!/usr/bin/perl -w
-my $key="RUTYOURSECRETHMLANSTICKERKEYHERE";
+# key can either be 32 HEX chars (HMLAN) or a password (wired gateway)
+#my $key="00112233445566778899AABBCCDDEEFF";
+#my $key="pA$$w0rd1!";
+
+my $key="00112233445566778899AABBCCDDEEFF";
+
+# ip address
my $hmlan="192.168.1.2";
BEGIN {
use HMLAN_CRYPT;
use IO::Socket::INET;
use IO::Select;
+use Digest::MD5;
#This should be random...
my $my_iv = '00112233445566778899AABBCCDDEEFF';
$read_set->can_read();
chomp(my $iv = <$sock>);
+if ($iv =~ /^H/) {
+ print "${iv}\n";
+ chomp($iv = <$sock>);
+}
+
if ($iv =~ /^V(................................)\r$/) {
$hmlan_iv = $1;
+ print $sock "V${my_iv}\r\n";
+} elsif ($iv =~ /^V(..),(................................)\r$/) {
+ $hmlan_iv = $2;
+ print $sock "V01,${my_iv}\r\n";
} else {
print STDERR "Unknown IV received: ${iv}\n";
exit(1);
}
-print $sock "V${my_iv}\r\n";
+if (length($key) < 32) {
+ $key = Digest::MD5::md5($key);
+} else {
+ $key = pack("H*", $key);
+}
-my $cipher_hmlan=HMLAN_CRYPT->new(pack("H*", $key), pack("H*", $my_iv));
-my $cipher_pc=HMLAN_CRYPT->new(pack("H*", $key), pack("H*", $hmlan_iv));
+my $cipher_hmlan=HMLAN_CRYPT->new($key, pack("H*", $my_iv));
+my $cipher_pc=HMLAN_CRYPT->new($key, pack("H*", $hmlan_iv));
$read_set->add(\*STDIN);