]>
Commit | Line | Data |
---|---|---|
7836eda2 MG |
1 | #!/usr/bin/perl -w |
2 | ||
ec3c7d4f | 3 | my $key="PUTYOURSECRETHMLANSTICKERKEYHERE"; |
7836eda2 MG |
4 | my $hmlan="192.168.1.2"; |
5 | ||
6 | BEGIN { | |
7 | use File::Basename; | |
8 | push @INC, dirname($0); | |
9 | } | |
10 | ||
11 | use HMLAN_CRYPT; | |
12 | use IO::Socket::INET; | |
13 | use IO::Select; | |
14 | ||
15 | #This should be random... | |
16 | my $my_iv = '00112233445566778899AABBCCDDEEFF'; | |
17 | my $hmlan_iv = ''; | |
18 | ||
19 | my $sock = IO::Socket::INET->new( | |
20 | PeerAddr => $hmlan, | |
21 | PeerPort => 1000, | |
22 | Proto => 'tcp', | |
23 | Blocking => 0); | |
24 | ||
25 | my $read_set = new IO::Select(); | |
26 | $read_set->add($sock); | |
27 | ||
28 | $read_set->can_read(); | |
29 | ||
30 | chomp(my $iv = <$sock>); | |
31 | if ($iv =~ /^V(................................)\r$/) { | |
32 | $hmlan_iv = $1; | |
33 | } else { | |
34 | print STDERR "Unknown IV received: ${iv}\n"; | |
35 | exit(1); | |
36 | } | |
37 | ||
38 | print $sock "V${my_iv}\r\n"; | |
39 | ||
40 | my $cipher_hmlan=HMLAN_CRYPT->new(pack("H*", $key), pack("H*", $my_iv)); | |
41 | my $cipher_pc=HMLAN_CRYPT->new(pack("H*", $key), pack("H*", $hmlan_iv)); | |
42 | ||
43 | $read_set->add(\*STDIN); | |
44 | ||
45 | while(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 | } |