I need to move a floppy disk image up to a device, via SSL. The device
expects a nice XML wrapper around the bytes of the disk image.
I have SSL working, and I can do XML conversations quite well. What I can't
seem to do (and I apologize in advance for my limited Perl knowledge) is
push that floppy image onto the SSL pipe with success. I know the opening
exchange is working, and I know the closing exchange is working, but I don't
think the right bytes, or number of bytes of that image file are going
across, although a network capture shows that ABOUT the right number of
bytes are sent over the wire. So, the question is, how do I best read in a
binary file and plop its bytes right there between those two XML chunks?
Here is the type of work I have put together:
#!/usr/bin/perl -w
use Socket;
use Net::SSLeay qw(die_now die_if_ssl_error) ;
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();
$CRLF = "\x0d\x0a";
($dest_serv, $port) = @ARGV; # Read command line
$port = getservbyname ($port, 'tcp') unless $port =~ /^\d+$/;
$dest_ip = gethostbyname ($dest_serv);
$dest_serv_params = sockaddr_in($port, $dest_ip);
socket (S, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!";
connect (S, $dest_serv_params) or die "connect: $!";
select (S); $| = 1; select (STDOUT); # Eliminate STDIO buffering
$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(S)); # Must use fileno
$res = Net::SSLeay::connect($ssl) and die_if_ssl_error("ssl connect");
print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n";
###################### part 1
$msg1 = "<?xml version=\"1.0\"?>< opening XML tags ...
><INSERT_VIRTUAL_FLOPPY IMAGE_LOCATION = \"c:\\disk.img\"
IMAGE_LENGTH=\"1474582\"/>$CRLF";
$res = Net::SSLeay::write($ssl, $msg1); # Perl knows how long $msg is
die_if_ssl_error("ssl write");
#CORE::shutdown S, 1; # Half close --> No more output, sends EOF to server
$got1 = Net::SSLeay::read($ssl); # Perl returns undef on failure
die_if_ssl_error("ssl read");
Net::SSLeay::print_errs();
print "\n---------------------I send:\n$msg1\n";
print "\nResponse to first third------------:\n";
print $got1;
########################## 2
sleep 2;
open (IMG, "disk.img") or die;
binmode IMG;
$bob = read(IMG, $file, 1474582);
$res = Net::SSLeay::write($ssl, $file); # Perl knows how long $msg is
die_if_ssl_error("ssl write");
$got2 = Net::SSLeay::read($ssl); # Perl returns undef on failure
die_if_ssl_error("ssl read");
print "\nResponse to middle (file) third------------:\n";
Net::SSLeay::print_errs();
print $got2;
############### 3
$msg3 = "<Closing XML tags...>$CRLF";
$res = Net::SSLeay::write($ssl, $msg3); # Perl knows how long $msg is
die_if_ssl_error("ssl write");
CORE::shutdown S, 1; # Half close --> No more output, sends EOF to server
$got3 = Net::SSLeay::read($ssl); # Perl returns undef on failure
die_if_ssl_error("ssl read");
Net::SSLeay::print_errs();
print "\n---------------------I send:\n$msg3\n";
print "\nResponse to last third------------:\n";
print $got3;
Net::SSLeay::free ($ssl); # Tear down connection
Net::SSLeay::CTX_free ($ctx);
close S;
Evan Scheessele
ESDO: HP-Corvallis
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]