I am currently working on a script to automatically log in to a web application on my company's web site. There are several pages that are part of the login process. One page asks the user for a digital certificate.

I can handle all of the other pages with LWP::UserAgent. As far as I can tell, Net::SSLeay and Crypt::SSLeay are the modules that can handle certificates. Since Net::SSLeay is not an LWP module, I'd like to use Crypt::SSLeay if possible.

According to the documentation for Crypt::SSLeay, this is how you include PEM encoded certificate and private key files:

$ENV{HTTPS_CERT_FILE} = 'cert.pem'; $ENV{HTTPS_KEY_FILE} = 'key.pem';

It looks like the PEM files that I have aren't being loaded, because when I use nonexistent filenames, it doesn't give me any errors.

Here's a snippet of the code I'm using to make my request:

my $cookie_jar = HTTP::Cookies->new; my $ua = new LWP::UserAgent; if ( $proxy ne "" ) { $ua->proxy(['http', 'https'], $proxy); } my $request = new HTTP::Request("POST", $url); $request->content_type('application/x-www-form-urlencoded'); $request->content($content); $ua->agent("Mozilla/4.7"); $cookie_jar->add_cookie_header($request); my $response = $ua->request($request); $cookie_jar->extract_cookies($response);

$content is the data that I'm posting (user name and password). Of course, I've set $url to the URL I'm trying to post to, and $proxy is the proxy server. With a little bit of extra code to handle timeouts, this is the same code that I've used for other POSTs.

I've got OpenSSL version 0.9.6b installed, all the latest versions of the LWP modules, and version 0.29 of Crypt::SSLeay.

Am I using Crypt:SSLeay correctly? Do I need to add code to my request? Or should I be using Net:SSLeay, or some other module?

Thanks in advance.
P.J.


In reply to Sending a certificate with an https request by pjsmith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.