]> git.kaiwu.me - nginx.git/commitdiff
SSL: avoid calling SSL_shutdown() during handshake (ticket #901).
authorMaxim Dounin <mdounin@mdounin.ru>
Fri, 19 Feb 2016 14:27:30 +0000 (17:27 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Fri, 19 Feb 2016 14:27:30 +0000 (17:27 +0300)
This fixes "called a function you should not call" and
"shutdown while in init" errors as observed with OpenSSL 1.0.2f
due to changes in how OpenSSL handles SSL_shutdown() during
SSL handshakes.

src/event/ngx_event_openssl.c

index 1ca1945e59caf4584a7d268f2bddc68ad193cb73..de10d48a5d9b267b5b6b914781e614e156466803 100644 (file)
@@ -1767,6 +1767,19 @@ ngx_ssl_shutdown(ngx_connection_t *c)
     int        n, sslerr, mode;
     ngx_err_t  err;
 
+    if (SSL_in_init(c->ssl->connection)) {
+        /*
+         * OpenSSL 1.0.2f complains if SSL_shutdown() is called during
+         * an SSL handshake, while previous versions always return 0.
+         * Avoid calling SSL_shutdown() if handshake wasn't completed.
+         */
+
+        SSL_free(c->ssl->connection);
+        c->ssl = NULL;
+
+        return NGX_OK;
+    }
+
     if (c->timedout) {
         mode = SSL_RECEIVED_SHUTDOWN|SSL_SENT_SHUTDOWN;
         SSL_set_quiet_shutdown(c->ssl->connection, 1);