libnet-proxy-perl-0.12.orig/0000755000175000017500000000000010705511550014036 5ustar abiabilibnet-proxy-perl-0.12.orig/t/0000755000175000017500000000000010705511550014301 5ustar abiabilibnet-proxy-perl-0.12.orig/t/90compile.t0000444000175000017500000000131510705511550016265 0ustar abiabiuse Test::More; use IPC::Open3; use File::Spec::Functions; use strict; my @scripts = glob catfile( 'script', '*' ); plan tests => scalar @scripts; my %prereq = ( 'script/connect-tunnel' => [qw( LWP::UserAgent )], ); for my $script (@scripts) { SKIP: { my $skip; for my $module ( @{ $prereq{$script} } ) { eval {"use $module;"}; $skip .= "$module " if $@; } skip "'$script' missing prereq: $skip", 1 if $skip; local ( *IN, *OUT, *ERR ); my $pid = open3( \*IN, \*OUT, \*ERR, "$^X -Mblib -c $script" ); wait; local $/ = undef; my $errput = ; like( $errput, qr/syntax OK/, "'$script' compiles" ); } } libnet-proxy-perl-0.12.orig/t/Util.pm0000444000175000017500000000362010705511550015553 0ustar abiabiuse strict; use warnings; use IO::Socket::INET; # return sockets connected to free ports # we can use sockport() to learn the port values # and close() to close the socket just before reopening it sub find_free_ports { my $n = shift; my @socks; for ( 1 .. $n ) { my $sock = listen_on_port(0); if ($sock) { push @socks, $sock; } } my @ports = map { $_->sockport() } @socks; diag "ports: @ports"; # close the sockets and return the ports $_->close() for @socks; return @ports; } # return a socket connected to port $port on localhost sub connect_to_port { my ($port, %opts) = @_; return IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => $port, Proto => 'tcp', %opts ); } # return a socket listening on $port on localhost sub listen_on_port { my ($port) = @_; return IO::Socket::INET->new( Listen => 1, LocalAddr => 'localhost', LocalPort => $port, Proto => 'tcp', ); } # compute a seed and show it use POSIX qw( INT_MAX ); sub init_rand { my $seed = @_ ? $_[0] : int rand INT_MAX; diag "Random seed $seed"; srand $seed; } # randomly exchange (or not) a pair sub random_swap { my ( $first, $second ) = @_; return rand > 0.5 ? ( $first, $second ) : ( $second, $first ); } # skip but fail # extends Test::More use Test::Builder; sub skip_fail { my ($why, $how_many) = @_; my $Test = Test::Builder->new(); for( 1 .. $how_many ) { $Test->ok( 0, $why ); } no warnings; last SKIP; } use IO::Select; use Test::More; sub is_closed { my ($sock, $name) = @_; $name ||= "$sock"; my $select = IO::Select->new( $sock ); my @read = $select->can_read(); if( @read ) { my $buf; my $read = $read[0]->sysread( $buf, 4096 ); is( $read, 0, "$name closed" ); } } 1; libnet-proxy-perl-0.12.orig/t/35hook_dual.t0000444000175000017500000001150610705511550016604 0ustar abiabiuse Test::More; use strict; use warnings; use Net::Proxy; use t::Util; my @lines = ( [ "thwapp qunckkk aiieee flrbbbbb clunk zlonk\n", "thwapp qunckkk aiieee flrbbbbb clunk zowie\n", "thwapp qunckkk aiieee flrbbbbb clunk zlonk\n", ], [ "cr_r_a_a_ck splatt crr_aaack awkkkkkk clunk zlopp ooooff pow\n", "cr_r_a_a_ck splatt crr_aaack awkkkkkk clunk zowie ooooff pow\n", "cr_r_a_a_ck splatt crr_aaack awkkkkkk clunk zlonk ooooff pow\n", ], [ "zgruppp clange clank_est whack zlopp pow awk swish\n", "zowie clange clank_est whack zowie pow awk swish\n", "zlonk clange clank_est whack zlonk pow awk swish\n", ], [ "bonk ouch_eth swa_a_p clank_est clash whack splatt zamm\n", "bonk ouch_eth swa_a_p clank_est clash whack splatt zowie\n", "bonk ouch_eth swa_a_p clank_est clash whack splatt zlonk\n", ], ); my $tests = 2 * ( @lines + 1 ); plan tests => $tests; init_rand(@ARGV); my @free = find_free_ports(3); SKIP: { skip 'Not enough available ports', $tests if @free < 3; my ( $proxy_port, $ssl_port, $ssh_port ) = @free; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'dual', port => $proxy_port, timeout => 0.5, hook => sub { my ( $dataref, $sock, $connector ) = @_; $$dataref =~ s/\bz\w+/zowie/g; }, server_first => { type => 'tcp', port => $ssh_port, }, client_first => { type => 'tcp', port => $ssl_port, hook => sub { my ( $dataref, $sock, $connector ) = @_; $$dataref =~ s/\bz\w+/zlonk/g; }, } }, out => { type => 'dummy' }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(2); exit; } else { # wait for the proxy to set up sleep 1; # the parent process does the testing my $ssh_listener = listen_on_port($ssh_port) or skip "Couldn't start the ssh server: $!", $tests; my $ssl_listener = listen_on_port($ssl_port) or skip "Couldn't start the ssl server: $!", $tests; my ( $client, $server ); # try 'ssh' $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", $tests; sleep 1; # wait for the timeout $server = $ssh_listener->accept() or skip_fail "Proxy didn't connect: $!", $tests; # transmit data my $orig_client = $client; for my $line (@lines) { print $server $line->[0]; # real server speaks first my $trans = $client ne $orig_client; is( <$client>, $line->[$trans], 'SSH line received ' . ( 'intact', 'transformed' )[$trans] ); ( $client, $server ) = random_swap( $client, $server ); } # close connections $server->close(); is_closed( $client, 'peer' ); $client->close(); # try ssl $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", $tests; print $client $lines[0][0]; # real client speaks first $server = $ssl_listener->accept() or skip_fail "Proxy didn't connect: $!", $tests; is( <$server>, $lines[0][1], "First SSL line received transformed (client)" ); # transmit the rest of the data shift @lines; $orig_client = $client; for my $line (@lines) { ( $client, $server ) = random_swap( $client, $server ); my $trans = $client eq $orig_client ? 1 : 2; print $client $line->[0]; # real client speaks first is( <$server>, $line->[$trans], 'SSL line received transformed ' . ( '', '(client)', '(server)' )[$trans] ); } # close connections $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/pod.t0000444000175000017500000000021410705511550015243 0ustar abiabi#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); libnet-proxy-perl-0.12.orig/t/11proxy_accessor.t0000444000175000017500000000132310705511550017670 0ustar abiabiuse strict; use warnings; use Test::More tests => 5; use Net::Proxy; my $sock = []; # dummy socket object my $peer = []; # dummy socket object my $connector = bless {}, 'Net::Proxy::Connector'; my $state = {}; Net::Proxy->set_peer( $sock, $peer ); is( Net::Proxy->get_peer( $sock ), $peer, 'Got back the peer' ); Net::Proxy->set_connector( $sock, $connector ); is( Net::Proxy->get_connector( $sock ), $connector, 'Got back the connector' ); Net::Proxy->set_state( $sock, $state ); is( Net::Proxy->get_state( $sock ), $state, 'Got back the state' ); # data is not clobbered is( Net::Proxy->get_connector( $sock ), $connector, 'Got back the connector' ); is( Net::Proxy->get_peer( $sock ), $peer, 'Got back the peer' ); libnet-proxy-perl-0.12.orig/t/36tcp_ctssl.t0000444000175000017500000000701210705511550016633 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use File::Spec::Functions; use t::Util; use Net::Proxy; my @lines = ( "oscar delta sierra echo papa\n", "Laurent_Fignon Henri_Pelissier Lucien_Petit_Breton Firmin_Lambot\n", "Toronto London Herzliya Melbourne Munich\n", "STARTTLS\n", "barkhausen schoenmaker sferics knoop fenice\n", "holy_icepicks holy_corpusles holy_Luthor_Burbank holy_hyperdermics\n", "STARTTLS\n", "Woody_Long Alicia_Rio Dorothy_Le_May Janine_Lindemulder Barbara_Summer\n", ); my $tests = @lines; my $all_tests = $tests + 1; plan tests => $all_tests; init_rand(@ARGV); # lock 2 ports my @free = find_free_ports(2); SKIP: { eval { require IO::Socket::SSL; }; skip 'IO::Socket::SSL required to test ssl', $all_tests if $@; skip 'Not enough available ports', $all_tests if @free < 2; no warnings 'once'; $IO::Socket::SSL::DEBUG = $ENV{NET_PROXY_VERBOSITY} || 0; my ( $proxy_port, $server_port ) = @free; my $pid = fork; skip 'proxy fork failed', $tests if !defined $pid; if ( $pid == 0 ) { my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port, timeout => 1, }, out => { type => 'ssl', host => 'localhost', port => $server_port, start_cleartext => 1, hook => sub { my ( $dataref, $sock, $connector ) = @_; if ( $$dataref =~ s/^STARTTLS\n// ) { print $sock "OK\n"; $connector->upgrade_SSL($sock); } }, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(1); exit; } else { SKIP: { # wait for the proxy to set up sleep 1; # start a server my $listener = listen_on_port($server_port) or skip "Couldn't start the server: $!", $tests; # start a client my $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", $tests; my $server = $listener->accept() or skip "Proxy didn't connect: $!", $tests; # remember which was the original server my $o_server = $server; my $is_ssl = 0; for my $line (@lines) { ( $client, $server ) = random_swap( $client, $server ); if ( $line eq "STARTTLS\n" ) { print $o_server $line; is( <$o_server>, "OK\n", "STARTTLS acknowledged" ); IO::Socket::SSL->start_SSL( $o_server, SSL_server => 1, SSL_cert_file => catfile( 't', 'test.cert' ), SSL_key_file => catfile( 't', 'test.key' ), ) if ! $is_ssl++; # do not upgrade twice } else { print $client $line; is( <$server>, $line, "Line received" ); } } $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/21connect.t0000444000175000017500000000322510705511550016262 0ustar abiabiuse strict; use warnings; use Test::More; use Net::Proxy::Connector; BEGIN { eval { require LWP::UserAgent; }; plan skip_all => 'LWP::UserAgent not available' if $@; } use Net::Proxy::Connector::connect; plan tests => 13; # delete all proxy keys from the environment delete $ENV{$_} for grep { /_proxy$/i } keys %ENV; my $c; my $args = {}; eval { $c = Net::Proxy::Connector::connect->new( $args ); }; like( $@, qr/^host parameter is required /, 'No host'); $args->{host} = 'example.com'; eval { $c = Net::Proxy::Connector::connect->new( $args ); }; like( $@, qr/^port parameter is required /, 'No port'); $args->{port} = 9999; $ENV{HTTP_PROXY} = 'http://powie:zgruppp@urkk.crunch.com:8888/'; eval { $c = Net::Proxy::Connector::connect->new( $args ); }; is( $@, '', 'env_proxy'); isa_ok( $c, 'Net::Proxy::Connector::connect' ); delete $ENV{HTTP_PROXY}; eval { $c = Net::Proxy::Connector::connect->new( $args ); }; like( $@, qr/^proxy_host parameter is required /, 'No proxy_host'); $args->{proxy_host} = 'urkk.crunch.com'; eval { $c = Net::Proxy::Connector::connect->new( $args ); }; is( $@, '', 'proxy_host'); isa_ok( $c, 'Net::Proxy::Connector::connect' ); $args->{proxy_port} = 8888; eval { $c = Net::Proxy::Connector::connect->new( $args ); }; is( $@, '', 'proxy_port'); isa_ok( $c, 'Net::Proxy::Connector::connect' ); $args->{proxy_user} = 'barkhausen'; eval { $c = Net::Proxy::Connector::connect->new( $args ); }; is( $@, '', 'proxy_user'); isa_ok( $c, 'Net::Proxy::Connector::connect' ); $args->{proxy_pass} = 'gerfaut'; eval { $c = Net::Proxy::Connector::connect->new( $args ); }; is( $@, '', 'proxy_pass'); isa_ok( $c, 'Net::Proxy::Connector::connect' ); libnet-proxy-perl-0.12.orig/t/10proxy_new.t0000444000175000017500000000431710705511550016664 0ustar abiabiuse Test::More tests => 13; use strict; use warnings; use Net::Proxy; my $proxy; # test constructor eval { $proxy = Net::Proxy->new(); }; like( $@, qr/^Argument to new\(\) must be a HASHREF/, 'new( HASHREF )' ); eval { $proxy = Net::Proxy->new(1); }; like( $@, qr/^Argument to new\(\) must be a HASHREF/, 'new( HASHREF )' ); # in argument eval { $proxy = Net::Proxy->new( {} ); }; like( $@, qr/^'in' connector required/, 'in arg required' ); eval { $proxy = Net::Proxy->new( { in => 'in' } ); }; like( $@, qr/^'in' connector must be a HASHREF/, 'in must be a HASHREF'); eval { $proxy = Net::Proxy->new( { in => {} } ); }; like( $@, qr/^'type' key required for 'in' connector/, 'type required for in arg' ); eval { $proxy = Net::Proxy->new( { in => { type => 'zlonk', hook => {} } } ); }; like( $@, qr/^'hook' key is not a CODE reference for 'in' connector/, 'hook must be a CODE reference' ); eval { $proxy = Net::Proxy->new( { in => { type => 'zlonk' } } ); }; like( $@, qr/^Couldn't load Net::Proxy::Connector::zlonk for 'in' connector/, q{NPC::zlonk doesn't exist} ); # out argument eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' } } ); }; like( $@, qr/^'out' connector required/, 'out arg required' ); eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' }, out => 'out' } ) }; like( $@, qr/^'out' connector must be a HASHREF/, 'in must be a HASHREF'); eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' }, out => {} } ); }; like( $@, qr/^'type' key required for 'out' connector/, 'type required for out arg' ); eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' }, out => { type => 'zlonk', hook => bless {}, 'CODE' } } ); }; like( $@, qr/^'hook' key is not a CODE reference for 'out' connector/, 'hook must be a CODE reference' ); eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' }, out => { type => 'zlonk' } } ); }; like( $@, qr/^Couldn't load Net::Proxy::Connector::zlonk for 'out' connector/, q{NPC::zlonk doesn't exist} ); # ok eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' }, out => { type => 'tcp' } } ); }; is( $@, '', 'Net::Proxy->new()' ); libnet-proxy-perl-0.12.orig/t/test.key0000444000175000017500000000156710705511550016001 0ustar abiabi-----BEGIN RSA PRIVATE KEY----- MIICXQIBAAKBgQDV/n6YLO/dM/kTUEJDnzVq32+O+dP/imsImeHNrnt0vRXqnj2k YOX5JdMg5nUoV0Yl4Dnq7eZLDkhkL+NAeWJY8ZIrgVXctFle+npSUc3h8mOBXAUP 5qy3L/+7S9IxmOAHU3iEl8jxC6//UgoqWROeyK1HEmxudzHj8yuLSPIGxwIDAQAB AoGBAIJMqQa97fvR5qq05vRH3/3IOSRkyIpD3TJqiIx13qRRciPe4IfTnJRdTLYu vU2n/oWXh4yd+OjgtIGUixo6DwAd31oN2yTJab4+VcC25MEkF0X3NV1e50HCoCuM xwHkINXxwoCIOkAONw7GzxDzeVa6Pp4GQ29LXqZ4WvQUC2MhAkEA+ME3bDUHHct3 LPuMoLMMakHF46YZM6OgUeLGADR9Bc21j/Pra/0tmh0RirbRknf/NIoD8aZyTxtV fMIorjWJ9wJBANw6F92J+dZHpeRfOMbp4rj0mcslBiH4XEzsh0fkQX9DWBrGb58P VVRdWUyAHsj3g49A58GvDaia2j7l3RcutbECQQCQqcUyf5A46pfPKCc7WYUx0jhk ULc9Sb41gN1HRz8h/eTF58OUlLNNefQ2qGUueeyHwG/Uu8ikarAHkt6XmXk3AkBx EMZV8FO7ptdN83Fj9op3aOVYva5zXF6PA9TEnTTfUMT4Ii8Gm8m0YaTKOPEVPrZl ou4Zq3U4viAUsNEc6NdRAkBiuM3ZtgwUX8yYYT4DkQHZfBpnePnazNeZYJvmQt7g SNUJ5PwTTG7t/vocr1oXBibWj+A9Hv5/4eDAbhdc4/Ps -----END RSA PRIVATE KEY----- libnet-proxy-perl-0.12.orig/t/40tcp_fail.t0000444000175000017500000000251110705511550016410 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use t::Util; use Net::Proxy; plan tests => my $tests = 1; # lock 2 ports my @free = find_free_ports(2); SKIP: { skip "Not enough available ports", $tests if @free < 2; my ( $proxy_port, $server_port ) = @free; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port, }, out => { type => 'tcp', host => 'localhost', port => $server_port, }, }, ); $proxy->register(); Net::Proxy->mainloop(1); exit; } else { # wait for the proxy to set up sleep 1; # no server my $client = connect_to_port($proxy_port) or skip "Couldn't start the client: $!", $tests; # the client is actually not connected at all is_closed( $client, 'peer' ); $client->close(); } } } libnet-proxy-perl-0.12.orig/t/36ssl_tcp.t0000444000175000017500000000463010705511550016307 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use File::Spec::Functions; use t::Util; use Net::Proxy; my @lines = ( "swa_a_p bang swish bap crunch\n", "zlonk zok zapeth crunch_eth crraack\n", "glipp zwapp urkkk cr_r_a_a_ck glurpp\n", "zzzzzwap thwapp zgruppp awk eee_yow\n", ); my $tests = @lines; my $all_tests = $tests + 1; plan tests => $all_tests; init_rand(@ARGV); # lock 2 ports my @free = find_free_ports(2); SKIP: { eval { require IO::Socket::SSL; }; skip 'IO::Socket::SSL required to test ssl', $all_tests if $@; skip 'Not enough available ports', $all_tests if @free < 2; no warnings 'once'; $IO::Socket::SSL::DEBUG = $ENV{NET_PROXY_VERBOSITY} || 0; my ( $proxy_port, $server_port ) = @free; my $pid = fork; skip 'proxy fork failed', $tests if !defined $pid; if ( $pid == 0 ) { my $proxy = Net::Proxy->new( { in => { type => 'ssl', port => $proxy_port, timeout => 1, SSL_cert_file => catfile( 't', 'test.cert' ), SSL_key_file => catfile( 't', 'test.key' ), }, out => { type => 'tcp', host => 'localhost', port => $server_port, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(1); exit; } else { SKIP: { # wait for the proxy to set up sleep 1; # start a server my $listener = listen_on_port($server_port) or skip "Couldn't start the server: $!", $tests; # start a client my $client = IO::Socket::SSL->new( PeerAddr => 'localhost', PeerPort => $proxy_port ) or skip "Couldn't start the client: $!", $tests; my $server = $listener->accept() or skip "Proxy didn't connect: $!", $tests; for my $line (@lines) { ( $client, $server ) = random_swap( $client, $server ); print $client $line; is( <$server>, $line, "Line received" ); } $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/14proxy_debug.t0000444000175000017500000001043610705511550017164 0ustar abiabiuse Test::More; use strict; use warnings; use Net::Proxy; my @messages = ( 'ham tomato shrubbery pate herring truffle lobster aubergine', 'kn na vn pk cy hn yu cc', 'thwack kayo zlonk qunckkk zlott cr_r_a_a_ck clunk_eth bang', 'The_Witch_of_Kaan Pipil_Khan Minstrel Sage Captain_Ahax Groo Chakaal', 'barry wendel_j_stone_iv myron laura ed richard millard_bullrush dilbert', 'lbrocard hvds ni_s gbarr lwall cbail mschwern rgarcia', 'XPT MUR CNY MDL GHC MWK YER LTL', 'elk wapiti antler alces_alces oryx moose caribou eland', 'Jimmy_Carter Ronald_Reagan Chester_Arthur George_Washington Gerald_Ford', 'Woodstock Rerun Peppermint_Patty Schroeder Pigpen Lucy Snoopy Linus', 'manganese eckstine lowenstein gebrail gland maijstral girgis godolphin', 'corge quux foobar fred waldo garply fubar grault', 'strontium platine germanium rhodium hafnium californium chrome terbium', 'maxime laboris adipisicing ullamco harum nobis sed inventore', 'Braga Pittsburgh Saint_Louis Merlbourne Ottawa Belfast Chicago Paris', 'mardi jeudi mercredi dimanche vendredi samedi lundi jeudi', 'Gregory_Gaillard Delphine_Moussin Michael_Denard Geraldine_Wiart', 'MONGOLIAN_LETTER_LA COMBINING_LATIN_SMALL_LETTER_X MYANMAR_SIGN_ANUSVARA', 'ansys_lm kis netinfo_local pcia_rxp_b xpl hri_port nkd stmf', 'holy_greed holy_ghost_writer holy_jawbreaker holy_barracuda', 'Rea Sushi Stretch Garfield Clive Caped_Avenger Squeak Arlene', 'spam toast ham lobster beans tomato aubergine', 'period bullet underscore pilcrow ellipsis dagger permille_sign', 'plugh foo quux foobar qux corge xyzzy', 'MBOX SIZE QUIT XFER OK NMBR RETR', 'Rerun Pigpen Charlie_Brown Schroeder Snoopy Marcie Linus', 'orca classroom versatile repay inception narrative chatter', 'Altair Electra Ancha Naos Canopus Merope Sadr', 'greed anger envy laziness gluttony pride lust', ); my @expected = @messages[ 0, 4, 8, 9, 12, 13, 14, 16, 17, 20 .. 24 ]; my $err = 'stderr.out'; plan tests => my $tests = @expected; SKIP: { # logs are sent to STDERR # (this is not a very nice way to spit logging info) # so, dup STDERR and save it to stderr.out open OLDERR, ">&STDERR" or skip "Can't dup STDERR: $!", $tests; open STDERR, '>', $err or skip "Can't redirect STDERR: $!", $tests; select STDERR; $| = 1; # make unbuffered # run our tests now my $i = 0; Net::Proxy->error( $messages[ $i++ ] ); Net::Proxy->notice( $messages[ $i++ ] ); Net::Proxy->info( $messages[ $i++ ] ); Net::Proxy->debug( $messages[ $i++ ] ); Net::Proxy->set_verbosity(0); Net::Proxy->error( $messages[ $i++ ] ); Net::Proxy->notice( $messages[ $i++ ] ); Net::Proxy->info( $messages[ $i++ ] ); Net::Proxy->debug( $messages[ $i++ ] ); Net::Proxy->set_verbosity(1); Net::Proxy->error( $messages[ $i++ ] ); Net::Proxy->notice( $messages[ $i++ ] ); Net::Proxy->info( $messages[ $i++ ] ); Net::Proxy->debug( $messages[ $i++ ] ); Net::Proxy->set_verbosity(2); Net::Proxy->error( $messages[ $i++ ] ); Net::Proxy->notice( $messages[ $i++ ] ); Net::Proxy->info( $messages[ $i++ ] ); Net::Proxy->debug( $messages[ $i++ ] ); Net::Proxy->set_verbosity(1); Net::Proxy->error( $messages[ $i++ ] ); Net::Proxy->notice( $messages[ $i++ ] ); Net::Proxy->info( $messages[ $i++ ] ); Net::Proxy->debug( $messages[ $i++ ] ); Net::Proxy->set_verbosity(3); Net::Proxy->error( $messages[ $i++ ] ); Net::Proxy->notice( $messages[ $i++ ] ); Net::Proxy->info( $messages[ $i++ ] ); Net::Proxy->debug( $messages[ $i++ ] ); Net::Proxy->set_verbosity(0); Net::Proxy->error( $messages[ $i++ ] ); Net::Proxy->notice( $messages[ $i++ ] ); Net::Proxy->info( $messages[ $i++ ] ); Net::Proxy->debug( $messages[ $i++ ] ); # get the old STDERR back open STDERR, ">&OLDERR" or die "Can't dup OLDERR: $!"; close OLDERR; # read stderr.out open my $fh, $err or skip "Unable to open $err: $!"; $i = 0; while (<$fh>) { like( $_, qr/\A\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d $expected[$i]\n\z/, "Expected line $i" ); $i++; } # close and remove all files close $fh or diag "close: $!"; unlink $err or diag "unlink: $!"; } libnet-proxy-perl-0.12.orig/t/30tcp_tcp.t0000444000175000017500000000455410705511550016273 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use t::Util; use Net::Proxy; my @lines = ( "swa_a_p bang swish bap crunch\n", "zlonk zok zapeth crunch_eth crraack\n", "glipp zwapp urkkk cr_r_a_a_ck glurpp\n", "zzzzzwap thwapp zgruppp awk eee_yow\n", ); my $tests = @lines + 2; plan tests => $tests; init_rand(@ARGV); # lock 2 ports my @free = find_free_ports(2); SKIP: { skip "Not enough available ports", $tests if @free < 2; my ( $proxy_port, $server_port ) = @free; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port, timeout => 1, }, out => { type => 'tcp', host => 'localhost', port => $server_port, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(1); exit; } else { # wait for the proxy to set up sleep 1; # the parent process does the testing my $listener = listen_on_port($server_port) or skip "Couldn't start the server: $!", $tests; my $client = connect_to_port($proxy_port) or skip "Couldn't start the client: $!", $tests; my $server = $listener->accept() or skip "Proxy didn't connect: $!", $tests; # mainloop(1) limits incoming connections to 1 sleep 1; my $client2 = connect_to_port($proxy_port); is( $client2, undef, "second client fails: $!" ); for my $line (@lines) { # anyone speaks first ( $client, $server ) = random_swap( $server, $client ); # send some data through print $client $line; is( <$server>, $line, "Line received" ); } $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/13proxy_stat.t0000444000175000017500000000206510705511550017047 0ustar abiabiuse Test::More tests => 10; use Net::Proxy; my $proxy = Net::Proxy->new( { in => { type => 'dummy' }, out => { type => 'dummy' } } ); is( $proxy->stat_opened(), 0, "No opened connection" ); is( $proxy->stat_closed(), 0, "No closed connection" ); $proxy->stat_inc_opened(); is( $proxy->stat_opened(), 1, "1 opened connection" ); $proxy->stat_inc_opened(); $proxy->stat_inc_opened(); is( $proxy->stat_opened(), 3, "3 opened connections" ); $proxy->stat_inc_closed(); is( $proxy->stat_closed(), 1, "1 closed connection" ); $proxy->stat_inc_closed(); $proxy->stat_inc_closed(); is( $proxy->stat_opened(), 3, "3 closed connections" ); my $proxy2 = Net::Proxy->new( { in => { type => 'dummy' }, out => { type => 'dummy' } } ); $proxy2->stat_inc_opened(); is( $proxy2->stat_opened(), 1, "1 opened connection"); is( Net::Proxy->stat_total_opened(), 4, "Total 4 opened connections" ); $proxy2->stat_inc_closed(); is( $proxy2->stat_closed(), 1, "1 closed connection"); is( Net::Proxy->stat_total_closed(), 4, "Total 4 closed connections" ); libnet-proxy-perl-0.12.orig/t/35signal.t0000444000175000017500000000167710705511550016124 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use Net::Proxy; # fetch signal numbers use Config; my %sig_num; my @names = split ' ', $Config{sig_name}; @sig_num{@names} = split ' ', $Config{sig_num}; my $tests = 1; if( $^O eq 'MSWin32' ) { plan skip_all => 'Test irrelevant on MSWin32'; } else { plan tests => $tests; } my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'dummy', }, out => { type => 'dummy', }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(1); exit; } else { # wait for the proxy to set up sleep 1; kill $sig_num{HUP}, $pid; is( wait, $pid, 'Proxy stopped by signal' ); } } libnet-proxy-perl-0.12.orig/t/00load.t0000444000175000017500000000145510705511550015550 0ustar abiabiuse Test::More; use File::Find; my %prereqs = ( 'Net::Proxy::Connector::connect' => [qw( LWP::UserAgent )], 'Net::Proxy::Connector::ssl' => [qw( IO::Socket::SSL )], 'Net::Proxy::Connector::connect_ssl' => [qw( LWP::UserAgent IO::Socket::SSL )], ); # compute the list of modules my @modules; find( sub { push @modules, $File::Find::name if /\.pm$/ }, 'blib/lib' ); @modules = sort map { s!/!::!g; s/\.pm$//; s/^blib::lib:://; $_ } @modules; plan tests => scalar @modules; for my $module (@modules) { SKIP: { my $missing_prereqs = 0; for my $prereq ( @{ $prereqs{$module} } ) { eval "require $prereq"; $missing_prereqs++ if $@; } skip "Missing prerequisites for $module", 1 if $missing_prereqs; use_ok($module); } } libnet-proxy-perl-0.12.orig/t/34hook_in.t0000444000175000017500000000545710705511550016274 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use t::Util; use Net::Proxy; my @lines = ( [ "swa_a_p bang swish bap crunch\n", "swa_a_p bang swish bap crunch\n" ], [ "zlonk zok zapeth crunch_eth crraack\n", "zowie zowie zowie crunch_eth crraack\n" ], [ "glipp zwapp urkkk cr_r_a_a_ck glurpp\n", "glipp zowie urkkk cr_r_a_a_ck glurpp\n" ], [ "zzzzzwap thwapp zgruppp awk eee_yow\n", "zowie thwapp zowie awk eee_yow\n" ], ); my $tests = @lines + 1; plan tests => $tests; init_rand(@ARGV); # lock 2 ports my @free = find_free_ports(2); SKIP: { skip "Not enough available ports", $tests if @free < 2; my ( $proxy_port, $server_port ) = @free; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port, timeout => 1, hook => sub { my ($dataref, $sock, $connector) = @_; $$dataref =~ s/\bz\w+/zowie/g; }, }, out => { type => 'tcp', host => 'localhost', port => $server_port, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(1); exit; } else { # wait for the proxy to set up sleep 1; # the parent process does the testing my $listener = listen_on_port($server_port) or skip "Couldn't start the server: $!", $tests; my $client = connect_to_port($proxy_port) or skip "Couldn't start the client: $!", $tests; my $server = $listener->accept() or skip "Proxy didn't connect: $!", $tests; # data from the client is transformed by the hook my $orig_client = $client; for my $line (@lines) { # anyone speaks first ( $client, $server ) = random_swap( $server, $client ); # send some data through print $client $line->[0]; my $trans = $client eq $orig_client; is( <$server>, $line->[$trans], "Line received " . ( "intact", "transformed" )[$trans] ); } $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/33dual.t0000444000175000017500000000664110705511550015566 0ustar abiabiuse Test::More; use strict; use warnings; use Net::Proxy; use t::Util; my @lines = ( "thwapp qunckkk aiieee flrbbbbb clunk zlonk\n", "tutu bidon toto test3 pipo titi\n", "pique ratatam am gram stram colegram\n", "Signs_Point_to_Yes Reply_Hazy_Try_Again Cannot_Predict_Now\n", ); my $tests = 2 * ( @lines + 1 ); plan tests => $tests; init_rand(@ARGV); my @free = find_free_ports(3); SKIP: { skip 'Not enough available ports', $tests if @free < 3; my ( $proxy_port, $ssl_port, $ssh_port ) = @free; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'dual', port => $proxy_port, timeout => 0.5, server_first => { type => 'tcp', port => $ssh_port, }, client_first => { type => 'tcp', port => $ssl_port, } }, out => { type => 'dummy' }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(2); exit; } else { # wait for the proxy to set up sleep 1; # the parent process does the testing my $ssh_listener = listen_on_port($ssh_port) or skip "Couldn't start the ssh server: $!", $tests; my $ssl_listener = listen_on_port($ssl_port) or skip "Couldn't start the ssl server: $!", $tests; my ( $client, $server ); # try 'ssh' $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", $tests; sleep 1; # wait for the timeout $server = $ssh_listener->accept() or skip_fail "Proxy didn't connect: $!", $tests; # transmit data for my $line (@lines) { print $server $line; # real server speaks first is( <$client>, $line, "SSH line received" ); ( $client, $server ) = random_swap( $client, $server ); } # close connections $server->close(); is_closed( $client, 'peer' ); $client->close(); # try ssl $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", $tests; print $client $lines[0]; # real client speaks first $server = $ssl_listener->accept() or skip_fail "Proxy didn't connect: $!", $tests; is( <$server>, $lines[0], "SSL line received" ); # transmit the rest of the data shift @lines; for my $line ( @lines ) { ( $client, $server ) = random_swap( $client, $server ); print $client $line; # real client speaks first is( <$server>, $line, "SSL line received" ); } # close connections $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/31tcp_tcp_multi.t0000444000175000017500000001257210705511550017505 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use t::Util; use Net::Proxy; # dummy data my @lines = ( "swa_a_p bang swish bap crunch\n", "zlonk zok zapeth crunch_eth crraack\n", "glipp zwapp urkkk cr_r_a_a_ck glurpp\n", "zzzzzwap thwapp zgruppp awk eee_yow\n", "ker_plop spla_a_t swoosh cr_r_a_a_ck bang_eth pam uggh\n", "AEGEAN_NUMBER_NINETY MATHEMATICAL_SANS_SERIF_ITALIC_SMALL_Y\n", "YI_SYLLABLE_SHUX ARABIC_LIGATURE_THEH_WITH_REH_FINAL_FORM\n", "TAG_PLUS_SIGN CYPRIOT_SYLLABLE_RE\n", "TAG_LATIN_CAPITAL_LETTER_S YI_SYLLABLE_QYRX\n", "MATHEMATICAL_DOUBLE_STRUCK_CAPITAL_U HALFWIDTH_HANGUL_LETTER_YEO\n", "linguine lasagne_ricce chiocciole\n", "fusilli_tricolore sedani_corti galla_mezzana\n", "fettucce_ricce maniche chifferi_rigati\n", "mista lasagne_festonate_a_nidi nidi\n", "capelvenere parigine lacchene\n", "occhi_di_passero guanti ditali\n", ); # compute a seed and show it init_rand( @ARGV ); # compute random configurations my @confs = sort { $a->[0] <=> $b->[0] } map { [ int rand 16, int rand 8 ] } 1 .. 3; # compute the total number of tests my $tests = 1 + ( my $first = int rand 8 ); $tests += $_->[1] for @confs; $tests += 1 + @confs; # show the config if if( @ARGV ) { diag sprintf "%2d %2d", @$_ for ( [ 0, $first ], @confs ); } plan tests => $tests; # lock 2 ports my @ports = find_free_ports(3); SKIP: { skip "Not enough available ports", $tests if @ports < 3; my ($proxy_port, $server_port, $fake_port) = @ports; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port }, out => { type => 'tcp', host => 'localhost', port => $server_port }, } ); $proxy->register(); # test unregister() my $fake_proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $fake_port }, out => { type => 'tcp', host => 'localhost', port => $server_port }, } ); $fake_proxy->register(); $fake_proxy->unregister(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop( @confs + 1 ); exit; } else { # wait for the proxy to set up sleep 1; # start the server my $listener = listen_on_port($server_port) or skip "Couldn't start the server: $!", $tests; # create the first pair my %pairs; { my $pair = ( [ connect_to_port($proxy_port), scalar $listener->accept(), $first, 0 ] ); %pairs = ( $pair => $pair ); } # check the other proxy is not listening { my $client = connect_to_port($fake_port); is( $client, undef, "Second proxy not here: $!" ); } my $step = my $n = my $count = 0; while (%pairs || @confs) { # create a new connection CONF: while ( @confs && $confs[0][0] == $step ) { my $conf = shift @confs; my $client = connect_to_port($proxy_port) or do { diag "Couldn't start the client: $!"; next CONF; }; my $server = $listener->accept() or do { diag "Proxy didn't connect: $!"; next CONF; }; my $pair = [ $client, $server, $conf->[1], ++$count ]; $pairs{$pair} = $pair; } PAIR: for my $pair (values %pairs) { # close the connection if finished if ( $pair->[2] <= 0 ) { $pair->[0]->close(); is_closed( $pair->[1], "other socket of pair $pair->[3]" ); $pair->[1]->close(); delete $pairs{$pair}; next PAIR; } # fetch data to send $n %= @lines; my $line = $lines[$n]; # randomly swap client/server @{$pair}[ 0, 1 ] = random_swap(@{$pair}[ 0, 1 ]); # send data through the connection print { $pair->[0] } $line; is( $pair->[1]->getline(), $line, "Step $step: line $n sent through pair $pair->[3]" ); $pair->[2]--; $n++; } $step++; } } } } libnet-proxy-perl-0.12.orig/t/37connectssl_tcp.t0000444000175000017500000000752310705511550017666 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use File::Spec::Functions; use t::Util; use Net::Proxy; my @lines = ( "saturday wednesday tuesday sunday friday\n", "agnes_nitt granny_weatherwax greebo vorbis jason_ogg\n", "Moins Scrof Ferla_Quist Caine Grove_Of_The_Unicorn\n", "rook pawn queen king bishop\n", "Fedora QiLinux gnuLinEx ZoneCD ROSLIMS\n", ); my $tests = @lines + 3; init_rand(@ARGV); plan tests => $tests; SKIP: { # check required modules for this test case for my $module (qw( LWP::UserAgent HTTP::Daemon IO::Socket::SSL )) { eval "require $module;"; skip "$module required to test connect_ssl", $tests if $@; } # lock 2 ports my @free = find_free_ports(2); skip "Not enough available ports", $tests if @free < 2; my ($proxy_port, $web_proxy_port) = @free; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port }, out => { type => 'connect_ssl', host => 'zlonk.crunch.com', port => 443, proxy_host => 'localhost', proxy_port => $web_proxy_port, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(2); exit; } else { # wait for the proxy to set up sleep 1; # the parent process does the testing my $daemon = HTTP::Daemon->new( LocalAddr => 'localhost', LocalPort => $web_proxy_port, ) or skip "Couldn't start the server: $!", $tests; my $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", $tests; my $server = $daemon->accept() or skip_fail "Proxy didn't connect: $!", $tests; # the server will first play the role of the web proxy, # and after a 200 OK will also act as a real server # check the request my $req = $server->get_request(); is( $req->method(), 'CONNECT', 'Proxy did a CONNECT' ); is( $req->uri()->host_port(), 'zlonk.crunch.com:443', 'host:port' ); # first time, the web proxy says 200 $server->send_response( HTTP::Response->new('200') ); # now the client will use SSL IO::Socket::SSL->start_SSL( $server, SSL_server => 1, SSL_cert_file => catfile( 't', 'test.cert' ), SSL_key_file => catfile( 't', 'test.key' ), ); # send some data through # FIXME this blocks when $server speaks first for my $line (@lines) { print $client $line; is( <$server>, $line, "Line received" ); ( $client, $server ) = random_swap( $client, $server ); } $client->close(); $server->close(); # second time, the web proxy says 403 (how to test this?) $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", 1; $server = $daemon->accept() or skip_fail "Proxy didn't connect: $!", 1; $server->get_request(); # ignore it $server->send_response( HTTP::Response->new('403') ); is_closed($client); } } } libnet-proxy-perl-0.12.orig/t/05connector.t0000444000175000017500000000064110705511550016624 0ustar abiabiuse Test::More tests => 3; use strict; use warnings; use Net::Proxy; use Net::Proxy::Connector; my $c = Net::Proxy::Connector->new( ); isa_ok( $c, 'Net::Proxy::Connector' ); # proxy-related methods eval { $c->set_proxy( [] ); }; like( $@, qr/is not a Net::Proxy object/, 'set_proxy() wants a Net::Proxy' ); my $p = bless {}, 'Net::Proxy'; $c->set_proxy( $p ); is( $c->get_proxy, $p, 'Got the Net::Proxy back' ); libnet-proxy-perl-0.12.orig/t/test.cert0000444000175000017500000000232510705511550016137 0ustar abiabi-----BEGIN CERTIFICATE----- MIIDYzCCAsygAwIBAgIJALPGz4A6fiErMA0GCSqGSIb3DQEBBQUAMH8xCzAJBgNV BAYTAkZSMQ4wDAYDVQQIEwVDbHVuazEOMAwGA1UEBxMFVXJra2sxETAPBgNVBAoT CEZscmJiYmJiMQ4wDAYDVQQLEwVXaGFtbTEPMA0GA1UEAxMGU3dvb3NoMRwwGgYJ KoZIhvcNAQkBFg1ib29rQGNwYW4ub3JnMB4XDTA2MDcxOTIwNDUzN1oXDTE2MDcx NjIwNDUzN1owfzELMAkGA1UEBhMCRlIxDjAMBgNVBAgTBUNsdW5rMQ4wDAYDVQQH EwVVcmtrazERMA8GA1UEChMIRmxyYmJiYmIxDjAMBgNVBAsTBVdoYW1tMQ8wDQYD VQQDEwZTd29vc2gxHDAaBgkqhkiG9w0BCQEWDWJvb2tAY3Bhbi5vcmcwgZ8wDQYJ KoZIhvcNAQEBBQADgY0AMIGJAoGBANX+fpgs790z+RNQQkOfNWrfb4750/+KawiZ 4c2ue3S9FeqePaRg5fkl0yDmdShXRiXgOert5ksOSGQv40B5YljxkiuBVdy0WV76 elJRzeHyY4FcBQ/mrLcv/7tL0jGY4AdTeISXyPELr/9SCipZE57IrUcSbG53MePz K4tI8gbHAgMBAAGjgeYwgeMwHQYDVR0OBBYEFPCxvrQ+xr3Pds/Vi5nZMbVL4BVS MIGzBgNVHSMEgaswgaiAFPCxvrQ+xr3Pds/Vi5nZMbVL4BVSoYGEpIGBMH8xCzAJ BgNVBAYTAkZSMQ4wDAYDVQQIEwVDbHVuazEOMAwGA1UEBxMFVXJra2sxETAPBgNV BAoTCEZscmJiYmJiMQ4wDAYDVQQLEwVXaGFtbTEPMA0GA1UEAxMGU3dvb3NoMRww GgYJKoZIhvcNAQkBFg1ib29rQGNwYW4ub3JnggkAs8bPgDp+ISswDAYDVR0TBAUw AwEB/zANBgkqhkiG9w0BAQUFAAOBgQC2NEQXiDql6P9rcsDrHWJtFjpQn5Qy4J7G mqWYl8oVaMwwKyS/V0uXnhjkzj1y6HgjTDNKUJ8mTLr98TARxckq1MwEkhrqMRrz TOKr+IzWRB9gySpKAOyIgX+0dSX+dHOn9goNg9tNa47EgHioKRg6hUoSCR+7p8M6 4oSjpGGBpQ== -----END CERTIFICATE----- libnet-proxy-perl-0.12.orig/t/pod-coverage.t0000444000175000017500000000144110705511550017037 0ustar abiabiuse Test::More; use File::Find; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; my @modules; find( sub { push @modules, $File::Find::name if /\.pm$/ }, 'blib/lib' ); @modules = sort map { s!/!::!g; s/\.pm$//; s/^blib::lib:://; $_ } @modules; plan tests => scalar @modules; pod_coverage_ok($_) for grep { !/::Connector::/ } @modules; pod_coverage_ok( $_, { trustme => [qr/^(?:listen|accept_from|connect|read_from|write_to|init)$/] } ) for grep { !/::connect_ssl/ } grep {/::Connector::/} @modules; pod_coverage_ok( $_, { trustme => [qr/^(?:listen|accept_from|connect|read_from|write_to|init|upgrade_SSL)$/] } ) for grep { /::connect_ssl/ } @modules; libnet-proxy-perl-0.12.orig/t/36tcp_ssl.t0000444000175000017500000000526010705511550016307 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use File::Spec::Functions; use t::Util; use Net::Proxy; my @lines = ( "oscar delta sierra echo papa\n", "Laurent_Fignon Henri_Pelissier Lucien_Petit_Breton Firmin_Lambot\n", "Toronto London Herzliya Melbourne Munich\n", "holy_icepicks holy_corpusles holy_Luthor_Burbank holy_hyperdermics\n", "Woody_Long Alicia_Rio Dorothy_Le_May Janine_Lindemulder Barbara_Summer\n", ); my $tests = @lines; my $all_tests = $tests + 1; plan tests => $all_tests; init_rand(@ARGV); # lock 2 ports my @free = find_free_ports(2); SKIP: { eval { require IO::Socket::SSL; }; skip 'IO::Socket::SSL required to test ssl', $all_tests if $@; skip 'Not enough available ports', $all_tests if @free < 2; no warnings 'once'; $IO::Socket::SSL::DEBUG = $ENV{NET_PROXY_VERBOSITY} || 0; my ( $proxy_port, $server_port ) = @free; my $pid = fork; skip 'proxy fork failed', $tests if !defined $pid; if ( $pid == 0 ) { my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port, timeout => 1, }, out => { type => 'ssl', host => 'localhost', port => $server_port, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(1); exit; } else { SKIP: { # wait for the proxy to set up sleep 1; # start a SSL server my $listener = IO::Socket::SSL->new( Listen => 1, LocalAddr => 'localhost', LocalPort => $server_port, Proto => 'tcp', SSL_cert_file => catfile( 't', 'test.cert' ), SSL_key_file => catfile( 't', 'test.key' ), ) or skip "Couldn't start the server: $!", $tests; # start a client my $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", $tests; my $server = $listener->accept() or skip "Proxy didn't connect: $!", $tests; for my $line (@lines) { ( $client, $server ) = random_swap( $client, $server ); print $client $line; is( <$server>, $line, "Line received" ); } $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/22dual.t0000444000175000017500000000350510705511550015560 0ustar abiabiuse strict; use warnings; use Test::More tests => 10; use Net::Proxy::Connector; use Net::Proxy::Connector::dual; my $c; my $args = {}; eval { $c = Net::Proxy::Connector::dual->new($args); }; like( $@, qr/^'client_first' connector required /, 'No client_first' ); $args->{client_first} = 1; eval { $c = Net::Proxy::Connector::dual->new($args); }; like( $@, qr/^'client_first' connector must be a HASHREF /, 'client_first not HASHREF' ); $args->{client_first} = {}; eval { $c = Net::Proxy::Connector::dual->new($args); }; like( $@, qr/^'type' key required for 'client_first' connector /, 'No type for client_first' ); $args->{client_first} = { type => 'zlonk' }; eval { $c = Net::Proxy::Connector::dual->new($args); }; like( $@, qr/^Couldn't load Net::Proxy::Connector::zlonk for 'client_first' connector: /, 'Bad connector type for client_first' ); $args->{client_first} = { type => 'tcp' }; $args->{_proxy_} = bless {}, 'Net::Proxy'; eval { $c = Net::Proxy::Connector::dual->new( $args ); }; like( $@, qr/^'server_first' connector required /, 'No server_first' ); $args->{server_first} = 1; eval { $c = Net::Proxy::Connector::dual->new($args); }; like( $@, qr/^'server_first' connector must be a HASHREF /, 'server_first not HASHREF' ); $args->{server_first} = { type => 'zowie' }; eval { $c = Net::Proxy::Connector::dual->new($args); }; like( $@, qr/^Couldn't load Net::Proxy::Connector::zowie for 'server_first' connector: /, 'Bad connector type for server_first' ); $args->{server_first} = { type => 'tcp' }; eval { $c = Net::Proxy::Connector::dual->new( $args ); }; like( $@, qr/^Parameter 'port' is required /, 'No port' ); $args->{port} = 444; eval { $c = Net::Proxy::Connector::dual->new( $args ); }; is( $@, '', 'dual object created'); isa_ok( $c, 'Net::Proxy::Connector::dual' ); libnet-proxy-perl-0.12.orig/t/34hook_out.t0000444000175000017500000000546010705511550016467 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use t::Util; use Net::Proxy; my @lines = ( [ "swa_a_p zamm swish bap crunch\n", "swa_a_p zowie swish bap crunch\n" ], [ "zlonk zok zapeth crunch_eth crraack\n", "zowie zowie zowie crunch_eth crraack\n" ], [ "glipp zwapp urkkk cr_r_a_a_ck glurpp\n", "glipp zowie urkkk cr_r_a_a_ck glurpp\n" ], [ "zzzzzwap thwapp zgruppp awk eee_yow\n", "zowie thwapp zowie awk eee_yow\n" ], ); my $tests = @lines + 1; plan tests => $tests; init_rand(@ARGV); # lock 2 ports my @free = find_free_ports(2); SKIP: { skip "Not enough available ports", $tests if @free < 2; my ( $proxy_port, $server_port ) = @free; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port, timeout => 1, }, out => { type => 'tcp', host => 'localhost', port => $server_port, hook => sub { my ($dataref, $sock, $connector) = @_; $$dataref =~ s/\bz\w+/zowie/g; }, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(1); exit; } else { # wait for the proxy to set up sleep 1; # the parent process does the testing my $listener = listen_on_port($server_port) or skip "Couldn't start the server: $!", $tests; my $client = connect_to_port($proxy_port) or skip "Couldn't start the client: $!", $tests; my $server = $listener->accept() or skip "Proxy didn't connect: $!", $tests; # data from the client is transformed by the hook my $orig_server = $server; for my $line (@lines) { # anyone speaks first ( $client, $server ) = random_swap( $server, $client ); # send some data through print $client $line->[0]; my $trans = $server ne $orig_server; is( <$server>, $line->[$trans], "Line received " . ( "intact", "transformed" )[$trans] ); } $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/20dummy.t0000444000175000017500000000063110705511550015761 0ustar abiabiuse Net::Proxy::Connector::dummy; use Test::More tests => 4; # these are dummy calls to the dummy connector # (mostly to raise coverage) my $conn = Net::Proxy::Connector::dummy->new(); is( $conn->read_from( '' ), '', 'read_from()' ); eval { $conn->write_to(); }; is( $@, '', 'write_to()' ); eval { $conn->listen(); }; is( $@, '', 'listen()' ); eval { $conn->accept_from(); }; is( $@, '', 'accept_from()' ); libnet-proxy-perl-0.12.orig/t/32tcp_connect.t0000444000175000017500000000712110705511550017131 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use t::Util; use Net::Proxy; my @lines = ( "fettuccia_riccia galla_genovese sedanetti pennine_rigate gobboni\n", "fenescecchie barbina gianduini umbricelli maniche\n", "gozzetti pepe tofarelle anelli_margherite_lisce farfallette\n", "sciviotti_ziti_rigati gobbini gomiti cravattine penne_di_zitoni\n", "amorosi cuoricini cicorie tempestina tortellini\n", ); my $tests = @lines + 3; init_rand(@ARGV); plan tests => $tests; SKIP: { # check required modules for this test case for my $module (qw( LWP::UserAgent HTTP::Daemon )) { eval "require $module;"; skip "$module required to test connect", $tests if $@; } # lock 2 ports my @free = find_free_ports(2); skip "Not enough available ports", $tests if @free < 2; my ($proxy_port, $web_proxy_port) = @free; my $pid = fork; SKIP: { skip "fork failed", $tests if !defined $pid; if ( $pid == 0 ) { # the child process runs the proxy my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port }, out => { type => 'connect', host => 'zlonk.crunch.com', port => 443, proxy_host => 'localhost', proxy_port => $web_proxy_port, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(2); exit; } else { # wait for the proxy to set up sleep 1; # the parent process does the testing my $daemon = HTTP::Daemon->new( LocalAddr => 'localhost', LocalPort => $web_proxy_port, ) or skip "Couldn't start the server: $!", $tests; my $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", $tests; my $server = $daemon->accept() or skip_fail "Proxy didn't connect: $!", $tests; # the server will first play the role of the web proxy, # and after a 200 OK will also act as a real server # check the request my $req = $server->get_request(); is( $req->method(), 'CONNECT', 'Proxy did a CONNECT' ); is( $req->uri()->host_port(), 'zlonk.crunch.com:443', 'host:port' ); # first time, the web proxy says 200 $server->send_response( HTTP::Response->new('200') ); # send some data through # FIXME this blocks when $server speaks first for my $line (@lines) { print $client $line; is( <$server>, $line, "Line received" ); ( $client, $server ) = random_swap( $client, $server ); } $client->close(); $server->close(); # second time, the web proxy says 403 (how to test this?) $client = connect_to_port($proxy_port) or skip_fail "Couldn't start the client: $!", 1; $server = $daemon->accept() or skip_fail "Proxy didn't connect: $!", 1; $server->get_request(); # ignore it $server->send_response( HTTP::Response->new('403') ); is_closed($client); } } } libnet-proxy-perl-0.12.orig/t/36ctssl_tcp.t0000444000175000017500000000640010705511550016633 0ustar abiabiuse Test::More; use strict; use warnings; use IO::Socket::INET; use File::Spec::Functions; use t::Util; use Net::Proxy; my @lines = ( "pete_peters sophie les mr_dork vijay\n", "d_fence abacus_remote ups_onlinet d2k_datamover2 ssslog_mgr\n", "Scooby_Doo Velma Freddy Daphne Shaggy\n", "STARTTLS\n", "Brian Florence Dougal Ermintrude Zebedee\n", "ale sherry cider wine whiskey\n", "Arcadio The_Witch_of_Kaan Drumm Rufferto Gravito\n", ); my $tests = @lines; my $all_tests = $tests + 1; plan tests => $all_tests; init_rand(@ARGV); # lock 2 ports my @free = find_free_ports(2); SKIP: { eval { require IO::Socket::SSL; }; skip 'IO::Socket::SSL required to test ssl', $all_tests if $@; skip 'Not enough available ports', $all_tests if @free < 2; no warnings 'once'; $IO::Socket::SSL::DEBUG = $ENV{NET_PROXY_VERBOSITY} || 0; my ( $proxy_port, $server_port ) = @free; my $pid = fork; skip 'proxy fork failed', $tests if !defined $pid; if ( $pid == 0 ) { my $proxy = Net::Proxy->new( { in => { type => 'ssl', port => $proxy_port, timeout => 1, start_cleartext => 1, SSL_cert_file => catfile( 't', 'test.cert' ), SSL_key_file => catfile( 't', 'test.key' ), hook => sub { my ( $dataref, $sock, $connector ) = @_; if ( $$dataref =~ s/^STARTTLS\n// ) { print $sock "OK\n"; $connector->upgrade_SSL($sock); } }, }, out => { type => 'tcp', host => 'localhost', port => $server_port, }, } ); $proxy->register(); Net::Proxy->set_verbosity( $ENV{NET_PROXY_VERBOSITY} || 0 ); Net::Proxy->mainloop(1); exit; } else { SKIP: { # wait for the proxy to set up sleep 1; # start a server my $listener = listen_on_port($server_port) or skip "Couldn't start the server: $!", $tests; # start a client my $client = connect_to_port($proxy_port) or skip "Couldn't start the client: $!", $tests; my $server = $listener->accept() or skip "Proxy didn't connect: $!", $tests; # remember which was the original client my $o_client = $client; # exchange the data for my $line (@lines) { ( $client, $server ) = random_swap( $client, $server ); if( $line eq "STARTTLS\n" ) { print $o_client $line; is( <$o_client>, "OK\n", "STARTTLS acknowledged" ); IO::Socket::SSL->start_SSL($o_client); } else { print $client $line; is( <$server>, $line, "Line received" ); } } $client->close(); is_closed( $server, 'peer' ); $server->close(); } } } libnet-proxy-perl-0.12.orig/t/41listen_fail.t0000444000175000017500000000151610705511550017125 0ustar abiabiuse Test::More; use strict; use warnings; use t::Util; use Net::Proxy; plan tests => my $tests = 1; # lock 2 ports my @free = find_free_ports(2); SKIP: { skip "Not enough available ports", $tests if @free < 2; my ( $proxy_port, $server_port ) = @free; my $server = listen_on_port( $proxy_port ) or skip "Failed to lock port $proxy_port", $tests; my $proxy = Net::Proxy->new( { in => { type => 'tcp', host => 'localhost', port => $proxy_port, }, out => { type => 'tcp', host => 'localhost', port => $server_port, }, }, ); $proxy->register(); eval { Net::Proxy->mainloop(); }; like( $@, qr/^Can't listen on localhost port \d+: /, 'Port in use' ); } libnet-proxy-perl-0.12.orig/t/12proxy_connectors.t0000444000175000017500000000104410705511550020244 0ustar abiabiuse strict; use warnings; use Test::More tests => 5; use Net::Proxy; my $proxy = Net::Proxy->new( { in => { type => 'dummy' }, out => { type => 'dummy' }, } ); isnt( $proxy->in_connector(), $proxy->out_connector(), 'Distinct connectors' ); ok( $proxy->in_connector()->is_in(), 'in_connector() is "in"' ); ok( !$proxy->out_connector()->is_in(), 'out_connector() is not "in"' ); ok( !$proxy->in_connector()->is_out(), 'in_connector() is not "out"' ); ok( $proxy->out_connector()->is_out(), 'out_connector() is "out"' ); libnet-proxy-perl-0.12.orig/lib/0000755000175000017500000000000010705511550014604 5ustar abiabilibnet-proxy-perl-0.12.orig/lib/Net/0000755000175000017500000000000010705511550015332 5ustar abiabilibnet-proxy-perl-0.12.orig/lib/Net/Proxy/0000755000175000017500000000000010705511550016453 5ustar abiabilibnet-proxy-perl-0.12.orig/lib/Net/Proxy/Connector.pm0000444000175000017500000002120710705511550020743 0ustar abiabipackage Net::Proxy::Connector; use strict; use warnings; use Carp; use Scalar::Util qw( refaddr ); use Net::Proxy; my %PROXY_OF; my $BUFFSIZE = 4096; # # the most basic possible constructor # sub new { my ( $class, $args ) = @_; my $self = bless $args ? {%$args} : {}, $class; $self->init() if $self->can('init'); delete $self->{_proxy_}; # this link back is now unnecessary return $self; } # # Each Connector is managed by a Net::Proxy object # sub set_proxy { my ( $self, $proxy ) = @_; croak "$proxy is not a Net::Proxy object" if !UNIVERSAL::isa( $proxy, 'Net::Proxy' ); return $PROXY_OF{ refaddr $self } = $proxy; } sub get_proxy { return $PROXY_OF{ refaddr $_[0] }; } sub is_in { my $id = refaddr $_[0]; return $id == refaddr $PROXY_OF{$id}->in_connector(); } sub is_out { my $id = refaddr $_[0]; return $id == refaddr $PROXY_OF{$id}->out_connector(); } # # the method that creates all the sockets # sub new_connection_on { my ( $self, $listener ) = @_; Net::Proxy->notice( 'New connection on ' . Net::Proxy->get_nick($listener) ); # call the actual Connector method my $sock = eval { $self->accept_from($listener); }; if( $@ ) { Net::Proxy->error( $@ ); return; } Net::Proxy->set_connector( $sock, $self ); Net::Proxy->set_buffer( $sock, '' ); Net::Proxy->set_callback( $sock, $self->{hook} ) if $self->{hook}; Net::Proxy->watch_reader_sockets($sock); # connect to the destination my $out = $self->get_proxy()->out_connector(); $out->_out_connect_from($sock); # update the stats $self->get_proxy()->stat_inc_opened(); return; } sub _out_connect_from { my ( $self, $sock ) = @_; my $peer = eval { $self->connect(); }; if ($@) { # connect() dies if the connection fails $@ =~ s/ at .*?\z//s; warn "connect() failed with error '$@'\n"; Net::Proxy->close_sockets($sock); return; } if ($peer) { # $peer is undef for Net::Proxy::Connector::dummy Net::Proxy->watch_reader_sockets($peer); Net::Proxy->set_connector( $peer, $self ); Net::Proxy->set_buffer( $peer, '' ); Net::Proxy->set_callback( $peer, $self->{hook} ) if $self->{hook}; Net::Proxy->set_nick( $peer, $peer->sockhost() . ':' . $peer->sockport() . ' -> ' . $peer->peerhost() . ':' . $peer->peerport() ); Net::Proxy->notice( 'Connected ' . Net::Proxy->get_nick( $peer ) ); Net::Proxy->set_peer( $peer, $sock ); Net::Proxy->set_peer( $sock, $peer ); Net::Proxy->notice( 'Peered ' . Net::Proxy->get_nick($sock) . ' with ' . Net::Proxy->get_nick($peer) ); } return; } # # base methods for exchanging raw data # # return raw data from the socket sub raw_read_from { my ( $self, $sock ) = @_; # low level read on the socket my $close = 0; my $buffer; my $read = $sock->sysread( $buffer, $BUFFSIZE ); ## Net::Proxy->debug("Read $read bytes from " . Net::Proxy->get_nick($sock)); # check for errors if ( not defined $read ) { warn sprintf( "Read undef from %s:%s (Error %d: %s)\n", $sock->sockhost(), $sock->sockport(), $!, "$!" ); $close = 1; } # connection closed if ( $close || $read == 0 ) { my $peer = Net::Proxy->get_peer($sock); $self->get_proxy()->close_sockets( $sock, $peer ); return; } return $buffer; } # send raw data to the socket sub raw_write_to { my ($self, $sock) = @_; my $data = Net::Proxy->get_buffer( $sock ); ## Net::Proxy->debug("Writing @{[length $data]} bytes (max $BUFFSIZE) to " . Net::Proxy->get_nick($sock)); my $written = $sock->syswrite( $data, $BUFFSIZE ); ## Net::Proxy->debug("Wrote $written bytes to " . Net::Proxy->get_nick($sock)); if( ! defined $written ) { warn sprintf("Read undef from %s:%s (Error %d: %s)\n", $sock->sockhost(), $sock->sockport(), $!, "$!"); } elsif ( $written == length $data ) { Net::Proxy->remove_writer_sockets( $sock ); Net::Proxy->set_buffer( $sock, '' ); } else { # there is some data left to write Net::Proxy->set_buffer( $sock, substr( $data, $written ) ); } return; } # # base methods for listen() and accept_from() # # the most basic possible listen() sub raw_listen { my $self = shift; my $sock = IO::Socket::INET->new( Listen => 1, LocalAddr => $self->{host}, LocalPort => $self->{port}, Proto => 'tcp', ReuseAddr => $^O eq 'MSWin32' ? 0 : 1, ); # this exception is not catched by Net::Proxy die "Can't listen on $self->{host} port $self->{port}: $!" unless $sock; Net::Proxy->set_nick( $sock, 'listener ' . $sock->sockhost() . ':' . $sock->sockport() ); return $sock; } # accept on a socket and return the new connected socket sub raw_accept_from { my ($self, $listen) = @_; my $sock = $listen->accept(); die $! unless $sock; Net::Proxy->set_nick( $sock, $sock->peerhost() . ':' . $sock->peerport() . ' -> ' . $sock->sockhost() . ':' . $sock->sockport() ); Net::Proxy->notice( 'Accepted ' . Net::Proxy->get_nick( $sock ) ); return $sock; } 1; __END__ =head1 NAME Net::Proxy::Connector - Base class for Net::Proxy protocols =head1 SYNOPSIS # # template for the zlonk connector # package Net::Proxy::Connector::zlonk; use strict; use Net::Proxy::Connector; our @ISA = qw( Net::Proxy::Connector ); # here are the methods you need to write for your connector # if it can be used as an 'in' connector sub listen { } sub accept_from { } # if it can be used as an 'out' connector sub connect { } # to process data sub read_from { } sub write_to { } 1; =head1 DESCRIPTION C is the base class for all specialised protocols used by C. =head1 METHODS =head2 Class methods The base class provides the following methods: =over 4 =item new() =back =head2 Instance methods =over 4 =item set_proxy( $proxy ) Define the proxy that "owns" the connector. =item get_proxy() Return the C object that "owns" the connector. =item is_in() Return a boolean value indicating if the C object is the C connector of its proxy. =item is_out() Return a boolean value indicating if the C object is the C connector of its proxy. =item new_connection_on( $socket ) This method is called by C to handle incoming connections, and in turn call C on the 'in' connector and C on the 'out' connector. =item raw_read_from( $socket ) This method can be used by C subclasses in their C methods, to fetch raw data on a socket. =item raw_write_to( $socket, $data ) This method can be used by C subclasses in their C methods, to send raw data on a socket. =item raw_listen( ) This method can be used by C subclasses in their C methods, to create a listening socket on their C and C parameters. =item raw_accept_from( $socket ) This method can be used internaly by C subclasses in their C methods, to accept a newly connected socket. =back =head1 Subclass methods The following methods should be defined in C subclasses: =head2 Initialisation =over 4 =item init() This method initalise the connector. =back =head2 Processing incoming/outgoing data =over 4 =item read_from( $socket ) Return the data that was possibly decapsulated by the connector. =item write_to( $socket, $data ) Write C<$data> to the given C<$socket>, according to the connector scheme. =back =head2 C connector =over 4 =item listen() Initiate listening sockets and return them. This method can use the C method to do the low-level listen call. =item accept_from( $socket ) C<$socket> is a listening socket created by C. This method returns the connected socket. This method can use the C method to do the low-level accept call. =back =head2 C connector =over 4 =item connect() Return a socket connected to the remote server. =back =head1 AUTHOR Philippe 'BooK' Bruhat, C<< >>. =head1 COPYRIGHT Copyright 2006 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/lib/Net/Proxy/Tutorial.pod0000444000175000017500000003522010705511550020762 0ustar abiabi=head1 NAME Net::Proxy::Tutorial - Network proxies for fun and profit =head1 SYNOPSIS This document describes in detail how to use C in several real-life situations. =head1 DEFINITIONS =head2 What is a proxy? You need a proxy every time you need to cross network boundaries to reach a service that is not directly accessible. The typical example is the corporate web proxy in a company. The corporate firewall is a boundary, usually very tightly closed, between the corporate network and the outside world (wild wild Internet). To let the employees access all the nice web sites outside, the company sets up a web proxy, which is authorised to cross the boundary (firewall) on your behalf. The web browser asks the proxy for whatever it needs, and the proxy goes and fetches the requested stuff on the web. Since the proxy sees the client requests, it can check if they fit the corporate browsing policy and decide if it will fetch the document for the requestor. It can also request authentication, and log the username with the request. Transparent proxies mimic the actual service you asked for, and reply as if they were the actual service provider. Except that the client doesn't notice there is a proxy in between. Most transparent web proxies grab outgoing traffic on port 80. Some ISP do this to cache responses and spare their bandwidth. =head2 Why do I need a proxy? Sometimes, the traffic you want to send or receive doesn't quite fit the model that the network designers had in mind. For example, if you need to modify network traffic, almost transparently, at a high level, you probably need C. =head1 DESCRIPTION In this section, we will see actual examples of use of C. =head2 A basic C script Most C based scripts look like the following: =over 4 =item * The usual boilerplate: #!perl use strict; use warnings; use Net::Proxy; =item * One or more proxies are created by calling C with the appropriate parameters: my $proxy = Net::Proxy->new( ... ); =item * The individual proxies are registered with the C framework: $proxy->register(); =item * Some framework options are defined: Net::Proxy->set_verbosity(1); Note: The C method is available only since C version 0.04. =item * The framework is started, sets up the listening sockets, and waits for connections to proxy around: Net::Proxy->mainloop(); =back =head2 The concepts behind C Any time a proxy handles a network connection, it actually manages two connections: a connection from the client to the proxy, and a connection from the proxy to the server. During normal processing, each chunk of data received on one connection is copied to the other connection, and vice-versa. C introduces the concept of "connectors". Connectors are used to represent the ends of the two connections that the proxy handles to create a single client-server connection. +-------+ | proxy | | | "client" --->(xx)[in] [out]---> "server" +-------+ In the above ASCII diagram, C<(xx)> represents the listening port number, and C<[in]> (left) and C<[out]> (right) the C connectors. The C connector accepts incoming connections on a listening port. Once a connection with the client is established, the proxy uses the C connector to connect to the destination server. The simplest connector is named C (we'll use C for short). When placed on the C side, it simply Cs for incoming connections and them Cs them. Then the C connector Cs to the server. Each connector accepts different parameters, which we'll see in the following examples. Since the proxy must handle every item of data going through, it can look at it, and modify it. This is what other connectors do: they can insert or transform data on the fly, which provides us with an incredible amount of power on our network connections, which we will leverage throughout this document. =head1 REAL-LIFE EXAMPLES =head2 Contacting a SSH server through the corporate web proxy (This example requires at least C version 0.02 to work.) In many companies, the corporate firewall doesn't let you connect outside with SSH. The only allowed access to the outside is via the web proxy. Luckily, web proxies are designed to let certain types of TCP connection go through them without modifications: encrypted SSL connections, used in HTTPS. These connections are handled in the following way: the client sends a C connect to the proxy which (according to a policy based on the hostname, port and the user's credentials) actually connects to the remote host and transfers the data between the client and server, without looking at the encrypted data. The proxy doesn't even check that the traffic is actual SSL traffic. So your SSH client could connect to a local proxy, which would send the C request to the web proxy, asking for a connection to your home SSH server. Thereafter, the local proxy would behave like a standard TCP proxy and simply pass the data around. Here is a network diagram showing the network configuration in ASCII-art: ' (internal network) ' (Internet) ' +-------+ +-------+ ' +-------+ | local | | web | ' | ssh | ssh | proxy | | proxy | ' | server| client --->(22)[tcp] | | | ' | | |[connect]-->(8080) |----'--->(22) | +-------+ +-------+ ' +-------+ ' ' Here's how to set up the local C instance: Net::Proxy->new( in => { type => 'tcp', host => 'localhost', port => 22, }, out => { type => 'connect', host => 'home.example.com', port => 22, # proxy details proxy_host => 'proxy.mycompany.com', proxy_port => 8080, # proxy credentials proxy_user => 'me', proxy_pass => 's3kr3t', }, )->register(); Most of the time, corporate web proxies do not allow connections on other ports than 443, the standard HTTPS port. You just need to reconfigure your SSH server so that it also listens on port 443: # sshd configuration file Port 22 Port 443 In the exemple above, you need to change the C/C from C<22> to C<443>. Many SSH clients (like PuTTY) already include configuration options to get through web proxies, so C probably isn't necessary any longer to handle this kind of traffic. =head2 Running two services on the same TCP port (This example requires at least C version 0.03 to work.) So you managed to get out of your corporate prison^Wnetwork by setting up your SSH server to listen on port 443. The problem is that you also run a HTTPS server; and if you want it to be accessible to anyone, it must run on port 443 (otherwise the corporate proxy won't let you pass through, and noone will find it anyway). Therefore, the only option is to run both the SSL web server and the SSH server on I. How is that even possible? TCP clearly doesn't allow this (or we wouldn't need those long F files in our F directories). What you need is a proxy that can guess what the client wants, but without contacting the server. If it manages to find out which server the client wants to connect to, it can then contact the expected server and do its usual proxy job. Luckily, there is a fundamental difference of behaviour between a http/s client and a SSH client: =over 4 =item * during a HTTP(S) connection, the client "speaks" first =item * during a SSH connection, the server sends a banner first =back ' (Internet) ' (internal network) ' ' +-------+ ' |reverse| ' | proxy | SSL client ---'--->( | [tcp]---> SSL server ' ((443)[dual] | SSH client ---'--->( | [tcp]---> SSH server ' +-------+ ' C's C connector is able to detect between two such clients with the help of a timeout. Net::Proxy->new( { in => { type => 'dual', host => '0.0.0.0', port => 443, client_first => { type => 'tcp', port => 444, # move the https server to another port }, server_first => { type => 'tcp', port => 22, # good old SSH }, # wait during a 2 second timeout timeout => 2, }, out => { type => 'dummy' }, } )->register(); =head2 Hiding SSH connections going through the corporate proxy from IDS (This example requires at least C version 0.06 to work.) The first technique we presented (using a CONNECT request to get out of the corporate network) is so well-known that many Intrusion Detection Systems (IDS) check the first packets of a connection to try and find hidden SSH connections crossing the corporate boundaries outwards. The server banner looks like this: SSH-2.0-OpenSSH_3.9p1 while the client banner may look like this: SSH-2.0-OpenSSH_4.2p1 Debian-5 You want to deceive Intrusion Detection Systems (IDS) by modifying the cleartext part of your SSH connection. Since the detection code simply looks for the "C" string, an "encryption" scheme as simple as ROT-13 is enough. ' (internal network) ' (Internet) ' +-------+ +-------+ ' +-------+ | local | | web | ' |reverse| ssh | proxy | | proxy | ' | proxy | client --->(22)[tcp] | | | ' | | |[connect]===>(8080) |===='===>(443)[tcp][tcp]---> ssh +-------+ +-------+ ' +-------+ server ' Traffic \________ ________/' ---> ssh v ' ===> ssh + rot13 Traffic scanned ' by the IDS ' ' The C connector option accepts a callback that will be called for each chunk of data received, before sending it out. The callback must have the following signature: # Net::Proxy versions 0.06 and 0.07 sub { my ( $dataref, $connector ) = @_; ... } # As from Net::Proxy version 0.08 sub { my ( $dataref, $socket, $connector ) = @_; ... } The ROT-13 routine is straightforward (and must be defined in both scripts): my $rot13 = sub { ${ $_[0] } =~ y/A-Za-z/N-ZA-Mn-za-m/ }; Client-side proxy: Net::Proxy->new( { in => { type => 'tcp', host => '0.0.0.0', port => 22, hook => $rot13 }, out => { type => 'connect', host => 'home.example.com', port => 22, hook => $rot13, # proxy configuration proxy_host => 'proxy.mycompany.com', proxy_port => 8080, # proxy credentials proxy_user => 'me', proxy_pass => 's3kr3t', }, } )->register(); Server-side proxy: Net::Proxy->new( { in => { type => 'tcp', host => '0.0.0.0', port => 443, hook => $rot13 }, out => { type => 'tcp', port => 22, hook => $rot13 } } )->register(); =head2 Hiding a SSH connection under SSL through a corporate proxy (This example requires at least C version 0.08 to work.) Another option to hide what you are doing in your connection through the corporate proxy, is to actually use SSL to connect to your SSH server (I<à la> B). This is what the proxy expects, after all. ' (internal network) ' (Internet) ' +-----------+ +-------+ ' +-------+ | local | | web | ' |reverse| ssh | proxy | | proxy | ' | proxy | client -->(22)[tcp] | | | ' | | |[connect_ssl]===>(8080) |==='==>(443)[ssl][tcp]---> ssh +-----------+ +-------+ ' +-------+ server ' Traffic \_______ _______/' ---> ssh v ' ===> ssh over SSL Traffic scanned ' by the IDS ' ' Client-side proxy: Net::Proxy->new( { in => { type => 'tcp', host => '0.0.0.0', port => 22, }, out => { type => 'connect_ssl', host => 'home.example.com', port => 443, # proxy configuration proxy_host => 'proxy.mycompany.com', proxy_port => 8080, # proxy credentials proxy_user => 'me', proxy_pass => 's3kr3t', }, } )->register(); Server-side proxy: Net::Proxy->new( { in => { type => 'ssl', host => '0.0.0.0', port => 443, }, out => { type => 'tcp', port => 22, } } )->register(); =head1 AUTHOR Philippe "BooK" Bruhat, C<< >>. =head1 COPYRIGHT Copyright 2006-2007 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This tutorial is distributed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License. =cut libnet-proxy-perl-0.12.orig/lib/Net/Proxy/Connector/0000755000175000017500000000000010705511550020405 5ustar abiabilibnet-proxy-perl-0.12.orig/lib/Net/Proxy/Connector/dual.pm0000444000175000017500000000771710705511550021702 0ustar abiabipackage Net::Proxy::Connector::dual; use strict; use warnings; use Carp; use Scalar::Util qw( reftype ); use Net::Proxy::Connector; our @ISA = qw( Net::Proxy::Connector ); sub init { my ($self) = @_; # check connectors for my $conn (qw( client_first server_first )) { croak "'$conn' connector required" if !exists $self->{$conn}; croak "'$conn' connector must be a HASHREF" if ref $self->{$conn} ne 'HASH'; croak "'type' key required for '$conn' connector" if !exists $self->{$conn}{type}; croak "'hook' key is not a CODE reference for '$conn' connector" if $self->{$conn}{hook} && reftype( $self->{$conn}{hook} ) ne 'CODE'; # load the class my $class = 'Net::Proxy::Connector::' . $self->{$conn}{type}; eval "require $class"; croak "Couldn't load $class for '$conn' connector: $@" if $@; # create and store the Connector object $self->{$conn} = $class->new( $self->{$conn} ); $self->{$conn}->set_proxy($self->{_proxy_}); } # other parameters croak q{Parameter 'port' is required} if !exists $self->{port}; $self->{timeout} ||= 1; # by default wait for one second $self->{host} ||= 'localhost'; # by default listen on localhost return; } # IN *listen = \&Net::Proxy::Connector::raw_listen; sub accept_from { my ( $self, $listen ) = @_; my $sock = $self->raw_accept_from($listen); # find out who speaks first # if the client talks first, it's a client_first connection my $waiter = IO::Select->new($sock); my @waited = $waiter->can_read( $self->{timeout} ); my $type = @waited ? 'client_first' : 'server_first'; # do the outgoing connection $self->{$type}->_out_connect_from($sock); return $sock; } # OUT # READ *read_from = \&Net::Proxy::Connector::raw_read_from; # WRITE *write_to = \&Net::Proxy::Connector::raw_write_to; 1; __END__ =head1 NAME Net::Proxy::Connector::dual - Y-shaped Net::Proxy connector =head1 DESCRIPTION C is a C that can forward the connection to two distinct services, based on the client connection, before any data is exchanged. =head1 CONNECTOR OPTIONS This connector can only work as an C connector. The C and C options are required: they are hashrefs containing the options necessary to create two C C objects that will be used to connect to the requested service. The C object decides between the two services by waiting during a short timeout. If the client sends some data directly, then it is connected via the C connector. Otherwise, at the end of the timeout, it is connected via the C connector. =over 4 =item * host The hostname on which the connector will listen for client connections. Default is C. =item * port The port on which the connector will listen for client connections. =item * server_first Typically an C connector to a SSH server or any service that sends a banner line. =item * client_first Typically an C connectrot to a web server or SSL server. =item * timeout The timeout in seconds (can be decimal) to make a decision. Default is 1 second. =back =head1 AUTHOR Philippe 'BooK' Bruhat, C<< >>. =head1 ACKNOWLEDGMENTS This module is based on a script named B, which I wrote with Frédéric Plé C<< >> (who had the original insight about the fact that not all servers speak first on the wire). Frédéric wrote a C program, while I wrote a Perl script (based on my experience with B). Now that C is available, I've ported the Perl script to use it. =head1 COPYRIGHT Copyright 2006 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/lib/Net/Proxy/Connector/connect.pm0000444000175000017500000001030410705511550022370 0ustar abiabipackage Net::Proxy::Connector::connect; use strict; use warnings; use Carp; use LWP::UserAgent; use Net::Proxy::Connector; our @ISA = qw( Net::Proxy::Connector ); sub init { my ($self) = @_; # check params for my $attr (qw( host port )) { croak "$attr parameter is required" if !exists $self->{$attr}; } # create a user agent class linked to this connector $self->{agent} = my $ua = LWP::UserAgent->new( agent => $self->{proxy_agent}, keep_alive => 1, ); # set the agent proxy if ( $self->{proxy_host} ) { $self->{proxy_port} ||= 8080; $self->{proxy_pass} ||= ''; my $auth = $self->{proxy_user} ? "$self->{proxy_user}:$self->{proxy_pass}\@" : ''; $ua->proxy( http => "http://$auth$self->{proxy_host}:$self->{proxy_port}/" ); } else { $self->{agent}->env_proxy(); } # no proxy defined! croak 'proxy_host parameter is required' unless $ua->proxy('http'); return $self; } # IN # OUT sub connect { my ($self) = (@_); # connect to the proxy my $req = HTTP::Request->new( CONNECT => "http://$self->{host}:$self->{port}/" ); my $res = $self->{agent}->request($req); # authentication failed die $res->status_line() if !$res->is_success(); # the socket connected to the proxy return $res->{client_socket}; } # READ *read_from = \&Net::Proxy::Connector::raw_read_from; # WRITE *write_to = \&Net::Proxy::Connector::raw_write_to; 1; __END__ =head1 NAME Net::Proxy::Connector::connect - Create CONNECT tunnels through HTTP proxies =head1 SYNOPSIS # sample proxy using Net::Proxy::Connector::tcp # and Net::Proxy::Connector::connect use Net::Proxy; # listen on localhost:6789 # and proxy to remotehost:9876 through proxy.company.com:8080 # using the given credentials my $proxy = Net::Proxy->new( in => { type => 'tcp', port => '6789' }, out => { type => 'connect', host => 'remotehost', port => '9876', proxy_host => 'proxy.company.com', proxy_port => '8080', proxy_user => 'jrandom', proxy_pass => 's3kr3t', proxy_agent => 'Mozilla/4.04 (X11; I; SunOS 5.4 sun4m)', }, ); $proxy->register(); Net::Proxy->mainloop(); =head1 DESCRIPTION C is a C that uses the HTTP CONNECT method to ask the proxy to create a tunnel to an outside server. Be aware that some proxies are set up to deny the creation of some outside tunnels (either to ports other than 443 or outside a specified set of outside hosts). This connector is only an "out" connector. =head1 CONNECTOR OPTIONS C accepts the following options: =head1 C =over 4 =item * host The destination host. =item * port The destination port. =item * proxy_host The web proxy name or address. =item * proxy_port The web proxy port. =item * proxy_user The authentication username for the proxy. =item * proxy_pass The authentication password for the proxy. =item * proxy_agent The user-agent string to use when connecting to the proxy. =back =head1 AUTHOR Philippe 'BooK' Bruhat, C<< >>. =head1 BUGS All the authentication schemes supported by C should be supported (we use an C internally to contact the proxy). This means we should also support NTLM, since it is supported as from C 5.66. C has not been actually tested with NTLM, though. Any report of success or failure with a NTLM proxy will be appreciated. =head1 HISTORY This module is based on my script C, that provided a command-line interface to create tunnels though HTTP proxies. It was first published on CPAN on March 2003. A better version of C (using C) is provided this distribution. =head1 COPYRIGHT Copyright 2006 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/lib/Net/Proxy/Connector/connect_ssl.pm0000444000175000017500000000712710705511550023262 0ustar abiabipackage Net::Proxy::Connector::connect_ssl; use strict; use warnings; use Carp; use Net::Proxy::Connector; use Net::Proxy::Connector::connect; our @ISA = qw( Net::Proxy::Connector::connect ); # we can't subclass Net::Proxy::Connector::ssl, because we don't want listen() # so, mix-in the needed methods from Net::Proxy::Connector::ssl use Net::Proxy::Connector::ssl; *upgrade_SSL = \&Net::Proxy::Connector::ssl::upgrade_SSL; # IN # OUT sub connect { my ($self) = (@_); # connect to the proxy, just like Net::Proxy::Connector::connect my $sock = $self->SUPER::connect(@_); # set a temporary nickname for the socket Net::Proxy->set_nick( $sock, $sock->sockhost() . ':' . $sock->sockport() . ' -> ' . $sock->peerhost() . ':' . $sock->peerport() ); Net::Proxy->notice( 'Connected (HTTP) ' . Net::Proxy->get_nick($sock) ); # and then upgrade the socket to SSL return $self->upgrade_SSL($sock); } # READ # WRITE 1; __END__ =head1 NAME Net::Proxy::Connector::connect_ssl - Create SSL/CONNECT tunnels through HTTP proxies =head1 SYNOPSIS # sample proxy using Net::Proxy::Connector::tcp # and Net::Proxy::Connector::connect_ssl use Net::Proxy; # listen on localhost:6789 # and proxy to remotehost:9876 through proxy.company.com:8080 # using the given credentials my $proxy = Net::Proxy->new( in => { type => 'tcp', port => '6789' }, out => { type => 'connect_ssl', host => 'remotehost', port => '9876', proxy_host => 'proxy.company.com', proxy_port => '8080', proxy_user => 'jrandom', proxy_pass => 's3kr3t', proxy_agent => 'Mozilla/4.04 (X11; I; SunOS 5.4 sun4m)', }, ); $proxy->register(); Net::Proxy->mainloop(); =head1 DESCRIPTION C is a C that uses the HTTP CONNECT method to ask the proxy to create a tunnel to an outside server. The data is then encrypted using SSL. Obviously, you'll need a server that understands SSL (or a proxy using C) at the other end. This connector is only an "out" connector. In addition to the options listed below, this connector accepts all C options to C. They are transparently passed through to the appropriate C methods when upgrading the socket to SSL. =head1 CONNECTOR OPTIONS C accepts the following options: =head1 C =over 4 =item * host The destination host. =item * port The destination port. =item * proxy_host The web proxy name or address. =item * proxy_port The web proxy port. =item * proxy_user The authentication username for the proxy. =item * proxy_pass The authentication password for the proxy. =item * proxy_agent The user-agent string to use when connecting to the proxy. =back =head1 AUTHOR Philippe 'BooK' Bruhat, C<< >>. =head1 HISTORY Because C blocks when it tries to connect to itself, it wasn't possible to pass an SSL-encrypted connection through a proxy with a single script: you needed one for the SSL encapsulation, and another one for bypassing the proxy with the C HTTP method. See C and C for details. =head1 COPYRIGHT Copyright 2007 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/lib/Net/Proxy/Connector/tcp.pm0000444000175000017500000000364310705511550021535 0ustar abiabipackage Net::Proxy::Connector::tcp; use strict; use warnings; use IO::Socket::INET; use Net::Proxy::Connector; our @ISA = qw( Net::Proxy::Connector ); sub init { my ($self) = @_; # set up some defaults $self->{host} ||= 'localhost'; $self->{timeout} ||= 1; } # IN *listen = \&Net::Proxy::Connector::raw_listen; *accept_from = \&Net::Proxy::Connector::raw_accept_from; # OUT sub connect { my ($self) = @_; my $sock = IO::Socket::INET->new( PeerAddr => $self->{host}, PeerPort => $self->{port}, Proto => 'tcp', Timeout => $self->{timeout}, ); die $! unless $sock; return $sock; } # READ *read_from = \&Net::Proxy::Connector::raw_read_from; # WRITE *write_to = \&Net::Proxy::Connector::raw_write_to; 1; __END__ =head1 NAME Net::Proxy::Connector::tcp - Net::Proxy connector for standard tcp proxies =head1 SYNOPSIS # sample proxy using Net::Proxy::Connector::tcp use Net::Proxy; my $proxy = Net::Proxy->new( in => { type => tcp, port => '6789' }, out => { type => tcp, host => 'remotehost', port => '9876' }, ); $proxy->register(); Net::Proxy->mainloop(); =head1 DESCRIPTION C is a connector for handling basic, standard TCP connections. =head1 CONNECTOR OPTIONS The connector accept the following options: =head2 C =over 4 =item * host The listening address. If not given, the default is C. =item * port The listening port. =back =head2 C =over 4 =item * host The remote host. =item * port The remote port. =item * timeout The socket timeout for connection (C only). =back =head1 AUTHOR Philippe 'BooK' Bruhat, C<< >>. =head1 COPYRIGHT Copyright 2006 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/lib/Net/Proxy/Connector/ssl.pm0000444000175000017500000001420510705511550021544 0ustar abiabipackage Net::Proxy::Connector::ssl; use strict; use warnings; use Net::Proxy::Connector; use IO::Socket::SSL; use Scalar::Util qw( refaddr ); use Carp; our @ISA = qw( Net::Proxy::Connector ); my %IS_SSL; sub init { my ($self) = @_; # set up some defaults $self->{host} ||= 'localhost'; } # IN sub listen { my ($self) = @_; my $sock; # start as a SSL socket (default) if ( !$self->{start_cleartext} ) { $sock = IO::Socket::SSL->new( Listen => 1, LocalAddr => $self->{host}, LocalPort => $self->{port}, Proto => 'tcp', map { $_ => $self->{$_} } grep { /^SSL_/ } keys %$self ); # this exception is not catched by Net::Proxy die "Can't listen on $self->{host} port $self->{port}: " . IO::Socket::SSL::errstr() unless $sock; } # or as a standard TCP socket, which may be upgraded later else { $sock = IO::Socket::INET->new( Listen => 1, LocalAddr => $self->{host}, LocalPort => $self->{port}, Proto => 'tcp', ); # this exception is not catched by Net::Proxy die "Can't listen on $self->{host} port $self->{port}: $!" unless $sock; } # remember the class of the socket $IS_SSL{ refaddr $sock } = !$self->{start_cleartext}; Net::Proxy->set_nick( $sock, 'SSL listener ' . $sock->sockhost() . ':' . $sock->sockport() ); Net::Proxy->info( 'Started ' . Net::Proxy->get_nick($sock) . ' as ' . ( $self->{start_cleartext} ? 'cleartext' : 'SSL' ) ); return $sock; } sub accept_from { my ($self, $listen) = @_; my $sock = $listen->accept(); die IO::Socket::SSL::errstr() if ! $sock; Net::Proxy->set_nick( $sock, $sock->peerhost() . ':' . $sock->peerport() . ' -> ' . $sock->sockhost() . ':' . $sock->sockport() ); Net::Proxy->notice( 'Accepted ' . Net::Proxy->get_nick( $sock ) ); return $sock; } # OUT sub connect { my ($self) = @_; my $sock; # connect as a SSL socket (default) if ( !$self->{start_cleartext} ) { $sock = IO::Socket::SSL->new( PeerAddr => $self->{host}, PeerPort => $self->{port}, Proto => 'tcp', Timeout => $self->{timeout}, map { $_ => $self->{$_} } grep { /^SSL_/ } keys %$self ); } # or as a standard TCP socket, which may be upgraded later else { $sock = IO::Socket::INET->new( PeerAddr => $self->{host}, PeerPort => $self->{port}, Proto => 'tcp', Timeout => $self->{timeout}, ); } die $self->{start_cleartext} ? $! : IO::Socket::SSL::errstr() unless $sock; return $sock; } # READ *read_from = \&Net::Proxy::Connector::raw_read_from; # WRITE *write_to = \&Net::Proxy::Connector::raw_write_to; # SSL-related methods # upgrade the socket to SSL (if needed) sub upgrade_SSL { my ( $self, $sock ) = @_; if ( $IS_SSL{ refaddr $sock } ) { carp( Net::Proxy->get_nick($sock) . ' already is a SSL socket' ); return $sock; } IO::Socket::SSL->start_SSL( $sock, SSL_server => $self->is_in(), map { $_ => $self->{$_} } grep { /^SSL_/ } keys %$self ); $IS_SSL{ refaddr $sock } = 1; Net::Proxy->notice( 'Upgraded ' . Net::Proxy->get_nick($sock) . ' to SSL' ); return $sock; } 1; __END__ =head1 NAME Net::Proxy::Connector::ssl - SSL Net::Proxy connector =head1 DESCRIPTION C is a C that can manage SSL connections (thanks to C). By default, this connector creates SSL sockets. You will need to subclass it to create "smarter" connectors than can upgrade their connections to SSL. In addition to the options listed below, this connector accepts all C options to C. They are transparently passed through to the appropriate C methods when needed. =head1 CONNECTOR OPTIONS The connector accept the following options: =head2 C =over 4 =item * host The listening address. If not given, the default is C. =item * port The listening port. =item * start_cleartext If true, the connection will start in cleartext. It is possible to upgrade a socket to using SSL with the C method. =back =head2 C =over 4 =item * host The listening address. If not given, the default is C. =item * port The listening port. =item * start_cleartext If true, the connection will start in cleartext. It is possible to upgrade a socket to using SSL with the C method. =back =head1 METHODS The C connector has an extra method: =over 4 =item upgrade_SSL( $sock ) This method will upgrade a cleartext socket to SSL. If the socket is already in SSL, it will C. =back =head1 CREATING A SELF-SIGNED CERTIFICATE I tend to forget this information, and the openssl documentation doesn't make this any clearer, so here are the most basic commands needed to create your own self-signed certificate (courtesy David Morel): $ openssl genrsa -out key.pem 1024 $ openssl req -new -key key.pem -x509 -out cert.pem -days 365 A certificate is required is you want to run a SSL server or a proxy with a C as its C connector. Once the key and certificate have been created, you can use them in your parameter list to C<< Net::Proxy->new() >> (they are passed through to C): Net::Proxy->new( { in => { host => '0.0.0.0', port => 443, SSL_key_file => 'key.pem', SSL_cert_file => 'cert.pem', }, out => { type => 'tcp', port => '80' } } ); =head1 AUTHOR Philippe 'BooK' Bruhat, C<< >>. =head1 COPYRIGHT Copyright 2006 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/lib/Net/Proxy/Connector/dummy.pm0000444000175000017500000000212610705511550022075 0ustar abiabipackage Net::Proxy::Connector::dummy; use strict; use warnings; use Net::Proxy::Connector; our @ISA = qw( Net::Proxy::Connector ); # IN sub listen { } sub accept_from { } # OUT sub connect { } # READ sub read_from { return '' } # WRITE sub write_to { } 1; __END__ =head1 NAME Net::Proxy::Connector::dummy - Dummy Net::Proxy connector =head1 DESCRIPTION C is a C that does I. It doesn't listen for incoming connections and does connect to other hosts. Future connectors may have their C method also handle the connection to a remote host. In this case, C may be used as an 'out' connector. You could also use the source code of this module as a template for writing new C classes. =head1 CONNECTOR OPTIONS None. =head1 AUTHOR Philippe 'BooK' Bruhat, C<< >>. =head1 COPYRIGHT Copyright 2006 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/lib/Net/Proxy.pm0000444000175000017500000005106710705511550017020 0ustar abiabipackage Net::Proxy; use strict; use warnings; use Carp; use Scalar::Util qw( refaddr reftype ); use IO::Select; use POSIX 'strftime'; our $VERSION = '0.12'; # interal socket information table my %SOCK_INFO; my %LISTENER; my %CLOSING; my $READERS; my $WRITERS; my %PROXY; my %STATS; # Net::Proxy attributes my %CONNECTOR = ( in => {}, out => {}, ); my $VERBOSITY = 0; # be silent by default my $BUFFSIZE = 16384; # # some logging-related methods # sub set_verbosity { $VERBOSITY = $_[1]; } { my $i; for my $meth (qw( error notice info debug )) { no strict 'refs'; my $level = $i++; *$meth = sub { return if $VERBOSITY < $level; print STDERR strftime "%Y-%m-%d %H:%M:%S $_[1]\n", localtime; }; } } # # constructor # sub new { my ( $class, $args ) = @_; my $self = bless \do { my $anon }, $class; croak "Argument to new() must be a HASHREF" if ref $args ne 'HASH'; for my $conn (qw( in out )) { # check arguments croak "'$conn' connector required" if !exists $args->{$conn}; croak "'$conn' connector must be a HASHREF" if ref $args->{$conn} ne 'HASH'; croak "'type' key required for '$conn' connector" if !exists $args->{$conn}{type}; croak "'hook' key is not a CODE reference for '$conn' connector" if $args->{$conn}{hook} && reftype( $args->{$conn}{hook} ) ne 'CODE'; # load the class my $class = 'Net::Proxy::Connector::' . $args->{$conn}{type}; eval "require $class"; croak "Couldn't load $class for '$conn' connector: $@" if $@; # create and store the Connector object $args->{$conn}{_proxy_} = $self; $CONNECTOR{$conn}{ refaddr $self} = $class->new( $args->{$conn} ); $CONNECTOR{$conn}{ refaddr $self}->set_proxy($self); } return $self; } sub register { $PROXY{ refaddr $_[0] } = $_[0]; } sub unregister { delete $PROXY{ refaddr $_[0] }; } # # The Net::Proxy attributes # sub in_connector { return $CONNECTOR{in}{ refaddr $_[0] }; } sub out_connector { return $CONNECTOR{out}{ refaddr $_[0] }; } # # create the socket setter/getter methods # these are actually Net::Proxy clas methods # BEGIN { my $n = 0; my $buffer_id; for my $attr (qw( peer connector state nick buffer callback )) { no strict 'refs'; my $i = $n; *{"get_$attr"} = sub { $SOCK_INFO{ refaddr $_[1] }[$i]; }; *{"set_$attr"} = sub { $SOCK_INFO{ refaddr $_[1] }[$i] = $_[2]; }; $buffer_id = $n if $attr eq 'buffer'; $n++; } # special shortcut sub add_to_buffer { $SOCK_INFO{ refaddr $_[1] }[$buffer_id] .= $_[2]; } } # # create statistical methods # for my $info (qw( opened closed )) { no strict 'refs'; *{"stat_inc_$info"} = sub { $STATS{ refaddr $_[0]}{$info}++; $STATS{total}{$info}++; }; *{"stat_$info"} = sub { $STATS{ refaddr $_[0]}{$info} || 0; }; *{"stat_total_$info"} = sub { $STATS{total}{$info} || 0; }; } # # socket-related methods # sub add_listeners { my ( $class, @socks ) = @_; for my $sock (@socks) { Net::Proxy->notice( 'Add ' . Net::Proxy->get_nick($sock) ); $LISTENER{ refaddr $sock} = $sock; } return; } sub close_sockets { my ( $class, @socks ) = @_; SOCKET: for my $sock (@socks) { if( my $data = Net::Proxy->get_buffer( $sock ) ) { ## Net::Proxy->debug( length($data) . ' bytes left to write on ' . Net::Proxy->get_nick( $sock ) ); $CLOSING{ refaddr $sock} = $sock; next SOCKET; } Net::Proxy->notice( 'Closing ' . Net::Proxy->get_nick( $sock ) ); # clean up connector if ( my $conn = Net::Proxy->get_connector($sock) ) { $conn->close($sock) if $conn->can('close'); # count connections to the proxy "in connectors" only my $proxy = $conn->get_proxy(); if ( refaddr $conn == refaddr $proxy->in_connector() && !_is_listener($sock) ) { $proxy->stat_inc_closed(); } } # clean up internal structures delete $SOCK_INFO{ refaddr $sock}; delete $LISTENER{ refaddr $sock}; delete $CLOSING{ refaddr $sock}; # clean up sockets $READERS->remove($sock); $WRITERS->remove($sock); $sock->close(); } return; } # # select() stuff # sub watch_reader_sockets { my ( $class, @socks ) = @_; $READERS->add(@socks); return; } sub watch_writer_sockets { my ( $class, @socks ) = @_; $WRITERS->add(@socks); return; } sub remove_writer_sockets { my ( $class, @socks ) = @_; $WRITERS->remove(@socks); return; } # # destructor # sub DESTROY { my ($self) = @_; delete $CONNECTOR{in}{ refaddr $self}; delete $CONNECTOR{out}{ refaddr $self}; } # # the mainloop itself # sub mainloop { my ( $class, $max_connections ) = @_; $max_connections ||= 0; # initialise the loop $READERS = IO::Select->new(); $WRITERS = IO::Select->new(); # initialise all proxies for my $proxy ( values %PROXY ) { my $in = $proxy->in_connector(); my @socks = $in->listen(); Net::Proxy->add_listeners(@socks); Net::Proxy->watch_reader_sockets(@socks); Net::Proxy->set_connector( $_, $in ) for @socks; } my $continue = 1; for my $signal (qw( INT HUP )) { $SIG{$signal} = sub { Net::Proxy->notice("Caught $signal signal"); $continue = 0; }; } # loop indefinitely while ( $continue and my @ready = IO::Select->select( $READERS, $WRITERS ) ) { ## Net::Proxy->debug( 0+@{$ready[0]} . " sockets ready for reading" ); ## Net::Proxy->debug( join "\n ", "Readers:", map { Net::Proxy->get_nick($_) } $READERS->handles() ); ## Net::Proxy->debug( 0+@{$ready[1]} . " sockets ready for writing" ); ## Net::Proxy->debug( join "\n ", "Writers:", map { Net::Proxy->get_nick($_) } $WRITERS->handles() ); # first read READER: for my $sock (@{$ready[0]}) { if ( _is_listener($sock) ) { # accept the new connection and connect to the destination Net::Proxy->get_connector($sock)->new_connection_on($sock); } else { # have we read too much? my $peer = Net::Proxy->get_peer($sock); next READER if !$peer || length( Net::Proxy->get_buffer($peer) ) >= $BUFFSIZE; # read the data if ( my $conn = Net::Proxy->get_connector($sock) ) { my $data = $conn->read_from($sock); next READER if !defined $data; if ($peer) { # run the hook on incoming data my $callback = Net::Proxy->get_callback( $sock ); $callback->( \$data, $sock, $conn ) if $callback && defined $data; Net::Proxy->add_to_buffer( $peer, $data ); Net::Proxy->watch_writer_sockets($peer); ## Net::Proxy->debug( "Will write " . length( Net::Proxy->get_buffer($peer)). " bytes to " . Net::Proxy->get_nick( $peer )); } } } } # then write for my $sock (@{$ready[1]}) { my $conn = Net::Proxy->get_connector($sock); $conn->write_to($sock); } } continue { if( %CLOSING ) { Net::Proxy->close_sockets( values %CLOSING ); } if( $max_connections ) { # stop after that many connections last if Net::Proxy->stat_total_closed() == $max_connections; # prevent new connections if ( %LISTENER && Net::Proxy->stat_total_opened() == $max_connections ) { Net::Proxy->close_sockets( values %LISTENER ); } } } # close all remaining sockets Net::Proxy->close_sockets( $READERS->handles(), $WRITERS->handles() ); } # # helper private FUNCTIONS # sub _is_listener { return exists $LISTENER{ refaddr $_[0] }; } 1; __END__ =head1 NAME Net::Proxy - Framework for proxying network connections in many ways =head1 SYNOPSIS use Net::Proxy; # proxy connections from localhost:6789 to remotehost:9876 # using standard TCP connections my $proxy = Net::Proxy->new( { in => { type => 'tcp', port => '6789' }, out => { type => 'tcp', host => 'remotehost', port => '9876' }, } ); # register the proxy object $proxy->register(); # and you can setup multiple proxies # and now proxy connections indefinitely Net::Proxy->mainloop(); =head1 DESCRIPTION A C object represents a proxy that accepts connections and then relays the data transfered between the source and the destination. The goal of this module is to abstract the different methods used to connect from the proxy to the destination. A proxy is a program that transfer data across a network boundary between a client and a server. C introduces the concept of "connectors" (implemented as C subclasses), which abstract the server part (connected to the client) and the client part (connected to the server) of the proxy. This architecture makes it easy to implement specific techniques to cross a given network boundary, possibly by using a proxy on one side of the network fence, and a reverse-proxy on the other side of the fence. See L for details about the existing connectors. =head1 METHODS If you only intend to use C and not write new connectors, you only need to know about C, C and C. =head2 Class methods =over 4 =item new( { in => { ... }, { out => { ... } } ) Return a new C object, with two connectors configured as described in the hashref. The connector parameters are described in the table below, as well as in each connector documentation. =item mainloop( $max_connections ) This method initialises all the registered C objects and then loops on all the sockets ready for reading, passing the data through the various C objets to handle the specifics of each connection. If C<$max_connections> is given, the proxy will stop after having fully processed that many connections. Otherwise, this method does not return. =item add_listeners( @sockets ) Add the given sockets to the list of listening sockets. =item watch_reader_sockets( @sockets ) Add the given sockets to the readers watch list. =item watch_writer_sockets( @sockets ) Add the given sockets to the writers watch list. =item remove_writer_sockets( @sockets ) Remove the given sockets from the writers watch list. =item close_sockets( @sockets ) Close the given sockets and cleanup the related internal structures. =item set_verbosity( $level ) Set the logging level. C<0> means not messages except warnings and errors. =item error( $message ) Log $message to STDERR, always. =item notice( $message ) Log $message to STDERR if verbosity level is equal to C<1> or more. =item info( $message ) Log $message to STDERR if verbosity level is equal to C<2> or more. =item debug( $message ) Log $message to STDERR if verbosity level is equal to C<3> or more. (Note: throughout the C source code, calls to C are commented with C<##>.) =back Some of the class methods are related to the socket objects that handle the actual connections. =over 4 =item get_peer( $socket ) =item set_peer( $socket, $peer ) Get or set the socket peer. =item get_connector( $socket ) =item set_connector( $socket, $connector ) Get or set the socket connector (a C object). =item get_state( $socket ) =item set_state( $socket, $state ) Get or set the socket state. Some C subclasses may wish to use this to store some internal information about the socket or the connection. =item get_nick( $socket ) =item set_nick( $socket, $nickname ) Get or set the socket nickname. Typically used by C to give informative names to socket (used in the log messages). =item get_buffer( $socket ) =item set_buffer( $socket, $data ) Get or set the content of the writing buffer for the socket. Used by C in C and C. =item get_callback( $socket ) =item set_callback( $socket, $coderef ) Get or set the callback currently associated with the socket. =item add_to_buffer( $socket, $data ) Add data to the writing buffer of the socket. =back =head2 Instance methods =over 4 =item register() Register a C object so that it will be included in the C processing. =item unregister() Unregister the C object. =item in_connector() Return the C objet that handles the incoming connection and handles the data coming from the "client" side. =item out_connector() Return the C objet that creates the outgoing connection and handles the data coming from the "server" side. =back =head2 Statistical methods The following methods manage some statistical information about the individual proxies: =over 4 =item stat_inc_opened() =item stat_inc_closed() Increment the "opened" or "closed" connection counter for this proxy. =item stat_opened() =item stat_closed() Return the count of "opened" or "closed" connections for this proxy. =item stat_total_opened() =item stat_total_closed() Return the total count of "opened" or "closed" connection across all proxy objects. =back =head1 CONNECTORS All connection types are provided with the help of specialised classes. The logic for protocol C is provided by the C class. =head2 Connector hooks There is a single parameter that all connectors accept: C. Given a code reference, the code reference will be called when data is I on the corresponding socket. The code reference should have the following signature: sub callback { my ($dataref, $sock, $connector) = @_; ... } C<$dataref> is a reference to the chunk of data received, C<$sock> is a reference to the socket that received the data, and C<$connector> is the C object that created the socket. This allows someone to eventually store data in a stash stored in the connector, so as to share data between sockets. =head2 Available connectors =over 4 =item * tcp (C) This is the simplest possible proxy connector. On the "in" side, it sits waiting for incoming connections, and on the "out" side, it connects to the configured host/port. =item * connect (C) This proxy connector can connect to a TCP server though a web proxy that accepts HTTP CONNECT requests. =item * dual (C) This proxy connector is a Y-shaped connector: depending on the client behaviour right after the connection is established, it connects it to one of two services, handled by two distinct connectors. =item * dummy (C) This proxy connector does nothing. You can use it as a template for writing new C classes. =back =head2 Summary This table summarises all the available C classes and the parameters their constructors recognise. C means that the given C cannot be used in that position (either C or C). Connector | in parameters | out parameters ------------+-----------------+----------------- tcp | host | host | port | port ------------+-----------------+----------------- connect | N/A | host | | port | | proxy_host | | proxy_port | | proxy_user | | proxy_pass | | proxy_agent ------------+-----------------+----------------- dual | host | N/A | port | | timeout | | server_first | | client_first | ------------+-----------------+----------------- dummy | N/A | N/A ------------+-----------------+----------------- ssl | host | host | port | port | start_cleartext | start_cleartext ------------+-----------------+----------------- connect_ssl| N/A | host | | port | | proxy_host | | proxy_port | | proxy_user | | proxy_pass | | proxy_agent C is used as the C parameter for a C, since the later is linked to two different connector objects. =head1 AUTHOR Philippe 'BooK' Bruhat, C<< >>. =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 TODO Here's my own wishlist: =over 4 =item * Write a connector fully compatible with GNU httptunnel (L). This one will probably be named C. =item * Enhance the httptunnel protocol to support multiple connections. =item * Implement RFC 3093 - Firewall Enhancement Protocol (FEP), as C. This RFC was published on April 1, 2001. This is probably impossible with C, since the FEP driver is a rather low-level driver (at the IP level of the network stack). =item * Implement DNS tunnel connectors. See L, OzymanDNS, L. L for examples. =item * Implement an UDP connector. (Is it feasible?) =item * Implement a connector that can be plugged to the STDIN/STDOUT of an external process, like the C option of OpenSSH. =item * Implement C, for UNIX sockets. =item * Implement ICMP tunnel connectors. See L, L, L, L for examples. Since ICMP implies low-level packet reading and writing, it may not be possible for C to handle it. =item * Look for inspiration in the I, at L. Look also here: L =item * Implement a C connector that can upgrade upgrade a connection to SSL transparently, even if the client or server doesn't support STARTTLS. Martin Werthmöller provided a full implementation of a connector that can handle IMAP connections and upgrade them to TLS if the client sends a C command. My implementation will split this in two parts C and C, that inherits from the former. =back =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Net::Proxy You can also look for information at: =over 4 =item * The Net::Proxy mailing-list L This list receive an email for each commit =item * The public source repository svn://svn.mongueurs.net/Net-Proxy/trunk/ Also available through a web interface at L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =head1 COPYRIGHT Copyright 2006-2007 Philippe 'BooK' Bruhat, All Rights Reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/README0000444000175000017500000000111610705511550014713 0ustar abiabiNet::Proxy ---------- This module is a framework for creating various kinds of network proxies in a very simple way. A proxy is a program that transfer data across a network boundary between a client and a server. Net::Proxy introduces the concept of "connectors", which abstract the server part (connected to the client) and the client part (connected to the server) of the proxy. This makes it very easy to implement specific techniques to cross a given network boundary, possibly by using a proxy on one side of the network fence, and a reverse-proxy on the other side of the fence. libnet-proxy-perl-0.12.orig/Changes0000444000175000017500000001070510705511550015332 0ustar abiabiRevision history for Perl extension Net::Proxy 0.12 Thu Oct 18 00:49:42 CEST 2007 [ENHANCEMENTS] - print a meaningful error message when the ssl connector can't listen [SCRIPTS] - connect-tunnel now dies early if LWP::UserAgent is not installed (and t/90compile.t does pass as well) [TESTS] - prevent t/21connect.t to fail when a environment proxy is defined 0.11 Mon Oct 15 03:44:30 CEST 2007 [ENHANCEMENTS] - added an error() method, for messages that must always be shown - better support for the cases where accept() fails - better error message when accept() fails for a SSL socket [DOCUMENTATION] - added a tutorial about Net::Proxy, with code examples [TESTS] - prevent t/pod-coverage.t to fail on the upgrade_SSL method mixed in Net::Proxy::Connector::connect_ssl 0.10 Mon Oct 1 22:26:50 CEST 2007 [DOCUMENTATION] - added information about the public SVN repository and the mailing-list [TESTS] - prevent t/21connect.t, t/32tcp_connect.t, t/90compile.t to fail when LWP::UserAgent is not installed 0.09 Thu Sep 13 11:01:21 CEST 2007 [ENHANCEMENTS] - the notice(), info() and debug() methods now have a timestamp [TESTS] - prevent the t/37connectssl_tcp.t test script to die when one of the prerequisites is missing (thus removing many FAILs) 0.08 Mon Apr 23 19:08:30 CEST 2007 [ENHANCEMENTS] - the hook callback now receives the socket on which the data was received, in addition to the connector [NEW CONNECTOR] - Net::Proxy::Connector::connect_ssl (combines Net::Proxy::Connector::connect and Net::Proxy::Connector::ssl in a single connector) [TESTS] - made tests more robust when connector prerequisites are missing - test Net::Proxy::Connector::ssl as an "in" connector - test the start_cleartext option of Net::Proxy::Connector::ssl 0.07 Sat Sep 2 19:47:24 CEST 2006 [ENHANCEMENTS] - added support for SSL proxies (ssl connector) [NEW CONNECTOR] - Net::Proxy::Connector::ssl [TESTS] - add support for NET_PROXY_VERBOSITY environnement variable in the tests, to have more verbose tests if needed 0.06 Thu Apr 20 21:27:00 CEST 2006 [ENHANCEMENTS] - add support for "hooks" on received data, as proposed by Martin Werthmöller (see http://www.cpanforum.com/threads/1991), but with a different implementation 0.05 Mon Apr 17 20:42:22 CEST 2006 [ENHANCEMENTS] - added a debug() method (but all uses of it are commented out) - better socket management algorithm: + prevents deadlocks (as could occur when having a connection and a tunneled connection within it both going through Net::Proxy) + limits buffering (so as to avoid sucking a lot of memory when one socket sends data faster than its peer can accept it) [SCRIPTS] - patched sslh so that it can listen not only on localhost. (Thanks to Dieter Voegtli.) 0.04 Tue Jan 17 14:47:20 CET 2006 [ENHANCEMENTS] - added some basic information logging (enable with Net::Proxy->set_verbosity( $level )) [TESTS] - test for several failure cases - the test suite now covers more than 95% of the code [SCRIPTS] - patched sslh so that it works correctly, now 0.03 Wed Jan 11 02:10:52 CET 2006 [DOCUMENTATION] - Correct SYNOPSIS for Net::Proxy::Connector::tcp - Added a SYNOPSIS for Net::Proxy::Connector::connect [NEW CONNECTOR] - Net::Proxy::Connector::dual [SCRIPTS] - previously unreleased sslh script ported to use Net::Proxy 0.02 Tue Jan 10 09:43:23 CET 2006 [ENHANCEMENTS] - added the README and Changes files - added statistical methods to Net::Proxy - mainloop($max) will refuse new connections after $max connections have started [NEW CONNECTOR] - Net::Proxy::Connector::connect [SCRIPTS] - connect-tunnel ported to use Net::Proxy 0.01 Fri Jan 6 03:32:46 CET 2006 [FEATURES] - The proxy is fully functionnal, but lacks several types of connectors [CONNECTORS] - Net::Proxy::Connector::tcp - Net::Proxy::Connector::dummy libnet-proxy-perl-0.12.orig/Build.PL0000444000175000017500000000071510705511550015333 0ustar abiabiuse Module::Build; my $build = Module::Build->new( module_name => 'Net::Proxy', license => 'perl', requires => { 'perl' => '5.6', 'Scalar::Util' => 0, 'IO::Select' => 0, 'IO::Socket' => 0, }, recommends => { 'LWP::UserAgent' => 2, 'IO::Socket::SSL' => 1 }, script_files => [ glob 'script/*' ], add_to_cleanup => ['Net-Proxy-*'], ); $build->create_build_script(); libnet-proxy-perl-0.12.orig/Makefile.PL0000444000175000017500000000110310705511550016001 0ustar abiabi# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'PL_FILES' => {}, 'NAME' => 'Net::Proxy', 'EXE_FILES' => [ 'script/connect-tunnel', 'script/sslh' ], 'VERSION_FROM' => 'lib/Net/Proxy.pm', 'PREREQ_PM' => { 'Scalar::Util' => 0, 'IO::Socket' => 0, 'IO::Select' => 0 } ) ; libnet-proxy-perl-0.12.orig/META.yml0000444000175000017500000000206010705511550015303 0ustar abiabi--- name: Net-Proxy version: 0.12 author: - "Philippe 'BooK' Bruhat, C<< >>." abstract: Framework for proxying network connections in many ways license: perl resources: license: http://dev.perl.org/licenses/ requires: IO::Select: 0 IO::Socket: 0 Scalar::Util: 0 perl: 5.6 recommends: IO::Socket::SSL: 1 LWP::UserAgent: 2 provides: Net::Proxy: file: lib/Net/Proxy.pm version: 0.12 Net::Proxy::Connector: file: lib/Net/Proxy/Connector.pm Net::Proxy::Connector::connect: file: lib/Net/Proxy/Connector/connect.pm Net::Proxy::Connector::connect_ssl: file: lib/Net/Proxy/Connector/connect_ssl.pm Net::Proxy::Connector::dual: file: lib/Net/Proxy/Connector/dual.pm Net::Proxy::Connector::dummy: file: lib/Net/Proxy/Connector/dummy.pm Net::Proxy::Connector::ssl: file: lib/Net/Proxy/Connector/ssl.pm Net::Proxy::Connector::tcp: file: lib/Net/Proxy/Connector/tcp.pm generated_by: Module::Build version 0.2808 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 libnet-proxy-perl-0.12.orig/script/0000755000175000017500000000000010705511550015342 5ustar abiabilibnet-proxy-perl-0.12.orig/script/sslh0000555000175000017500000001340410705511550016241 0ustar abiabi#!/usr/bin/perl -w use strict; use Getopt::Long; use Net::Proxy; use vars qw( %CONF $VERSION ); $VERSION = 0.04; # default values %CONF = ( port => 'localhost:443', timeout => 2, ssh => 'localhost:22', ssl => 'localhost:443', verbose => 0, ); # get the options Getopt::Long::Configure("bundling"); GetOptions( \%CONF, "help|h", "port|p=s", "timeout|t=i", "verbose|v+", "version|V", "ssh|s=s", "ssl|https|l=s", ) or die << 'USAGE'; Usage: sslh [-v] [-p host:port] [-t timeout] [--ssh host:port] [--ssl host:port] USAGE # set up the verbosity level Net::Proxy->set_verbosity( $CONF{verbose} ); # check the options die "--timeout must be a positive number (possibly fractional)\n" unless $CONF{timeout} > 0; die "--ssh and -ssl must point to different servers\n" if $CONF{ssh} eq $CONF{ssl}; # create the proxy listening socket die "--port option required\n" unless exists $CONF{port}; # compute host / port { my %hostport; for (qw( ssl ssh port )) { $CONF{$_} = "localhost:$CONF{$_}" if index( $CONF{$_}, ':' ) < 0; $CONF{$_} = [ split /:/, $CONF{$_} ]; push @{ $hostport{ join ':', ( gethostbyname( $CONF{$_}[0] ) )[0], $CONF{$_}[1] } }, $_; } # check for duplicates for( keys %hostport ) { if( @{$hostport{$_}} != 1 ) { die "Options " . join( " and ", map {"--$_"} @{ $hostport{$_} } ) . " are identical! ($_)\n"; } } } # create the proxy my $proxy = Net::Proxy->new( { in => { type => 'dual', host => $CONF{port}[0], port => $CONF{port}[1], timeout => $CONF{timeout}, server_first => { type => 'tcp', host => $CONF{ssh}[0], port => $CONF{ssh}[1], }, client_first => { type => 'tcp', host => $CONF{ssl}[0], port => $CONF{ssl}[1], }, }, out => { type => 'dummy'}, }); $proxy->register(); Net::Proxy->mainloop(); __END__ =head1 NAME sslh - Switch incoming connection between SSH and SSL/HTTPS servers =head1 SYNOPSIS B S<[ B<-v> ]> S<[ B<-p> I<[host:]port> ]> S<[ B<-t> I ]> S<[ B<--ssh> I<[host:]port> ]> S<[ B<--ssl> I<[host:]port> ]> =head1 DESCRIPTION B is a simple script that lets you switch an incoming connection on a single port between distinct SSH and SSL/HTTPS servers. B listens for connections on a port and is able to redirect them either to an HTTPS web server or a SSH server. This lets one setup both a HTTPS web server and a SSH server and access them through the same host+port. =head1 OPTIONS The program follows the usual GNU command line syntax, with long options starting with two dashes. =over 4 =item B<-p>, B<--port> I<[host:]port> The port the proxy will listen to. If no port is given, 443 is used by default. If no host is given, C is used by default. =item B<-s>, B<--ssh> I<[host:]port> The SSH server which the SSH connections must be forwarded to. If omitted, the default is I. =item B<-l>, B<--ssl>, B<--https> I<[host:]port> The HTTPS server which the HTTPS connections must be forwarded to. If omitted, the default is I. =item B<-t>, B<--timeout> I Timeout in seconds before a silent incoming connection is considered as a SSH connection. The number can be fractional. The default is I<2>seconds. =item B<-v>, B<--verbose> Verbose output. This option can be used several times for more verbose output. =back =head1 EXAMPLE OF USE Is this tool actually useful? Yes. For example one can use it to access both a SSH server and a secure web server via a corporate proxy that only accepts to relay connections to port 443. Creating a tunnel that passes SSH connection through a CONNECT-enabled web proxy is easy with B (also included in the C distribution). The proxy will let both SSH and HTTPS connections out (since they all point to port 443), and the home server will connect those incoming connections to the appropriate server. This only requires to run the HTTPS server on a non standard port (not 443). =head1 TECHNICAL NOTE How can this proxy find out what kind of protocol is using a TCP connection to port 443, without being connected (yet) to the server? We actually rely on a slight difference between the SSL and SSH protocols (found thanks to B): =over 4 =item SSH Once the TCP connection is established, the server speaks first, presenting itself by saying something like: SSH-2.0-OpenSSH_3.6.1p2 Debian 1:3.6.1p2-1 =item SSL With SSL, it's always the client that speaks first. =back This means that B can be used with any pair of protocols/services that share this property (the client speaks first for one and the server speaks first for the other). =head1 AUTHORS =over 4 =item Original idea and C version Frédéric Plé C<< >>. =item Perl versions Philippe 'BooK' Bruhat C<< >>. =back =head1 SCRIPT HISTORY Version 0.01 of the script was a quick hack designed in 2003 as a proof of concept. Version 0.02 (and higher) are based on C, and included with the C distribution. Version 0.02 didn't work, though. Version 0.03 correctly initialised the C connector. Version 0.04 lets the proxy listen on any address (instead of C, which is still the default). Thanks to Dieter Voegtli for spotting this. =head1 SEE ALSO L, L. =head1 COPYRIGHT Copyright 2003-2006, Philippe Bruhat. All rights reserved. =head1 LICENSE This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/script/connect-tunnel0000555000175000017500000001734410705511550020233 0ustar abiabi#!/usr/bin/perl -w use strict; use warnings; use Net::Proxy; use Getopt::Long; use Pod::Usage; our $VERSION = '0.07'; # die early if this module is not installed eval { require LWP::UserAgent; }; die "LWP::UserAgent required to run connect-tunnel\n" if $@; # default configuration our %CONF = ( 'proxy-authentication' => '', 'proxy' => $ENV{HTTP_PROXY}, 'user-agent' => "connect-tunnel/$VERSION", 'verbose' => 0, ); # # get and check the options # GetOptions( \%CONF, "verbose|v+", "tunnel|T=s@", "proxy|P=s", "proxy-authentication|A=s", "local-only|L", "user-agent|U=s" ) or pod2usage(); # set up the verbosity level Net::Proxy->set_verbosity( $CONF{verbose} ); # check for a proxy if ( $CONF{proxy} ) { $CONF{proxy} .= ":8080" if not $CONF{proxy} =~ /:/; } die "--proxy option required$/" if !$CONF{proxy}; # create the tunnels entrances die "--tunnel option required$/" unless exists $CONF{tunnel}; # split proxy-authentication { my ( $user, $pass ) = split ':', $CONF{'proxy-authentication'}, 2; $CONF{'proxy-authentication'} = $CONF{'proxy-authentication'} ? [ proxy_user => $user, proxy_pass => $pass ] : []; } for my $tunnel ( @{ $CONF{tunnel} } ) { die "--tunnel format required$/" if $tunnel !~ /^\d+:[\w.]+:\d+$/; my ( $port, $host, $hostport ) = split ':', $tunnel; my ( $proxy_host, $proxy_port) = split ':', $CONF{proxy}; my $proxy = Net::Proxy->new( { in => { type => 'tcp', port => $port, host => $CONF{'local-only'} ? 'localhost' : '0.0.0.0', }, out => { type => 'connect', host => $host, port => $hostport, proxy_host => $proxy_host, proxy_port => $proxy_port, proxy_agent => $CONF{'user-agent'}, @{ $CONF{'proxy-authentication'} }, }, } ); $proxy->register(); } # the main loop Net::Proxy->mainloop(); __END__ =head1 NAME connect-tunnel - Create CONNECT tunnels through HTTP proxies =head1 SYNOPSIS B S<[ B<-Lv> ]> S<[ B<-A> I ]> S<[ B<-P> I ]> S<[ B<-C> I ]> S<[ B<-T> I ]> =head1 DESCRIPTION B sets up tunneled connections to external hosts by redirecting connections to local ports towards thoses hosts/ports through a HTTP proxy. B makes use of the HTTP C method to ask the proxy to create a tunnel to an outside server. Be aware that some proxies are set up to deny outside tunnels (either to ports other than 443 or outside a specified set of outside hosts). =head1 OPTIONS The program follows the usual GNU command line syntax, with long options starting with two dashes. =over 4 =item B<-A>, B<--proxy-authentication> I Proxy authentication information. Please note that all the authentication schemes supported by C are supported (we use an C internally to contact the proxy). =item B<-C>, B<--control-port> I The port to which one can connect to issue control commands to B. See L for more details about the available commands. =item B<-L>, B<--local-only> Create the tunnels so that they will only listen on C. Thus, only connections originating from the machine that runs B will be accepted. That was the default behaviour in B version 0.02. =item B<-P>, B<--proxy> I[I<:port>] The proxy is required to connect the tunnels. If no port is given, 8080 is used by default. See also L. =item B<-T>, B<--tunnel> I Specifies that the given I on the local host is to be forwarded to the given I and I on the remote side. This works by allocating a socket to listen to I on the local side, and whenever a connection is made to this I, B forwards it to the proxy (with the credentials, if required), which in turn forwards it to the final destination. Note that this does not imply the use of any cryptographic system (SSL or any other). This is a simple TCP redirection. The security if any, is the one provided by the protocol used to connect to the destination through B. On Unix systems, only root can forward privileged ports. Note that you can setup tunnels to multiple destinations, by using the B<--tunnel> option several times. =item B<-U>, B<--user-agent> I Specify User-Agent value to send in HTTP requests. The default is to send C>. =item B<-v>, B<--verbose> Verbose output. This option can be used several times for more verbose output. =back =head1 EXAMPLES To connect to a SSH server running on C, on port 443, through the proxy C, running on port 8080, use the following command: connect-tunnel -P proxy.company.com:8080 -T 22:ssh.example.com:443 And now point your favorite ssh client to the machine running B. You can also emulate a "standard" user-agent: connect-tunnel -U "Mozilla/4.03 [en] (X11; I; Linux 2.1.89 i586)" -P proxy.company.com:8080 -T 22:ssh.example.com:443 B can easily use your proxy credentials to connect outside: connect-tunnel -U "Mozilla/4.03 [en] (X11; I; Linux 2.1.89 i586)" -P proxy.company.com:8080 -T 22:ssh.example.com:443 -A book:s3kr3t But if you don't want anybody else to connect to your tunnels and through the proxy with I credentials, use the B<--local-only> option: connect-tunnel -U "Mozilla/4.03 [en] (X11; I; Linux 2.1.89 i586)" -P proxy.company.com:8080 -T 22:ssh.example.com:443 -A book:s3kr3t -L If you have several destinations, there is no need to run several instances of B: connect-tunnel -U "Mozilla/4.03 [en] (X11; I; Linux 2.1.89 i586)" -P proxy.company.com:8080 -A book:s3kr3t -L -T 22:ssh.example.com:443 -T 222:ssh2.example.com:443 But naturally, you will need to correctly set up the ports in your clients. Mmm, such a long command line would perfectly fit in an alias or a F<.BAT> file. C<;-)> =head1 ENVIRONMENT VARIABLES The environment variable C can be used to provide a proxy definition. The environment variable is overriden by the B<--proxy> option, if passed to B. =head1 AUTHOR Philippe "BooK" Bruhat, C<< >>. I seem to have re-invented a well-known wheel with that script, but at least, I hope I have added a few interesting options to it. =head1 SCRIPT HISTORY The first version of the script was a quick hack that let me go through a corporate proxy. Version 0.02 and version 0.03 were released on CPAN in 2003. Version 0.04 sits half-finished in a CVS repository at home: I couldn't decypher the spaghetti of my data structures any more. C<:-(> Version 0.05 (and higher) are based on C, and included with the C distribution. =head1 Even though it's not rocket science, B has been cited in at least one academic works: =over 4 =item * I, Daniel Alman Available at SANS InfoSec Reading Room: Covert Channels L Direct link: L =back =head1 COPYRIGHT Copyright 2003-2007, Philippe Bruhat. All rights reserved. =head1 LICENSE This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =cut libnet-proxy-perl-0.12.orig/MANIFEST0000444000175000017500000000151710705511550015171 0ustar abiabiBuild.PL Changes lib/Net/Proxy.pm lib/Net/Proxy/Connector.pm lib/Net/Proxy/Connector/connect.pm lib/Net/Proxy/Connector/connect_ssl.pm lib/Net/Proxy/Connector/dual.pm lib/Net/Proxy/Connector/dummy.pm lib/Net/Proxy/Connector/ssl.pm lib/Net/Proxy/Connector/tcp.pm lib/Net/Proxy/Tutorial.pod Makefile.PL MANIFEST This list of files META.yml README script/connect-tunnel script/sslh t/00load.t t/05connector.t t/10proxy_new.t t/11proxy_accessor.t t/12proxy_connectors.t t/13proxy_stat.t t/14proxy_debug.t t/20dummy.t t/21connect.t t/22dual.t t/30tcp_tcp.t t/31tcp_tcp_multi.t t/32tcp_connect.t t/33dual.t t/34hook_in.t t/34hook_out.t t/35hook_dual.t t/35signal.t t/36ctssl_tcp.t t/36ssl_tcp.t t/36tcp_ctssl.t t/36tcp_ssl.t t/37connectssl_tcp.t t/40tcp_fail.t t/41listen_fail.t t/90compile.t t/pod-coverage.t t/pod.t t/test.cert t/test.key t/Util.pm