… | |
… | |
673 | |
673 | |
674 | # all others are fine for our purposes |
674 | # all others are fine for our purposes |
675 | } |
675 | } |
676 | } |
676 | } |
677 | |
677 | |
|
|
678 | =item $handle->starttls ($tls[, $tls_ctx]) |
|
|
679 | |
|
|
680 | Instead of starting TLS negotiation immediately when the AnyEvent::Handle |
|
|
681 | object is created, you can also do that at a later time by calling |
|
|
682 | C<starttls>. |
|
|
683 | |
|
|
684 | The first argument is the same as the C<tls> constructor argument (either |
|
|
685 | C<"connect">, C<"accept"> or an existing Net::SSLeay object). |
|
|
686 | |
|
|
687 | The second argument is the optional C<Net::SSLeay::CTX> object that is |
|
|
688 | used when AnyEvent::Handle has to create its own TLS connection object. |
|
|
689 | |
|
|
690 | =cut |
|
|
691 | |
678 | # TODO: maybe document... |
692 | # TODO: maybe document... |
679 | sub starttls { |
693 | sub starttls { |
680 | my ($self, $ssl, $ctx) = @_; |
694 | my ($self, $ssl, $ctx) = @_; |
|
|
695 | |
|
|
696 | $self->stoptls; |
681 | |
697 | |
682 | if ($ssl eq "accept") { |
698 | if ($ssl eq "accept") { |
683 | $ssl = Net::SSLeay::new ($ctx || TLS_CTX ()); |
699 | $ssl = Net::SSLeay::new ($ctx || TLS_CTX ()); |
684 | Net::SSLeay::set_accept_state ($ssl); |
700 | Net::SSLeay::set_accept_state ($ssl); |
685 | } elsif ($ssl eq "connect") { |
701 | } elsif ($ssl eq "connect") { |
… | |
… | |
710 | Net::SSLeay::BIO_write ($_[0]{tls_rbio}, ${$_[1]}); |
726 | Net::SSLeay::BIO_write ($_[0]{tls_rbio}, ${$_[1]}); |
711 | &_dotls; |
727 | &_dotls; |
712 | }; |
728 | }; |
713 | } |
729 | } |
714 | |
730 | |
|
|
731 | =item $handle->stoptls |
|
|
732 | |
|
|
733 | Destroys the SSL connection, if any. Partial read or write data will be |
|
|
734 | lost. |
|
|
735 | |
|
|
736 | =cut |
|
|
737 | |
|
|
738 | sub stoptls { |
|
|
739 | my ($self) = @_; |
|
|
740 | |
|
|
741 | Net::SSLeay::free (delete $self->{tls}) if $self->{tls}; |
|
|
742 | delete $self->{tls_rbio}; |
|
|
743 | delete $self->{tls_wbio}; |
|
|
744 | delete $self->{tls_wbuf}; |
|
|
745 | delete $self->{filter_r}; |
|
|
746 | delete $self->{filter_w}; |
|
|
747 | } |
|
|
748 | |
715 | sub DESTROY { |
749 | sub DESTROY { |
716 | my $self = shift; |
750 | my $self = shift; |
717 | |
751 | |
718 | Net::SSLeay::free (delete $self->{tls}) if $self->{tls}; |
752 | $self->stoptls; |
719 | } |
753 | } |
720 | |
754 | |
721 | =item AnyEvent::Handle::TLS_CTX |
755 | =item AnyEvent::Handle::TLS_CTX |
722 | |
756 | |
723 | This function creates and returns the Net::SSLeay::CTX object used by |
757 | This function creates and returns the Net::SSLeay::CTX object used by |