SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking

Sergey Kandaurov pluknet на nginx.com
Вт Июл 12 11:52:16 UTC 2022


On Tue, Jul 12, 2022 at 04:23:59AM +0300, Maxim Dounin wrote:
> Hello!
> 
> On Mon, Jul 11, 2022 at 09:06:53PM +0300, Gena Makhomed wrote:
> 
> > On 10.07.2022 11:41, Maxim Dounin wrote:
> > 
> > >> Как выловить такие ошибки в логе? 
> > >> я их не вижу, есть ошибки типа warn Но это не то.
> > 
> > > Вы чуть раньше в этом треде писали Илье, "client sent plain HTTP
> > > request to HTTPS port".  Как и другие ошибки в клиентских
> > > запросах, эти ошибки логгируются на уровне info.
> > 
> > nginx/1.23.0 из официального репозитория nginx.org пишет в лог:
> > 
> > 2022/07/11 13:14:48 [crit] 67688#67688: *154358 SSL_do_handshake() 
> > failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad 
> > key share) while SSL handshaking, client: 192.241.214.22, server: 
> > 0.0.0.0:443
> > 
> > проблема тут https://stackoverflow.com/a/67424645 на стороне клиента,
> > но в лог информация пишется на уровне [crit] - так и должно быть?
> 
> Нет, так не должно быть. Просто это относительно новая ошибка, 
> добавленная в OpenSSL 1.1.1 / TLSv1.3, и ей пока не прибит 
> правильный уровень логгирования.  Патч ниже.
> 
> Если в логах вылезает что-то ещё - можно и нужно жаловаться.
> 
> # HG changeset patch
> # User Maxim Dounin <mdounin на mdounin.ru>
> # Date 1657587735 -10800
> #      Tue Jul 12 04:02:15 2022 +0300
> # Node ID ae4b86fa92e6eb0c1fa13482695218b334f2adc3
> # Parent  219217ea49a8d648f5cadd046f1b1294ef05693c
> SSL: logging levels of various errors added in OpenSSL 1.1.1.
> 
> Starting with OpenSSL 1.1.1, various additional errors can be reported
> by OpenSSL in case of client-related issues, most notably during TLSv1.3
> handshakes.  In particular, SSL_R_BAD_KEY_SHARE ("bad key share"),
> SSL_R_BAD_EXTENSION ("bad extension"), SSL_R_BAD_CIPHER ("bad cipher"),
> SSL_R_BAD_ECPOINT ("bad ecpoint").  These are now logged at the "info"
> level.

Looks good.

I managed to repoduce all of the errors except SSL_R_BAD_CIPHER,
which requires extra effort to implement HRR in order to trigger it.
Others are easy to trigger.

If trying to enumerate TLSv1.3-specific client errors, I'd also add these
I catched with my QUIC tests adjusted to generic TLSv1.3 over TCP:

boringssl/include/openssl/ssl.h:#define SSL_R_MISSING_KEY_SHARE 258
boringssl/include/openssl/ssl.h:#define SSL_R_DUPLICATE_KEY_SHARE 264
- extension is either missing or includes a dublicate group

OpenSSL has a similar error "no suitable key share" for MISSING_KEY_SHARE.
I couldn't find an equivalent for DUPLICATE_KEY_SHARE, though.

boringssl/include/openssl/ssl.h:#define SSL_R_ERROR_PARSING_EXTENSION 149
boringssl/include/openssl/ssl.h:#define SSL_R_PARSE_TLSEXT 190
- both enqueued when e.g. receiving QUIC transport params in generic TLSv1.3:
"SSL: error:10000095:SSL routines:OPENSSL_internal:ERROR_PARSING_EXTENSION:extension 57
      error:100000be:SSL routines:OPENSSL_internal:PARSE_TLSEXT) while SSL handshaking"

PARSE_TLSEXT seems to be a rough replacement for SSL_R_BAD_EXTENSION.

Note: several of these BoringSSL-specific errors have number reused.

