]> git.zerfleddert.de Git - fhem-stuff/blame - HMLAN/hmlan-crypt-test.pl
fix coc-as-cuno
[fhem-stuff] / HMLAN / hmlan-crypt-test.pl
CommitLineData
7836eda2
MG
1#!/usr/bin/perl -w
2
ec3c7d4f 3my $key="PUTYOURSECRETHMLANSTICKERKEYHERE";
7836eda2
MG
4my $hmlan="192.168.1.2";
5
6BEGIN {
7 use File::Basename;
8 push @INC, dirname($0);
9}
10
11use HMLAN_CRYPT;
12use IO::Socket::INET;
13use IO::Select;
14
15#This should be random...
16my $my_iv = '00112233445566778899AABBCCDDEEFF';
17my $hmlan_iv = '';
18
19my $sock = IO::Socket::INET->new(
20 PeerAddr => $hmlan,
21 PeerPort => 1000,
22 Proto => 'tcp',
23 Blocking => 0);
24
25my $read_set = new IO::Select();
26$read_set->add($sock);
27
28$read_set->can_read();
29
30chomp(my $iv = <$sock>);
31if ($iv =~ /^V(................................)\r$/) {
32 $hmlan_iv = $1;
33} else {
34 print STDERR "Unknown IV received: ${iv}\n";
35 exit(1);
36}
37
38print $sock "V${my_iv}\r\n";
39
40my $cipher_hmlan=HMLAN_CRYPT->new(pack("H*", $key), pack("H*", $my_iv));
41my $cipher_pc=HMLAN_CRYPT->new(pack("H*", $key), pack("H*", $hmlan_iv));
42
43$read_set->add(\*STDIN);
44
45while(1) {
46 my @ready = $read_set->can_read();
47 foreach my $r (@ready) {
48 if ($r == $sock) {
49 while(my $buf=<$r>) {
50 print $cipher_hmlan->decrypt($buf);
51 }
52 } else {
53 my $buf = <$r>;
54 exit(1) if (!$buf);
55
56 print $sock $cipher_pc->encrypt($buf);
57 }
58 }
59}
Impressum, Datenschutz