X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/fhem-stuff/blobdiff_plain/ec3c7d4ff8096dcd8bed99323f7dfb2028465382..532a7bf0b5af89a860126c534048a9923cf516d1:/HMLAN/hmlan-crypt-test.pl diff --git a/HMLAN/hmlan-crypt-test.pl b/HMLAN/hmlan-crypt-test.pl index cab3ad8..37c3523 100755 --- a/HMLAN/hmlan-crypt-test.pl +++ b/HMLAN/hmlan-crypt-test.pl @@ -1,6 +1,12 @@ #!/usr/bin/perl -w -my $key="PUTYOURSECRETHMLANSTICKERKEYHERE"; +# 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 { @@ -11,6 +17,7 @@ BEGIN { use HMLAN_CRYPT; use IO::Socket::INET; use IO::Select; +use Digest::MD5; #This should be random... my $my_iv = '00112233445566778899AABBCCDDEEFF'; @@ -28,17 +35,30 @@ $read_set->add($sock); $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);