ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.24 by root, Sat May 24 15:11:46 2008 UTC vs.
Revision 1.26 by root, Sat May 24 15:20:46 2008 UTC

145 145
146When this parameter is given, it enables TLS (SSL) mode, that means it 146When this parameter is given, it enables TLS (SSL) mode, that means it
147will start making tls handshake and will transparently encrypt/decrypt 147will start making tls handshake and will transparently encrypt/decrypt
148data. 148data.
149 149
150TLS mode requires Net::SSLeay to be installed (it will be loaded
151automatically when you try to create a TLS handle).
152
150For the TLS server side, use C<accept>, and for the TLS client side of a 153For the TLS server side, use C<accept>, and for the TLS client side of a
151connection, use C<connect> mode. 154connection, use C<connect> mode.
152 155
153You can also provide your own TLS connection object, but you have 156You can also provide your own TLS connection object, but you have
154to make sure that you call either C<Net::SSLeay::set_connect_state> 157to make sure that you call either C<Net::SSLeay::set_connect_state>
155or C<Net::SSLeay::set_accept_state> on it before you pass it to 158or C<Net::SSLeay::set_accept_state> on it before you pass it to
156AnyEvent::Handle. 159AnyEvent::Handle.
160
161See the C<starttls> method if you need to start TLs negotiation later.
157 162
158=item tls_ctx => $ssl_ctx 163=item tls_ctx => $ssl_ctx
159 164
160Use the given Net::SSLeay::CTX object to create the new TLS connection 165Use the given Net::SSLeay::CTX object to create the new TLS connection
161(unless a connection object was specified directly). If this parameter is 166(unless a connection object was specified directly). If this parameter is
673 678
674 # all others are fine for our purposes 679 # all others are fine for our purposes
675 } 680 }
676} 681}
677 682
683=item $handle->starttls ($tls[, $tls_ctx])
684
685Instead of starting TLS negotiation immediately when the AnyEvent::Handle
686object is created, you can also do that at a later time by calling
687C<starttls>.
688
689The first argument is the same as the C<tls> constructor argument (either
690C<"connect">, C<"accept"> or an existing Net::SSLeay object).
691
692The second argument is the optional C<Net::SSLeay::CTX> object that is
693used when AnyEvent::Handle has to create its own TLS connection object.
694
695=cut
696
678# TODO: maybe document... 697# TODO: maybe document...
679sub starttls { 698sub starttls {
680 my ($self, $ssl, $ctx) = @_; 699 my ($self, $ssl, $ctx) = @_;
700
701 $self->stoptls;
681 702
682 if ($ssl eq "accept") { 703 if ($ssl eq "accept") {
683 $ssl = Net::SSLeay::new ($ctx || TLS_CTX ()); 704 $ssl = Net::SSLeay::new ($ctx || TLS_CTX ());
684 Net::SSLeay::set_accept_state ($ssl); 705 Net::SSLeay::set_accept_state ($ssl);
685 } elsif ($ssl eq "connect") { 706 } elsif ($ssl eq "connect") {
710 Net::SSLeay::BIO_write ($_[0]{tls_rbio}, ${$_[1]}); 731 Net::SSLeay::BIO_write ($_[0]{tls_rbio}, ${$_[1]});
711 &_dotls; 732 &_dotls;
712 }; 733 };
713} 734}
714 735
736=item $handle->stoptls
737
738Destroys the SSL connection, if any. Partial read or write data will be
739lost.
740
741=cut
742
743sub stoptls {
744 my ($self) = @_;
745
746 Net::SSLeay::free (delete $self->{tls}) if $self->{tls};
747 delete $self->{tls_rbio};
748 delete $self->{tls_wbio};
749 delete $self->{tls_wbuf};
750 delete $self->{filter_r};
751 delete $self->{filter_w};
752}
753
715sub DESTROY { 754sub DESTROY {
716 my $self = shift; 755 my $self = shift;
717 756
718 Net::SSLeay::free (delete $self->{tls}) if $self->{tls}; 757 $self->stoptls;
719} 758}
720 759
721=item AnyEvent::Handle::TLS_CTX 760=item AnyEvent::Handle::TLS_CTX
722 761
723This function creates and returns the Net::SSLeay::CTX object used by 762This function creates and returns the Net::SSLeay::CTX object used by

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines