kebex has asked for the wisdom of the Perl Monks concerning the following question:

I've created a network XML service that needs SSL encryption. Since it's socket based I wanted to use IO::Socket:SSL (instead of INET), but I have problems:

When I run:

$sock = new IO::Socket::SSL (
Listen => 5,
LocalAddr => 'localhost',
LocalPort => 9000,
Proto => 'tcp',
SSL_verify_mode => 0x01
) or die "unable to create socket: $!\n";

I get the error message 'No such file or directory'. I assume that it means it can't find the certificate or the key.

(I got this code from Jukka Juslins paper on his work at CERN (http://elan.cs.hut.fi:9090/erikoistyo.html).)

I have created the certificate and the key with openssl and put them both in certs/ and in @INC's path to IO::Socket::SSL but there's no difference.

I've also put in an 'init_context' before the above command:

IO::Socket::SSL::context_init (
SSL_use_cert => 1,
SSL_key_file => 'certs/server-key.pem',
SSL_cert_file => 'certs/server-cert.pem'
);

But then I get the error message:
Can't use string ("SSL_use_cert") as a HASH ref while "strict refs" in use at /usr/local/lib/perl5/site_perl/5.6.1/IO/Socket/SSL.pm line 684.

If soneone has successfully used IO::Socket:SSL (without LWP), I would appreciate a few pointers to get me going.

Thanks
kebex

  • Comment on IO::Socket:SSL 'No such file or directory'

Replies are listed 'Best First'.
Re: IO::Socket:SSL 'No such file or directory'
by arturo (Vicar) on Jul 19, 2001 at 18:53 UTC

    The second error message you're getting is because (I'm willing to bet, though I don't have the module's code here) you're calling a subroutine that was designed as a method as if it were a regular subroutine. But a method is designed to take a reference to an object first (and an object is a reference to some kind of data structure that's been blessd into a package). Long story short: that sub expects to be called as a method, and to be passed a hashref as its first argument. By calling it directly, you're upsetting its expectations. So call it as a method of your $sock object:

    $sock->context_init(SSL_use_cert =>1, SSL_key_file =>'certs/sev/er-key.pem', SSL_cert_file =>'certs/server-cert.pem');

    Depending on your setup, you might want to make those relative paths absolute, in case you move the script.

    HTH!

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'