]> git.zerfleddert.de Git - fhem-stuff/commitdiff
add support for communicating with the wired gateway
authorMichael Gernoth <michael@gernoth.net>
Tue, 18 Jun 2013 18:57:15 +0000 (20:57 +0200)
committerMichael Gernoth <michael@gernoth.net>
Tue, 18 Jun 2013 18:57:15 +0000 (20:57 +0200)
HMLAN/hmlan-crypt-test.pl

index cab3ad8b606f407891ac2cf0321719add3a44d19..37c3523693d803f1b13e1fdf09432d9ea1025c7b 100755 (executable)
@@ -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);
 
Impressum, Datenschutz