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

I am writing a SSL enabled HTTP client but am having problems getting the SSL layer to initialize before writing to the socket. To create the tcp socket I am using IO::Socket::INET.

Any examples i've seen use Socket to create and associate the file descriptor to the SSL layer. Is there any way I can associate the file descriptor from the IO::Socket::INET object to the SSL layer? My code below only produces the output of: Cipher `(NONE)'

#!/usr/local/bin/perl use IO::Socket::INET; use Net::SSLeay qw(die_now die_if_ssl_error ssl_read_all print_errs) ; Net::SSLeay::load_error_strings(); Net::SSLeay::SSLeay_add_ssl_algorithms(); Net::SSLeay::randomize(); $|++; ($dest_serv, $port, $msg) = @ARGV; # Read command line my $sock = IO::Socket::INET->new( Proto => 'tcp', Type => SOCK_STREAM, Blocking => 0 ); $sock->connect( $port, inet_aton($dest_serv) ); $ctx = Net::SSLeay::CTX_new() or die_now("Failed to create SSL_CTX $!" +); Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) and die_if_ssl_error("ssl ctx set options"); $ssl = Net::SSLeay::new($ctx) or die_now("Failed to create SSL $!"); Net::SSLeay::set_fd($ssl, fileno($sock)); $res = Net::SSLeay::connect($ssl) and die_if_ssl_error("ssl connect"); print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n"; $res = Net::SSLeay::write($ssl, "GET / HTTP/1.1\nHOST: $dest_serv\n\n" +); die_if_ssl_error("ssl write"); CORE::shutdown $sock, 1; $got = Net::SSLeay::ssl_read_all($ssl); die_if_ssl_error("ssl read"); Net::SSLeay::free ($ssl); Net::SSLeay::CTX_free ($ctx); close $sock; print $got;

Replies are listed 'Best First'.
Re: Net::SSLeay and file descriptors
by Anonymous Monk on Sep 13, 2006 at 07:35 UTC
      That module works nicely, thankyou.