Skip to content

Commit

Permalink
fixed a serious TLS handshake bug in Mojo::IOLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 20, 2010
1 parent adf7e0d commit 2e3824e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -47,7 +47,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Fixed a small under bug in Mojolicious::Lite.
- Fixed logging of UTF-8 errors. (und3f)
- Fixed Mojo::DOM parser bug. (esskar)
- Fixed TLS handshake bug in Mojo::DOM. (und3f)
- Fixed TLS handshake bug in Mojo::IOLoop. (und3f)

0.999929 2010-08-17 00:00:00
- Removed OS X resource fork files.
Expand Down
19 changes: 16 additions & 3 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -12,6 +12,7 @@ use IO::File;
use IO::Poll qw/POLLERR POLLHUP POLLIN POLLOUT/;
use IO::Socket;
use Mojo::ByteStream;
use Scalar::Util 'weaken';
use Socket qw/IPPROTO_TCP TCP_NODELAY/;
use Time::HiRes 'time';

Expand Down Expand Up @@ -508,9 +509,15 @@ sub start_tls {
# Arguments
my $args = ref $_[0] ? $_[0] : {@_};

# Weaken
weaken $self;

# Options
my %options =
(SSL_startHandshake => 0, Timeout => $self->connect_timeout);
my %options = (
SSL_startHandshake => 0,
SSL_error_trap => sub { $self->_drop_immediately(shift) },
Timeout => $self->connect_timeout
);
if ($args->{tls_ca_file}) {
$options{SSL_ca_file} = $args->{tls_ca_file};
$options{SSL_verify_mode} = 0x01;
Expand Down Expand Up @@ -624,9 +631,15 @@ sub _accept {
# Listen
my $l = $self->{_listen}->{$listen};

# Weaken
weaken $self;

# TLS handshake
my $tls = $l->{tls};
$socket = IO::Socket::SSL->start_SSL($socket, %$tls) if $tls;
if ($tls) {
$tls->{SSL_error_trap} = sub { $self->_drop_immediately(shift) };
$socket = IO::Socket::SSL->start_SSL($socket, %$tls);
}

# Add connection
my $id = "$socket";
Expand Down

0 comments on commit 2e3824e

Please sign in to comment.