title: How to use LWP with client cert and CA
body: <p>I curenttly have some perl code which drops out to shell to call curl to talk to an end point with certificates. this works fine but i always feel like i am cheating in perl when i escape to shell and take the easy option. below is the curl command i am using and this works fine.</p>
  
  <p>$soap_response = <code>echo '$soap_request' | curl --cacert $self-&gt;{'server_cert'} --cert $self-&gt;{'client_cert'} -d '\@-' -H 'SOAPAction:urn:anonOutInOp' $self-&gt;{'end_point'} -s | xmllint -format -</code>;</p>
  
  <p>I have a CA file, and a client file, both in PEM format.</p>
  
  <p>I have tried to use LWP and Net::SSL to make this communication purely in perl and get rid of the reliance on curl but i cannot for the life of me get it to work.</p>
  
  <p>I set up the enviroment for Net:SSL as</p>
  
  <pre><code>#set up the ssl envrioment for Net::SSL
  $ENV{HTTPS_DEBUG} = 1;
  $ENV{HTTPS_CERT_FILE} = $client_cert;
  $ENV{HTTPS_CA_FILE}   = $server_cert;
  $ENV{HTTPS_CA_DIR}    = $certificate_dir;
  </code></pre>
  
  <p>then send my request as</p>
  
  <pre><code>my $ua = new LWP::UserAgent();
  my $request = HTTP::Request-&gt;new(POST =&gt; $endpoint);
  $request-&gt;header(SOAPAction =&gt; '"query"');
  $request-&gt;content($query);
  $request-&gt;content_type("text/xml; charset=utf-8");
  
  my $response = $ua-&gt;request($request);
  print $response-&gt;content,"\n";
  </code></pre>
  
  <p>The output i get when running is</p>
  
  <pre><code>SSL_connect:before/connect initialization
  SSL_connect:SSLv2/v3 write client hello A
  SSL_connect:SSLv3 read server hello A
  SSL_connect:SSLv3 read server certificate A
  SSL_connect:SSLv3 read server key exchange A
  SSL_connect:SSLv3 read server certificate request A
  SSL_connect:SSLv3 read server done A
  SSL_connect:SSLv3 write client certificate A
  SSL_connect:SSLv3 write client key exchange A
  SSL_connect:SSLv3 write change cipher spec A
  SSL_connect:SSLv3 write finished A
  SSL_connect:SSLv3 flush data
  SSL_connect:SSLv3 read finished A
  &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;soapenv:Body&gt;&lt;soapenv:Fault&gt;&lt;faultcode xmlns:ns1="http://xml.apache.org/axis/"&gt;ns1:HTTP&lt;/faultcode&gt;&lt;faultstring&gt;(403)Forbidden&lt;/faultstring&gt;&lt;detail&gt;&lt;ns2:hostname xmlns:ns2="http://xml.apache.org/axis/"&gt;hh0pgw01&lt;/ns2:hostname&gt;&lt;ns3:HttpErrorCode xmlns:ns3="http://xml.apache.org/axis/"&gt;403&lt;/ns3:HttpErrorCode&gt;&lt;/detail&gt;&lt;/soapenv:Fault&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>so it seems like its exchanged the CA file and is happy with the host however my request is then being rejected with 403 forbiden error, which i suspect is to do with my client key not being exchanged properly with the request.</p>
  
  <p>Can anyone help me resolve this issue or suggest where it may be falling down.</p>