3 #this is a hacked up version of one of the examples in the Net::SSLeay
4 #documentation, It will return a x509 cert and contents sufficient for
5 #use in Business::OnlinePayment::FnsVanuatu just use
6 # perl ./getfnscert.pl >> FnsVanuatu.pm to append the new data
7 # you'll have to edit things to make it go in the certconst subroutine
9 use Net::SSLeay qw(die_now die_if_ssl_error) ;
10 Net::SSLeay::load_error_strings();
11 Net::SSLeay::SSLeay_add_ssl_algorithms();
12 Net::SSLeay::randomize();
14 ($dest_serv, $port, $msg) = ('psc.paysystems.com', '443', 'GET /');
15 $port = getservbyname ($port, 'tcp') unless $port =~ /^\d+$/;
16 $dest_ip = gethostbyname ($dest_serv);
17 $dest_serv_params = sockaddr_in($port, $dest_ip);
19 socket (S, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!";
20 connect (S, $dest_serv_params) or die "connect: $!";
21 select (S); $| = 1; select (STDOUT); # Eliminate STDIO buffering
23 # The network connection is now open, lets fire up SSL
25 $ctx = Net::SSLeay::CTX_new() or die_now("Failed to create SSL_CTX $!");
26 Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL)
27 and die_if_ssl_error("ssl ctx set options");
28 $ssl = Net::SSLeay::new($ctx) or die_now("Failed to create SSL $!");
29 Net::SSLeay::set_fd($ssl, fileno(S)); # Must use fileno
30 $res = Net::SSLeay::connect($ssl) and die_if_ssl_error("ssl connect");
31 # print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n";
32 print Net::SSLeay::dump_peer_certificate($ssl),"\n";
33 my $cert = Net::SSLeay::get_peer_certificate($ssl);
34 print Net::SSLeay::PEM_get_string_X509($cert),"\n";
35 # print Net::SSLeay::get_verify_result($ssl),"\n";
38 $res = Net::SSLeay::write($ssl, $msg); # Perl knows how long $msg is
39 die_if_ssl_error("ssl write");
40 shutdown S, 1; # Half close --> No more output, sends EOF to server
41 $got = Net::SSLeay::read($ssl); # Perl returns undef on failure
42 die_if_ssl_error("ssl read");
45 Net::SSLeay::free ($ssl); # Tear down connection
46 Net::SSLeay::CTX_free ($ctx);