Zucan has asked for the wisdom of the Perl Monks concerning the following question:
Here is an example of me using IO::Socket::SSL, which does not work:#!/usr/bin/perl -w use strict; use IO::Socket::INET; my $port = 12345; my $server = IO::Socket::INET->new( LocalAddr => '127.0.0.1', LocalPort => $port, Listen => 10, Reuse => 1, ) or die "failed to listen: $!"; my $client = $server->accept; my $cf = $client->fileno; open(STDIN, "<&$cf") || die "Couldn't dup client to stdin"; open(STDOUT, ">&$cf") || die "Couldn't dup client to stdout"; print "The client should see this message.\n"; close($client);
Here is the output of each script when ran:#!/usr/bin/perl -w use strict; use IO::Socket::SSL; my $port = 12345; my $server = IO::Socket::SSL->new( LocalAddr => '127.0.0.1', LocalPort => $port, Listen => 10, Reuse => 1, SSL_cert_file => 'cert.pem', SSL_key_file => 'key.pem', ) or die "failed to listen: $!"; my $client = $server->accept; my $cf = $client->fileno; open(STDIN, "<&$cf") || die "Couldn't dup client to stdin"; open(STDOUT, ">&$cf") || die "Couldn't dup client to stdout"; print "The client should see this message.\n"; close($client);
$ nc localhost 12345 The client should see this message. $ nc --ssl localhost 12345
There are plenty of examples about how to do a forking server with the IO::Socket module with STDIN/STDOUT redirection. As soon as the IO::Socket module is flipped to SSL, the redirection no longer works. The above examples do not do what I really wanted, which is to shell out and execute a command. If I can't get a basic print statement to work with IO redirection, then shelling out won't work either.
I looked at other modules too. Net::Server was more useful to me and seemed to work better. Here is an example without using SSL:The above works perfectly. All three echo commands go over the socket. Here is the SSL example:#!/usr/bin/perl -w package NetServer; use strict; use base qw(Net::Server::Fork); sub process_request { my $self = shift; ### COMMAND PIPE print "Executing Command Pipe\n"; open DATA, "/usr/bin/echo ==== Command Pipe Successful|" or die "Couldn't open command: $!"; while (defined(my $line = <DATA>)) { chomp($line); print "$line\n"; } close DATA; ### SYSTEM COMMAND print "Executing System Command\n"; system("/usr/bin/echo ==== System Command Successful"); ### EXEC COMMAND print "Executing Exec Command\n"; exec "/usr/bin/echo ==== Exec Command Successful" or die "Couldn't exec command: $!"; } NetServer->run(port=>12345);
I tried it with both "ssl" and "ssleay" and the results were identical. Surprisingly, I get the output from the Command Pipe, but I don't get output from the other two. The following is the output from the non-ssl and the ssl example scripts from above:#!/usr/bin/perl -w package NetServer; use strict; use base qw(Net::Server::Fork); sub SSL_key_file { "key.pem" } sub SSL_cert_file { "cert.pem" } sub process_request { my $self = shift; ### COMMAND PIPE print "Executing Command Pipe\n"; open DATA, "/usr/bin/echo ==== Command Pipe Successful|" or die "Couldn't open command: $!"; while (defined(my $line = <DATA>)) { chomp($line); print "$line\n"; } close DATA; ### SYSTEM COMMAND print "Executing System Command\n"; system("/usr/bin/echo ==== System Command Successful"); ### EXEC COMMAND print "Executing Exec Command\n"; exec "/usr/bin/echo ==== Exec Command Successful" or die "Couldn't exec command: $!"; } #NetServer->run(proto => 'ssl', port=>12345); NetServer->run(proto => 'ssleay', port=>12345);
$ nc localhost 12345 Executing Command Pipe ==== Command Pipe Successful Executing System Command ==== System Command Successful Executing Exec Command ==== Exec Command Successful $ nc --ssl localhost 12345 Executing Command Pipe ==== Command Pipe Successful Executing System Command Executing Exec Command
Just to be sure the Command Pipe section wasn't interfering with the other two sections, I did play around with commenting all but one section at a time and the results were the same... the Command Pipe works but the System Command and Exec Command sections do not.
I spent the last several days researching this on the Internet, reading up in my books and playing around extensively in code. I now ask for Wisdom from the Perl Monks community. I would like to know why redirection doesn't work at all with IO::Socket::SSL and what am I missing with regards to the system() and exec() calls that prevents redirection working with the Net::Server module.
Thank you,
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: IO::Socket:SSL and Net::Server STDOUT redirection
by McA (Priest) on Nov 17, 2014 at 16:45 UTC | |
by Zucan (Beadle) on Nov 17, 2014 at 19:41 UTC | |
by McA (Priest) on Nov 17, 2014 at 19:59 UTC | |
by Zucan (Beadle) on Nov 17, 2014 at 21:23 UTC | |
Re: IO::Socket:SSL and Net::Server STDOUT redirection
by Loops (Curate) on Nov 17, 2014 at 19:21 UTC | |
by Zucan (Beadle) on Nov 17, 2014 at 21:51 UTC |