Is it possible to create a read / write FileHandle to call system ()?

I have a login test POP3 script that uses IO::Socket::INETto read and write to an open socket over TCP: 110. This is what I'm used to: -

my $sock = IO::Socket::INET->new(
    PeerAddr    =>  "$h:$port",
    Proto       =>  "tcp",
) or die "$!\n";

However, I also need to test the same POP3 session through SSL-protected POP3S (TCP: 995).

I found that I can use the following on the command line, which gets me a similar state as "telnet hostname 110" but is encrypted: -

openssl s_client -crlf -connect hostname:995

I hope to find a way that I can configure some kind of read / write FileHandle or socket in the openssl command, which I can read until it is empty, and then write to the required POP3 commands, then read the answers, and so on ...

, , , , perl, " " !

, , script , perl, .

@ventatsu , IPC::Open2 : -

my ($sslread,$sslwrite);
my $ssl_fh = open2(
    $sslread,
    $sslwrite,
    "openssl s_client -crlf -connect mail.example.com:995"
) or die "$!\n";

while (<$sslread>) {
    print;
    if (/^\+OK.*$/) {
        ## Try to log in
        print $sslwrite "USER $u\r\n";
        print "USER $u\n";
        while (<$sslread>) {
            print;
            if (/^\+OK.*$/) {
                ## Keep going
                print $sslwrite "PASS $p\r\n";
                print "PASS $p\n";
                while (<$sslread>) {
                    print;
                }       
            }       
        }       
        print $sslwrite "QUIT"; 
        print "QUIT\n";
    }       
}       

waitpid( $ssl_fh, 0 );
my $child_exit_status = $? >> 8;

SSL : -

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.

, POP3 SSL CLI : -

openssl s_client -crlf -connect mail.example.com:995
<snip out the SSL bumph />
+OK The Microsoft Exchange POP3 service is ready.
USER mailtest@example.com
+OK
PASS Abcd3fGh
+OK User successfully logged on.

SSL- script : -

Testing pop3s on mail.example.com:995
<snip out the SSL bumph />
+OK The Microsoft Exchange POP3 service is ready.
USER mailtest@example.com
+OK
PASS Abcd3fGh
-ERR Logon failure: unknown user name or bad password.

?

+3
1

IPC::Open2 , . , IO::Socket::SSL, IO::Socket::INET, .

Update: , \r. man s_client -crlf + . $sslwrite, "\r\n". , , "\ r\r\n" . , -crlf openssl .

+1

All Articles