title: How can I use a PKCS12 ssl certificate with newer LWP?
body: <p>I'm having difficulty getting a PKCS12 certificate to work using new LWP (6.x). Basically, this code works under perl5.8.8 and old <a href="http://metacpan.org/module/Crypt%3a%3aSSLeay" rel="nofollow">Crypt::SSLeay</a> (version 0.57) and <a href="https://metacpan.org/release/libwww-perl" rel="nofollow">LWP</a> (version 5.826):</p>
  
  <pre><code>local $ENV{HTTPS_PKCS12_PASSWORD} = $sslPassword;
  local $ENV{HTTPS_PKCS12_FILE} = $pkcs12_cert;
  my $response = LWP::UserAgent-&gt;new-&gt;request(POST($url, Content =&gt; $content));
  </code></pre>
  
  <p>...but does not under perl5.14.2 and latest versions of Crypt::SSLeay 0.64) and LWP (6.03).</p>
  
  <p>By doesn't work, I mean that I get an HTTP::Response object back like:</p>
  
  <pre><code>bless( {
       '_content' =&gt; 'Can\'t connect to host:port
  ',
       '_rc' =&gt; 500,
       '_headers' =&gt; bless( { 
                              'client-warning' =&gt; 'Internal response',
                              'client-date' =&gt; 'Thu, 27 Sep 2012 18:28:34 GMT',
                              'content-type' =&gt; 'text/plain'
                            }, 'HTTP::Headers' ),
       '_msg' =&gt; 'Can\'t connect to host:port',
       '_request' =&gt; ...
  )
  </code></pre>
  
  <p>I understand that much ssl-related code has changed in LWP lately; is PKCS12 support known to still work?  Should I be setting different variables/options in order to get the certificate and password to be picked up?</p>
  
  <p>I've also tried passing this to LWP::UserAgent->new with no luck:</p>
  
  <pre><code>ssl_opts =&gt; {
      SSL_use_cert =&gt; 1,
      SSL_cert_file =&gt; $pkcs12_cert,
      SSL_passwd_cb =&gt; sub { $sslPassword },
  }
  </code></pre>
  
  <hr>
  
  <p>Follow-up: I converted the PKCS12 cert to a PEM:</p>
  
  <pre><code>openssl pkcs12 -in my_pkcs12.p12 -out mycert.pem -clcerts -nokeys
  openssl pkcs12 -in my_pkcs.p12 -out mykey.pem -nocerts
  &lt;passphrase entered&gt;
  </code></pre>
  
  <p>and can use the new files via:</p>
  
  <pre><code>curl -k --cert mycert.pem --key mykey.pem --pass passphrase --cert-type PEM https://url
  </code></pre>
  
  <p>...and set these environment variables in the test script:</p>
  
  <pre><code>$ENV{HTTPS_CERT_FILE} = 'mycert.pem';
  $ENV{HTTPS_KEY_FILE}  = 'mykey.pem';
  </code></pre>
  
  <p>...and <em>that</em> works as well under older LWP, and again does not work under new LWP.. so at least it is not something specific to PKCS12 certs at issue, but rather something more fundamental in how SSL handling has been changed internally.</p>