> 
> diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
> --- a/src/event/ngx_event_openssl.c
> +++ b/src/event/ngx_event_openssl.c
> @@ -3343,6 +3343,12 @@ ngx_ssl_connection_error(ngx_connection_
>  #ifdef SSL_R_NO_SUITABLE_KEY_SHARE
>              || n == SSL_R_NO_SUITABLE_KEY_SHARE                      /*  101 */
>  #endif
> +#ifdef SSL_R_BAD_KEY_SHARE
> +            || n == SSL_R_BAD_KEY_SHARE                              /*  108 */
> +#endif
> +#ifdef SSL_R_BAD_EXTENSION
> +            || n == SSL_R_BAD_EXTENSION                              /*  110 */
> +#endif
>  #ifdef SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM
>              || n == SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM            /*  118 */
>  #endif
> @@ -3357,6 +3363,9 @@ ngx_ssl_connection_error(ngx_connection_
>              || n == SSL_R_NO_CIPHERS_PASSED                          /*  182 */
>  #endif
>              || n == SSL_R_NO_CIPHERS_SPECIFIED                       /*  183 */
> +#ifdef SSL_R_BAD_CIPHER
> +            || n == SSL_R_BAD_CIPHER                                 /*  186 */
> +#endif
>              || n == SSL_R_NO_COMPRESSION_SPECIFIED                   /*  187 */
>              || n == SSL_R_NO_SHARED_CIPHER                           /*  193 */
>              || n == SSL_R_RECORD_LENGTH_MISMATCH                     /*  213 */
> @@ -3391,6 +3400,9 @@ ngx_ssl_connection_error(ngx_connection_
>  #ifdef SSL_R_APPLICATION_DATA_ON_SHUTDOWN
>              || n == SSL_R_APPLICATION_DATA_ON_SHUTDOWN               /*  291 */
>  #endif
> +#ifdef SSL_R_BAD_ECPOINT
> +            || n == SSL_R_BAD_ECPOINT                                /*  306 */
> +#endif
>  #ifdef SSL_R_RENEGOTIATE_EXT_TOO_LONG
>              || n == SSL_R_RENEGOTIATE_EXT_TOO_LONG                   /*  335 */
>              || n == SSL_R_RENEGOTIATION_ENCODING_ERR                 /*  336 */
> 

diff -r 6d0fd3d3b91e src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c	Wed Jun 22 13:15:15 2022 +0400
+++ b/src/event/ngx_event_openssl.c	Tue Jul 12 15:42:26 2022 +0400
@@ -3355,6 +3355,9 @@ ngx_ssl_connection_error(ngx_connection_
 #endif
             || n == SSL_R_BLOCK_CIPHER_PAD_IS_WRONG                  /*  129 */
             || n == SSL_R_DIGEST_CHECK_FAILED                        /*  149 */
+#ifdef SSL_R_ERROR_PARSING_EXTENSION
+            || n == SSL_R_ERROR_PARSING_EXTENSION                    /*  149 */
+#endif
             || n == SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST              /*  151 */
             || n == SSL_R_EXCESSIVE_MESSAGE_SIZE                     /*  152 */
             || n == SSL_R_HTTPS_PROXY_REQUEST                        /*  155 */
@@ -3387,6 +3390,12 @@ ngx_ssl_connection_error(ngx_connection_
             || n == SSL_R_NO_COMMON_SIGNATURE_ALGORITHMS             /*  253 */
 #endif
             || n == SSL_R_UNSUPPORTED_PROTOCOL                       /*  258 */
+#ifdef SSL_R_MISSING_KEY_SHARE
+            || n == SSL_R_MISSING_KEY_SHARE                          /*  258 */
+#endif
+#ifdef SSL_R_DUPLICATE_KEY_SHARE
+            || n == SSL_R_DUPLICATE_KEY_SHARE                        /*  264 */
+#endif
 #ifdef SSL_R_NO_SHARED_GROUP
             || n == SSL_R_NO_SHARED_GROUP                            /*  266 */
 #endif



Подробная информация о списке рассылки nginx-ru