Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

IO::Socket::SSL with http proxy tunnel?

by lembark (Novice)
on Jun 15, 2022 at 19:13 UTC ( [id://11144778]=perlquestion: print w/replies, xml ) Need Help??

lembark has asked for the wisdom of the Perl Monks concerning the following question:

Trying to access a service behind a firewall that uses http proxies.

Q: Anyone have experience, or reference to a working example, of using IO::Socket::* to connect with this soft of a HTTP->HTTPS tunnel proxy?

thank you

IO-Socket-SSL-2.074.tar.gz
Homegrown perl-5.34.1.
RHEL6 for system lib's [yes, 6].

Curl to the site shows something like (hostnames & IP's modified):
curl --verbose 'https://foo.bar.net/bim/bam' * Trying 10.10.10.10... * Connected to 10.10.10.10 (10.10.10.10) port 80 (#0) * Establish HTTP proxy tunnel to foo.bar.net:443 > CONNECT foo.bar.net:443 HTTP/1.1 > Host: foo.bar.net:443 > User-Agent: curl/7.44.0 > Proxy-Connection: Keep-Alive > < HTTP/1.1 503 Service Unavailable < Cache-Control: no-cache < X-XSS-Protection: 1 < Connection: close < Content-Type: text/html; charset=utf-8 < Content-Length: 750 < Pragma: no-cache < Set-Cookie: frobnicate; path=/; Httponly < * Received HTTP code 503 from proxy after CONNECT * Closing connection 0 curl: (56) Received HTTP code 503 from proxy after CONNECT
Looking at the tunnel portion I've tried several approaches shown in IO::Socket::SSL:

Under "Talk Plain and SSL With The Same Socket"

Alternatives are turning a stock INET socket into an SSL:

my $sock = IO::Socket::INET->new(...) or die $!; IO::Socket::SSL->start_SSL($sock,%sslargs) or die $SSL_ERROR; $sock->stop_SSL or die $SSL_ERROR;
Or starting the connection without SSL and going from there:
my $sock = IO::Socket::SSL->new( PeerAddr => ... SSL_startHandshake => 0, %sslargs ) or die $!;
Both of these get me "connection reset by peer", maybe because the HTTP portion of the connection doesn't like the switchover to SSL.
eval { my $sock = IO::Socket::INET->new( %http_argz ); IO::Socket::SSL->start_SSL ( $sock , %https_argz ); print $sock "GET / HTTP/1.0\r\n\r\n"; };
Leaves me with a sigpipe.

Replies are listed 'Best First'.
Re: IO::Socket::SSL with http proxy tunnel?
by roboticus (Chancellor) on Jun 16, 2022 at 03:42 UTC

    lembark:

    Sorry, I can't help with your problem. But I *did* want to mention that since you were logged in, you can go back and use the 'Edit' link to tweak that node node into shape instead of making a new one that's formatted nicely.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: IO::Socket::SSL with http proxy tunnel?
by nikosv (Deacon) on Jun 26, 2022 at 12:54 UTC
    Try
    BEGIN {
    $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "IO::Socket::SSL";
    $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
    $ENV{PERL_LWP_ENV_PROXY}='http://127.0.0.1:5865';
    $ENV{HTTPS_PROXY}               = 'http://127.0.0.1:5865';
    $ENV{HTTPS_DEBUG} = 1;
    $ENV{HTTPS_VERSION} = '3';
    }  
    
Re: IO::Socket::SSL with http proxy tunnel?
by lembark (Novice) on Jun 15, 2022 at 19:18 UTC
    So much for checking the preview...
    
    Trying to access a service behind a firewall that uses http proxies.
    
    Q: Anyone have experience, or reference to a working example, of using
    IO::Socket::* to connect with this soft of a HTTP->HTTPS tunnel proxy?
    
    thank you
    
    IO-Socket-SSL-2.074.tar.gz
    Homegrown perl-5.34.1.
    RHEL6 for system lib's yes, 6.
    
    Curl to the site shows something like (hostnames & IP's modified):
    
    curl --verbose 'https://foo.bar.net/bim/bam'
    * Trying 10.10.10.10... * Connected to 10.10.10.10 (10.10.10.10) port 80 (#0)
    * Establish HTTP proxy tunnel to foo.bar.net:443
    > CONNECT foo.bar.net:443 HTTP/1.1
    > Host: foo.bar.net:443 > User-Agent: curl/7.44.0
    > Proxy-Connection: Keep-Alive
    >
    < HTTP/1.1 503 Service Unavailable
    < Cache-Control: no-cache
    < X-XSS-Protection: 1
    < Connection: close
    < Content-Type: text/html; charset=utf-8
    < Content-Length: 750
    < Pragma: no-cache
    < Set-Cookie: frobnicate; path=/; Httponly
    < * Received HTTP code 503 from proxy after CONNECT
    * Closing connection 0 curl: (56) Received HTTP code 503 from proxy after CONNECT
    
    Looking at the tunnel portion I've tried several approaches shown in IO::Socket::SSL:
    
    https://metacpan.org/dist/IO-Socket-SSL/view/lib/IO/Socket/SSL.pod
    
    Under "Talk Plain and SSL With The Same Socket" alternatives are turning a stock INET
    socket into an SSL:
      
      my $sock = IO::Socket::INET->new(...) or die $!;
      IO::Socket::SSL->start_SSL($sock,%sslargs) or die $SSL_ERROR;
      $sock->stop_SSL or die $SSL_ERROR;
    
    Or starting the connection without SSL and going from there:
    
      my $sock = IO::Socket::SSL->new( PeerAddr => ... SSL_startHandshake => 0, %sslargs ) or die $!;
    
    Both of these get me "connection reset by peer", maybe because the HTTP portion of
    the connection doesn't like the switchover to SSL.
    
      eval
      {
        my $sock = IO::Socket::INET->new( %http_argz );
        IO::Socket::SSL->start_SSL ( $sock , %https_argz );
        print $sock "GET / HTTP/1.0\r\n\r\n";
       };
    
    Leaves me with a sigpipe. 
      Re-implementing HTTP over proxy using a raw SSL socket seems like a lot of work. (personally I would try to get the service to use SSH tunneling, but maybe you don't have control over that)

      I would guess someone already did HTTP proxy in Perl before, and a little googling proved fruitful:

      Stack Overflow: Perl HTTPS over proxy using LWP::UserAgent

      Does that do what you need?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11144778]
Approved by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found