Skip to content

Commit 907126a

Browse files
author
David Cooper
committed
Fix extract_calist()
When a server supports client authentication, extract_calist() extracts the list of supported certification authorities sent by the server. extract_calist() uses different code to extract the list from a TLS 1.3 response than from a TLS 1.2 or earlier response, since the CertificateRequest message was changed for TLS 1.3. For TLS 1.2 and earlier, extract_calist() assumes that the CertificateRequest message is a sequence of certificate types, signature algorithms, and certification authorities. However, the signature algorithms field was added in TLS 1.2 and does not appear in TLS 1.1 and earlier. So, the current code does not work unless the server supports TLS 1.2 or TLS 1.3. This commit fixes the problem by checking whether the response is a TLS 1.2 response, and skipping over the extraction of the signature algorithms field if the response is neither TLS 1.2 nor TLS 1.3.
1 parent a466608 commit 907126a

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

testssl.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21299,14 +21299,19 @@ print_dn() {
2129921299
# distinguished names that are in the CA list.
2130021300
extract_calist() {
2130121301
local response="$1"
21302-
local is_tls13=false
21302+
local is_tls12=false is_tls13=false
2130321303
local certreq calist="" certtypes sigalgs dn
2130421304
local calist_string=""
2130521305
local -i len type
2130621306

21307-
# Determine whether this is a TLS 1.3 response, since the information
21308-
# is encoded in a different place for TLS 1.3.
21309-
[[ "$response" =~ \<\<\<\ TLS\ 1.3[\,]?\ Handshake\ \[length\ [0-9a-fA-F]*\]\,\ CertificateRequest ]] && is_tls13=true
21307+
# Determine whether this is a TLS 1.2 or TLS 1.3 response, since the information
21308+
# is encoded in a different place for TLS 1.3 and the CertificateRequest message
21309+
# differs between TLS 1.2 and TLS 1.1 and earlier.
21310+
if [[ "$response" =~ \<\<\<\ TLS\ 1.3[\,]?\ Handshake\ \[length\ [0-9a-fA-F]*\]\,\ CertificateRequest ]]; then
21311+
is_tls13=true
21312+
elif [[ "$response" =~ \<\<\<\ TLS\ 1.2[\,]?\ Handshake\ \[length\ [0-9a-fA-F]*\]\,\ CertificateRequest ]]; then
21313+
is_tls12=true
21314+
fi
2131021315

2131121316
# Extract just the CertificateRequest message as an ASCII-HEX string.
2131221317
certreq="${response##*CertificateRequest}"
@@ -21342,15 +21347,17 @@ extract_calist() {
2134221347
# struct {
2134321348
# ClientCertificateType certificate_types<1..2^8-1>;
2134421349
# SignatureAndHashAlgorithm
21345-
# supported_signature_algorithms<2^16-1>;
21350+
# supported_signature_algorithms<2^16-1>; - only present in TLS 1.2
2134621351
# DistinguishedName certificate_authorities<0..2^16-1>;
2134721352
# } CertificateRequest;
2134821353
len=2*$(hex2dec "${certreq:0:2}")
2134921354
certtypes="${certreq:2:len}"
2135021355
certreq="${certreq:$((len+2))}"
21351-
len=2*$(hex2dec "${certreq:0:4}")
21352-
sigalgs="${certreq:4:len}"
21353-
certreq="${certreq:$((len+4))}"
21356+
if "$is_tls12"; then
21357+
len=2*$(hex2dec "${certreq:0:4}")
21358+
sigalgs="${certreq:4:len}"
21359+
certreq="${certreq:$((len+4))}"
21360+
fi
2135421361
len=2*$(hex2dec "${certreq:0:4}")
2135521362
calist="${certreq:4:len}"
2135621363
fi

0 commit comments

Comments
 (0)