Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > IO::Socket::SSL : $sock is not defined if client is not SSL (crash)

Reply
Thread Tools

IO::Socket::SSL : $sock is not defined if client is not SSL (crash)

 
 
sgt_b2002@yahoo.com
Guest
Posts: n/a
 
      12-18-2005
Working on a small utility and everything works perfectly using
IO:Socket::INET. When I move over to using IO::Socket::SSL, a certain
piece of code no longer works. Essentially, this is a "one client only"
application. If the original socket is defined, subsequent connections
are immediately closed. When using IO::Socket::INET, this works great.
Moving over to SSL, things die.

Here when a non SSL connection is established, the new $sock object is
never defined. Because it is not defined, calls to it obviously fail.
Shouldn't $tempsock be created regardless of whether or not SSL is
being used? I'm thinking that SSL_error_trap was designed to deal with
those cases.

Right now, the below code will kill the server if a non SSL client
connects. Here is the error:

Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be
16 at /usr/lib/perl5/5.8.7/i686-linux/Socket.pm line 370.

If I remove everything but the $tempsock object, I'll get a "can't call
method close on an undefined object".

Any ideas?

[code snippet]
$agent_sock = new IO::Socket::SSL(
LocalHost => $aip,
LocalPort => $aport,
Proto => 'tcp',
Listen => 1,
Reuse => 1,
SSL_cert_file => 'server.crt',
SSL_key_file => 'server.key',
SSL_error_trap => \&ssl_error,
);
$agent_sock or die "Socket error: $!";

$sel = IO::Select->new($agent_sock);

while(@ready = $sel->can_read) {

foreach $fh (@ready) {
if ($fh == $agent_sock) {
if (defined $asock) {
my $tempsock = $agent_sock->accept();
my ($tempsock,$tempaddr) = $agent_sock->accept();
my ($tempport, $tempip) = sockaddr_in($tempaddr);
my $tempipnum = inet_ntoa($tempip);
$tempsock->close;
print "Closed an unsolicited Agent connection from
".$tempipnum.':'.$tempport."\n";
last;
}
($asock, $a_addr) = $agent_sock->accept();
($a_port, $a_ip) = sockaddr_in($a_addr);
$a_ipnum = inet_ntoa($a_ip);
print "Relay Agent connecting from: $a_ipnum:$a_port\n";
$sel->add($asock);
<snip>
[/code snippet]

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      12-19-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Working on a small utility and everything works perfectly using
> IO:Socket::INET. When I move over to using IO::Socket::SSL, a certain
> piece of code no longer works. Essentially, this is a "one client only"
> application.


What is a "one client only" application?

> If the original socket is defined, subsequent connections
> are immediately closed.


Then why even bother accepting them?

> When using IO::Socket::INET, this works great.
> Moving over to SSL, things die.
>
> Here when a non SSL connection is established, the new $sock object is
> never defined. Because it is not defined, calls to it obviously fail.


Then don't make calls to it when it is undefined.

> Shouldn't $tempsock be created regardless of whether or not SSL is
> being used?


Apparently not.

> I'm thinking that SSL_error_trap was designed to deal with
> those cases.


It was, but probably the way it "deals" with them is not the way you think
it does.

Since you haven't shown us the code of \&ssl_error, which is what you
pass to SSL_error_trap, how are we to know what you think it does?


>
> Right now, the below code will kill the server if a non SSL client
> connects. Here is the error:
>
> Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be
> 16 at /usr/lib/perl5/5.8.7/i686-linux/Socket.pm line 370.
>
> If I remove everything but the $tempsock object, I'll get a "can't call
> method close on an undefined object".
>
> Any ideas?


Yeah. check the success and/or failure of "accept", and act accordingly.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User-defined exception: "global name 'TestRunError' is not defined" jmike@alum.mit.edu Python 1 07-10-2008 12:37 PM
problem reconnecting an ssl client, the ssl ruby daemon hang jkevinlb@gmail.com Ruby 1 05-16-2007 05:22 PM
.Net client and SSL mutual authentication : 403 Forbidden, client certificate not sent Mfenetre ASP .Net Security 11 10-12-2005 03:02 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM
Python SSL Socket Client to Java SSL Server. HELP me PLEASE. Krzysztof Paź Python 1 09-26-2003 08:36 PM



Advertisments