[PATCH] AnyEvent::Handle: avoid use of Net::SSLeay::ST_OK() in _dotls()

Chris Novakovic chris at chrisn.me.uk
Sat Sep 1 03:26:52 CEST 2018


When checking whether the on_starttls callback should be triggered for
an AnyEvent::Handle object, _dotls() checks whether the TLS handshake
has been successfully performed by checking whether the current state of
the internal Net::SSLeay SSL context equals Net::SSLeay::ST_OK().
ST_OK() is mapped to the SSL_ST_OK constant in OpenSSL, but this
constant was removed in OpenSSL 1.1.0 [1], and will therefore be
undefined (and trigger a crash) if OpenSSL 1.1.0 or above is being used.

Fortunately, there's a function equivalent to this check in the OpenSSL
API --- SSL_is_init_finished() [2,3] --- that just wasn't being exposed
via Net::SSLeay. It avoids the need to use any of the handshake state
constants and is available in every version of OpenSSL and LibreSSL
supported by Net-SSLeay. We've now exposed this function in Net::SSLeay
[4], and a patch against AnyEvent-7.14/lib/AnyEvent/Handle.pm is
attached that uses this function instead, allowing AnyEvent to work with
OpenSSL 1.1.0 and above. Net::SSLeay::is_init_finished() is available
from developer release 1.86_05 onwards, so there should also be some
sort of minimum dependency on the next stable release after that
somewhere; it'll probably be 1.88, and we plan to release it soon.

This was reported by Michael Loeffler on rt.cpan.org [5], which I know
isn't used by AnyEvent, but I thought I'd CC him so he's aware of the
fix and can close that ticket himself if this patch is accepted.

[1]
https://github.com/openssl/openssl/commit/f3ae986218ad2269758f4994ffe137b8233dc0b8
[2]
https://github.com/openssl/openssl/blob/f460e8396f8cb1be1bbd6a8a22d7e24b80d8a607/ssl/statem/statem.c#L76
[3] https://www.openssl.org/docs/man1.1.1/man3/SSL_is_init_finished.html
[4]
https://github.com/radiator-software/p5-net-ssleay/commit/041a0787be29bf648c6947a172c735c66e70fe01
[5] https://rt.cpan.org/Ticket/Display.html?id=124723
-------------- next part --------------
diff -Naur AnyEvent-7.14/lib/AnyEvent/Handle.pm AnyEvent-7.14-new/lib/AnyEvent/Handle.pm
--- AnyEvent-7.14/lib/AnyEvent/Handle.pm	2016-11-26 03:33:34.000000000 +0000
+++ AnyEvent-7.14-new/lib/AnyEvent/Handle.pm	2018-09-01 02:04:42.769287806 +0100
@@ -2113,7 +2113,7 @@
    }
 
    $self->{_on_starttls}
-      and Net::SSLeay::state ($self->{tls}) == Net::SSLeay::ST_OK ()
+      and Net::SSLeay::is_init_finished ($self->{tls})
       and (delete $self->{_on_starttls})->($self, 1, "TLS/SSL connection established");
 }
 


More information about the anyevent mailing list