diff --git a/ChangeLog.d/fix-alpn-empty-list.txt b/ChangeLog.d/fix-alpn-empty-list.txt new file mode 100644 index 0000000000..03b9345686 --- /dev/null +++ b/ChangeLog.d/fix-alpn-empty-list.txt @@ -0,0 +1,7 @@ +Bugfix + * Fix mbedtls_ssl_conf_alpn_protocols() silently accepting an empty + protocol list, which caused an invalid ALPN extension with a + zero-length protocol_name_list to be sent during the handshake, + violating RFC 7301 and causing conforming peers to reject the + connection with a fatal decode error. mbedtls_ssl_conf_alpn_protocols() + now returns MBEDTLS_ERR_SSL_BAD_INPUT_DATA for an empty list. diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 0195576213..dbebdf9c57 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2526,6 +2526,16 @@ int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf, size_t cur_len, tot_len; const char *const *p; + /* + * RFC 7301 3.1: the ALPN extension's protocol_name_list must contain + * at least one entry - an empty list is not a valid ProtocolNameList + * and must not be sent. Reject it here rather than silently sending + * an ALPN extension with a zero-length list later. + */ + if (*protos == NULL) { + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + } + /* * RFC 7301 3.1: "Empty strings MUST NOT be included and byte strings * MUST NOT be truncated."