Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

How to enable SSL support in sockets connected with a sock5 server?

by dxxd116 (Beadle)
on Jan 12, 2009 at 11:57 UTC ( #735647=perlquestion: print w/replies, xml ) Need Help??
dxxd116 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Guys: Does anyone have experience in this situation? First, I established a socket connection to a socks5 proxy Server through the use of Net::SOCKS module. Then I realized that I try to enable SSL in order to communicate with the gmail smtp server through the "STARTTLS" command. Then I am lost, what should be done next in order to send an email through the socket? Codes are as below:
use Net::SOCKS; use Net::SSLeay; use IO::Socket::INET; use IO::Socket::SSL; use MIME::Base64 qw[encode_base64 decode_base64]; use Digest::HMAC_MD5 qw[hmac_md5_hex]; my $sock = new Net::SOCKS(socks_addr => '', socks_port =>9188, #user_id => 'the_user', #user_password => 'the_password', #force_nonanonymous => 0, protocol_version => 5); print "Cannot establish connection using socks!\n" if !$sock; print "Connecting to google gmail now!\n"; my $f= $sock->connect(peer_addr => '', peer_port => 587); open FH, ">:utf8","socks.txt"; my $line=<$f>; print $line ; print FH $line; print $f "EHLO localhost\n"; $line=<$f>; print $line; print FH $line; print $f "StartTLS\n"; $line=<$f>; print $line; print FH $line; #What is next?...
  • Comment on How to enable SSL support in sockets connected with a sock5 server?
  • Download Code

Replies are listed 'Best First'.
Re: How to enable SSL support in sockets connected with a sock5 server?
by Corion (Pope) on Jan 12, 2009 at 12:07 UTC

    IO::Socket::SSL has a ->start_SSL method, which will upgrade your "plain" socket to a SSL-encrypted connection. I think this is what all the other things that use StartTLS use (Google Code Search), but if not, maybe you find the appropriate things there. Also, have you looked at what CPAN has to offer for ESMTP, which seems what you're implementing?

      Connecting to google gmail now! 220 ESMTP q18sm34685365pog.9 at your service, [] 250-SIZE 35651584 Usage: IO::Handle::error(handle) at C:/Perl/site/lib/IO/Socket/ +line 611, <GEN0> line 3.
      Above is the reponse I got after I use IO::Socket::SSL::start_SSL method on the socket connected through a socks5 server. Code added are as below
      if(not IO::Socket::SSL::start_SSL($f, SSL_version => "SSLv3 TLSv1")){ die "Couldn't start TLS: \n" . IO::Socket::SSL::errstr ."\n"; } print $f "EHLO localhost\n"; $line=<$f>; print $line; print FH $line; print $f "AUTH LOGIN\n"; $line=<$f>; print $line; print FH $line;
      Any ideas? Thank you very much!
        Specifically in connection to the gmail servers, I had significantly more luck a few months back when I wrote an automailer using Net::SMTP::TLS - the final code is published here.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://735647]
Approved by Corion
[marto]: 5 is an Odd_number
[Corion]: That could fix itself within the next 24 hours :)
[marto]: we should blame LanX
[marto]: purely because he isn't here :P
[Eily]: marto oh ok, since normally it would have been 1, which is odd as well, I didn't think this was what you were refering to
[Eily]: what? Does that mean we can't blame LanX when he's there?
[marto]: but 5 in total, is odd, where as 10 is even
[marto]: sure, we can blame LanX when he is around, but he is more likely to moan about it :P
[Eily]: there's 6 in total though :P
[Eily]: unless LanX did something to maths when I wasn't looking

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-03-20 10:00 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (249 votes). Check out past polls.