I have a basic question using PERL for connecting to a socket and
communicating with a credit card authorization gateway (but maintaining
the SSL data integrity). I have read several documents on SSLeay
(including the FAQ and Programmers reference), but I am still having some
difficulty.
Here is the scenario:
Our application is in PERL. We have a shoppingcart software that runs on
our secure server (https:secure.myserver.com). We are needing to connect
to a secure transaction gateway (https:secure.transaction-gateway.com)
via a socket to authorize the credit card information that comes through
the cart. After we connect, we send them the users cc info, and then need
to get back the comma delimited string that contains the response code
(accepted or declined). We have no problem doing this with PERL
insecurely(without SSL), but we are not sure the minimum requirements of
the SSL function calls used to transfer the encrypted data. We would
normally use filehandles to communicate with the server we are connecting
to.
Here is our routine (but what are we missing??) :
$remote_host =
"www.authorize.net";
$remote_port = "443"; # SSL Port
use Socket;
socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
# build the remote address
$internet_addr = inet_aton($remote_host) ||
die "Couldn't convert $remote_host into an Internet address:
$!\n";
$paddr = sockaddr_in($remote_port, $internet_addr);
connect(SERVER, $paddr) || die "Couldn't connect to
$remote_host:$remote_port : $!\n";
# create an SSL structure ???(are we suppose to pass in
# arguments or our filehandle or can con be our filehandle?) need to make
'con' a variable???
con=(SSL *)SSL_new();
# give it a file descriptor to use ???(can we use our filehandle- SERVER
instead of con?)???
SSL_set_fd(con,s);
# connect
SSL_connect(con);
$headers = qq~
POST /scripts/authrequest.asp HTTP/1.1
Host:
www.authorize.net:443
Content-type: application/x-www-form-urlencoded
Content-length:32
~;
$post = "home=Cosby&favorite+flavor=flies";
$data = $headers . $post;
# send data
SSL_write(con,$data,???);
# receive data
SSL_read(con,buf,??unkown??);
# close(socket)
SSL_shutdown(con)
-------------
Thanks for your help
using PERL for connecting/sending/receiving data through a secure socket.
I would be happy to give you my kids in compensation for your help
:)
Are there any good resources that describe the SSLeay function calls in
more detail -- describing the arguments or variables associated with each
function(besides the ones at openssl.org, or through the FAQ and
programmers reference -- I have checked all of the links through
those).
Greg Graf
System Admin
GSG WEBS/GSG Net
