fix: check whether a protocol is enabled during the length calculation in create_npn_advertisement #10381
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
If the following conditions are met, an issue occurs where ATS sends an invalid Server Hello during the TLS handshake:
How to reproduce
If reproduced, the following error will be displayed:
Cause
The issue is caused by ATS setting a length of the NPN string greater than the actual length in the NPN extension.
For example, when HTTP/2 is disabled in sni.yaml, the NPN string should be
8http/1.18http/1.0and its length should be 18, but ATS sets the length as 21.Here are some pointers to the relevant bits of code:
The
ssl_next_protos_advertised_callbackfunction is responsible for setting the NPN string and its length.trafficserver/iocore/net/SSLUtils.cc
Lines 1611 to 1616 in adac616
The NPN string is stored in the
ALPNSupport::npn, and its length is stored in theALPNSupport::npnsz.trafficserver/iocore/net/SSLUtils.cc
Lines 479 to 490 in adac616
trafficserver/iocore/net/ALPNSupport.cc
Lines 84 to 87 in adac616
trafficserver/iocore/net/P_ALPNSupport.h
Lines 58 to 63 in adac616
The values of
ALPNSupport::npnandALPNSupport::npnszare set in theSSLNextProtocolSet::create_npn_advertisementfunction.trafficserver/iocore/net/ALPNSupport.cc
Line 126 in adac616
In
SSLNextProtocolSet::create_npn_advertisement, it is checked whether each protocol is enabled when setting the value forALPNSupport::npn.trafficserver/iocore/net/SSLNextProtocolSet.cc
Lines 66 to 71 in adac616
However, when setting the value for
ALPNSupport::npnsz, it isn't checked whether each protocol is enabled.trafficserver/iocore/net/SSLNextProtocolSet.cc
Lines 56 to 59 in adac616
As a result, when HTTP/2 is disabled in sni.yaml, the value excluding HTTP/2 is set for
ALPNSupport::npn, but the value including HTTP/2 is set forALPNSupport::npnsz.Therefore, the length of the NPN string is greater than the actual length.