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

Hi Monks, Can anybody explain me 'Net::SSLeay::ssl_write_all ($ssl, $stuff)'?? 1 how to get the $ssl . 2.What is this argument. I could not get the proper result from this as well as the post_https method of Net::SSLeay from the payment gateway. Then I shifted to use curl for same purpose. While using the curl from the perl script I succeeded a bit more to get the appropriate error measseges which were not coming in case of Net::SSLeay methods. I need advice on difference of following in the perl script, 1 `curl` and 2 system (curl) Also, if I m running the curl command with the same arguments as in perl script from the command line I m getting different results(but more appropriate). Please help me out on this. Thanks, SHAM
  • Comment on Difference between curl and Net;;SSLeay for getting the SSL connection

Replies are listed 'Best First'.
Re: Difference between curl and Net;;SSLeay for getting the SSL connection
by erroneousBollock (Curate) on Sep 14, 2007 at 16:52 UTC
    There's no need to use Net::SSLeay to do what you describe in perl, instead use the module LWP::UserAgent.

    When LWP::UserAgent gets a url that starts with 'https://' it automatically loads and uses Crypt::SSLeay to handle SSL.

    LWP::UserAgent provides a very simple API which allows you to talk to HTTP servers, which is basically all you need to do here.

    Next time, please format your post using the allowed HTML tags... it'll make it much easier for others to read.

    -David

      Hi David, What you are saying is very correct, I had used this simple method to get what I want, but I was getiint the following errors

      1.Not proxied and
      2.peer certificate is not varified
      And fact is that Client is saying that if you are having SSL implementation to connect to thier gateway it will not ask for certificae.

      Can you please look at the following code.
      use strict; use Data::Dumper; use LWP::UserAgent; use HTTP::Request; use HTTP::Headers; use LWP::Debug qw(+); my $method = 'POST'; my $host = 'orbitalvar1.paymentech.net'; my $uri = '/authorize'; $uri = 'https://orbital1.paymentech.net/authorize'; ## This is the fake request we are generating my $xmlRequest = '<?xml version="1.0" encoding="UTF-8"?>'. '<Request>'. '<NewOrder>'. '<IndustryType>EC</IndustryType>'. '<MessageType>A</MessageType>'. '<BIN>000002</BIN>'. '<TerminalID>001</TerminalID>'. '<AccountNum>4111111111111111</AccountNum>'. '<Exp>1009</Exp>'. '<CurrencyCode>840</CurrencyCode>'. '<CurrencyExponent>2</CurrencyExponent>'. '<CardSecVal>213</CardSecVal>'. '<AVSzip>33408</AVSzip>'. '<AVSaddress1>test address</AVSaddress1>'. '<AVScity>miami</AVScity>'. '<AVSstate>FL</AVSstate>'. '<AVSphoneNum>5618926384</AVSphoneNum>'. '<AVSname>Raj Malahotra</AVSname>'. '<AVScountryCode>US</AVScountryCode>'. '<AVSDestzip>33408</AVSDestzip>'. '<AVSDestaddress1>Dest addresss</AVSDestaddres +s1>'. '<AVSDestcity>testcity</AVSDestcity>'. '<AVSDeststate>FL</AVSDeststate>'. '<AVSDestname>Raj Malahotra</AVSDestname>'. '<AVSDestcountryCode>US</AVSDestcountryCode>'. '<CustomerProfileFromOrderInd>A</CustomerProfi +leFromOrderInd>'. '<OrderID>091933208935</OrderID>'. '<Amount>1500</Amount>'. '<BMLShippingCost>1500</BMLShippingCost>'. + '<BMLTNCVersion>5</BMLTNCVersion>'. + '</NewOrder>'. '</Request>'; my $MIME_Version = '1.1'; my $content_type = 'application/PTI42'; my $content_length = length($xmlRequest); my $content_transfer_encoding = 'text'; my $request_number = '1'; my $document_type = 'Request'; my $header = HTTP::Headers->new; $header->header ( 'MIME-Version' => $MIME_Version, 'Content-Type' => $content_type, 'Content-length' => $content_length, + 'Content-transfer-encoding' => $content_transfer_encodi +ng, 'Request-number' => $request_number, 'Document-type' => $document_type, + ); my $fix_headres = 'POST /AUTHORIZE HTTP/1.1' . "\r\n" . $header; my $HTTP_req = HTTP::Request->new($method,$uri,$header,$xmlRequest) ; my $UserAgent = LWP::UserAgent->new(); #$ENV{HTTPS_PROXY} = '192.168.9.10:443'; $UserAgent->env_proxy; my $host_response = $UserAgent->request($HTTP_req); print STDERR "\n========= headers ======== \n" . Dumper($header); + print STDERR "\n========= request ======== \n" . Dumper($HTTP_req +); print STDERR "\n========= response ======== \n" . Dumper($host_re +sponse); __END__
      Please suggest what I am missing while using LWP::UserAgent. Thanks, SHAM.....
        Firstly, please use <readmore> tags when you post large amounts of code.

        I was getiint the following errors

        1.Not proxied and
        Please read the Crypt::SSLeay documentation.

        Don't use LWP's env_proxy method, it doesn't work properly in all situations with HTTPS. Set the HTTPS_PROXY variable in the environment, Crypt::SSLeay will pick up on it and use the appropriate arguments to the SSL connect() method. You may also need to set the HTTPS_PROXY_USERNAME and HTTPS_PROXY_PASSWORD variables (if the proxy requires basic authentication).

        2.peer certificate is not varified
        And fact is that Client is saying that if you are having SSL implementation to connect to thier gateway it will not ask for certificae.
        So does the server require peer certificate authentication or not?

        If it does, you'll need to set the HTTPS_CERT_FILE and HTTPS_KEY_FILE environment variables, so that Crypt::SSLeay will know where to look for those files.

        Can you please look at the following code.
        I have no idea what you're doing with all that header manipulation... can I presume that the payment gateway documentation prescribes those actions?

        -David