Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to create a read/write FileHandle for a system() call?
    primarykey
    data
    text
    <p>I have a POP3 login test script which uses <code>IO::Socket::INET</code> to read and write to the opened socket on TCP:110. This is what I'm used to: -</p> <pre><code>my $sock = IO::Socket::INET-&gt;new( PeerAddr =&gt; "$h:$port", Proto =&gt; "tcp", ) or die "$!\n"; </code></pre> <p>However, I also need to test the same POP3 conversation through SSL-secured POP3S (TCP:995).</p> <p>I've found that I can use the following on the command-line, which gets me a similar state as "telnet hostname 110", but encrypted: -</p> <pre><code>openssl s_client -crlf -connect hostname:995 </code></pre> <p>I am hoping to find a way that I can set up some sort of read/write FileHandle or socket on the openssl command, which I can read til it's empty, then write in the required POP3 commands into, then read the responses, and so on...</p> <p>I feel like because I can see it on screen, it's close enough to grab, but I don't quite know my way around perl well enough, to "get it" and move on!</p> <p>Unfortunately, the server this script will be run on, is not able to have more perl modules installed, which might have been an obvious solution.</p> <p><em>UPDATE</em></p> <p>Thanks to @ventatsu for the inspiration, I am now using <code>IPC::Open2</code> like this: -</p> <pre><code>my ($sslread,$sslwrite); my $ssl_fh = open2( $sslread, $sslwrite, "openssl s_client -crlf -connect mail.example.com:995" ) or die "$!\n"; while (&lt;$sslread&gt;) { print; if (/^\+OK.*$/) { ## Try to log in print $sslwrite "USER $u\r\n"; print "USER $u\n"; while (&lt;$sslread&gt;) { print; if (/^\+OK.*$/) { ## Keep going print $sslwrite "PASS $p\r\n"; print "PASS $p\n"; while (&lt;$sslread&gt;) { print; } } } print $sslwrite "QUIT"; print "QUIT\n"; } } waitpid( $ssl_fh, 0 ); my $child_exit_status = $? &gt;&gt; 8; </code></pre> <p>My non-SSL test scrip works thusly: -</p> <pre><code>Testing pop3 on mail.example.com:110 +OK The Microsoft Exchange POP3 service is ready. USER mailtest@example.com +OK PASS Abcd3fGh +OK User successfully logged on. </code></pre> <p>The credentials work OK when I run the POP3 commands in an interactive SSL session on the CLI like this: -</p> <pre><code>openssl s_client -crlf -connect mail.example.com:995 &lt;snip out the SSL bumph /&gt; +OK The Microsoft Exchange POP3 service is ready. USER mailtest@example.com +OK PASS Abcd3fGh +OK User successfully logged on. </code></pre> <p>But my SSL test script only almost works thusly: -</p> <pre><code>Testing pop3s on mail.example.com:995 &lt;snip out the SSL bumph /&gt; +OK The Microsoft Exchange POP3 service is ready. USER mailtest@example.com +OK PASS Abcd3fGh -ERR Logon failure: unknown user name or bad password. </code></pre> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload