我有一個POP3登錄測試腳本,它使用IO::Socket::INET
讀取和寫入TCP:110上打開的套接字。這是我已經習慣了: -是否可以爲system()調用創建讀/寫FileHandle?
my $sock = IO::Socket::INET->new(
PeerAddr => "$h:$port",
Proto => "tcp",
) or die "$!\n";
不過,我也需要測試通過SSL安全POP3S(TCP:995)相同的POP3對話。
我發現我可以使用命令行,這讓我類似的狀態「的telnet主機名110」以下,但加密: -
openssl s_client -crlf -connect hostname:995
我希望能找到一個我可以在openssl命令上設置某種讀/寫FileHandle或套接字的方式,我可以直接讀取它,然後將所需的POP3命令寫入,然後讀取響應,等等......
我覺得,因爲我可以在屏幕上看到它,它足夠接近抓取,但我不太瞭解perl的方式,以「得到它」,並繼續前進!
不幸的是,這個腳本將運行的服務器不能安裝更多的perl模塊,這可能是一個明顯的解決方案。
UPDATE
感謝@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 [email protected]
+OK
PASS Abcd3fGh
+OK User successfully logged on.
當我在CLI上的交互式SSL會話中運行POP3命令時,證書工作正常,如下所示: -
openssl s_client -crlf -connect mail.example.com:995
<snip out the SSL bumph />
+OK The Microsoft Exchange POP3 service is ready.
USER [email protected]
+OK
PASS Abcd3fGh
+OK User successfully logged on.
但我的SSL測試腳本只差一點作品正是如此: -
Testing pop3s on mail.example.com:995
<snip out the SSL bumph />
+OK The Microsoft Exchange POP3 service is ready.
USER [email protected]
+OK
PASS Abcd3fGh
-ERR Logon failure: unknown user name or bad password.
我在做什麼錯?
@ventatsu感謝您的快速響應。無法添加更多模塊的問題使IO :: Socket :: SSL成爲非啓動器,但我確實發現「IPC :: Open2」**對我來說是可用的,到目前爲止,我幾乎得到了一個工作SSL測試... – furriephillips
我會在我的原始文章@ventatsu的更新中解釋,所以我可以有多行輸出。 – furriephillips