Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Proxy Authentication

by rmb (Novice)
on Jun 10, 2004 at 15:12 UTC ( [id://363104]=note: print w/replies, xml ) Need Help??


in reply to Re: Proxy Authentication
in thread Proxy Authentication

Corion, Thanks, I commented them out because I could not get them to work. I don't like the idea of passwords being in plain text either in the script or in the users environment. Do you know of anyway round that? Thanks, rmb

Replies are listed 'Best First'.
Re^3: Proxy Authentication
by Corion (Patriarch) on Jun 10, 2004 at 15:18 UTC

    Of course - ask the user for it:

    use ExtUtils::MakeMaker; my $user = prompt "Proxy user:"; my $password = prompt "Proxy password:"; # ... continue as before

    In short, if you want to use data in a program, somehow that data needs to get to that program. There is no way around it.

    Also, regarding your manual proxy settings, "I could not get them to work" is not really helpfull, as the weather impedes my ESP abilities somewhat. Maybe you can describe to us a bit more precise what fails, and how it fails, and what the log messages and error messages are...

Re^3: Proxy Authentication
by xiper (Friar) on Jun 11, 2004 at 04:39 UTC
    I don't like the idea of passwords being in plain text either in the script or in the users environment. Do you know of anyway round that?
    Well, you could just manually (or semi-manually) add the raw header
    Proxy-Authorization: Basic <string>
    where <string> is a base64 encoded string containing the username and password separated by a colon, generated like so:
    use MIME::Base64; print encode_base64( join( ':', $username, $password ) );
    and either manually print it in the right spot (after the GET or POST line)
    print "Proxy-Authorization: Basic SSdtIG5vdCB0aGF0IHN0dXBpZC4uLiA6KQ== +\n";
    or, in your case, use HTTP::Headers
    use HTTP::Headers; my $header = HTTP::Headers->new( Proxy_Authorization => 'Basic SSdtIG5 +vdCB0aGF0IHN0dXBpZC4uLiA6KQ==' );
    and add $header as the third parameter to your HTTP::Request constructor:
    my $request = new HTTP::Request('GET', $ARGV[0], $header);
    (insert usual disclaimers about passwords... blah blah... security through obscurity... blah blah...)

    - ><iper

    use japh; print;
      xiper,

      This looked very promising and tried the code below but get the 502 error. Is their a way of establishing exactly what the proxy is objecting to? I am sure that the domain\username and password are correct.

      #!/usr/local/bin/perl use LWP::UserAgent; use HTTP::Request; use HTTP::Response; use HTTP::Headers; my $header = HTTP::Headers->new( Proxy_Authorization => 'Basic ZW1lYVx +yYmlzc2V0OnJvbjQ1Ng==' ); my $ua = new LWP::UserAgent; #$ua->proxy('http', 'http://domain\username:password@10.10.10.10:8080/ +'); $ua->proxy('http', 'http://10.10.10.10:8080/'); $ua->no_proxy('my_domain.com'); my $request = new HTTP::Request('GET', $ARGV[0], $header); #$request->proxy_authorization_basic( 'domain\username', 'password' ); my $response = $ua->request($request); if ($response->is_success) { print $response->content; } else { print $response->error_as_HTML; }
      And this is the error that I am getting

      $ perl -d ./get_url.pl http://www.google.co.uk Loading DB routines from perl5db.pl version 1.19 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(./get_url.pl:8): my $header = HTTP::Headers->new( Proxy_Authori +zation => 'Basic ZW1lYVxyYmlzc2V0OnJvbjQ1Ng==' ); DB<1> s HTTP::Headers::new(/usr/local/lib/perl5/site_perl/5.8.0/HTTP/Headers.p +m:70): 70: my($class) = shift; DB<1> s HTTP::Headers::new(/usr/local/lib/perl5/site_perl/5.8.0/HTTP/Headers.p +m:71): 71: my $self = bless {}, $class; DB<1> s HTTP::Headers::new(/usr/local/lib/perl5/site_perl/5.8.0/HTTP/Headers.p +m:72): 72: $self->header(@_) if @_; # set up initial headers DB<1> x $header 0 undef DB<2> r scalar context return from HTTP::Headers::new: 'proxy-authorization' = +> 'Basic ZW1lYVxyYmlzc2V0OnJvbjQ1Ng==' main::(./get_url.pl:10): my $ua = new LWP::UserAgent; DB<2> r <HTML> <HEAD><TITLE>An Error Occurred</TITLE></HEAD> <BODY> <H1>An Error Occurred</H1> 502 Proxy Error ( The ISA Server denies the specified Uniform Resource + Locator (URL). ) </BODY> </HTML> Debugged program terminated. Use q to quit or R to restart,

      Any advice appreciated.

      rmb

        rmb, I hope you already changed your password! if not, do it as soon as you can.

        you see, between a password in plain text in your user environment and a password base64-encoded on PerlMonks, I would prefer the first :-)

        cheers,
        Aldo King of Laziness, Wizard of Impatience, Lord of Hubris
        Well, the code looks correct, and as eclark mentioned below, it works okay for me. It sounds like either the proxy isn't accepting your username/domain/password, or it isn't accepting the url you're giving it - look up the error code in your proxy's documentation. Make sure you can access the same page with the same credentials using a browser with the same proxy settings on the same computer. Try different url types and/or combinations of domain/username (eg, "username", "domain\username", "username@domain", "domain.suffix.com.uk\username", "username@domain.suffix.com.uk", etc).

        A good way to debug these things (as samtregar recently mentioned), is to write a small proxy using HTTP::Proxy, point your script & browser to it, and see what the difference is in the request header they send. Here's a snippit to get you started:

        #! /usr/bin/perl use strict; use HTTP::Proxy qw( :log ); my $proxy = new HTTP::Proxy; $proxy->port( 8081 ); $proxy->logfh( *STDOUT ); $proxy->logmask( ALL ); $proxy->start;
        Good luck!

        - ><iper

        use japh; print;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-20 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found