Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: IO::Socket:SSL and Net::Server STDOUT redirection

by Zucan (Beadle)
on Nov 17, 2014 at 19:41 UTC ( [id://1107468]=note: print w/replies, xml ) Need Help??


in reply to Re: IO::Socket:SSL and Net::Server STDOUT redirection
in thread IO::Socket:SSL and Net::Server STDOUT redirection

This didn't work for me:
my $client = $server->accept; open(STDIN, "<&=", $client) || die "Couldn't dup client to stdin"; open(STDOUT, ">&=", $client) || die "Couldn't dup client to stdout"; print "The client should see this STDOUT message.\n"; print $client "The client should see this SOCKET message.\n";
What I see is this:
$ nc --ssl localhost 12345 The client should see this SOCKET message

Before I was using "nc --ssl host port", I was using "openssl s_client -connect host:port" for my testing. I got all the certificate info at the beginning of the output and I didn't see anything that helped. I would love to know what you saw in the openssl output that clued you in on the file descriptor. In any case, changing my script to your suggestion doesn't change anything for me.

On a similar note: I was reading up on IO redirection in Perl and it doesn't seem surprising that system() and exec() continues to use the standard STDIN/STDIO/STDERR file descriptors. The redirection in Perl stays within perl and doesn't carry forth externally. It may be possible to use FileHandle or Tie::Handle to get it to work, but since using an command pipe with open() seems to work, it doesn't seem worth the extra effort. It works with POE as well.

Mostly, I am bummed by the fact that IO::Socket::SSL acts differently from IO::Socket::INET. I can't get any redirection working at the moment. I at least have something working with Net::Server and with POE.

Replies are listed 'Best First'.
Re^3: IO::Socket:SSL and Net::Server STDOUT redirection
by McA (Priest) on Nov 17, 2014 at 19:59 UTC

    Hi Zucan,

    sorry, but I have to admit I'm an idiot. While testing several options being curious, I did exactly the same as you:

    print $client "The client should see this message.\n";

    I left this line unchanged while changing others and was happy to "having found the solution".

    Sorry again.

    But with using openssl s_client I found out that sending the message via STDOUT seemed to circumvent the encryption layer. This lead me to the conclusion that you have to redirect some "upper" layer.

    UPDATE: Being aschamed about my error I gave it another try. I now did a:

    *STDOUT = $client;

    I really hope this also works for you now.

    Regards
    McA

      Ah, that worked!

      Here is the working example:
      #!/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; *STDOUT = $client; print "The client should see this STDOUT message.\n"; print $client "The client should see this SOCKET message.\n"; close($client);
      The output I now see is as follows:
      $ nc --ssl localhost 12345 The client should see this STDOUT message. The client should see this SOCKET message.
      Thank you!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1107468]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-29 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found