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;

In reply to Net::SSLeay and file descriptors by vancetech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.