From: Emeric Brun Date: Tue, 28 Jan 2014 14:43:53 +0000 (+0100) Subject: MINOR: ssl: handshake optim for long certificate chains. X-Git-Tag: v1.5-dev22~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8b2bb5c05e64c65ea3a6c9c69e719d853a667ad;p=thirdparty%2Fhaproxy.git MINOR: ssl: handshake optim for long certificate chains. Suggested on the mailing list by Ilya Grigorik and greatly inspired from Nginx code: we try to dynamicaly rise the output buffer size from 4k to 16k during the handshake to reduce the number of round trips. This is mostly beneficial when initcwnd==10. Ilya's tests confirm the gain and show a handshake time divided by 3 : before: http://www.webpagetest.org/result/140116_VW_3bd95a5cfb7e667498ef13b59639b9bf/2/details/ after: http://www.webpagetest.org/result/140201_2X_03511ec63344f442b81c24d2bf39f59d/3/details/ --- diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 45a6dd03e9..7107a31abd 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -75,6 +75,7 @@ #include #define SSL_SOCK_ST_FL_VERIFY_DONE 0x00000001 +#define SSL_SOCK_ST_FL_16K_WBFSIZE 0x00000002 /* bits 0xFFFF0000 are reserved to store verify errors */ /* Verify errors macros */ @@ -101,6 +102,7 @@ void ssl_sock_infocbk(const SSL *ssl, int where, int ret) { struct connection *conn = (struct connection *)SSL_get_app_data(ssl); (void)ret; /* shut gcc stupid warning */ + BIO *write_bio; if (where & SSL_CB_HANDSHAKE_START) { /* Disable renegotiation (CVE-2009-3555) */ @@ -109,6 +111,21 @@ void ssl_sock_infocbk(const SSL *ssl, int where, int ret) conn->err_code = CO_ER_SSL_RENEG; } } + + if ((where & SSL_CB_ACCEPT_LOOP) == SSL_CB_ACCEPT_LOOP) { + if (!(conn->xprt_st & SSL_SOCK_ST_FL_16K_WBFSIZE)) { + /* Long certificate chains optimz + If write and read bios are differents, we + consider that the buffering was activated, + so we rise the output buffer size from 4k + to 16k */ + write_bio = SSL_get_wbio(ssl); + if (write_bio != SSL_get_rbio(ssl)) { + BIO_set_write_buffer_size(write_bio, 16384); + conn->xprt_st |= SSL_SOCK_ST_FL_16K_WBFSIZE; + } + } + } } /* Callback is called for each certificate of the chain during a verify