My Quest for the Elusive Non-blocking SSL Client

I have been trying to construct an SSL client which works in non-blocking mode on a variety of platforms (i.e. it needs to run under UNIX (or Linux) and Windows). It uses a custom select dispatcher, which I am at this point unwilling to change (it would affect too much existing code).

I have looked at the following modules for implementing this client:

How I got Net::SSLeay to work

Being primarily a UNIX guy, I usually implement first on UNIX (in this case snow leopard), and then port to Windows. After much weeping and gnashing of teeth, I was able to get such a client working on my Mac using Net::SSLeay. The weeping and gnashing of teeth occured primarily not because Net::SSLeay is bad, or difficult, but because it isn't really well documented. In the process of implementation, here's what I arrived at:

References

The code which I "stole" off the web, came for the following source:

http://devpit.org/wiki/OpenSSL_with_nonblocking_sockets_(in_Perl)

Since I was writing a client and his sample code was for a server, I didn't use much of his code, but the magical incantations were useful. I didn't implement his "drain the socket on read strategy", because the server always closes when its finished writing and "read" always selects true on a closed socket, so I don't have to worry about orphan data in the SSL buffer.

Replies are listed 'Best First'.
Re: Quest for the Elusive Non-Blocking SSL Client
by ambrus (Abbot) on Dec 19, 2010 at 14:45 UTC

    Did you try AnyEvent::Handle? It comes with SSL support, backed by Net::SSLeay, which, funnily, uses the openssl library (not the ssleay library).

      Thanks for the suggestion, but the problem isn't doing event handling, its getting Net::SSLeay to install under windows. If I could get Net::SSLeay to install, then I could try my working code (which works very well on snow leopard) under Windows.

      Also, when I say "Windows", I guess I mean "ActiveState Perl on Windows", and when I say "Install", I mean "Install using cpan or ActiveState Package Manager".

      I'm really not much of a Windows person.

Re: Quest for the Elusive Non-Blocking SSL Client
by syphilis (Archbishop) on Dec 18, 2010 at 22:23 UTC
    IO::Socket::SSL builds and installs fine for me on Windows. What was the problem you came up against ?

    Cheers,
    Rob

      Rob,

      Thanks for the reply. Here's what I'm seeing:

      • The install of IO::Socket::SSL fails because it can't find Net::SSLeay.
      • Of course, if I could install Net::SSLeay, I wouldn't need IO::Socket::SSL. I already have code which works with Net::SSLeay (at least under snow leopard).
      • Net::SSLeay fails because it can't find openssl. It asks me to set the OPENSSL_PREFIX environment variable.
      • It looks like there is a directory under C: which contains OpenSSL (after I download and install the latest openssl, which for some reason, doesn't set the OPENSSL_PREFIX environment variable). So I set the environment variable.
      • However, this version of openssl is newer than the openssl with which Net::SSLeay was built (which is not surprising, because I just downloaded it).
      • It still tries to install, but ultimately, it fails...

      Does this mean that I have to abandon the package managers and go rebuild Net::SSLeay from source?

      Thanks,

      Bill B

      Hm. I have IO::Socket::SSL running on Linux box. I didn't even install it, it came bundled with perl (gentoo linux)

      But as a side note, the openssl library really sucks for not providing direct support for non-blocking reading/writing. I guess thinking only in threads plays its role in design. Please, don't take it as complain. Just pointing out, that things are not simple even outside of Perl :)